[Mesa-dev] [v4 PATCH 4/6] spirv_extensions: define spirv_extensions_supported

Alejandro PiƱeiro apinheiro at igalia.com
Thu Mar 8 15:00:17 UTC 2018


Add a struct to maintain which SPIR-V extensions are supported, and an
utility method to initialize it based on
nir_spirv_supported_capabilities.

v2:
  * Fixing code style (Ian Romanick)
  * Adding a prefix (spirv) to fill_supported_spirv_extensions (Ian Romanick)

v3: rebase update (nir_spirv_supported_extensions renamed)

v4: include AMD_gcn_shader
---

Note that in the end this struct is basically a cache of the supported
extensions. As we are filling it using the capabilities, we could
compute them each time the strings are requested. And as we don't have
too many extensions right now, it would not be really expensive. I
just think that sounds better this way.

 src/compiler/spirv/spirv_extensions.c | 33 +++++++++++++++++++++++++++++++++
 src/compiler/spirv/spirv_extensions.h | 13 +++++++++++++
 2 files changed, 46 insertions(+)

diff --git a/src/compiler/spirv/spirv_extensions.c b/src/compiler/spirv/spirv_extensions.c
index 0c9855d76cb..7b0215c7f9f 100644
--- a/src/compiler/spirv/spirv_extensions.c
+++ b/src/compiler/spirv/spirv_extensions.c
@@ -21,6 +21,7 @@
  * IN THE SOFTWARE.
  */
 
+#include <stdbool.h>
 #include "spirv_extensions.h"
 #include "util/macros.h"
 
@@ -45,3 +46,35 @@ spirv_extensions_to_string(enum SpvExtension ext)
 
    return "unknown";
 }
+
+/**
+ * Sets the supported flags for known SPIR-V extensions based on the
+ * capabilites supported (spirv capabilities based on the spirv to nir
+ * support).
+ *
+ * One could argue that makes more sense in the other way around, as from the
+ * spec pov capabilities are enable for a given extension. But from our pov,
+ * we support or not (depending on the driver) some given capability, and
+ * spirv_to_nir check for capabilities not extensions. Also we usually fill
+ * first the supported capabilities, that are not always related to an
+ * extension.
+ */
+void
+spirv_fill_supported_spirv_extensions(struct spirv_supported_extensions *ext,
+                                      const struct spirv_supported_capabilities *cap)
+{
+   for (unsigned i = 0; i < SPV_EXTENSIONS_COUNT; i++)
+      ext->supported[i] = false;
+
+   ext->count = 0;
+
+   ext->supported[SPV_KHR_shader_draw_parameters] = cap->draw_parameters;
+   ext->supported[SPV_KHR_multiview] = cap->multiview;
+   ext->supported[SPV_KHR_variable_pointers] = cap->variable_pointers;
+   ext->supported[SPV_AMD_gcn_shader] = cap->AMD_gcn_shader;
+
+   for (unsigned i = 0; i < SPV_EXTENSIONS_COUNT; i++) {
+      if (ext->supported[i])
+         ext->count++;
+   }
+}
diff --git a/src/compiler/spirv/spirv_extensions.h b/src/compiler/spirv/spirv_extensions.h
index 3e1cb7ea4cb..80a5a4699e9 100644
--- a/src/compiler/spirv/spirv_extensions.h
+++ b/src/compiler/spirv/spirv_extensions.h
@@ -24,6 +24,8 @@
 #ifndef _SPIRV_EXTENSIONS_H_
 #define _SPIRV_EXTENSIONS_H_
 
+#include "compiler/shader_info.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -41,8 +43,19 @@ enum SpvExtension {
    SPV_EXTENSIONS_COUNT
 };
 
+struct spirv_supported_extensions {
+   /** Flags the supported extensions. Array to make it easier to iterate. */
+   bool supported[SPV_EXTENSIONS_COUNT];
+
+   /** Number of supported extensions */
+   unsigned int count;
+};
+
 const char *spirv_extensions_to_string(enum SpvExtension ext);
 
+void spirv_fill_supported_spirv_extensions(struct spirv_supported_extensions *ext,
+                                           const struct spirv_supported_capabilities *cap);
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.14.1



More information about the mesa-dev mailing list