PENGUINLIONG / spirq-rs

Light weight SPIR-V reflection library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"CorruptedSpirv: cannot find a suitable type" error when structure contains array of structures

zedrian opened this issue · comments

Here is an example of a shader code (compute shader in my case):

#version 450

layout (set=0, binding=0, rgba8) writeonly uniform image2D frame;

struct Object {
    vec3 position;
    uint type;
    vec4 rotation;
    vec3 half_size;
    uint dummy;
};

struct Scene {
    uint object_count;
    Object object; // this works fine
//    Object objects[10]; // this causes an error: "cannot find a suitable type"
};

void main() {
    const ivec2 xy = gl_GlobalInvocationID.xy;

    Scene scene;
    scene.object_count = 5;

    vec4 pixel = vec4(0, 0, 0, 1);
    pixel.r = scene.object_count * 0.1;

    imageStore(frame, xy, pixel);
}

Contents of the main() function are not so important, please pay attention to the Scene structure - it contains a uint member and another member that is either structure (Object) or an array of structures (Object[10]).

When Scene contains just a structure, the shader is reflected correctly. But when using an array of structures, SpirvBinary::reflect() returns an error: "CorruptedSpirv: cannot find a suitable type".

Can we fix that?

Just looked into it. It sources from an early design decision to simply ignore structure declarations without Offset decoration to its members. But clearly, structs used internally also have no such decoration; but since it's not registered, it report such error. Let's see how I could help.

Though, it's quite surprising that a single declaration works on your machine. In my case any instantiation of Object lead to that error.

Maybe you and I are using different compilation setups when generating SPIR-V:
I use shaderc 0.7.1 with target environment Vulkan1_2.

Just for memo. The problem should have been resolved by #52 with an update to SPIR-Q 0.4.12 already on crates.io. The current main branch does not have the updated Cargo.toml yet but will soon catch up.

Works fine now, thanks!