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,6 +3629,29 @@ TIntermTyped *TParseContext::addFunctionCallOrMethod(TFunction *fnCall, TIntermN ...@@ -3629,6 +3629,29 @@ TIntermTyped *TParseContext::addFunctionCallOrMethod(TFunction *fnCall, TIntermN
callNode = aggregate; callNode = aggregate;
if(op == EOpClamp)
{
// Special case for clamp -- try to fold it as min(max(t, minVal), maxVal)
TIntermSequence &parameters = paramNode->getAsAggregate()->getSequence();
TIntermConstantUnion *valConstant = parameters[0]->getAsTyped()->getAsConstantUnion();
TIntermConstantUnion *minConstant = parameters[1]->getAsTyped()->getAsConstantUnion();
TIntermConstantUnion *maxConstant = parameters[2]->getAsTyped()->getAsConstantUnion();
if (valConstant && minConstant && maxConstant)
{
TIntermTyped *typedReturnNode = valConstant->fold(EOpMax, minConstant, infoSink());
if (typedReturnNode && typedReturnNode->getAsConstantUnion())
{
typedReturnNode = maxConstant->fold(EOpMin, typedReturnNode->getAsConstantUnion(), infoSink());
}
if (typedReturnNode)
{
callNode = typedReturnNode;
}
}
}
else
{
if(fnCandidate->getParamCount() == 2) if(fnCandidate->getParamCount() == 2)
{ {
TIntermSequence &parameters = paramNode->getAsAggregate()->getSequence(); TIntermSequence &parameters = paramNode->getAsAggregate()->getSequence();
...@@ -3649,6 +3672,7 @@ TIntermTyped *TParseContext::addFunctionCallOrMethod(TFunction *fnCall, TIntermN ...@@ -3649,6 +3672,7 @@ TIntermTyped *TParseContext::addFunctionCallOrMethod(TFunction *fnCall, TIntermN
} }
} }
} }
}
else else
{ {
// This is a real function call // This is a real function call
......
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