Commit b387ce93 by Tim Van Patten Committed by Commit Bot

Vulkan: Move ProgramInfo/ShaderInfo to ProgramExecutableVk

The classes ProgramInfo and ShaderInfo are being moved into ProgramExecutableVk along with the ProgramVk members mDefaultProgramInfo and mLineRasterProgramInfo. This refactor is necessary since these members are common between ProgramVks and ProgramPipelineVks. Bug: angleproject:3570 Change-Id: I94cdb1096c6a0c007d858135af694da58d7897ff Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2068901 Commit-Queue: Tim Van Patten <timvp@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent f47dccab
......@@ -23,6 +23,105 @@ DefaultUniformBlock::DefaultUniformBlock() = default;
DefaultUniformBlock::~DefaultUniformBlock() = default;
// ShaderInfo implementation.
ShaderInfo::ShaderInfo() {}
ShaderInfo::~ShaderInfo() = default;
angle::Result ShaderInfo::initShaders(ContextVk *contextVk,
const gl::ShaderMap<std::string> &shaderSources,
const ShaderMapInterfaceVariableInfoMap &variableInfoMap)
{
ASSERT(!valid());
ANGLE_TRY(GlslangWrapperVk::GetShaderCode(contextVk, contextVk->getCaps(), shaderSources,
variableInfoMap, &mSpirvBlobs));
mIsInitialized = true;
return angle::Result::Continue;
}
void ShaderInfo::release(ContextVk *contextVk)
{
for (SpirvBlob &spirvBlob : mSpirvBlobs)
{
spirvBlob.clear();
}
mIsInitialized = false;
}
void ShaderInfo::load(gl::BinaryInputStream *stream)
{
// Read in shader codes for all shader types
for (const gl::ShaderType shaderType : gl::AllShaderTypes())
{
SpirvBlob *spirvBlob = &mSpirvBlobs[shaderType];
// Read the SPIR-V
stream->readIntVector<uint32_t>(spirvBlob);
}
mIsInitialized = true;
}
void ShaderInfo::save(gl::BinaryOutputStream *stream)
{
ASSERT(valid());
// Write out shader codes for all shader types
for (const gl::ShaderType shaderType : gl::AllShaderTypes())
{
const SpirvBlob &spirvBlob = mSpirvBlobs[shaderType];
// Write the SPIR-V
stream->writeIntVector(spirvBlob);
}
}
// ProgramInfo implementation.
ProgramInfo::ProgramInfo() {}
ProgramInfo::~ProgramInfo() = default;
angle::Result ProgramInfo::initProgram(ContextVk *contextVk,
const ShaderInfo &shaderInfo,
bool enableLineRasterEmulation)
{
const gl::ShaderMap<SpirvBlob> &spirvBlobs = shaderInfo.getSpirvBlobs();
for (const gl::ShaderType shaderType : gl::AllShaderTypes())
{
const SpirvBlob &spirvBlob = spirvBlobs[shaderType];
if (!spirvBlob.empty())
{
ANGLE_TRY(vk::InitShaderAndSerial(contextVk, &mShaders[shaderType].get(),
spirvBlob.data(),
spirvBlob.size() * sizeof(uint32_t)));
mProgramHelper.setShader(shaderType, &mShaders[shaderType]);
}
}
if (enableLineRasterEmulation)
{
mProgramHelper.enableSpecializationConstant(
sh::vk::SpecializationConstantId::LineRasterEmulation);
}
return angle::Result::Continue;
}
void ProgramInfo::release(ContextVk *contextVk)
{
mProgramHelper.release(contextVk);
for (vk::RefCounted<vk::ShaderAndSerial> &shader : mShaders)
{
shader.get().destroy(contextVk->getDevice());
}
}
ProgramExecutableVk::ProgramExecutableVk()
: mEmptyDescriptorSets{}, mNumDefaultUniformDescriptors(0), mDynamicBufferOffsets{}
{}
......@@ -57,6 +156,9 @@ void ProgramExecutableVk::reset(ContextVk *contextVk)
mTextureDescriptorsCache.clear();
mDescriptorBuffersCache.clear();
mDefaultProgramInfo.release(contextVk);
mLineRasterProgramInfo.release(contextVk);
}
std::unique_ptr<rx::LinkEvent> ProgramExecutableVk::load(gl::BinaryInputStream *stream)
......
......@@ -20,6 +20,50 @@
namespace rx
{
class ShaderInfo final : angle::NonCopyable
{
public:
ShaderInfo();
~ShaderInfo();
angle::Result initShaders(ContextVk *contextVk,
const gl::ShaderMap<std::string> &shaderSources,
const ShaderMapInterfaceVariableInfoMap &variableInfoMap);
void release(ContextVk *contextVk);
ANGLE_INLINE bool valid() const { return mIsInitialized; }
const gl::ShaderMap<SpirvBlob> &getSpirvBlobs() const { return mSpirvBlobs; }
// Save and load implementation for GLES Program Binary support.
void load(gl::BinaryInputStream *stream);
void save(gl::BinaryOutputStream *stream);
private:
gl::ShaderMap<SpirvBlob> mSpirvBlobs;
bool mIsInitialized = false;
};
class ProgramInfo final : angle::NonCopyable
{
public:
ProgramInfo();
~ProgramInfo();
angle::Result initProgram(ContextVk *contextVk,
const ShaderInfo &shaderInfo,
bool enableLineRasterEmulation);
void release(ContextVk *contextVk);
ANGLE_INLINE bool valid() const { return mProgramHelper.valid(); }
vk::ShaderProgramHelper *getShaderProgram() { return &mProgramHelper; }
private:
vk::ShaderProgramHelper mProgramHelper;
gl::ShaderMap<vk::RefCounted<vk::ShaderAndSerial>> mShaders;
};
// State for the default uniform blocks.
struct DefaultUniformBlock final : private angle::NonCopyable
{
......@@ -148,6 +192,9 @@ class ProgramExecutableVk
// TODO: http://anglebug.com/4524: Need a different hash key than a string,
// since that's slow to calculate.
ShaderMapInterfaceVariableInfoMap mVariableInfoMap;
ProgramInfo mDefaultProgramInfo;
ProgramInfo mLineRasterProgramInfo;
};
} // namespace rx
......
......@@ -160,106 +160,6 @@ class Std140BlockLayoutEncoderFactory : public gl::CustomBlockLayoutEncoderFacto
};
} // anonymous namespace
// ProgramVk::ShaderInfo implementation.
ProgramVk::ShaderInfo::ShaderInfo() {}
ProgramVk::ShaderInfo::~ShaderInfo() = default;
angle::Result ProgramVk::ShaderInfo::initShaders(
ContextVk *contextVk,
const gl::ShaderMap<std::string> &shaderSources,
const ShaderMapInterfaceVariableInfoMap &variableInfoMap)
{
ASSERT(!valid());
ANGLE_TRY(GlslangWrapperVk::GetShaderCode(contextVk, contextVk->getCaps(), shaderSources,
variableInfoMap, &mSpirvBlobs));
mIsInitialized = true;
return angle::Result::Continue;
}
void ProgramVk::ShaderInfo::release(ContextVk *contextVk)
{
for (SpirvBlob &spirvBlob : mSpirvBlobs)
{
spirvBlob.clear();
}
mIsInitialized = false;
}
void ProgramVk::ShaderInfo::load(gl::BinaryInputStream *stream)
{
// Read in shader codes for all shader types
for (const gl::ShaderType shaderType : gl::AllShaderTypes())
{
SpirvBlob *spirvBlob = &mSpirvBlobs[shaderType];
// Read the SPIR-V
stream->readIntVector<uint32_t>(spirvBlob);
}
mIsInitialized = true;
}
void ProgramVk::ShaderInfo::save(gl::BinaryOutputStream *stream)
{
ASSERT(valid());
// Write out shader codes for all shader types
for (const gl::ShaderType shaderType : gl::AllShaderTypes())
{
const SpirvBlob &spirvBlob = mSpirvBlobs[shaderType];
// Write the SPIR-V
stream->writeIntVector(spirvBlob);
}
}
// ProgramVk::ProgramInfo implementation.
ProgramVk::ProgramInfo::ProgramInfo() {}
ProgramVk::ProgramInfo::~ProgramInfo() = default;
angle::Result ProgramVk::ProgramInfo::initProgram(ContextVk *contextVk,
const ShaderInfo &shaderInfo,
bool enableLineRasterEmulation)
{
const gl::ShaderMap<SpirvBlob> &spirvBlobs = shaderInfo.getSpirvBlobs();
for (const gl::ShaderType shaderType : gl::AllShaderTypes())
{
const SpirvBlob &spirvBlob = spirvBlobs[shaderType];
if (!spirvBlob.empty())
{
ANGLE_TRY(vk::InitShaderAndSerial(contextVk, &mShaders[shaderType].get(),
spirvBlob.data(),
spirvBlob.size() * sizeof(uint32_t)));
mProgramHelper.setShader(shaderType, &mShaders[shaderType]);
}
}
if (enableLineRasterEmulation)
{
mProgramHelper.enableSpecializationConstant(
sh::vk::SpecializationConstantId::LineRasterEmulation);
}
return angle::Result::Continue;
}
void ProgramVk::ProgramInfo::release(ContextVk *contextVk)
{
mProgramHelper.release(contextVk);
for (vk::RefCounted<vk::ShaderAndSerial> &shader : mShaders)
{
shader.get().destroy(contextVk->getDevice());
}
}
// ProgramVk implementation.
ProgramVk::ProgramVk(const gl::ProgramState &state) : ProgramImpl(state)
{
......@@ -279,8 +179,6 @@ void ProgramVk::reset(ContextVk *contextVk)
RendererVk *renderer = contextVk->getRenderer();
mShaderInfo.release(contextVk);
mDefaultProgramInfo.release(contextVk);
mLineRasterProgramInfo.release(contextVk);
for (auto &uniformBlock : mDefaultUniformBlocks)
{
......
......@@ -175,7 +175,6 @@ class ProgramVk : public ProgramImpl
angle::Result linkImpl(const gl::Context *glContext, gl::InfoLog &infoLog);
void linkResources(const gl::ProgramLinkedResources &resources);
class ProgramInfo;
ANGLE_INLINE angle::Result initProgram(ContextVk *contextVk,
bool enableLineRasterEmulation,
ProgramInfo *programInfo,
......@@ -201,8 +200,8 @@ class ProgramVk : public ProgramImpl
{
bool enableLineRasterEmulation = UseLineRaster(contextVk, mode);
ProgramInfo &programInfo =
enableLineRasterEmulation ? mLineRasterProgramInfo : mDefaultProgramInfo;
ProgramInfo &programInfo = enableLineRasterEmulation ? mExecutable.mLineRasterProgramInfo
: mExecutable.mDefaultProgramInfo;
return initProgram(contextVk, enableLineRasterEmulation, &programInfo, shaderProgramOut);
}
......@@ -210,59 +209,12 @@ class ProgramVk : public ProgramImpl
ANGLE_INLINE angle::Result initComputeProgram(ContextVk *contextVk,
vk::ShaderProgramHelper **shaderProgramOut)
{
return initProgram(contextVk, false, &mDefaultProgramInfo, shaderProgramOut);
return initProgram(contextVk, false, &mExecutable.mDefaultProgramInfo, shaderProgramOut);
}
gl::ShaderMap<DefaultUniformBlock> mDefaultUniformBlocks;
gl::ShaderBitSet mDefaultUniformBlocksDirty;
class ShaderInfo final : angle::NonCopyable
{
public:
ShaderInfo();
~ShaderInfo();
angle::Result initShaders(ContextVk *contextVk,
const gl::ShaderMap<std::string> &shaderSources,
const ShaderMapInterfaceVariableInfoMap &variableInfoMap);
void release(ContextVk *contextVk);
ANGLE_INLINE bool valid() const { return mIsInitialized; }
const gl::ShaderMap<SpirvBlob> &getSpirvBlobs() const { return mSpirvBlobs; }
// Save and load implementation for GLES Program Binary support.
void load(gl::BinaryInputStream *stream);
void save(gl::BinaryOutputStream *stream);
private:
gl::ShaderMap<SpirvBlob> mSpirvBlobs;
bool mIsInitialized = false;
};
class ProgramInfo final : angle::NonCopyable
{
public:
ProgramInfo();
~ProgramInfo();
angle::Result initProgram(ContextVk *contextVk,
const ShaderInfo &shaderInfo,
bool enableLineRasterEmulation);
void release(ContextVk *contextVk);
ANGLE_INLINE bool valid() const { return mProgramHelper.valid(); }
vk::ShaderProgramHelper *getShaderProgram() { return &mProgramHelper; }
private:
vk::ShaderProgramHelper mProgramHelper;
gl::ShaderMap<vk::RefCounted<vk::ShaderAndSerial>> mShaders;
};
ProgramInfo mDefaultProgramInfo;
ProgramInfo mLineRasterProgramInfo;
// We keep the SPIR-V code to use for draw call pipeline creation.
ShaderInfo mShaderInfo;
......
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