Commit 04ea03e4 by Jamie Madill Committed by Commit Bot

Make default block member info a constant.

Instead of generating a struct each time we can use a constexpr constructor to use a single representation. Bug: angleproject:3024 Change-Id: I14dec65a4f6ac9ab2f7e7af444862e4ceab88d8c Reviewed-on: https://chromium-review.googlesource.com/c/1392395Reviewed-by: 's avatarJiajia Qin <jiajia.qin@intel.com> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 76f66954
...@@ -27,27 +27,20 @@ struct InterfaceBlock; ...@@ -27,27 +27,20 @@ struct InterfaceBlock;
struct BlockMemberInfo struct BlockMemberInfo
{ {
BlockMemberInfo() constexpr BlockMemberInfo() = default;
: offset(-1),
arrayStride(-1),
matrixStride(-1),
isRowMajorMatrix(false),
topLevelArrayStride(-1)
{}
BlockMemberInfo(int offset, int arrayStride, int matrixStride, bool isRowMajorMatrix) constexpr BlockMemberInfo(int offset, int arrayStride, int matrixStride, bool isRowMajorMatrix)
: offset(offset), : offset(offset),
arrayStride(arrayStride), arrayStride(arrayStride),
matrixStride(matrixStride), matrixStride(matrixStride),
isRowMajorMatrix(isRowMajorMatrix), isRowMajorMatrix(isRowMajorMatrix)
topLevelArrayStride(-1)
{} {}
BlockMemberInfo(int offset, constexpr BlockMemberInfo(int offset,
int arrayStride, int arrayStride,
int matrixStride, int matrixStride,
bool isRowMajorMatrix, bool isRowMajorMatrix,
int topLevelArrayStride) int topLevelArrayStride)
: offset(offset), : offset(offset),
arrayStride(arrayStride), arrayStride(arrayStride),
matrixStride(matrixStride), matrixStride(matrixStride),
...@@ -55,15 +48,26 @@ struct BlockMemberInfo ...@@ -55,15 +48,26 @@ struct BlockMemberInfo
topLevelArrayStride(topLevelArrayStride) topLevelArrayStride(topLevelArrayStride)
{} {}
static BlockMemberInfo getDefaultBlockInfo() { return BlockMemberInfo(-1, -1, -1, false, -1); } // A single integer identifying the offset of an active variable.
int offset = -1;
// A single integer identifying the stride between array elements in an active variable.
int arrayStride = -1;
int offset; // A single integer identifying the stride between columns of a column-major matrix or rows of a
int arrayStride; // row-major matrix.
int matrixStride; int matrixStride = -1;
bool isRowMajorMatrix;
int topLevelArrayStride; // Only used for shader storage block members. // A single integer identifying whether an active variable is a row-major matrix.
bool isRowMajorMatrix = false;
// A single integer identifying the number of active array elements of the top-level shader
// storage block member containing the active variable.
int topLevelArrayStride = -1;
}; };
constexpr BlockMemberInfo kDefaultBlockMemberInfo;
class BlockLayoutEncoder class BlockLayoutEncoder
{ {
public: public:
......
...@@ -523,7 +523,7 @@ class FlattenUniformVisitor : public sh::VariableNameVisitor ...@@ -523,7 +523,7 @@ class FlattenUniformVisitor : public sh::VariableNameVisitor
{ {
LinkedUniform linkedUniform(variable.type, variable.precision, fullNameWithArrayIndex, LinkedUniform linkedUniform(variable.type, variable.precision, fullNameWithArrayIndex,
variable.arraySizes, getBinding(), getOffset(), mLocation, variable.arraySizes, getBinding(), getOffset(), mLocation,
-1, sh::BlockMemberInfo::getDefaultBlockInfo()); -1, sh::kDefaultBlockMemberInfo);
linkedUniform.mappedName = fullMappedNameWithArrayIndex; linkedUniform.mappedName = fullMappedNameWithArrayIndex;
linkedUniform.active = mMarkActive; linkedUniform.active = mMarkActive;
linkedUniform.staticUse = mMarkStaticUse; linkedUniform.staticUse = mMarkStaticUse;
......
...@@ -48,7 +48,7 @@ GLuint ActiveVariable::activeShaderCount() const ...@@ -48,7 +48,7 @@ GLuint ActiveVariable::activeShaderCount() const
} }
LinkedUniform::LinkedUniform() LinkedUniform::LinkedUniform()
: typeInfo(nullptr), bufferIndex(-1), blockInfo(sh::BlockMemberInfo::getDefaultBlockInfo()) : typeInfo(nullptr), bufferIndex(-1), blockInfo(sh::kDefaultBlockMemberInfo)
{} {}
LinkedUniform::LinkedUniform(GLenum typeIn, LinkedUniform::LinkedUniform(GLenum typeIn,
...@@ -77,7 +77,7 @@ LinkedUniform::LinkedUniform(const sh::Uniform &uniform) ...@@ -77,7 +77,7 @@ LinkedUniform::LinkedUniform(const sh::Uniform &uniform)
: sh::Uniform(uniform), : sh::Uniform(uniform),
typeInfo(&GetUniformTypeInfo(type)), typeInfo(&GetUniformTypeInfo(type)),
bufferIndex(-1), bufferIndex(-1),
blockInfo(sh::BlockMemberInfo::getDefaultBlockInfo()) blockInfo(sh::kDefaultBlockMemberInfo)
{ {
ASSERT(!isArrayOfArrays()); ASSERT(!isArrayOfArrays());
ASSERT(!isArray() || !isStruct()); ASSERT(!isArray() || !isStruct());
...@@ -139,7 +139,7 @@ size_t LinkedUniform::getElementComponents() const ...@@ -139,7 +139,7 @@ size_t LinkedUniform::getElementComponents() const
} }
BufferVariable::BufferVariable() BufferVariable::BufferVariable()
: bufferIndex(-1), blockInfo(sh::BlockMemberInfo::getDefaultBlockInfo()), topLevelArraySize(-1) : bufferIndex(-1), blockInfo(sh::kDefaultBlockMemberInfo), topLevelArraySize(-1)
{} {}
BufferVariable::BufferVariable(GLenum typeIn, BufferVariable::BufferVariable(GLenum typeIn,
......
...@@ -238,7 +238,7 @@ bool InterfaceBlockInfo::getBlockMemberInfo(const std::string &name, ...@@ -238,7 +238,7 @@ bool InterfaceBlockInfo::getBlockMemberInfo(const std::string &name,
auto infoIter = mBlockLayout.find(name); auto infoIter = mBlockLayout.find(name);
if (infoIter == mBlockLayout.end()) if (infoIter == mBlockLayout.end())
{ {
*infoOut = sh::BlockMemberInfo::getDefaultBlockInfo(); *infoOut = sh::kDefaultBlockMemberInfo;
return false; return false;
} }
......
...@@ -715,7 +715,7 @@ bool ProgramGL::getUniformBlockMemberInfo(const std::string & /* memberUniformNa ...@@ -715,7 +715,7 @@ bool ProgramGL::getUniformBlockMemberInfo(const std::string & /* memberUniformNa
if (uniformIndex == GL_INVALID_INDEX) if (uniformIndex == GL_INVALID_INDEX)
{ {
*memberInfoOut = sh::BlockMemberInfo::getDefaultBlockInfo(); *memberInfoOut = sh::kDefaultBlockMemberInfo;
return false; return false;
} }
...@@ -744,7 +744,7 @@ bool ProgramGL::getShaderStorageBlockMemberInfo(const std::string & /* memberNam ...@@ -744,7 +744,7 @@ bool ProgramGL::getShaderStorageBlockMemberInfo(const std::string & /* memberNam
if (index == GL_INVALID_INDEX) if (index == GL_INVALID_INDEX)
{ {
*memberInfoOut = sh::BlockMemberInfo::getDefaultBlockInfo(); *memberInfoOut = sh::kDefaultBlockMemberInfo;
return false; return false;
} }
......
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