summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/saturated-cooperation/simple.slang
blob: 80db40bb3890374d647f85e2e21c03e1a70c9605 (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
//DISABLED_TEST(compute, vulkan):COMPARE_COMPUTE_EX():-vk -compute -shaderobj -output-using-type -render-features wave-ops
//DISABLED_TEST(compute):COMPARE_COMPUTE_EX():-dx12 -profile sm_6_5 -compute -shaderobj -output-using-type -render-features wave-ops

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

struct Unit{};

static int count = 0;

int cooperate(float x, Unit)
{
    count += 1;
    return int(x) * 2;
}

int fallback(float x, Unit)
{
    count += 100;
    return int(x) * 3;
}

// Make sure that we have enough invocations to saturate the first workgroup
[numthreads(128, 1, 1)]
void computeMain(uint tig : SV_GroupIndex)
{
    // The values we're cooperating over are {0, 2, 3}
    // We track the number of sets evaluated in the "count" variable, and write
    // that at index 0
    let i = tig < 4 ? float(outputBuffer[tig]) : 0;
    Unit unit;
    let x = saturated_cooperation(cooperate, fallback, i, unit);
    if(tig < 4)
        outputBuffer[tig] = tig == 0 ? count : x;

}