Resources not included in reflection if used directly as array index
alienself opened this issue · 3 comments
Hi again,
I hope I don't bother you too much with those issues, I just love your library and rely on it every day.
I found a little bug when using a binding as array index, the binding is not added to the resources array in the program entry.
Here is an example:
I have two bindings, a uniform and a storage buffer:
@group(0) @binding(2) var<uniform> batchIndex: u32;
@group(0) @binding(3) var<storage, read> batchOffsets: array<u32>;
When accessing batchOffsets
directly with batchIndex
like below batchIndex
is not added to entry.vertex.0.resources
@vertex
fn vertex_main(
vertex: VertexInput
) -> VertexOutput {
let batchOffset = batchOffsets[batchIndex]; // will NOT work
// ...
}
A simple workaround is simply to create a temporary variable:
@vertex
fn vertex_main(
vertex: VertexInput
) -> VertexOutput {
let index = batchIndex;
let batchOffset = batchOffsets[index]; // will work
// ...
}
Additonally, the issue is the same if the batchIndex
uniform is a struct rather than a value:
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
// ...
}
No, thank you, I really appreciate exercising the library and finding the edge cases. I'll get it fixed up.
Fix is in git and npm
Awesome! Once again, thank you very much for this super fast update.