Commit 9a20cc97 by Chris Forbes

Add support for constant folding of clamp()

Fixes: dEQP-GLES3.functional.shaders.constant_expressions.other.complex* Bug: b/116598062 Change-Id: Ife2dd2edad17d6ebbd02653f484637672ce6af0a Reviewed-on: https://swiftshader-review.googlesource.com/20828Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarChris Forbes <chrisforbes@google.com>
parent c5e68abd
...@@ -3629,24 +3629,48 @@ TIntermTyped *TParseContext::addFunctionCallOrMethod(TFunction *fnCall, TIntermN ...@@ -3629,24 +3629,48 @@ TIntermTyped *TParseContext::addFunctionCallOrMethod(TFunction *fnCall, TIntermN
callNode = aggregate; callNode = aggregate;
if(fnCandidate->getParamCount() == 2) if(op == EOpClamp)
{ {
// Special case for clamp -- try to fold it as min(max(t, minVal), maxVal)
TIntermSequence &parameters = paramNode->getAsAggregate()->getSequence(); TIntermSequence &parameters = paramNode->getAsAggregate()->getSequence();
TIntermTyped *left = parameters[0]->getAsTyped(); TIntermConstantUnion *valConstant = parameters[0]->getAsTyped()->getAsConstantUnion();
TIntermTyped *right = parameters[1]->getAsTyped(); TIntermConstantUnion *minConstant = parameters[1]->getAsTyped()->getAsConstantUnion();
TIntermConstantUnion *maxConstant = parameters[2]->getAsTyped()->getAsConstantUnion();
TIntermConstantUnion *leftTempConstant = left->getAsConstantUnion(); if (valConstant && minConstant && maxConstant)
TIntermConstantUnion *rightTempConstant = right->getAsConstantUnion();
if (leftTempConstant && rightTempConstant)
{ {
TIntermTyped *typedReturnNode = leftTempConstant->fold(op, rightTempConstant, infoSink()); TIntermTyped *typedReturnNode = valConstant->fold(EOpMax, minConstant, infoSink());
if (typedReturnNode && typedReturnNode->getAsConstantUnion())
if(typedReturnNode) {
typedReturnNode = maxConstant->fold(EOpMin, typedReturnNode->getAsConstantUnion(), infoSink());
}
if (typedReturnNode)
{ {
callNode = typedReturnNode; callNode = typedReturnNode;
} }
} }
} }
else
{
if(fnCandidate->getParamCount() == 2)
{
TIntermSequence &parameters = paramNode->getAsAggregate()->getSequence();
TIntermTyped *left = parameters[0]->getAsTyped();
TIntermTyped *right = parameters[1]->getAsTyped();
TIntermConstantUnion *leftTempConstant = left->getAsConstantUnion();
TIntermConstantUnion *rightTempConstant = right->getAsConstantUnion();
if (leftTempConstant && rightTempConstant)
{
TIntermTyped *typedReturnNode = leftTempConstant->fold(op, rightTempConstant, infoSink());
if(typedReturnNode)
{
callNode = typedReturnNode;
}
}
}
}
} }
} }
else else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment