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

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: Switch-case instead of if-series. 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
« no previous file with comments | « no previous file | gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 'extension_flag': 'oes_standard_derivatives'
361 }
362 ],
363 },
345 # TODO: Consider implemenenting these states 364 # TODO: Consider implemenenting these states
346 # GL_GENERATE_MIPMAP_HINT
347 # GL_ACTIVE_TEXTURE, 365 # GL_ACTIVE_TEXTURE,
348 # GL_PACK_ALIGNMENT, 366 # GL_PACK_ALIGNMENT,
349 # GL_UNPACK_ALIGNMENT 367 # GL_UNPACK_ALIGNMENT
350 'LineWidth': { 368 'LineWidth': {
351 'type': 'Normal', 369 'type': 'Normal',
352 'func': 'LineWidth', 370 'func': 'LineWidth',
353 'enum': 'GL_LINE_WIDTH', 371 'enum': 'GL_LINE_WIDTH',
354 'states': [ 372 'states': [
355 { 373 {
356 'name': 'line_width', 374 'name': 'line_width',
(...skipping 1025 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 """Overridden 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 file.Write(" switch (%s) {\n" % args[0].name)
3317 for state in states:
3318 file.Write(" case %s:\n" % state['enum'])
3319 file.Write(" if (state_.%s != %s) {\n" %
3320 (state['name'], args[1].name))
3321 file.Write(" state_.%s = %s;\n" % (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 file.Write(" break;\n")
3327 file.Write(" default:\n")
3328 file.Write(" NOTREACHED();\n")
3329 file.Write(" }\n")
3330
3331
3281 class CustomHandler(TypeHandler): 3332 class CustomHandler(TypeHandler):
3282 """Handler for commands that are auto-generated but require minor tweaks.""" 3333 """Handler for commands that are auto-generated but require minor tweaks."""
3283 3334
3284 def __init__(self): 3335 def __init__(self):
3285 TypeHandler.__init__(self) 3336 TypeHandler.__init__(self)
3286 3337
3287 def WriteServiceImplementation(self, func, file): 3338 def WriteServiceImplementation(self, func, file):
3288 """Overrriden from TypeHandler.""" 3339 """Overrriden from TypeHandler."""
3289 pass 3340 pass
3290 3341
(...skipping 3441 matching lines...) Expand 10 before | Expand all | Expand 10 after
6732 'HandWritten': HandWrittenHandler(), 6783 'HandWritten': HandWrittenHandler(),
6733 'Is': IsHandler(), 6784 'Is': IsHandler(),
6734 'Manual': ManualHandler(), 6785 'Manual': ManualHandler(),
6735 'PUT': PUTHandler(), 6786 'PUT': PUTHandler(),
6736 'PUTn': PUTnHandler(), 6787 'PUTn': PUTnHandler(),
6737 'PUTXn': PUTXnHandler(), 6788 'PUTXn': PUTXnHandler(),
6738 'StateSet': StateSetHandler(), 6789 'StateSet': StateSetHandler(),
6739 'StateSetRGBAlpha': StateSetRGBAlphaHandler(), 6790 'StateSetRGBAlpha': StateSetRGBAlphaHandler(),
6740 'StateSetFrontBack': StateSetFrontBackHandler(), 6791 'StateSetFrontBack': StateSetFrontBackHandler(),
6741 'StateSetFrontBackSeparate': StateSetFrontBackSeparateHandler(), 6792 'StateSetFrontBackSeparate': StateSetFrontBackSeparateHandler(),
6793 'StateSetNamedParameter': StateSetNamedParameter(),
6742 'STRn': STRnHandler(), 6794 'STRn': STRnHandler(),
6743 'Todo': TodoHandler(), 6795 'Todo': TodoHandler(),
6744 } 6796 }
6745 6797
6746 for func_name in _FUNCTION_INFO: 6798 for func_name in _FUNCTION_INFO:
6747 info = _FUNCTION_INFO[func_name] 6799 info = _FUNCTION_INFO[func_name]
6748 type = '' 6800 type = ''
6749 if 'type' in info: 6801 if 'type' in info:
6750 type = info['type'] 6802 type = info['type']
6751 self._function_info[func_name] = FunctionInfo(info, 6803 self._function_info[func_name] = FunctionInfo(info,
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
7051 state = _STATES[state_name] 7103 state = _STATES[state_name]
7052 if state['type'] == 'FrontBack': 7104 if state['type'] == 'FrontBack':
7053 num_states = len(state['states']) 7105 num_states = len(state['states'])
7054 for ndx, group in enumerate(Grouper(num_states / 2, state['states'])): 7106 for ndx, group in enumerate(Grouper(num_states / 2, state['states'])):
7055 args = [] 7107 args = []
7056 for item in group: 7108 for item in group:
7057 args.append('%s' % item['name']) 7109 args.append('%s' % item['name'])
7058 file.Write( 7110 file.Write(
7059 " gl%s(%s, %s);\n" % 7111 " gl%s(%s, %s);\n" %
7060 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], ", ".join(args))) 7112 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], ", ".join(args)))
7113 elif state['type'] == 'NamedParameter':
7114 for item in state['states']:
7115 if 'extension_flag' in item:
7116 file.Write(" if (feature_info_->feature_flags().%s)\n " %
7117 item['extension_flag'])
7118 file.Write(" gl%s(%s, %s);\n" %
7119 (state['func'], item['enum'], item['name']))
7061 else: 7120 else:
7062 args = [] 7121 args = []
7063 for item in state['states']: 7122 for item in state['states']:
7064 args.append('%s' % item['name']) 7123 args.append('%s' % item['name'])
7065 file.Write(" gl%s(%s);\n" % (state['func'], ", ".join(args))) 7124 file.Write(" gl%s(%s);\n" % (state['func'], ", ".join(args)))
7066 file.Write("}\n") 7125 file.Write("}\n")
7067 7126
7068 file.Write("""bool ContextState::GetEnabled(GLenum cap) const { 7127 file.Write("""bool ContextState::GetEnabled(GLenum cap) const {
7069 switch (cap) { 7128 switch (cap) {
7070 """) 7129 """)
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
7218 for item in group: 7277 for item in group:
7219 if 'expected' in item: 7278 if 'expected' in item:
7220 args.append(item['expected']) 7279 args.append(item['expected'])
7221 else: 7280 else:
7222 args.append(item['default']) 7281 args.append(item['default'])
7223 file.Write( 7282 file.Write(
7224 " EXPECT_CALL(*gl_, %s(%s, %s))\n" % 7283 " EXPECT_CALL(*gl_, %s(%s, %s))\n" %
7225 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], ", ".join(args))) 7284 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], ", ".join(args)))
7226 file.Write(" .Times(1)\n") 7285 file.Write(" .Times(1)\n")
7227 file.Write(" .RetiresOnSaturation();\n") 7286 file.Write(" .RetiresOnSaturation();\n")
7287 elif state['type'] == 'NamedParameter':
7288 for item in state['states']:
7289 if 'extension_flag' in item:
7290 continue
7291 file.Write(
7292 " EXPECT_CALL(*gl_, %s(%s, %s))\n" %
7293 (state['func'], item['enum'], item['default']))
7294 file.Write(" .Times(1)\n")
7295 file.Write(" .RetiresOnSaturation();\n")
7228 else: 7296 else:
7229 args = [] 7297 args = []
7230 for item in state['states']: 7298 for item in state['states']:
7231 if 'expected' in item: 7299 if 'expected' in item:
7232 args.append(item['expected']) 7300 args.append(item['expected'])
7233 else: 7301 else:
7234 args.append(item['default']) 7302 args.append(item['default'])
7235 file.Write(" EXPECT_CALL(*gl_, %s(%s))\n" % 7303 file.Write(" EXPECT_CALL(*gl_, %s(%s))\n" %
7236 (state['func'], ", ".join(args))) 7304 (state['func'], ", ".join(args)))
7237 file.Write(" .Times(1)\n") 7305 file.Write(" .Times(1)\n")
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
7631 7699
7632 (options, args) = parser.parse_args(args=argv) 7700 (options, args) = parser.parse_args(args=argv)
7633 7701
7634 # Add in states and capabilites to GLState 7702 # Add in states and capabilites to GLState
7635 for state_name in sorted(_STATES.keys()): 7703 for state_name in sorted(_STATES.keys()):
7636 state = _STATES[state_name] 7704 state = _STATES[state_name]
7637 if 'enum' in state: 7705 if 'enum' in state:
7638 _ENUM_LISTS['GLState']['valid'].append(state['enum']) 7706 _ENUM_LISTS['GLState']['valid'].append(state['enum'])
7639 else: 7707 else:
7640 for item in state['states']: 7708 for item in state['states']:
7709 if 'extension_flag' in item:
7710 continue
7641 _ENUM_LISTS['GLState']['valid'].append(item['enum']) 7711 _ENUM_LISTS['GLState']['valid'].append(item['enum'])
7642 for capability in _CAPABILITY_FLAGS: 7712 for capability in _CAPABILITY_FLAGS:
7643 _ENUM_LISTS['GLState']['valid'].append("GL_%s" % capability['name'].upper()) 7713 _ENUM_LISTS['GLState']['valid'].append("GL_%s" % capability['name'].upper())
7644 7714
7645 # This script lives under gpu/command_buffer, cd to base directory. 7715 # This script lives under gpu/command_buffer, cd to base directory.
7646 os.chdir(os.path.dirname(__file__) + "/../..") 7716 os.chdir(os.path.dirname(__file__) + "/../..")
7647 7717
7648 gen = GLGenerator(options.verbose) 7718 gen = GLGenerator(options.verbose)
7649 gen.ParseGLH("common/GLES2/gl2.h") 7719 gen.ParseGLH("common/GLES2/gl2.h")
7650 7720
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
7698 gen.WriteGLES2Header("../GLES2/gl2chromium_autogen.h") 7768 gen.WriteGLES2Header("../GLES2/gl2chromium_autogen.h")
7699 7769
7700 if gen.errors > 0: 7770 if gen.errors > 0:
7701 print "%d errors" % gen.errors 7771 print "%d errors" % gen.errors
7702 return 1 7772 return 1
7703 return 0 7773 return 0
7704 7774
7705 7775
7706 if __name__ == '__main__': 7776 if __name__ == '__main__':
7707 sys.exit(main(sys.argv[1:])) 7777 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698