yum-mirror/slang

Making it easier to work with shaders

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

Yong HeFix Conditioanl<T, false> fields with a semantic. (#7855)9d47a3529

master
1.3 KiB49 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_]+]] = OpConstant %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
10static const int constValue0 = 32;
11
12[SpecializationConstant]
13const int constValue1 = 2;
14
15//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer
16RWStructuredBuffer<float> outputBuffer;
17
18void func(out float buffer[constValue0 / constValue1])
19{
20    for (uint i = 0; i < constValue0 / constValue1; i++)
21    {
22        buffer[i] = i;
23    }
24}
25
26struct MyStruct<let N: int>
27{
28    float buffer[N / constValue1];
29}
30
31[shader("compute")]
32[numthreads(1, 1, 1)]
33void computeMain()
34{
35    // This test checks we can use spec constants for array sizes.
36    MyStruct<constValue0> s;
37
38    func(s.buffer);
39
40    float temp = 0.0f;
41    for (uint i = 0; i < constValue0 / constValue1; i++)
42    {
43        temp += s.buffer[i] * 2;
44    }
45
46    // Result will be (0 + localConst-1) * localConst = 15 * 16 = 240
47    outputBuffer[0] = temp;
48    // BUF: 240
49}