gfx-rs / wgpu

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

WGSL template arg. parsing should permit a single trailing comma #6394

Open ErichDonGubler opened 1 month ago

ErichDonGubler commented 1 month ago

Description

Until recently, Dawn didn't allow a trailing comma in template argument lists, and WebGPU CTS also tested that parse cases with a trailing comma failed to parse. Naga also implemented this behavior. However, it turns out that this was all incorrect! 😱

The WGSL. spec. states that the template_arg_comma_list must accept a single optional trailing comma:

Screenshot 2024-10-10 at 6 06 51β€―PM

As of https://github.com/gpuweb/cts/pull/3959, the CTS fixed this to follow the spec., with Dawn following suit in https://crbug.com/366000875. Naga should also fix this, so we don't diverge.

Repro steps

Try to compile this shader:

// ../in.wgsl

@group(0) @binding(0)
var<storage, read,> x: i32;

@group(0) @binding(1)
var<storage,> x: i32;

…which, at time of writing, yields the following in naga-cli:

$ cargo run --package naga-cli -- ../in.wgsl

    Finished dev [unoptimized + debuginfo] target(s) in 0.08s
     Running `target/debug/naga ../in.wgsl`
Could not parse WGSL:
error: expected identifier, found '>'
  β”Œβ”€ ../in.wgsl:7:13
  β”‚
7 β”‚ var<storage,> x: i32;
  β”‚             ^ expected identifier

Error: nu::shell::non_zero_exit_code

  Γ— External command had a non-zero exit code
   ╭─[entry #3:1:1]
 1 β”‚ cargo run -p naga-cli -- ../in.wgsl
   Β· ──┬──
   Β·   ╰── exited with code 1
   ╰────

Alternatively, if lines 3-4 are commented out:

    Finished dev [unoptimized + debuginfo] target(s) in 0.08s
     Running `target/debug/naga ../in.wgsl`
Could not parse WGSL:
error: expected identifier, found '>'
  β”Œβ”€ ../in.wgsl:7:13
  β”‚
7 β”‚ var<storage,> x: i32;
  β”‚             ^ expected identifier

Error: nu::shell::non_zero_exit_code

  Γ— External command had a non-zero exit code
   ╭─[entry #4:1:1]
 1 β”‚ cargo run -p naga-cli -- ../in.wgsl | clip
   Β· ──┬──
   Β·   ╰── exited with code 1
   ╰────

Expected vs observed behavior

The repro steps should produce no errors.

Extra materials

-

Platform

-

ErichDonGubler commented 3 weeks ago

Firefox downstream tracking: bug 1923994