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 ...@@ -3022,7 +3022,7 @@ void Program::defineInterfaceBlock(const sh::InterfaceBlock &interfaceBlock, GLe
InterfaceBlock block(interfaceBlock.name, interfaceBlock.mappedName, true, arrayElement, InterfaceBlock block(interfaceBlock.name, interfaceBlock.mappedName, true, arrayElement,
blockBinding + arrayElement); blockBinding + arrayElement);
block.memberIndexes = blockIndexes; 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 // 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] // 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 ...@@ -3055,7 +3055,7 @@ void Program::defineInterfaceBlock(const sh::InterfaceBlock &interfaceBlock, GLe
InterfaceBlock block(interfaceBlock.name, interfaceBlock.mappedName, false, 0, InterfaceBlock block(interfaceBlock.name, interfaceBlock.mappedName, false, 0,
blockBinding); blockBinding);
block.memberIndexes = blockIndexes; block.memberIndexes = blockIndexes;
MarkResourceStaticUse(&block, shaderType, interfaceBlock.staticUse); block.setStaticUse(shaderType, interfaceBlock.staticUse);
block.dataSize = static_cast<unsigned int>(blockSize); block.dataSize = static_cast<unsigned int>(blockSize);
if (interfaceBlock.blockType == sh::BlockType::BLOCK_UNIFORM) if (interfaceBlock.blockType == sh::BlockType::BLOCK_UNIFORM)
{ {
......
...@@ -13,21 +13,32 @@ ...@@ -13,21 +13,32 @@
namespace gl namespace gl
{ {
template <typename T> StaticallyUsed::StaticallyUsed()
void MarkResourceStaticUse(T *resource, GLenum shaderType, bool used) : 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) switch (shaderType)
{ {
case GL_VERTEX_SHADER: case GL_VERTEX_SHADER:
resource->vertexStaticUse = used; vertexStaticUse = used;
break; break;
case GL_FRAGMENT_SHADER: case GL_FRAGMENT_SHADER:
resource->fragmentStaticUse = used; fragmentStaticUse = used;
break; break;
case GL_COMPUTE_SHADER: case GL_COMPUTE_SHADER:
resource->computeStaticUse = used; computeStaticUse = used;
break; break;
default: default:
...@@ -35,16 +46,15 @@ void MarkResourceStaticUse(T *resource, GLenum shaderType, bool used) ...@@ -35,16 +46,15 @@ void MarkResourceStaticUse(T *resource, GLenum shaderType, bool used)
} }
} }
template void MarkResourceStaticUse(LinkedUniform *resource, GLenum shaderType, bool used); void StaticallyUsed::unionWith(const StaticallyUsed &other)
template void MarkResourceStaticUse(InterfaceBlock *resource, GLenum shaderType, bool used); {
vertexStaticUse |= other.vertexStaticUse;
fragmentStaticUse |= other.fragmentStaticUse;
computeStaticUse |= other.computeStaticUse;
}
LinkedUniform::LinkedUniform() LinkedUniform::LinkedUniform()
: typeInfo(nullptr), : typeInfo(nullptr), bufferIndex(-1), blockInfo(sh::BlockMemberInfo::getDefaultBlockInfo())
bufferIndex(-1),
blockInfo(sh::BlockMemberInfo::getDefaultBlockInfo()),
vertexStaticUse(false),
fragmentStaticUse(false),
computeStaticUse(false)
{ {
} }
...@@ -57,12 +67,7 @@ LinkedUniform::LinkedUniform(GLenum typeIn, ...@@ -57,12 +67,7 @@ LinkedUniform::LinkedUniform(GLenum typeIn,
const int locationIn, const int locationIn,
const int bufferIndexIn, const int bufferIndexIn,
const sh::BlockMemberInfo &blockInfoIn) const sh::BlockMemberInfo &blockInfoIn)
: typeInfo(&GetUniformTypeInfo(typeIn)), : typeInfo(&GetUniformTypeInfo(typeIn)), bufferIndex(bufferIndexIn), blockInfo(blockInfoIn)
bufferIndex(bufferIndexIn),
blockInfo(blockInfoIn),
vertexStaticUse(false),
fragmentStaticUse(false),
computeStaticUse(false)
{ {
type = typeIn; type = typeIn;
precision = precisionIn; precision = precisionIn;
...@@ -77,35 +82,26 @@ LinkedUniform::LinkedUniform(const sh::Uniform &uniform) ...@@ -77,35 +82,26 @@ 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::BlockMemberInfo::getDefaultBlockInfo())
vertexStaticUse(false),
fragmentStaticUse(false),
computeStaticUse(false)
{ {
} }
LinkedUniform::LinkedUniform(const LinkedUniform &uniform) LinkedUniform::LinkedUniform(const LinkedUniform &uniform)
: sh::Uniform(uniform), : sh::Uniform(uniform),
StaticallyUsed(uniform),
typeInfo(uniform.typeInfo), typeInfo(uniform.typeInfo),
bufferIndex(uniform.bufferIndex), bufferIndex(uniform.bufferIndex),
blockInfo(uniform.blockInfo), blockInfo(uniform.blockInfo)
vertexStaticUse(uniform.vertexStaticUse),
fragmentStaticUse(uniform.fragmentStaticUse),
computeStaticUse(uniform.computeStaticUse)
{ {
} }
LinkedUniform &LinkedUniform::operator=(const LinkedUniform &uniform) LinkedUniform &LinkedUniform::operator=(const LinkedUniform &uniform)
{ {
sh::Uniform::operator=(uniform); sh::Uniform::operator=(uniform);
StaticallyUsed::operator=(uniform);
typeInfo = uniform.typeInfo; typeInfo = uniform.typeInfo;
bufferIndex = uniform.bufferIndex; bufferIndex = uniform.bufferIndex;
blockInfo = uniform.blockInfo; blockInfo = uniform.blockInfo;
vertexStaticUse = uniform.vertexStaticUse;
fragmentStaticUse = uniform.fragmentStaticUse;
computeStaticUse = uniform.computeStaticUse;
return *this; return *this;
} }
...@@ -148,13 +144,17 @@ size_t LinkedUniform::getElementComponents() const ...@@ -148,13 +144,17 @@ size_t LinkedUniform::getElementComponents() const
return typeInfo->componentCount; return typeInfo->componentCount;
} }
ShaderVariableBuffer::ShaderVariableBuffer() ShaderVariableBuffer::ShaderVariableBuffer() : binding(0), dataSize(0)
: binding(0), {
dataSize(0), }
vertexStaticUse(false),
fragmentStaticUse(false), ShaderVariableBuffer::~ShaderVariableBuffer()
computeStaticUse(false) {
}
int ShaderVariableBuffer::numActiveVariables() const
{ {
return static_cast<int>(memberIndexes.size());
} }
InterfaceBlock::InterfaceBlock() : isArray(false), arrayElement(0) InterfaceBlock::InterfaceBlock() : isArray(false), arrayElement(0)
......
...@@ -20,11 +20,24 @@ namespace gl ...@@ -20,11 +20,24 @@ namespace gl
{ {
struct UniformTypeInfo; struct UniformTypeInfo;
template <typename T> struct StaticallyUsed
void MarkResourceStaticUse(T *resource, GLenum shaderType, bool used); {
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 // Helper struct representing a single shader uniform
struct LinkedUniform : public sh::Uniform struct LinkedUniform : public sh::Uniform, public StaticallyUsed
{ {
LinkedUniform(); LinkedUniform();
LinkedUniform(GLenum type, LinkedUniform(GLenum type,
...@@ -54,27 +67,19 @@ struct LinkedUniform : public sh::Uniform ...@@ -54,27 +67,19 @@ struct LinkedUniform : public sh::Uniform
// Identifies the containing buffer backed resource -- interface block or atomic counter buffer. // Identifies the containing buffer backed resource -- interface block or atomic counter buffer.
int bufferIndex; int bufferIndex;
sh::BlockMemberInfo blockInfo; sh::BlockMemberInfo blockInfo;
bool vertexStaticUse;
bool fragmentStaticUse;
bool computeStaticUse;
}; };
// Parent struct for atomic counter, uniform block, and shader storage block buffer, which all // 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. // contain a group of shader variables, and have a GL buffer backed.
struct ShaderVariableBuffer struct ShaderVariableBuffer : public StaticallyUsed
{ {
ShaderVariableBuffer(); ShaderVariableBuffer();
virtual ~ShaderVariableBuffer(){}; virtual ~ShaderVariableBuffer();
int numActiveVariables() const { return static_cast<int>(memberIndexes.size()); } int numActiveVariables() const;
int binding; int binding;
unsigned int dataSize; unsigned int dataSize;
std::vector<unsigned int> memberIndexes; std::vector<unsigned int> memberIndexes;
bool vertexStaticUse;
bool fragmentStaticUse;
bool computeStaticUse;
}; };
using AtomicCounterBuffer = ShaderVariableBuffer; using AtomicCounterBuffer = ShaderVariableBuffer;
......
...@@ -536,7 +536,7 @@ UniformLinker::ShaderUniformCount UniformLinker::flattenUniformImpl( ...@@ -536,7 +536,7 @@ UniformLinker::ShaderUniformCount UniformLinker::flattenUniformImpl(
if (markStaticUse) if (markStaticUse)
{ {
existingUniform->staticUse = true; existingUniform->staticUse = true;
MarkResourceStaticUse(existingUniform, shaderType, true); existingUniform->setStaticUse(shaderType, true);
} }
} }
else else
...@@ -548,7 +548,7 @@ UniformLinker::ShaderUniformCount UniformLinker::flattenUniformImpl( ...@@ -548,7 +548,7 @@ UniformLinker::ShaderUniformCount UniformLinker::flattenUniformImpl(
linkedUniform.staticUse = markStaticUse; linkedUniform.staticUse = markStaticUse;
if (markStaticUse) if (markStaticUse)
{ {
MarkResourceStaticUse(&linkedUniform, shaderType, true); linkedUniform.setStaticUse(shaderType, true);
} }
uniformList->push_back(linkedUniform); 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