Skip to content

Commit 74e8f05

Browse files
critsecjohnkslang
andauthored
Implement GL_EXT_terminate_invocation (KhronosGroup#2454)
* Implement GL_EXT_terminate_invocation. * terminateInvocation: declare the SPV extension * Update test results for spirv-tools and bison version bumps Co-authored-by: John Kessenich <cepheus@frii.com>
1 parent 383eaf3 commit 74e8f05

26 files changed

+6176
-5799
lines changed

SPIRV/GLSL.ext.KHR.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,6 @@ static const char* const E_SPV_KHR_non_semantic_info = "SPV_KHR_non_s
4949
static const char* const E_SPV_KHR_ray_tracing = "SPV_KHR_ray_tracing";
5050
static const char* const E_SPV_KHR_ray_query = "SPV_KHR_ray_query";
5151
static const char* const E_SPV_KHR_fragment_shading_rate = "SPV_KHR_fragment_shading_rate";
52+
static const char* const E_SPV_KHR_terminate_invocation = "SPV_KHR_terminate_invocation";
53+
5254
#endif // #ifndef GLSLextKHR_H

SPIRV/GlslangToSpv.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3458,6 +3458,10 @@ bool TGlslangToSpvTraverser::visitBranch(glslang::TVisit /* visit */, glslang::T
34583458
case glslang::EOpKill:
34593459
builder.makeDiscard();
34603460
break;
3461+
case glslang::EOpTerminateInvocation:
3462+
builder.addExtension(spv::E_SPV_KHR_terminate_invocation);
3463+
builder.makeTerminateInvocation();
3464+
break;
34613465
case glslang::EOpBreak:
34623466
if (breakForLoop.top())
34633467
builder.createLoopExit();

SPIRV/SpvBuilder.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,13 @@ void Builder::makeDiscard()
14531453
createAndSetNoPredecessorBlock("post-discard");
14541454
}
14551455

1456+
// Comments in header
1457+
void Builder::makeTerminateInvocation()
1458+
{
1459+
buildPoint->addInstruction(std::unique_ptr<Instruction>(new Instruction(OpTerminateInvocation)));
1460+
createAndSetNoPredecessorBlock("post-terminate-invocation");
1461+
}
1462+
14561463
// Comments in header
14571464
Id Builder::createVariable(Decoration precision, StorageClass storageClass, Id type, const char* name, Id initializer)
14581465
{

SPIRV/SpvBuilder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,9 @@ class Builder {
357357
// Generate all the code needed to finish up a function.
358358
void leaveFunction();
359359

360-
// Create a discard.
360+
// Create a discard or terminate-invocation.
361361
void makeDiscard();
362+
void makeTerminateInvocation();
362363

363364
// Create a global or function local or IO variable.
364365
Id createVariable(Decoration precision, StorageClass, Id type, const char* name = nullptr,

SPIRV/doc.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,8 @@ const char* OpcodeString(int op)
13361336
case 365: return "OpGroupNonUniformQuadBroadcast";
13371337
case 366: return "OpGroupNonUniformQuadSwap";
13381338

1339+
case OpTerminateInvocation: return "OpTerminateInvocation";
1340+
13391341
case 4421: return "OpSubgroupBallotKHR";
13401342
case 4422: return "OpSubgroupFirstInvocationKHR";
13411343
case 4428: return "OpSubgroupAllKHR";
@@ -1504,6 +1506,7 @@ void Parameterize()
15041506
InstructionDesc[OpBranchConditional].setResultAndType(false, false);
15051507
InstructionDesc[OpSwitch].setResultAndType(false, false);
15061508
InstructionDesc[OpKill].setResultAndType(false, false);
1509+
InstructionDesc[OpTerminateInvocation].setResultAndType(false, false);
15071510
InstructionDesc[OpReturn].setResultAndType(false, false);
15081511
InstructionDesc[OpReturnValue].setResultAndType(false, false);
15091512
InstructionDesc[OpUnreachable].setResultAndType(false, false);

SPIRV/spirv.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,6 +1849,7 @@ inline void HasResultAndType(Op opcode, bool *hasResult, bool *hasResultType) {
18491849
case OpBranchConditional: *hasResult = false; *hasResultType = false; break;
18501850
case OpSwitch: *hasResult = false; *hasResultType = false; break;
18511851
case OpKill: *hasResult = false; *hasResultType = false; break;
1852+
case OpTerminateInvocation: *hasResult = false; *hasResultType = false; break;
18521853
case OpReturn: *hasResult = false; *hasResultType = false; break;
18531854
case OpReturnValue: *hasResult = false; *hasResultType = false; break;
18541855
case OpUnreachable: *hasResult = false; *hasResultType = false; break;

SPIRV/spvIR.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ class Block {
263263
case OpBranchConditional:
264264
case OpSwitch:
265265
case OpKill:
266+
case OpTerminateInvocation:
266267
case OpReturn:
267268
case OpReturnValue:
268269
case OpUnreachable:

Test/baseResults/cppDeepNest.frag.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cppDeepNest.frag
22
ERROR: 0:66: '#if/#ifdef/#ifndef' : maximum nesting depth exceeded
33
ERROR: 0:66: '' : missing #endif
4-
ERROR: 0:66: '' : syntax error, unexpected $end
4+
ERROR: 0:66: '' : syntax error, unexpected end of file
55
ERROR: 3 compilation errors. No code generated.
66

77

Test/baseResults/numeral.frag.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ERROR: 0:88: '' : float literal needs a decimal point or exponent
1212
ERROR: 0:98: '' : numeric literal too big
1313
ERROR: 0:101: '' : numeric literal too big
1414
ERROR: 0:104: '#' : preprocessor directive cannot be preceded by another token
15-
ERROR: 0:104: '' : syntax error, unexpected $end, expecting COMMA or SEMICOLON
15+
ERROR: 0:104: '' : syntax error, unexpected end of file, expecting COMMA or SEMICOLON
1616
ERROR: 14 compilation errors. No code generated.
1717

1818

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
spv.terminate.frag
2+
// Module Version 10000
3+
// Generated by (magic number): 8000a
4+
// Id's are bound by 7
5+
6+
Capability Shader
7+
Extension "SPV_KHR_terminate_invocation"
8+
1: ExtInstImport "GLSL.std.450"
9+
MemoryModel Logical GLSL450
10+
EntryPoint Fragment 4 "main"
11+
ExecutionMode 4 OriginUpperLeft
12+
Source GLSL 400
13+
SourceExtension "GL_EXT_terminate_invocation"
14+
Name 4 "main"
15+
2: TypeVoid
16+
3: TypeFunction 2
17+
4(main): 2 Function None 3
18+
5: Label
19+
TerminateInvocation
20+
FunctionEnd

0 commit comments

Comments
 (0)