Commit 92e7bc89 by Jamie Madill Committed by Commit Bot

Remove ProgramLinkedResources from ProgramExecutable.

Instead of storing the entire LinkedResources struct, we can keep it only for the duration of the linking calls. Refactoring change only. It sets the stage for more refactoring. This change also switches the link call to use LinkingState's ProgramLinkedResources directly to avoid the need to copy the varying packing or use a pointer. Bug: angleproject:4514 Bug: angleproject:5496 Change-Id: Iefea3c16a33213dc338cc54efaa7c3064ea6ae08 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2601403Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarTim Van Patten <timvp@google.com> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent e09e947d
...@@ -849,7 +849,7 @@ void LoadInterfaceBlock(BinaryInputStream *stream, InterfaceBlock *block) ...@@ -849,7 +849,7 @@ void LoadInterfaceBlock(BinaryInputStream *stream, InterfaceBlock *block)
struct Program::LinkingState struct Program::LinkingState
{ {
std::shared_ptr<ProgramExecutable> linkedExecutable; std::shared_ptr<ProgramExecutable> linkedExecutable;
std::unique_ptr<ProgramLinkedResources> resources; ProgramLinkedResources resources;
egl::BlobCache::Key programHash; egl::BlobCache::Key programHash;
std::unique_ptr<rx::LinkEvent> linkEvent; std::unique_ptr<rx::LinkEvent> linkEvent;
bool linkingFromBinary; bool linkingFromBinary;
...@@ -1499,9 +1499,9 @@ void Program::bindFragmentOutputIndex(GLuint index, const char *name) ...@@ -1499,9 +1499,9 @@ void Program::bindFragmentOutputIndex(GLuint index, const char *name)
mFragmentOutputIndexes.bindLocation(index, name); mFragmentOutputIndexes.bindLocation(index, name);
} }
angle::Result Program::linkMergedVaryings(const Context *context, bool Program::linkMergedVaryings(const Context *context,
const ProgramExecutable &executable, const ProgramMergedVaryings &mergedVaryings,
const ProgramMergedVaryings &mergedVaryings) VaryingPacking *varyingPacking)
{ {
ShaderType tfStage = ShaderType tfStage =
mState.mAttachedShaders[ShaderType::Geometry] ? ShaderType::Geometry : ShaderType::Vertex; mState.mAttachedShaders[ShaderType::Geometry] ? ShaderType::Geometry : ShaderType::Vertex;
...@@ -1510,19 +1510,19 @@ angle::Result Program::linkMergedVaryings(const Context *context, ...@@ -1510,19 +1510,19 @@ angle::Result Program::linkMergedVaryings(const Context *context,
if (!linkValidateTransformFeedback(context->getClientVersion(), infoLog, mergedVaryings, if (!linkValidateTransformFeedback(context->getClientVersion(), infoLog, mergedVaryings,
tfStage, context->getCaps())) tfStage, context->getCaps()))
{ {
return angle::Result::Stop; return false;
} }
if (!executable.mResources->varyingPacking.collectAndPackUserVaryings( if (!varyingPacking->collectAndPackUserVaryings(
infoLog, mergedVaryings, mState.getTransformFeedbackVaryingNames(), isSeparable())) infoLog, mergedVaryings, mState.getTransformFeedbackVaryingNames(), isSeparable()))
{ {
return angle::Result::Stop; return false;
} }
gatherTransformFeedbackVaryings(mergedVaryings, tfStage); gatherTransformFeedbackVaryings(mergedVaryings, tfStage);
mState.updateTransformFeedbackStrides(); mState.updateTransformFeedbackStrides();
return angle::Result::Continue; return true;
} }
angle::Result Program::link(const Context *context) angle::Result Program::link(const Context *context)
...@@ -1593,19 +1593,21 @@ angle::Result Program::linkImpl(const Context *context) ...@@ -1593,19 +1593,21 @@ angle::Result Program::linkImpl(const Context *context)
bool result = linkValidateShaders(infoLog); bool result = linkValidateShaders(infoLog);
ASSERT(result); ASSERT(result);
std::unique_ptr<LinkingState> linkingState(new LinkingState());
ProgramMergedVaryings mergedVaryings; ProgramMergedVaryings mergedVaryings;
ProgramLinkedResources &resources = linkingState->resources;
if (mState.mAttachedShaders[ShaderType::Compute]) if (mState.mAttachedShaders[ShaderType::Compute])
{ {
mState.mExecutable->mResources.reset(new ProgramLinkedResources( resources.varyingPacking.init(0, PackMode::ANGLE_RELAXED);
0, PackMode::ANGLE_RELAXED, &mState.mExecutable->mUniformBlocks, resources.init(&mState.mExecutable->mUniformBlocks, &mState.mExecutable->mUniforms,
&mState.mExecutable->mUniforms, &mState.mExecutable->mComputeShaderStorageBlocks, &mState.mExecutable->mComputeShaderStorageBlocks, &mState.mBufferVariables,
&mState.mBufferVariables, &mState.mExecutable->mAtomicCounterBuffers)); &mState.mExecutable->mAtomicCounterBuffers);
GLuint combinedImageUniforms = 0u; GLuint combinedImageUniforms = 0u;
if (!linkUniforms(context->getCaps(), context->getClientVersion(), infoLog, if (!linkUniforms(context->getCaps(), context->getClientVersion(), infoLog,
mState.mUniformLocationBindings, &combinedImageUniforms, mState.mUniformLocationBindings, &combinedImageUniforms,
&mState.mExecutable->getResources().unusedUniforms)) &resources.unusedUniforms))
{ {
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -1634,9 +1636,8 @@ angle::Result Program::linkImpl(const Context *context) ...@@ -1634,9 +1636,8 @@ angle::Result Program::linkImpl(const Context *context)
return angle::Result::Continue; return angle::Result::Continue;
} }
InitUniformBlockLinker(mState, &mState.mExecutable->getResources().uniformBlockLinker); InitUniformBlockLinker(mState, &resources.uniformBlockLinker);
InitShaderStorageBlockLinker(mState, InitShaderStorageBlockLinker(mState, &resources.shaderStorageBlockLinker);
&mState.mExecutable->getResources().shaderStorageBlockLinker);
} }
else else
{ {
...@@ -1653,11 +1654,11 @@ angle::Result Program::linkImpl(const Context *context) ...@@ -1653,11 +1654,11 @@ angle::Result Program::linkImpl(const Context *context)
packMode = PackMode::WEBGL_STRICT; packMode = PackMode::WEBGL_STRICT;
} }
mState.mExecutable->mResources.reset(new ProgramLinkedResources( resources.varyingPacking.init(static_cast<GLuint>(data.getCaps().maxVaryingVectors),
static_cast<GLuint>(data.getCaps().maxVaryingVectors), packMode, packMode);
&mState.mExecutable->mUniformBlocks, &mState.mExecutable->mUniforms, resources.init(&mState.mExecutable->mUniformBlocks, &mState.mExecutable->mUniforms,
&mState.mExecutable->mGraphicsShaderStorageBlocks, &mState.mBufferVariables, &mState.mExecutable->mGraphicsShaderStorageBlocks, &mState.mBufferVariables,
&mState.mExecutable->mAtomicCounterBuffers)); &mState.mExecutable->mAtomicCounterBuffers);
if (!linkAttributes(context, infoLog)) if (!linkAttributes(context, infoLog))
{ {
...@@ -1672,7 +1673,7 @@ angle::Result Program::linkImpl(const Context *context) ...@@ -1672,7 +1673,7 @@ angle::Result Program::linkImpl(const Context *context)
GLuint combinedImageUniforms = 0u; GLuint combinedImageUniforms = 0u;
if (!linkUniforms(context->getCaps(), context->getClientVersion(), infoLog, if (!linkUniforms(context->getCaps(), context->getClientVersion(), infoLog,
mState.mUniformLocationBindings, &combinedImageUniforms, mState.mUniformLocationBindings, &combinedImageUniforms,
&mState.mExecutable->getResources().unusedUniforms)) &resources.unusedUniforms))
{ {
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -1714,9 +1715,8 @@ angle::Result Program::linkImpl(const Context *context) ...@@ -1714,9 +1715,8 @@ angle::Result Program::linkImpl(const Context *context)
mState.mSpecConstUsageBits |= fragmentShader->getSpecConstUsageBits(); mState.mSpecConstUsageBits |= fragmentShader->getSpecConstUsageBits();
} }
InitUniformBlockLinker(mState, &mState.mExecutable->getResources().uniformBlockLinker); InitUniformBlockLinker(mState, &resources.uniformBlockLinker);
InitShaderStorageBlockLinker(mState, InitShaderStorageBlockLinker(mState, &resources.shaderStorageBlockLinker);
&mState.mExecutable->getResources().shaderStorageBlockLinker);
ProgramPipeline *programPipeline = context->getState().getProgramPipeline(); ProgramPipeline *programPipeline = context->getState().getProgramPipeline();
if (programPipeline && programPipeline->usesShaderProgram(id())) if (programPipeline && programPipeline->usesShaderProgram(id()))
...@@ -1727,16 +1727,18 @@ angle::Result Program::linkImpl(const Context *context) ...@@ -1727,16 +1727,18 @@ angle::Result Program::linkImpl(const Context *context)
{ {
mergedVaryings = getMergedVaryings(); mergedVaryings = getMergedVaryings();
} }
ANGLE_TRY(linkMergedVaryings(context, *mState.mExecutable, mergedVaryings)); if (!linkMergedVaryings(context, mergedVaryings, &resources.varyingPacking))
{
return angle::Result::Continue;
}
} }
updateLinkedShaderStages(); updateLinkedShaderStages();
mLinkingState.reset(new LinkingState()); mLinkingState = std::move(linkingState);
mLinkingState->linkingFromBinary = false; mLinkingState->linkingFromBinary = false;
mLinkingState->programHash = programHash; mLinkingState->programHash = programHash;
mLinkingState->linkEvent = mLinkingState->linkEvent = mProgram->link(context, resources, infoLog, mergedVaryings);
mProgram->link(context, mState.mExecutable->getResources(), infoLog, mergedVaryings);
// Must be after mProgram->link() to avoid misleading the linker about output variables. // Must be after mProgram->link() to avoid misleading the linker about output variables.
mState.updateProgramInterfaceInputs(); mState.updateProgramInterfaceInputs();
......
...@@ -500,9 +500,9 @@ class Program final : public LabeledObject, public angle::Subject ...@@ -500,9 +500,9 @@ class Program final : public LabeledObject, public angle::Subject
void bindFragmentOutputLocation(GLuint index, const char *name); void bindFragmentOutputLocation(GLuint index, const char *name);
void bindFragmentOutputIndex(GLuint index, const char *name); void bindFragmentOutputIndex(GLuint index, const char *name);
angle::Result linkMergedVaryings(const Context *context, bool linkMergedVaryings(const Context *context,
const ProgramExecutable &executable, const ProgramMergedVaryings &mergedVaryings,
const ProgramMergedVaryings &mergedVaryings); VaryingPacking *varyingPacking);
// KHR_parallel_shader_compile // KHR_parallel_shader_compile
// Try to link the program asynchrously. As a result, background threads may be launched to // Try to link the program asynchrously. As a result, background threads may be launched to
......
...@@ -297,12 +297,6 @@ class ProgramExecutable final : public angle::Subject ...@@ -297,12 +297,6 @@ class ProgramExecutable final : public angle::Subject
GLuint getUniformIndexFromImageIndex(GLuint imageIndex) const; GLuint getUniformIndexFromImageIndex(GLuint imageIndex) const;
gl::ProgramLinkedResources &getResources() const
{
ASSERT(mResources);
return *mResources;
}
void saveLinkedStateInfo(const ProgramState &state); void saveLinkedStateInfo(const ProgramState &state);
std::vector<sh::ShaderVariable> getLinkedOutputVaryings(ShaderType shaderType) std::vector<sh::ShaderVariable> getLinkedOutputVaryings(ShaderType shaderType)
{ {
...@@ -412,8 +406,6 @@ class ProgramExecutable final : public angle::Subject ...@@ -412,8 +406,6 @@ class ProgramExecutable final : public angle::Subject
ShaderMap<std::vector<sh::ShaderVariable>> mLinkedOutputVaryings; ShaderMap<std::vector<sh::ShaderVariable>> mLinkedOutputVaryings;
ShaderMap<std::vector<sh::ShaderVariable>> mLinkedInputVaryings; ShaderMap<std::vector<sh::ShaderVariable>> mLinkedInputVaryings;
ShaderMap<int> mLinkedShaderVersions; ShaderMap<int> mLinkedShaderVersions;
// TODO: http://anglebug.com/4514: Remove
std::unique_ptr<gl::ProgramLinkedResources> mResources;
}; };
} // namespace gl } // namespace gl
......
...@@ -1051,12 +1051,16 @@ bool UniformLinker::checkMaxCombinedAtomicCounters(const Caps &caps, InfoLog &in ...@@ -1051,12 +1051,16 @@ bool UniformLinker::checkMaxCombinedAtomicCounters(const Caps &caps, InfoLog &in
} }
// InterfaceBlockLinker implementation. // InterfaceBlockLinker implementation.
InterfaceBlockLinker::InterfaceBlockLinker(std::vector<InterfaceBlock> *blocksOut, InterfaceBlockLinker::InterfaceBlockLinker() = default;
std::vector<std::string> *unusedInterfaceBlocksOut)
: mShaderBlocks({}), mBlocksOut(blocksOut), mUnusedInterfaceBlocksOut(unusedInterfaceBlocksOut)
{}
InterfaceBlockLinker::~InterfaceBlockLinker() {} InterfaceBlockLinker::~InterfaceBlockLinker() = default;
void InterfaceBlockLinker::init(std::vector<InterfaceBlock> *blocksOut,
std::vector<std::string> *unusedInterfaceBlocksOut)
{
mBlocksOut = blocksOut;
mUnusedInterfaceBlocksOut = unusedInterfaceBlocksOut;
}
void InterfaceBlockLinker::addShaderBlocks(ShaderType shaderType, void InterfaceBlockLinker::addShaderBlocks(ShaderType shaderType,
const std::vector<sh::InterfaceBlock> *blocks) const std::vector<sh::InterfaceBlock> *blocks)
...@@ -1181,14 +1185,18 @@ void InterfaceBlockLinker::defineInterfaceBlock(const GetBlockSizeFunc &getBlock ...@@ -1181,14 +1185,18 @@ void InterfaceBlockLinker::defineInterfaceBlock(const GetBlockSizeFunc &getBlock
} }
// UniformBlockLinker implementation. // UniformBlockLinker implementation.
UniformBlockLinker::UniformBlockLinker(std::vector<InterfaceBlock> *blocksOut, UniformBlockLinker::UniformBlockLinker() = default;
std::vector<LinkedUniform> *uniformsOut,
std::vector<std::string> *unusedInterfaceBlocksOut)
: InterfaceBlockLinker(blocksOut, unusedInterfaceBlocksOut), mUniformsOut(uniformsOut)
{}
UniformBlockLinker::~UniformBlockLinker() {} UniformBlockLinker::~UniformBlockLinker() {}
void UniformBlockLinker::init(std::vector<InterfaceBlock> *blocksOut,
std::vector<LinkedUniform> *uniformsOut,
std::vector<std::string> *unusedInterfaceBlocksOut)
{
InterfaceBlockLinker::init(blocksOut, unusedInterfaceBlocksOut);
mUniformsOut = uniformsOut;
}
size_t UniformBlockLinker::getCurrentBlockMemberIndex() const size_t UniformBlockLinker::getCurrentBlockMemberIndex() const
{ {
return mUniformsOut->size(); return mUniformsOut->size();
...@@ -1206,15 +1214,17 @@ sh::ShaderVariableVisitor *UniformBlockLinker::getVisitor( ...@@ -1206,15 +1214,17 @@ sh::ShaderVariableVisitor *UniformBlockLinker::getVisitor(
} }
// ShaderStorageBlockLinker implementation. // ShaderStorageBlockLinker implementation.
ShaderStorageBlockLinker::ShaderStorageBlockLinker( ShaderStorageBlockLinker::ShaderStorageBlockLinker() = default;
std::vector<InterfaceBlock> *blocksOut,
std::vector<BufferVariable> *bufferVariablesOut,
std::vector<std::string> *unusedInterfaceBlocksOut)
: InterfaceBlockLinker(blocksOut, unusedInterfaceBlocksOut),
mBufferVariablesOut(bufferVariablesOut)
{}
ShaderStorageBlockLinker::~ShaderStorageBlockLinker() {} ShaderStorageBlockLinker::~ShaderStorageBlockLinker() = default;
void ShaderStorageBlockLinker::init(std::vector<InterfaceBlock> *blocksOut,
std::vector<BufferVariable> *bufferVariablesOut,
std::vector<std::string> *unusedInterfaceBlocksOut)
{
InterfaceBlockLinker::init(blocksOut, unusedInterfaceBlocksOut);
mBufferVariablesOut = bufferVariablesOut;
}
size_t ShaderStorageBlockLinker::getCurrentBlockMemberIndex() const size_t ShaderStorageBlockLinker::getCurrentBlockMemberIndex() const
{ {
...@@ -1233,12 +1243,14 @@ sh::ShaderVariableVisitor *ShaderStorageBlockLinker::getVisitor( ...@@ -1233,12 +1243,14 @@ sh::ShaderVariableVisitor *ShaderStorageBlockLinker::getVisitor(
} }
// AtomicCounterBufferLinker implementation. // AtomicCounterBufferLinker implementation.
AtomicCounterBufferLinker::AtomicCounterBufferLinker( AtomicCounterBufferLinker::AtomicCounterBufferLinker() = default;
std::vector<AtomicCounterBuffer> *atomicCounterBuffersOut)
: mAtomicCounterBuffersOut(atomicCounterBuffersOut) AtomicCounterBufferLinker::~AtomicCounterBufferLinker() = default;
{}
AtomicCounterBufferLinker::~AtomicCounterBufferLinker() {} void AtomicCounterBufferLinker::init(std::vector<AtomicCounterBuffer> *atomicCounterBuffersOut)
{
mAtomicCounterBuffersOut = atomicCounterBuffersOut;
}
void AtomicCounterBufferLinker::link(const std::map<int, unsigned int> &sizeMap) const void AtomicCounterBufferLinker::link(const std::map<int, unsigned int> &sizeMap) const
{ {
...@@ -1250,22 +1262,22 @@ void AtomicCounterBufferLinker::link(const std::map<int, unsigned int> &sizeMap) ...@@ -1250,22 +1262,22 @@ void AtomicCounterBufferLinker::link(const std::map<int, unsigned int> &sizeMap)
} }
} }
ProgramLinkedResources::ProgramLinkedResources( ProgramLinkedResources::ProgramLinkedResources() = default;
GLuint maxVaryingVectors,
PackMode packMode,
std::vector<InterfaceBlock> *uniformBlocksOut,
std::vector<LinkedUniform> *uniformsOut,
std::vector<InterfaceBlock> *shaderStorageBlocksOut,
std::vector<BufferVariable> *bufferVariablesOut,
std::vector<AtomicCounterBuffer> *atomicCounterBuffersOut)
: varyingPacking(maxVaryingVectors, packMode),
uniformBlockLinker(uniformBlocksOut, uniformsOut, &unusedInterfaceBlocks),
shaderStorageBlockLinker(shaderStorageBlocksOut, bufferVariablesOut, &unusedInterfaceBlocks),
atomicCounterBufferLinker(atomicCounterBuffersOut)
{}
ProgramLinkedResources::~ProgramLinkedResources() = default; ProgramLinkedResources::~ProgramLinkedResources() = default;
void ProgramLinkedResources::init(std::vector<InterfaceBlock> *uniformBlocksOut,
std::vector<LinkedUniform> *uniformsOut,
std::vector<InterfaceBlock> *shaderStorageBlocksOut,
std::vector<BufferVariable> *bufferVariablesOut,
std::vector<AtomicCounterBuffer> *atomicCounterBuffersOut)
{
uniformBlockLinker.init(uniformBlocksOut, uniformsOut, &unusedInterfaceBlocks);
shaderStorageBlockLinker.init(shaderStorageBlocksOut, bufferVariablesOut,
&unusedInterfaceBlocks);
atomicCounterBufferLinker.init(atomicCounterBuffersOut);
}
void ProgramLinkedResourcesLinker::linkResources(const ProgramState &programState, void ProgramLinkedResourcesLinker::linkResources(const ProgramState &programState,
const ProgramLinkedResources &resources) const const ProgramLinkedResources &resources) const
{ {
...@@ -1294,7 +1306,7 @@ void ProgramLinkedResourcesLinker::linkResources(const ProgramState &programStat ...@@ -1294,7 +1306,7 @@ void ProgramLinkedResourcesLinker::linkResources(const ProgramState &programStat
// Link uniform interface blocks. // Link uniform interface blocks.
resources.uniformBlockLinker.linkBlocks(getUniformBlockSize, getUniformBlockMemberInfo); resources.uniformBlockLinker.linkBlocks(getUniformBlockSize, getUniformBlockMemberInfo);
// Gather storage bufer interface block info. // Gather storage buffer interface block info.
InterfaceBlockInfo shaderStorageBlockInfo(mCustomEncoderFactory); InterfaceBlockInfo shaderStorageBlockInfo(mCustomEncoderFactory);
for (const ShaderType shaderType : AllShaderTypes()) for (const ShaderType shaderType : AllShaderTypes())
{ {
......
...@@ -112,8 +112,9 @@ class InterfaceBlockLinker : angle::NonCopyable ...@@ -112,8 +112,9 @@ class InterfaceBlockLinker : angle::NonCopyable
const GetBlockMemberInfoFunc &getMemberInfo) const; const GetBlockMemberInfoFunc &getMemberInfo) const;
protected: protected:
InterfaceBlockLinker(std::vector<InterfaceBlock> *blocksOut, InterfaceBlockLinker();
std::vector<std::string> *unusedInterfaceBlocksOut); void init(std::vector<InterfaceBlock> *blocksOut,
std::vector<std::string> *unusedInterfaceBlocksOut);
void defineInterfaceBlock(const GetBlockSizeFunc &getBlockSize, void defineInterfaceBlock(const GetBlockSizeFunc &getBlockSize,
const GetBlockMemberInfoFunc &getMemberInfo, const GetBlockMemberInfoFunc &getMemberInfo,
const sh::InterfaceBlock &interfaceBlock, const sh::InterfaceBlock &interfaceBlock,
...@@ -121,26 +122,28 @@ class InterfaceBlockLinker : angle::NonCopyable ...@@ -121,26 +122,28 @@ class InterfaceBlockLinker : angle::NonCopyable
virtual size_t getCurrentBlockMemberIndex() const = 0; virtual size_t getCurrentBlockMemberIndex() const = 0;
ShaderMap<const std::vector<sh::InterfaceBlock> *> mShaderBlocks;
std::vector<InterfaceBlock> *mBlocksOut;
std::vector<std::string> *mUnusedInterfaceBlocksOut;
virtual sh::ShaderVariableVisitor *getVisitor(const GetBlockMemberInfoFunc &getMemberInfo, virtual sh::ShaderVariableVisitor *getVisitor(const GetBlockMemberInfoFunc &getMemberInfo,
const std::string &namePrefix, const std::string &namePrefix,
const std::string &mappedNamePrefix, const std::string &mappedNamePrefix,
ShaderType shaderType, ShaderType shaderType,
int blockIndex) const = 0; int blockIndex) const = 0;
ShaderMap<const std::vector<sh::InterfaceBlock> *> mShaderBlocks = {};
std::vector<InterfaceBlock> *mBlocksOut = nullptr;
std::vector<std::string> *mUnusedInterfaceBlocksOut = nullptr;
}; };
class UniformBlockLinker final : public InterfaceBlockLinker class UniformBlockLinker final : public InterfaceBlockLinker
{ {
public: public:
UniformBlockLinker(std::vector<InterfaceBlock> *blocksOut, UniformBlockLinker();
std::vector<LinkedUniform> *uniformsOut,
std::vector<std::string> *unusedInterfaceBlocksOut);
~UniformBlockLinker() override; ~UniformBlockLinker() override;
void init(std::vector<InterfaceBlock> *blocksOut,
std::vector<LinkedUniform> *uniformsOut,
std::vector<std::string> *unusedInterfaceBlocksOut);
private: private:
size_t getCurrentBlockMemberIndex() const override; size_t getCurrentBlockMemberIndex() const override;
...@@ -150,17 +153,19 @@ class UniformBlockLinker final : public InterfaceBlockLinker ...@@ -150,17 +153,19 @@ class UniformBlockLinker final : public InterfaceBlockLinker
ShaderType shaderType, ShaderType shaderType,
int blockIndex) const override; int blockIndex) const override;
std::vector<LinkedUniform> *mUniformsOut; std::vector<LinkedUniform> *mUniformsOut = nullptr;
}; };
class ShaderStorageBlockLinker final : public InterfaceBlockLinker class ShaderStorageBlockLinker final : public InterfaceBlockLinker
{ {
public: public:
ShaderStorageBlockLinker(std::vector<InterfaceBlock> *blocksOut, ShaderStorageBlockLinker();
std::vector<BufferVariable> *bufferVariablesOut,
std::vector<std::string> *unusedInterfaceBlocksOut);
~ShaderStorageBlockLinker() override; ~ShaderStorageBlockLinker() override;
void init(std::vector<InterfaceBlock> *blocksOut,
std::vector<BufferVariable> *bufferVariablesOut,
std::vector<std::string> *unusedInterfaceBlocksOut);
private: private:
size_t getCurrentBlockMemberIndex() const override; size_t getCurrentBlockMemberIndex() const override;
...@@ -170,19 +175,20 @@ class ShaderStorageBlockLinker final : public InterfaceBlockLinker ...@@ -170,19 +175,20 @@ class ShaderStorageBlockLinker final : public InterfaceBlockLinker
ShaderType shaderType, ShaderType shaderType,
int blockIndex) const override; int blockIndex) const override;
std::vector<BufferVariable> *mBufferVariablesOut; std::vector<BufferVariable> *mBufferVariablesOut = nullptr;
}; };
class AtomicCounterBufferLinker final : angle::NonCopyable class AtomicCounterBufferLinker final : angle::NonCopyable
{ {
public: public:
AtomicCounterBufferLinker(std::vector<AtomicCounterBuffer> *atomicCounterBuffersOut); AtomicCounterBufferLinker();
~AtomicCounterBufferLinker(); ~AtomicCounterBufferLinker();
void init(std::vector<AtomicCounterBuffer> *atomicCounterBuffersOut);
void link(const std::map<int, unsigned int> &sizeMap) const; void link(const std::map<int, unsigned int> &sizeMap) const;
private: private:
std::vector<AtomicCounterBuffer> *mAtomicCounterBuffersOut; std::vector<AtomicCounterBuffer> *mAtomicCounterBuffersOut = nullptr;
}; };
// The link operation is responsible for finishing the link of uniform and interface blocks. // The link operation is responsible for finishing the link of uniform and interface blocks.
...@@ -206,15 +212,15 @@ struct UnusedUniform ...@@ -206,15 +212,15 @@ struct UnusedUniform
struct ProgramLinkedResources struct ProgramLinkedResources
{ {
ProgramLinkedResources(GLuint maxVaryingVectors, ProgramLinkedResources();
PackMode packMode,
std::vector<InterfaceBlock> *uniformBlocksOut,
std::vector<LinkedUniform> *uniformsOut,
std::vector<InterfaceBlock> *shaderStorageBlocksOut,
std::vector<BufferVariable> *bufferVariablesOut,
std::vector<AtomicCounterBuffer> *atomicCounterBuffersOut);
~ProgramLinkedResources(); ~ProgramLinkedResources();
void init(std::vector<InterfaceBlock> *uniformBlocksOut,
std::vector<LinkedUniform> *uniformsOut,
std::vector<InterfaceBlock> *shaderStorageBlocksOut,
std::vector<BufferVariable> *bufferVariablesOut,
std::vector<AtomicCounterBuffer> *atomicCounterBuffersOut);
VaryingPacking varyingPacking; VaryingPacking varyingPacking;
UniformBlockLinker uniformBlockLinker; UniformBlockLinker uniformBlockLinker;
ShaderStorageBlockLinker shaderStorageBlockLinker; ShaderStorageBlockLinker shaderStorageBlockLinker;
......
...@@ -537,6 +537,7 @@ angle::Result ProgramPipeline::link(const Context *context) ...@@ -537,6 +537,7 @@ angle::Result ProgramPipeline::link(const Context *context)
} }
ProgramMergedVaryings mergedVaryings; ProgramMergedVaryings mergedVaryings;
VaryingPacking varyingPacking;
if (!getExecutable().isCompute()) if (!getExecutable().isCompute())
{ {
...@@ -571,20 +572,25 @@ angle::Result ProgramPipeline::link(const Context *context) ...@@ -571,20 +572,25 @@ angle::Result ProgramPipeline::link(const Context *context)
GLuint maxVaryingVectors = GLuint maxVaryingVectors =
static_cast<GLuint>(context->getState().getCaps().maxVaryingVectors); static_cast<GLuint>(context->getState().getCaps().maxVaryingVectors);
VaryingPacking varyingPacking(maxVaryingVectors, packMode); varyingPacking.init(maxVaryingVectors, packMode);
mergedVaryings = getMergedVaryings(); mergedVaryings = getMergedVaryings();
for (ShaderType shaderType : getExecutable().getLinkedShaderStages()) for (ShaderType shaderType : getExecutable().getLinkedShaderStages())
{ {
Program *program = mState.mPrograms[shaderType]; Program *program = mState.mPrograms[shaderType];
ASSERT(program); ASSERT(program);
program->getExecutable().getResources().varyingPacking.reset(); if (!program->linkMergedVaryings(context, mergedVaryings, &varyingPacking))
ANGLE_TRY( {
program->linkMergedVaryings(context, program->getExecutable(), mergedVaryings)); return angle::Result::Stop;
}
} }
} }
else
{
varyingPacking.init(0, gl::PackMode::ANGLE_RELAXED);
}
ANGLE_TRY(getImplementation()->link(context, mergedVaryings)); ANGLE_TRY(getImplementation()->link(context, mergedVaryings, varyingPacking));
mState.mIsLinked = true; mState.mIsLinked = true;
......
...@@ -167,12 +167,16 @@ PackedVarying &PackedVarying::operator=(PackedVarying &&other) ...@@ -167,12 +167,16 @@ PackedVarying &PackedVarying::operator=(PackedVarying &&other)
} }
// Implementation of VaryingPacking // Implementation of VaryingPacking
VaryingPacking::VaryingPacking(GLuint maxVaryingVectors, PackMode packMode) VaryingPacking::VaryingPacking() = default;
: mRegisterMap(maxVaryingVectors), mPackMode(packMode)
{}
VaryingPacking::~VaryingPacking() = default; VaryingPacking::~VaryingPacking() = default;
void VaryingPacking::init(GLuint maxVaryingVectors, PackMode packMode)
{
mRegisterMap.resize(maxVaryingVectors);
mPackMode = packMode;
}
void VaryingPacking::reset() void VaryingPacking::reset()
{ {
clearRegisterMap(); clearRegisterMap();
......
...@@ -202,9 +202,11 @@ enum class PackMode ...@@ -202,9 +202,11 @@ enum class PackMode
class VaryingPacking final : angle::NonCopyable class VaryingPacking final : angle::NonCopyable
{ {
public: public:
VaryingPacking(GLuint maxVaryingVectors, PackMode packMode); VaryingPacking();
~VaryingPacking(); ~VaryingPacking();
void init(GLuint maxVaryingVectors, PackMode packMode);
bool packUserVaryings(gl::InfoLog &infoLog, const std::vector<PackedVarying> &packedVaryings); bool packUserVaryings(gl::InfoLog &infoLog, const std::vector<PackedVarying> &packedVaryings);
bool collectAndPackUserVaryings(gl::InfoLog &infoLog, bool collectAndPackUserVaryings(gl::InfoLog &infoLog,
...@@ -274,7 +276,7 @@ class VaryingPacking final : angle::NonCopyable ...@@ -274,7 +276,7 @@ class VaryingPacking final : angle::NonCopyable
ShaderMap<std::vector<std::string>> mInactiveVaryingMappedNames; ShaderMap<std::vector<std::string>> mInactiveVaryingMappedNames;
ShaderMap<std::vector<std::string>> mActiveOutputBuiltIns; ShaderMap<std::vector<std::string>> mActiveOutputBuiltIns;
PackMode mPackMode; PackMode mPackMode = PackMode::ANGLE_RELAXED;
}; };
} // namespace gl } // namespace gl
......
...@@ -46,14 +46,16 @@ class VaryingPackingTest : public ::testing::TestWithParam<GLuint> ...@@ -46,14 +46,16 @@ class VaryingPackingTest : public ::testing::TestWithParam<GLuint>
// Uses the "relaxed" ANGLE packing mode. // Uses the "relaxed" ANGLE packing mode.
bool packVaryings(GLuint maxVaryings, const std::vector<sh::ShaderVariable> &shVaryings) bool packVaryings(GLuint maxVaryings, const std::vector<sh::ShaderVariable> &shVaryings)
{ {
VaryingPacking varyingPacking(maxVaryings, PackMode::ANGLE_RELAXED); VaryingPacking varyingPacking;
varyingPacking.init(maxVaryings, PackMode::ANGLE_RELAXED);
return testVaryingPacking(shVaryings, &varyingPacking); return testVaryingPacking(shVaryings, &varyingPacking);
} }
// Uses the stricter WebGL style packing rules. // Uses the stricter WebGL style packing rules.
bool packVaryingsStrict(GLuint maxVaryings, const std::vector<sh::ShaderVariable> &shVaryings) bool packVaryingsStrict(GLuint maxVaryings, const std::vector<sh::ShaderVariable> &shVaryings)
{ {
VaryingPacking varyingPacking(maxVaryings, PackMode::WEBGL_STRICT); VaryingPacking varyingPacking;
varyingPacking.init(maxVaryings, PackMode::WEBGL_STRICT);
return testVaryingPacking(shVaryings, &varyingPacking); return testVaryingPacking(shVaryings, &varyingPacking);
} }
......
...@@ -12,7 +12,8 @@ namespace rx ...@@ -12,7 +12,8 @@ namespace rx
{ {
angle::Result ProgramPipelineImpl::link(const gl::Context *context, angle::Result ProgramPipelineImpl::link(const gl::Context *context,
const gl::ProgramMergedVaryings &mergedVaryings) const gl::ProgramMergedVaryings &mergedVaryings,
const gl::VaryingPacking &varyingPacking)
{ {
return angle::Result::Continue; return angle::Result::Continue;
} }
......
...@@ -24,7 +24,8 @@ class ProgramPipelineImpl : public angle::NonCopyable ...@@ -24,7 +24,8 @@ class ProgramPipelineImpl : public angle::NonCopyable
virtual void destroy(const gl::Context *context) {} virtual void destroy(const gl::Context *context) {}
virtual angle::Result link(const gl::Context *context, virtual angle::Result link(const gl::Context *context,
const gl::ProgramMergedVaryings &mergedVaryings); const gl::ProgramMergedVaryings &mergedVaryings,
const gl::VaryingPacking &varyingPacking);
const gl::ProgramPipelineState &getState() const { return mState; } const gl::ProgramPipelineState &getState() const { return mState; }
......
...@@ -576,7 +576,7 @@ void AssignOutputLocations(const gl::ProgramExecutable &programExecutable, ...@@ -576,7 +576,7 @@ void AssignOutputLocations(const gl::ProgramExecutable &programExecutable,
} }
void AssignVaryingLocations(const GlslangSourceOptions &options, void AssignVaryingLocations(const GlslangSourceOptions &options,
const gl::ProgramExecutable &programExecutable, const gl::VaryingPacking &varyingPacking,
const gl::ShaderType shaderType, const gl::ShaderType shaderType,
const gl::ShaderType frontShaderType, const gl::ShaderType frontShaderType,
GlslangProgramInterfaceInfo *programInterfaceInfo, GlslangProgramInterfaceInfo *programInterfaceInfo,
...@@ -596,8 +596,7 @@ void AssignVaryingLocations(const GlslangSourceOptions &options, ...@@ -596,8 +596,7 @@ void AssignVaryingLocations(const GlslangSourceOptions &options,
} }
// Assign varying locations. // Assign varying locations.
for (const gl::PackedVaryingRegister &varyingReg : for (const gl::PackedVaryingRegister &varyingReg : varyingPacking.getRegisterList())
programExecutable.getResources().varyingPacking.getRegisterList())
{ {
if (!IsFirstRegisterOfVarying(varyingReg, false)) if (!IsFirstRegisterOfVarying(varyingReg, false))
{ {
...@@ -637,7 +636,7 @@ void AssignVaryingLocations(const GlslangSourceOptions &options, ...@@ -637,7 +636,7 @@ void AssignVaryingLocations(const GlslangSourceOptions &options,
// Add an entry for inactive varyings. // Add an entry for inactive varyings.
const gl::ShaderMap<std::vector<std::string>> &inactiveVaryingMappedNames = const gl::ShaderMap<std::vector<std::string>> &inactiveVaryingMappedNames =
programExecutable.getResources().varyingPacking.getInactiveVaryingMappedNames(); varyingPacking.getInactiveVaryingMappedNames();
for (const std::string &varyingName : inactiveVaryingMappedNames[shaderType]) for (const std::string &varyingName : inactiveVaryingMappedNames[shaderType])
{ {
ASSERT(!gl::IsBuiltInName(varyingName)); ASSERT(!gl::IsBuiltInName(varyingName));
...@@ -657,7 +656,7 @@ void AssignVaryingLocations(const GlslangSourceOptions &options, ...@@ -657,7 +656,7 @@ void AssignVaryingLocations(const GlslangSourceOptions &options,
// Add an entry for active builtins varyings. This will allow inactive builtins, such as // Add an entry for active builtins varyings. This will allow inactive builtins, such as
// gl_PointSize, gl_ClipDistance etc to be removed. // gl_PointSize, gl_ClipDistance etc to be removed.
const gl::ShaderMap<std::vector<std::string>> &activeOutputBuiltIns = const gl::ShaderMap<std::vector<std::string>> &activeOutputBuiltIns =
programExecutable.getResources().varyingPacking.getActiveOutputBuiltIns(); varyingPacking.getActiveOutputBuiltIns();
for (const std::string &builtInName : activeOutputBuiltIns[shaderType]) for (const std::string &builtInName : activeOutputBuiltIns[shaderType])
{ {
ASSERT(gl::IsBuiltInName(builtInName)); ASSERT(gl::IsBuiltInName(builtInName));
...@@ -690,6 +689,7 @@ void AssignVaryingLocations(const GlslangSourceOptions &options, ...@@ -690,6 +689,7 @@ void AssignVaryingLocations(const GlslangSourceOptions &options,
// Calculates XFB layout qualifier arguments for each tranform feedback varying. Stores calculated // Calculates XFB layout qualifier arguments for each tranform feedback varying. Stores calculated
// values for the SPIR-V transformation. // values for the SPIR-V transformation.
void AssignTransformFeedbackExtensionQualifiers(const gl::ProgramExecutable &programExecutable, void AssignTransformFeedbackExtensionQualifiers(const gl::ProgramExecutable &programExecutable,
const gl::VaryingPacking &varyingPacking,
uint32_t locationsUsedForXfbExtension, uint32_t locationsUsedForXfbExtension,
const gl::ShaderType shaderType, const gl::ShaderType shaderType,
ShaderInterfaceVariableInfoMap *variableInfoMapOut) ShaderInterfaceVariableInfoMap *variableInfoMapOut)
...@@ -788,8 +788,7 @@ void AssignTransformFeedbackExtensionQualifiers(const gl::ProgramExecutable &pro ...@@ -788,8 +788,7 @@ void AssignTransformFeedbackExtensionQualifiers(const gl::ProgramExecutable &pro
// other hand, we need to decorate the exact member that is captured (as whole-block // other hand, we need to decorate the exact member that is captured (as whole-block
// capture is not supported). // capture is not supported).
const gl::PackedVarying *originalVarying = nullptr; const gl::PackedVarying *originalVarying = nullptr;
for (const gl::PackedVaryingRegister &varyingReg : for (const gl::PackedVaryingRegister &varyingReg : varyingPacking.getRegisterList())
programExecutable.getResources().varyingPacking.getRegisterList())
{ {
if (!IsFirstRegisterOfVarying(varyingReg, tfVarying.isShaderIOBlock)) if (!IsFirstRegisterOfVarying(varyingReg, tfVarying.isShaderIOBlock))
{ {
...@@ -3806,6 +3805,7 @@ void GlslangGenTransformFeedbackEmulationOutputs(const GlslangSourceOptions &opt ...@@ -3806,6 +3805,7 @@ void GlslangGenTransformFeedbackEmulationOutputs(const GlslangSourceOptions &opt
void GlslangAssignLocations(const GlslangSourceOptions &options, void GlslangAssignLocations(const GlslangSourceOptions &options,
const gl::ProgramExecutable &programExecutable, const gl::ProgramExecutable &programExecutable,
const gl::VaryingPacking &varyingPacking,
const gl::ShaderType shaderType, const gl::ShaderType shaderType,
const gl::ShaderType frontShaderType, const gl::ShaderType frontShaderType,
GlslangProgramInterfaceInfo *programInterfaceInfo, GlslangProgramInterfaceInfo *programInterfaceInfo,
...@@ -3828,7 +3828,7 @@ void GlslangAssignLocations(const GlslangSourceOptions &options, ...@@ -3828,7 +3828,7 @@ void GlslangAssignLocations(const GlslangSourceOptions &options,
if (!programExecutable.hasLinkedShaderStage(gl::ShaderType::Compute)) if (!programExecutable.hasLinkedShaderStage(gl::ShaderType::Compute))
{ {
// Assign varying locations. // Assign varying locations.
AssignVaryingLocations(options, programExecutable, shaderType, frontShaderType, AssignVaryingLocations(options, varyingPacking, shaderType, frontShaderType,
programInterfaceInfo, variableInfoMapOut); programInterfaceInfo, variableInfoMapOut);
if (!programExecutable.getLinkedTransformFeedbackVaryings().empty() && if (!programExecutable.getLinkedTransformFeedbackVaryings().empty() &&
...@@ -3836,8 +3836,8 @@ void GlslangAssignLocations(const GlslangSourceOptions &options, ...@@ -3836,8 +3836,8 @@ void GlslangAssignLocations(const GlslangSourceOptions &options,
(shaderType == programExecutable.getLinkedTransformFeedbackStage())) (shaderType == programExecutable.getLinkedTransformFeedbackStage()))
{ {
AssignTransformFeedbackExtensionQualifiers( AssignTransformFeedbackExtensionQualifiers(
programExecutable, programInterfaceInfo->locationsUsedForXfbExtension, shaderType, programExecutable, varyingPacking,
variableInfoMapOut); programInterfaceInfo->locationsUsedForXfbExtension, shaderType, variableInfoMapOut);
} }
} }
...@@ -3910,8 +3910,9 @@ void GlslangGetShaderSource(const GlslangSourceOptions &options, ...@@ -3910,8 +3910,9 @@ void GlslangGetShaderSource(const GlslangSourceOptions &options,
for (const gl::ShaderType shaderType : programState.getExecutable().getLinkedShaderStages()) for (const gl::ShaderType shaderType : programState.getExecutable().getLinkedShaderStages())
{ {
GlslangAssignLocations(options, programState.getExecutable(), shaderType, frontShaderType, GlslangAssignLocations(options, programState.getExecutable(), resources.varyingPacking,
programInterfaceInfo, variableInfoMapOut); shaderType, frontShaderType, programInterfaceInfo,
variableInfoMapOut);
frontShaderType = shaderType; frontShaderType = shaderType;
} }
......
...@@ -173,6 +173,7 @@ void GlslangGenTransformFeedbackEmulationOutputs( ...@@ -173,6 +173,7 @@ void GlslangGenTransformFeedbackEmulationOutputs(
void GlslangAssignLocations(const GlslangSourceOptions &options, void GlslangAssignLocations(const GlslangSourceOptions &options,
const gl::ProgramExecutable &programExecutable, const gl::ProgramExecutable &programExecutable,
const gl::VaryingPacking &varyingPacking,
const gl::ShaderType shaderType, const gl::ShaderType shaderType,
const gl::ShaderType frontShaderType, const gl::ShaderType frontShaderType,
GlslangProgramInterfaceInfo *programInterfaceInfo, GlslangProgramInterfaceInfo *programInterfaceInfo,
......
...@@ -432,9 +432,9 @@ void GlslangGetShaderSource(const gl::ProgramState &programState, ...@@ -432,9 +432,9 @@ void GlslangGetShaderSource(const gl::ProgramState &programState,
options, programState, &xfbOnlyInterfaceInfo, xfbOnlyShaderSourceOut, options, programState, &xfbOnlyInterfaceInfo, xfbOnlyShaderSourceOut,
xfbOnlyVSVariableInfoMapOut); xfbOnlyVSVariableInfoMapOut);
GlslangAssignLocations(options, programState.getExecutable(), gl::ShaderType::Vertex, GlslangAssignLocations(options, programState.getExecutable(), resources.varyingPacking,
gl::ShaderType::InvalidEnum, &xfbOnlyInterfaceInfo, gl::ShaderType::Vertex, gl::ShaderType::InvalidEnum,
xfbOnlyVSVariableInfoMapOut); &xfbOnlyInterfaceInfo, xfbOnlyVSVariableInfoMapOut);
} }
} }
......
...@@ -53,7 +53,8 @@ void ProgramPipelineVk::fillProgramStateMap( ...@@ -53,7 +53,8 @@ void ProgramPipelineVk::fillProgramStateMap(
} }
angle::Result ProgramPipelineVk::link(const gl::Context *glContext, angle::Result ProgramPipelineVk::link(const gl::Context *glContext,
const gl::ProgramMergedVaryings &mergedVaryings) const gl::ProgramMergedVaryings &mergedVaryings,
const gl::VaryingPacking &varyingPacking)
{ {
ContextVk *contextVk = vk::GetImpl(glContext); ContextVk *contextVk = vk::GetImpl(glContext);
const gl::State &glState = glContext->getState(); const gl::State &glState = glContext->getState();
...@@ -82,8 +83,8 @@ angle::Result ProgramPipelineVk::link(const gl::Context *glContext, ...@@ -82,8 +83,8 @@ angle::Result ProgramPipelineVk::link(const gl::Context *glContext,
glslangProgramInterfaceInfo.locationsUsedForXfbExtension = glslangProgramInterfaceInfo.locationsUsedForXfbExtension =
programProgramInterfaceInfo.locationsUsedForXfbExtension; programProgramInterfaceInfo.locationsUsedForXfbExtension;
GlslangAssignLocations(options, glProgram->getState().getExecutable(), shaderType, GlslangAssignLocations(options, glProgram->getState().getExecutable(), varyingPacking,
frontShaderType, &glslangProgramInterfaceInfo, shaderType, frontShaderType, &glslangProgramInterfaceInfo,
&mExecutable.mVariableInfoMap); &mExecutable.mVariableInfoMap);
frontShaderType = shaderType; frontShaderType = shaderType;
} }
......
...@@ -46,7 +46,8 @@ class ProgramPipelineVk : public ProgramPipelineImpl ...@@ -46,7 +46,8 @@ class ProgramPipelineVk : public ProgramPipelineImpl
gl::ShaderMap<const gl::ProgramState *> *programStatesOut); gl::ShaderMap<const gl::ProgramState *> *programStatesOut);
angle::Result link(const gl::Context *glContext, angle::Result link(const gl::Context *glContext,
const gl::ProgramMergedVaryings &mergedVaryings) override; const gl::ProgramMergedVaryings &mergedVaryings,
const gl::VaryingPacking &varyingPacking) override;
angle::Result updateUniforms(ContextVk *contextVk); angle::Result updateUniforms(ContextVk *contextVk);
......
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