KhronosGroup / SPIRV-Reflect

SPIRV-Reflect is a lightweight library that provides a C/C++ reflection API for SPIR-V shader bytecode in Vulkan applications.
Apache License 2.0
672 stars 147 forks source link

Error parsing compute shader SPIR-V generated by `glslang` 14.1.0. #257

Closed corporateshark closed 5 months ago

corporateshark commented 5 months ago

Error parsing compute SPIR-V generated by glslang 14.1.0.

image

base_node->op == SpvOpBitcast

SPIR-V compute shader: dump_2.zip SPIRV-Reflect: vulkan-sdk-1.3.280.0

spencer-lunarg commented 5 months ago

can reproduce with

#version 460
#extension GL_EXT_buffer_reference2 : require
#extension GL_EXT_buffer_reference_uvec2 : require

layout(buffer_reference) buffer VertexBuffer;
layout(buffer_reference, buffer_reference_align = 16, std430) buffer VertexBuffer {
    int x;
};

layout(push_constant, std430) uniform PerFrameData {
    uvec2 bufferId;
} pc;

void main() {
    VertexBuffer(pc.bufferId).x = 0;
}

the core issue is we aren't handling cases of using the OpBitcast introduced by GL_EXT_buffer_reference_uvec2 everywhere correctly

corporateshark commented 5 months ago

@spencer-lunarg what should we do about it?

spencer-lunarg commented 5 months ago

sorry not fully back to my normal work setup yet... just took a second look and now double guessing myself what is the "right" answer is (will have more time tomorrow to take a look at this and get a proper fix with testing)

for now, a "temp fix" would be to go

diff --git a/spirv_reflect.c b/spirv_reflect.c
index 92f8b33..cb6e178 100644
--- a/spirv_reflect.c
+++ b/spirv_reflect.c
@@ -555,6 +555,9 @@ static uint32_t FindBaseId(SpvReflectPrvParser* p_parser, SpvReflectPrvAccessCha
       case SpvOpFunctionParameter: {
         UNCHECKED_READU32(p_parser, base_node->word_offset + 2, base_id);
       } break;
+      case SpvOpBitcast: {
+        return 0;
+      } break;
       default: {
         assert(false);
       } break;

but it might mark the push constant variable member unused falsely, so if that isn't important it can unblock you