PENGUINLIONG / spirq-rs

Light weight SPIR-V reflection library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Storage buffer recognised as unifom buffer.

DoeringChristian opened this issue · comments

In my shader i have defined an array of buffers like this:

layout(set = 0, binding = 0) buffer BVH{
    BVHNode nodes[];
}bvh[2];

But when reflecting the spirv code I get this ad the Desciptor:

Descriptor { name: Some("bvh"), desc_bind: (set=0, bind=0), desc_ty: UniformBuffer, ty: BVH { nodes: [BVHNode { min: vec4<f32>, max: vec4<f32>, ty: u32, right: u32, miss: u32, _pad: u32 }] }, nbind: 2 }

I have also tried it with spirv-reflect-rs and it outputs the following:

ReflectDescriptorBinding { spirv_id: 499, name: "bvh", binding: 0, input_attachment_index: 0, set: 0, descriptor_type: StorageBuffer, resource_type: UnorderedAccessView, ...

Where it is recognized correctly as a StorageBuffer. I came to the conclusion that the error couldn't lie in the spirv compiler I'm using.
Unfortunately I'm not relatively new to rust and don't quite understand how your project is working (especially the auto generated code) so I can't fix it myself. Thanks for your help.

Found out that I was compiling the glsl code with inline-spirv without using the vulkan1_2 flag so it didn't compile to spriv1.5 but I'm still confused why spirv-reflect-rs got the descriptor type right.

sry I just saw this. In early versions of SPIR-V (<1.3 I believe) uniform buffer and storage buffer share a same storage class Uniform. And it's only after 1.3 SPIR-V added a dedicated storage class StorageBuffer for it. SPIR-Q should get this right (but it's not) so I would like to look into this. Thanks a lot for the report. :)

Okay, now I see what's been happening. The multibinding nested a layer of OpTypeArray while the BufferBlock decoration is on the OpTypeStruct inside. Should have been fixed with #79 .

If it sounds good to you, could you try with the fixed version with the following in your Cargo.toml?

spirq = { git = 'https://github.com/PENGUINLIONG/spirq', branch = 'fix-old-store-buf-multibind' }

I have tested it on the new branch with inline-spirv and it seems to work ok now:

[Descriptor { name: Some("bvh"), desc_bind: (set=0, bind=0), desc_ty: StorageBuffer(ReadWrite), ty: BVH { nodes: [u32] }, nbind: 1 }]

Thanks for fixing it so quickly.

Great! I'm closing this then. Thanks again for your help. :D