yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Yong HeRewriting the lower-buffer-element-type pass to avoid unnecessary packing/unpacking. (#8526)a6deb5ed8

master
1.8 KiB50 linesraw
1//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk -output-using-type -xslang -matrix-layout-column-major -emit-spirv-directly
2
3// TEST_INPUT: set ptr = ubuffer(data=[1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0],stride=4)
4uniform float3x4 *ptr;
5
6// TEST_INPUT: set outputBuffer = out ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0],stride=4)
7RWStructuredBuffer<float> outputBuffer;
8
9[shader("compute")]
10[numthreads(1, 1, 1)]
11void computeMain(uint3 dtid: SV_DispatchThreadID)
12{
13    // This matrix is in memry column major. Slang respects this here and load it properly!
14    float3x4 correctly_read_matrix = *ptr;
15    outputBuffer[0] = correctly_read_matrix[0][0];
16    outputBuffer[1] = correctly_read_matrix[0][1];
17    outputBuffer[2] = correctly_read_matrix[0][2];
18    outputBuffer[3] = correctly_read_matrix[0][3];
19    outputBuffer[4] = correctly_read_matrix[1][0];
20    outputBuffer[5] = correctly_read_matrix[1][1];
21    outputBuffer[6] = correctly_read_matrix[1][2];
22    outputBuffer[7] = correctly_read_matrix[1][3];
23    // CHECK: 1.0
24    // CHECK: 4.0
25    // CHECK: 7.0
26    // CHECK: 10.0
27    // CHECK: 2.0
28    // CHECK: 5.0
29    // CHECK: 8.0
30    // CHECK: 11.0
31
32    // With this syntax however, Slang was ignoring the column major setting and loads it as it it was row major!
33    float3x4 broken_matrix = ptr[0];
34    outputBuffer[8] = broken_matrix[0][0];
35    outputBuffer[9] = broken_matrix[0][1];
36    outputBuffer[10] = broken_matrix[0][2];
37    outputBuffer[11] = broken_matrix[0][3];
38    outputBuffer[12] = broken_matrix[1][0];
39    outputBuffer[13] = broken_matrix[1][1];
40    outputBuffer[14] = broken_matrix[1][2];
41    outputBuffer[15] = broken_matrix[1][3];
42    // CHECK: 1.0
43    // CHECK: 4.0
44    // CHECK: 7.0
45    // CHECK: 10.0
46    // CHECK: 2.0
47    // CHECK: 5.0
48    // CHECK: 8.0
49    // CHECK: 11.0
50}