diff options
Diffstat (limited to 'gfx/angle/src/compiler/translator/RemoveDynamicIndexing.cpp')
-rwxr-xr-x | gfx/angle/src/compiler/translator/RemoveDynamicIndexing.cpp | 73 |
1 files changed, 38 insertions, 35 deletions
diff --git a/gfx/angle/src/compiler/translator/RemoveDynamicIndexing.cpp b/gfx/angle/src/compiler/translator/RemoveDynamicIndexing.cpp index 31914dcf36..37955e7360 100755 --- a/gfx/angle/src/compiler/translator/RemoveDynamicIndexing.cpp +++ b/gfx/angle/src/compiler/translator/RemoveDynamicIndexing.cpp @@ -14,9 +14,6 @@ #include "compiler/translator/IntermNodePatternMatcher.h" #include "compiler/translator/SymbolTable.h" -namespace sh -{ - namespace { @@ -95,15 +92,21 @@ TIntermBinary *CreateIndexDirectBaseSymbolNode(const TType &indexedType, const int index, TQualifier baseQualifier) { + TIntermBinary *indexNode = new TIntermBinary(EOpIndexDirect); + indexNode->setType(fieldType); TIntermSymbol *baseSymbol = CreateBaseSymbol(indexedType, baseQualifier); - TIntermBinary *indexNode = - new TIntermBinary(EOpIndexDirect, baseSymbol, TIntermTyped::CreateIndexNode(index)); + indexNode->setLeft(baseSymbol); + indexNode->setRight(CreateIntConstantNode(index)); return indexNode; } TIntermBinary *CreateAssignValueSymbolNode(TIntermTyped *targetNode, const TType &assignedValueType) { - return new TIntermBinary(EOpAssign, targetNode, CreateValueSymbol(assignedValueType)); + TIntermBinary *assignNode = new TIntermBinary(EOpAssign); + assignNode->setType(assignedValueType); + assignNode->setLeft(targetNode); + assignNode->setRight(CreateValueSymbol(assignedValueType)); + return assignNode; } TIntermTyped *EnsureSignedInt(TIntermTyped *node) @@ -175,7 +178,7 @@ TType GetFieldType(const TType &indexedType) // base[1] = value; // } // Note that else is not used in above functions to avoid the RewriteElseBlocks transformation. -TIntermFunctionDefinition *GetIndexFunctionDefinition(TType type, bool write) +TIntermAggregate *GetIndexFunctionDefinition(TType type, bool write) { ASSERT(!type.isArray()); // Conservatively use highp here, even if the indexed type is not highp. That way the code can't @@ -183,6 +186,8 @@ TIntermFunctionDefinition *GetIndexFunctionDefinition(TType type, bool write) // highp values are being indexed in the shader. For HLSL precision doesn't matter, but in // principle this code could be used with multiple backends. type.setPrecision(EbpHigh); + TIntermAggregate *indexingFunction = new TIntermAggregate(EOpFunction); + indexingFunction->setNameObj(GetIndexFunctionName(type, write)); TType fieldType = GetFieldType(type); int numCases = 0; @@ -194,6 +199,14 @@ TIntermFunctionDefinition *GetIndexFunctionDefinition(TType type, bool write) { numCases = type.getNominalSize(); } + if (write) + { + indexingFunction->setType(TType(EbtVoid)); + } + else + { + indexingFunction->setType(fieldType); + } TIntermAggregate *paramsNode = new TIntermAggregate(EOpParameters); TQualifier baseQualifier = EvqInOut; @@ -208,8 +221,9 @@ TIntermFunctionDefinition *GetIndexFunctionDefinition(TType type, bool write) TIntermSymbol *valueParam = CreateValueSymbol(fieldType); paramsNode->getSequence()->push_back(valueParam); } + indexingFunction->getSequence()->push_back(paramsNode); - TIntermBlock *statementList = new TIntermBlock(); + TIntermAggregate *statementList = new TIntermAggregate(EOpSequence); for (int i = 0; i < numCases; ++i) { TIntermCase *caseNode = new TIntermCase(CreateIntConstantNode(i)); @@ -239,17 +253,18 @@ TIntermFunctionDefinition *GetIndexFunctionDefinition(TType type, bool write) TIntermSwitch *switchNode = new TIntermSwitch(CreateIndexSymbol(), statementList); - TIntermBlock *bodyNode = new TIntermBlock(); + TIntermAggregate *bodyNode = new TIntermAggregate(EOpSequence); bodyNode->getSequence()->push_back(switchNode); - TIntermBinary *cond = - new TIntermBinary(EOpLessThan, CreateIndexSymbol(), CreateIntConstantNode(0)); + TIntermBinary *cond = new TIntermBinary(EOpLessThan); cond->setType(TType(EbtBool, EbpUndefined)); + cond->setLeft(CreateIndexSymbol()); + cond->setRight(CreateIntConstantNode(0)); // Two blocks: one accesses (either reads or writes) the first element and returns, // the other accesses the last element. - TIntermBlock *useFirstBlock = new TIntermBlock(); - TIntermBlock *useLastBlock = new TIntermBlock(); + TIntermAggregate *useFirstBlock = new TIntermAggregate(EOpSequence); + TIntermAggregate *useLastBlock = new TIntermAggregate(EOpSequence); TIntermBinary *indexFirstNode = CreateIndexDirectBaseSymbolNode(type, fieldType, 0, baseQualifier); TIntermBinary *indexLastNode = @@ -272,20 +287,12 @@ TIntermFunctionDefinition *GetIndexFunctionDefinition(TType type, bool write) TIntermBranch *returnLastNode = new TIntermBranch(EOpReturn, indexLastNode); useLastBlock->getSequence()->push_back(returnLastNode); } - TIntermIfElse *ifNode = new TIntermIfElse(cond, useFirstBlock, nullptr); + TIntermSelection *ifNode = new TIntermSelection(cond, useFirstBlock, nullptr); bodyNode->getSequence()->push_back(ifNode); bodyNode->getSequence()->push_back(useLastBlock); - TIntermFunctionDefinition *indexingFunction = nullptr; - if (write) - { - indexingFunction = new TIntermFunctionDefinition(TType(EbtVoid), paramsNode, bodyNode); - } - else - { - indexingFunction = new TIntermFunctionDefinition(fieldType, paramsNode, bodyNode); - } - indexingFunction->getFunctionSymbolInfo()->setNameObj(GetIndexFunctionName(type, write)); + indexingFunction->getSequence()->push_back(bodyNode); + return indexingFunction; } @@ -327,8 +334,8 @@ RemoveDynamicIndexingTraverser::RemoveDynamicIndexingTraverser(const TSymbolTabl void RemoveDynamicIndexingTraverser::insertHelperDefinitions(TIntermNode *root) { - TIntermBlock *rootBlock = root->getAsBlock(); - ASSERT(rootBlock != nullptr); + TIntermAggregate *rootAgg = root->getAsAggregate(); + ASSERT(rootAgg != nullptr && rootAgg->getOp() == EOpSequence); TIntermSequence insertions; for (TType type : mIndexedVecAndMatrixTypes) { @@ -338,7 +345,7 @@ void RemoveDynamicIndexingTraverser::insertHelperDefinitions(TIntermNode *root) { insertions.push_back(GetIndexFunctionDefinition(type, true)); } - mInsertions.push_back(NodeInsertMultipleEntry(rootBlock, 0, insertions, TIntermSequence())); + mInsertions.push_back(NodeInsertMultipleEntry(rootAgg, 0, insertions, TIntermSequence())); } // Create a call to dyn_index_*() based on an indirect indexing op node @@ -350,8 +357,7 @@ TIntermAggregate *CreateIndexFunctionCall(TIntermBinary *node, TIntermAggregate *indexingCall = new TIntermAggregate(EOpFunctionCall); indexingCall->setLine(node->getLine()); indexingCall->setUserDefined(); - indexingCall->getFunctionSymbolInfo()->setNameObj( - GetIndexFunctionName(indexedNode->getType(), false)); + indexingCall->setNameObj(GetIndexFunctionName(indexedNode->getType(), false)); indexingCall->getSequence()->push_back(indexedNode); indexingCall->getSequence()->push_back(index); @@ -369,8 +375,7 @@ TIntermAggregate *CreateIndexedWriteFunctionCall(TIntermBinary *node, ASSERT(leftCopy != nullptr && leftCopy->getAsTyped() != nullptr); TIntermAggregate *indexedWriteCall = CreateIndexFunctionCall(node, leftCopy->getAsTyped(), index); - indexedWriteCall->getFunctionSymbolInfo()->setNameObj( - GetIndexFunctionName(node->getLeft()->getType(), true)); + indexedWriteCall->setNameObj(GetIndexFunctionName(node->getLeft()->getType(), true)); indexedWriteCall->setType(TType(EbtVoid)); indexedWriteCall->getSequence()->push_back(writtenValue); return indexedWriteCall; @@ -393,7 +398,7 @@ bool RemoveDynamicIndexingTraverser::visitBinary(Visit visit, TIntermBinary *nod // Now v_expr[s0] can be safely executed several times without unintended side effects. // Init the temp variable holding the index - TIntermDeclaration *initIndex = createTempInitDeclaration(node->getRight()); + TIntermAggregate *initIndex = createTempInitDeclaration(node->getRight()); insertStatementInParentBlock(initIndex); mUsedTreeInsertion = true; @@ -444,7 +449,7 @@ bool RemoveDynamicIndexingTraverser::visitBinary(Visit visit, TIntermBinary *nod // Store the index in a temporary signed int variable. TIntermTyped *indexInitializer = EnsureSignedInt(node->getRight()); - TIntermDeclaration *initIndex = createTempInitDeclaration(indexInitializer); + TIntermAggregate *initIndex = createTempInitDeclaration(indexInitializer); initIndex->setLine(node->getLine()); insertionsBefore.push_back(initIndex); @@ -509,5 +514,3 @@ void RemoveDynamicIndexing(TIntermNode *root, traverser.insertHelperDefinitions(root); traverser.updateTree(); } - -} // namespace sh |