summaryrefslogtreecommitdiffstats
path: root/tests/bugs/atomic-coerce.slang
blob: aa1ebd1a73dc15b9465cba1016e21cfa8b018a9a (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
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj 
//TEST(compute,vulkan):COMPARE_COMPUTE_EX:-vk -slang -compute -shaderobj
//TEST(compute):COMPARE_COMPUTE:-slang -shaderobj -mtl
// Not supported in WGSL: Use of traditional atomics intrinsics (InterlockedXXX functions)
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-wgpu

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

groupshared uint gs_values[2];

[shader("compute")]
[numthreads(4, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
    int index = (int)dispatchThreadID.x;
    
    // Initialize first
    if (index < 2)
    {
        gs_values[index] = 2;
    }

    GroupMemoryBarrierWithGroupSync();
 
    // NOTE! We have to cast to uint, to make atomic work
    InterlockedAdd(gs_values[index & 1], uint(index * index));
           
    outputBuffer[index] = gs_values[index & 1];
}