Commit 4ef25033 by jchen10 Committed by Commit Bot

Refactor StaticallyUsed

Gather vertexStaticUse, fragmentStaticUse, and computeStaticUse into a new mixin class StaticallyUsed, from which various program resources can inherit to track their shader references. BUG=angleproject:1920 Change-Id: Ibb3c0fe035bb8789aad65dbdfefaf7cb17b64c4e Reviewed-on: https://chromium-review.googlesource.com/748317 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 2348e21a
......@@ -3022,7 +3022,7 @@ void Program::defineInterfaceBlock(const sh::InterfaceBlock &interfaceBlock, GLe
InterfaceBlock block(interfaceBlock.name, interfaceBlock.mappedName, true, arrayElement,
blockBinding + arrayElement);
block.memberIndexes = blockIndexes;
MarkResourceStaticUse(&block, shaderType, interfaceBlock.staticUse);
block.setStaticUse(shaderType, interfaceBlock.staticUse);
// Since all block elements in an array share the same active interface blocks, they
// will all be active once any block member is used. So, since interfaceBlock.name[0]
......@@ -3055,7 +3055,7 @@ void Program::defineInterfaceBlock(const sh::InterfaceBlock &interfaceBlock, GLe
InterfaceBlock block(interfaceBlock.name, interfaceBlock.mappedName, false, 0,
blockBinding);
block.memberIndexes = blockIndexes;
MarkResourceStaticUse(&block, shaderType, interfaceBlock.staticUse);
block.setStaticUse(shaderType, interfaceBlock.staticUse);
block.dataSize = static_cast<unsigned int>(blockSize);
if (interfaceBlock.blockType == sh::BlockType::BLOCK_UNIFORM)
{
......
......@@ -13,21 +13,32 @@
namespace gl
{
template <typename T>
void MarkResourceStaticUse(T *resource, GLenum shaderType, bool used)
StaticallyUsed::StaticallyUsed()
: vertexStaticUse(false), fragmentStaticUse(false), computeStaticUse(false)
{
}
StaticallyUsed::~StaticallyUsed()
{
}
StaticallyUsed::StaticallyUsed(const StaticallyUsed &rhs) = default;
StaticallyUsed &StaticallyUsed::operator=(const StaticallyUsed &rhs) = default;
void StaticallyUsed::setStaticUse(GLenum shaderType, bool used)
{
switch (shaderType)
{
case GL_VERTEX_SHADER:
resource->vertexStaticUse = used;
vertexStaticUse = used;
break;
case GL_FRAGMENT_SHADER:
resource->fragmentStaticUse = used;
fragmentStaticUse = used;
break;
case GL_COMPUTE_SHADER:
resource->computeStaticUse = used;
computeStaticUse = used;
break;
default:
......@@ -35,16 +46,15 @@ void MarkResourceStaticUse(T *resource, GLenum shaderType, bool used)
}
}
template void MarkResourceStaticUse(LinkedUniform *resource, GLenum shaderType, bool used);
template void MarkResourceStaticUse(InterfaceBlock *resource, GLenum shaderType, bool used);
void StaticallyUsed::unionWith(const StaticallyUsed &other)
{
vertexStaticUse |= other.vertexStaticUse;
fragmentStaticUse |= other.fragmentStaticUse;
computeStaticUse |= other.computeStaticUse;
}
LinkedUniform::LinkedUniform()
: typeInfo(nullptr),
bufferIndex(-1),
blockInfo(sh::BlockMemberInfo::getDefaultBlockInfo()),
vertexStaticUse(false),
fragmentStaticUse(false),
computeStaticUse(false)
: typeInfo(nullptr), bufferIndex(-1), blockInfo(sh::BlockMemberInfo::getDefaultBlockInfo())
{
}
......@@ -57,12 +67,7 @@ LinkedUniform::LinkedUniform(GLenum typeIn,
const int locationIn,
const int bufferIndexIn,
const sh::BlockMemberInfo &blockInfoIn)
: typeInfo(&GetUniformTypeInfo(typeIn)),
bufferIndex(bufferIndexIn),
blockInfo(blockInfoIn),
vertexStaticUse(false),
fragmentStaticUse(false),
computeStaticUse(false)
: typeInfo(&GetUniformTypeInfo(typeIn)), bufferIndex(bufferIndexIn), blockInfo(blockInfoIn)
{
type = typeIn;
precision = precisionIn;
......@@ -77,35 +82,26 @@ LinkedUniform::LinkedUniform(const sh::Uniform &uniform)
: sh::Uniform(uniform),
typeInfo(&GetUniformTypeInfo(type)),
bufferIndex(-1),
blockInfo(sh::BlockMemberInfo::getDefaultBlockInfo()),
vertexStaticUse(false),
fragmentStaticUse(false),
computeStaticUse(false)
blockInfo(sh::BlockMemberInfo::getDefaultBlockInfo())
{
}
LinkedUniform::LinkedUniform(const LinkedUniform &uniform)
: sh::Uniform(uniform),
StaticallyUsed(uniform),
typeInfo(uniform.typeInfo),
bufferIndex(uniform.bufferIndex),
blockInfo(uniform.blockInfo),
vertexStaticUse(uniform.vertexStaticUse),
fragmentStaticUse(uniform.fragmentStaticUse),
computeStaticUse(uniform.computeStaticUse)
blockInfo(uniform.blockInfo)
{
}
LinkedUniform &LinkedUniform::operator=(const LinkedUniform &uniform)
{
sh::Uniform::operator=(uniform);
StaticallyUsed::operator=(uniform);
typeInfo = uniform.typeInfo;
bufferIndex = uniform.bufferIndex;
blockInfo = uniform.blockInfo;
vertexStaticUse = uniform.vertexStaticUse;
fragmentStaticUse = uniform.fragmentStaticUse;
computeStaticUse = uniform.computeStaticUse;
return *this;
}
......@@ -148,13 +144,17 @@ size_t LinkedUniform::getElementComponents() const
return typeInfo->componentCount;
}
ShaderVariableBuffer::ShaderVariableBuffer()
: binding(0),
dataSize(0),
vertexStaticUse(false),
fragmentStaticUse(false),
computeStaticUse(false)
ShaderVariableBuffer::ShaderVariableBuffer() : binding(0), dataSize(0)
{
}
ShaderVariableBuffer::~ShaderVariableBuffer()
{
}
int ShaderVariableBuffer::numActiveVariables() const
{
return static_cast<int>(memberIndexes.size());
}
InterfaceBlock::InterfaceBlock() : isArray(false), arrayElement(0)
......
......@@ -20,11 +20,24 @@ namespace gl
{
struct UniformTypeInfo;
template <typename T>
void MarkResourceStaticUse(T *resource, GLenum shaderType, bool used);
struct StaticallyUsed
{
StaticallyUsed();
StaticallyUsed(const StaticallyUsed &rhs);
virtual ~StaticallyUsed();
StaticallyUsed &operator=(const StaticallyUsed &rhs);
void setStaticUse(GLenum shaderType, bool used);
void unionWith(const StaticallyUsed &other);
bool vertexStaticUse;
bool fragmentStaticUse;
bool computeStaticUse;
};
// Helper struct representing a single shader uniform
struct LinkedUniform : public sh::Uniform
struct LinkedUniform : public sh::Uniform, public StaticallyUsed
{
LinkedUniform();
LinkedUniform(GLenum type,
......@@ -54,27 +67,19 @@ struct LinkedUniform : public sh::Uniform
// Identifies the containing buffer backed resource -- interface block or atomic counter buffer.
int bufferIndex;
sh::BlockMemberInfo blockInfo;
bool vertexStaticUse;
bool fragmentStaticUse;
bool computeStaticUse;
};
// Parent struct for atomic counter, uniform block, and shader storage block buffer, which all
// contain a group of shader variables, and have a GL buffer backed.
struct ShaderVariableBuffer
struct ShaderVariableBuffer : public StaticallyUsed
{
ShaderVariableBuffer();
virtual ~ShaderVariableBuffer(){};
int numActiveVariables() const { return static_cast<int>(memberIndexes.size()); }
virtual ~ShaderVariableBuffer();
int numActiveVariables() const;
int binding;
unsigned int dataSize;
std::vector<unsigned int> memberIndexes;
bool vertexStaticUse;
bool fragmentStaticUse;
bool computeStaticUse;
};
using AtomicCounterBuffer = ShaderVariableBuffer;
......
......@@ -536,7 +536,7 @@ UniformLinker::ShaderUniformCount UniformLinker::flattenUniformImpl(
if (markStaticUse)
{
existingUniform->staticUse = true;
MarkResourceStaticUse(existingUniform, shaderType, true);
existingUniform->setStaticUse(shaderType, true);
}
}
else
......@@ -548,7 +548,7 @@ UniformLinker::ShaderUniformCount UniformLinker::flattenUniformImpl(
linkedUniform.staticUse = markStaticUse;
if (markStaticUse)
{
MarkResourceStaticUse(&linkedUniform, shaderType, true);
linkedUniform.setStaticUse(shaderType, true);
}
uniformList->push_back(linkedUniform);
......
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