From 6f7c8271710b43349d34b8f7569ceb6957400548 Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 12 Mar 2024 19:31:25 -0700 Subject: Fix `sessionDesc.defaultMatrixLayoutMode` being ineffective. (#3753) * Fix `sessionDesc.defaultMatrixLayoutMode` being ineffective. * Fix matrix layout in buffer pointer. * Attempt to fix. * Fix buffer element type lowering for buffer pointers. * Add comment. * Fix test. * Fix member lookup in `Ref`. * Fix validation error. * Enhance test. --- tests/spirv/buffer-pointer-matrix-layout.slang | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/spirv/buffer-pointer-matrix-layout.slang (limited to 'tests/spirv/buffer-pointer-matrix-layout.slang') diff --git a/tests/spirv/buffer-pointer-matrix-layout.slang b/tests/spirv/buffer-pointer-matrix-layout.slang new file mode 100644 index 000000000..2ccde7b71 --- /dev/null +++ b/tests/spirv/buffer-pointer-matrix-layout.slang @@ -0,0 +1,34 @@ +//TEST:SIMPLE(filecheck=CHECK): -target spirv -emit-spirv-directly -stage compute -entry main -matrix-layout-column-major + +// CHECK: OpLoad %_MatrixStorage_float3x4_ColMajornatural {{.*}} Aligned 4 +// CHECK: OpLoad %_MatrixStorage_float3x4_ColMajornatural {{.*}} Aligned 4 + +struct Push +{ + float3x4* ptr; +}; + +[[vk::push_constant]] Push push; +[shader("compute")] +[numthreads(1, 1, 1)] +void main(uint3 dtid : SV_DispatchThreadID) +{ + // This matrix is in memry column major. Slang respects this here and load it properly! + float3x4 correctly_read_matrix = *push.ptr; + printf("(%f,%f,%f,%f)\n(%f,%f,%f,%f)\n", + correctly_read_matrix[0][0], correctly_read_matrix[0][1], correctly_read_matrix[0][2], correctly_read_matrix[0][3], + correctly_read_matrix[1][0], correctly_read_matrix[1][1], correctly_read_matrix[1][2], correctly_read_matrix[1][3] + ); + printf("(%f,%f,%f,%f)\n\n", + correctly_read_matrix[2][0], correctly_read_matrix[2][1], correctly_read_matrix[2][2], correctly_read_matrix[2][3] + ); + // With this syntax however, Slang ignores the column major setting and loads it as it it was row major! + float3x4 broken_matrix = push.ptr[0]; + printf("(%f,%f,%f,%f)\n(%f,%f,%f,%f)\n", + broken_matrix[0][0], broken_matrix[0][1], broken_matrix[0][2], broken_matrix[0][3], + broken_matrix[1][0], broken_matrix[1][1], broken_matrix[1][2], broken_matrix[1][3] + ); + printf("(%f,%f,%f,%f)\n\n", + broken_matrix[2][0], broken_matrix[2][1], broken_matrix[2][2], broken_matrix[2][3] + ); +} \ No newline at end of file -- cgit v1.2.3