OLD | NEW |
---|---|
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 2345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2356 'decoder_func': 'glClearDepth', | 2356 'decoder_func': 'glClearDepth', |
2357 'gl_test_func': 'glClearDepth', | 2357 'gl_test_func': 'glClearDepth', |
2358 'valid_args': { | 2358 'valid_args': { |
2359 '0': '0.5f' | 2359 '0': '0.5f' |
2360 }, | 2360 }, |
2361 }, | 2361 }, |
2362 'ClientWaitSync': { | 2362 'ClientWaitSync': { |
2363 'type': 'Custom', | 2363 'type': 'Custom', |
2364 'data_transfer_methods': ['shm'], | 2364 'data_transfer_methods': ['shm'], |
2365 'cmd_args': 'GLuint sync, GLbitfieldSyncFlushFlags flags, ' | 2365 'cmd_args': 'GLuint sync, GLbitfieldSyncFlushFlags flags, ' |
2366 'GLuint timeout_0, GLuint timeout_1, GLenum* result', | 2366 'GLuint64 timeout, GLenum* result', |
2367 'unsafe': True, | 2367 'unsafe': True, |
2368 'result': ['GLenum'], | 2368 'result': ['GLenum'], |
2369 'trace_level': 2, | 2369 'trace_level': 2, |
2370 }, | 2370 }, |
2371 'ColorMask': { | 2371 'ColorMask': { |
2372 'type': 'StateSet', | 2372 'type': 'StateSet', |
2373 'state': 'ColorMask', | 2373 'state': 'ColorMask', |
2374 'no_gl': True, | 2374 'no_gl': True, |
2375 'expectation': False, | 2375 'expectation': False, |
2376 }, | 2376 }, |
(...skipping 1437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3814 'VertexAttribPointer': { | 3814 'VertexAttribPointer': { |
3815 'type': 'Manual', | 3815 'type': 'Manual', |
3816 'cmd_args': 'GLuint indx, GLintVertexAttribSize size, ' | 3816 'cmd_args': 'GLuint indx, GLintVertexAttribSize size, ' |
3817 'GLenumVertexAttribType type, GLboolean normalized, ' | 3817 'GLenumVertexAttribType type, GLboolean normalized, ' |
3818 'GLsizei stride, GLuint offset', | 3818 'GLsizei stride, GLuint offset', |
3819 'client_test': False, | 3819 'client_test': False, |
3820 }, | 3820 }, |
3821 'WaitSync': { | 3821 'WaitSync': { |
3822 'type': 'Custom', | 3822 'type': 'Custom', |
3823 'cmd_args': 'GLuint sync, GLbitfieldSyncFlushFlags flags, ' | 3823 'cmd_args': 'GLuint sync, GLbitfieldSyncFlushFlags flags, ' |
3824 'GLuint timeout_0, GLuint timeout_1', | 3824 'GLuint64 timeout', |
Zhenyao Mo
2015/12/15 23:19:20
Now it's the same original signature, we don't nee
David Yen
2015/12/15 23:20:30
That's what I originally thought too, but actually
| |
3825 'impl_func': False, | 3825 'impl_func': False, |
3826 'client_test': False, | 3826 'client_test': False, |
3827 'unsafe': True, | 3827 'unsafe': True, |
3828 'trace_level': 1, | 3828 'trace_level': 1, |
3829 }, | 3829 }, |
3830 'Scissor': { | 3830 'Scissor': { |
3831 'type': 'StateSet', | 3831 'type': 'StateSet', |
3832 'state': 'Scissor', | 3832 'state': 'Scissor', |
3833 }, | 3833 }, |
3834 'Viewport': { | 3834 'Viewport': { |
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4585 else: | 4585 else: |
4586 f.write(" struct Result {\n") | 4586 f.write(" struct Result {\n") |
4587 for line in result: | 4587 for line in result: |
4588 f.write(" %s;\n" % line) | 4588 f.write(" %s;\n" % line) |
4589 f.write(" };\n\n") | 4589 f.write(" };\n\n") |
4590 | 4590 |
4591 func.WriteCmdComputeSize(f) | 4591 func.WriteCmdComputeSize(f) |
4592 func.WriteCmdSetHeader(f) | 4592 func.WriteCmdSetHeader(f) |
4593 func.WriteCmdInit(f) | 4593 func.WriteCmdInit(f) |
4594 func.WriteCmdSet(f) | 4594 func.WriteCmdSet(f) |
4595 func.WriteArgAccessors(f) | |
4595 | 4596 |
4596 f.write(" gpu::CommandHeader header;\n") | 4597 f.write(" gpu::CommandHeader header;\n") |
4598 total_args = 0 | |
4597 args = func.GetCmdArgs() | 4599 args = func.GetCmdArgs() |
4598 for arg in args: | 4600 for arg in args: |
4599 f.write(" %s %s;\n" % (arg.cmd_type, arg.name)) | 4601 for cmd_type, name in arg.GetArgDecls(): |
4602 f.write(" %s %s;\n" % (cmd_type, name)) | |
4603 total_args += 1 | |
4600 | 4604 |
4601 consts = func.GetCmdConstants() | 4605 consts = func.GetCmdConstants() |
4602 for const in consts: | 4606 for const in consts: |
4607 const_decls = const.GetArgDecls() | |
4608 assert(len(const_decls) == 1) | |
4609 const_cmd_type, const_name = const_decls[0] | |
4603 f.write(" static const %s %s = %s;\n" % | 4610 f.write(" static const %s %s = %s;\n" % |
4604 (const.cmd_type, const.name, const.GetConstantValue())) | 4611 (const_cmd_type, const_name, const.GetConstantValue())) |
4605 | 4612 |
4606 f.write("};\n") | 4613 f.write("};\n") |
4607 f.write("\n") | 4614 f.write("\n") |
4608 | 4615 |
4609 size = len(args) * _SIZE_OF_UINT32 + _SIZE_OF_COMMAND_HEADER | 4616 size = total_args * _SIZE_OF_UINT32 + _SIZE_OF_COMMAND_HEADER |
4610 f.write("static_assert(sizeof(%s) == %d,\n" % (func.name, size)) | 4617 f.write("static_assert(sizeof(%s) == %d,\n" % (func.name, size)) |
4611 f.write(" \"size of %s should be %d\");\n" % | 4618 f.write(" \"size of %s should be %d\");\n" % |
4612 (func.name, size)) | 4619 (func.name, size)) |
4613 f.write("static_assert(offsetof(%s, header) == 0,\n" % func.name) | 4620 f.write("static_assert(offsetof(%s, header) == 0,\n" % func.name) |
4614 f.write(" \"offset of %s header should be 0\");\n" % | 4621 f.write(" \"offset of %s header should be 0\");\n" % |
4615 func.name) | 4622 func.name) |
4616 offset = _SIZE_OF_COMMAND_HEADER | 4623 offset = _SIZE_OF_COMMAND_HEADER |
4617 for arg in args: | 4624 for arg in args: |
4618 f.write("static_assert(offsetof(%s, %s) == %d,\n" % | 4625 for _, name in arg.GetArgDecls(): |
4619 (func.name, arg.name, offset)) | 4626 f.write("static_assert(offsetof(%s, %s) == %d,\n" % |
4620 f.write(" \"offset of %s %s should be %d\");\n" % | 4627 (func.name, name, offset)) |
4621 (func.name, arg.name, offset)) | 4628 f.write(" \"offset of %s %s should be %d\");\n" % |
4622 offset += _SIZE_OF_UINT32 | 4629 (func.name, name, offset)) |
4630 offset += _SIZE_OF_UINT32 | |
4623 if not result == None and len(result) > 1: | 4631 if not result == None and len(result) > 1: |
4624 offset = 0; | 4632 offset = 0; |
4625 for line in result: | 4633 for line in result: |
4626 parts = line.split() | 4634 parts = line.split() |
4627 name = parts[-1] | 4635 name = parts[-1] |
4628 check = """ | 4636 check = """ |
4629 static_assert(offsetof(%(cmd_name)s::Result, %(field_name)s) == %(offset)d, | 4637 static_assert(offsetof(%(cmd_name)s::Result, %(field_name)s) == %(offset)d, |
4630 "offset of %(cmd_name)s Result %(field_name)s should be " | 4638 "offset of %(cmd_name)s Result %(field_name)s should be " |
4631 "%(offset)d"); | 4639 "%(offset)d"); |
4632 """ | 4640 """ |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4712 args = func.GetCmdArgs() | 4720 args = func.GetCmdArgs() |
4713 for value, arg in enumerate(args): | 4721 for value, arg in enumerate(args): |
4714 f.write(",\n static_cast<%s>(%d)" % (arg.type, value + 11)) | 4722 f.write(",\n static_cast<%s>(%d)" % (arg.type, value + 11)) |
4715 f.write(");\n") | 4723 f.write(");\n") |
4716 f.write(" EXPECT_EQ(static_cast<uint32_t>(cmds::%s::kCmdId),\n" % | 4724 f.write(" EXPECT_EQ(static_cast<uint32_t>(cmds::%s::kCmdId),\n" % |
4717 func.name) | 4725 func.name) |
4718 f.write(" cmd.header.command);\n") | 4726 f.write(" cmd.header.command);\n") |
4719 func.type_handler.WriteCmdSizeTest(func, f) | 4727 func.type_handler.WriteCmdSizeTest(func, f) |
4720 for value, arg in enumerate(args): | 4728 for value, arg in enumerate(args): |
4721 f.write(" EXPECT_EQ(static_cast<%s>(%d), cmd.%s);\n" % | 4729 f.write(" EXPECT_EQ(static_cast<%s>(%d), cmd.%s);\n" % |
4722 (arg.type, value + 11, arg.name)) | 4730 (arg.type, value + 11, arg.GetArgAccessor())) |
4723 f.write(" CheckBytesWrittenMatchesExpectedSize(\n") | 4731 f.write(" CheckBytesWrittenMatchesExpectedSize(\n") |
4724 f.write(" next_cmd, sizeof(cmd));\n") | 4732 f.write(" next_cmd, sizeof(cmd));\n") |
4725 f.write("}\n") | 4733 f.write("}\n") |
4726 f.write("\n") | 4734 f.write("\n") |
4727 | 4735 |
4728 def WriteImmediateFormatTest(self, func, f): | 4736 def WriteImmediateFormatTest(self, func, f): |
4729 """Writes a format test for an immediate version of a command.""" | 4737 """Writes a format test for an immediate version of a command.""" |
4730 pass | 4738 pass |
4731 | 4739 |
4732 def WriteGetDataSizeCode(self, func, f): | 4740 def WriteGetDataSizeCode(self, func, f): |
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5490 f.write( | 5498 f.write( |
5491 " uint32_t total_size = 0; // WARNING: compute correct size.\n") | 5499 " uint32_t total_size = 0; // WARNING: compute correct size.\n") |
5492 | 5500 |
5493 def WriteImmediateCmdInit(self, func, f): | 5501 def WriteImmediateCmdInit(self, func, f): |
5494 """Overrriden from TypeHandler.""" | 5502 """Overrriden from TypeHandler.""" |
5495 f.write(" void Init(%s) {\n" % func.MakeTypedCmdArgString("_")) | 5503 f.write(" void Init(%s) {\n" % func.MakeTypedCmdArgString("_")) |
5496 self.WriteImmediateCmdGetTotalSize(func, f) | 5504 self.WriteImmediateCmdGetTotalSize(func, f) |
5497 f.write(" SetHeader(total_size);\n") | 5505 f.write(" SetHeader(total_size);\n") |
5498 args = func.GetCmdArgs() | 5506 args = func.GetCmdArgs() |
5499 for arg in args: | 5507 for arg in args: |
5500 f.write(" %s = _%s;\n" % (arg.name, arg.name)) | 5508 arg.WriteSetCode(f, 4, '_%s' % arg.name) |
5501 f.write(" }\n") | 5509 f.write(" }\n") |
5502 f.write("\n") | 5510 f.write("\n") |
5503 | 5511 |
5504 def WriteImmediateCmdSet(self, func, f): | 5512 def WriteImmediateCmdSet(self, func, f): |
5505 """Overrriden from TypeHandler.""" | 5513 """Overrriden from TypeHandler.""" |
5506 copy_args = func.MakeCmdArgString("_", False) | 5514 copy_args = func.MakeCmdArgString("_", False) |
5507 f.write(" void* Set(void* cmd%s) {\n" % | 5515 f.write(" void* Set(void* cmd%s) {\n" % |
5508 func.MakeTypedCmdArgString("_", True)) | 5516 func.MakeTypedCmdArgString("_", True)) |
5509 self.WriteImmediateCmdGetTotalSize(func, f) | 5517 self.WriteImmediateCmdGetTotalSize(func, f) |
5510 f.write(" static_cast<ValueType*>(cmd)->Init(%s);\n" % copy_args) | 5518 f.write(" static_cast<ValueType*>(cmd)->Init(%s);\n" % copy_args) |
(...skipping 3003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8514 | 8522 |
8515 return len(self.GetValidValues()) == 1 | 8523 return len(self.GetValidValues()) == 1 |
8516 | 8524 |
8517 def GetConstantValue(self): | 8525 def GetConstantValue(self): |
8518 return self.GetValidValues()[0] | 8526 return self.GetValidValues()[0] |
8519 | 8527 |
8520 class Argument(object): | 8528 class Argument(object): |
8521 """A class that represents a function argument.""" | 8529 """A class that represents a function argument.""" |
8522 | 8530 |
8523 cmd_type_map_ = { | 8531 cmd_type_map_ = { |
8524 'GLenum': 'uint32_t', | 8532 'GLenum': ['uint32_t'], |
8525 'GLint': 'int32_t', | 8533 'GLint': ['int32_t'], |
8526 'GLintptr': 'int32_t', | 8534 'GLintptr': ['int32_t'], |
8527 'GLsizei': 'int32_t', | 8535 'GLsizei': ['int32_t'], |
8528 'GLsizeiptr': 'int32_t', | 8536 'GLsizeiptr': ['int32_t'], |
8529 'GLfloat': 'float', | 8537 'GLfloat': ['float'], |
8530 'GLclampf': 'float', | 8538 'GLclampf': ['float'], |
8539 'GLuint64': ['uint32_t', 'uint32_t'], | |
8531 } | 8540 } |
8532 need_validation_ = ['GLsizei*', 'GLboolean*', 'GLenum*', 'GLint*'] | 8541 need_validation_ = ['GLsizei*', 'GLboolean*', 'GLenum*', 'GLint*'] |
8533 | 8542 |
8534 def __init__(self, name, type): | 8543 def __init__(self, name, type): |
8535 self.name = name | 8544 self.name = name |
8536 self.optional = type.endswith("Optional*") | 8545 self.optional = type.endswith("Optional*") |
8537 if self.optional: | 8546 if self.optional: |
8538 type = type[:-len("Optional*")] + "*" | 8547 type = type[:-len("Optional*")] + "*" |
8539 self.type = type | 8548 self.type = type |
8540 | 8549 |
8541 if type in self.cmd_type_map_: | 8550 if type in self.cmd_type_map_: |
8542 self.cmd_type = self.cmd_type_map_[type] | 8551 self.cmd_type = self.cmd_type_map_[type] |
8543 else: | 8552 else: |
8544 self.cmd_type = 'uint32_t' | 8553 self.cmd_type = ['uint32_t'] |
8545 | 8554 |
8546 def IsPointer(self): | 8555 def IsPointer(self): |
8547 """Returns true if argument is a pointer.""" | 8556 """Returns true if argument is a pointer.""" |
8548 return False | 8557 return False |
8549 | 8558 |
8550 def IsPointer2D(self): | 8559 def IsPointer2D(self): |
8551 """Returns true if argument is a 2D pointer.""" | 8560 """Returns true if argument is a 2D pointer.""" |
8552 return False | 8561 return False |
8553 | 8562 |
8554 def IsConstant(self): | 8563 def IsConstant(self): |
(...skipping 12 matching lines...) Expand all Loading... | |
8567 | 8576 |
8568 def GetValidArg(self, func): | 8577 def GetValidArg(self, func): |
8569 """Gets a valid value for this argument.""" | 8578 """Gets a valid value for this argument.""" |
8570 valid_arg = func.GetValidArg(self) | 8579 valid_arg = func.GetValidArg(self) |
8571 if valid_arg != None: | 8580 if valid_arg != None: |
8572 return valid_arg | 8581 return valid_arg |
8573 | 8582 |
8574 index = func.GetOriginalArgs().index(self) | 8583 index = func.GetOriginalArgs().index(self) |
8575 return str(index + 1) | 8584 return str(index + 1) |
8576 | 8585 |
8586 def GetArgDecls(self): | |
8587 if len(self.cmd_type) == 1: | |
8588 return [(self.cmd_type[0], self.name)] | |
8589 else: | |
8590 return [(cmd_type, self.name + '_%d' % i) | |
8591 for i, cmd_type | |
8592 in enumerate(self.cmd_type)] | |
8593 | |
8577 def GetValidClientSideArg(self, func): | 8594 def GetValidClientSideArg(self, func): |
8578 """Gets a valid value for this argument.""" | 8595 """Gets a valid value for this argument.""" |
8579 valid_arg = func.GetValidArg(self) | 8596 valid_arg = func.GetValidArg(self) |
8580 if valid_arg != None: | 8597 if valid_arg != None: |
8581 return valid_arg | 8598 return valid_arg |
8582 | 8599 |
8583 if self.IsPointer(): | 8600 if self.IsPointer(): |
8584 return 'nullptr' | 8601 return 'nullptr' |
8585 index = func.GetOriginalArgs().index(self) | 8602 index = func.GetOriginalArgs().index(self) |
8586 if self.type == 'GLsync': | 8603 if self.type == 'GLsync': |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8624 return '123' | 8641 return '123' |
8625 | 8642 |
8626 def GetNumInvalidValues(self, func): | 8643 def GetNumInvalidValues(self, func): |
8627 """returns the number of invalid values to be tested.""" | 8644 """returns the number of invalid values to be tested.""" |
8628 return 0 | 8645 return 0 |
8629 | 8646 |
8630 def GetInvalidArg(self, index): | 8647 def GetInvalidArg(self, index): |
8631 """returns an invalid value and expected parse result by index.""" | 8648 """returns an invalid value and expected parse result by index.""" |
8632 return ("---ERROR0---", "---ERROR2---", None) | 8649 return ("---ERROR0---", "---ERROR2---", None) |
8633 | 8650 |
8651 def GetArgAccessor(self): | |
8652 """Returns the name of the accessor for the argument within the struct.""" | |
8653 return self.name | |
8654 | |
8634 def GetLogArg(self): | 8655 def GetLogArg(self): |
8635 """Get argument appropriate for LOG macro.""" | 8656 """Get argument appropriate for LOG macro.""" |
8636 if self.type == 'GLboolean': | 8657 if self.type == 'GLboolean': |
8637 return 'GLES2Util::GetStringBool(%s)' % self.name | 8658 return 'GLES2Util::GetStringBool(%s)' % self.name |
8638 if self.type == 'GLenum': | 8659 if self.type == 'GLenum': |
8639 return 'GLES2Util::GetStringEnum(%s)' % self.name | 8660 return 'GLES2Util::GetStringEnum(%s)' % self.name |
8640 return self.name | 8661 return self.name |
8641 | 8662 |
8642 def WriteGetCode(self, f): | 8663 def WriteGetCode(self, f): |
8643 """Writes the code to get an argument from a command structure.""" | 8664 """Writes the code to get an argument from a command structure.""" |
8644 if self.type == 'GLsync': | 8665 if self.type == 'GLsync': |
8645 my_type = 'GLuint' | 8666 my_type = 'GLuint' |
8646 else: | 8667 else: |
8647 my_type = self.type | 8668 my_type = self.type |
8648 f.write(" %s %s = static_cast<%s>(c.%s);\n" % | 8669 f.write(" %s %s = static_cast<%s>(c.%s);\n" % |
8649 (my_type, self.name, my_type, self.name)) | 8670 (my_type, self.name, my_type, self.name)) |
8650 | 8671 |
8672 def WriteSetCode(self, f, indent, var): | |
8673 f.write("%s%s = %s;\n" % (' ' * indent, self.name, var)) | |
8674 | |
8675 def WriteArgAccessor(self, f): | |
8676 """Writes specialized accessor for argument.""" | |
8677 pass | |
8678 | |
8651 def WriteValidationCode(self, f, func): | 8679 def WriteValidationCode(self, f, func): |
8652 """Writes the validation code for an argument.""" | 8680 """Writes the validation code for an argument.""" |
8653 pass | 8681 pass |
8654 | 8682 |
8655 def WriteClientSideValidationCode(self, f, func): | 8683 def WriteClientSideValidationCode(self, f, func): |
8656 """Writes the validation code for an argument.""" | 8684 """Writes the validation code for an argument.""" |
8657 pass | 8685 pass |
8658 | 8686 |
8659 def WriteDestinationInitalizationValidation(self, f, func): | 8687 def WriteDestinationInitalizationValidation(self, f, func): |
8660 """Writes the client side destintion initialization validation.""" | 8688 """Writes the client side destintion initialization validation.""" |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8882 """A class that represents a GLenum argument""" | 8910 """A class that represents a GLenum argument""" |
8883 | 8911 |
8884 def __init__(self, name, type): | 8912 def __init__(self, name, type): |
8885 EnumBaseArgument.__init__(self, name, "GLenum", type, "GL_INVALID_ENUM") | 8913 EnumBaseArgument.__init__(self, name, "GLenum", type, "GL_INVALID_ENUM") |
8886 | 8914 |
8887 def GetLogArg(self): | 8915 def GetLogArg(self): |
8888 """Overridden from Argument.""" | 8916 """Overridden from Argument.""" |
8889 return ("GLES2Util::GetString%s(%s)" % | 8917 return ("GLES2Util::GetString%s(%s)" % |
8890 (self.type_name, self.name)) | 8918 (self.type_name, self.name)) |
8891 | 8919 |
8892 | |
8893 class IntArgument(EnumBaseArgument): | 8920 class IntArgument(EnumBaseArgument): |
8894 """A class for a GLint argument that can only accept specific values. | 8921 """A class for a GLint argument that can only accept specific values. |
8895 | 8922 |
8896 For example glTexImage2D takes a GLint for its internalformat | 8923 For example glTexImage2D takes a GLint for its internalformat |
8897 argument instead of a GLenum. | 8924 argument instead of a GLenum. |
8898 """ | 8925 """ |
8899 | 8926 |
8900 def __init__(self, name, type): | 8927 def __init__(self, name, type): |
8901 EnumBaseArgument.__init__(self, name, "GLint", type, "GL_INVALID_VALUE") | 8928 EnumBaseArgument.__init__(self, name, "GLint", type, "GL_INVALID_VALUE") |
8902 | 8929 |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9155 else: | 9182 else: |
9156 type = type.replace(match.group(1), "GLuint") | 9183 type = type.replace(match.group(1), "GLuint") |
9157 Argument.__init__(self, name, type) | 9184 Argument.__init__(self, name, type) |
9158 | 9185 |
9159 def WriteGetCode(self, f): | 9186 def WriteGetCode(self, f): |
9160 """Overridden from Argument.""" | 9187 """Overridden from Argument.""" |
9161 if self.type == "GLsync": | 9188 if self.type == "GLsync": |
9162 my_type = "GLuint" | 9189 my_type = "GLuint" |
9163 else: | 9190 else: |
9164 my_type = self.type | 9191 my_type = self.type |
9165 f.write(" %s %s = c.%s;\n" % (my_type, self.name, self.name)) | 9192 f.write(" %s %s = c.%s;\n" % (my_type, self.name, self.GetArgAccessor())) |
9166 | 9193 |
9167 def GetValidArg(self, func): | 9194 def GetValidArg(self, func): |
9168 return "client_%s_id_" % self.resource_type.lower() | 9195 return "client_%s_id_" % self.resource_type.lower() |
9169 | 9196 |
9170 def GetValidGLArg(self, func): | 9197 def GetValidGLArg(self, func): |
9171 if self.resource_type == "Sync": | 9198 if self.resource_type == "Sync": |
9172 return "reinterpret_cast<GLsync>(kService%sId)" % self.resource_type | 9199 return "reinterpret_cast<GLsync>(kService%sId)" % self.resource_type |
9173 return "kService%sId" % self.resource_type | 9200 return "kService%sId" % self.resource_type |
9174 | 9201 |
9175 | 9202 |
(...skipping 23 matching lines...) Expand all Loading... | |
9199 """Represents a resource id argument to a function that can be zero.""" | 9226 """Represents a resource id argument to a function that can be zero.""" |
9200 | 9227 |
9201 def __init__(self, name, type): | 9228 def __init__(self, name, type): |
9202 match = re.match("(GLidZero\w+)", type) | 9229 match = re.match("(GLidZero\w+)", type) |
9203 self.resource_type = match.group(1)[8:] | 9230 self.resource_type = match.group(1)[8:] |
9204 type = type.replace(match.group(1), "GLuint") | 9231 type = type.replace(match.group(1), "GLuint") |
9205 Argument.__init__(self, name, type) | 9232 Argument.__init__(self, name, type) |
9206 | 9233 |
9207 def WriteGetCode(self, f): | 9234 def WriteGetCode(self, f): |
9208 """Overridden from Argument.""" | 9235 """Overridden from Argument.""" |
9209 f.write(" %s %s = c.%s;\n" % (self.type, self.name, self.name)) | 9236 f.write(" %s %s = c.%s;\n" % (self.type, self.name, self.GetArgAccessor())) |
9210 | 9237 |
9211 def GetValidArg(self, func): | 9238 def GetValidArg(self, func): |
9212 return "client_%s_id_" % self.resource_type.lower() | 9239 return "client_%s_id_" % self.resource_type.lower() |
9213 | 9240 |
9214 def GetValidGLArg(self, func): | 9241 def GetValidGLArg(self, func): |
9215 return "kService%sId" % self.resource_type | 9242 return "kService%sId" % self.resource_type |
9216 | 9243 |
9217 def GetNumInvalidValues(self, func): | 9244 def GetNumInvalidValues(self, func): |
9218 """returns the number of invalid values to be tested.""" | 9245 """returns the number of invalid values to be tested.""" |
9219 return 1 | 9246 return 1 |
9220 | 9247 |
9221 def GetInvalidArg(self, index): | 9248 def GetInvalidArg(self, index): |
9222 """returns an invalid value by index.""" | 9249 """returns an invalid value by index.""" |
9223 return ("kInvalidClientId", "kNoError", "GL_INVALID_VALUE") | 9250 return ("kInvalidClientId", "kNoError", "GL_INVALID_VALUE") |
9224 | 9251 |
9225 | 9252 |
9253 class Int64Argument(Argument): | |
9254 """Represents a GLuint64 argument which splits up into 2 uint32 items.""" | |
9255 | |
9256 def __init__(self, name, type): | |
9257 Argument.__init__(self, name, type) | |
9258 | |
9259 def GetArgAccessor(self): | |
9260 return "%s()" % self.name | |
9261 | |
9262 def WriteArgAccessor(self, f): | |
9263 """Writes specialized accessor for compound members.""" | |
9264 f.write(" %s %s() const {\n" % (self.type, self.name)) | |
9265 f.write(" return static_cast<%s>(\n" % self.type) | |
9266 f.write(" GLES2Util::MapTwoUint32ToUint64(\n") | |
9267 f.write(" %s_0,\n" % self.name) | |
9268 f.write(" %s_1));\n" % self.name) | |
9269 f.write(" }\n") | |
9270 f.write("\n") | |
9271 | |
9272 def WriteGetCode(self, f): | |
9273 """Writes the code to get an argument from a command structure.""" | |
9274 f.write(" %s %s = c.%s();\n" % (self.type, self.name, self.name)) | |
9275 | |
9276 def WriteSetCode(self, f, indent, var): | |
9277 indent_str = ' ' * indent | |
9278 f.write("%sGLES2Util::MapUint64ToTwoUint32(static_cast<uint64_t>(%s),\n" % | |
9279 (indent_str, var)) | |
9280 f.write("%s &%s_0,\n" % | |
9281 (indent_str, self.name)) | |
9282 f.write("%s &%s_1);\n" % | |
9283 (indent_str, self.name)) | |
9284 | |
9226 class Function(object): | 9285 class Function(object): |
9227 """A class that represents a function.""" | 9286 """A class that represents a function.""" |
9228 | 9287 |
9229 type_handlers = { | 9288 type_handlers = { |
9230 '': TypeHandler(), | 9289 '': TypeHandler(), |
9231 'Bind': BindHandler(), | 9290 'Bind': BindHandler(), |
9232 'Create': CreateHandler(), | 9291 'Create': CreateHandler(), |
9233 'Custom': CustomHandler(), | 9292 'Custom': CustomHandler(), |
9234 'Data': DataHandler(), | 9293 'Data': DataHandler(), |
9235 'Delete': DeleteHandler(), | 9294 'Delete': DeleteHandler(), |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9592 f.write(" header.SetCmd<ValueType>();\n") | 9651 f.write(" header.SetCmd<ValueType>();\n") |
9593 f.write(" }\n") | 9652 f.write(" }\n") |
9594 f.write("\n") | 9653 f.write("\n") |
9595 | 9654 |
9596 def WriteCmdInit(self, f): | 9655 def WriteCmdInit(self, f): |
9597 """Writes the cmd's Init function.""" | 9656 """Writes the cmd's Init function.""" |
9598 f.write(" void Init(%s) {\n" % self.MakeTypedCmdArgString("_")) | 9657 f.write(" void Init(%s) {\n" % self.MakeTypedCmdArgString("_")) |
9599 f.write(" SetHeader();\n") | 9658 f.write(" SetHeader();\n") |
9600 args = self.GetCmdArgs() | 9659 args = self.GetCmdArgs() |
9601 for arg in args: | 9660 for arg in args: |
9602 f.write(" %s = _%s;\n" % (arg.name, arg.name)) | 9661 arg.WriteSetCode(f, 4, '_%s' % arg.name) |
9603 f.write(" }\n") | 9662 f.write(" }\n") |
9604 f.write("\n") | 9663 f.write("\n") |
9605 | 9664 |
9606 def WriteCmdSet(self, f): | 9665 def WriteCmdSet(self, f): |
9607 """Writes the cmd's Set function.""" | 9666 """Writes the cmd's Set function.""" |
9608 copy_args = self.MakeCmdArgString("_", False) | 9667 copy_args = self.MakeCmdArgString("_", False) |
9609 f.write(" void* Set(void* cmd%s) {\n" % | 9668 f.write(" void* Set(void* cmd%s) {\n" % |
9610 self.MakeTypedCmdArgString("_", True)) | 9669 self.MakeTypedCmdArgString("_", True)) |
9611 f.write(" static_cast<ValueType*>(cmd)->Init(%s);\n" % copy_args) | 9670 f.write(" static_cast<ValueType*>(cmd)->Init(%s);\n" % copy_args) |
9612 f.write(" return NextCmdAddress<ValueType>(cmd);\n") | 9671 f.write(" return NextCmdAddress<ValueType>(cmd);\n") |
9613 f.write(" }\n") | 9672 f.write(" }\n") |
9614 f.write("\n") | 9673 f.write("\n") |
9615 | 9674 |
9675 def WriteArgAccessors(self, f): | |
9676 """Writes the cmd's accessor functions.""" | |
9677 for arg in self.GetCmdArgs(): | |
9678 arg.WriteArgAccessor(f) | |
9679 | |
9616 def WriteStruct(self, f): | 9680 def WriteStruct(self, f): |
9617 self.type_handler.WriteStruct(self, f) | 9681 self.type_handler.WriteStruct(self, f) |
9618 | 9682 |
9619 def WriteDocs(self, f): | 9683 def WriteDocs(self, f): |
9620 self.type_handler.WriteDocs(self, f) | 9684 self.type_handler.WriteDocs(self, f) |
9621 | 9685 |
9622 def WriteCmdHelper(self, f): | 9686 def WriteCmdHelper(self, f): |
9623 """Writes the cmd's helper.""" | 9687 """Writes the cmd's helper.""" |
9624 self.type_handler.WriteCmdHelper(self, f) | 9688 self.type_handler.WriteCmdHelper(self, f) |
9625 | 9689 |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9879 return BoolArgument(arg_name, arg_type) | 9943 return BoolArgument(arg_name, arg_type) |
9880 elif t.startswith('GLintUniformLocation'): | 9944 elif t.startswith('GLintUniformLocation'): |
9881 return UniformLocationArgument(arg_name) | 9945 return UniformLocationArgument(arg_name) |
9882 elif (t.startswith('GLint') and t != 'GLint' and | 9946 elif (t.startswith('GLint') and t != 'GLint' and |
9883 not t.startswith('GLintptr')): | 9947 not t.startswith('GLintptr')): |
9884 return IntArgument(arg_name, arg_type) | 9948 return IntArgument(arg_name, arg_type) |
9885 elif t == 'GLsizeiNotNegative' or t == 'GLintptrNotNegative': | 9949 elif t == 'GLsizeiNotNegative' or t == 'GLintptrNotNegative': |
9886 return SizeNotNegativeArgument(arg_name, t.replace('NotNegative', '')) | 9950 return SizeNotNegativeArgument(arg_name, t.replace('NotNegative', '')) |
9887 elif t.startswith('GLsize'): | 9951 elif t.startswith('GLsize'): |
9888 return SizeArgument(arg_name, arg_type) | 9952 return SizeArgument(arg_name, arg_type) |
9953 elif t == 'GLuint64' or t == 'GLint64': | |
9954 return Int64Argument(arg_name, arg_type) | |
9889 else: | 9955 else: |
9890 return Argument(arg_name, arg_type) | 9956 return Argument(arg_name, arg_type) |
9891 | 9957 |
9892 | 9958 |
9893 class GLGenerator(object): | 9959 class GLGenerator(object): |
9894 """A class to generate GL command buffers.""" | 9960 """A class to generate GL command buffers.""" |
9895 | 9961 |
9896 _function_re = re.compile(r'GL_APICALL(.*?)GL_APIENTRY (.*?) \((.*?)\);') | 9962 _function_re = re.compile(r'GL_APICALL(.*?)GL_APIENTRY (.*?) \((.*?)\);') |
9897 | 9963 |
9898 def __init__(self, verbose): | 9964 def __init__(self, verbose): |
(...skipping 1355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
11254 Format(gen.generated_cpp_filenames) | 11320 Format(gen.generated_cpp_filenames) |
11255 | 11321 |
11256 if gen.errors > 0: | 11322 if gen.errors > 0: |
11257 print "%d errors" % gen.errors | 11323 print "%d errors" % gen.errors |
11258 return 1 | 11324 return 1 |
11259 return 0 | 11325 return 0 |
11260 | 11326 |
11261 | 11327 |
11262 if __name__ == '__main__': | 11328 if __name__ == '__main__': |
11263 sys.exit(main(sys.argv[1:])) | 11329 sys.exit(main(sys.argv[1:])) |
OLD | NEW |