naga
naga copied to clipboard
[wgsl-in] `workgroup_size` parsed as a builtin variable although it is an attribute only
workgroup_size
doesn't seem to be a builtin variable at all (it's not listed in the builtin variables section of the spec). The spec defines it as an attribute (see workgroup_size
). This means it should not be allowed as a parameter to main
.
For example, the following should not be allowed:
fn main([[builtin(workgroup_size)]] workgroup_size: vec3<u32>) {
This attribute is only supposed to appear like this (see workgroup_size
):
[[stage(compute), workgroup_size(128)]]
fn main() {
I find this somewhat regrettable, as you'll have to save your workgroup_size
in a variable as well (since you can't use a constant variable in the attribute, only non-negative integer literals; duplicating the value, allowing for a mismatch between the actual value and the variable) if you wanna do some math with it, but that is an issue to be raised with the spec.
The spec has it at some point, and then https://github.com/gpuweb/gpuweb/issues/1590 happened. We haven't updated Naga for this specifically yet. It's likely that we'll keep the builtin in IR, since it's represented by the native languages, but we'd fail WebGPU validation if it's used.
Now the spec permits constant expressions as workgroup_size
parameters, so you can use a named constant.