Skip to content

Implement WGSL template list discovery #4501

@jimblandy

Description

@jimblandy

Because Naga doesn't implement WGSL's template list discovery algorithm, full constant expressions aren't permitted everywhere they ought to be. Or at least, not without parentheses. The following is valid WGSL, but Naga rejects it, even on the const-expressions-2 branch:

$ cat expr-array-length.wgsl 
var<workgroup> buffer: array<u32, 1024 * 1024>;
$ naga expr-array-length.wgsl 
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s
     Running `/home/jimb/rust/naga/target/debug/naga expr-array-length.wgsl`
error: expected '>', found '*'
  ┌─ expr-array-length.wgsl:1:40
  │
1 │ var<workgroup> buffer: array<u32, 1024 * 1024>;
  │                                        ^ expected '>'

Could not parse WGSL
$ 

If we change it as follows, Naga accepts it:

var<workgroup> buffer: array<u32, (1024 * 1024)>;

The problem here is that Naga doesn't yet implement template list discovery, so it can't tell that the > in array<u32, 1024 * 1024> is the closing bracket of a template list, rather than a > operator in an expression.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

In Progress

Relationships

None yet

Development

No branches or pull requests

Issue actions