Commit b75fee4e by Jamie Madill

Fix HLSL compiler error with else-rewriting in functions.

In functions with return types where we would use if-else rewriting, we would potentially generate a spurious HLSL error that warned of branches with no return value in the function. This was causing a maps regression where overlays would not draw in Earth mode. BUG=346463 Change-Id: Icd53023286dfa43b653fd6e261b1cdb952627706 Reviewed-on: https://chromium-review.googlesource.com/187847Reviewed-by: 's avatarNicolas Capens <nicolascapens@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 19f0ff5c
...@@ -36,11 +36,18 @@ TIntermUnary *MakeNewUnary(TOperator op, TIntermTyped *operand) ...@@ -36,11 +36,18 @@ TIntermUnary *MakeNewUnary(TOperator op, TIntermTyped *operand)
return unary; return unary;
} }
ElseBlockRewriter::ElseBlockRewriter()
: TIntermTraverser(true, false, true, false),
mTemporaryIndex(0),
mFunctionType(NULL)
{}
bool ElseBlockRewriter::visitAggregate(Visit visit, TIntermAggregate *node) bool ElseBlockRewriter::visitAggregate(Visit visit, TIntermAggregate *node)
{ {
switch (node->getOp()) switch (node->getOp())
{ {
case EOpSequence: case EOpSequence:
if (visit == PostVisit)
{ {
for (size_t statementIndex = 0; statementIndex != node->getSequence().size(); statementIndex++) for (size_t statementIndex = 0; statementIndex != node->getSequence().size(); statementIndex++)
{ {
...@@ -63,6 +70,11 @@ bool ElseBlockRewriter::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -63,6 +70,11 @@ bool ElseBlockRewriter::visitAggregate(Visit visit, TIntermAggregate *node)
} }
break; break;
case EOpFunction:
// Store the current function context (see comment below)
mFunctionType = ((visit == PreVisit) ? &node->getType() : NULL);
break;
default: break; default: break;
} }
...@@ -82,8 +94,22 @@ TIntermNode *ElseBlockRewriter::rewriteSelection(TIntermSelection *selection) ...@@ -82,8 +94,22 @@ TIntermNode *ElseBlockRewriter::rewriteSelection(TIntermSelection *selection)
TIntermBinary *storeCondition = MakeNewBinary(EOpInitialize, conditionSymbolA, TIntermBinary *storeCondition = MakeNewBinary(EOpInitialize, conditionSymbolA,
typedCondition, resultType); typedCondition, resultType);
TIntermUnary *negatedCondition = MakeNewUnary(EOpLogicalNot, conditionSymbolB); TIntermUnary *negatedCondition = MakeNewUnary(EOpLogicalNot, conditionSymbolB);
TIntermNode *negatedElse = NULL;
// crbug.com/346463
// D3D generates error messages claiming a function has no return value, when rewriting
// an if-else clause that returns something non-void in a function. By appending dummy
// returns (that are unreachable) we can silence this compile error.
if (mFunctionType && mFunctionType->getBasicType() != EbtVoid)
{
TString typeString = mFunctionType->getStruct() ? mFunctionType->getStruct()->name() :
mFunctionType->getBasicString();
TString rawText = "return (" + typeString + ")0";
negatedElse = new TIntermRaw(*mFunctionType, rawText);
}
TIntermSelection *falseBlock = new TIntermSelection(negatedCondition, TIntermSelection *falseBlock = new TIntermSelection(negatedCondition,
selection->getFalseBlock(), NULL); selection->getFalseBlock(), negatedElse);
TIntermSelection *newIfElse = new TIntermSelection(conditionSymbolC, TIntermSelection *newIfElse = new TIntermSelection(conditionSymbolC,
selection->getTrueBlock(), falseBlock); selection->getTrueBlock(), falseBlock);
......
...@@ -18,16 +18,14 @@ namespace sh ...@@ -18,16 +18,14 @@ namespace sh
class ElseBlockRewriter : public TIntermTraverser class ElseBlockRewriter : public TIntermTraverser
{ {
public: public:
ElseBlockRewriter() ElseBlockRewriter();
: TIntermTraverser(false, false, true, false)
, mTemporaryIndex(0)
{}
protected: protected:
bool visitAggregate(Visit visit, TIntermAggregate *aggregate); bool visitAggregate(Visit visit, TIntermAggregate *aggregate);
private: private:
int mTemporaryIndex; int mTemporaryIndex;
const TType *mFunctionType;
TIntermNode *rewriteSelection(TIntermSelection *selection); TIntermNode *rewriteSelection(TIntermSelection *selection);
}; };
......
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