summaryrefslogtreecommitdiffstats
path: root/tests/bugs/gh-3429.slang
blob: 115ebdb06f4f36816b81f321e9daa73e5da7d91c (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
50
51
52
53
54
55
56
// This test checks that kIROp_StructuredBufferLoad and similar instructions
// are not movable.

//TEST:SIMPLE(filecheck=CHECK): -entry computeMain -stage compute -target hlsl

[[vk::binding(0, 0)]]
StructuredBuffer<float> gSomeData;

[[vk::binding(1, 0)]]
RWTexture2D<float4> gResultImage;

struct PushConstants
{
    bool bufferHasOnlyOneElement;
};

[[vk::push_constant]]
ConstantBuffer<PushConstants> gPushConstants;

float loadDataConditionTrue()
{
    return gSomeData[0];
}

float loadDataConditionFalse()
{
    return gSomeData[1];
}

[ForceInline]
float getDataDependingOnCondition(bool condition)
{
    if (condition)
    {
        return loadDataConditionTrue();
    }
    else
    {
        return loadDataConditionFalse();
    }

    return 0.0;
}

[numthreads(1,1,1)]
void computeMain()
{
    // CHECK: if
    // CHECK: loadDataConditionTrue
    // CHECK: else
    // CHECK: loadDataConditionFalse
    float v = getDataDependingOnCondition(gPushConstants.bufferHasOnlyOneElement);

    int2 pixelIndex = int2(0);
    gResultImage[pixelIndex] = float4(v, v, v, 1.0);
}