summaryrefslogtreecommitdiff
path: root/tests/compute/atomics-groupshared.slang
blob: 4b86e1b9e458d0ef59cb171a9ffc8841ce1dd515 (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
// atomics-groupshared.slang

//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12

//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out

RWStructuredBuffer<uint> outputBuffer;

groupshared uint shared[4];

uint test(uint val)
{
    uint originalValue;

    shared[val] = 0;

    GroupMemoryBarrierWithGroupSync();

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

    return shared[val];
}

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