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.4 KiB42 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 5
5// CHECK: %[[I3:[0-9A-Za-z_]+]] = OpConstant %int 3
6// CHECK: %[[COP0:[0-9A-Za-z_]+]] = OpSpecConstantOp %int SRem %[[C0]] %[[I3]]
7// CHECK: %[[I2:[0-9A-Za-z_]+]] = OpConstant %int 2
8// CHECK: %[[COP1:[0-9A-Za-z_]+]] = OpSpecConstantOp %int IMul %[[I2]] %[[C0]]
9// CHECK: %[[COP2:[0-9A-Za-z_]+]] = OpSpecConstantOp %int IAdd %[[COP0]] %[[COP1]]
10// CHECK: %[[ARR_TYPE:[0-9A-Za-z_]+]] = OpTypeArray %float %[[COP2]]
11// CHECK: %[[PT_TYPE:[0-9A-Za-z_]+]] = OpTypePointer Workgroup %[[ARR_TYPE]]
12// CHECK: OpVariable %[[PT_TYPE]] Workgroup
13
14
15[SpecializationConstant]
16const int constValue0 = 5;
17
18groupshared float buffer[constValue0 * 2 + constValue0 % 3];
19
20//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer
21RWStructuredBuffer<float> outputBuffer;
22
23[shader("compute")]
24[numthreads(12, 1, 1)]
25void computeMain(uint3 id : SV_GroupThreadID)
26{
27    buffer[id.x] = id.x;
28
29    GroupMemoryBarrier();
30    if (id.x == 0)
31    {
32        static const int size = constValue0 * 2 + constValue0 % 3;
33        float temp = 0;
34        for (uint i = 0; i < size; i++)
35        {
36            temp = temp + buffer[i];
37        }
38        outputBuffer[0] = temp;
39    }
40    // Result will be (0 + size-1) * size / 2
41    // BUF: 66
42}