The tests/compute/buffer-layout.slang sample contains a struct with an element of type float2 c[2];, and the struct is used in a constant buffer.
The corresponding WGSL member declaration is array<vec2<f32>, i32(2)>, so the array element stride is 8.
WGSL requires that array elements have alignment 16, but it doesn't silently change the layout of the array.
Instead it prints an error message suggesting to use vec4 in the array type, instead.
Error while parsing WGSL: :14:22 error: 'uniform' storage requires that array elements are aligned to 16
bytes, but array element of type 'vec2<f32>' has a stride of 8 bytes. Consider using a vec4 instead.
@align(16) c_0 : array<vec2<f32>, i32(2)>,
^^^^^^^^^^^^^^^^^^^^^^^^
We should work around this.
If we instead emit array<S, i32(2)> where S is a struct containing the vec2<f32> (or whatever other type with stride less than 16), then it should work because the size of S will get aligned up to 16.
The tests/compute/buffer-layout.slang sample contains a struct with an element of type
float2 c[2];
, and the struct is used in a constant buffer.The corresponding WGSL member declaration is
array<vec2<f32>, i32(2)>
, so the array element stride is8
. WGSL requires that array elements have alignment16
, but it doesn't silently change the layout of the array. Instead it prints an error message suggesting to use vec4 in the array type, instead.We should work around this. If we instead emit
array<S, i32(2)>
whereS
is a struct containing thevec2<f32>
(or whatever other type with stride less than 16), then it should work because the size ofS
will get aligned up to16
.Affected tests: