<div dir="ltr">Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 17, 2017 at 12:31 PM, Ian Romanick <span dir="ltr"><<a href="mailto:idr@freedesktop.org" target="_blank">idr@freedesktop.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">From: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
<br>
The old table based spirv_*_to_string functions would return NULL for<br>
any values "inside" the table that didn't have entries.  The tables also<br>
needed to be updated by hand each time a new spirv.h was imported.<br>
Generate the file instead.<br>
<br>
</span>v2: Make this script work more like src/mesa/main/format_fallback.<wbr>py.<br>
Suggested by Jason.  Remove SCons supports.  Suggested by Jason and<br>
Emil.  Put all the build work in <a href="http://Makefile.nir.am" rel="noreferrer" target="_blank">Makefile.nir.am</a> in lieu of adding a new<br>
<a href="http://Makefile.spirv.am" rel="noreferrer" target="_blank">Makefile.spirv.am</a>.  Suggested by Emil.  Add support for Android builds<br>
based on code provided by Emil.<br>
<span class=""><br>
Signed-off-by: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
Suggested-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br>
---<br>
</span> src/compiler/<a href="http://Android.nir.gen.mk" rel="noreferrer" target="_blank">Android.nir.gen.<wbr>mk</a>    |   7 ++<br>
 src/compiler/<a href="http://Makefile.nir.am" rel="noreferrer" target="_blank">Makefile.nir.am</a>       |  16 +++-<br>
 src/compiler/Makefile.sources      |   4 +-<br>
 src/compiler/spirv/spirv_info.<wbr>c    | 156 ------------------------------<wbr>-------<br>
 src/compiler/spirv/spirv_info_<wbr>c.py |  82 +++++++++++++++++++<br>
 5 files changed, 106 insertions(+), 159 deletions(-)<br>
<span class=""> delete mode 100644 src/compiler/spirv/spirv_info.<wbr>c<br>
 create mode 100644 src/compiler/spirv/spirv_info_<wbr>c.py<br>
<br>
</span>diff --git a/src/compiler/<a href="http://Android.nir.gen.mk" rel="noreferrer" target="_blank">Android.nir.<wbr>gen.mk</a> b/src/compiler/<a href="http://Android.nir.gen.mk" rel="noreferrer" target="_blank">Android.nir.<wbr>gen.mk</a><br>
index 908875d..4507ac4 100644<br>
--- a/src/compiler/<a href="http://Android.nir.gen.mk" rel="noreferrer" target="_blank">Android.nir.<wbr>gen.mk</a><br>
+++ b/src/compiler/<a href="http://Android.nir.gen.mk" rel="noreferrer" target="_blank">Android.nir.<wbr>gen.mk</a><br>
@@ -94,3 +94,10 @@ nir_opt_algebraic_deps := \<br>
 $(intermediates)/nir/nir_opt_<wbr>algebraic.c: $(nir_opt_algebraic_deps)<br>
        @mkdir -p $(dir $@)<br>
        $(hide) $(MESA_PYTHON2) $(nir_opt_algebraic_gen) $< > $@<br>
+<br>
+LOCAL_GENERATED_SOURCES += $(addprefix $(intermediates)/, \<br>
+       $(SPIRV_GENERATED_FILES))<br>
+<br>
+$(intermediates)/spirv/spirv_<wbr>info.c: $(LOCAL_PATH)/spirv/spirv_<wbr>info_c.py $(LOCAL_PATH)/spirv/spirv.<wbr>core.grammar.json<br>
+       @mkdir -p $(dir $@)<br>
+       $(hide) $(MESA_PYTHON2) $(LOCAL_PATH)/spirv/spirv_<wbr>info_c.py $(LOCAL_PATH)/spirv/spirv.<wbr>core.grammar.json $@ || ($(RM) $@; false)<br>
diff --git a/src/compiler/<a href="http://Makefile.nir.am" rel="noreferrer" target="_blank">Makefile.nir.am</a> b/src/compiler/<a href="http://Makefile.nir.am" rel="noreferrer" target="_blank">Makefile.nir.am</a><br>
index 13f02a7..1533ee5 100644<br>
<span class="">--- a/src/compiler/<a href="http://Makefile.nir.am" rel="noreferrer" target="_blank">Makefile.nir.am</a><br>
+++ b/src/compiler/<a href="http://Makefile.nir.am" rel="noreferrer" target="_blank">Makefile.nir.am</a><br>
@@ -29,6 +29,7 @@ nir_libnir_la_LIBADD = \<br>
 nir_libnir_la_SOURCES =                                        \<br>
        $(NIR_FILES)                                    \<br>
        $(SPIRV_FILES)                                  \<br>
+       $(SPIRV_GENERATED_FILES)                        \<br>
        $(NIR_GENERATED_FILES)<br>
<br>
 nir/nir_builder_opcodes.h: nir/nir_opcodes.py nir/nir_builder_opcodes_h.py<br>
</span>@@ -51,6 +52,10 @@ nir/nir_opt_algebraic.c: nir/nir_opt_algebraic.py nir/nir_algebraic.py<br>
        $(MKDIR_GEN)<br>
        $(PYTHON_GEN) $(srcdir)/nir/nir_opt_<wbr>algebraic.py > $@ || ($(RM) $@; false)<br>
<span class=""><br>
+spirv/spirv_info.c: spirv/spirv_info_c.py spirv/spirv.core.grammar.json<br>
+       $(MKDIR_GEN)<br>
</span>+       $(PYTHON_GEN) $(srcdir)/spirv/spirv_info_c.<wbr>py $(srcdir)/spirv/spirv.core.<wbr>grammar.json $@ || ($(RM) $@; false)<br>
+<br>
 noinst_PROGRAMS += spirv2nir<br>
<br>
 spirv2nir_SOURCES = \<br>
@@ -91,8 +96,13 @@ nir_tests_control_flow_tests_<wbr>LDADD =                 \<br>
 TESTS += nir/tests/control_flow_tests<br>
<br>
<br>
-BUILT_SOURCES += $(NIR_GENERATED_FILES)<br>
-CLEANFILES += $(NIR_GENERATED_FILES)<br>
+BUILT_SOURCES += \<br>
+       $(NIR_GENERATED_FILES) \<br>
+       $(SPIRV_GENERATED_FILES)<br>
+<br>
+CLEANFILES += \<br>
+       $(NIR_GENERATED_FILES) \<br>
+       $(SPIRV_GENERATED_FILES)<br>
<br>
 EXTRA_DIST += \<br>
        nir/nir_algebraic.py                            \<br>
@@ -104,4 +114,6 @@ EXTRA_DIST += \<br>
        nir/nir_opt_algebraic.py                        \<br>
        nir/tests \<br>
        nir/README \<br>
+       spirv/spirv_info_c.py                           \<br>
+       spirv/spirv.core.grammar.json                   \<br>
        SConscript.nir<br>
<span class="">diff --git a/src/compiler/Makefile.<wbr>sources b/src/compiler/Makefile.<wbr>sources<br>
index d3447fb..785782b 100644<br>
--- a/src/compiler/Makefile.<wbr>sources<br>
+++ b/src/compiler/Makefile.<wbr>sources<br>
@@ -277,12 +277,14 @@ NIR_FILES = \<br>
        nir/nir_worklist.c \<br>
        nir/nir_worklist.h<br>
<br>
+SPIRV_GENERATED_FILES = \<br>
+       spirv/spirv_info.c<br>
+<br>
 SPIRV_FILES = \<br>
        spirv/GLSL.std.450.h \<br>
        spirv/nir_spirv.h \<br>
        spirv/spirv.h \<br>
        spirv/spirv_info.h \<br>
-       spirv/spirv_info.c \<br>
        spirv/spirv_to_nir.c \<br>
        spirv/vtn_alu.c \<br>
        spirv/vtn_cfg.c \<br>
</span><div><div class="h5">diff --git a/src/compiler/spirv/spirv_<wbr>info.c b/src/compiler/spirv/spirv_<wbr>info.c<br>
deleted file mode 100644<br>
index 1036b41..0000000<br>
--- a/src/compiler/spirv/spirv_<wbr>info.c<br>
+++ /dev/null<br>
@@ -1,156 +0,0 @@<br>
-/*<br>
- * Copyright © 2016 Intel Corporation<br>
- *<br>
- * Permission is hereby granted, free of charge, to any person obtaining a<br>
- * copy of this software and associated documentation files (the "Software"),<br>
- * to deal in the Software without restriction, including without limitation<br>
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
- * and/or sell copies of the Software, and to permit persons to whom the<br>
- * Software is furnished to do so, subject to the following conditions:<br>
- *<br>
- * The above copyright notice and this permission notice (including the next<br>
- * paragraph) shall be included in all copies or substantial portions of the<br>
- * Software.<br>
- *<br>
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL<br>
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
- * IN THE SOFTWARE.<br>
- */<br>
-<br>
-#include "spirv_info.h"<br>
-#include "util/macros.h"<br>
-<br>
-#define CAPABILITY(cap) [SpvCapability##cap] = #cap<br>
-static const char * const capability_to_string[] = {<br>
-   CAPABILITY(Matrix),<br>
-   CAPABILITY(Shader),<br>
-   CAPABILITY(Geometry),<br>
-   CAPABILITY(Tessellation),<br>
-   CAPABILITY(Addresses),<br>
-   CAPABILITY(Linkage),<br>
-   CAPABILITY(Kernel),<br>
-   CAPABILITY(Vector16),<br>
-   CAPABILITY(Float16Buffer),<br>
-   CAPABILITY(Float16),<br>
-   CAPABILITY(Float64),<br>
-   CAPABILITY(Int64),<br>
-   CAPABILITY(Int64Atomics),<br>
-   CAPABILITY(ImageBasic),<br>
-   CAPABILITY(ImageReadWrite),<br>
-   CAPABILITY(ImageMipmap),<br>
-   CAPABILITY(Pipes),<br>
-   CAPABILITY(Groups),<br>
-   CAPABILITY(DeviceEnqueue),<br>
-   CAPABILITY(LiteralSampler),<br>
-   CAPABILITY(AtomicStorage),<br>
-   CAPABILITY(Int16),<br>
-   CAPABILITY(<wbr>TessellationPointSize),<br>
-   CAPABILITY(GeometryPointSize),<br>
-   CAPABILITY(<wbr>ImageGatherExtended),<br>
-   CAPABILITY(<wbr>StorageImageMultisample),<br>
-   CAPABILITY(<wbr>UniformBufferArrayDynamicIndex<wbr>ing),<br>
-   CAPABILITY(<wbr>SampledImageArrayDynamicIndexi<wbr>ng),<br>
-   CAPABILITY(<wbr>StorageBufferArrayDynamicIndex<wbr>ing),<br>
-   CAPABILITY(<wbr>StorageImageArrayDynamicIndexi<wbr>ng),<br>
-   CAPABILITY(ClipDistance),<br>
-   CAPABILITY(CullDistance),<br>
-   CAPABILITY(ImageCubeArray),<br>
-   CAPABILITY(SampleRateShading),<br>
-   CAPABILITY(ImageRect),<br>
-   CAPABILITY(SampledRect),<br>
-   CAPABILITY(GenericPointer),<br>
-   CAPABILITY(Int8),<br>
-   CAPABILITY(InputAttachment),<br>
-   CAPABILITY(SparseResidency),<br>
-   CAPABILITY(MinLod),<br>
-   CAPABILITY(Sampled1D),<br>
-   CAPABILITY(Image1D),<br>
-   CAPABILITY(SampledCubeArray),<br>
-   CAPABILITY(SampledBuffer),<br>
-   CAPABILITY(ImageBuffer),<br>
-   CAPABILITY(ImageMSArray),<br>
-   CAPABILITY(<wbr>StorageImageExtendedFormats),<br>
-   CAPABILITY(ImageQuery),<br>
-   CAPABILITY(DerivativeControl),<br>
-   CAPABILITY(<wbr>InterpolationFunction),<br>
-   CAPABILITY(TransformFeedback),<br>
-   CAPABILITY(GeometryStreams),<br>
-   CAPABILITY(<wbr>StorageImageReadWithoutFormat)<wbr>,<br>
-   CAPABILITY(<wbr>StorageImageWriteWithoutFormat<wbr>),<br>
-   CAPABILITY(MultiViewport),<br>
-   CAPABILITY(SubgroupDispatch),<br>
-   CAPABILITY(NamedBarrier),<br>
-   CAPABILITY(PipeStorage),<br>
-   CAPABILITY(SubgroupBallotKHR),<br>
-   CAPABILITY(DrawParameters),<br>
-};<br>
-<br>
-const char *<br>
-spirv_capability_to_string(<wbr>SpvCapability cap)<br>
-{<br>
-   if (cap < ARRAY_SIZE(capability_to_<wbr>string))<br>
-      return capability_to_string[cap];<br>
-   else<br>
-      return "unknown";<br>
-}<br>
-<br>
-#define DECORATION(dec) [SpvDecoration##dec] = #dec<br>
-static const char * const decoration_to_string[] = {<br>
-   DECORATION(RelaxedPrecision),<br>
-   DECORATION(SpecId),<br>
-   DECORATION(Block),<br>
-   DECORATION(BufferBlock),<br>
-   DECORATION(RowMajor),<br>
-   DECORATION(ColMajor),<br>
-   DECORATION(ArrayStride),<br>
-   DECORATION(MatrixStride),<br>
-   DECORATION(GLSLShared),<br>
-   DECORATION(GLSLPacked),<br>
-   DECORATION(CPacked),<br>
-   DECORATION(BuiltIn),<br>
-   DECORATION(NoPerspective),<br>
-   DECORATION(Flat),<br>
-   DECORATION(Patch),<br>
-   DECORATION(Centroid),<br>
-   DECORATION(Sample),<br>
-   DECORATION(Invariant),<br>
-   DECORATION(Restrict),<br>
-   DECORATION(Aliased),<br>
-   DECORATION(Volatile),<br>
-   DECORATION(Constant),<br>
-   DECORATION(Coherent),<br>
-   DECORATION(NonWritable),<br>
-   DECORATION(NonReadable),<br>
-   DECORATION(Uniform),<br>
-   DECORATION(<wbr>SaturatedConversion),<br>
-   DECORATION(Stream),<br>
-   DECORATION(Location),<br>
-   DECORATION(Component),<br>
-   DECORATION(Index),<br>
-   DECORATION(Binding),<br>
-   DECORATION(DescriptorSet),<br>
-   DECORATION(Offset),<br>
-   DECORATION(XfbBuffer),<br>
-   DECORATION(XfbStride),<br>
-   DECORATION(FuncParamAttr),<br>
-   DECORATION(FPRoundingMode),<br>
-   DECORATION(FPFastMathMode),<br>
-   DECORATION(LinkageAttributes),<br>
-   DECORATION(NoContraction),<br>
-   DECORATION(<wbr>InputAttachmentIndex),<br>
-   DECORATION(Alignment),<br>
-   DECORATION(MaxByteOffset),<br>
-};<br>
-<br>
-const char *<br>
-spirv_decoration_to_string(<wbr>SpvDecoration dec)<br>
-{<br>
-   if (dec < ARRAY_SIZE(decoration_to_<wbr>string))<br>
-      return decoration_to_string[dec];<br>
-   else<br>
-      return "unknown";<br>
-}<br>
diff --git a/src/compiler/spirv/spirv_<wbr>info_c.py b/src/compiler/spirv/spirv_<wbr>info_c.py<br>
new file mode 100644<br>
</div></div>index 0000000..c5e11df<br>
--- /dev/null<br>
+++ b/src/compiler/spirv/spirv_<wbr>info_c.py<br>
@@ -0,0 +1,82 @@<br>
+COPYRIGHT = """\<br>
+/*<br>
<span class="">+ * Copyright (C) 2017 Intel Corporation<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial portions of the<br>
+ * Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>
+ * DEALINGS IN THE SOFTWARE.<br>
+ */<br>
+"""<br>
+<br>
</span>+import argparse<br>
+import json<br>
+from sys import stdout<br>
+from mako.template import Template<br>
<span class="">+<br>
+def collect_data(spirv, kind):<br>
+    for x in spirv["operand_kinds"]:<br>
+        if x["kind"] == kind:<br>
+            operands = x<br>
</span>+            break<br>
<span class="">+<br>
+    # There are some duplicate values in some of the tables (thanks guys!), so<br>
+    # filter them out.<br>
+    last_value = -1<br>
+    values = []<br>
+    for x in operands["enumerants"]:<br>
+        if x["value"] != last_value:<br>
+            last_value = x["value"]<br>
+            values.append(x["enumerant"])<br>
+<br>
+    return (kind, values)<br>
+<br>
</span>+def parse_args():<br>
+    p = argparse.ArgumentParser()<br>
+    p.add_argument("json")<br>
+    p.add_argument("out")<br>
+    return p.parse_args()<br>
+<br>
+TEMPLATE  = Template(COPYRIGHT + """\<br>
+#include "spirv_info.h"<br>
+% for kind,values in info:<br>
<span class="">+<br>
+const char *<br>
+spirv_${kind.lower()}_to_<wbr>string(Spv${kind} v)<br>
+{<br>
+   switch (v) {<br>
+    % for name in values:<br>
+   case Spv${kind}${name}: return "Spv${kind}${name}";<br>
+    % endfor<br>
+   case Spv${kind}Max: break; /* silence warnings about unhandled enums. */<br>
+   }<br>
+<br>
+   return "unknown";<br>
+}<br>
+% endfor<br>
+""")<br>
</span><span class="">+<br>
+if __name__ == "__main__":<br>
</span>+    pargs = parse_args()<br>
+<br>
+    spirv_info = json.JSONDecoder().decode(<wbr>open(pargs.json, "r").read())<br>
<span class="">+<br>
+    capabilities = collect_data(spirv_info, "Capability")<br>
+    decorations = collect_data(spirv_info, "Decoration")<br>
+<br>
</span>+    with open(pargs.out, 'w') as f:<br>
+        f.write(TEMPLATE.render(info=[<wbr>capabilities, decorations]))<br>
<div class="HOEnZb"><div class="h5">--<br>
2.9.4<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>
</div></div></blockquote></div><br></div>