yum-mirror/slang

Making it easier to work with shaders

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

Yong He[Metal] Fix global constant array emit. (#4392)33e81a031

master
1.0 KiB36 linesraw
1// static-const-array.slang
2
3//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -shaderobj
4//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type -shaderobj
5//TEST(compute):COMPARE_COMPUTE_EX:-cpu -slang -compute -output-using-type -shaderobj
6
7//TEST_INPUT:ubuffer(data=[0 0 0 0  0 0 0 0], stride=4):out, name outputBuffer
8RWStructuredBuffer<float> outputBuffer;
9
10
11static const matrix<float, 2, 3> kMatrix = { 1, 2, 4, -1, -2, -3 };
12static const float3 kVector = { -1, -2, -3 };
13
14static const matrix<float, 2, 3> kArray[2] =
15{
16    matrix<float, 2, 3>(0, 1, 2, 3, 4, 5),
17    matrix<float, 2, 3>(float3(6, 7, 8), float3(9, 10, 11)),
18};
19
20float test(int inVal, int index)
21{
22    matrix<float, 2, 3> mat = kArray[index] + kMatrix;
23    mat[0] =+ kVector;
24    
25    float2 a = { inVal, inVal + 1};
26    float3 v = mul(a, mat);
27    return v.x + v.y + v.z;
28}
29
30[numthreads(8, 1, 1)]
31void computeMain(int3 tid : SV_DispatchThreadID)
32{
33    int inVal = tid.x;
34    float outVal = test(inVal, inVal & 1);
35    outputBuffer[inVal] = outVal;
36}