scripts: Use altlen instead of parsing latexmath
authorMike Schuchardt <mikes@lunarg.com>
Tue, 10 Aug 2021 19:43:16 +0000 (12:43 -0700)
committerMike Schuchardt <mikes@lunarg.com>
Tue, 10 Aug 2021 22:35:45 +0000 (15:35 -0700)
KhronosGroup/Vulkan-ValidationLayers switched to this method a while ago
and this syncs the KhronosGroup/Vulkan-Tools version of
helper_file_generator.py to match.

scripts/vulkan_tools_helper_file_generator.py

index 0217027..1b24a5e 100644 (file)
@@ -263,32 +263,6 @@ class HelperFileOutputGenerator(OutputGenerator):
             elif elem.tag == 'name':
                 name = noneStr(elem.text)
         return (type, name)
-    # Extract length values from latexmath.  Currently an inflexible solution that looks for specific
-    # patterns that are found in vk.xml.  Will need to be updated when new patterns are introduced.
-    def parseLateXMath(self, source):
-        name = 'ERROR'
-        decoratedName = 'ERROR'
-        if 'mathit' in source:
-            # Matches expressions similar to 'latexmath:[\lceil{\mathit{rasterizationSamples} \over 32}\rceil]'
-            match = re.match(r'latexmath\s*\:\s*\[\s*\\l(\w+)\s*\{\s*\\mathit\s*\{\s*(\w+)\s*\}\s*\\over\s*(\d+)\s*\}\s*\\r(\w+)\s*\]', source)
-            if not match or match.group(1) != match.group(4):
-                raise 'Unrecognized latexmath expression'
-            name = match.group(2)
-            # 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*(\\textrm\{)?(\w+)\}?\s*\\over\s*(\d+)\s*\]', source)
-            name = match.group(2)
-            decoratedName = '{}/{}'.format(*match.group(2, 3))
-        return name, decoratedName
     #
     # Retrieve the value of the len tag
     def getLen(self, param):
@@ -302,9 +276,10 @@ class HelperFileOutputGenerator(OutputGenerator):
                 result = len.split(',')[0]
             else:
                 result = len
-            if 'latexmath' in len:
-                param_type, param_name = self.getTypeNameTuple(param)
-                len_name, result = self.parseLateXMath(len)
+            if 'altlen' in param.attrib:
+                # Elements with latexmath 'len' also contain a C equivalent 'altlen' attribute
+                # Use indexing operator instead of get() so we fail if the attribute is missing
+                result = param.attrib['altlen']
             # Spec has now notation for len attributes, using :: instead of platform specific pointer symbol
             result = str(result).replace('::', '->')
         return result