Front-end: Implement 2nd task of issue #400; precision of result and operation.
From the ES spec + Bugzilla 15931 and GL_KHR_vulkan_glsl:
- Update precision qualifiers for all built-in function prototypes.
- Implement the new algorithm used to distinguish built-in function
operation precisions from result precisions.
Also add tracking of separate result and operation precisions, and
use that in generating SPIR-V.
(SPIR-V cares about precision of operation, while the front-end
cares about precision of result, for propagation.)
diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp
index be266ac..6aec9e6 100755
--- a/SPIRV/GlslangToSpv.cpp
+++ b/SPIRV/GlslangToSpv.cpp
@@ -283,10 +283,10 @@
}
}
-// Translate glslang type to SPIR-V precision decorations.
-spv::Decoration TranslatePrecisionDecoration(const glslang::TType& type)
+// Translate glslang precision to SPIR-V precision decorations.
+spv::Decoration TranslatePrecisionDecoration(glslang::TPrecisionQualifier glslangPrecision)
{
- switch (type.getQualifier().precision) {
+ switch (glslangPrecision) {
case glslang::EpqLow: return spv::DecorationRelaxedPrecision;
case glslang::EpqMedium: return spv::DecorationRelaxedPrecision;
default:
@@ -294,6 +294,12 @@
}
}
+// Translate glslang type to SPIR-V precision decorations.
+spv::Decoration TranslatePrecisionDecoration(const glslang::TType& type)
+{
+ return TranslatePrecisionDecoration(type.getQualifier().precision);
+}
+
// Translate glslang type to SPIR-V block decorations.
spv::Decoration TranslateBlockDecoration(const glslang::TType& type)
{
@@ -940,7 +946,7 @@
spv::Id leftRValue = accessChainLoad(node->getLeft()->getType());
// do the operation
- rValue = createBinaryOperation(node->getOp(), TranslatePrecisionDecoration(node->getType()),
+ rValue = createBinaryOperation(node->getOp(), TranslatePrecisionDecoration(node->getOperationPrecision()),
TranslateNoContractionDecoration(node->getType().getQualifier()),
convertGlslangToSpvType(node->getType()), leftRValue, rValue,
node->getType().getBasicType());
@@ -1065,7 +1071,7 @@
spv::Id right = accessChainLoad(node->getRight()->getType());
// get result
- spv::Id result = createBinaryOperation(node->getOp(), TranslatePrecisionDecoration(node->getType()),
+ spv::Id result = createBinaryOperation(node->getOp(), TranslatePrecisionDecoration(node->getOperationPrecision()),
TranslateNoContractionDecoration(node->getType().getQualifier()),
convertGlslangToSpvType(node->getType()), left, right,
node->getLeft()->getType().getBasicType());
@@ -1142,7 +1148,7 @@
else
operand = accessChainLoad(node->getOperand()->getType());
- spv::Decoration precision = TranslatePrecisionDecoration(node->getType());
+ spv::Decoration precision = TranslatePrecisionDecoration(node->getOperationPrecision());
spv::Decoration noContraction = TranslateNoContractionDecoration(node->getType().getQualifier());
// it could be a conversion
@@ -1187,7 +1193,7 @@
else
op = glslang::EOpSub;
- spv::Id result = createBinaryOperation(op, TranslatePrecisionDecoration(node->getType()),
+ spv::Id result = createBinaryOperation(op, precision,
TranslateNoContractionDecoration(node->getType().getQualifier()),
convertGlslangToSpvType(node->getType()), operand, one,
node->getType().getBasicType());
@@ -1249,7 +1255,7 @@
assert(node->getOp());
- spv::Decoration precision = TranslatePrecisionDecoration(node->getType());
+ spv::Decoration precision = TranslatePrecisionDecoration(node->getOperationPrecision());
switch (node->getOp()) {
case glslang::EOpSequence:
@@ -2573,7 +2579,7 @@
translateArguments(*node->getAsAggregate(), arguments);
else
translateArguments(*node->getAsUnaryNode(), arguments);
- spv::Decoration precision = TranslatePrecisionDecoration(node->getType());
+ spv::Decoration precision = TranslatePrecisionDecoration(node->getOperationPrecision());
spv::Builder::TextureParameters params = { };
params.sampler = arguments[0];