[Mesa-dev] [PATCH v3 3/6] spirv_extensions: define spirv_extensions_supported

Eduardo Lima Mitev elima at igalia.com
Wed Dec 13 20:09:16 UTC 2017


From: Alejandro PiƱeiro <apinheiro at igalia.com>

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)
---
 src/compiler/spirv/spirv_extensions.c | 32 ++++++++++++++++++++++++++++++++
 src/compiler/spirv/spirv_extensions.h | 13 +++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/src/compiler/spirv/spirv_extensions.c b/src/compiler/spirv/spirv_extensions.c
index 3acbe28408a..dd8df817c8c 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"
 
@@ -44,3 +45,34 @@ 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;
+
+   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 478b128e1da..d26882a8d4c 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
@@ -40,8 +42,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.15.1



More information about the mesa-dev mailing list