summaryrefslogtreecommitdiffstats
path: root/tests/compute/atomics-groupshared.slang
blob: 22b2add3d37f69cc10bbeba450adec88f37236cc (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
// atomics-groupshared.slang

//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -shaderobj
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -vk -shaderobj
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -cuda -shaderobj
//TEST(compute):COMPARE_COMPUTE:-slang -shaderobj -mtl
// Not supported in WGSL: Use of traditional atomics intrinsics (InterlockedXXX functions)
//DISABLE_TEST(compute):COMPARE_COMPUTE:-slang -shaderobj -wgpu

//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer

RWStructuredBuffer<uint> outputBuffer;

groupshared uint shared[4];

uint test(uint val)
{
    uint originalValue;

    shared[val] = 0;

    GroupMemoryBarrierWithGroupSync();

    uint originalSum = 0;

    InterlockedAdd(shared[val],         val,         originalValue);
    originalSum += originalValue;
    
    InterlockedAdd(shared[val ^ 1],     val*16,     originalValue);
    originalSum += originalValue;
    
    InterlockedAdd(shared[val ^ 2],     val*16*16,     originalValue);
    originalSum += originalValue;
    
    GroupMemoryBarrierWithGroupSync();

    return shared[val] ^ originalSum;
}

[numthreads(4, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
    uint tid = dispatchThreadID.x;
    uint val = test(tid);
    outputBuffer[tid] = val;
}