Skip to content

Should error when shader has multiple group-bindings with the same values #5787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
stefnotch opened this issue Jun 9, 2024 · 3 comments
Closed
Labels
area: naga front-end area: validation Issues related to validation, diagnostics, and error handling lang: WGSL WebGPU Shading Language type: bug Something isn't working

Comments

@stefnotch
Copy link
Contributor

Description

When I write a shader like

@group(0) @binding(0)
var<storage,read_write> foo: array<u32>;
        
@group(0) @binding(0)
var<storage,read_write> bar: array<u32>;

then I would expect that to result in an error. After all, the WGSL specification says

Two different resource variables in a shader must not have the same group and binding values, when considered as a pair.
https://www.w3.org/TR/WGSL/#resource-interface

Repro steps
The shader above.

Expected vs observed behavior
I expect a shader creation error. The actual behaviour is that naga happily accepts this.

Amusingly, Chrome also seems to accept it. (At least the version of Microsoft Edge that I tested does accept this.)

Platform

  • Windows 11
  • WGSL trunk on commit 583cc6a (one of the latest commits)
@stefnotch
Copy link
Contributor Author

(Yes I was trying out all the forbidden edge cases while writing unit tests for my #5713 😆 )

@Wumpf Wumpf added type: bug Something isn't working area: validation Issues related to validation, diagnostics, and error handling area: naga front-end lang: WGSL WebGPU Shading Language labels Jun 10, 2024
@teoxoy
Copy link
Member

teoxoy commented Jun 10, 2024

The resource interface of a shader is the set of module-scope resource variables statically accessed by functions in the shader stage.

Could you try to add an entry-point using those 2 bindings and see if it still works?

@stefnotch
Copy link
Contributor Author

Ah, I clearly didn't read the spec properly. Yes, it works as expected when one uses the bindings

naga/tests/wgsl_errors.rs

#[test]
fn duplicated_group_binding() {
    check_validation! {
        "@group(0) @binding(0)
        var<storage,read_write> foo: array<f32>;
                
        @group(0) @binding(0)
        var<storage,read_write> bar: array<f32>;
        
        @vertex
        fn main() -> @builtin(position) vec4<f32> {
            let a = foo[0];
            let b = bar[0];
            return vec4<f32>(a, b, 0.0, 1.0);
        }":
        Err(naga::valid::ValidationError::EntryPoint {
            stage: naga::ShaderStage::Vertex,
            source: naga::valid::EntryPointError::BindingCollision(..),
            ..
        })
    }
}

And there are also tests in the official testing suite
https://github.com/gpuweb/cts/blob/b0f5b1839f40f8f793ec2e4a6eecae41a273e0b3/src/webgpu/shader/validation/shader_io/group_and_binding.spec.ts#L135-L138

So I can safely close this.

@github-project-automation github-project-automation bot moved this from Todo to Done in WebGPU for Firefox Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: naga front-end area: validation Issues related to validation, diagnostics, and error handling lang: WGSL WebGPU Shading Language type: bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

3 participants