Make sure type gets set consistently in folded binary operations
Add a wrapper function that handles creating the folded node and setting the
right parameters on it, so that the folding function handles only
calculating the folded values.
This will fix the precision set to constant folded values in some cases.
Previously the precision was always set to be equal to one of the operands
to the binary operation, but now both operands are taken into account.
Folding binary operations is now in a separate function from folding unary
operations.
TEST=dEQP-GLES3.functional.shaders.constant_expressions.*
BUG=angleproject:817
Change-Id: Id97e765173c6110f49607e21c3fb90019b1ebac7
Reviewed-on: https://chromium-review.googlesource.com/274001
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Tested-by: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/Intermediate.cpp b/src/compiler/translator/Intermediate.cpp
index 1d8b36b..5762b1e 100644
--- a/src/compiler/translator/Intermediate.cpp
+++ b/src/compiler/translator/Intermediate.cpp
@@ -57,19 +57,10 @@
if (!node->promote(mInfoSink))
return NULL;
- //
// See if we can fold constants.
- //
- TIntermConstantUnion *leftTempConstant = left->getAsConstantUnion();
- TIntermConstantUnion *rightTempConstant = right->getAsConstantUnion();
- if (leftTempConstant && rightTempConstant)
- {
- TIntermTyped *typedReturnNode =
- leftTempConstant->fold(node->getOp(), rightTempConstant, mInfoSink);
-
- if (typedReturnNode)
- return typedReturnNode;
- }
+ TIntermTyped *foldedNode = node->fold(mInfoSink);
+ if (foldedNode)
+ return foldedNode;
return node;
}
@@ -143,7 +134,7 @@
if (childTempConstant)
{
- TIntermTyped *newChild = childTempConstant->fold(op, nullptr, mInfoSink);
+ TIntermTyped *newChild = childTempConstant->foldUnary(op, mInfoSink);
if (newChild)
return newChild;