Use packed enums on shader types in ANGLE renderer
This patch uses a packed internal enum ShaderType everywhere we
need a shader type instead of the GLenum value of the shader type.
This patch also uses program::getAttachedShader(type) everywhere
we need to get gl::Shader from a program in ANGLE.
BUG=angleproject:2169
Change-Id: I28a7fa1cfe35622c57a486932911110688eaadec
Reviewed-on: https://chromium-review.googlesource.com/972844
Commit-Queue: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/libANGLE/ProgramLinkedResources.cpp b/src/libANGLE/ProgramLinkedResources.cpp
index 5dcd0b9..9ef76b7 100644
--- a/src/libANGLE/ProgramLinkedResources.cpp
+++ b/src/libANGLE/ProgramLinkedResources.cpp
@@ -49,7 +49,7 @@
}
template <typename VarT>
-void SetActive(std::vector<VarT> *list, const std::string &name, GLenum shaderType, bool active)
+void SetActive(std::vector<VarT> *list, const std::string &name, ShaderType shaderType, bool active)
{
for (auto &variable : *list)
{
@@ -99,7 +99,7 @@
return LinkMismatchError::NO_MISMATCH;
}
-using ShaderUniform = std::pair<GLenum, const sh::Uniform *>;
+using ShaderUniform = std::pair<ShaderType, const sh::Uniform *>;
bool ValidateGraphicsUniformsPerShader(const Context *context,
Shader *shaderToLink,
@@ -154,9 +154,10 @@
InfoLog &infoLog,
const ProgramBindings &uniformLocationBindings)
{
- if (mState.getAttachedVertexShader() && mState.getAttachedFragmentShader())
+ if (mState.getAttachedShader(ShaderType::Vertex) &&
+ mState.getAttachedShader(ShaderType::Fragment))
{
- ASSERT(mState.getAttachedComputeShader() == nullptr);
+ ASSERT(mState.getAttachedShader(ShaderType::Compute) == nullptr);
if (!validateGraphicsUniforms(context, infoLog))
{
return false;
@@ -187,17 +188,18 @@
{
// Check that uniforms defined in the graphics shaders are identical
std::map<std::string, ShaderUniform> linkedUniforms;
- for (const sh::Uniform &vertexUniform : mState.getAttachedVertexShader()->getUniforms(context))
+ for (const sh::Uniform &vertexUniform :
+ mState.getAttachedShader(ShaderType::Vertex)->getUniforms(context))
{
- linkedUniforms[vertexUniform.name] = std::make_pair(GL_VERTEX_SHADER, &vertexUniform);
+ linkedUniforms[vertexUniform.name] = std::make_pair(ShaderType::Vertex, &vertexUniform);
}
std::vector<Shader *> activeShadersToLink;
- if (mState.getAttachedGeometryShader())
+ if (mState.getAttachedShader(ShaderType::Geometry))
{
- activeShadersToLink.push_back(mState.getAttachedGeometryShader());
+ activeShadersToLink.push_back(mState.getAttachedShader(ShaderType::Geometry));
}
- activeShadersToLink.push_back(mState.getAttachedFragmentShader());
+ activeShadersToLink.push_back(mState.getAttachedShader(ShaderType::Fragment));
const size_t numActiveShadersToLink = activeShadersToLink.size();
for (size_t shaderIndex = 0; shaderIndex < numActiveShadersToLink; ++shaderIndex)
@@ -451,9 +453,9 @@
const Caps &caps = context->getCaps();
- if (mState.getAttachedComputeShader())
+ if (mState.getAttachedShader(ShaderType::Compute))
{
- Shader *computeShader = mState.getAttachedComputeShader();
+ Shader *computeShader = mState.getAttachedShader(ShaderType::Compute);
// TODO (mradev): check whether we need finer-grained component counting
if (!flattenUniformsAndCheckCapsForShader(
@@ -471,7 +473,7 @@
}
else
{
- Shader *vertexShader = mState.getAttachedVertexShader();
+ Shader *vertexShader = mState.getAttachedShader(ShaderType::Vertex);
if (!flattenUniformsAndCheckCapsForShader(
context, vertexShader, caps.maxVertexUniformVectors,
@@ -486,7 +488,7 @@
return false;
}
- Shader *fragmentShader = mState.getAttachedFragmentShader();
+ Shader *fragmentShader = mState.getAttachedShader(ShaderType::Fragment);
if (!flattenUniformsAndCheckCapsForShader(
context, fragmentShader, caps.maxFragmentUniformVectors, caps.maxTextureImageUnits,
@@ -500,7 +502,7 @@
return false;
}
- Shader *geometryShader = mState.getAttachedGeometryShader();
+ Shader *geometryShader = mState.getAttachedShader(ShaderType::Geometry);
// TODO (jiawei.shao@intel.com): check whether we need finer-grained component counting
if (geometryShader &&
!flattenUniformsAndCheckCapsForShader(
@@ -528,7 +530,7 @@
std::vector<LinkedUniform> *samplerUniforms,
std::vector<LinkedUniform> *imageUniforms,
std::vector<LinkedUniform> *atomicCounterUniforms,
- GLenum shaderType)
+ ShaderType shaderType)
{
int location = uniform.location;
ShaderUniformCount shaderUniformCount =
@@ -550,7 +552,7 @@
std::vector<LinkedUniform> *samplerUniforms,
std::vector<LinkedUniform> *imageUniforms,
std::vector<LinkedUniform> *atomicCounterUniforms,
- GLenum shaderType,
+ ShaderType shaderType,
bool markActive,
bool markStaticUse,
int binding,
@@ -590,7 +592,7 @@
std::vector<LinkedUniform> *samplerUniforms,
std::vector<LinkedUniform> *imageUniforms,
std::vector<LinkedUniform> *atomicCounterUniforms,
- GLenum shaderType,
+ ShaderType shaderType,
bool markActive,
bool markStaticUse,
int binding,
@@ -617,7 +619,7 @@
std::vector<LinkedUniform> *samplerUniforms,
std::vector<LinkedUniform> *imageUniforms,
std::vector<LinkedUniform> *atomicCounterUniforms,
- GLenum shaderType,
+ ShaderType shaderType,
bool markActive,
bool markStaticUse,
int binding,
@@ -650,7 +652,7 @@
std::vector<LinkedUniform> *samplerUniforms,
std::vector<LinkedUniform> *imageUniforms,
std::vector<LinkedUniform> *atomicCounterUniforms,
- GLenum shaderType,
+ ShaderType shaderType,
bool markActive,
bool markStaticUse,
int binding,
@@ -808,7 +810,7 @@
{
}
-void InterfaceBlockLinker::addShaderBlocks(GLenum shader,
+void InterfaceBlockLinker::addShaderBlocks(ShaderType shader,
const std::vector<sh::InterfaceBlock> *blocks)
{
mShaderBlocks.push_back(std::make_pair(shader, blocks));
@@ -823,7 +825,7 @@
for (const auto &shaderBlocks : mShaderBlocks)
{
- const GLenum shaderType = shaderBlocks.first;
+ const ShaderType shaderType = shaderBlocks.first;
for (const auto &block : *shaderBlocks.second)
{
@@ -866,7 +868,7 @@
int blockIndex,
bool singleEntryForTopLevelArray,
int topLevelArraySize,
- GLenum shaderType) const
+ ShaderType shaderType) const
{
// Nested arrays are processed starting from outermost (arrayNestingIndex 0u) and ending at the
// innermost.
@@ -901,7 +903,7 @@
int blockIndex,
bool singleEntryForTopLevelArray,
int topLevelArraySize,
- GLenum shaderType) const
+ ShaderType shaderType) const
{
for (const VarT &field : fields)
{
@@ -922,7 +924,7 @@
int blockIndex,
bool singleEntryForTopLevelArray,
int topLevelArraySize,
- GLenum shaderType) const
+ ShaderType shaderType) const
{
int nextArraySize = topLevelArraySize;
if (((field.isArray() && field.isStruct()) || field.isArrayOfArrays()) &&
@@ -1002,7 +1004,7 @@
void InterfaceBlockLinker::defineInterfaceBlock(const GetBlockSize &getBlockSize,
const GetBlockMemberInfo &getMemberInfo,
const sh::InterfaceBlock &interfaceBlock,
- GLenum shaderType) const
+ ShaderType shaderType) const
{
size_t blockSize = 0;
std::vector<unsigned int> blockIndexes;
@@ -1074,7 +1076,7 @@
int blockIndex,
const sh::BlockMemberInfo &memberInfo,
int /*topLevelArraySize*/,
- GLenum shaderType) const
+ ShaderType shaderType) const
{
LinkedUniform newUniform(field.type, field.precision, fullName, field.arraySizes, -1, -1, -1,
blockIndex, memberInfo);
@@ -1092,7 +1094,7 @@
}
void UniformBlockLinker::updateBlockMemberActiveImpl(const std::string &fullName,
- GLenum shaderType,
+ ShaderType shaderType,
bool active) const
{
SetActive(mUniformsOut, fullName, shaderType, active);
@@ -1115,7 +1117,7 @@
int blockIndex,
const sh::BlockMemberInfo &memberInfo,
int topLevelArraySize,
- GLenum shaderType) const
+ ShaderType shaderType) const
{
BufferVariable newBufferVariable(field.type, field.precision, fullName, field.arraySizes,
blockIndex, memberInfo);
@@ -1133,7 +1135,7 @@
}
void ShaderStorageBlockLinker::updateBlockMemberActiveImpl(const std::string &fullName,
- GLenum shaderType,
+ ShaderType shaderType,
bool active) const
{
SetActive(mBufferVariablesOut, fullName, shaderType, active);