From 5e35c99132f1a259b25130128fef382f745dd372 Mon Sep 17 00:00:00 2001 From: Steven Perron Date: Mon, 11 Nov 2024 10:33:54 -0500 Subject: [PATCH 1/4] Fix undefined enums There are a few places where an enum value is purpoposly getting a value that is not one of the enum values. This is causing a problem when testing. I have a quick fix to make those values `int` instead of the enum type. The variables could contain `-1` as a special value to indicate that no storage class or builtin is used. We cannot change the enum class to add `-1` because it is defined in spirv headers. --- common/output_stream.cpp | 4 ++-- common/output_stream.h | 4 ++-- spirv_reflect.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/common/output_stream.cpp b/common/output_stream.cpp index 1a81b2c4..ab6b5312 100644 --- a/common/output_stream.cpp +++ b/common/output_stream.cpp @@ -204,7 +204,7 @@ std::string ToStringShaderStage(SpvReflectShaderStageFlagBits stage) { return "???"; } -std::string ToStringSpvStorageClass(SpvStorageClass storage_class) { +std::string ToStringSpvStorageClass(int storage_class) { switch (storage_class) { case SpvStorageClassUniformConstant: return "UniformConstant"; @@ -343,7 +343,7 @@ std::string ToStringDescriptorType(SpvReflectDescriptorType value) { return "VK_DESCRIPTOR_TYPE_???"; } -static std::string ToStringSpvBuiltIn(SpvBuiltIn built_in) { +static std::string ToStringSpvBuiltIn(int built_in) { switch (built_in) { case SpvBuiltInPosition: return "Position"; diff --git a/common/output_stream.h b/common/output_stream.h index d29014a7..32d9b73c 100644 --- a/common/output_stream.h +++ b/common/output_stream.h @@ -9,7 +9,7 @@ std::string ToStringSpvSourceLanguage(SpvSourceLanguage lang); std::string ToStringSpvExecutionModel(SpvExecutionModel model); -std::string ToStringSpvStorageClass(SpvStorageClass storage_class); +std::string ToStringSpvStorageClass(int storage_class); std::string ToStringSpvDim(SpvDim dim); std::string ToStringSpvBuiltIn(const SpvReflectInterfaceVariable& variable, bool preface); std::string ToStringSpvImageFormat(SpvImageFormat fmt); @@ -66,4 +66,4 @@ class SpvReflectToYaml { std::map interface_variable_to_index_; }; -#endif \ No newline at end of file +#endif diff --git a/spirv_reflect.h b/spirv_reflect.h index 7a92c34c..631230c9 100644 --- a/spirv_reflect.h +++ b/spirv_reflect.h @@ -393,7 +393,7 @@ typedef struct SpvReflectTypeDescription { const char* type_name; // Non-NULL if type is member of a struct const char* struct_member_name; - SpvStorageClass storage_class; + int storage_class; SpvReflectTypeFlags type_flags; SpvReflectDecorationFlags decoration_flags; @@ -429,7 +429,7 @@ typedef struct SpvReflectInterfaceVariable { SpvStorageClass storage_class; const char* semantic; SpvReflectDecorationFlags decoration_flags; - SpvBuiltIn built_in; + int built_in; SpvReflectNumericTraits numeric; SpvReflectArrayTraits array; From f59830c1aa6cd59d9d87e219f8b2266971a712a3 Mon Sep 17 00:00:00 2001 From: Steven Perron Date: Mon, 11 Nov 2024 11:37:27 -0500 Subject: [PATCH 2/4] Add cast in the c code. --- spirv_reflect.c | 3 ++- spirv_reflect.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/spirv_reflect.c b/spirv_reflect.c index efb1149e..98f8db0a 100644 --- a/spirv_reflect.c +++ b/spirv_reflect.c @@ -2188,7 +2188,8 @@ static SpvReflectResult ParseDescriptorBindings(SpvReflectPrvParser* p_parser, S // from the pointer so that we can use it to deduce deescriptor types. SpvStorageClass pointer_storage_class = SpvStorageClassMax; if (p_type->op == SpvOpTypePointer) { - pointer_storage_class = p_type->storage_class; + assert(p_type->storage_class != -1 && "Pointer types must have a valid storage class."); + pointer_storage_class = (SpvStorageClass)p_type->storage_class; // Find the type's node SpvReflectPrvNode* p_type_node = FindNode(p_parser, p_type->id); if (IsNull(p_type_node)) { diff --git a/spirv_reflect.h b/spirv_reflect.h index 631230c9..cc08ae23 100644 --- a/spirv_reflect.h +++ b/spirv_reflect.h @@ -393,6 +393,9 @@ typedef struct SpvReflectTypeDescription { const char* type_name; // Non-NULL if type is member of a struct const char* struct_member_name; + + // The storage class (SpvStorageClass) if the type, and -1 if it does not have a storage class. + // Note that SpvSt int storage_class; SpvReflectTypeFlags type_flags; SpvReflectDecorationFlags decoration_flags; From 0276545cb62682448789033b4f0970741a17405f Mon Sep 17 00:00:00 2001 From: Steven Perron Date: Mon, 11 Nov 2024 11:40:15 -0500 Subject: [PATCH 3/4] Fix comments. --- spirv_reflect.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spirv_reflect.h b/spirv_reflect.h index cc08ae23..b03e87db 100644 --- a/spirv_reflect.h +++ b/spirv_reflect.h @@ -395,7 +395,6 @@ typedef struct SpvReflectTypeDescription { const char* struct_member_name; // The storage class (SpvStorageClass) if the type, and -1 if it does not have a storage class. - // Note that SpvSt int storage_class; SpvReflectTypeFlags type_flags; SpvReflectDecorationFlags decoration_flags; @@ -432,6 +431,8 @@ typedef struct SpvReflectInterfaceVariable { SpvStorageClass storage_class; const char* semantic; SpvReflectDecorationFlags decoration_flags; + + // The builtin id if the variable is a builtin, and -1 otherwise. int built_in; SpvReflectNumericTraits numeric; SpvReflectArrayTraits array; From 2b7cb91f2d5c3adcdee8643b484215dd8f2b1527 Mon Sep 17 00:00:00 2001 From: Steven Perron Date: Mon, 11 Nov 2024 12:28:53 -0500 Subject: [PATCH 4/4] Update spirv_reflect.h Co-authored-by: Spencer Fricke <115671160+spencer-lunarg@users.noreply.github.com> --- spirv_reflect.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spirv_reflect.h b/spirv_reflect.h index b03e87db..09ebc1f6 100644 --- a/spirv_reflect.h +++ b/spirv_reflect.h @@ -432,7 +432,7 @@ typedef struct SpvReflectInterfaceVariable { const char* semantic; SpvReflectDecorationFlags decoration_flags; - // The builtin id if the variable is a builtin, and -1 otherwise. + // The builtin id (SpvBuiltIn) if the variable is a builtin, and -1 otherwise. int built_in; SpvReflectNumericTraits numeric; SpvReflectArrayTraits array;