Chromium Code Reviews

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

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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 1295 matching lines...)
1306 'valid': [ 1306 'valid': [
1307 'GL_SUBSCRIBED_VALUES_BUFFER_CHROMIUM', 1307 'GL_SUBSCRIBED_VALUES_BUFFER_CHROMIUM',
1308 ], 1308 ],
1309 }, 1309 },
1310 'SubscriptionTarget': { 1310 'SubscriptionTarget': {
1311 'type': 'GLenum', 1311 'type': 'GLenum',
1312 'valid': [ 1312 'valid': [
1313 'GL_MOUSE_POSITION_CHROMIUM', 1313 'GL_MOUSE_POSITION_CHROMIUM',
1314 ], 1314 ],
1315 }, 1315 },
1316 'UniformParameter': {
1317 'type': 'GLenum',
1318 'valid': [
1319 'GL_UNIFORM_SIZE',
1320 'GL_UNIFORM_TYPE',
1321 'GL_UNIFORM_NAME_LENGTH',
1322 'GL_UNIFORM_BLOCK_INDEX',
1323 'GL_UNIFORM_OFFSET',
1324 'GL_UNIFORM_ARRAY_STRIDE',
1325 'GL_UNIFORM_MATRIX_STRIDE',
1326 'GL_UNIFORM_IS_ROW_MAJOR',
1327 ],
1328 'invalid': [
1329 'GL_UNIFORM_BLOCK_NAME_LENGTH',
1330 ],
1331 },
1332 'UniformBlockParameter': {
1333 'type': 'GLenum',
1334 'valid': [
1335 'GL_UNIFORM_BLOCK_BINDING',
1336 'GL_UNIFORM_BLOCK_DATA_SIZE',
1337 'GL_UNIFORM_BLOCK_NAME_LENGTH',
1338 'GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS',
1339 'GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES',
1340 'GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER',
1341 'GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER',
1342 ],
1343 'invalid': [
1344 'GL_NEAREST',
1345 ],
1346 },
1316 'VertexAttribType': { 1347 'VertexAttribType': {
1317 'type': 'GLenum', 1348 'type': 'GLenum',
1318 'valid': [ 1349 'valid': [
1319 'GL_BYTE', 1350 'GL_BYTE',
1320 'GL_UNSIGNED_BYTE', 1351 'GL_UNSIGNED_BYTE',
1321 'GL_SHORT', 1352 'GL_SHORT',
1322 'GL_UNSIGNED_SHORT', 1353 'GL_UNSIGNED_SHORT',
1323 # 'GL_FIXED', // This is not available on Desktop GL. 1354 # 'GL_FIXED', // This is not available on Desktop GL.
1324 'GL_FLOAT', 1355 'GL_FLOAT',
1325 ], 1356 ],
(...skipping 701 matching lines...)
2027 'data_transfer_methods': ['shm'], 2058 'data_transfer_methods': ['shm'],
2028 'cmd_args': 2059 'cmd_args':
2029 'GLidProgram program, GLuint index, uint32_t name_bucket_id, ' 2060 'GLidProgram program, GLuint index, uint32_t name_bucket_id, '
2030 'void* result', 2061 'void* result',
2031 'result': [ 2062 'result': [
2032 'int32_t success', 2063 'int32_t success',
2033 'int32_t size', 2064 'int32_t size',
2034 'uint32_t type', 2065 'uint32_t type',
2035 ], 2066 ],
2036 }, 2067 },
2068 'GetActiveUniformBlockiv': {
2069 'type': 'Custom',
2070 'data_transfer_methods': ['shm'],
2071 'result': ['SizedResult<GLint>'],
2072 'unsafe': True,
2073 },
2037 'GetActiveUniformBlockName': { 2074 'GetActiveUniformBlockName': {
2038 'type': 'Custom', 2075 'type': 'Custom',
2039 'data_transfer_methods': ['shm'], 2076 'data_transfer_methods': ['shm'],
2040 'cmd_args': 2077 'cmd_args':
2041 'GLidProgram program, GLuint index, uint32_t name_bucket_id, ' 2078 'GLidProgram program, GLuint index, uint32_t name_bucket_id, '
2042 'void* result', 2079 'void* result',
2043 'result': ['int32_t'], 2080 'result': ['int32_t'],
2044 'unsafe': True, 2081 'unsafe': True,
2045 }, 2082 },
2083 'GetActiveUniformsiv': {
2084 'type': 'Custom',
2085 'data_transfer_methods': ['shm'],
2086 'cmd_args':
2087 'GLidProgram program, uint32_t indices_bucket_id, GLenum pname, '
2088 'GLint* params',
2089 'result': ['SizedResult<GLint>'],
2090 'unsafe': True,
2091 },
2046 'GetAttachedShaders': { 2092 'GetAttachedShaders': {
2047 'type': 'Custom', 2093 'type': 'Custom',
2048 'data_transfer_methods': ['shm'], 2094 'data_transfer_methods': ['shm'],
2049 'cmd_args': 'GLidProgram program, void* result, uint32_t result_size', 2095 'cmd_args': 'GLidProgram program, void* result, uint32_t result_size',
2050 'result': ['SizedResult<GLuint>'], 2096 'result': ['SizedResult<GLuint>'],
2051 }, 2097 },
2052 'GetAttribLocation': { 2098 'GetAttribLocation': {
2053 'type': 'Custom', 2099 'type': 'Custom',
2054 'data_transfer_methods': ['shm'], 2100 'data_transfer_methods': ['shm'],
2055 'cmd_args': 2101 'cmd_args':
(...skipping 171 matching lines...)
2227 'type': 'Custom', 2273 'type': 'Custom',
2228 'expectation': False, 2274 'expectation': False,
2229 'impl_func': False, 2275 'impl_func': False,
2230 'extension': True, 2276 'extension': True,
2231 'chromium': True, 2277 'chromium': True,
2232 'client_test': False, 2278 'client_test': False,
2233 'cmd_args': 'GLidProgram program, uint32_t bucket_id', 2279 'cmd_args': 'GLidProgram program, uint32_t bucket_id',
2234 'result': ['uint32_t'], 2280 'result': ['uint32_t'],
2235 'unsafe': True, 2281 'unsafe': True,
2236 }, 2282 },
2283 'GetUniformsES3CHROMIUM': {
2284 'type': 'Custom',
2285 'expectation': False,
2286 'impl_func': False,
2287 'extension': True,
2288 'chromium': True,
2289 'client_test': False,
2290 'cmd_args': 'GLidProgram program, uint32_t bucket_id',
2291 'result': ['uint32_t'],
2292 'unsafe': True,
2293 },
2294 'GetTransformFeedbackVarying': {
2295 'type': 'Custom',
2296 'data_transfer_methods': ['shm'],
2297 'cmd_args':
2298 'GLidProgram program, GLuint index, uint32_t name_bucket_id, '
2299 'void* result',
2300 'result': [
2301 'int32_t success',
2302 'int32_t size',
2303 'uint32_t type',
2304 ],
2305 'unsafe': True,
2306 },
2307 'GetTransformFeedbackVaryingsCHROMIUM': {
2308 'type': 'Custom',
2309 'expectation': False,
2310 'impl_func': False,
2311 'extension': True,
2312 'chromium': True,
2313 'client_test': False,
2314 'cmd_args': 'GLidProgram program, uint32_t bucket_id',
2315 'result': ['uint32_t'],
2316 'unsafe': True,
2317 },
2237 'GetUniformfv': { 2318 'GetUniformfv': {
2238 'type': 'Custom', 2319 'type': 'Custom',
2239 'data_transfer_methods': ['shm'], 2320 'data_transfer_methods': ['shm'],
2240 'result': ['SizedResult<GLfloat>'], 2321 'result': ['SizedResult<GLfloat>'],
2241 }, 2322 },
2242 'GetUniformiv': { 2323 'GetUniformiv': {
2243 'type': 'Custom', 2324 'type': 'Custom',
2244 'data_transfer_methods': ['shm'], 2325 'data_transfer_methods': ['shm'],
2245 'result': ['SizedResult<GLint>'], 2326 'result': ['SizedResult<GLint>'],
2246 }, 2327 },
2328 'GetUniformIndices': {
2329 'type': 'Custom',
2330 'data_transfer_methods': ['shm'],
2331 'result': ['SizedResult<GLuint>'],
2332 'cmd_args': 'GLidProgram program, uint32_t names_bucket_id, '
2333 'GLuint* indices',
2334 'unsafe': True,
2335 },
2247 'GetUniformLocation': { 2336 'GetUniformLocation': {
2248 'type': 'Custom', 2337 'type': 'Custom',
2249 'data_transfer_methods': ['shm'], 2338 'data_transfer_methods': ['shm'],
2250 'cmd_args': 2339 'cmd_args':
2251 'GLidProgram program, uint32_t name_bucket_id, GLint* location', 2340 'GLidProgram program, uint32_t name_bucket_id, GLint* location',
2252 'result': ['GLint'], 2341 'result': ['GLint'],
2253 'error_return': -1, # http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformL ocation.xml 2342 'error_return': -1, # http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformL ocation.xml
2254 }, 2343 },
2255 'GetVertexAttribfv': { 2344 'GetVertexAttribfv': {
2256 'type': 'GETn', 2345 'type': 'GETn',
(...skipping 471 matching lines...)
2728 'UniformMatrix4x2fv': { 2817 'UniformMatrix4x2fv': {
2729 'type': 'PUTn', 2818 'type': 'PUTn',
2730 'count': 8, 2819 'count': 8,
2731 'unsafe': True, 2820 'unsafe': True,
2732 }, 2821 },
2733 'UniformMatrix4x3fv': { 2822 'UniformMatrix4x3fv': {
2734 'type': 'PUTn', 2823 'type': 'PUTn',
2735 'count': 12, 2824 'count': 12,
2736 'unsafe': True, 2825 'unsafe': True,
2737 }, 2826 },
2827 'UniformBlockBinding': {
2828 'type': 'Custom',
2829 'impl_func': False,
2830 'unsafe': True,
2831 },
2738 'UnmapBufferCHROMIUM': { 2832 'UnmapBufferCHROMIUM': {
2739 'gen_cmd': False, 2833 'gen_cmd': False,
2740 'extension': True, 2834 'extension': True,
2741 'chromium': True, 2835 'chromium': True,
2742 'client_test': False, 2836 'client_test': False,
2743 }, 2837 },
2744 'UnmapBufferSubDataCHROMIUM': { 2838 'UnmapBufferSubDataCHROMIUM': {
2745 'gen_cmd': False, 2839 'gen_cmd': False,
2746 'extension': True, 2840 'extension': True,
2747 'chromium': True, 2841 'chromium': True,
(...skipping 3725 matching lines...)
6473 } 6567 }
6474 } 6568 }
6475 }); 6569 });
6476 """ 6570 """
6477 file.Write(log_code_block % { 6571 file.Write(log_code_block % {
6478 'data': data_arg.name, 6572 'data': data_arg.name,
6479 'length': length_arg.name if not length_arg == None else '' 6573 'length': length_arg.name if not length_arg == None else ''
6480 }) 6574 })
6481 for arg in func.GetOriginalArgs(): 6575 for arg in func.GetOriginalArgs():
6482 arg.WriteClientSideValidationCode(file, func) 6576 arg.WriteClientSideValidationCode(file, func)
6483 size_code_block = """ // Compute the total size. 6577
6484 base::CheckedNumeric<size_t> total_size = count;
6485 total_size += 1;
6486 total_size *= sizeof(GLint);
6487 if (!total_size.IsValid()) {
6488 SetGLError(GL_INVALID_VALUE, "gl%(func_name)s", "overflow");
6489 return;
6490 }
6491 size_t header_size = total_size.ValueOrDefault(0);
6492 std::vector<GLint> header(count + 1);
6493 header[0] = static_cast<GLint>(count);
6494 for (GLsizei ii = 0; ii < count; ++ii) {
6495 GLint len = 0;
6496 if (%(data)s[ii]) {"""
6497 if length_arg == None:
6498 size_code_block += """
6499 len = static_cast<GLint>(strlen(%(data)s[ii]));"""
6500 else:
6501 size_code_block += """
6502 len = (%(length)s && %(length)s[ii] >= 0) ?
6503 %(length)s[ii] : base::checked_cast<GLint>(strlen(%(data)s[ii]));"""
6504 size_code_block += """
6505 }
6506 total_size += len;
6507 total_size += 1; // NULL at the end of each char array.
6508 if (!total_size.IsValid()) {
6509 SetGLError(GL_INVALID_VALUE, "gl%(func_name)s", "overflow");
6510 return;
6511 }
6512 header[ii + 1] = len;
6513 }
6514 """
6515 file.Write(size_code_block % {
6516 'data': data_arg.name,
6517 'length': length_arg.name if not length_arg == None else '',
6518 'func_name': func.name,
6519 })
6520 data_code_block = """ // Pack data into a bucket on the service.
6521 helper_->SetBucketSize(kResultBucketId, total_size.ValueOrDefault(0));
6522 size_t offset = 0;
6523 for (GLsizei ii = 0; ii <= count; ++ii) {
6524 const char* src = (ii == 0) ? reinterpret_cast<const char*>(&header[0]) :
6525 %(data)s[ii - 1];
6526 base::CheckedNumeric<size_t> checked_size = (ii == 0) ? header_size :
6527 static_cast<size_t>(header[ii]);
6528 if (ii > 0) {
6529 checked_size += 1; // NULL in the end.
6530 }
6531 if (!checked_size.IsValid()) {
6532 SetGLError(GL_INVALID_VALUE, "gl%(func_name)s", "overflow");
6533 return;
6534 }
6535 size_t size = checked_size.ValueOrDefault(0);
6536 while (size) {
6537 ScopedTransferBufferPtr buffer(size, helper_, transfer_buffer_);
6538 if (!buffer.valid() || buffer.size() == 0) {
6539 SetGLError(GL_OUT_OF_MEMORY, "gl%(func_name)s", "too large");
6540 return;
6541 }
6542 size_t copy_size = buffer.size();
6543 if (ii > 0 && buffer.size() == size)
6544 --copy_size;
6545 if (copy_size)
6546 memcpy(buffer.address(), src, copy_size);
6547 if (copy_size < buffer.size()) {
6548 // Append NULL in the end.
6549 DCHECK(copy_size + 1 == buffer.size());
6550 char* str = reinterpret_cast<char*>(buffer.address());
6551 str[copy_size] = 0;
6552 }
6553 helper_->SetBucketData(kResultBucketId, offset, buffer.size(),
6554 buffer.shm_id(), buffer.offset());
6555 offset += buffer.size();
6556 src += buffer.size();
6557 size -= buffer.size();
6558 }
6559 }
6560 DCHECK_EQ(total_size.ValueOrDefault(0), offset);
6561 """
6562 file.Write(data_code_block % {
6563 'data': data_arg.name,
6564 'length': length_arg.name if not length_arg == None else '',
6565 'func_name': func.name,
6566 })
6567 bucket_args = [] 6578 bucket_args = []
6568 for arg in func.GetOriginalArgs(): 6579 for arg in func.GetOriginalArgs():
6569 if arg.name == 'count' or arg == self.__GetLengthArg(func): 6580 if arg.name == 'count' or arg == self.__GetLengthArg(func):
6570 continue 6581 continue
6571 if arg == self.__GetDataArg(func): 6582 if arg == self.__GetDataArg(func):
6572 bucket_args.append('kResultBucketId') 6583 bucket_args.append('kResultBucketId')
6573 else: 6584 else:
6574 bucket_args.append(arg.name) 6585 bucket_args.append(arg.name)
6575 file.Write(" helper_->%sBucket(%s);\n" % 6586 code_block = """
6576 (func.name, ", ".join(bucket_args))) 6587 if (!PackStringsToBucket(count, %(data)s, %(length)s, "gl%(func_name)s")) {
6577 file.Write(" helper_->SetBucketSize(kResultBucketId, 0);"); 6588 return;
6578 file.Write(" CheckGLError();\n") 6589 }
6579 file.Write("}\n") 6590 helper_->%(func_name)sBucket(%(bucket_args)s);
6580 file.Write("\n") 6591 helper_->SetBucketSize(kResultBucketId, 0);
6592 CheckGLError();
6593 }
6594
6595 """
6596 file.Write(code_block % {
6597 'data': data_arg.name,
6598 'length': length_arg.name if not length_arg == None else 'NULL',
6599 'func_name': func.name,
6600 'bucket_args': ', '.join(bucket_args),
6601 })
6581 6602
6582 def WriteGLES2ImplementationUnitTest(self, func, file): 6603 def WriteGLES2ImplementationUnitTest(self, func, file):
6583 """Overrriden from TypeHandler.""" 6604 """Overrriden from TypeHandler."""
6584 code = """ 6605 code = """
6585 TEST_F(GLES2ImplementationTest, %(name)s) { 6606 TEST_F(GLES2ImplementationTest, %(name)s) {
6586 const uint32 kBucketId = GLES2Implementation::kResultBucketId; 6607 const uint32 kBucketId = GLES2Implementation::kResultBucketId;
6587 const char* kString1 = "happy"; 6608 const char* kString1 = "happy";
6588 const char* kString2 = "ending"; 6609 const char* kString2 = "ending";
6589 const size_t kString1Size = ::strlen(kString1) + 1; 6610 const size_t kString1Size = ::strlen(kString1) + 1;
6590 const size_t kString2Size = ::strlen(kString2) + 1; 6611 const size_t kString2Size = ::strlen(kString2) + 1;
(...skipping 1411 matching lines...)
8002 class InputStringArrayBucketArgument(Argument): 8023 class InputStringArrayBucketArgument(Argument):
8003 """A string array input argument where the strings are passed in a bucket.""" 8024 """A string array input argument where the strings are passed in a bucket."""
8004 8025
8005 def __init__(self, name, type): 8026 def __init__(self, name, type):
8006 Argument.__init__(self, name + "_bucket_id", "uint32_t") 8027 Argument.__init__(self, name + "_bucket_id", "uint32_t")
8007 self._original_name = name 8028 self._original_name = name
8008 8029
8009 def WriteGetCode(self, file): 8030 def WriteGetCode(self, file):
8010 """Overridden from Argument.""" 8031 """Overridden from Argument."""
8011 code = """ 8032 code = """
8012 const size_t kMinBucketSize = sizeof(GLint);
8013 // Each string has at least |length| in the header and a NUL character.
8014 const size_t kMinStringSize = sizeof(GLint) + 1;
8015 Bucket* bucket = GetBucket(c.%(name)s); 8033 Bucket* bucket = GetBucket(c.%(name)s);
8016 if (!bucket) { 8034 if (!bucket) {
8017 return error::kInvalidArguments; 8035 return error::kInvalidArguments;
8018 } 8036 }
8019 const size_t bucket_size = bucket->size(); 8037 GLsizei count = 0;
8020 if (bucket_size < kMinBucketSize) { 8038 std::vector<char*> strs;
8039 std::vector<GLint> len;
8040 if (!bucket->GetAsStrings(&count, &strs, &len)) {
8021 return error::kInvalidArguments; 8041 return error::kInvalidArguments;
8022 } 8042 }
8023 const char* bucket_data = bucket->GetDataAs<const char*>(0, bucket_size); 8043 const char** %(original_name)s =
8024 const GLint* header = reinterpret_cast<const GLint*>(bucket_data); 8044 strs.size() > 0 ? const_cast<const char**>(&strs[0]) : NULL;
8025 GLsizei count = static_cast<GLsizei>(header[0]); 8045 const GLint* length =
8026 if (count < 0) { 8046 len.size() > 0 ? const_cast<const GLint*>(&len[0]) : NULL;
8027 return error::kInvalidArguments; 8047 (void)length;
8028 }
8029 const size_t max_count = (bucket_size - kMinBucketSize) / kMinStringSize;
8030 if (max_count < static_cast<size_t>(count)) {
8031 return error::kInvalidArguments;
8032 }
8033 const GLint* length = header + 1;
8034 scoped_ptr<const char*[]> strs;
8035 if (count > 0)
8036 strs.reset(new const char*[count]);
8037 const char** %(original_name)s = strs.get();
8038 base::CheckedNumeric<size_t> total_size = sizeof(GLint);
8039 total_size *= count + 1; // Header size.
8040 if (!total_size.IsValid())
8041 return error::kInvalidArguments;
8042 for (GLsizei ii = 0; ii < count; ++ii) {
8043 %(original_name)s[ii] = bucket_data + total_size.ValueOrDefault(0);
8044 total_size += length[ii];
8045 total_size += 1; // NUL char at the end of each char array.
8046 if (!total_size.IsValid() || total_size.ValueOrDefault(0) > bucket_size ||
8047 %(original_name)s[ii][length[ii]] != 0) {
8048 return error::kInvalidArguments;
8049 }
8050 }
8051 if (total_size.ValueOrDefault(0) != bucket_size) {
8052 return error::kInvalidArguments;
8053 }
8054 """ 8048 """
8055 file.Write(code % { 8049 file.Write(code % {
8056 'name': self.name, 8050 'name': self.name,
8057 'original_name': self._original_name, 8051 'original_name': self._original_name,
8058 }) 8052 })
8059 8053
8060 def GetValidArg(self, func): 8054 def GetValidArg(self, func):
8061 return "kNameBucketId" 8055 return "kNameBucketId"
8062 8056
8063 def GetValidGLArg(self, func): 8057 def GetValidGLArg(self, func):
(...skipping 2074 matching lines...)
10138 Format(gen.generated_cpp_filenames) 10132 Format(gen.generated_cpp_filenames)
10139 10133
10140 if gen.errors > 0: 10134 if gen.errors > 0:
10141 print "%d errors" % gen.errors 10135 print "%d errors" % gen.errors
10142 return 1 10136 return 1
10143 return 0 10137 return 0
10144 10138
10145 10139
10146 if __name__ == '__main__': 10140 if __name__ == '__main__':
10147 sys.exit(main(sys.argv[1:])) 10141 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.cc ('k') | gpu/command_buffer/client/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine