summaryrefslogtreecommitdiffstats
path: root/tests/spirv/buffer-pointer-matrix-layout.slang
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-03-12 19:31:25 -0700
committerGitHub <noreply@github.com>2024-03-12 19:31:25 -0700
commit6f7c8271710b43349d34b8f7569ceb6957400548 (patch)
tree288c18bb4b9a2cf32de7e400c1fe8b56385b727e /tests/spirv/buffer-pointer-matrix-layout.slang
parenteef7e208bf7436a4f111a9290f37204e3220d82b (diff)
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<T>`. * Fix validation error. * Enhance test.
Diffstat (limited to 'tests/spirv/buffer-pointer-matrix-layout.slang')
-rw-r--r--tests/spirv/buffer-pointer-matrix-layout.slang34
1 files changed, 34 insertions, 0 deletions
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