Skip to content

Commit df386da

Browse files
authored
Add vec3-in-array-test (#5264)
1 parent 004e3ef commit df386da

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/tests/shader/struct_layout.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,40 @@ fn create_struct_layout_tests(storage_type: InputStorageType) -> Vec<ShaderTest>
155155
));
156156
}
157157

158+
// Test for https://github.com/gfx-rs/wgpu/issues/5262.
159+
//
160+
// The struct is supposed to have a size of 32 and alignment of 16, but on metal, it has size 24.
161+
for ty in ["f32", "u32", "i32"] {
162+
let header = format!("struct Inner {{ vec: vec3<{ty}>, scalar1: u32, scalar2: u32 }}");
163+
let members = String::from("arr: array<Inner, 2>");
164+
let direct = String::from(
165+
"\
166+
output[0] = bitcast<u32>(input.arr[0].vec.x);
167+
output[1] = bitcast<u32>(input.arr[0].vec.y);
168+
output[2] = bitcast<u32>(input.arr[0].vec.z);
169+
output[3] = bitcast<u32>(input.arr[0].scalar1);
170+
output[4] = bitcast<u32>(input.arr[0].scalar2);
171+
output[5] = bitcast<u32>(input.arr[1].vec.x);
172+
output[6] = bitcast<u32>(input.arr[1].vec.y);
173+
output[7] = bitcast<u32>(input.arr[1].vec.z);
174+
output[8] = bitcast<u32>(input.arr[1].scalar1);
175+
output[9] = bitcast<u32>(input.arr[1].scalar2);
176+
",
177+
);
178+
179+
tests.push(
180+
ShaderTest::new(
181+
format!("Alignment of 24 byte struct with a vec3<{ty}>"),
182+
members,
183+
direct,
184+
&input_values,
185+
&[0, 1, 2, 3, 4, 8, 9, 10, 11, 12],
186+
)
187+
.header(header)
188+
.failures(Backends::METAL),
189+
);
190+
}
191+
158192
// Mat3 alignment tests
159193
for ty in ["f32", "u32", "i32"] {
160194
for columns in [2, 3, 4] {

0 commit comments

Comments
 (0)