summaryrefslogtreecommitdiffstats
path: root/tests/spirv/spec-constant-generic.slang
blob: 1d7e3c1fe28e7dce113b5f14c5c60d9598c772aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//TEST:SIMPLE(filecheck=CHECK): -target spirv
//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -output-using-type -emit-spirv-directly

// CHECK: %[[C0:[0-9A-Za-z_]+]] = OpConstant %int 32
// CHECK: %[[C1:[0-9A-Za-z_]+]] = OpSpecConstant %int 2
// CHECK: %[[COP0:[0-9A-Za-z_]+]] = OpSpecConstantOp %int SDiv %[[C0]] %[[C1]]
// CHECK: %[[ARR_TYPE:[0-9A-Za-z_]+]] = OpTypeArray %float %[[COP0]]
// CHECK: %[[PT_TYPE:[0-9A-Za-z_]+]] = OpTypePointer Function %[[ARR_TYPE]]

static const int constValue0 = 32;

[SpecializationConstant]
const int constValue1 = 2;

//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer
RWStructuredBuffer<float> outputBuffer;

void func(out float buffer[constValue0 / constValue1])
{
    for (uint i = 0; i < constValue0 / constValue1; i++)
    {
        buffer[i] = i;
    }
}

struct MyStruct<let N: int>
{
    float buffer[N / constValue1];
}

[shader("compute")]
[numthreads(1, 1, 1)]
void computeMain()
{
    // This test checks we can use spec constants for array sizes.
    MyStruct<constValue0> s;

    func(s.buffer);

    float temp = 0.0f;
    for (uint i = 0; i < constValue0 / constValue1; i++)
    {
        temp += s.buffer[i] * 2;
    }

    // Result will be (0 + localConst-1) * localConst = 15 * 16 = 240
    outputBuffer[0] = temp;
    // BUF: 240
}