gfx-rs / wgpu

A cross-platform, safe, pure-Rust graphics API.
https://wgpu.rs
Apache License 2.0
12.49k stars 914 forks source link

get_bind_group_layout fails when layout is auto #6095

Closed sagudev closed 1 month ago

sagudev commented 2 months ago

Description When layout is not explicitly provided when creating pipeline, get_bind_group_layout fails with Error reflecting bind group 0: Invalid group index 0, but explicitly providing it makes it work.

Repro steps Relevant CTS test that fails in firefox (and servo): webgpu:api,validation,getBindGroupLayout:index_range,auto_layout:*

I also extracted relevant failing CTS subtest in rust/wgpu repro: https://github.com/sagudev/wgpu-problem/tree/get-auto-bind-group-layout (also contains explicit code that makes it work using explicit feature).

Platform Happens on current trunk.

sagudev commented 2 months ago

This happens on both compute/render pipeline.

Wumpf commented 1 month ago

Duplicate of

sagudev commented 1 month ago

I tested repro with https://github.com/gfx-rs/wgpu/pull/6280 and while it does not panic it still raises validation error (per CTS it should return appropriate bind group), so please reopen the issue.

sagudev commented 1 month ago

The problem is that usage = 0: https://github.com/gfx-rs/wgpu/blob/9f85f8aeea6c43c1a412bafc8fbcfb43aad0dd20/wgpu-core/src/validation.rs#L897-L900 for compute pipeline with:

@group(0) @binding(0) var<uniform> binding: f32;

@compute @workgroup_size(1) fn main(
  @builtin(global_invocation_id) id: vec3<u32>
) {
    _ = binding;
}
sagudev commented 1 month ago

More specifically the problem is that naga eliminates phony assigement, converting wgsl from above to wgsl returns:

@group(0) @binding(0) 
var<uniform> binding: f32;

@compute @workgroup_size(1, 1, 1)
fn main(@builtin(global_invocation_id) id: vec3<u32>) {
}
sagudev commented 1 month ago

this is regression naga-cli v0.12.3->naga-cli v0.13.0

sagudev commented 1 month ago

I think it's https://github.com/gfx-rs/naga/pull/2378, but also we remove expressions on compacting ...