yum-mirror/slang

Making it easier to work with shaders

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

Anders LeinoUpdate Slang-RHI again to get more WGPU fixes (#5475)e1c3c4ae3

master
2.1 KiB59 linesraw
1// column-major.slang
2
3//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-cpu -compute -compile-arg -O3 -shaderobj -Xslang -matrix-layout-column-major
4//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-slang -compute -shaderobj -Xslang -matrix-layout-column-major
5//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-slang -compute -dx12 -shaderobj -Xslang -matrix-layout-column-major
6//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-vk -compute -shaderobj -Xslang -matrix-layout-column-major
7//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-vk -compute -emit-spirv-via-glsl -Xslang -matrix-layout-column-major
8//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-cuda -compute -shaderobj -Xslang -matrix-layout-column-major
9//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-mtl -compute -shaderobj -Xslang -matrix-layout-column-major
10
11// This data is in column major layout order.... 
12//TEST_INPUT:cbuffer(data=[1.0 0.0 0.0 10.0  0.0 1.0 0.0 20.0  0.0 0.0 1.0 30.0  0.0 0.0 0.0 1.0]):name matrixBuffer
13
14ConstantBuffer<float4x4> matrixBuffer;
15
16//TEST_INPUT:ubuffer(data=[0], stride=4):out,name output
17RWStructuredBuffer<uint> output;
18
19bool floatCheck(float data, float valueToCheckFor)
20{
21    return data < (valueToCheckFor + 0.001) && data > valueToCheckFor - 0.001;
22}
23
24[numthreads(1, 1, 1)]
25void computeMain(uint3 tid : SV_DispatchThreadID)
26{
27    float4 v = float4(1, 2, 3, 1);
28
29    float4x4 M1 = matrixBuffer;
30    
31    float4 r = mul(v, M1);
32
33    float4x4 M2 = mul(M1, M1);
34
35    float4x4 M3 = float4x4(
36            1.0, 0.0, 0.0, 10.0, 
37            0.0, 1.0, 0.0, 20.0,
38            0.0, 0.0, 1.0, 30.0,
39            0.0, 0.0, 0.0, 1.0
40        );
41
42    output[0] = uint(true
43            && floatCheck(r.x, 11)
44            && floatCheck(r.y, 22)
45            && floatCheck(r.z, 33)
46            && floatCheck(r.w, 1)
47
48            && floatCheck(M1[3][0], 10)
49
50            && floatCheck(M2[3][0], 20)
51            && floatCheck(M2._41, 20)
52            && floatCheck(M2._41_32[0], 20)
53            && floatCheck(M2._33_42[0], 1)
54            && floatCheck(M2._42_33[0], 40)
55
56            && floatCheck(M3[0][3], 10)
57        );
58    //BUF: 1
59}