Non-Functional: Add postprocess as more robust way to add capabilities
When capabilities are needed for specific SPIR-V instructions, it is
fragile to do so based on GLSL/AST usage; it should be based on actual
instructions they got translated to.
diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp
index c3e7940..86c4d49 100755
--- a/SPIRV/GlslangToSpv.cpp
+++ b/SPIRV/GlslangToSpv.cpp
@@ -1191,6 +1191,7 @@
// Finish creating SPV, after the traversal is complete.
void TGlslangToSpvTraverser::finishSpv()
{
+ // Finish the entry point function
if (! entryPointTerminated) {
builder.setBuildPoint(shaderEntry->getLastBlock());
builder.leaveFunction();
@@ -1200,7 +1201,9 @@
for (auto it = iOSet.cbegin(); it != iOSet.cend(); ++it)
entryPoint->addIdOperand(*it);
- builder.eliminateDeadDecorations();
+ // Add capabilities, extensions, remove unneeded decorations, etc.,
+ // based on the resulting SPIR-V.
+ builder.postProcess();
}
// Write the SPV into 'out'.
@@ -4627,27 +4630,21 @@
unaryOp = spv::OpFwidth;
break;
case glslang::EOpDPdxFine:
- builder.addCapability(spv::CapabilityDerivativeControl);
unaryOp = spv::OpDPdxFine;
break;
case glslang::EOpDPdyFine:
- builder.addCapability(spv::CapabilityDerivativeControl);
unaryOp = spv::OpDPdyFine;
break;
case glslang::EOpFwidthFine:
- builder.addCapability(spv::CapabilityDerivativeControl);
unaryOp = spv::OpFwidthFine;
break;
case glslang::EOpDPdxCoarse:
- builder.addCapability(spv::CapabilityDerivativeControl);
unaryOp = spv::OpDPdxCoarse;
break;
case glslang::EOpDPdyCoarse:
- builder.addCapability(spv::CapabilityDerivativeControl);
unaryOp = spv::OpDPdyCoarse;
break;
case glslang::EOpFwidthCoarse:
- builder.addCapability(spv::CapabilityDerivativeControl);
unaryOp = spv::OpFwidthCoarse;
break;
case glslang::EOpInterpolateAtCentroid:
@@ -4655,7 +4652,6 @@
if (typeProxy == glslang::EbtFloat16)
builder.addExtension(spv::E_SPV_AMD_gpu_shader_half_float);
#endif
- builder.addCapability(spv::CapabilityInterpolationFunction);
libCall = spv::GLSLstd450InterpolateAtCentroid;
break;
case glslang::EOpAny:
@@ -4791,8 +4787,6 @@
#endif
#ifdef NV_EXTENSIONS
case glslang::EOpSubgroupPartition:
- builder.addExtension(spv::E_SPV_NV_shader_subgroup_partitioned);
- builder.addCapability(spv::CapabilityGroupNonUniformPartitionedNV);
unaryOp = spv::OpGroupNonUniformPartitionNV;
break;
#endif
@@ -6087,7 +6081,6 @@
if (typeProxy == glslang::EbtFloat16)
builder.addExtension(spv::E_SPV_AMD_gpu_shader_half_float);
#endif
- builder.addCapability(spv::CapabilityInterpolationFunction);
libCall = spv::GLSLstd450InterpolateAtSample;
break;
case glslang::EOpInterpolateAtOffset:
@@ -6095,7 +6088,6 @@
if (typeProxy == glslang::EbtFloat16)
builder.addExtension(spv::E_SPV_AMD_gpu_shader_half_float);
#endif
- builder.addCapability(spv::CapabilityInterpolationFunction);
libCall = spv::GLSLstd450InterpolateAtOffset;
break;
case glslang::EOpAddCarry: