summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/angle/src/compiler/translator/RecordConstantPrecision.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/angle/src/compiler/translator/RecordConstantPrecision.cpp')
-rw-r--r--src/3rdparty/angle/src/compiler/translator/RecordConstantPrecision.cpp94
1 files changed, 52 insertions, 42 deletions
diff --git a/src/3rdparty/angle/src/compiler/translator/RecordConstantPrecision.cpp b/src/3rdparty/angle/src/compiler/translator/RecordConstantPrecision.cpp
index 14e88b749a..5233a29f19 100644
--- a/src/3rdparty/angle/src/compiler/translator/RecordConstantPrecision.cpp
+++ b/src/3rdparty/angle/src/compiler/translator/RecordConstantPrecision.cpp
@@ -3,20 +3,24 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
-// During parsing, all constant expressions are folded to constant union nodes. The expressions that have been
-// folded may have had precision qualifiers, which should affect the precision of the consuming operation.
-// If the folded constant union nodes are written to output as such they won't have any precision qualifiers,
-// and their effect on the precision of the consuming operation is lost.
+// During parsing, all constant expressions are folded to constant union nodes. The expressions that
+// have been folded may have had precision qualifiers, which should affect the precision of the
+// consuming operation. If the folded constant union nodes are written to output as such they won't
+// have any precision qualifiers, and their effect on the precision of the consuming operation is
+// lost.
//
-// RecordConstantPrecision is an AST traverser that inspects the precision qualifiers of constants and hoists
-// the constants outside the containing expression as precision qualified named variables in case that is
-// required for correct precision propagation.
+// RecordConstantPrecision is an AST traverser that inspects the precision qualifiers of constants
+// and hoists the constants outside the containing expression as precision qualified named variables
+// in case that is required for correct precision propagation.
//
#include "compiler/translator/RecordConstantPrecision.h"
#include "compiler/translator/InfoSink.h"
-#include "compiler/translator/IntermNode.h"
+#include "compiler/translator/IntermTraverse.h"
+
+namespace sh
+{
namespace
{
@@ -24,7 +28,7 @@ namespace
class RecordConstantPrecisionTraverser : public TIntermTraverser
{
public:
- RecordConstantPrecisionTraverser();
+ RecordConstantPrecisionTraverser(TSymbolTable *symbolTable);
void visitConstantUnion(TIntermConstantUnion *node) override;
@@ -37,14 +41,18 @@ class RecordConstantPrecisionTraverser : public TIntermTraverser
bool mFoundHigherPrecisionConstant;
};
-RecordConstantPrecisionTraverser::RecordConstantPrecisionTraverser()
- : TIntermTraverser(true, false, true),
- mFoundHigherPrecisionConstant(false)
+RecordConstantPrecisionTraverser::RecordConstantPrecisionTraverser(TSymbolTable *symbolTable)
+ : TIntermTraverser(true, false, true, symbolTable), mFoundHigherPrecisionConstant(false)
{
}
bool RecordConstantPrecisionTraverser::operandAffectsParentOperationPrecision(TIntermTyped *operand)
{
+ if (getParentNode()->getAsCaseNode() || getParentNode()->getAsBlock())
+ {
+ return false;
+ }
+
const TIntermBinary *parentAsBinary = getParentNode()->getAsBinaryNode();
if (parentAsBinary != nullptr)
{
@@ -52,15 +60,15 @@ bool RecordConstantPrecisionTraverser::operandAffectsParentOperationPrecision(TI
// its precision has no effect.
switch (parentAsBinary->getOp())
{
- case EOpInitialize:
- case EOpAssign:
- case EOpIndexDirect:
- case EOpIndexDirectStruct:
- case EOpIndexDirectInterfaceBlock:
- case EOpIndexIndirect:
- return false;
- default:
- break;
+ case EOpInitialize:
+ case EOpAssign:
+ case EOpIndexDirect:
+ case EOpIndexDirectStruct:
+ case EOpIndexDirectInterfaceBlock:
+ case EOpIndexIndirect:
+ return false;
+ default:
+ break;
}
TIntermTyped *otherOperand = parentAsBinary->getRight();
@@ -68,9 +76,10 @@ bool RecordConstantPrecisionTraverser::operandAffectsParentOperationPrecision(TI
{
otherOperand = parentAsBinary->getLeft();
}
- // If the precision of the other child is at least as high as the precision of the constant, the precision of
- // the constant has no effect.
- if (otherOperand->getAsConstantUnion() == nullptr && otherOperand->getPrecision() >= operand->getPrecision())
+ // If the precision of the other child is at least as high as the precision of the constant,
+ // the precision of the constant has no effect.
+ if (otherOperand->getAsConstantUnion() == nullptr &&
+ otherOperand->getPrecision() >= operand->getPrecision())
{
return false;
}
@@ -92,14 +101,15 @@ bool RecordConstantPrecisionTraverser::operandAffectsParentOperationPrecision(TI
{
return false;
}
- // If the precision of operands does affect the result, but the precision of any of the other children
- // has a precision that's at least as high as the precision of the constant, the precision of the constant
- // has no effect.
+ // If the precision of operands does affect the result, but the precision of any of the
+ // other children has a precision that's at least as high as the precision of the constant,
+ // the precision of the constant has no effect.
TIntermSequence *parameters = parentAsAggregate->getSequence();
for (TIntermNode *parameter : *parameters)
{
const TIntermTyped *typedParameter = parameter->getAsTyped();
- if (parameter != operand && typedParameter != nullptr && parameter->getAsConstantUnion() == nullptr &&
+ if (parameter != operand && typedParameter != nullptr &&
+ parameter->getAsConstantUnion() == nullptr &&
typedParameter->getPrecision() >= operand->getPrecision())
{
return false;
@@ -114,37 +124,36 @@ void RecordConstantPrecisionTraverser::visitConstantUnion(TIntermConstantUnion *
if (mFoundHigherPrecisionConstant)
return;
- // If the constant has lowp or undefined precision, it can't increase the precision of consuming operations.
+ // If the constant has lowp or undefined precision, it can't increase the precision of consuming
+ // operations.
if (node->getPrecision() < EbpMedium)
return;
- // It's possible the node has no effect on the precision of the consuming expression, depending on the
- // consuming expression, and the precision of the other parameters of the expression.
+ // It's possible the node has no effect on the precision of the consuming expression, depending
+ // on the consuming expression, and the precision of the other parameters of the expression.
if (!operandAffectsParentOperationPrecision(node))
return;
- // Make the constant a precision-qualified named variable to make sure it affects the precision of the consuming
- // expression.
+ // Make the constant a precision-qualified named variable to make sure it affects the precision
+ // of the consuming expression.
TIntermSequence insertions;
insertions.push_back(createTempInitDeclaration(node, EvqConst));
insertStatementsInParentBlock(insertions);
- mReplacements.push_back(NodeUpdateEntry(getParentNode(), node, createTempSymbol(node->getType()), false));
+ queueReplacement(createTempSymbol(node->getType()), OriginalNode::IS_DROPPED);
mFoundHigherPrecisionConstant = true;
}
void RecordConstantPrecisionTraverser::nextIteration()
{
- nextTemporaryIndex();
+ nextTemporaryId();
mFoundHigherPrecisionConstant = false;
}
-} // namespace
+} // namespace
-void RecordConstantPrecision(TIntermNode *root, unsigned int *temporaryIndex)
+void RecordConstantPrecision(TIntermNode *root, TSymbolTable *symbolTable)
{
- RecordConstantPrecisionTraverser traverser;
- ASSERT(temporaryIndex != nullptr);
- traverser.useTemporaryIndex(temporaryIndex);
+ RecordConstantPrecisionTraverser traverser(symbolTable);
// Iterate as necessary, and reset the traverser between iterations.
do
{
@@ -152,6 +161,7 @@ void RecordConstantPrecision(TIntermNode *root, unsigned int *temporaryIndex)
root->traverse(&traverser);
if (traverser.foundHigherPrecisionConstant())
traverser.updateTree();
- }
- while (traverser.foundHigherPrecisionConstant());
+ } while (traverser.foundHigherPrecisionConstant());
}
+
+} // namespace sh