Commit 93b059db by Olli Etuaho Committed by Commit Bot

Index symbols by id in OutputHLSL

This is cleaner than indexing them by their name string. BUG=angleproject:2267 TEST=angle_unittests Change-Id: I0d0ef5e3f6a3f26c94f096b086cdf3da40d495e4 Reviewed-on: https://chromium-review.googlesource.com/845559 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent d8724a94
...@@ -346,7 +346,7 @@ TString OutputHLSL::generateStructMapping(const std::vector<MappedStruct> &std14 ...@@ -346,7 +346,7 @@ TString OutputHLSL::generateStructMapping(const std::vector<MappedStruct> &std14
TInterfaceBlock *interfaceBlock = TInterfaceBlock *interfaceBlock =
mappedStruct.blockDeclarator->getType().getInterfaceBlock(); mappedStruct.blockDeclarator->getType().getInterfaceBlock();
const TName &instanceName = mappedStruct.blockDeclarator->getName(); const TName &instanceName = mappedStruct.blockDeclarator->getName();
if (mReferencedUniformBlocks.count(interfaceBlock->name()) == 0) if (mReferencedUniformBlocks.count(interfaceBlock->uniqueId().get()) == 0)
{ {
continue; continue;
} }
...@@ -416,11 +416,10 @@ void OutputHLSL::header(TInfoSinkBase &out, ...@@ -416,11 +416,10 @@ void OutputHLSL::header(TInfoSinkBase &out,
" " + Decorate(name) + ArrayString(type) + " = " + initializer(type) + ";\n"; " " + Decorate(name) + ArrayString(type) + " = " + initializer(type) + ";\n";
} }
for (ReferencedSymbols::const_iterator attribute = mReferencedAttributes.begin(); for (const auto &attribute : mReferencedAttributes)
attribute != mReferencedAttributes.end(); attribute++)
{ {
const TType &type = attribute->second->getType(); const TType &type = attribute.second->getType();
const TString &name = attribute->second->getSymbol(); const TString &name = attribute.second->getSymbol();
attributes += "static " + TypeString(type) + " " + Decorate(name) + ArrayString(type) + attributes += "static " + TypeString(type) + " " + Decorate(name) + ArrayString(type) +
" = " + initializer(type) + ";\n"; " = " + initializer(type) + ";\n";
...@@ -490,12 +489,10 @@ void OutputHLSL::header(TInfoSinkBase &out, ...@@ -490,12 +489,10 @@ void OutputHLSL::header(TInfoSinkBase &out,
if (mShaderVersion >= 300) if (mShaderVersion >= 300)
{ {
for (ReferencedSymbols::const_iterator outputVariableIt = for (const auto &outputVariable : mReferencedOutputVariables)
mReferencedOutputVariables.begin();
outputVariableIt != mReferencedOutputVariables.end(); outputVariableIt++)
{ {
const TString &variableName = outputVariableIt->first; const TString &variableName = outputVariable.second->getSymbol();
const TType &variableType = outputVariableIt->second->getType(); const TType &variableType = outputVariable.second->getType();
out << "static " + TypeString(variableType) + " out_" + variableName + out << "static " + TypeString(variableType) + " out_" + variableName +
ArrayString(variableType) + " = " + initializer(variableType) + ";\n"; ArrayString(variableType) + " = " + initializer(variableType) + ";\n";
...@@ -874,6 +871,8 @@ void OutputHLSL::visitSymbol(TIntermSymbol *node) ...@@ -874,6 +871,8 @@ void OutputHLSL::visitSymbol(TIntermSymbol *node)
TString name = node->getSymbol(); TString name = node->getSymbol();
const TSymbolUniqueId &uniqueId = node->uniqueId();
if (name == "gl_DepthRange") if (name == "gl_DepthRange")
{ {
mUsesDepthRange = true; mUsesDepthRange = true;
...@@ -892,23 +891,23 @@ void OutputHLSL::visitSymbol(TIntermSymbol *node) ...@@ -892,23 +891,23 @@ void OutputHLSL::visitSymbol(TIntermSymbol *node)
if (interfaceBlock) if (interfaceBlock)
{ {
mReferencedUniformBlocks[interfaceBlock->name()] = node; mReferencedUniformBlocks[interfaceBlock->uniqueId().get()] = node;
} }
else else
{ {
mReferencedUniforms[name] = node; mReferencedUniforms[uniqueId.get()] = node;
} }
out << DecorateVariableIfNeeded(node->getName()); out << DecorateVariableIfNeeded(node->getName());
} }
else if (qualifier == EvqAttribute || qualifier == EvqVertexIn) else if (qualifier == EvqAttribute || qualifier == EvqVertexIn)
{ {
mReferencedAttributes[name] = node; mReferencedAttributes[uniqueId.get()] = node;
out << Decorate(name); out << Decorate(name);
} }
else if (IsVarying(qualifier)) else if (IsVarying(qualifier))
{ {
mReferencedVaryings[name] = node; mReferencedVaryings[uniqueId.get()] = node;
out << Decorate(name); out << Decorate(name);
if (name == "ViewID_OVR") if (name == "ViewID_OVR")
{ {
...@@ -917,7 +916,7 @@ void OutputHLSL::visitSymbol(TIntermSymbol *node) ...@@ -917,7 +916,7 @@ void OutputHLSL::visitSymbol(TIntermSymbol *node)
} }
else if (qualifier == EvqFragmentOut) else if (qualifier == EvqFragmentOut)
{ {
mReferencedOutputVariables[name] = node; mReferencedOutputVariables[uniqueId.get()] = node;
out << "out_" << name; out << "out_" << name;
} }
else if (qualifier == EvqFragColor) else if (qualifier == EvqFragColor)
...@@ -1240,7 +1239,8 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node) ...@@ -1240,7 +1239,8 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node)
{ {
TInterfaceBlock *interfaceBlock = leftType.getInterfaceBlock(); TInterfaceBlock *interfaceBlock = leftType.getInterfaceBlock();
TIntermSymbol *instanceArraySymbol = node->getLeft()->getAsSymbolNode(); TIntermSymbol *instanceArraySymbol = node->getLeft()->getAsSymbolNode();
mReferencedUniformBlocks[interfaceBlock->name()] = instanceArraySymbol; mReferencedUniformBlocks[interfaceBlock->uniqueId().get()] =
instanceArraySymbol;
const int arrayIndex = node->getRight()->getAsConstantUnion()->getIConst(0); const int arrayIndex = node->getRight()->getAsConstantUnion()->getIConst(0);
out << mUniformHLSL->UniformBlockInstanceString( out << mUniformHLSL->UniformBlockInstanceString(
instanceArraySymbol->getSymbol(), arrayIndex); instanceArraySymbol->getSymbol(), arrayIndex);
...@@ -1834,9 +1834,12 @@ bool OutputHLSL::visitDeclaration(Visit visit, TIntermDeclaration *node) ...@@ -1834,9 +1834,12 @@ bool OutputHLSL::visitDeclaration(Visit visit, TIntermDeclaration *node)
TIntermSymbol *symbol = variable->getAsSymbolNode(); TIntermSymbol *symbol = variable->getAsSymbolNode();
ASSERT(symbol); // Varying declarations can't have initializers. ASSERT(symbol); // Varying declarations can't have initializers.
// Vertex outputs which are declared but not written to should still be declared to if (symbol->variable().symbolType() != SymbolType::Empty)
// allow successful linking. {
mReferencedVaryings[symbol->getSymbol()] = symbol; // Vertex outputs which are declared but not written to should still be declared to
// allow successful linking.
mReferencedVaryings[symbol->uniqueId().get()] = symbol;
}
} }
} }
return false; return false;
......
...@@ -28,7 +28,8 @@ class ImageFunctionHLSL; ...@@ -28,7 +28,8 @@ class ImageFunctionHLSL;
class UnfoldShortCircuit; class UnfoldShortCircuit;
class UniformHLSL; class UniformHLSL;
typedef std::map<TString, TIntermSymbol *> ReferencedSymbols; // Map from uniqueId to a symbol node.
typedef std::map<int, TIntermSymbol *> ReferencedSymbols;
class OutputHLSL : public TIntermTraverser class OutputHLSL : public TIntermTraverser
{ {
...@@ -156,7 +157,7 @@ class OutputHLSL : public TIntermTraverser ...@@ -156,7 +157,7 @@ class OutputHLSL : public TIntermTraverser
ReferencedSymbols mReferencedUniforms; ReferencedSymbols mReferencedUniforms;
// Indexed by block name, not instance name. Stored nodes point to either the block instance in // Indexed by block id, not instance id. Stored nodes point to either the block instance in
// the case of an instanced block, or a member uniform in the case of a non-instanced block. // the case of an instanced block, or a member uniform in the case of a non-instanced block.
// TODO(oetuaho): Consider a different type of data structure for storing referenced interface // TODO(oetuaho): Consider a different type of data structure for storing referenced interface
// blocks. It needs to know the instance name if any and link to the TInterfaceBlock object. // blocks. It needs to know the instance name if any and link to the TInterfaceBlock object.
......
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