Commit 2caf7ffd by Xinghua Cao Committed by Commit Bot

Address a TODO for instance uniform block

This patch resolves one TODO that Support to translate instance uniform block containing only a large array member to Structured buffer on D3D backend when necessary. Bug: angleproject:4205 Change-Id: If2cd6cf633080820ea33e52269d7d86cd587c9ee Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2114912 Commit-Queue: Xinghua Cao <xinghua.cao@intel.com> Reviewed-by: 's avatarJiajia Qin <jiajia.qin@intel.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 23196076
......@@ -86,6 +86,30 @@ bool IsInStd140UniformBlock(TIntermTyped *node)
return false;
}
bool IsInstanceUniformBlock(TIntermTyped *node)
{
TIntermBinary *binaryNode = node->getAsBinaryNode();
if (binaryNode)
{
return IsInstanceUniformBlock(binaryNode->getLeft());
}
const TVariable &variable = node->getAsSymbolNode()->variable();
const TType &variableType = variable.getType();
const TType &type = node->getType();
if (type.getQualifier() == EvqUniform)
{
// determine if it is instance uniform block.
const TInterfaceBlock *interfaceBlock = type.getInterfaceBlock();
return interfaceBlock && variableType.isInterfaceBlock();
}
return false;
}
const char *GetHLSLAtomicFunctionStringAndLeftParenthesis(TOperator op)
{
switch (op)
......@@ -1683,7 +1707,11 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node)
node->getLeft()->getType().getInterfaceBlock();
const TIntermConstantUnion *index = node->getRight()->getAsConstantUnion();
const TField *field = interfaceBlock->fields()[index->getIConst(0)];
if (structInStd140UniformBlock)
bool instanceUniformBlock = IsInstanceUniformBlock(node->getLeft());
if (structInStd140UniformBlock ||
(instanceUniformBlock &&
mResourcesHLSL->shouldTranslateUniformBlockToStructuredBuffer(
*interfaceBlock)))
{
out << "_";
}
......
......@@ -656,16 +656,29 @@ TString ResourcesHLSL::uniformBlocksHeader(
// In order to avoid compile performance issue, translate uniform block to structured
// buffer. anglebug.com/3682.
// TODO(anglebug.com/4205): Support uniform block with an instance name.
if (instanceVariable == nullptr &&
shouldTranslateUniformBlockToStructuredBuffer(interfaceBlock))
if (shouldTranslateUniformBlockToStructuredBuffer(interfaceBlock))
{
unsigned int structuredBufferRegister = mSRVRegister;
interfaceBlocks +=
uniformBlockWithOneLargeArrayMemberString(interfaceBlock, structuredBufferRegister);
if (instanceVariable != nullptr && instanceVariable->getType().isArray())
{
unsigned int instanceArraySize =
instanceVariable->getType().getOutermostArraySize();
for (unsigned int arrayIndex = 0; arrayIndex < instanceArraySize; arrayIndex++)
{
interfaceBlocks += uniformBlockWithOneLargeArrayMemberString(
interfaceBlock, instanceVariable, structuredBufferRegister + arrayIndex,
arrayIndex);
}
mSRVRegister += instanceArraySize;
}
else
{
interfaceBlocks += uniformBlockWithOneLargeArrayMemberString(
interfaceBlock, instanceVariable, structuredBufferRegister, GL_INVALID_INDEX);
mSRVRegister += 1u;
}
mUniformBlockRegisterMap[interfaceBlock.name().data()] = structuredBufferRegister;
mUniformBlockUseStructuredBufferMap[interfaceBlock.name().data()] = true;
mSRVRegister += 1u;
continue;
}
......@@ -758,7 +771,9 @@ TString ResourcesHLSL::uniformBlockString(const TInterfaceBlock &interfaceBlock,
TString ResourcesHLSL::uniformBlockWithOneLargeArrayMemberString(
const TInterfaceBlock &interfaceBlock,
unsigned int registerIndex)
const TVariable *instanceVariable,
unsigned int registerIndex,
unsigned int arrayIndex)
{
TString hlsl, typeString;
......@@ -766,8 +781,18 @@ TString ResourcesHLSL::uniformBlockWithOneLargeArrayMemberString(
const TLayoutBlockStorage blockStorage = interfaceBlock.blockStorage();
typeString = InterfaceBlockFieldTypeString(field, blockStorage, true);
hlsl += "StructuredBuffer <" + typeString + "> " + Decorate(field.name()) + " : register(t" +
str(registerIndex) + ");\n";
if (instanceVariable != nullptr)
{
hlsl += "StructuredBuffer <" + typeString + "> " +
InterfaceBlockInstanceString(instanceVariable->name(), arrayIndex) + "_" +
Decorate(field.name()) + +" : register(t" + str(registerIndex) + ");\n";
}
else
{
hlsl += "StructuredBuffer <" + typeString + "> " + Decorate(field.name()) +
" : register(t" + str(registerIndex) + ");\n";
}
return hlsl;
}
......
......@@ -68,6 +68,7 @@ class ResourcesHLSL : angle::NonCopyable
unsigned int getReadonlyImage2DRegisterIndex() const { return mReadonlyImage2DRegisterIndex; }
unsigned int getImage2DRegisterIndex() const { return mImage2DRegisterIndex; }
bool shouldTranslateUniformBlockToStructuredBuffer(const TInterfaceBlock &interfaceBlock);
private:
TString uniformBlockString(const TInterfaceBlock &interfaceBlock,
......@@ -75,7 +76,9 @@ class ResourcesHLSL : angle::NonCopyable
unsigned int registerIndex,
unsigned int arrayIndex);
TString uniformBlockWithOneLargeArrayMemberString(const TInterfaceBlock &interfaceBlock,
unsigned int registerIndex);
const TVariable *instanceVariable,
unsigned int registerIndex,
unsigned int arrayIndex);
TString shaderStorageBlockString(const TInterfaceBlock &interfaceBlock,
const TVariable *instanceVariable,
......@@ -125,7 +128,6 @@ class ResourcesHLSL : angle::NonCopyable
const HLSLRWTextureGroup textureGroup,
const TVector<const TVariable *> &group,
unsigned int *groupTextureRegisterIndex);
bool shouldTranslateUniformBlockToStructuredBuffer(const TInterfaceBlock &interfaceBlock);
unsigned int mUniformRegister;
unsigned int mUniformBlockRegister;
......
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