wgsl_reflect icon indicating copy to clipboard operation
wgsl_reflect copied to clipboard

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

Open alienself opened this issue 1 year ago • 3 comments
trafficstars

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
    // ...
}

alienself avatar Sep 27 '24 16:09 alienself

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.

brendan-duncan avatar Sep 27 '24 16:09 brendan-duncan

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

alienself avatar Sep 27 '24 18:09 alienself

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?

brendan-duncan avatar Sep 28 '24 17:09 brendan-duncan