summaryrefslogtreecommitdiffstats
path: root/tests/metal/groupshared-threadlocal-same-parameter.slang
blob: 1249d4703aa4c74ca6868a08abd424deef30be00 (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
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUF): -shaderobj -output-using-type
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUF): -vk -shaderobj -output-using-type
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUF): -vk -emit-spirv-directly -shaderobj -output-using-type
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-slang -shaderobj -mtl

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

static groupshared uint g_values[2];
static uint g_altValues[2] = { 2, 3 };

static groupshared uint g_valuesReturned[2];
static uint g_altValuesReturned[2];

uint[2] maybeGroupSharedReturn(uint id)
{
    if (id == 0)
    {
        return g_values;
    }
    else
    {
        return g_altValues;
    }
}

[numthreads(2, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
    g_values = { 1, 0 };
    AllMemoryBarrierWithGroupSync();
    uint tid = dispatchThreadID.x;
    if (tid == 0)
    {
        g_valuesReturned[tid] = maybeGroupSharedReturn(tid)[tid];
    }
    else
    {
        g_altValuesReturned[tid] = maybeGroupSharedReturn(tid)[tid];
    }

    AllMemoryBarrierWithGroupSync();
    if (tid == 0)
    {
        outputBuffer[tid] = g_valuesReturned[tid];
    }
    else
    {
        outputBuffer[tid] = g_altValuesReturned[tid];
    }

    // BUF: 1
    // BUF: 3
}