-
Notifications
You must be signed in to change notification settings - Fork 353
Description
It's handy to have a constant expression for the zero value for bool, float, integer, vectors, matrices, and arrays and structs of these types.
Let's call these "nullable" types.
I'm not entirely hung up on the 'null' name, but if T is a nullable type, then null<T> is the zero value for that type.
Mirroring the text about "default values" in WGSL 3.7.1, we have:
null<bool> is false
null<i32> is 0
null<u32> is 0
null<f32> is +0.0 (positive zero, i.e. where the sign bit is 0)
A null vector is a vector with null elements. A null matrix is a matrix with null component vectors.
A null array is an array of null elements.
A null structure is a structure with all its members being null.
All this corresponds to the OpConstantNull in SPIR-V.
Aside from being generally useful, this aids in translation from LLVM, where to fill a vector it uses a pattern starting with an undef vector and then fills it with a chain of insert-element instructions. It's handy to replace any "undef" with a zero.