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