From: Alejandro Piñeiro <apinhe...@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) --- src/compiler/spirv/spirv_extensions.c | 31 +++++++++++++++++++++++++++++++ src/compiler/spirv/spirv_extensions.h | 12 ++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/compiler/spirv/spirv_extensions.c b/src/compiler/spirv/spirv_extensions.c index f50f87b52e1..ae0ceec9a47 100644 --- a/src/compiler/spirv/spirv_extensions.c +++ b/src/compiler/spirv/spirv_extensions.c @@ -44,3 +44,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 nir_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 0568132a517..7c3d9f0f563 100644 --- a/src/compiler/spirv/spirv_extensions.h +++ b/src/compiler/spirv/spirv_extensions.h @@ -25,6 +25,7 @@ #define _SPIRV_EXTENSIONS_H_ #include "compiler/nir/nir.h" +#include "nir_spirv.h" #ifdef __cplusplus extern "C" { @@ -42,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 nir_spirv_supported_capabilities *cap); + #ifdef __cplusplus } #endif -- 2.15.0 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev