brendan-duncan / wgsl_reflect

A WebGPU Shading Language parser and reflection library for Javascript.
MIT License
184 stars 20 forks source link

Regression: Resources not included in reflection if used directly as array index #59

Open alienself opened 2 weeks ago

alienself commented 2 weeks ago

Hi,

I am seeing the reappearance of the same issue described in the following issue which got fixed: https://github.com/brendan-duncan/wgsl_reflect/issues/52, the binding is not added to the resources array in the program entry.

struct BatchIndex {
   index: u32,
}
@group(0) @binding(2) var<uniform> batchIndex: BatchIndex;
@group(0) @binding(3) var<storage, read> batchOffsets: array<u32>;

@vertex
fn vertex_main(
  vertex: VertexInput
) -> VertexOutput {
    let batchOffset = batchOffsets[batchIndex.index]; // will NOT work
    // ...
}

Workaround but not ideal:

@vertex
fn vertex_main(
  vertex: VertexInput
) -> VertexOutput {
    let index = batchIndex;
    let batchOffset = batchOffsets[index]; // will work
    // ...
}
brendan-duncan commented 2 weeks ago

Sorry about that. Work deadlines are making me not test thoroughly. I don't know why I didn't add a unit test for that. I'll get it fixed up as soon as I get a chance.

alienself commented 2 weeks ago

Okay no worries! Let me know when you are able to have a look.

brendan-duncan commented 2 weeks ago

Getting a chance to look at this.

I do have a unit test for that shader code to index an array with uniform. I modified it with this version to index it with a struct member, and it passes. I checked

struct BatchIndex {
    index: u32,
}
@group(0) @binding(2) var<uniform>  batchIndex: BatchIndex;
@group(0) @binding(3) var<storage, read> batchOffsets: array<u32>;
@vertex
fn main() {
    let batchOffset = batchOffsets[batchIndex.index];
}

in the little tester page, https://brendan-duncan.github.io/wgsl_reflect/example.html, and it parsed fine.

This is from the github main branch. Is that what you're testing against?