Implement GL_EXT_terminate_invocation (#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>
This commit is contained in:
Jesse Hall 2020-11-09 08:30:01 -08:00 committed by GitHub
parent 383eaf3293
commit 74e8f05b9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 6223 additions and 5846 deletions

View file

@ -49,4 +49,6 @@ static const char* const E_SPV_KHR_non_semantic_info = "SPV_KHR_non_s
static const char* const E_SPV_KHR_ray_tracing = "SPV_KHR_ray_tracing";
static const char* const E_SPV_KHR_ray_query = "SPV_KHR_ray_query";
static const char* const E_SPV_KHR_fragment_shading_rate = "SPV_KHR_fragment_shading_rate";
static const char* const E_SPV_KHR_terminate_invocation = "SPV_KHR_terminate_invocation";
#endif // #ifndef GLSLextKHR_H

View file

@ -3458,6 +3458,10 @@ bool TGlslangToSpvTraverser::visitBranch(glslang::TVisit /* visit */, glslang::T
case glslang::EOpKill:
builder.makeDiscard();
break;
case glslang::EOpTerminateInvocation:
builder.addExtension(spv::E_SPV_KHR_terminate_invocation);
builder.makeTerminateInvocation();
break;
case glslang::EOpBreak:
if (breakForLoop.top())
builder.createLoopExit();

View file

@ -1453,6 +1453,13 @@ void Builder::makeDiscard()
createAndSetNoPredecessorBlock("post-discard");
}
// Comments in header
void Builder::makeTerminateInvocation()
{
buildPoint->addInstruction(std::unique_ptr<Instruction>(new Instruction(OpTerminateInvocation)));
createAndSetNoPredecessorBlock("post-terminate-invocation");
}
// Comments in header
Id Builder::createVariable(Decoration precision, StorageClass storageClass, Id type, const char* name, Id initializer)
{

View file

@ -357,8 +357,9 @@ public:
// Generate all the code needed to finish up a function.
void leaveFunction();
// Create a discard.
// Create a discard or terminate-invocation.
void makeDiscard();
void makeTerminateInvocation();
// Create a global or function local or IO variable.
Id createVariable(Decoration precision, StorageClass, Id type, const char* name = nullptr,

View file

@ -1336,6 +1336,8 @@ const char* OpcodeString(int op)
case 365: return "OpGroupNonUniformQuadBroadcast";
case 366: return "OpGroupNonUniformQuadSwap";
case OpTerminateInvocation: return "OpTerminateInvocation";
case 4421: return "OpSubgroupBallotKHR";
case 4422: return "OpSubgroupFirstInvocationKHR";
case 4428: return "OpSubgroupAllKHR";
@ -1504,6 +1506,7 @@ void Parameterize()
InstructionDesc[OpBranchConditional].setResultAndType(false, false);
InstructionDesc[OpSwitch].setResultAndType(false, false);
InstructionDesc[OpKill].setResultAndType(false, false);
InstructionDesc[OpTerminateInvocation].setResultAndType(false, false);
InstructionDesc[OpReturn].setResultAndType(false, false);
InstructionDesc[OpReturnValue].setResultAndType(false, false);
InstructionDesc[OpUnreachable].setResultAndType(false, false);

View file

@ -1849,6 +1849,7 @@ inline void HasResultAndType(Op opcode, bool *hasResult, bool *hasResultType) {
case OpBranchConditional: *hasResult = false; *hasResultType = false; break;
case OpSwitch: *hasResult = false; *hasResultType = false; break;
case OpKill: *hasResult = false; *hasResultType = false; break;
case OpTerminateInvocation: *hasResult = false; *hasResultType = false; break;
case OpReturn: *hasResult = false; *hasResultType = false; break;
case OpReturnValue: *hasResult = false; *hasResultType = false; break;
case OpUnreachable: *hasResult = false; *hasResultType = false; break;

View file

@ -263,6 +263,7 @@ public:
case OpBranchConditional:
case OpSwitch:
case OpKill:
case OpTerminateInvocation:
case OpReturn:
case OpReturnValue:
case OpUnreachable: