Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Test for #5262 #5264

Merged
merged 1 commit into from
Feb 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions tests/tests/shader/struct_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,40 @@ fn create_struct_layout_tests(storage_type: InputStorageType) -> Vec<ShaderTest>
));
}

// Test for https://github.com/gfx-rs/wgpu/issues/5262.
//
// The struct is supposed to have a size of 32 and alignment of 16, but on metal, it has size 24.
for ty in ["f32", "u32", "i32"] {
let header = format!("struct Inner {{ vec: vec3<{ty}>, scalar1: u32, scalar2: u32 }}");
let members = String::from("arr: array<Inner, 2>");
let direct = String::from(
"\
output[0] = bitcast<u32>(input.arr[0].vec.x);
output[1] = bitcast<u32>(input.arr[0].vec.y);
output[2] = bitcast<u32>(input.arr[0].vec.z);
output[3] = bitcast<u32>(input.arr[0].scalar1);
output[4] = bitcast<u32>(input.arr[0].scalar2);
output[5] = bitcast<u32>(input.arr[1].vec.x);
output[6] = bitcast<u32>(input.arr[1].vec.y);
output[7] = bitcast<u32>(input.arr[1].vec.z);
output[8] = bitcast<u32>(input.arr[1].scalar1);
output[9] = bitcast<u32>(input.arr[1].scalar2);
",
);

tests.push(
ShaderTest::new(
format!("Alignment of 24 byte struct with a vec3<{ty}>"),
members,
direct,
&input_values,
&[0, 1, 2, 3, 4, 8, 9, 10, 11, 12],
)
.header(header)
.failures(Backends::METAL),
);
}

// Mat3 alignment tests
for ty in ["f32", "u32", "i32"] {
for columns in [2, 3, 4] {
Expand Down
Loading