wgsl_to_wgpu
wgsl_to_wgpu copied to clipboard
Don't assume all bind groups are used in create_pipeline_layout
wgpu can detect the case where a bind group layout is not included in the pipeline layout and not used in the shader or used in the shader but not included in the pipeline layout. wgsl_to_wgpu assumes all bind groups are used, which can create problems for different pipelines in the same WGSL file. A depth only pass for shadows might not use the material uniforms buffer but still want to use the same vertex code as the color pass, for example.
This may require recreating some of the validation code used by naga or wgpu. It's also worth investigating how this works with non consecutive bind groups if index 1 is unused for bind groups 0, 1, 2.
Just a fun fact, with WGSL (I only tried compute shaders), you can have conflicting bindings as long as you don't use the conflicted ones from the same kernel:
@group(0) @binding(0)
var <storage, read> a: u32;
@group(0) @binding(0)
var <storage, read> b:f32;
@compute @workgroup_size(32)
fn whatever1() {
let param = a;
...
}
@compute @workgroup_size(32)
fn whatever2() {
let param = b;
...
}
@compute @workgroup_size(32)
fn whatever2() {
let something = a;
// DISALLOWED:
let param = b;
...
}
This is what's written in the current spec:
Two different resource variables in a shader must not have the same group and binding values, when considered as a pair.
Where a "shader" is not a script, but an entry point and everything it transitively accesses.
So if the assumption of wgsl_to_wgpu that a "shader" is the whole file, that assumption is wrong.
We can generate different bind group initialization code for each entry point in theory. I'm not sure how easily that can be done in practice. This may also become more difficult when considering vertex+fragment shaders since each stage can access different bind groups. I would like for wgsl_to_wgpu to at least accept all valid WGSL even if the generated code has some limitations. The current bind group checking probably needs to be relaxed to conform with the spec.