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) ...@@ -55,10 +55,7 @@ Compiler::Compiler(rx::GLImplFactory *implFactory, const ContextState &state)
state.getExtensions().webglCompatibility)), state.getExtensions().webglCompatibility)),
mOutputType(mImplementation->getTranslatorOutputType()), mOutputType(mImplementation->getTranslatorOutputType()),
mResources(), mResources(),
mFragmentCompiler(nullptr), mShaderCompilers({})
mVertexCompiler(nullptr),
mComputeCompiler(nullptr),
mGeometryCompiler(nullptr)
{ {
ASSERT(state.getClientMajorVersion() == 2 || state.getClientMajorVersion() == 3); ASSERT(state.getClientMajorVersion() == 2 || state.getClientMajorVersion() == 3);
...@@ -156,40 +153,17 @@ Compiler::Compiler(rx::GLImplFactory *implFactory, const ContextState &state) ...@@ -156,40 +153,17 @@ Compiler::Compiler(rx::GLImplFactory *implFactory, const ContextState &state)
Compiler::~Compiler() Compiler::~Compiler()
{ {
if (mFragmentCompiler) for (ShaderType shaderType : AllShaderTypes())
{ {
sh::Destruct(mFragmentCompiler); ShHandle compilerHandle = mShaderCompilers[shaderType];
mFragmentCompiler = nullptr; if (compilerHandle)
{
ASSERT(activeCompilerHandles > 0); sh::Destruct(compilerHandle);
activeCompilerHandles--; mShaderCompilers[shaderType] = nullptr;
}
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;
ASSERT(activeCompilerHandles > 0); ASSERT(activeCompilerHandles > 0);
activeCompilerHandles--; activeCompilerHandles--;
}
} }
if (activeCompilerHandles == 0) if (activeCompilerHandles == 0)
...@@ -202,26 +176,8 @@ Compiler::~Compiler() ...@@ -202,26 +176,8 @@ Compiler::~Compiler()
ShHandle Compiler::getCompilerHandle(ShaderType type) ShHandle Compiler::getCompilerHandle(ShaderType type)
{ {
ShHandle *compiler = nullptr; ASSERT(type != ShaderType::InvalidEnum);
switch (type) ShHandle *compiler = &mShaderCompilers[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;
}
if (!(*compiler)) if (!(*compiler))
{ {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "GLSLANG/ShaderLang.h" #include "GLSLANG/ShaderLang.h"
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
#include "libANGLE/PackedGLEnums_autogen.h" #include "libANGLE/PackedGLEnums.h"
#include "libANGLE/RefCountObject.h" #include "libANGLE/RefCountObject.h"
namespace rx namespace rx
...@@ -41,10 +41,7 @@ class Compiler final : public RefCountObjectNoID ...@@ -41,10 +41,7 @@ class Compiler final : public RefCountObjectNoID
ShShaderOutput mOutputType; ShShaderOutput mOutputType;
ShBuiltInResources mResources; ShBuiltInResources mResources;
ShHandle mFragmentCompiler; ShaderMap<ShHandle> mShaderCompilers;
ShHandle mVertexCompiler;
ShHandle mComputeCompiler;
ShHandle mGeometryCompiler;
}; };
} // namespace gl } // namespace gl
......
...@@ -172,8 +172,16 @@ struct AllShaderTypes ...@@ -172,8 +172,16 @@ struct AllShaderTypes
angle::EnumIterator<ShaderType> end() const { return kAfterShaderTypeMax; } 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>; using ShaderBitSet = angle::PackedEnumBitSet<ShaderType>;
template <typename T>
using ShaderMap = angle::PackedEnumMap<ShaderType, T>;
TextureType SamplerTypeToTextureType(GLenum samplerType); TextureType SamplerTypeToTextureType(GLenum samplerType);
} // namespace gl } // namespace gl
......
...@@ -352,6 +352,8 @@ class ProgramState final : angle::NonCopyable ...@@ -352,6 +352,8 @@ class ProgramState final : angle::NonCopyable
const ShaderBitSet &getLinkedShaderStages() const { return mLinkedShaderStages; } const ShaderBitSet &getLinkedShaderStages() const { return mLinkedShaderStages; }
bool hasAttachedShader() const;
private: private:
friend class MemoryProgramCache; friend class MemoryProgramCache;
friend class Program; friend class Program;
...@@ -362,10 +364,7 @@ class ProgramState final : angle::NonCopyable ...@@ -362,10 +364,7 @@ class ProgramState final : angle::NonCopyable
sh::WorkGroupSize mComputeShaderLocalSize; sh::WorkGroupSize mComputeShaderLocalSize;
Shader *mAttachedFragmentShader; ShaderMap<Shader *> mAttachedShaders;
Shader *mAttachedVertexShader;
Shader *mAttachedComputeShader;
Shader *mAttachedGeometryShader;
std::vector<std::string> mTransformFeedbackVaryingNames; std::vector<std::string> mTransformFeedbackVaryingNames;
std::vector<TransformFeedbackVarying> mLinkedTransformFeedbackVaryings; std::vector<TransformFeedbackVarying> mLinkedTransformFeedbackVaryings;
......
...@@ -188,27 +188,29 @@ bool UniformLinker::validateGraphicsUniforms(const Context *context, InfoLog &in ...@@ -188,27 +188,29 @@ bool UniformLinker::validateGraphicsUniforms(const Context *context, InfoLog &in
{ {
// Check that uniforms defined in the graphics shaders are identical // Check that uniforms defined in the graphics shaders are identical
std::map<std::string, ShaderUniform> linkedUniforms; 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 (ShaderType shaderType : kAllGraphicsShaderTypes)
for (size_t shaderIndex = 0; shaderIndex < numActiveShadersToLink; ++shaderIndex)
{ {
bool isLastShader = (shaderIndex == numActiveShadersToLink - 1); Shader *currentShader = mState.getAttachedShader(shaderType);
if (!ValidateGraphicsUniformsPerShader(context, activeShadersToLink[shaderIndex], if (currentShader)
!isLastShader, &linkedUniforms, infoLog))
{ {
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 ...@@ -802,7 +804,7 @@ bool UniformLinker::checkMaxCombinedAtomicCounters(const Caps &caps, InfoLog &in
// InterfaceBlockLinker implementation. // InterfaceBlockLinker implementation.
InterfaceBlockLinker::InterfaceBlockLinker(std::vector<InterfaceBlock> *blocksOut) InterfaceBlockLinker::InterfaceBlockLinker(std::vector<InterfaceBlock> *blocksOut)
: mBlocksOut(blocksOut) : mShaderBlocks({}), mBlocksOut(blocksOut)
{ {
} }
...@@ -810,10 +812,10 @@ InterfaceBlockLinker::~InterfaceBlockLinker() ...@@ -810,10 +812,10 @@ InterfaceBlockLinker::~InterfaceBlockLinker()
{ {
} }
void InterfaceBlockLinker::addShaderBlocks(ShaderType shader, void InterfaceBlockLinker::addShaderBlocks(ShaderType shaderType,
const std::vector<sh::InterfaceBlock> *blocks) const std::vector<sh::InterfaceBlock> *blocks)
{ {
mShaderBlocks.push_back(std::make_pair(shader, blocks)); mShaderBlocks[shaderType] = blocks;
} }
void InterfaceBlockLinker::linkBlocks(const GetBlockSize &getBlockSize, void InterfaceBlockLinker::linkBlocks(const GetBlockSize &getBlockSize,
...@@ -823,11 +825,14 @@ void InterfaceBlockLinker::linkBlocks(const GetBlockSize &getBlockSize, ...@@ -823,11 +825,14 @@ void InterfaceBlockLinker::linkBlocks(const GetBlockSize &getBlockSize,
std::set<std::string> visitedList; 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)) if (!IsActiveInterfaceBlock(block))
continue; continue;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include "angle_gl.h" #include "angle_gl.h"
#include "common/angleutils.h" #include "common/angleutils.h"
#include "libANGLE/PackedGLEnums_autogen.h" #include "libANGLE/PackedGLEnums.h"
#include "libANGLE/VaryingPacking.h" #include "libANGLE/VaryingPacking.h"
#include <functional> #include <functional>
...@@ -234,8 +234,7 @@ class InterfaceBlockLinker : angle::NonCopyable ...@@ -234,8 +234,7 @@ class InterfaceBlockLinker : angle::NonCopyable
ShaderType shaderType, ShaderType shaderType,
bool active) const = 0; bool active) const = 0;
using ShaderBlocks = std::pair<ShaderType, const std::vector<sh::InterfaceBlock> *>; ShaderMap<const std::vector<sh::InterfaceBlock> *> mShaderBlocks;
std::vector<ShaderBlocks> mShaderBlocks;
std::vector<InterfaceBlock> *mBlocksOut; 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