naga icon indicating copy to clipboard operation
naga copied to clipboard

[wgsl-in] `workgroup_size` parsed as a builtin variable although it is an attribute only

Open hcsch opened this issue 2 years ago • 1 comments

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.

hcsch avatar Aug 18 '21 03:08 hcsch

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.

kvark avatar Aug 18 '21 05:08 kvark

Now the spec permits constant expressions as workgroup_size parameters, so you can use a named constant.

jimblandy avatar Dec 12 '22 17:12 jimblandy