<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Mar 14, 2017 at 4:04 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">It seems new extensions will start to use aliases in enums, meaning<br>
multiple enums with the same value. This forces us to track the values<br>
of the enums to generate correct C code.<br></blockquote><div><br></div><div>Seriously?  That seems a bit sketchy.  Or is this for promoted extensions?<br><br></div><div>The patch looks correct assuming this is something we actually want.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Signed-off-by: Lionel Landwerlin <<a href="mailto:lionel.g.landwerlin@intel.com">lionel.g.landwerlin@intel.com</a><wbr>><br>
Cc: Dylan Baker <<a href="mailto:dylan@pnwbakers.com">dylan@pnwbakers.com</a>><br>
---<br>
 src/vulkan/util/gen_enum_to_<wbr>str.py | 49 ++++++++++++++++++++++++++++++<wbr>--------<br>
 1 file changed, 39 insertions(+), 10 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 fb31addf94..1ffe4e362b 100644<br>
--- a/src/vulkan/util/gen_enum_to_<wbr>str.py<br>
+++ b/src/vulkan/util/gen_enum_to_<wbr>str.py<br>
@@ -24,6 +24,7 @@<br>
 from __future__ import print_function<br>
 import argparse<br>
 import os<br>
+import re<br>
 import textwrap<br>
 import xml.etree.cElementTree as et<br>
<br>
@@ -67,9 +68,9 @@ C_TEMPLATE = Template(textwrap.dedent(u"""\<br>
         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>
         {<br>
             switch(input) {<br>
-            % for v in enum.values:<br>
-                case ${v}:<br>
-                    return "${v}";<br>
+            % for k, v in enum.values.iteritems():<br>
+                case ${v[0]}:<br>
+                    return "${' / '.join(v)}";<br>
             % endfor<br>
             default:<br>
                 unreachable("Undefined enum value.");<br>
@@ -116,10 +117,17 @@ class EnumFactory(object):<br>
 class VkEnum(object):<br>
     """Simple struct-like class representing a single Vulkan Enum."""<br>
<br>
-    def __init__(self, name, values=None):<br>
+    def __init__(self, name):<br>
         <a href="http://self.name" rel="noreferrer" target="_blank">self.name</a> = name<br>
-        self.values = values or []<br>
+        self.values = {}<br>
+        self.names = {}<br>
<br>
+    def add_item(self, name, value):<br>
+        if value in self.values:<br>
+            self.values[value].append(<wbr>name)<br>
+        else:<br>
+            self.values[value] = [name]<br>
+        self.names[name] = value<br>
<br>
 def xml_parser(filename):<br>
     """Parse the XML file and return parsed data.<br>
@@ -129,6 +137,24 @@ def xml_parser(filename):<br>
     """<br>
     efactory = EnumFactory(VkEnum)<br>
<br>
+    number_regexp = re.compile('^-?[0-9]+$')<br>
+<br>
+    def compute_enum_value(enum, elem, parent):<br>
+        if 'offset' in elem.attrib:<br>
+            # Formula taken from the src/spec/generator.py<br>
+            # <a href="https://github.com/khronosGroup/Vulkan-Docs" rel="noreferrer" target="_blank">https://github.com/<wbr>khronosGroup/Vulkan-Docs</a><br>
+            value = 1000000000 + (int(parent.attrib['number']) - 1) * 1000<br>
+            value += int(elem.attrib['offset'])<br>
+            if 'dir' in e.attrib:<br>
+                value = -value<br>
+        else:<br>
+            number = elem.attrib['value']<br>
+            if re.match(number_regexp, number):<br>
+                value = int(number)<br>
+            else:<br>
+                value = enum.names[number]<br>
+        return value<br>
+<br>
     with open(filename, 'rb') as f:<br>
         context = iter(et.iterparse(f, events=('start', 'end')))<br>
<br>
@@ -140,16 +166,19 @@ def xml_parser(filename):<br>
         for event, elem in context:<br>
             if event == 'end' and elem.tag == 'enums':<br>
                 type_ = elem.attrib.get('type')<br>
-                if type_ == 'enum':<br>
-                    enum = efactory(elem.attrib['name'])<br>
-                    enum.values.extend([e.attrib['<wbr>name'] for e in elem<br>
-                                        if e.tag == 'enum'])<br>
+                if type_ != 'enum':<br>
+                    continue<br>
+                enum = efactory(elem.attrib['name'])<br>
+                for e in elem:<br>
+                    if e.tag != 'enum':<br>
+                        continue<br>
+                    enum.add_item(e.attrib['name']<wbr>, compute_enum_value(enum, e, None))<br>
             elif event == 'end' and elem.tag == 'extension':<br>
                 if elem.attrib['supported'] != 'vulkan':<br>
                     continue<br>
                 for e in elem.findall('.//enum[@<wbr>extends][@offset]'):<br>
                     enum = efactory(e.attrib['extends'])<br>
-                    enum.values.append(e.attrib['<wbr>name'])<br>
+                    enum.add_item(e.attrib['name']<wbr>, compute_enum_value(enum, e, elem))<br>
<br>
             root.clear()<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
2.11.0<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>