Commit 016105bb by Jiawei Shao Committed by Commit Bot

Store shader information in ShaderMap in class Program and Compiler

This patch is the first one in the series of using ShaderMap as the container of the resources for each type of shader everywhere in ANGLE. This patch defines the new data structure ShaderMap and use it in class Program and Compiler in ANGLE front-end. The following work includes: 1. Use ShaderMap in D3D back-ends. 2. Use ShaderMap in Vulkan back-ends. BUG=angleproject:2169 Change-Id: I1c284d95f5a071c45bb468901eabc15694fffe38 Reviewed-on: https://chromium-review.googlesource.com/1011722 Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 76b2c385
......@@ -55,10 +55,7 @@ Compiler::Compiler(rx::GLImplFactory *implFactory, const ContextState &state)
state.getExtensions().webglCompatibility)),
mOutputType(mImplementation->getTranslatorOutputType()),
mResources(),
mFragmentCompiler(nullptr),
mVertexCompiler(nullptr),
mComputeCompiler(nullptr),
mGeometryCompiler(nullptr)
mShaderCompilers({})
{
ASSERT(state.getClientMajorVersion() == 2 || state.getClientMajorVersion() == 3);
......@@ -156,40 +153,17 @@ Compiler::Compiler(rx::GLImplFactory *implFactory, const ContextState &state)
Compiler::~Compiler()
{
if (mFragmentCompiler)
for (ShaderType shaderType : AllShaderTypes())
{
sh::Destruct(mFragmentCompiler);
mFragmentCompiler = nullptr;
ASSERT(activeCompilerHandles > 0);
activeCompilerHandles--;
}
if (mVertexCompiler)
{
sh::Destruct(mVertexCompiler);
mVertexCompiler = nullptr;
ASSERT(activeCompilerHandles > 0);
activeCompilerHandles--;
}
if (mComputeCompiler)
{
sh::Destruct(mComputeCompiler);
mComputeCompiler = nullptr;
ASSERT(activeCompilerHandles > 0);
activeCompilerHandles--;
}
if (mGeometryCompiler)
{
sh::Destruct(mGeometryCompiler);
mGeometryCompiler = nullptr;
ShHandle compilerHandle = mShaderCompilers[shaderType];
if (compilerHandle)
{
sh::Destruct(compilerHandle);
mShaderCompilers[shaderType] = nullptr;
ASSERT(activeCompilerHandles > 0);
activeCompilerHandles--;
ASSERT(activeCompilerHandles > 0);
activeCompilerHandles--;
}
}
if (activeCompilerHandles == 0)
......@@ -202,26 +176,8 @@ Compiler::~Compiler()
ShHandle Compiler::getCompilerHandle(ShaderType type)
{
ShHandle *compiler = nullptr;
switch (type)
{
case ShaderType::Vertex:
compiler = &mVertexCompiler;
break;
case ShaderType::Fragment:
compiler = &mFragmentCompiler;
break;
case ShaderType::Compute:
compiler = &mComputeCompiler;
break;
case ShaderType::Geometry:
compiler = &mGeometryCompiler;
break;
default:
UNREACHABLE();
return nullptr;
}
ASSERT(type != ShaderType::InvalidEnum);
ShHandle *compiler = &mShaderCompilers[type];
if (!(*compiler))
{
......
......@@ -12,7 +12,7 @@
#include "GLSLANG/ShaderLang.h"
#include "libANGLE/Error.h"
#include "libANGLE/PackedGLEnums_autogen.h"
#include "libANGLE/PackedGLEnums.h"
#include "libANGLE/RefCountObject.h"
namespace rx
......@@ -41,10 +41,7 @@ class Compiler final : public RefCountObjectNoID
ShShaderOutput mOutputType;
ShBuiltInResources mResources;
ShHandle mFragmentCompiler;
ShHandle mVertexCompiler;
ShHandle mComputeCompiler;
ShHandle mGeometryCompiler;
ShaderMap<ShHandle> mShaderCompilers;
};
} // namespace gl
......
......@@ -172,8 +172,16 @@ struct AllShaderTypes
angle::EnumIterator<ShaderType> end() const { return kAfterShaderTypeMax; }
};
constexpr size_t kGraphicsShaderCount = static_cast<size_t>(ShaderType::EnumCount) - 1u;
// Arrange the shader types in the order of rendering pipeline
constexpr std::array<ShaderType, kGraphicsShaderCount> kAllGraphicsShaderTypes = {
ShaderType::Vertex, ShaderType::Geometry, ShaderType::Fragment};
using ShaderBitSet = angle::PackedEnumBitSet<ShaderType>;
template <typename T>
using ShaderMap = angle::PackedEnumMap<ShaderType, T>;
TextureType SamplerTypeToTextureType(GLenum samplerType);
} // namespace gl
......
......@@ -352,6 +352,8 @@ class ProgramState final : angle::NonCopyable
const ShaderBitSet &getLinkedShaderStages() const { return mLinkedShaderStages; }
bool hasAttachedShader() const;
private:
friend class MemoryProgramCache;
friend class Program;
......@@ -362,10 +364,7 @@ class ProgramState final : angle::NonCopyable
sh::WorkGroupSize mComputeShaderLocalSize;
Shader *mAttachedFragmentShader;
Shader *mAttachedVertexShader;
Shader *mAttachedComputeShader;
Shader *mAttachedGeometryShader;
ShaderMap<Shader *> mAttachedShaders;
std::vector<std::string> mTransformFeedbackVaryingNames;
std::vector<TransformFeedbackVarying> mLinkedTransformFeedbackVaryings;
......
......@@ -188,27 +188,29 @@ bool UniformLinker::validateGraphicsUniforms(const Context *context, InfoLog &in
{
// Check that uniforms defined in the graphics shaders are identical
std::map<std::string, ShaderUniform> linkedUniforms;
for (const sh::Uniform &vertexUniform :
mState.getAttachedShader(ShaderType::Vertex)->getUniforms(context))
{
linkedUniforms[vertexUniform.name] = std::make_pair(ShaderType::Vertex, &vertexUniform);
}
std::vector<Shader *> activeShadersToLink;
if (mState.getAttachedShader(ShaderType::Geometry))
{
activeShadersToLink.push_back(mState.getAttachedShader(ShaderType::Geometry));
}
activeShadersToLink.push_back(mState.getAttachedShader(ShaderType::Fragment));
const size_t numActiveShadersToLink = activeShadersToLink.size();
for (size_t shaderIndex = 0; shaderIndex < numActiveShadersToLink; ++shaderIndex)
for (ShaderType shaderType : kAllGraphicsShaderTypes)
{
bool isLastShader = (shaderIndex == numActiveShadersToLink - 1);
if (!ValidateGraphicsUniformsPerShader(context, activeShadersToLink[shaderIndex],
!isLastShader, &linkedUniforms, infoLog))
Shader *currentShader = mState.getAttachedShader(shaderType);
if (currentShader)
{
return false;
if (shaderType == ShaderType::Vertex)
{
for (const sh::Uniform &vertexUniform : currentShader->getUniforms(context))
{
linkedUniforms[vertexUniform.name] =
std::make_pair(ShaderType::Vertex, &vertexUniform);
}
}
else
{
bool isLastShader = (shaderType == ShaderType::Fragment);
if (!ValidateGraphicsUniformsPerShader(context, currentShader, !isLastShader,
&linkedUniforms, infoLog))
{
return false;
}
}
}
}
......@@ -802,7 +804,7 @@ bool UniformLinker::checkMaxCombinedAtomicCounters(const Caps &caps, InfoLog &in
// InterfaceBlockLinker implementation.
InterfaceBlockLinker::InterfaceBlockLinker(std::vector<InterfaceBlock> *blocksOut)
: mBlocksOut(blocksOut)
: mShaderBlocks({}), mBlocksOut(blocksOut)
{
}
......@@ -810,10 +812,10 @@ InterfaceBlockLinker::~InterfaceBlockLinker()
{
}
void InterfaceBlockLinker::addShaderBlocks(ShaderType shader,
void InterfaceBlockLinker::addShaderBlocks(ShaderType shaderType,
const std::vector<sh::InterfaceBlock> *blocks)
{
mShaderBlocks.push_back(std::make_pair(shader, blocks));
mShaderBlocks[shaderType] = blocks;
}
void InterfaceBlockLinker::linkBlocks(const GetBlockSize &getBlockSize,
......@@ -823,11 +825,14 @@ void InterfaceBlockLinker::linkBlocks(const GetBlockSize &getBlockSize,
std::set<std::string> visitedList;
for (const auto &shaderBlocks : mShaderBlocks)
for (ShaderType shaderType : AllShaderTypes())
{
const ShaderType shaderType = shaderBlocks.first;
if (!mShaderBlocks[shaderType])
{
continue;
}
for (const auto &block : *shaderBlocks.second)
for (const auto &block : *mShaderBlocks[shaderType])
{
if (!IsActiveInterfaceBlock(block))
continue;
......
......@@ -13,7 +13,7 @@
#include "angle_gl.h"
#include "common/angleutils.h"
#include "libANGLE/PackedGLEnums_autogen.h"
#include "libANGLE/PackedGLEnums.h"
#include "libANGLE/VaryingPacking.h"
#include <functional>
......@@ -234,8 +234,7 @@ class InterfaceBlockLinker : angle::NonCopyable
ShaderType shaderType,
bool active) const = 0;
using ShaderBlocks = std::pair<ShaderType, const std::vector<sh::InterfaceBlock> *>;
std::vector<ShaderBlocks> mShaderBlocks;
ShaderMap<const std::vector<sh::InterfaceBlock> *> mShaderBlocks;
std::vector<InterfaceBlock> *mBlocksOut;
......
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