From df386dae02af724582408cfd2109bf3f9f8a4df5 Mon Sep 17 00:00:00 2001 From: Connor Fitzgerald Date: Sun, 18 Feb 2024 12:46:29 -0500 Subject: [PATCH] Add vec3-in-array-test (#5264) --- tests/tests/shader/struct_layout.rs | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/tests/shader/struct_layout.rs b/tests/tests/shader/struct_layout.rs index 3aa731f946..ea135e5320 100644 --- a/tests/tests/shader/struct_layout.rs +++ b/tests/tests/shader/struct_layout.rs @@ -155,6 +155,40 @@ fn create_struct_layout_tests(storage_type: InputStorageType) -> Vec )); } + // 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"); + let direct = String::from( + "\ + output[0] = bitcast(input.arr[0].vec.x); + output[1] = bitcast(input.arr[0].vec.y); + output[2] = bitcast(input.arr[0].vec.z); + output[3] = bitcast(input.arr[0].scalar1); + output[4] = bitcast(input.arr[0].scalar2); + output[5] = bitcast(input.arr[1].vec.x); + output[6] = bitcast(input.arr[1].vec.y); + output[7] = bitcast(input.arr[1].vec.z); + output[8] = bitcast(input.arr[1].scalar1); + output[9] = bitcast(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] {