Commit 12a18ad3 by Olli Etuaho Committed by Commit Bot

Simplify interface block instance recording

Instead of storing instance names as part of TInterfaceBlock, store instance names only in interface block instance symbols. Wherever the instance name is needed it can be fetched from the instance symbol. BUG=angleproject:2267 TEST=angle_end2end_tests Change-Id: Ia265e4db7901eebec57c9c3769d84c17651a35ba Reviewed-on: https://chromium-review.googlesource.com/803221Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent e4477001
...@@ -132,7 +132,8 @@ class CollectVariablesTraverser : public TIntermTraverser ...@@ -132,7 +132,8 @@ class CollectVariablesTraverser : public TIntermTraverser
Attribute recordAttribute(const TIntermSymbol &variable) const; Attribute recordAttribute(const TIntermSymbol &variable) const;
OutputVariable recordOutputVariable(const TIntermSymbol &variable) const; OutputVariable recordOutputVariable(const TIntermSymbol &variable) const;
Varying recordVarying(const TIntermSymbol &variable) const; Varying recordVarying(const TIntermSymbol &variable) const;
void recordInterfaceBlock(const TType &interfaceBlockType, void recordInterfaceBlock(const TString &instanceName,
const TType &interfaceBlockType,
InterfaceBlock *interfaceBlock) const; InterfaceBlock *interfaceBlock) const;
Uniform recordUniform(const TIntermSymbol &variable) const; Uniform recordUniform(const TIntermSymbol &variable) const;
...@@ -316,7 +317,7 @@ InterfaceBlock *CollectVariablesTraverser::recordGLInUsed(const TType &glInType) ...@@ -316,7 +317,7 @@ InterfaceBlock *CollectVariablesTraverser::recordGLInUsed(const TType &glInType)
{ {
ASSERT(glInType.getQualifier() == EvqPerVertexIn); ASSERT(glInType.getQualifier() == EvqPerVertexIn);
InterfaceBlock info; InterfaceBlock info;
recordInterfaceBlock(glInType, &info); recordInterfaceBlock("gl_in", glInType, &info);
info.staticUse = true; info.staticUse = true;
mPerVertexInAdded = true; mPerVertexInAdded = true;
...@@ -646,7 +647,8 @@ Varying CollectVariablesTraverser::recordVarying(const TIntermSymbol &variable) ...@@ -646,7 +647,8 @@ Varying CollectVariablesTraverser::recordVarying(const TIntermSymbol &variable)
} }
// TODO(jiawei.shao@intel.com): implement GL_OES_shader_io_blocks. // TODO(jiawei.shao@intel.com): implement GL_OES_shader_io_blocks.
void CollectVariablesTraverser::recordInterfaceBlock(const TType &interfaceBlockType, void CollectVariablesTraverser::recordInterfaceBlock(const TString &instanceName,
const TType &interfaceBlockType,
InterfaceBlock *interfaceBlock) const InterfaceBlock *interfaceBlock) const
{ {
ASSERT(interfaceBlockType.getBasicType() == EbtInterfaceBlock); ASSERT(interfaceBlockType.getBasicType() == EbtInterfaceBlock);
...@@ -657,8 +659,7 @@ void CollectVariablesTraverser::recordInterfaceBlock(const TType &interfaceBlock ...@@ -657,8 +659,7 @@ void CollectVariablesTraverser::recordInterfaceBlock(const TType &interfaceBlock
interfaceBlock->name = blockType->name().c_str(); interfaceBlock->name = blockType->name().c_str();
interfaceBlock->mappedName = getMappedName(TName(blockType->name())); interfaceBlock->mappedName = getMappedName(TName(blockType->name()));
interfaceBlock->instanceName = interfaceBlock->instanceName = instanceName.c_str();
(blockType->hasInstanceName() ? blockType->instanceName().c_str() : "");
ASSERT(!interfaceBlockType.isArrayOfArrays()); // Disallowed by GLSL ES 3.10 section 4.3.9 ASSERT(!interfaceBlockType.isArrayOfArrays()); // Disallowed by GLSL ES 3.10 section 4.3.9
interfaceBlock->arraySize = interfaceBlockType.isArray() ? interfaceBlockType.getOutermostArraySize() : 0; interfaceBlock->arraySize = interfaceBlockType.isArray() ? interfaceBlockType.getOutermostArraySize() : 0;
...@@ -729,7 +730,7 @@ bool CollectVariablesTraverser::visitDeclaration(Visit, TIntermDeclaration *node ...@@ -729,7 +730,7 @@ bool CollectVariablesTraverser::visitDeclaration(Visit, TIntermDeclaration *node
if (typedNode.getBasicType() == EbtInterfaceBlock) if (typedNode.getBasicType() == EbtInterfaceBlock)
{ {
InterfaceBlock interfaceBlock; InterfaceBlock interfaceBlock;
recordInterfaceBlock(variable.getType(), &interfaceBlock); recordInterfaceBlock(variable.getSymbol(), variable.getType(), &interfaceBlock);
switch (qualifier) switch (qualifier)
{ {
......
...@@ -1024,8 +1024,8 @@ void IdentifyBuiltIns(sh::GLenum type, ...@@ -1024,8 +1024,8 @@ void IdentifyBuiltIns(sh::GLenum type,
NewPoolTString("gl_Position"), zeroSourceLoc); NewPoolTString("gl_Position"), zeroSourceLoc);
fieldList->push_back(glPositionField); fieldList->push_back(glPositionField);
TInterfaceBlock *glInBlock = new TInterfaceBlock( TInterfaceBlock *glInBlock =
glPerVertexString, fieldList, NewPoolTString("gl_in"), TLayoutQualifier::Create()); new TInterfaceBlock(glPerVertexString, fieldList, TLayoutQualifier::Create());
// The array size of gl_in is undefined until we get a valid input primitive // The array size of gl_in is undefined until we get a valid input primitive
// declaration. // declaration.
...@@ -1034,8 +1034,8 @@ void IdentifyBuiltIns(sh::GLenum type, ...@@ -1034,8 +1034,8 @@ void IdentifyBuiltIns(sh::GLenum type,
symbolTable.insertVariableExt(ESSL3_1_BUILTINS, extension, "gl_in", glInType); symbolTable.insertVariableExt(ESSL3_1_BUILTINS, extension, "gl_in", glInType);
TType glPositionType(EbtFloat, EbpHigh, EvqPosition, 4); TType glPositionType(EbtFloat, EbpHigh, EvqPosition, 4);
glPositionType.setInterfaceBlock(new TInterfaceBlock( glPositionType.setInterfaceBlock(
glPerVertexString, fieldList, nullptr, TLayoutQualifier::Create())); new TInterfaceBlock(glPerVertexString, fieldList, TLayoutQualifier::Create()));
symbolTable.insertVariableExt(ESSL3_1_BUILTINS, extension, "gl_Position", symbolTable.insertVariableExt(ESSL3_1_BUILTINS, extension, "gl_Position",
glPositionType); glPositionType);
symbolTable.insertVariableExt(ESSL3_1_BUILTINS, extension, "gl_PrimitiveIDIn", symbolTable.insertVariableExt(ESSL3_1_BUILTINS, extension, "gl_PrimitiveIDIn",
......
...@@ -343,9 +343,7 @@ TString OutputHLSL::generateStructMapping(const std::vector<MappedStruct> &std14 ...@@ -343,9 +343,7 @@ TString OutputHLSL::generateStructMapping(const std::vector<MappedStruct> &std14
mappedStruct.blockDeclarator->getType().getInterfaceBlock(); mappedStruct.blockDeclarator->getType().getInterfaceBlock();
const TString &interfaceBlockName = interfaceBlock->name(); const TString &interfaceBlockName = interfaceBlock->name();
const TName &instanceName = mappedStruct.blockDeclarator->getName(); const TName &instanceName = mappedStruct.blockDeclarator->getName();
if (mReferencedUniformBlocks.count(interfaceBlockName) == 0 && if (mReferencedUniformBlocks.count(interfaceBlockName) == 0)
(instanceName.getString() == "" ||
mReferencedUniformBlocks.count(instanceName.getString()) == 0))
{ {
continue; continue;
} }
...@@ -368,8 +366,8 @@ TString OutputHLSL::generateStructMapping(const std::vector<MappedStruct> &std14 ...@@ -368,8 +366,8 @@ TString OutputHLSL::generateStructMapping(const std::vector<MappedStruct> &std14
unsigned int instanceStringArrayIndex = GL_INVALID_INDEX; unsigned int instanceStringArrayIndex = GL_INVALID_INDEX;
if (isInstanceArray) if (isInstanceArray)
instanceStringArrayIndex = instanceArrayIndex; instanceStringArrayIndex = instanceArrayIndex;
TString instanceString = mUniformHLSL->uniformBlockInstanceString( TString instanceString = mUniformHLSL->UniformBlockInstanceString(
*interfaceBlock, instanceStringArrayIndex); instanceName.getString(), instanceStringArrayIndex);
originalName += instanceString; originalName += instanceString;
mappedName += instanceString; mappedName += instanceString;
originalName += "."; originalName += ".";
...@@ -1239,10 +1237,11 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node) ...@@ -1239,10 +1237,11 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node)
if (visit == PreVisit) if (visit == PreVisit)
{ {
TInterfaceBlock *interfaceBlock = leftType.getInterfaceBlock(); TInterfaceBlock *interfaceBlock = leftType.getInterfaceBlock();
TIntermSymbol *instanceArraySymbol = node->getLeft()->getAsSymbolNode();
mReferencedUniformBlocks[interfaceBlock->name()] = instanceArraySymbol;
const int arrayIndex = node->getRight()->getAsConstantUnion()->getIConst(0); const int arrayIndex = node->getRight()->getAsConstantUnion()->getIConst(0);
mReferencedUniformBlocks[interfaceBlock->instanceName()] = out << mUniformHLSL->UniformBlockInstanceString(
node->getLeft()->getAsSymbolNode(); instanceArraySymbol->getSymbol(), arrayIndex);
out << mUniformHLSL->uniformBlockInstanceString(*interfaceBlock, arrayIndex);
return false; return false;
} }
} }
......
...@@ -155,7 +155,13 @@ class OutputHLSL : public TIntermTraverser ...@@ -155,7 +155,13 @@ class OutputHLSL : public TIntermTraverser
std::stack<TInfoSinkBase *> mInfoSinkStack; std::stack<TInfoSinkBase *> mInfoSinkStack;
ReferencedSymbols mReferencedUniforms; ReferencedSymbols mReferencedUniforms;
// Indexed by block name, not instance name. 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.
// 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.
ReferencedSymbols mReferencedUniformBlocks; ReferencedSymbols mReferencedUniformBlocks;
ReferencedSymbols mReferencedAttributes; ReferencedSymbols mReferencedAttributes;
ReferencedSymbols mReferencedVaryings; ReferencedSymbols mReferencedVaryings;
ReferencedSymbols mReferencedOutputVariables; ReferencedSymbols mReferencedOutputVariables;
......
...@@ -3814,7 +3814,7 @@ TIntermDeclaration *TParseContext::addInterfaceBlock( ...@@ -3814,7 +3814,7 @@ TIntermDeclaration *TParseContext::addInterfaceBlock(
} }
TInterfaceBlock *interfaceBlock = TInterfaceBlock *interfaceBlock =
new TInterfaceBlock(&blockName, fieldList, instanceName, blockLayoutQualifier); new TInterfaceBlock(&blockName, fieldList, blockLayoutQualifier);
TType interfaceBlockType(interfaceBlock, typeQualifier.qualifier, blockLayoutQualifier); TType interfaceBlockType(interfaceBlock, typeQualifier.qualifier, blockLayoutQualifier);
if (arrayIndex != nullptr) if (arrayIndex != nullptr)
{ {
......
...@@ -934,11 +934,9 @@ int TFieldListCollection::calculateDeepestNesting() const ...@@ -934,11 +934,9 @@ int TFieldListCollection::calculateDeepestNesting() const
TInterfaceBlock::TInterfaceBlock(const TString *name, TInterfaceBlock::TInterfaceBlock(const TString *name,
const TFieldList *fields, const TFieldList *fields,
const TString *instanceName,
const TLayoutQualifier &layoutQualifier) const TLayoutQualifier &layoutQualifier)
: TFieldListCollection(fields), : TFieldListCollection(fields),
mName(name), mName(name),
mInstanceName(instanceName),
mBlockStorage(layoutQualifier.blockStorage), mBlockStorage(layoutQualifier.blockStorage),
mBinding(layoutQualifier.binding) mBinding(layoutQualifier.binding)
{ {
......
...@@ -86,18 +86,15 @@ class TInterfaceBlock : public TFieldListCollection ...@@ -86,18 +86,15 @@ class TInterfaceBlock : public TFieldListCollection
POOL_ALLOCATOR_NEW_DELETE(); POOL_ALLOCATOR_NEW_DELETE();
TInterfaceBlock(const TString *name, TInterfaceBlock(const TString *name,
const TFieldList *fields, const TFieldList *fields,
const TString *instanceName,
const TLayoutQualifier &layoutQualifier); const TLayoutQualifier &layoutQualifier);
const TString &name() const { return *mName; } const TString &name() const { return *mName; }
const TString &instanceName() const { return *mInstanceName; }
bool hasInstanceName() const { return mInstanceName != nullptr; }
TLayoutBlockStorage blockStorage() const { return mBlockStorage; } TLayoutBlockStorage blockStorage() const { return mBlockStorage; }
int blockBinding() const { return mBinding; } int blockBinding() const { return mBinding; }
private: private:
const TString *mName; const TString *mName; // Name of the block, not the instance name. Instance name is only stored
const TString *mInstanceName; // for interface block instance names // in the interface block symbols.
TLayoutBlockStorage mBlockStorage; TLayoutBlockStorage mBlockStorage;
int mBinding; int mBinding;
......
...@@ -466,42 +466,40 @@ TString UniformHLSL::uniformBlocksHeader(const ReferencedSymbols &referencedInte ...@@ -466,42 +466,40 @@ TString UniformHLSL::uniformBlocksHeader(const ReferencedSymbols &referencedInte
{ {
TString interfaceBlocks; TString interfaceBlocks;
for (ReferencedSymbols::const_iterator interfaceBlockIt = referencedInterfaceBlocks.begin(); for (const auto &interfaceBlockReference : referencedInterfaceBlocks)
interfaceBlockIt != referencedInterfaceBlocks.end(); interfaceBlockIt++)
{ {
const TType &nodeType = interfaceBlockIt->second->getType(); const TType &nodeType = interfaceBlockReference.second->getType();
const TInterfaceBlock &interfaceBlock = *nodeType.getInterfaceBlock(); const TInterfaceBlock &interfaceBlock = *nodeType.getInterfaceBlock();
// nodeType.isInterfaceBlock() == false means the node is a field of a uniform block which // nodeType.isInterfaceBlock() == false means the node is a field of a uniform block which
// doesn't have instance name, so this block cannot be an array. // doesn't have instance name.
unsigned int interfaceBlockArraySize = 0u; const TString &instanceName =
if (nodeType.isInterfaceBlock() && nodeType.isArray()) nodeType.isInterfaceBlock() ? interfaceBlockReference.second->getSymbol() : "";
{
interfaceBlockArraySize = nodeType.getOutermostArraySize();
}
unsigned int activeRegister = mUniformBlockRegister;
mUniformBlockRegisterMap[interfaceBlock.name().c_str()] = activeRegister;
mUniformBlockRegister += std::max(1u, interfaceBlockArraySize);
// FIXME: interface block field names
if (interfaceBlock.hasInstanceName()) if (instanceName != "")
{ {
interfaceBlocks += uniformBlockStructString(interfaceBlock); interfaceBlocks += uniformBlockStructString(interfaceBlock);
} }
if (interfaceBlockArraySize > 0) unsigned int activeRegister = mUniformBlockRegister;
mUniformBlockRegisterMap[interfaceBlock.name().c_str()] = activeRegister;
if (instanceName != "" && nodeType.isArray())
{ {
for (unsigned int arrayIndex = 0; arrayIndex < interfaceBlockArraySize; arrayIndex++) unsigned int interfaceBlockInstanceArraySize = nodeType.getOutermostArraySize();
for (unsigned int arrayIndex = 0; arrayIndex < interfaceBlockInstanceArraySize;
arrayIndex++)
{ {
interfaceBlocks += interfaceBlocks += uniformBlockString(interfaceBlock, instanceName,
uniformBlockString(interfaceBlock, activeRegister + arrayIndex, arrayIndex); activeRegister + arrayIndex, arrayIndex);
} }
mUniformBlockRegister += interfaceBlockInstanceArraySize;
} }
else else
{ {
interfaceBlocks += uniformBlockString(interfaceBlock, activeRegister, GL_INVALID_INDEX); interfaceBlocks +=
uniformBlockString(interfaceBlock, instanceName, activeRegister, GL_INVALID_INDEX);
mUniformBlockRegister += 1u;
} }
} }
...@@ -509,6 +507,7 @@ TString UniformHLSL::uniformBlocksHeader(const ReferencedSymbols &referencedInte ...@@ -509,6 +507,7 @@ TString UniformHLSL::uniformBlocksHeader(const ReferencedSymbols &referencedInte
} }
TString UniformHLSL::uniformBlockString(const TInterfaceBlock &interfaceBlock, TString UniformHLSL::uniformBlockString(const TInterfaceBlock &interfaceBlock,
const TString &instanceName,
unsigned int registerIndex, unsigned int registerIndex,
unsigned int arrayIndex) unsigned int arrayIndex)
{ {
...@@ -521,10 +520,10 @@ TString UniformHLSL::uniformBlockString(const TInterfaceBlock &interfaceBlock, ...@@ -521,10 +520,10 @@ TString UniformHLSL::uniformBlockString(const TInterfaceBlock &interfaceBlock,
")\n" ")\n"
"{\n"; "{\n";
if (interfaceBlock.hasInstanceName()) if (instanceName != "")
{ {
hlsl += " " + InterfaceBlockStructName(interfaceBlock) + " " + hlsl += " " + InterfaceBlockStructName(interfaceBlock) + " " +
uniformBlockInstanceString(interfaceBlock, arrayIndex) + ";\n"; UniformBlockInstanceString(instanceName, arrayIndex) + ";\n";
} }
else else
{ {
...@@ -537,20 +536,16 @@ TString UniformHLSL::uniformBlockString(const TInterfaceBlock &interfaceBlock, ...@@ -537,20 +536,16 @@ TString UniformHLSL::uniformBlockString(const TInterfaceBlock &interfaceBlock,
return hlsl; return hlsl;
} }
TString UniformHLSL::uniformBlockInstanceString(const TInterfaceBlock &interfaceBlock, TString UniformHLSL::UniformBlockInstanceString(const TString &instanceName,
unsigned int arrayIndex) unsigned int arrayIndex)
{ {
if (!interfaceBlock.hasInstanceName()) if (arrayIndex != GL_INVALID_INDEX)
{
return "";
}
else if (arrayIndex != GL_INVALID_INDEX)
{ {
return DecoratePrivate(interfaceBlock.instanceName()) + "_" + str(arrayIndex); return DecoratePrivate(instanceName) + "_" + str(arrayIndex);
} }
else else
{ {
return Decorate(interfaceBlock.instanceName()); return Decorate(instanceName);
} }
} }
......
...@@ -39,8 +39,7 @@ class UniformHLSL : angle::NonCopyable ...@@ -39,8 +39,7 @@ class UniformHLSL : angle::NonCopyable
TString uniformBlocksHeader(const ReferencedSymbols &referencedInterfaceBlocks); TString uniformBlocksHeader(const ReferencedSymbols &referencedInterfaceBlocks);
// Used for direct index references // Used for direct index references
static TString uniformBlockInstanceString(const TInterfaceBlock &interfaceBlock, static TString UniformBlockInstanceString(const TString &instanceName, unsigned int arrayIndex);
unsigned int arrayIndex);
const std::map<std::string, unsigned int> &getUniformBlockRegisterMap() const const std::map<std::string, unsigned int> &getUniformBlockRegisterMap() const
{ {
...@@ -53,6 +52,7 @@ class UniformHLSL : angle::NonCopyable ...@@ -53,6 +52,7 @@ class UniformHLSL : angle::NonCopyable
private: private:
TString uniformBlockString(const TInterfaceBlock &interfaceBlock, TString uniformBlockString(const TInterfaceBlock &interfaceBlock,
const TString &instanceName,
unsigned int registerIndex, unsigned int registerIndex,
unsigned int arrayIndex); unsigned int arrayIndex);
TString uniformBlockMembersString(const TInterfaceBlock &interfaceBlock, TString uniformBlockMembersString(const TInterfaceBlock &interfaceBlock,
......
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