Skip to content

Commit 7923b3e

Browse files
authored
Merge pull request KhronosGroup#2353 from vkushwaha-nv/SPV_EXT_shader_atomic_float
Add changes for SPV_EXT_shader_atomic_float_add
2 parents 9165cbb + 79b9392 commit 7923b3e

13 files changed

+1109
-5
lines changed

SPIRV/GLSL.ext.EXT.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ static const char* const E_SPV_EXT_shader_viewport_index_layer = "SPV_EXT_shade
3535
static const char* const E_SPV_EXT_fragment_fully_covered = "SPV_EXT_fragment_fully_covered";
3636
static const char* const E_SPV_EXT_fragment_invocation_density = "SPV_EXT_fragment_invocation_density";
3737
static const char* const E_SPV_EXT_demote_to_helper_invocation = "SPV_EXT_demote_to_helper_invocation";
38+
static const char* const E_SPV_EXT_shader_atomic_float_add = "SPV_EXT_shader_atomic_float_add";
3839

3940
#endif // #ifndef GLSLextEXT_H

SPIRV/GlslangToSpv.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6682,6 +6682,14 @@ spv::Id TGlslangToSpvTraverser::createAtomicOperation(glslang::TOperator op, spv
66826682
case glslang::EOpImageAtomicAdd:
66836683
case glslang::EOpAtomicCounterAdd:
66846684
opCode = spv::OpAtomicIAdd;
6685+
if (typeProxy == glslang::EbtFloat || typeProxy == glslang::EbtDouble) {
6686+
opCode = spv::OpAtomicFAddEXT;
6687+
builder.addExtension(spv::E_SPV_EXT_shader_atomic_float_add);
6688+
if (typeProxy == glslang::EbtFloat)
6689+
builder.addCapability(spv::CapabilityAtomicFloat32AddEXT);
6690+
else
6691+
builder.addCapability(spv::CapabilityAtomicFloat64AddEXT);
6692+
}
66856693
break;
66866694
case glslang::EOpAtomicCounterSubtract:
66876695
opCode = spv::OpAtomicISub;

SPIRV/doc.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,9 @@ const char* CapabilityString(int info)
938938

939939
case CapabilityIntegerFunctions2INTEL: return "CapabilityIntegerFunctions2INTEL";
940940

941+
case CapabilityAtomicFloat32AddEXT: return "AtomicFloat32AddEXT";
942+
case CapabilityAtomicFloat64AddEXT: return "AtomicFloat64AddEXT";
943+
941944
default: return "Bad";
942945
}
943946
}
@@ -1313,6 +1316,8 @@ const char* OpcodeString(int op)
13131316
case 4430: return "OpSubgroupAllEqualKHR";
13141317
case 4432: return "OpSubgroupReadInvocationKHR";
13151318

1319+
case OpAtomicFAddEXT: return "OpAtomicFAddEXT";
1320+
13161321
case 5000: return "OpGroupIAddNonUniformAMD";
13171322
case 5001: return "OpGroupFAddNonUniformAMD";
13181323
case 5002: return "OpGroupFMinNonUniformAMD";
@@ -2260,6 +2265,11 @@ void Parameterize()
22602265
InstructionDesc[OpAtomicIAdd].operands.push(OperandMemorySemantics, "'Semantics'");
22612266
InstructionDesc[OpAtomicIAdd].operands.push(OperandId, "'Value'");
22622267

2268+
InstructionDesc[OpAtomicFAddEXT].operands.push(OperandId, "'Pointer'");
2269+
InstructionDesc[OpAtomicFAddEXT].operands.push(OperandScope, "'Scope'");
2270+
InstructionDesc[OpAtomicFAddEXT].operands.push(OperandMemorySemantics, "'Semantics'");
2271+
InstructionDesc[OpAtomicFAddEXT].operands.push(OperandId, "'Value'");
2272+
22632273
InstructionDesc[OpAtomicISub].operands.push(OperandId, "'Pointer'");
22642274
InstructionDesc[OpAtomicISub].operands.push(OperandScope, "'Scope'");
22652275
InstructionDesc[OpAtomicISub].operands.push(OperandMemorySemantics, "'Semantics'");

Test/baseResults/spv.atomicFloat.comp.out

Lines changed: 658 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
spv.atomicFloat_Error.comp
2+
ERROR: 0:25: 'atomicAdd' : required extension not requested: GL_EXT_shader_atomic_float
3+
ERROR: 0:26: 'atomicAdd' : required extension not requested: GL_EXT_shader_atomic_float
4+
ERROR: 0:27: 'atomicAdd' : required extension not requested: GL_EXT_shader_atomic_float
5+
ERROR: 0:28: 'atomicAdd' : required extension not requested: GL_EXT_shader_atomic_float
6+
ERROR: 0:31: 'atomicAdd' : required extension not requested: GL_EXT_shader_atomic_float
7+
ERROR: 0:32: 'atomicAdd' : required extension not requested: GL_EXT_shader_atomic_float
8+
ERROR: 0:33: 'atomicAdd' : required extension not requested: GL_EXT_shader_atomic_float
9+
ERROR: 0:34: 'atomicAdd' : required extension not requested: GL_EXT_shader_atomic_float
10+
ERROR: 0:37: 'atomicExchange' : required extension not requested: GL_EXT_shader_atomic_float
11+
ERROR: 0:38: 'atomicExchange' : required extension not requested: GL_EXT_shader_atomic_float
12+
ERROR: 0:39: 'atomicExchange' : required extension not requested: GL_EXT_shader_atomic_float
13+
ERROR: 0:40: 'atomicExchange' : required extension not requested: GL_EXT_shader_atomic_float
14+
ERROR: 0:43: 'atomicExchange' : required extension not requested: GL_EXT_shader_atomic_float
15+
ERROR: 0:44: 'atomicExchange' : required extension not requested: GL_EXT_shader_atomic_float
16+
ERROR: 0:45: 'atomicExchange' : required extension not requested: GL_EXT_shader_atomic_float
17+
ERROR: 0:46: 'atomicExchange' : required extension not requested: GL_EXT_shader_atomic_float
18+
ERROR: 0:50: 'atomicLoad' : required extension not requested: GL_EXT_shader_atomic_float
19+
ERROR: 0:51: 'atomicStore' : required extension not requested: GL_EXT_shader_atomic_float
20+
ERROR: 0:52: 'atomicLoad' : required extension not requested: GL_EXT_shader_atomic_float
21+
ERROR: 0:53: 'atomicStore' : required extension not requested: GL_EXT_shader_atomic_float
22+
ERROR: 0:56: 'atomicLoad' : required extension not requested: GL_EXT_shader_atomic_float
23+
ERROR: 0:57: 'atomicStore' : required extension not requested: GL_EXT_shader_atomic_float
24+
ERROR: 0:58: 'atomicLoad' : required extension not requested: GL_EXT_shader_atomic_float
25+
ERROR: 0:59: 'atomicStore' : required extension not requested: GL_EXT_shader_atomic_float
26+
ERROR: 0:63: 'imageAtomicAdd' : required extension not requested: GL_EXT_shader_atomic_float
27+
ERROR: 0:64: 'imageAtomicAdd' : required extension not requested: GL_EXT_shader_atomic_float
28+
ERROR: 0:66: 'imageAtomicLoad' : required extension not requested: GL_EXT_shader_atomic_float
29+
ERROR: 0:67: 'imageAtomicStore' : required extension not requested: GL_EXT_shader_atomic_float
30+
ERROR: 0:80: 'atomicAdd' : no matching overloaded function found
31+
ERROR: 0:81: 'atomicAdd' : no matching overloaded function found
32+
ERROR: 0:82: 'atomicAdd' : no matching overloaded function found
33+
ERROR: 0:83: 'atomicAdd' : no matching overloaded function found
34+
ERROR: 0:86: 'atomicExchange' : no matching overloaded function found
35+
ERROR: 0:87: 'atomicExchange' : no matching overloaded function found
36+
ERROR: 0:88: 'atomicExchange' : no matching overloaded function found
37+
ERROR: 0:89: 'atomicExchange' : no matching overloaded function found
38+
ERROR: 0:90: 'atomicExchange' : no matching overloaded function found
39+
ERROR: 0:91: 'atomicExchange' : no matching overloaded function found
40+
ERROR: 0:95: 'atomicLoad' : no matching overloaded function found
41+
ERROR: 0:96: 'atomicStore' : no matching overloaded function found
42+
ERROR: 0:99: 'imageAtomicAdd' : no matching overloaded function found
43+
ERROR: 0:100: 'imageAtomicAdd' : no matching overloaded function found
44+
ERROR: 0:101: 'imageAtomicAdd' : no matching overloaded function found
45+
ERROR: 0:102: 'imageAtomicExchange' : no matching overloaded function found
46+
ERROR: 0:103: 'imageAtomicExchange' : no matching overloaded function found
47+
ERROR: 0:104: 'imageAtomicExchange' : no matching overloaded function found
48+
ERROR: 0:105: 'imageAtomicLoad' : no matching overloaded function found
49+
ERROR: 0:106: 'imageAtomicLoad' : no matching overloaded function found
50+
ERROR: 0:107: 'imageAtomicLoad' : no matching overloaded function found
51+
ERROR: 0:108: 'imageAtomicStore' : no matching overloaded function found
52+
ERROR: 0:109: 'imageAtomicStore' : no matching overloaded function found
53+
ERROR: 0:110: 'imageAtomicStore' : no matching overloaded function found
54+
ERROR: 52 compilation errors. No code generated.
55+
56+
57+
SPIR-V is not generated for failed compile or link

Test/spv.atomicFloat.comp

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
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

Comments
 (0)