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

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

Issue 12647003: Refactor a bunch of Texture related GPU code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 1159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 # bind function. 1170 # bind function.
1171 # states: array of states that get set by this function corresponding to 1171 # states: array of states that get set by this function corresponding to
1172 # the given arguments 1172 # the given arguments
1173 # state_flag: name of flag that is set to true when function is called. 1173 # state_flag: name of flag that is set to true when function is called.
1174 # no_gl: no GL function is called. 1174 # no_gl: no GL function is called.
1175 # valid_args: A dictionary of argument indices to args to use in unit tests 1175 # valid_args: A dictionary of argument indices to args to use in unit tests
1176 # when they can not be automatically determined. 1176 # when they can not be automatically determined.
1177 # pepper_interface: The pepper interface that is used for this extension 1177 # pepper_interface: The pepper interface that is used for this extension
1178 # invalid_test: False if no invalid test needed. 1178 # invalid_test: False if no invalid test needed.
1179 # shadowed: True = the value is shadowed so no glGetXXX call will be made. 1179 # shadowed: True = the value is shadowed so no glGetXXX call will be made.
1180 # first_element_only: For PUT types, True if only the first element of an
1181 # array is used and we end up calling the single value
1182 # corresponding function. eg. TexParameteriv -> TexParameteri
1180 1183
1181 _FUNCTION_INFO = { 1184 _FUNCTION_INFO = {
1182 'ActiveTexture': { 1185 'ActiveTexture': {
1183 'decoder_func': 'DoActiveTexture', 1186 'decoder_func': 'DoActiveTexture',
1184 'unit_test': False, 1187 'unit_test': False,
1185 'impl_func': False, 1188 'impl_func': False,
1186 'client_test': False, 1189 'client_test': False,
1187 }, 1190 },
1188 'AttachShader': {'decoder_func': 'DoAttachShader'}, 1191 'AttachShader': {'decoder_func': 'DoAttachShader'},
1189 'BindAttribLocation': {'type': 'GLchar', 'bucket': True, 'needs_size': True}, 1192 'BindAttribLocation': {'type': 'GLchar', 'bucket': True, 'needs_size': True},
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after
1885 'client_test': False, 1888 'client_test': False,
1886 'extension': True, 1889 'extension': True,
1887 }, 1890 },
1888 'TexImage2D': { 1891 'TexImage2D': {
1889 'type': 'Manual', 1892 'type': 'Manual',
1890 'immediate': True, 1893 'immediate': True,
1891 'client_test': False, 1894 'client_test': False,
1892 }, 1895 },
1893 'TexParameterf': { 1896 'TexParameterf': {
1894 'decoder_func': 'DoTexParameterf', 1897 'decoder_func': 'DoTexParameterf',
1898 'gl_test_func': 'glTexParameteri',
1895 'valid_args': { 1899 'valid_args': {
1896 '2': 'GL_NEAREST' 1900 '2': 'GL_NEAREST'
1897 }, 1901 },
1898 }, 1902 },
1899 'TexParameteri': { 1903 'TexParameteri': {
1900 'decoder_func': 'DoTexParameteri', 1904 'decoder_func': 'DoTexParameteri',
1901 'valid_args': { 1905 'valid_args': {
1902 '2': 'GL_NEAREST' 1906 '2': 'GL_NEAREST'
1903 }, 1907 },
1904 }, 1908 },
1905 'TexParameterfv': { 1909 'TexParameterfv': {
1906 'type': 'PUT', 1910 'type': 'PUT',
1907 'data_type': 'GLfloat', 1911 'data_type': 'GLfloat',
1908 'data_value': 'GL_NEAREST', 1912 'data_value': 'GL_NEAREST',
1909 'count': 1, 1913 'count': 1,
1910 'decoder_func': 'DoTexParameterfv', 1914 'decoder_func': 'DoTexParameterfv',
1915 'gl_test_func': 'glTexParameteri',
1916 'first_element_only': True,
1911 }, 1917 },
1912 'TexParameteriv': { 1918 'TexParameteriv': {
1913 'type': 'PUT', 1919 'type': 'PUT',
1914 'data_type': 'GLint', 1920 'data_type': 'GLint',
1915 'data_value': 'GL_NEAREST', 1921 'data_value': 'GL_NEAREST',
1916 'count': 1, 1922 'count': 1,
1917 'decoder_func': 'DoTexParameteriv', 1923 'decoder_func': 'DoTexParameteriv',
1924 'gl_test_func': 'glTexParameteri',
1925 'first_element_only': True,
1918 }, 1926 },
1919 'TexSubImage2D': { 1927 'TexSubImage2D': {
1920 'type': 'Manual', 1928 'type': 'Manual',
1921 'immediate': True, 1929 'immediate': True,
1922 'client_test': False, 1930 'client_test': False,
1923 'cmd_args': 'GLenumTextureTarget target, GLint level, ' 1931 'cmd_args': 'GLenumTextureTarget target, GLint level, '
1924 'GLint xoffset, GLint yoffset, ' 1932 'GLint xoffset, GLint yoffset, '
1925 'GLsizei width, GLsizei height, ' 1933 'GLsizei width, GLsizei height, '
1926 'GLenumTextureFormat format, GLenumPixelType type, ' 1934 'GLenumTextureFormat format, GLenumPixelType type, '
1927 'const void* pixels, GLboolean internal' 1935 'const void* pixels, GLboolean internal'
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after
2747 gl_arg_strings.append(arg.GetValidGLArg(func, count, 0)) 2755 gl_arg_strings.append(arg.GetValidGLArg(func, count, 0))
2748 gl_func_name = func.GetGLTestFunctionName() 2756 gl_func_name = func.GetGLTestFunctionName()
2749 vars = { 2757 vars = {
2750 'test_name': 'GLES2DecoderTest%d' % file.file_num, 2758 'test_name': 'GLES2DecoderTest%d' % file.file_num,
2751 'name':name, 2759 'name':name,
2752 'gl_func_name': gl_func_name, 2760 'gl_func_name': gl_func_name,
2753 'args': ", ".join(arg_strings), 2761 'args': ", ".join(arg_strings),
2754 'gl_args': ", ".join(gl_arg_strings), 2762 'gl_args': ", ".join(gl_arg_strings),
2755 } 2763 }
2756 vars.update(extra) 2764 vars.update(extra)
2765 old_test = ""
2766 while (old_test != test):
2767 old_test = test
2768 test = test % vars
2757 file.Write(test % vars) 2769 file.Write(test % vars)
2758 2770
2759 def WriteInvalidUnitTest(self, func, file, test, extra = {}): 2771 def WriteInvalidUnitTest(self, func, file, test, extra = {}):
2760 """Writes a invalid unit test.""" 2772 """Writes a invalid unit test."""
2761 for arg_index, arg in enumerate(func.GetOriginalArgs()): 2773 for arg_index, arg in enumerate(func.GetOriginalArgs()):
2762 num_invalid_values = arg.GetNumInvalidValues(func) 2774 num_invalid_values = arg.GetNumInvalidValues(func)
2763 for value_index in range(0, num_invalid_values): 2775 for value_index in range(0, num_invalid_values):
2764 arg_strings = [] 2776 arg_strings = []
2765 parse_result = "kNoError" 2777 parse_result = "kNoError"
2766 gl_error = None 2778 gl_error = None
(...skipping 1744 matching lines...) Expand 10 before | Expand all | Expand 10 after
4511 4523
4512 4524
4513 class PUTHandler(TypeHandler): 4525 class PUTHandler(TypeHandler):
4514 """Handler for glTexParameter_v, glVertexAttrib_v functions.""" 4526 """Handler for glTexParameter_v, glVertexAttrib_v functions."""
4515 4527
4516 def __init__(self): 4528 def __init__(self):
4517 TypeHandler.__init__(self) 4529 TypeHandler.__init__(self)
4518 4530
4519 def WriteServiceUnitTest(self, func, file): 4531 def WriteServiceUnitTest(self, func, file):
4520 """Writes the service unit test for a command.""" 4532 """Writes the service unit test for a command."""
4533 expected_call = "EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s));"
4534 if func.GetInfo("first_element_only"):
4535 gl_arg_strings = []
4536 for count, arg in enumerate(func.GetOriginalArgs()):
4537 gl_arg_strings.append(arg.GetValidGLArg(func, count, 0))
4538 gl_arg_strings[-1] = "*" + gl_arg_strings[-1]
4539 expected_call = ("EXPECT_CALL(*gl_, %%(gl_func_name)s(%s));" %
4540 ", ".join(gl_arg_strings))
4521 valid_test = """ 4541 valid_test = """
4522 TEST_F(%(test_name)s, %(name)sValidArgs) { 4542 TEST_F(%(test_name)s, %(name)sValidArgs) {
4523 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s));
4524 SpecializedSetup<cmds::%(name)s, 0>(true); 4543 SpecializedSetup<cmds::%(name)s, 0>(true);
4525 cmds::%(name)s cmd; 4544 cmds::%(name)s cmd;
4526 cmd.Init(%(args)s); 4545 cmd.Init(%(args)s);
4527 GetSharedMemoryAs<%(data_type)s*>()[0] = %(data_value)s; 4546 GetSharedMemoryAs<%(data_type)s*>()[0] = %(data_value)s;
4547 %(expected_call)s
4528 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 4548 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4529 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 4549 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4530 } 4550 }
4531 """ 4551 """
4532 extra = { 4552 extra = {
4533 'data_type': func.GetInfo('data_type'), 4553 'data_type': func.GetInfo('data_type'),
4534 'data_value': func.GetInfo('data_value') or '0', 4554 'data_value': func.GetInfo('data_value') or '0',
4555 'expected_call': expected_call,
4535 } 4556 }
4536 self.WriteValidUnitTest(func, file, valid_test, extra) 4557 self.WriteValidUnitTest(func, file, valid_test, extra)
4537 4558
4538 invalid_test = """ 4559 invalid_test = """
4539 TEST_F(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { 4560 TEST_F(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) {
4540 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s)).Times(0); 4561 EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_args)s)).Times(0);
4541 SpecializedSetup<cmds::%(name)s, 0>(false); 4562 SpecializedSetup<cmds::%(name)s, 0>(false);
4542 cmds::%(name)s cmd; 4563 cmds::%(name)s cmd;
4543 cmd.Init(%(args)s); 4564 cmd.Init(%(args)s);
4544 GetSharedMemoryAs<%(data_type)s*>()[0] = %(data_value)s; 4565 GetSharedMemoryAs<%(data_type)s*>()[0] = %(data_value)s;
4545 EXPECT_EQ(error::%(parse_result)s, ExecuteCmd(cmd));%(gl_error_test)s 4566 EXPECT_EQ(error::%(parse_result)s, ExecuteCmd(cmd));%(gl_error_test)s
4546 } 4567 }
4547 """ 4568 """
4548 self.WriteInvalidUnitTest(func, file, invalid_test, extra) 4569 self.WriteInvalidUnitTest(func, file, invalid_test, extra)
4549 4570
4550 def WriteImmediateServiceUnitTest(self, func, file): 4571 def WriteImmediateServiceUnitTest(self, func, file):
4551 """Writes the service unit test for a command.""" 4572 """Writes the service unit test for a command."""
4552 valid_test = """ 4573 valid_test = """
4553 TEST_F(%(test_name)s, %(name)sValidArgs) { 4574 TEST_F(%(test_name)s, %(name)sValidArgs) {
4554 cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>(); 4575 cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>();
4555 EXPECT_CALL(
4556 *gl_,
4557 %(gl_func_name)s(%(gl_args)s,
4558 reinterpret_cast<%(data_type)s*>(ImmediateDataAddress(&cmd))));
4559 SpecializedSetup<cmds::%(name)s, 0>(true); 4576 SpecializedSetup<cmds::%(name)s, 0>(true);
4560 %(data_type)s temp[%(data_count)s] = { %(data_value)s, }; 4577 %(data_type)s temp[%(data_count)s] = { %(data_value)s, };
4561 cmd.Init(%(gl_args)s, &temp[0]); 4578 cmd.Init(%(gl_args)s, &temp[0]);
4579 EXPECT_CALL(
4580 *gl_,
4581 %(gl_func_name)s(%(gl_args)s, %(data_ref)sreinterpret_cast<
4582 %(data_type)s*>(ImmediateDataAddress(&cmd))));
4562 EXPECT_EQ(error::kNoError, 4583 EXPECT_EQ(error::kNoError,
4563 ExecuteImmediateCmd(cmd, sizeof(temp))); 4584 ExecuteImmediateCmd(cmd, sizeof(temp)));
4564 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 4585 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4565 } 4586 }
4566 """ 4587 """
4567 gl_arg_strings = [] 4588 gl_arg_strings = []
4568 gl_any_strings = [] 4589 gl_any_strings = []
4569 for count, arg in enumerate(func.GetOriginalArgs()[0:-1]): 4590 for count, arg in enumerate(func.GetOriginalArgs()[0:-1]):
4570 gl_arg_strings.append(arg.GetValidGLArg(func, count, 0)) 4591 gl_arg_strings.append(arg.GetValidGLArg(func, count, 0))
4571 gl_any_strings.append("_") 4592 gl_any_strings.append("_")
4572 extra = { 4593 extra = {
4594 'data_ref': ("*" if func.GetInfo('first_element_only') else ""),
4573 'data_type': func.GetInfo('data_type'), 4595 'data_type': func.GetInfo('data_type'),
4574 'data_count': func.GetInfo('count'), 4596 'data_count': func.GetInfo('count'),
4575 'data_value': func.GetInfo('data_value') or '0', 4597 'data_value': func.GetInfo('data_value') or '0',
4576 'gl_args': ", ".join(gl_arg_strings), 4598 'gl_args': ", ".join(gl_arg_strings),
4577 'gl_any_args': ", ".join(gl_any_strings), 4599 'gl_any_args': ", ".join(gl_any_strings),
4578 } 4600 }
4579 self.WriteValidUnitTest(func, file, valid_test, extra) 4601 self.WriteValidUnitTest(func, file, valid_test, extra)
4580 4602
4581 invalid_test = """ 4603 invalid_test = """
4582 TEST_F(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { 4604 TEST_F(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) {
(...skipping 3029 matching lines...) Expand 10 before | Expand all | Expand 10 after
7612 gen.WriteGLES2Header("../GLES2/gl2chromium_autogen.h") 7634 gen.WriteGLES2Header("../GLES2/gl2chromium_autogen.h")
7613 7635
7614 if gen.errors > 0: 7636 if gen.errors > 0:
7615 print "%d errors" % gen.errors 7637 print "%d errors" % gen.errors
7616 return 1 7638 return 1
7617 return 0 7639 return 0
7618 7640
7619 7641
7620 if __name__ == '__main__': 7642 if __name__ == '__main__':
7621 sys.exit(main(sys.argv[1:])) 7643 sys.exit(main(sys.argv[1:]))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698