Remove arraySize in TInterfaceBlock
This patch intends to remove the field 'arraySize' in TInterfaceBlock.
The field 'arraySize' in TInterfaceBlock is redundant because:
1. If the interface block has instance name, it is recorded as one
symbol as a whole, and its array size is recorded in the TType
of the symbol.
2. If the interface block doesn't have instance name, its members are
recorded separately, and it cannot be declared as an interface block
array.
This patch can make the implementation of Geometry Shader easier
when we set array size to the built-in interface block 'gl_in' and other
user-defined unsized input interface blocks during the compilation of a
Geometry Shader.
BUG=angleproject:1941
TEST=angle_end2end_test
Change-Id: I9a51aab9b8f9ea7e88af157505c092426cee7e6e
Reviewed-on: https://chromium-review.googlesource.com/615759
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/compiler/translator/ParseContext.cpp b/src/compiler/translator/ParseContext.cpp
index a4796e3..f1cb9ed 100644
--- a/src/compiler/translator/ParseContext.cpp
+++ b/src/compiler/translator/ParseContext.cpp
@@ -3517,7 +3517,7 @@
}
TInterfaceBlock *interfaceBlock =
- new TInterfaceBlock(&blockName, fieldList, instanceName, arraySize, blockLayoutQualifier);
+ new TInterfaceBlock(&blockName, fieldList, instanceName, blockLayoutQualifier);
TType interfaceBlockType(interfaceBlock, typeQualifier.qualifier, blockLayoutQualifier,
arraySize);
diff --git a/src/compiler/translator/Types.h b/src/compiler/translator/Types.h
index 3a0ec78..e120cd4 100644
--- a/src/compiler/translator/Types.h
+++ b/src/compiler/translator/Types.h
@@ -149,11 +149,9 @@
TInterfaceBlock(const TString *name,
TFieldList *fields,
const TString *instanceName,
- int arraySize,
const TLayoutQualifier &layoutQualifier)
: TFieldListCollection(name, fields),
mInstanceName(instanceName),
- mArraySize(arraySize),
mBlockStorage(layoutQualifier.blockStorage),
mMatrixPacking(layoutQualifier.matrixPacking),
mBinding(layoutQualifier.binding)
@@ -162,8 +160,6 @@
const TString &instanceName() const { return *mInstanceName; }
bool hasInstanceName() const { return mInstanceName != nullptr; }
- bool isArray() const { return mArraySize > 0; }
- int arraySize() const { return mArraySize; }
TLayoutBlockStorage blockStorage() const { return mBlockStorage; }
TLayoutMatrixPacking matrixPacking() const { return mMatrixPacking; }
int blockBinding() const { return mBinding; }
@@ -176,7 +172,6 @@
private:
const TString *mInstanceName; // for interface block instance names
- int mArraySize; // 0 if not an array
TLayoutBlockStorage mBlockStorage;
TLayoutMatrixPacking mMatrixPacking;
int mBinding;
@@ -495,7 +490,10 @@
bool array;
unsigned int arraySize;
- // 0 unless this is an interface block, or interface block member variable
+ // This is set only in the following two cases:
+ // 1) Represents an interface block.
+ // 2) Represents the member variable of an unnamed interface block.
+ // It's nullptr also for members of named interface blocks.
TInterfaceBlock *interfaceBlock;
// 0 unless this is a struct
diff --git a/src/compiler/translator/UniformHLSL.cpp b/src/compiler/translator/UniformHLSL.cpp
index 53e321c..8932301 100644
--- a/src/compiler/translator/UniformHLSL.cpp
+++ b/src/compiler/translator/UniformHLSL.cpp
@@ -363,11 +363,14 @@
const TType &nodeType = interfaceBlockIt->second->getType();
const TInterfaceBlock &interfaceBlock = *nodeType.getInterfaceBlock();
- unsigned int arraySize = static_cast<unsigned int>(interfaceBlock.arraySize());
+ // 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 =
+ nodeType.isInterfaceBlock() ? nodeType.getArraySize() : 0;
unsigned int activeRegister = mUniformBlockRegister;
mUniformBlockRegisterMap[interfaceBlock.name().c_str()] = activeRegister;
- mUniformBlockRegister += std::max(1u, arraySize);
+ mUniformBlockRegister += std::max(1u, interfaceBlockArraySize);
// FIXME: interface block field names
@@ -376,9 +379,9 @@
interfaceBlocks += uniformBlockStructString(interfaceBlock);
}
- if (arraySize > 0)
+ if (interfaceBlockArraySize > 0)
{
- for (unsigned int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++)
+ for (unsigned int arrayIndex = 0; arrayIndex < interfaceBlockArraySize; arrayIndex++)
{
interfaceBlocks +=
uniformBlockString(interfaceBlock, activeRegister + arrayIndex, arrayIndex);
@@ -429,7 +432,7 @@
{
return "";
}
- else if (interfaceBlock.isArray())
+ else if (arrayIndex != GL_INVALID_INDEX)
{
return DecoratePrivate(interfaceBlock.instanceName()) + "_" + str(arrayIndex);
}