scripts: Add ceiling function to vk_struct_size_helper
authormizhen <ming.zheng@amd.com>
Fri, 31 Mar 2017 15:08:16 +0000 (09:08 -0600)
committerardaLunarG <arda@lunarg.com>
Mon, 3 Apr 2017 17:20:51 +0000 (11:20 -0600)
Change-Id: Ia377c52e43442fec17b823c888df6685eff0aca5

scripts/helper_file_generator.py

index 2e7c7b2..0d35b83 100644 (file)
@@ -209,7 +209,15 @@ class HelperFileOutputGenerator(OutputGenerator):
             if not match or match.group(1) != match.group(4):
                 raise 'Unrecognized latexmath expression'
             name = match.group(2)
-            decoratedName = '{}/{}'.format(*match.group(2, 3))
+            # Need to add 1 for ceiling function; otherwise, the allocated packet
+            # size will be less than needed during capture for some title which use
+            # this in VkPipelineMultisampleStateCreateInfo. based on ceiling function
+            # definition,it is '{0}%{1}?{0}/{1} + 1:{0}/{1}'.format(*match.group(2, 3)),
+            # its value <= '{}/{} + 1'.
+            if match.group(1) == 'ceil':
+                decoratedName = '{}/{} + 1'.format(*match.group(2, 3))
+            else:
+                decoratedName = '{}/{}'.format(*match.group(2, 3))
         else:
             # Matches expressions similar to 'latexmath : [dataSize \over 4]'
             match = re.match(r'latexmath\s*\:\s*\[\s*(\w+)\s*\\over\s*(\d+)\s*\]', source)
@@ -437,7 +445,7 @@ class HelperFileOutputGenerator(OutputGenerator):
                                 checked_type = member.type
                                 if checked_type == 'void':
                                     checked_type = 'void*'
-                                struct_size_body += '        struct_size += struct_ptr->%s * sizeof(%s);\n' % (member.len, checked_type)
+                                struct_size_body += '        struct_size += (struct_ptr->%s ) * sizeof(%s);\n' % (member.len, checked_type)
             struct_size_body += '    }\n'
             struct_size_body += '    return struct_size;\n'
             struct_size_body += '}\n'