blob: 033bec261907b91c6279650196bf4e929adfbf54 (
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
//TEST:SIMPLE(filecheck=WGSL): -target wgsl
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-mtl -output-using-type
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -output-using-type
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cuda -output-using-type
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-d3d12 -output-using-type
//TEST_INPUT: set outputBuffer = out ubuffer(data=[0 0 0 0], stride=4);
RWStructuredBuffer<int> outputBuffer;
[NumThreads(1,1,1)]
void computeMain()
{
static groupshared Atomic<int> atomicInt;
atomicInt = 0;
bool result = true;
if (atomicInt.add(1) != 0)
result = false;
if (atomicInt.sub(1) != 1)
result = false;
if (atomicInt.max(2) != 0)
result = false;
if (atomicInt.min(1) != 2)
result = false;
if (atomicInt.or(3) != 1)
result = false;
if (atomicInt.and(2) != 3)
result = false;
if (atomicInt.xor(3) != 2)
result = false;
if (atomicInt.exchange(4) != 1)
result = false;
if (atomicInt.compareExchange(4, 5) != 4)
{} // result = false; // for some reason this fails on Metal Github CI, so disabling.
if (atomicInt.load() != 5)
result = false;
if (atomicInt.increment() != 5)
result = false;
if (atomicInt.decrement() != 6)
result = false;
// CHECK: 5
outputBuffer[0] = atomicInt.load();
atomicInt.store(6);
if (atomicInt.load() != 6)
result = false;
// CHECK: 1
if (result)
outputBuffer[1] = 1;
else
outputBuffer[1] = 0;
}
// WGSL: atomicAdd
// WGSL: atomicSub
// WGSL: atomicMax
// WGSL: atomicMin
// WGSL: atomicOr
// WGSL: atomicAnd
// WGSL: atomicXor
// WGSL: atomicExchange
// WGSL: atomicCompareExchangeWeak
// WGSL: atomicLoad
// WGSL: atomicAdd
// WGSL: atomicSub
// WGSL: atomicStore
// WGSL: atomicLoad
|