summaryrefslogtreecommitdiffstats
path: root/tests/glsl-intrinsic/atomic/atomicCounter.slang
blob: 4e32800e08e4dc9458133838049a5361bfef8aa0 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//TEST:SIMPLE(filecheck=CHECK_GLSL):  -allow-glsl -stage compute -entry computeMain -target glsl -DTARGET_GLSL
//TEST:SIMPLE(filecheck=CHECK_SPV):  -allow-glsl -stage compute -entry computeMain -target spirv -emit-spirv-directly -DTARGET_SPIRV
//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -compute -entry computeMain -allow-glsl
//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -compute -entry computeMain -allow-glsl -emit-spirv-directly
#version 430

//TEST_INPUT:ubuffer(data=[0 0], stride=4):out,name=outputBuffer
buffer MyBlockName
{
    uint data[2];
} outputBuffer;

// CHECK_GLSL-DAG: void main(
// CHECK_SPV-DAG: OpEntryPoint

//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0], stride=4):name=one
layout(binding = 1, offset = 12) uniform atomic_uint one;
bool testSetterAndGetter()
{
    return true

// CHECK_GLSL-DAG: atomicExchange
// CHECK_SPV-DAG: OpAtomicExchange
        && atomicCounterExchange(one, 1) == 0

// CHECK_GLSL-DAG: atomicExchange
// no idea how to check the spirv reliabley...
        && atomicCounter(one) == 1
        && atomicCounterExchange(one, 5) == 1
        && atomicCounter(one) == 5
        ;
}

bool counterAsParam(atomic_uint param)
{
    return true
        && atomicCounterExchange(param, 5) != 100

// CHECK_GLSL-DAG: atomicAdd(
// CHECK_SPV-DAG: OpAtomicIAdd
        && atomicCounterIncrement(param) == 5
        && atomicCounter(param) == 6
        ;
}

// GLSL_CHECK-LABEL: bool testAtomicUint
// SPV_CHECK-LABEL: testAtomicUint
bool testAtomicUint()
{
// ensure the code emits for `one` index into [3] for 12/4
// CHECK_GLSL-DAG: {{.*}}_data_{{.*}}[3]{{.*}}
    return true
    
        && atomicCounterExchange(one, 5) != 100
// CHECK_GLSL-DAG: atomicAdd(
// CHECK_SPV-DAG: OpAtomicIIncrement
        && atomicCounterIncrement(one) == 5
        && atomicCounter(one) == 6

        && atomicCounterExchange(one, 5) != 100
// CHECK_GLSL-DAG: atomicExchange(
// CHECK_SPV-DAG: OpAtomicIDecrement
        && atomicCounterDecrement(one) == 4

        && atomicCounterExchange(one, 5) != 100
// CHECK_GLSL-DAG: atomicAdd(
        && atomicCounterAdd(one, 1) == 5
        && atomicCounter(one) == 6

        && atomicCounterExchange(one, 5) != 100
// CHECK_GLSL-DAG: atomicExchange
// CHECK_SPV-DAG: OpAtomicISub
        && atomicCounterSubtract(one, 1) == 5
        && atomicCounter(one) == 4

        && atomicCounterExchange(one, 5) != 100
// CHECK_GLSL-DAG: atomicMin(
// CHECK_SPV-DAG: OpAtomicUMin
        && atomicCounterMin(one, 1) == 5
        && atomicCounter(one) == 1

        && atomicCounterExchange(one, 5) != 100
// CHECK_GLSL-DAG: atomicMax(
// CHECK_SPV-DAG: OpAtomicUMax
        && atomicCounterMax(one, 1) == 5 
        && atomicCounter(one) == 5

// CHECK_GLSL-DAG: atomicAnd(
// CHECK_SPV: OpAtomicAnd
        && atomicCounterExchange(one, 5) != 100
        && atomicCounterAnd(one, 2) == 5
        && atomicCounter(one) == 0

// CHECK_GLSL-DAG: atomicOr(
// CHECK_SPV-DAG: OpAtomicOr
        && atomicCounterExchange(one, 5) != 100
        && atomicCounterOr(one, 8) == 5
        && atomicCounter(one) == 13

// CHECK_GLSL-DAG: atomicXor(
// CHECK_SPV-DAG: OpAtomicXor
        && atomicCounterExchange(one, 5) != 100
        && atomicCounterXor(one, 4) == 5
        && atomicCounter(one) == 1

// CHECK_GLSL-DAG: atomicCompSwap(
// CHECK_SPV-DAG: OpAtomicCompareExchange
        && atomicCounterExchange(one, 5) != 100
        && atomicCounterCompSwap(one, 5, 3) == 5 
        && atomicCounter(one) == 3

// CHECK_GLSL-DAG: atomicCompSwap(
// CHECK_SPV-DAG: OpAtomicCompareExchange
        && atomicCounterExchange(one, 5) != 100
        && atomicCounterCompSwap(one, 5, 3) == 5 
        && atomicCounter(one) == 3

        && counterAsParam(one);
        ;
}

void computeMain()
{
    outputBuffer.data[0] = true
            && testSetterAndGetter()
            ;
    outputBuffer.data[1] = true
            && testAtomicUint()
            ;
    // BUF: 1
    // BUF-NEXT: 1
}