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

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: Initialize extension state conditionally. Exclude extension tokens from static validity tables. 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 '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 """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 if 'extension_flag' in item:
7112 file.Write(" if (feature_info_->feature_flags().%s)\n " %
7113 item['extension_flag'])
7114 file.Write(" gl%s(%s, %s);\n" %
7115 (state['func'], item['enum'], item['name']))
7061 else: 7116 else:
7062 args = [] 7117 args = []
7063 for item in state['states']: 7118 for item in state['states']:
7064 args.append('%s' % item['name']) 7119 args.append('%s' % item['name'])
7065 file.Write(" gl%s(%s);\n" % (state['func'], ", ".join(args))) 7120 file.Write(" gl%s(%s);\n" % (state['func'], ", ".join(args)))
7066 file.Write("}\n") 7121 file.Write("}\n")
7067 7122
7068 file.Write("""bool ContextState::GetEnabled(GLenum cap) const { 7123 file.Write("""bool ContextState::GetEnabled(GLenum cap) const {
7069 switch (cap) { 7124 switch (cap) {
7070 """) 7125 """)
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
7218 for item in group: 7273 for item in group:
7219 if 'expected' in item: 7274 if 'expected' in item:
7220 args.append(item['expected']) 7275 args.append(item['expected'])
7221 else: 7276 else:
7222 args.append(item['default']) 7277 args.append(item['default'])
7223 file.Write( 7278 file.Write(
7224 " EXPECT_CALL(*gl_, %s(%s, %s))\n" % 7279 " EXPECT_CALL(*gl_, %s(%s, %s))\n" %
7225 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], ", ".join(args))) 7280 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], ", ".join(args)))
7226 file.Write(" .Times(1)\n") 7281 file.Write(" .Times(1)\n")
7227 file.Write(" .RetiresOnSaturation();\n") 7282 file.Write(" .RetiresOnSaturation();\n")
7283 elif state['type'] == 'NamedParameter':
7284 for item in state['states']:
7285 if 'extension_flag' in item:
7286 continue
7287 file.Write(
7288 " EXPECT_CALL(*gl_, %s(%s, %s))\n" %
7289 (state['func'], item['enum'], item['default']))
7290 file.Write(" .Times(1)\n")
7291 file.Write(" .RetiresOnSaturation();\n")
7228 else: 7292 else:
7229 args = [] 7293 args = []
7230 for item in state['states']: 7294 for item in state['states']:
7231 if 'expected' in item: 7295 if 'expected' in item:
7232 args.append(item['expected']) 7296 args.append(item['expected'])
7233 else: 7297 else:
7234 args.append(item['default']) 7298 args.append(item['default'])
7235 file.Write(" EXPECT_CALL(*gl_, %s(%s))\n" % 7299 file.Write(" EXPECT_CALL(*gl_, %s(%s))\n" %
7236 (state['func'], ", ".join(args))) 7300 (state['func'], ", ".join(args)))
7237 file.Write(" .Times(1)\n") 7301 file.Write(" .Times(1)\n")
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
7631 7695
7632 (options, args) = parser.parse_args(args=argv) 7696 (options, args) = parser.parse_args(args=argv)
7633 7697
7634 # Add in states and capabilites to GLState 7698 # Add in states and capabilites to GLState
7635 for state_name in sorted(_STATES.keys()): 7699 for state_name in sorted(_STATES.keys()):
7636 state = _STATES[state_name] 7700 state = _STATES[state_name]
7637 if 'enum' in state: 7701 if 'enum' in state:
7638 _ENUM_LISTS['GLState']['valid'].append(state['enum']) 7702 _ENUM_LISTS['GLState']['valid'].append(state['enum'])
7639 else: 7703 else:
7640 for item in state['states']: 7704 for item in state['states']:
7705 if 'extension_flag' in item:
7706 continue
7641 _ENUM_LISTS['GLState']['valid'].append(item['enum']) 7707 _ENUM_LISTS['GLState']['valid'].append(item['enum'])
7642 for capability in _CAPABILITY_FLAGS: 7708 for capability in _CAPABILITY_FLAGS:
7643 _ENUM_LISTS['GLState']['valid'].append("GL_%s" % capability['name'].upper()) 7709 _ENUM_LISTS['GLState']['valid'].append("GL_%s" % capability['name'].upper())
7644 7710
7645 # This script lives under gpu/command_buffer, cd to base directory. 7711 # This script lives under gpu/command_buffer, cd to base directory.
7646 os.chdir(os.path.dirname(__file__) + "/../..") 7712 os.chdir(os.path.dirname(__file__) + "/../..")
7647 7713
7648 gen = GLGenerator(options.verbose) 7714 gen = GLGenerator(options.verbose)
7649 gen.ParseGLH("common/GLES2/gl2.h") 7715 gen.ParseGLH("common/GLES2/gl2.h")
7650 7716
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
7698 gen.WriteGLES2Header("../GLES2/gl2chromium_autogen.h") 7764 gen.WriteGLES2Header("../GLES2/gl2chromium_autogen.h")
7699 7765
7700 if gen.errors > 0: 7766 if gen.errors > 0:
7701 print "%d errors" % gen.errors 7767 print "%d errors" % gen.errors
7702 return 1 7768 return 1
7703 return 0 7769 return 0
7704 7770
7705 7771
7706 if __name__ == '__main__': 7772 if __name__ == '__main__':
7707 sys.exit(main(sys.argv[1:])) 7773 sys.exit(main(sys.argv[1:]))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698