yum-mirror/slang

Making it easier to work with shaders

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

sricker-nvidiaFix broken -emit-spirv-via-glsl test option (#7091)b39ec87cc

master
1.5 KiB48 linesraw
1//TEST:SIMPLE(filecheck=CHECK): -target spirv
2//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -output-using-type -emit-spirv-directly
3
4// CHECK: %[[C0:[0-9A-Za-z_]+]] = OpSpecConstant %int 32
5// CHECK: %[[C1:[0-9A-Za-z_]+]] = OpSpecConstant %int 2
6// CHECK: %[[COP0:[0-9A-Za-z_]+]] = OpSpecConstantOp %int SDiv %[[C0]] %[[C1]]
7// CHECK: %[[ARR_TYPE:[0-9A-Za-z_]+]] = OpTypeArray %float %[[COP0]]
8// CHECK: %[[PT_TYPE:[0-9A-Za-z_]+]] = OpTypePointer Function %[[ARR_TYPE]]
9
10[SpecializationConstant]
11const int constValue0 = 32;
12
13[SpecializationConstant]
14const int constValue1 = 2;
15
16//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer
17RWStructuredBuffer<float> outputBuffer;
18
19void func(out float buffer[constValue0 / constValue1])
20{
21    for (uint i = 0; i < constValue0 / constValue1; i++)
22    {
23        buffer[i] = i;
24    }
25}
26
27[shader("compute")]
28[numthreads(1, 1, 1)]
29void computeMain()
30{
31    // This test checks that when we are using local constant that are computed from spec constant,
32    // the size can be defined in global scope, and type check can pass the when we call `func`.
33    const int localConst = constValue0 / constValue1;
34    float buffer[localConst];
35    // CHECK: OpVariable %[[PT_TYPE]] Function
36
37    func(buffer);
38
39    float temp = 0.0f;
40    for (uint i = 0; i < localConst; i++)
41    {
42        temp += buffer[i] * 2;
43    }
44
45    // Result will be (0 + localConst-1) * localConst = 15 * 16 = 240
46    outputBuffer[0] = temp;
47    // BUF: 240
48}