1
+ #version 450 core
2
+
3
+ #extension GL_KHR_memory_scope_semantics : enable
4
+ #extension GL_EXT_shader_atomic_float: enable
5
+ #pragma use_vulkan_memory_model
6
+
7
+ layout(local_size_x = 16, local_size_y = 16) in;
8
+
9
+ layout(binding = 0) buffer Buffer
10
+ {
11
+ float dataf;
12
+ double datad;
13
+ } buf;
14
+
15
+ shared float atomf;
16
+ shared double atomd;
17
+
18
+ layout(binding = 0, r32f) volatile coherent uniform image1D fimage1D;
19
+ layout(binding = 1, r32f) volatile coherent uniform image1DArray fimage1DArray;
20
+ layout(binding = 2, r32f) volatile coherent uniform image2D fimage2D;
21
+ layout(binding = 3, r32f) volatile coherent uniform image2DArray fimage2DArray;
22
+ layout(binding = 4, r32f) volatile coherent uniform image2DRect fimage2DRect;
23
+ layout(binding = 5, r32f) volatile coherent uniform imageCube fimageCube;
24
+ layout(binding = 6, r32f) volatile coherent uniform imageCubeArray fimageCubeArray;
25
+ layout(binding = 9, r32f) volatile coherent uniform image3D fimage3D;
26
+
27
+ void main()
28
+ {
29
+ //atomicAdd
30
+ float resultf = 0;
31
+ resultf = atomicAdd(atomf, 3.0);
32
+ resultf = atomicAdd(atomf, 4.5, gl_ScopeDevice, gl_StorageSemanticsBuffer, gl_SemanticsRelaxed);
33
+ resultf = atomicAdd(buf.dataf, 3.0);
34
+ resultf = atomicAdd(buf.dataf, 4.5, gl_ScopeDevice, gl_StorageSemanticsBuffer, gl_SemanticsRelaxed);
35
+
36
+ double resultd = 0;
37
+ resultd = atomicAdd(atomd, 3.0);
38
+ resultd = atomicAdd(atomd, 4.5, gl_ScopeDevice, gl_StorageSemanticsBuffer, gl_SemanticsRelaxed);
39
+ resultd = atomicAdd(buf.datad, 3.0);
40
+ resultd = atomicAdd(buf.datad, 4.5, gl_ScopeDevice, gl_StorageSemanticsBuffer, gl_SemanticsRelaxed);
41
+
42
+ //atomicExchange
43
+ resultf = atomicExchange(buf.dataf, resultf);
44
+ buf.dataf += resultf;
45
+ resultf = atomicExchange(buf.dataf, resultf, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed);
46
+ buf.dataf += resultf;
47
+ resultf = atomicExchange(atomf, resultf);
48
+ buf.dataf += resultf;
49
+ resultf = atomicExchange(atomf, resultf, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed);
50
+ buf.dataf += resultf;
51
+
52
+ resultd = atomicExchange(buf.datad, resultd);
53
+ buf.datad += resultd;
54
+ resultd = atomicExchange(buf.datad, resultd, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed);
55
+ buf.datad += resultd;
56
+ resultd = atomicExchange(atomd, resultd);
57
+ buf.datad += resultd;
58
+ resultd = atomicExchange(atomd, resultd, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed);
59
+ buf.datad += resultd;
60
+
61
+ //atomic load/store
62
+ resultf = atomicLoad(buf.dataf, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed);
63
+ atomicStore(buf.dataf, resultf, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed);
64
+ buf.dataf += resultf;
65
+
66
+ resultf = atomicLoad(atomf, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed);
67
+ atomicStore(atomf, resultf, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed);
68
+ buf.dataf += resultf;
69
+
70
+ resultd = atomicLoad(buf.datad, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed);
71
+ atomicStore(buf.datad, resultd, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed);
72
+ buf.datad += resultd;
73
+
74
+ resultd = atomicLoad(atomd, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed);
75
+ atomicStore(atomd, resultd, gl_ScopeDevice, gl_StorageSemanticsShared, gl_SemanticsRelaxed);
76
+ buf.datad += resultd;
77
+
78
+ // image atomics on 1D:
79
+ atomf = imageAtomicAdd(fimage1D, int(0), 2.0);
80
+ buf.dataf += atomf;
81
+ atomf = imageAtomicAdd(fimage1D, int(1), 3.0, gl_ScopeDevice, gl_StorageSemanticsImage , gl_SemanticsRelaxed);
82
+ buf.dataf += atomf;
83
+
84
+ atomf = imageAtomicExchange(fimage1D, int(1), 4.0, gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed);
85
+ buf.dataf += atomf;
86
+
87
+ atomf = imageAtomicLoad(fimage1D, int(1), gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed);
88
+ buf.dataf += atomf;
89
+
90
+ imageAtomicStore(fimage1D, int(2), atomf, gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed);
91
+ buf.dataf += atomf;
92
+
93
+ // image atomics on 1D Array:
94
+ atomf = imageAtomicAdd(fimage1DArray, ivec2(0,0), 2.0);
95
+ buf.dataf += atomf;
96
+ atomf = imageAtomicAdd(fimage1DArray, ivec2(1,1), 3.0, gl_ScopeDevice, gl_StorageSemanticsImage , gl_SemanticsRelaxed);
97
+ buf.dataf += atomf;
98
+
99
+ atomf = imageAtomicExchange(fimage1DArray, ivec2(1,0), 4.0, gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed);
100
+ buf.dataf += atomf;
101
+
102
+ atomf = imageAtomicLoad(fimage1DArray, ivec2(1,1), gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed);
103
+ buf.dataf += atomf;
104
+
105
+ imageAtomicStore(fimage1DArray, ivec2(2,2), atomf, gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed);
106
+ buf.dataf += atomf;
107
+
108
+ // image atomics on 2D:
109
+ atomf = imageAtomicAdd(fimage2D, ivec2(0,0), 2.0);
110
+ buf.dataf += atomf;
111
+ atomf = imageAtomicAdd(fimage2D, ivec2(1,1), 3.0, gl_ScopeDevice, gl_StorageSemanticsImage , gl_SemanticsRelaxed);
112
+ buf.dataf += atomf;
113
+
114
+ atomf = imageAtomicExchange(fimage2D, ivec2(1,0), 4.0, gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed);
115
+ buf.dataf += atomf;
116
+
117
+ atomf = imageAtomicLoad(fimage2D, ivec2(1,1), gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed);
118
+ buf.dataf += atomf;
119
+
120
+ imageAtomicStore(fimage2D, ivec2(2,2), atomf, gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed);
121
+ buf.dataf += atomf;
122
+
123
+ // image atomics on 2D Rect:
124
+ atomf = imageAtomicAdd(fimage2DRect, ivec2(0,0), 2.0);
125
+ buf.dataf += atomf;
126
+ atomf = imageAtomicAdd(fimage2DRect, ivec2(1,1), 3.0, gl_ScopeDevice, gl_StorageSemanticsImage , gl_SemanticsRelaxed);
127
+ buf.dataf += atomf;
128
+
129
+ atomf = imageAtomicExchange(fimage2DRect, ivec2(1,0), 4.0, gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed);
130
+ buf.dataf += atomf;
131
+
132
+ atomf = imageAtomicLoad(fimage2DRect, ivec2(1,1), gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed);
133
+ buf.dataf += atomf;
134
+
135
+ imageAtomicStore(fimage2DRect, ivec2(2,2), atomf, gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed);
136
+ buf.dataf += atomf;
137
+
138
+ // image atomics on 2D Array:
139
+ atomf = imageAtomicAdd(fimage2DArray, ivec3(0,0,0), 2.0);
140
+ buf.dataf += atomf;
141
+ atomf = imageAtomicAdd(fimage2DArray, ivec3(1,1,0), 3.0, gl_ScopeDevice, gl_StorageSemanticsImage , gl_SemanticsRelaxed);
142
+ buf.dataf += atomf;
143
+
144
+ atomf = imageAtomicExchange(fimage2DArray, ivec3(1,0,1), 4.0, gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed);
145
+ buf.dataf += atomf;
146
+
147
+ atomf = imageAtomicLoad(fimage2DArray, ivec3(1,1,1), gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed);
148
+ buf.dataf += atomf;
149
+
150
+ imageAtomicStore(fimage2DArray, ivec3(2,2,0), atomf, gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed);
151
+ buf.dataf += atomf;
152
+
153
+ // image atomics on Cube:
154
+ atomf = imageAtomicAdd(fimageCube, ivec3(0,0,0), 2.0);
155
+ buf.dataf += atomf;
156
+ atomf = imageAtomicAdd(fimageCube, ivec3(1,1,0), 3.0, gl_ScopeDevice, gl_StorageSemanticsImage , gl_SemanticsRelaxed);
157
+ buf.dataf += atomf;
158
+
159
+ atomf = imageAtomicExchange(fimageCube, ivec3(1,0,0), 4.0, gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed);
160
+ buf.dataf += atomf;
161
+
162
+ atomf = imageAtomicLoad(fimageCube, ivec3(1,1,1), gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed);
163
+ buf.dataf += atomf;
164
+
165
+ imageAtomicStore(fimageCube, ivec3(2,2,1), atomf, gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed);
166
+ buf.dataf += atomf;
167
+
168
+ // image atomics on Cube Array:
169
+ atomf = imageAtomicAdd(fimageCubeArray, ivec3(0,0,0), 2.0);
170
+ buf.dataf += atomf;
171
+ atomf = imageAtomicAdd(fimageCubeArray, ivec3(1,1,0), 3.0, gl_ScopeDevice, gl_StorageSemanticsImage , gl_SemanticsRelaxed);
172
+ buf.dataf += atomf;
173
+
174
+ atomf = imageAtomicExchange(fimageCubeArray, ivec3(1,0,1), 4.0, gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed);
175
+ buf.dataf += atomf;
176
+
177
+ atomf = imageAtomicLoad(fimageCubeArray, ivec3(1,1,1), gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed);
178
+ buf.dataf += atomf;
179
+
180
+ imageAtomicStore(fimageCubeArray, ivec3(2,2,0), atomf, gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed);
181
+ buf.dataf += atomf;
182
+
183
+ // image atomics on 3D:
184
+ atomf = imageAtomicAdd(fimage3D, ivec3(0,0,0), 2.0);
185
+ buf.dataf += atomf;
186
+ atomf = imageAtomicAdd(fimage3D, ivec3(1,1,0), 3.0, gl_ScopeDevice, gl_StorageSemanticsImage , gl_SemanticsRelaxed);
187
+ buf.dataf += atomf;
188
+
189
+ atomf = imageAtomicExchange(fimage3D, ivec3(1,0,1), 4.0, gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed);
190
+ buf.dataf += atomf;
191
+
192
+ atomf = imageAtomicLoad(fimage3D, ivec3(1,1,1), gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed);
193
+ buf.dataf += atomf;
194
+
195
+ imageAtomicStore(fimage3D, ivec3(2,2,0), atomf, gl_ScopeDevice, gl_StorageSemanticsImage, gl_SemanticsRelaxed);
196
+ buf.dataf += atomf;
197
+ }
0 commit comments