Store referenced interface blocks in a cleaner data structure
The previous code was hard to read since the referenced interface
blocks stored a different type of node depending on if the interface
block was instanced or not.
BUG=angleproject:2267
TEST=angle_unittests
Change-Id: Ie8fdb61a17280ca0875159702f819b884d08706b
Reviewed-on: https://chromium-review.googlesource.com/839443
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/translator/OutputHLSL.cpp b/src/compiler/translator/OutputHLSL.cpp
index ccd6037..04ce8eb 100644
--- a/src/compiler/translator/OutputHLSL.cpp
+++ b/src/compiler/translator/OutputHLSL.cpp
@@ -82,6 +82,12 @@
} // anonymous namespace
+TReferencedBlock::TReferencedBlock(const TInterfaceBlock *aBlock,
+ const TVariable *aInstanceVariable)
+ : block(aBlock), instanceVariable(aInstanceVariable)
+{
+}
+
void OutputHLSL::writeFloat(TInfoSinkBase &out, float f)
{
// This is known not to work for NaN on all drivers but make the best effort to output NaNs
@@ -896,7 +902,16 @@
if (interfaceBlock)
{
- mReferencedUniformBlocks[interfaceBlock->uniqueId().get()] = node;
+ if (mReferencedUniformBlocks.count(interfaceBlock->uniqueId().get()) == 0)
+ {
+ const TVariable *instanceVariable = nullptr;
+ if (variableType.isInterfaceBlock())
+ {
+ instanceVariable = &variable;
+ }
+ mReferencedUniformBlocks[interfaceBlock->uniqueId().get()] =
+ new TReferencedBlock(interfaceBlock, instanceVariable);
+ }
}
else
{
@@ -1242,10 +1257,13 @@
{
if (visit == PreVisit)
{
- TInterfaceBlock *interfaceBlock = leftType.getInterfaceBlock();
TIntermSymbol *instanceArraySymbol = node->getLeft()->getAsSymbolNode();
- mReferencedUniformBlocks[interfaceBlock->uniqueId().get()] =
- instanceArraySymbol;
+ TInterfaceBlock *interfaceBlock = leftType.getInterfaceBlock();
+ if (mReferencedUniformBlocks.count(interfaceBlock->uniqueId().get()) == 0)
+ {
+ mReferencedUniformBlocks[interfaceBlock->uniqueId().get()] =
+ new TReferencedBlock(interfaceBlock, &instanceArraySymbol->variable());
+ }
const int arrayIndex = node->getRight()->getAsConstantUnion()->getIConst(0);
out << mUniformHLSL->UniformBlockInstanceString(instanceArraySymbol->getName(),
arrayIndex);