Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """code generator for GLES2 command buffers.""" | 6 """code generator for GLES2 command buffers.""" |
| 7 | 7 |
| 8 import itertools | 8 import itertools |
| 9 import os | 9 import os |
| 10 import os.path | 10 import os.path |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 407 'name': 'pack_alignment', | 407 'name': 'pack_alignment', |
| 408 'type': 'GLint', | 408 'type': 'GLint', |
| 409 'enum': 'GL_PACK_ALIGNMENT', | 409 'enum': 'GL_PACK_ALIGNMENT', |
| 410 'default': '4' | 410 'default': '4' |
| 411 }, | 411 }, |
| 412 { | 412 { |
| 413 'name': 'unpack_alignment', | 413 'name': 'unpack_alignment', |
| 414 'type': 'GLint', | 414 'type': 'GLint', |
| 415 'enum': 'GL_UNPACK_ALIGNMENT', | 415 'enum': 'GL_UNPACK_ALIGNMENT', |
| 416 'default': '4' | 416 'default': '4' |
| 417 }, | |
| 418 { | |
| 419 'name': 'pack_row_length', | |
| 420 'type': 'GLint', | |
| 421 'enum': 'GL_PACK_ROW_LENGTH', | |
| 422 'default': '0', | |
| 423 'es3': True | |
| 424 }, | |
| 425 { | |
| 426 'name': 'pack_skip_pixels', | |
| 427 'type': 'GLint', | |
| 428 'enum': 'GL_PACK_SKIP_PIXELS', | |
| 429 'default': '0', | |
| 430 'es3': True | |
| 431 }, | |
| 432 { | |
| 433 'name': 'pack_skip_rows', | |
| 434 'type': 'GLint', | |
| 435 'enum': 'GL_PACK_SKIP_ROWS', | |
| 436 'default': '0', | |
| 437 'es3': True | |
| 438 }, | |
| 439 { | |
| 440 'name': 'unpack_row_length', | |
| 441 'type': 'GLint', | |
| 442 'enum': 'GL_UNPACK_ROW_LENGTH', | |
| 443 'default': '0', | |
| 444 'es3': True | |
| 445 }, | |
| 446 { | |
| 447 'name': 'unpack_image_height', | |
| 448 'type': 'GLint', | |
| 449 'enum': 'GL_UNPACK_IMAGE_HEIGHT', | |
| 450 'default': '0', | |
| 451 'es3': True | |
| 452 }, | |
| 453 { | |
| 454 'name': 'unpack_skip_pixels', | |
| 455 'type': 'GLint', | |
| 456 'enum': 'GL_UNPACK_SKIP_PIXELS', | |
| 457 'default': '0', | |
| 458 'es3': True | |
| 459 }, | |
| 460 { | |
| 461 'name': 'unpack_skip_rows', | |
| 462 'type': 'GLint', | |
| 463 'enum': 'GL_UNPACK_SKIP_ROWS', | |
| 464 'default': '0', | |
| 465 'es3': True | |
| 466 }, | |
| 467 { | |
| 468 'name': 'unpack_skip_images', | |
| 469 'type': 'GLint', | |
| 470 'enum': 'GL_UNPACK_SKIP_IMAGES', | |
| 471 'default': '0', | |
| 472 'es3': True | |
| 417 } | 473 } |
| 418 ], | 474 ], |
| 419 }, | 475 }, |
| 420 # TODO: Consider implemenenting these states | 476 # TODO: Consider implemenenting these states |
| 421 # GL_ACTIVE_TEXTURE | 477 # GL_ACTIVE_TEXTURE |
| 422 'LineWidth': { | 478 'LineWidth': { |
| 423 'type': 'Normal', | 479 'type': 'Normal', |
| 424 'func': 'LineWidth', | 480 'func': 'LineWidth', |
| 425 'enum': 'GL_LINE_WIDTH', | 481 'enum': 'GL_LINE_WIDTH', |
| 426 'states': [ | 482 'states': [ |
| (...skipping 9750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10177 if test_prev: | 10233 if test_prev: |
| 10178 f.write(")\n") | 10234 f.write(")\n") |
| 10179 f.write( | 10235 f.write( |
| 10180 " gl%s(%s, %s);\n" % | 10236 " gl%s(%s, %s);\n" % |
| 10181 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], | 10237 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], |
| 10182 ", ".join(args))) | 10238 ", ".join(args))) |
| 10183 elif state['type'] == 'NamedParameter': | 10239 elif state['type'] == 'NamedParameter': |
| 10184 for item in state['states']: | 10240 for item in state['states']: |
| 10185 item_name = CachedStateName(item) | 10241 item_name = CachedStateName(item) |
| 10186 | 10242 |
| 10243 if 'es3' in item: | |
| 10244 assert item['es3'] | |
| 10245 f.write(" if (feature_info_->IsES3Enabled()) {\n"); | |
|
Ken Russell (switch to Gerrit)
2015/11/25 00:59:41
This needs to be IsES3Capable() because we may swi
Zhenyao Mo
2015/11/25 18:18:48
Done.
| |
| 10187 if 'extension_flag' in item: | 10246 if 'extension_flag' in item: |
| 10188 f.write(" if (feature_info_->feature_flags().%s) {\n " % | 10247 f.write(" if (feature_info_->feature_flags().%s) {\n " % |
| 10189 item['extension_flag']) | 10248 item['extension_flag']) |
| 10190 if test_prev: | 10249 if test_prev: |
| 10191 if isinstance(item['default'], list): | 10250 if isinstance(item['default'], list): |
| 10192 f.write(" if (memcmp(prev_state->%s, %s, " | 10251 f.write(" if (memcmp(prev_state->%s, %s, " |
| 10193 "sizeof(%s) * %d)) {\n" % | 10252 "sizeof(%s) * %d)) {\n" % |
| 10194 (item_name, item_name, item['type'], | 10253 (item_name, item_name, item['type'], |
| 10195 len(item['default']))) | 10254 len(item['default']))) |
| 10196 else: | 10255 else: |
| 10197 f.write(" if (prev_state->%s != %s) {\n " % | 10256 f.write(" if (prev_state->%s != %s) {\n " % |
| 10198 (item_name, item_name)) | 10257 (item_name, item_name)) |
| 10199 if 'gl_version_flag' in item: | 10258 if 'gl_version_flag' in item: |
| 10200 item_name = item['gl_version_flag'] | 10259 item_name = item['gl_version_flag'] |
| 10201 inverted = '' | 10260 inverted = '' |
| 10202 if item_name[0] == '!': | 10261 if item_name[0] == '!': |
| 10203 inverted = '!' | 10262 inverted = '!' |
| 10204 item_name = item_name[1:] | 10263 item_name = item_name[1:] |
| 10205 f.write(" if (%sfeature_info_->gl_version_info().%s) {\n" % | 10264 f.write(" if (%sfeature_info_->gl_version_info().%s) {\n" % |
| 10206 (inverted, item_name)) | 10265 (inverted, item_name)) |
| 10207 f.write(" gl%s(%s, %s);\n" % | 10266 f.write(" gl%s(%s, %s);\n" % |
| 10208 (state['func'], | 10267 (state['func'], |
| 10209 (item['enum_set'] | 10268 (item['enum_set'] |
| 10210 if 'enum_set' in item else item['enum']), | 10269 if 'enum_set' in item else item['enum']), |
| 10211 item['name'])) | 10270 item['name'])) |
| 10212 if 'gl_version_flag' in item: | 10271 if 'gl_version_flag' in item or 'es3' in item: |
| 10213 f.write(" }\n") | 10272 f.write(" }\n") |
| 10214 if test_prev: | 10273 if test_prev: |
| 10215 if 'extension_flag' in item: | 10274 if 'extension_flag' in item: |
| 10216 f.write(" ") | 10275 f.write(" ") |
| 10217 f.write(" }") | 10276 f.write(" }") |
| 10218 if 'extension_flag' in item: | 10277 if 'extension_flag' in item: |
| 10219 f.write(" }") | 10278 f.write(" }") |
| 10220 else: | 10279 else: |
| 10221 if 'extension_flag' in state: | 10280 if 'extension_flag' in state: |
| 10222 f.write(" if (feature_info_->feature_flags().%s)\n " % | 10281 f.write(" if (feature_info_->feature_flags().%s)\n " % |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10399 f.write(" if (es3_capable) {") | 10458 f.write(" if (es3_capable) {") |
| 10400 for capability in _CAPABILITY_FLAGS: | 10459 for capability in _CAPABILITY_FLAGS: |
| 10401 capability_es3 = 'es3' in capability and capability['es3'] == True | 10460 capability_es3 = 'es3' in capability and capability['es3'] == True |
| 10402 if capability_es3: | 10461 if capability_es3: |
| 10403 f.write(" ExpectEnableDisable(GL_%s, %s);\n" % | 10462 f.write(" ExpectEnableDisable(GL_%s, %s);\n" % |
| 10404 (capability['name'].upper(), | 10463 (capability['name'].upper(), |
| 10405 ('false', 'true')['default' in capability])) | 10464 ('false', 'true')['default' in capability])) |
| 10406 f.write(""" } | 10465 f.write(""" } |
| 10407 } | 10466 } |
| 10408 | 10467 |
| 10409 void GLES2DecoderTestBase::SetupInitStateExpectations() { | 10468 void GLES2DecoderTestBase::SetupInitStateExpectations(bool es3_capable) { |
| 10410 """) | 10469 """) |
| 10411 # We need to sort the keys so the expectations match | 10470 # We need to sort the keys so the expectations match |
| 10412 for state_name in sorted(_STATES.keys()): | 10471 for state_name in sorted(_STATES.keys()): |
| 10413 state = _STATES[state_name] | 10472 state = _STATES[state_name] |
| 10414 if state['type'] == 'FrontBack': | 10473 if state['type'] == 'FrontBack': |
| 10415 num_states = len(state['states']) | 10474 num_states = len(state['states']) |
| 10416 for ndx, group in enumerate(Grouper(num_states / 2, state['states'])): | 10475 for ndx, group in enumerate(Grouper(num_states / 2, state['states'])): |
| 10417 args = [] | 10476 args = [] |
| 10418 for item in group: | 10477 for item in group: |
| 10419 if 'expected' in item: | 10478 if 'expected' in item: |
| 10420 args.append(item['expected']) | 10479 args.append(item['expected']) |
| 10421 else: | 10480 else: |
| 10422 args.append(item['default']) | 10481 args.append(item['default']) |
| 10423 f.write( | 10482 f.write( |
| 10424 " EXPECT_CALL(*gl_, %s(%s, %s))\n" % | 10483 " EXPECT_CALL(*gl_, %s(%s, %s))\n" % |
| 10425 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], ", ".join(args))) | 10484 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], ", ".join(args))) |
| 10426 f.write(" .Times(1)\n") | 10485 f.write(" .Times(1)\n") |
| 10427 f.write(" .RetiresOnSaturation();\n") | 10486 f.write(" .RetiresOnSaturation();\n") |
| 10428 elif state['type'] == 'NamedParameter': | 10487 elif state['type'] == 'NamedParameter': |
| 10429 for item in state['states']: | 10488 for item in state['states']: |
| 10430 if 'extension_flag' in item: | 10489 if 'extension_flag' in item: |
| 10431 f.write(" if (group_->feature_info()->feature_flags().%s) {\n" % | 10490 f.write(" if (group_->feature_info()->feature_flags().%s) {\n" % |
| 10432 item['extension_flag']) | 10491 item['extension_flag']) |
| 10433 f.write(" ") | 10492 f.write(" ") |
| 10493 if 'es3' in item: | |
| 10494 assert item['es3'] | |
| 10495 f.write(" if (es3_capable) {\n") | |
| 10496 f.write(" ") | |
| 10434 expect_value = item['default'] | 10497 expect_value = item['default'] |
| 10435 if isinstance(expect_value, list): | 10498 if isinstance(expect_value, list): |
| 10436 # TODO: Currently we do not check array values. | 10499 # TODO: Currently we do not check array values. |
| 10437 expect_value = "_" | 10500 expect_value = "_" |
| 10438 | 10501 |
| 10439 f.write( | 10502 f.write( |
| 10440 " EXPECT_CALL(*gl_, %s(%s, %s))\n" % | 10503 " EXPECT_CALL(*gl_, %s(%s, %s))\n" % |
| 10441 (state['func'], | 10504 (state['func'], |
| 10442 (item['enum_set'] | 10505 (item['enum_set'] |
| 10443 if 'enum_set' in item else item['enum']), | 10506 if 'enum_set' in item else item['enum']), |
| 10444 expect_value)) | 10507 expect_value)) |
| 10445 f.write(" .Times(1)\n") | 10508 f.write(" .Times(1)\n") |
| 10446 f.write(" .RetiresOnSaturation();\n") | 10509 f.write(" .RetiresOnSaturation();\n") |
| 10447 if 'extension_flag' in item: | 10510 if 'extension_flag' in item or 'es3' in item: |
| 10448 f.write(" }\n") | 10511 f.write(" }\n") |
| 10449 else: | 10512 else: |
| 10450 if 'extension_flag' in state: | 10513 if 'extension_flag' in state: |
| 10451 f.write(" if (group_->feature_info()->feature_flags().%s) {\n" % | 10514 f.write(" if (group_->feature_info()->feature_flags().%s) {\n" % |
| 10452 state['extension_flag']) | 10515 state['extension_flag']) |
| 10453 f.write(" ") | 10516 f.write(" ") |
| 10454 args = [] | 10517 args = [] |
| 10455 for item in state['states']: | 10518 for item in state['states']: |
| 10456 if 'expected' in item: | 10519 if 'expected' in item: |
| 10457 args.append(item['expected']) | 10520 args.append(item['expected']) |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10772 | 10835 |
| 10773 """) | 10836 """) |
| 10774 | 10837 |
| 10775 enums = sorted(_NAMED_TYPE_INFO.keys()) | 10838 enums = sorted(_NAMED_TYPE_INFO.keys()) |
| 10776 for enum in enums: | 10839 for enum in enums: |
| 10777 if _NAMED_TYPE_INFO[enum]['type'] == 'GLenum': | 10840 if _NAMED_TYPE_INFO[enum]['type'] == 'GLenum': |
| 10778 f.write("std::string GLES2Util::GetString%s(uint32_t value) {\n" % | 10841 f.write("std::string GLES2Util::GetString%s(uint32_t value) {\n" % |
| 10779 enum) | 10842 enum) |
| 10780 valid_list = _NAMED_TYPE_INFO[enum]['valid'] | 10843 valid_list = _NAMED_TYPE_INFO[enum]['valid'] |
| 10781 if 'valid_es3' in _NAMED_TYPE_INFO[enum]: | 10844 if 'valid_es3' in _NAMED_TYPE_INFO[enum]: |
| 10782 valid_list = valid_list + _NAMED_TYPE_INFO[enum]['valid_es3'] | 10845 for es3_enum in _NAMED_TYPE_INFO[enum]['valid_es3']: |
| 10846 if not es3_enum in valid_list: | |
| 10847 valid_list.append(es3_enum) | |
| 10783 assert len(valid_list) == len(set(valid_list)) | 10848 assert len(valid_list) == len(set(valid_list)) |
| 10784 if len(valid_list) > 0: | 10849 if len(valid_list) > 0: |
| 10785 f.write(" static const EnumToString string_table[] = {\n") | 10850 f.write(" static const EnumToString string_table[] = {\n") |
| 10786 for value in valid_list: | 10851 for value in valid_list: |
| 10787 f.write(' { %s, "%s" },\n' % (value, value)) | 10852 f.write(' { %s, "%s" },\n' % (value, value)) |
| 10788 f.write(""" }; | 10853 f.write(""" }; |
| 10789 return GLES2Util::GetQualifiedEnumString( | 10854 return GLES2Util::GetQualifiedEnumString( |
| 10790 string_table, arraysize(string_table), value); | 10855 string_table, arraysize(string_table), value); |
| 10791 } | 10856 } |
| 10792 | 10857 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11013 help="base directory for resulting files, under chrome/src. default is " | 11078 help="base directory for resulting files, under chrome/src. default is " |
| 11014 "empty. Use this if you want the result stored under gen.") | 11079 "empty. Use this if you want the result stored under gen.") |
| 11015 parser.add_option( | 11080 parser.add_option( |
| 11016 "-v", "--verbose", action="store_true", | 11081 "-v", "--verbose", action="store_true", |
| 11017 help="prints more output.") | 11082 help="prints more output.") |
| 11018 | 11083 |
| 11019 (options, args) = parser.parse_args(args=argv) | 11084 (options, args) = parser.parse_args(args=argv) |
| 11020 | 11085 |
| 11021 # Add in states and capabilites to GLState | 11086 # Add in states and capabilites to GLState |
| 11022 gl_state_valid = _NAMED_TYPE_INFO['GLState']['valid'] | 11087 gl_state_valid = _NAMED_TYPE_INFO['GLState']['valid'] |
| 11088 gl_state_valid_es3 = _NAMED_TYPE_INFO['GLState']['valid_es3'] | |
| 11023 for state_name in sorted(_STATES.keys()): | 11089 for state_name in sorted(_STATES.keys()): |
| 11024 state = _STATES[state_name] | 11090 state = _STATES[state_name] |
| 11025 if 'extension_flag' in state: | 11091 if 'extension_flag' in state: |
| 11026 continue | 11092 continue |
| 11027 if 'enum' in state: | 11093 if 'enum' in state: |
| 11028 if not state['enum'] in gl_state_valid: | 11094 if not state['enum'] in gl_state_valid: |
| 11029 gl_state_valid.append(state['enum']) | 11095 gl_state_valid.append(state['enum']) |
| 11030 else: | 11096 else: |
| 11031 for item in state['states']: | 11097 for item in state['states']: |
| 11032 if 'extension_flag' in item: | 11098 if 'extension_flag' in item: |
| 11033 continue | 11099 continue |
| 11034 if not item['enum'] in gl_state_valid: | 11100 if 'es3' in item: |
| 11035 gl_state_valid.append(item['enum']) | 11101 assert item['es3'] |
| 11102 if not item['enum'] in gl_state_valid_es3: | |
| 11103 gl_state_valid_es3.append(item['enum']) | |
| 11104 else: | |
| 11105 if not item['enum'] in gl_state_valid: | |
| 11106 gl_state_valid.append(item['enum']) | |
| 11036 for capability in _CAPABILITY_FLAGS: | 11107 for capability in _CAPABILITY_FLAGS: |
| 11037 valid_value = "GL_%s" % capability['name'].upper() | 11108 valid_value = "GL_%s" % capability['name'].upper() |
| 11038 if not valid_value in gl_state_valid: | 11109 if not valid_value in gl_state_valid: |
| 11039 gl_state_valid.append(valid_value) | 11110 gl_state_valid.append(valid_value) |
| 11040 | 11111 |
| 11041 # This script lives under gpu/command_buffer, cd to base directory. | 11112 # This script lives under gpu/command_buffer, cd to base directory. |
| 11042 os.chdir(os.path.dirname(__file__) + "/../..") | 11113 os.chdir(os.path.dirname(__file__) + "/../..") |
| 11043 base_dir = os.getcwd() | 11114 base_dir = os.getcwd() |
| 11044 gen = GLGenerator(options.verbose) | 11115 gen = GLGenerator(options.verbose) |
| 11045 gen.ParseGLH("gpu/command_buffer/cmd_buffer_functions.txt") | 11116 gen.ParseGLH("gpu/command_buffer/cmd_buffer_functions.txt") |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11115 Format(gen.generated_cpp_filenames) | 11186 Format(gen.generated_cpp_filenames) |
| 11116 | 11187 |
| 11117 if gen.errors > 0: | 11188 if gen.errors > 0: |
| 11118 print "%d errors" % gen.errors | 11189 print "%d errors" % gen.errors |
| 11119 return 1 | 11190 return 1 |
| 11120 return 0 | 11191 return 0 |
| 11121 | 11192 |
| 11122 | 11193 |
| 11123 if __name__ == '__main__': | 11194 if __name__ == '__main__': |
| 11124 sys.exit(main(sys.argv[1:])) | 11195 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |