Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: gpu/command_buffer/build_gles2_cmd_buffer.py

Issue 15792007: gpu: Autogenerate glHint state (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 'default': '0', 335 'default': '0',
336 }, 336 },
337 { 337 {
338 'name': 'stencil_back_mask', 338 'name': 'stencil_back_mask',
339 'type': 'GLuint', 339 'type': 'GLuint',
340 'enum': 'GL_STENCIL_BACK_VALUE_MASK', 340 'enum': 'GL_STENCIL_BACK_VALUE_MASK',
341 'default': '0xFFFFFFFFU', 341 'default': '0xFFFFFFFFU',
342 }, 342 },
343 ], 343 ],
344 }, 344 },
345 'Hint': {
346 'type': 'NamedParameter',
347 'func': 'Hint',
348 'states': [
349 {
350 'name': 'hint_generate_mipmap',
351 'type': 'GLenum',
352 'enum': 'GL_GENERATE_MIPMAP_HINT',
353 'default': 'GL_DONT_CARE'
354 },
355 {
356 'name': 'hint_fragment_shader_derivative',
357 'type': 'GLenum',
358 'enum': 'GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES',
359 'default': 'GL_DONT_CARE'
360 }
361 ],
362 },
345 # TODO: Consider implemenenting these states 363 # TODO: Consider implemenenting these states
346 # GL_GENERATE_MIPMAP_HINT
347 # GL_ACTIVE_TEXTURE, 364 # GL_ACTIVE_TEXTURE,
348 # GL_PACK_ALIGNMENT, 365 # GL_PACK_ALIGNMENT,
349 # GL_UNPACK_ALIGNMENT 366 # GL_UNPACK_ALIGNMENT
350 'LineWidth': { 367 'LineWidth': {
351 'type': 'Normal', 368 'type': 'Normal',
352 'func': 'LineWidth', 369 'func': 'LineWidth',
353 'enum': 'GL_LINE_WIDTH', 370 'enum': 'GL_LINE_WIDTH',
354 'states': [ 371 'states': [
355 { 372 {
356 'name': 'line_width', 373 'name': 'line_width',
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 'VertexPointer': { 927 'VertexPointer': {
911 'type': 'GLenum', 928 'type': 'GLenum',
912 'valid': [ 929 'valid': [
913 'GL_VERTEX_ATTRIB_ARRAY_POINTER', 930 'GL_VERTEX_ATTRIB_ARRAY_POINTER',
914 ], 931 ],
915 }, 932 },
916 'HintTarget': { 933 'HintTarget': {
917 'type': 'GLenum', 934 'type': 'GLenum',
918 'valid': [ 935 'valid': [
919 'GL_GENERATE_MIPMAP_HINT', 936 'GL_GENERATE_MIPMAP_HINT',
937 'GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES',
920 ], 938 ],
921 'invalid': [ 939 'invalid': [
922 'GL_PERSPECTIVE_CORRECTION_HINT', 940 'GL_PERSPECTIVE_CORRECTION_HINT',
923 ], 941 ],
924 }, 942 },
925 'HintMode': { 943 'HintMode': {
926 'type': 'GLenum', 944 'type': 'GLenum',
927 'valid': [ 945 'valid': [
928 'GL_FASTEST', 946 'GL_FASTEST',
929 'GL_NICEST', 947 'GL_NICEST',
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 '1': 'GL_INCR' 1400 '1': 'GL_INCR'
1383 }, 1401 },
1384 }, 1402 },
1385 'StencilOpSeparate': { 1403 'StencilOpSeparate': {
1386 'type': 'StateSetFrontBackSeparate', 1404 'type': 'StateSetFrontBackSeparate',
1387 'state': 'StencilOp', 1405 'state': 'StencilOp',
1388 'valid_args': { 1406 'valid_args': {
1389 '1': 'GL_INCR' 1407 '1': 'GL_INCR'
1390 }, 1408 },
1391 }, 1409 },
1392 'Hint': {'decoder_func': 'DoHint'}, 1410 'Hint': {
1411 'type': 'StateSetNamedParameter',
1412 'state': 'Hint',
1413 },
1393 'CullFace': {'type': 'StateSet', 'state': 'CullFace'}, 1414 'CullFace': {'type': 'StateSet', 'state': 'CullFace'},
1394 'FrontFace': {'type': 'StateSet', 'state': 'FrontFace'}, 1415 'FrontFace': {'type': 'StateSet', 'state': 'FrontFace'},
1395 'DepthFunc': {'type': 'StateSet', 'state': 'DepthFunc'}, 1416 'DepthFunc': {'type': 'StateSet', 'state': 'DepthFunc'},
1396 'LineWidth': { 1417 'LineWidth': {
1397 'type': 'StateSet', 1418 'type': 'StateSet',
1398 'state': 'LineWidth', 1419 'state': 'LineWidth',
1399 'valid_args': { 1420 'valid_args': {
1400 '0': '0.5f' 1421 '0': '0.5f'
1401 }, 1422 },
1402 }, 1423 },
(...skipping 1868 matching lines...) Expand 10 before | Expand all | Expand 10 after
3271 for ndx, item in enumerate(group): 3292 for ndx, item in enumerate(group):
3272 file.Write(" state_.%s = %s;\n" % (item['name'], args[ndx].name)) 3293 file.Write(" state_.%s = %s;\n" % (item['name'], args[ndx].name))
3273 if 'state_flag' in state: 3294 if 'state_flag' in state:
3274 file.Write(" %s = true;\n" % state['state_flag']) 3295 file.Write(" %s = true;\n" % state['state_flag'])
3275 if not func.GetInfo("no_gl"): 3296 if not func.GetInfo("no_gl"):
3276 file.Write(" %s(%s);\n" % 3297 file.Write(" %s(%s);\n" %
3277 (func.GetGLFunctionName(), func.MakeOriginalArgString(""))) 3298 (func.GetGLFunctionName(), func.MakeOriginalArgString("")))
3278 file.Write(" }\n") 3299 file.Write(" }\n")
3279 3300
3280 3301
3302 class StateSetNamedParameter(TypeHandler):
3303 """Handler for commands that set a state chosen with an enum parameter."""
3304
3305 def __init__(self):
3306 TypeHandler.__init__(self)
3307
3308 def WriteHandlerImplementation(self, func, file):
3309 """Overriden from TypeHandler."""
3310 state_name = func.GetInfo('state')
3311 state = _STATES[state_name]
3312 states = state['states']
3313 args = func.GetOriginalArgs()
3314 num_args = len(args)
3315 assert num_args == 2
3316 for state in states:
3317 file.Write(" " if state is states[0] else " } else ")
3318 file.Write("if (%s == %s &&\n state_.%s != %s) {\n" %
3319 (args[0].name, state['enum'], state['name'], args[1].name))
3320 file.Write(" state_.%s = %s;\n" %
3321 (state['name'], args[1].name))
3322 if not func.GetInfo("no_gl"):
3323 file.Write(" %s(%s);\n" %
3324 (func.GetGLFunctionName(), func.MakeOriginalArgString("")))
3325 file.Write(" }\n")
3326
3327
3281 class CustomHandler(TypeHandler): 3328 class CustomHandler(TypeHandler):
3282 """Handler for commands that are auto-generated but require minor tweaks.""" 3329 """Handler for commands that are auto-generated but require minor tweaks."""
3283 3330
3284 def __init__(self): 3331 def __init__(self):
3285 TypeHandler.__init__(self) 3332 TypeHandler.__init__(self)
3286 3333
3287 def WriteServiceImplementation(self, func, file): 3334 def WriteServiceImplementation(self, func, file):
3288 """Overrriden from TypeHandler.""" 3335 """Overrriden from TypeHandler."""
3289 pass 3336 pass
3290 3337
(...skipping 3441 matching lines...) Expand 10 before | Expand all | Expand 10 after
6732 'HandWritten': HandWrittenHandler(), 6779 'HandWritten': HandWrittenHandler(),
6733 'Is': IsHandler(), 6780 'Is': IsHandler(),
6734 'Manual': ManualHandler(), 6781 'Manual': ManualHandler(),
6735 'PUT': PUTHandler(), 6782 'PUT': PUTHandler(),
6736 'PUTn': PUTnHandler(), 6783 'PUTn': PUTnHandler(),
6737 'PUTXn': PUTXnHandler(), 6784 'PUTXn': PUTXnHandler(),
6738 'StateSet': StateSetHandler(), 6785 'StateSet': StateSetHandler(),
6739 'StateSetRGBAlpha': StateSetRGBAlphaHandler(), 6786 'StateSetRGBAlpha': StateSetRGBAlphaHandler(),
6740 'StateSetFrontBack': StateSetFrontBackHandler(), 6787 'StateSetFrontBack': StateSetFrontBackHandler(),
6741 'StateSetFrontBackSeparate': StateSetFrontBackSeparateHandler(), 6788 'StateSetFrontBackSeparate': StateSetFrontBackSeparateHandler(),
6789 'StateSetNamedParameter': StateSetNamedParameter(),
6742 'STRn': STRnHandler(), 6790 'STRn': STRnHandler(),
6743 'Todo': TodoHandler(), 6791 'Todo': TodoHandler(),
6744 } 6792 }
6745 6793
6746 for func_name in _FUNCTION_INFO: 6794 for func_name in _FUNCTION_INFO:
6747 info = _FUNCTION_INFO[func_name] 6795 info = _FUNCTION_INFO[func_name]
6748 type = '' 6796 type = ''
6749 if 'type' in info: 6797 if 'type' in info:
6750 type = info['type'] 6798 type = info['type']
6751 self._function_info[func_name] = FunctionInfo(info, 6799 self._function_info[func_name] = FunctionInfo(info,
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
7051 state = _STATES[state_name] 7099 state = _STATES[state_name]
7052 if state['type'] == 'FrontBack': 7100 if state['type'] == 'FrontBack':
7053 num_states = len(state['states']) 7101 num_states = len(state['states'])
7054 for ndx, group in enumerate(Grouper(num_states / 2, state['states'])): 7102 for ndx, group in enumerate(Grouper(num_states / 2, state['states'])):
7055 args = [] 7103 args = []
7056 for item in group: 7104 for item in group:
7057 args.append('%s' % item['name']) 7105 args.append('%s' % item['name'])
7058 file.Write( 7106 file.Write(
7059 " gl%s(%s, %s);\n" % 7107 " gl%s(%s, %s);\n" %
7060 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], ", ".join(args))) 7108 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], ", ".join(args)))
7109 elif state['type'] == 'NamedParameter':
7110 for item in state['states']:
7111 file.Write(" gl%s(%s, %s);\n" %
7112 (state['func'], item['enum'], item['name']))
7061 else: 7113 else:
7062 args = [] 7114 args = []
7063 for item in state['states']: 7115 for item in state['states']:
7064 args.append('%s' % item['name']) 7116 args.append('%s' % item['name'])
7065 file.Write(" gl%s(%s);\n" % (state['func'], ", ".join(args))) 7117 file.Write(" gl%s(%s);\n" % (state['func'], ", ".join(args)))
7066 file.Write("}\n") 7118 file.Write("}\n")
7067 7119
7068 file.Write("""bool ContextState::GetEnabled(GLenum cap) const { 7120 file.Write("""bool ContextState::GetEnabled(GLenum cap) const {
7069 switch (cap) { 7121 switch (cap) {
7070 """) 7122 """)
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
7218 for item in group: 7270 for item in group:
7219 if 'expected' in item: 7271 if 'expected' in item:
7220 args.append(item['expected']) 7272 args.append(item['expected'])
7221 else: 7273 else:
7222 args.append(item['default']) 7274 args.append(item['default'])
7223 file.Write( 7275 file.Write(
7224 " EXPECT_CALL(*gl_, %s(%s, %s))\n" % 7276 " EXPECT_CALL(*gl_, %s(%s, %s))\n" %
7225 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], ", ".join(args))) 7277 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], ", ".join(args)))
7226 file.Write(" .Times(1)\n") 7278 file.Write(" .Times(1)\n")
7227 file.Write(" .RetiresOnSaturation();\n") 7279 file.Write(" .RetiresOnSaturation();\n")
7280 elif state['type'] == 'NamedParameter':
7281 for item in state['states']:
7282 file.Write(
7283 " EXPECT_CALL(*gl_, %s(%s, %s))\n" %
7284 (state['func'], item['enum'], item['default']))
7285 file.Write(" .Times(1)\n")
7286 file.Write(" .RetiresOnSaturation();\n")
7228 else: 7287 else:
7229 args = [] 7288 args = []
7230 for item in state['states']: 7289 for item in state['states']:
7231 if 'expected' in item: 7290 if 'expected' in item:
7232 args.append(item['expected']) 7291 args.append(item['expected'])
7233 else: 7292 else:
7234 args.append(item['default']) 7293 args.append(item['default'])
7235 file.Write(" EXPECT_CALL(*gl_, %s(%s))\n" % 7294 file.Write(" EXPECT_CALL(*gl_, %s(%s))\n" %
7236 (state['func'], ", ".join(args))) 7295 (state['func'], ", ".join(args)))
7237 file.Write(" .Times(1)\n") 7296 file.Write(" .Times(1)\n")
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
7698 gen.WriteGLES2Header("../GLES2/gl2chromium_autogen.h") 7757 gen.WriteGLES2Header("../GLES2/gl2chromium_autogen.h")
7699 7758
7700 if gen.errors > 0: 7759 if gen.errors > 0:
7701 print "%d errors" % gen.errors 7760 print "%d errors" % gen.errors
7702 return 1 7761 return 1
7703 return 0 7762 return 0
7704 7763
7705 7764
7706 if __name__ == '__main__': 7765 if __name__ == '__main__':
7707 sys.exit(main(sys.argv[1:])) 7766 sys.exit(main(sys.argv[1:]))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698