User-defined functions that accept pointers to runtime-sized structures are permitted by WGSL, but are useless, because such pointers cannot be produced. These uncallable functions also happen to be a pain to generate code for. WGSL should just forbid them.
User-defined functions can only accept pointers in the function, private, or workgroup storage classes (WGSL §8.3). Runtime-sized arrays can only appear in the storage storage class (§4.2.8). Thus, no pointer to a runtime-sized array or a struct containing one can be passed to a user-defined function.
However, there is nothing in WGSL to prevent one from defining a function that accepts an argument of type ptr<storage, array<T>, A> anyway. For example:
[[block]]
struct Unsized { data: array<f32>; };
fn acceptable_pointer_to_unsized(arg: ptr<workgroup, Unsized>) -> f32 {
return (*arg).data[0];
}
Tint and Naga cheerfully translate this into SPIR-V. Naga will even emit index bounds checking code for it. But Tint objects if asked to produce MSL with --transform robustness:
error: no matching call to arrayLength(ptr<workgroup, array<f32>, read_write>)
1 candidate function:
arrayLength(ptr<storage, array<T>, A>) -> u32
I'm working on the equivalent of --transform robustness for Naga, and have run into a similar problem generating Metal output.
It would be helpful if translators could avoid having to generate code for such functions. The WGSL spec could simply forbid user-defined functions from accepting pointers whose store type contains a runtime-sized array.
See also: gfx-rs/naga#1513
User-defined functions that accept pointers to runtime-sized structures are permitted by WGSL, but are useless, because such pointers cannot be produced. These uncallable functions also happen to be a pain to generate code for. WGSL should just forbid them.
User-defined functions can only accept pointers in the
function,private, orworkgroupstorage classes (WGSL §8.3). Runtime-sized arrays can only appear in thestoragestorage class (§4.2.8). Thus, no pointer to a runtime-sized array or a struct containing one can be passed to a user-defined function.However, there is nothing in WGSL to prevent one from defining a function that accepts an argument of type
ptr<storage, array<T>, A>anyway. For example:Tint and Naga cheerfully translate this into SPIR-V. Naga will even emit index bounds checking code for it. But Tint objects if asked to produce MSL with
--transform robustness:I'm working on the equivalent of
--transform robustnessfor Naga, and have run into a similar problem generating Metal output.It would be helpful if translators could avoid having to generate code for such functions. The WGSL spec could simply forbid user-defined functions from accepting pointers whose store type contains a runtime-sized array.
See also: gfx-rs/naga#1513