<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Sep 15, 2017 at 7:10 AM, Lionel Landwerlin <span dir="ltr"><<a href="mailto:lionel.g.landwerlin@intel.com" target="_blank">lionel.g.landwerlin@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">New extensions can introduce additional enums. Most of the new enums<br>
will have disjoint numbers from the initial enums. For example new<br>
formats introduced by VK_IMG_format_pvrtc :<br>
<br>
VK_FORMAT_ASTC_10x8_UNORM_<wbr>BLOCK = 177,<br>
VK_FORMAT_ASTC_10x8_SRGB_BLOCK = 178,<br>
VK_FORMAT_ASTC_10x10_UNORM_<wbr>BLOCK = 179,<br>
VK_FORMAT_ASTC_10x10_SRGB_<wbr>BLOCK = 180,<br>
VK_FORMAT_ASTC_12x10_UNORM_<wbr>BLOCK = 181,<br>
VK_FORMAT_ASTC_12x10_SRGB_<wbr>BLOCK = 182,<br>
VK_FORMAT_ASTC_12x12_UNORM_<wbr>BLOCK = 183,<br>
VK_FORMAT_ASTC_12x12_SRGB_<wbr>BLOCK = 184,<br>
VK_FORMAT_PVRTC1_2BPP_UNORM_<wbr>BLOCK_IMG = 1000054000,<br>
VK_FORMAT_PVRTC1_4BPP_UNORM_<wbr>BLOCK_IMG = 1000054001,<br>
VK_FORMAT_PVRTC2_2BPP_UNORM_<wbr>BLOCK_IMG = 1000054002,<br>
VK_FORMAT_PVRTC2_4BPP_UNORM_<wbr>BLOCK_IMG = 1000054003,<br>
VK_FORMAT_PVRTC1_2BPP_SRGB_<wbr>BLOCK_IMG = 1000054004,<br>
VK_FORMAT_PVRTC1_4BPP_SRGB_<wbr>BLOCK_IMG = 1000054005,<br>
VK_FORMAT_PVRTC2_2BPP_SRGB_<wbr>BLOCK_IMG = 1000054006,<br>
VK_FORMAT_PVRTC2_4BPP_SRGB_<wbr>BLOCK_IMG = 1000054007,<br>
<br>
It's obvious we can't have a single table for handling those anymore.<br>
<br>
Fortunately the enum values actually contain the number of the<br>
extension that introduced the new enums. So we can build an<br>
indirection table off the extension number and then index by<br>
subtracting the first enum of the the format enum value.<br>
<br>
This change makes the extension number available in the generated enum<br>
code.<br>
<br>
Signed-off-by: Lionel Landwerlin <<a href="mailto:lionel.g.landwerlin@intel.com">lionel.g.landwerlin@intel.com</a><wbr>><br>
---<br>
 src/vulkan/util/gen_enum_to_<wbr>str.py | 23 +++++++++++++++++++++--<br>
 1 file changed, 21 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/src/vulkan/util/gen_enum_to_<wbr>str.py b/src/vulkan/util/gen_enum_to_<wbr>str.py<br>
index 28bfbfde235..06d625d9ac8 100644<br>
--- a/src/vulkan/util/gen_enum_to_<wbr>str.py<br>
+++ b/src/vulkan/util/gen_enum_to_<wbr>str.py<br>
@@ -91,6 +91,10 @@ H_TEMPLATE = Template(textwrap.dedent(u"""\<br>
<br>
     #include <vulkan/vulkan.h><br>
<br>
+    % for ext in extensions:<br>
+    #define _${<a href="http://ext.name" rel="noreferrer" target="_blank">ext.name</a>}_number (${ext.number})<br></blockquote><div><br></div><div>I was about to say that this is already in the Vulkan headers but then I looked and it isn't. :-(<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+    % endfor<br>
+<br>
     % for enum in enums:<br>
     const char * vk_${<a href="http://enum.name" rel="noreferrer" target="_blank">enum.name</a>[2:]}_to_str(${<a href="http://enum.name" rel="noreferrer" target="_blank">e<wbr>num.name</a>} input);<br>
     % endfor<br>
@@ -113,6 +117,14 @@ class NamedFactory(object):<br>
         return n<br>
<br>
<br>
+class VkExtension(object):<br>
+    """Simple struct-like class representing extensions"""<br>
+<br>
+    def __init__(self, name, number):<br>
+        <a href="http://self.name" rel="noreferrer" target="_blank">self.name</a> = name<br>
+        self.number = number<br>
+<br>
+<br>
 class VkEnum(object):<br>
     """Simple struct-like class representing a single Vulkan Enum."""<br>
<br>
@@ -121,6 +133,7 @@ class VkEnum(object):<br>
         self.values = values or []<br>
<br>
<br>
+<br></blockquote><div><br></div><div>Extra newline.  Other than, LGTM<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
 def xml_parser(filename):<br>
     """Parse the XML file and return parsed data.<br>
<br>
@@ -128,6 +141,7 @@ def xml_parser(filename):<br>
     of VkEnum objects.<br>
     """<br>
     enum_factory = NamedFactory(VkEnum)<br>
+    ext_factory = NamedFactory(VkExtension)<br>
<br>
     with open(filename, 'rb') as f:<br>
         context = iter(et.iterparse(f, events=('start', 'end')))<br>
@@ -144,6 +158,8 @@ def xml_parser(filename):<br>
                     enum = enum_factory(elem.attrib['<wbr>name'])<br>
                     enum.values.extend([e.attrib['<wbr>name'] for e in elem<br>
                                         if e.tag == 'enum'])<br>
+            elif event == 'start' and elem.tag == 'extension':<br>
+                ext_factory(elem.attrib['name'<wbr>], int(elem.attrib['number']))<br>
             elif event == 'end' and elem.tag == 'extension':<br>
                 if elem.attrib['supported'] != 'vulkan':<br>
                     continue<br>
@@ -153,7 +169,8 @@ def xml_parser(filename):<br>
<br>
             root.clear()<br>
<br>
-    return enum_factory.registry.values()<br>
+    return (enum_factory.registry.values(<wbr>),<br>
+            ext_factory.registry.values())<br>
<br>
<br>
 def main():<br>
@@ -165,14 +182,16 @@ def main():<br>
<br>
     args = parser.parse_args()<br>
<br>
-    enums = xml_parser(args.xml)<br>
+    enums, extensions = xml_parser(args.xml)<br>
     enums.sort(key=lambda e: <a href="http://e.name" rel="noreferrer" target="_blank">e.name</a>)<br>
+    extensions.sort(key=lambda e: e.number)<br>
     for template, file_ in [(C_TEMPLATE, os.path.join(args.outdir, 'vk_enum_to_str.c')),<br>
                             (H_TEMPLATE, os.path.join(args.outdir, 'vk_enum_to_str.h'))]:<br>
         with open(file_, 'wb') as f:<br>
             f.write(template.render(<br>
                 file=os.path.basename(__file__<wbr>),<br>
                 enums=enums,<br>
+                extensions=extensions,<br>
                 copyright=COPYRIGHT))<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
--<br>
2.14.1<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>