mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-18 19:28:36 +00:00
AbstractPipeline: Support returning "cache data"
"Cache data" can be used to assist a driver with creating pipelines by using previously-compiled shader ISA.
This commit is contained in:
parent
2863183532
commit
61a656570e
@ -127,7 +127,9 @@ std::unique_ptr<AbstractShader> Renderer::CreateShaderFromBinary(ShaderStage sta
|
||||
return DXShader::CreateFromBytecode(stage, DXShader::CreateByteCode(data, length));
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractPipeline> Renderer::CreatePipeline(const AbstractPipelineConfig& config)
|
||||
std::unique_ptr<AbstractPipeline> Renderer::CreatePipeline(const AbstractPipelineConfig& config,
|
||||
const void* cache_data,
|
||||
size_t cache_data_length)
|
||||
{
|
||||
return DXPipeline::Create(config);
|
||||
}
|
||||
|
@ -34,7 +34,9 @@ public:
|
||||
size_t length) override;
|
||||
std::unique_ptr<NativeVertexFormat>
|
||||
CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) override;
|
||||
std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config) override;
|
||||
std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config,
|
||||
const void* cache_data = nullptr,
|
||||
size_t cache_data_length = 0) override;
|
||||
std::unique_ptr<AbstractFramebuffer>
|
||||
CreateFramebuffer(AbstractTexture* color_attachment, AbstractTexture* depth_attachment) override;
|
||||
|
||||
|
@ -82,6 +82,8 @@ void VideoBackend::FillBackendInfo()
|
||||
g_Config.backend_info.bSupportsFragmentStoresAndAtomics = true;
|
||||
g_Config.backend_info.bSupportsGSInstancing = true;
|
||||
g_Config.backend_info.bSupportsSSAA = true;
|
||||
g_Config.backend_info.bSupportsShaderBinaries = true;
|
||||
g_Config.backend_info.bSupportsPipelineCacheData = false;
|
||||
|
||||
g_Config.backend_info.Adapters = D3DCommon::GetAdapterNames();
|
||||
g_Config.backend_info.AAModes = D3D::GetAAModes(g_Config.iAdapter);
|
||||
|
@ -99,7 +99,9 @@ Renderer::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl)
|
||||
return std::make_unique<DXVertexFormat>(vtx_decl);
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractPipeline> Renderer::CreatePipeline(const AbstractPipelineConfig& config)
|
||||
std::unique_ptr<AbstractPipeline> Renderer::CreatePipeline(const AbstractPipelineConfig& config,
|
||||
const void* cache_data,
|
||||
size_t cache_data_length)
|
||||
{
|
||||
return DXPipeline::Create(config);
|
||||
}
|
||||
|
@ -41,7 +41,9 @@ public:
|
||||
size_t length) override;
|
||||
std::unique_ptr<NativeVertexFormat>
|
||||
CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) override;
|
||||
std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config) override;
|
||||
std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config,
|
||||
const void* cache_data = nullptr,
|
||||
size_t cache_data_length = 0) override;
|
||||
|
||||
u16 BBoxRead(int index) override;
|
||||
void BBoxWrite(int index, u16 value) override;
|
||||
|
@ -80,6 +80,8 @@ void VideoBackend::FillBackendInfo()
|
||||
g_Config.backend_info.bSupportsPartialDepthCopies = false;
|
||||
g_Config.backend_info.Adapters = D3DCommon::GetAdapterNames();
|
||||
g_Config.backend_info.AAModes = DXContext::GetAAModes(g_Config.iAdapter);
|
||||
g_Config.backend_info.bSupportsShaderBinaries = true;
|
||||
g_Config.backend_info.bSupportsPipelineCacheData = true;
|
||||
|
||||
// We can only check texture support once we have a device.
|
||||
if (g_dx_context)
|
||||
|
@ -23,11 +23,6 @@ Shader::Shader(ShaderStage stage, BinaryData bytecode)
|
||||
|
||||
Shader::~Shader() = default;
|
||||
|
||||
bool Shader::HasBinary() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
AbstractShader::BinaryData Shader::GetBinary() const
|
||||
{
|
||||
return m_bytecode;
|
||||
|
@ -16,7 +16,6 @@ public:
|
||||
|
||||
const BinaryData& GetByteCode() const { return m_bytecode; }
|
||||
|
||||
bool HasBinary() const override;
|
||||
BinaryData GetBinary() const override;
|
||||
|
||||
static bool CompileShader(D3D_FEATURE_LEVEL feature_level, BinaryData* out_bytecode,
|
||||
|
@ -52,6 +52,8 @@ void VideoBackend::InitBackendInfo()
|
||||
g_Config.backend_info.bSupportsLogicOp = false;
|
||||
g_Config.backend_info.bSupportsLargePoints = false;
|
||||
g_Config.backend_info.bSupportsPartialDepthCopies = false;
|
||||
g_Config.backend_info.bSupportsShaderBinaries = false;
|
||||
g_Config.backend_info.bSupportsPipelineCacheData = false;
|
||||
|
||||
// aamodes: We only support 1 sample, so no MSAA
|
||||
g_Config.backend_info.Adapters.clear();
|
||||
|
@ -46,9 +46,6 @@ class NullShader final : public AbstractShader
|
||||
public:
|
||||
explicit NullShader(ShaderStage stage) : AbstractShader(stage) {}
|
||||
~NullShader() = default;
|
||||
|
||||
bool HasBinary() const override { return false; }
|
||||
BinaryData GetBinary() const override { return {}; }
|
||||
};
|
||||
|
||||
std::unique_ptr<AbstractShader> Renderer::CreateShaderFromSource(ShaderStage stage,
|
||||
@ -70,7 +67,9 @@ public:
|
||||
~NullPipeline() override = default;
|
||||
};
|
||||
|
||||
std::unique_ptr<AbstractPipeline> Renderer::CreatePipeline(const AbstractPipelineConfig& config)
|
||||
std::unique_ptr<AbstractPipeline> Renderer::CreatePipeline(const AbstractPipelineConfig& config,
|
||||
const void* cache_data,
|
||||
size_t cache_data_length)
|
||||
{
|
||||
return std::make_unique<NullPipeline>();
|
||||
}
|
||||
|
@ -28,7 +28,9 @@ public:
|
||||
size_t length) override;
|
||||
std::unique_ptr<NativeVertexFormat>
|
||||
CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) override;
|
||||
std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config) override;
|
||||
std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config,
|
||||
const void* cache_data = nullptr,
|
||||
size_t cache_data_length = 0) override;
|
||||
|
||||
u32 AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) override { return 0; }
|
||||
void PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num_points) override {}
|
||||
|
@ -44,17 +44,6 @@ OGLShader::~OGLShader()
|
||||
glDeleteProgram(m_gl_compute_program_id);
|
||||
}
|
||||
|
||||
bool OGLShader::HasBinary() const
|
||||
{
|
||||
// NOTE: GL shaders do not have binaries, programs do.
|
||||
return false;
|
||||
}
|
||||
|
||||
AbstractShader::BinaryData OGLShader::GetBinary() const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
std::unique_ptr<OGLShader> OGLShader::CreateFromSource(ShaderStage stage, const char* source,
|
||||
size_t length)
|
||||
{
|
||||
|
@ -24,8 +24,6 @@ public:
|
||||
GLenum GetGLShaderType() const { return m_type; }
|
||||
GLuint GetGLShaderID() const { return m_gl_id; }
|
||||
GLuint GetGLComputeProgramID() const { return m_gl_compute_program_id; }
|
||||
bool HasBinary() const override;
|
||||
BinaryData GetBinary() const override;
|
||||
|
||||
static std::unique_ptr<OGLShader> CreateFromSource(ShaderStage stage, const char* source,
|
||||
size_t length);
|
||||
|
@ -828,7 +828,9 @@ std::unique_ptr<AbstractShader> Renderer::CreateShaderFromBinary(ShaderStage sta
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractPipeline> Renderer::CreatePipeline(const AbstractPipelineConfig& config)
|
||||
std::unique_ptr<AbstractPipeline> Renderer::CreatePipeline(const AbstractPipelineConfig& config,
|
||||
const void* cache_data,
|
||||
size_t cache_data_length)
|
||||
{
|
||||
return OGLPipeline::Create(config);
|
||||
}
|
||||
|
@ -102,7 +102,9 @@ public:
|
||||
size_t length) override;
|
||||
std::unique_ptr<NativeVertexFormat>
|
||||
CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) override;
|
||||
std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config) override;
|
||||
std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config,
|
||||
const void* cache_data = nullptr,
|
||||
size_t cache_data_length = 0) override;
|
||||
std::unique_ptr<AbstractFramebuffer>
|
||||
CreateFramebuffer(AbstractTexture* color_attachment, AbstractTexture* depth_attachment) override;
|
||||
|
||||
|
@ -90,6 +90,8 @@ void VideoBackend::InitBackendInfo()
|
||||
g_Config.backend_info.bSupportsCopyToVram = true;
|
||||
g_Config.backend_info.bSupportsLargePoints = true;
|
||||
g_Config.backend_info.bSupportsPartialDepthCopies = true;
|
||||
g_Config.backend_info.bSupportsShaderBinaries = false;
|
||||
g_Config.backend_info.bSupportsPipelineCacheData = false;
|
||||
|
||||
// TODO: There is a bug here, if texel buffers or SSBOs/atomics are not supported the graphics
|
||||
// options will show the option when it is not supported. The only way around this would be
|
||||
|
@ -64,7 +64,6 @@ public:
|
||||
explicit SWShader(ShaderStage stage) : AbstractShader(stage) {}
|
||||
~SWShader() = default;
|
||||
|
||||
bool HasBinary() const override { return false; }
|
||||
BinaryData GetBinary() const override { return {}; }
|
||||
};
|
||||
|
||||
@ -87,7 +86,9 @@ public:
|
||||
~SWPipeline() override = default;
|
||||
};
|
||||
|
||||
std::unique_ptr<AbstractPipeline> SWRenderer::CreatePipeline(const AbstractPipelineConfig& config)
|
||||
std::unique_ptr<AbstractPipeline> SWRenderer::CreatePipeline(const AbstractPipelineConfig& config,
|
||||
const void* cache_data,
|
||||
size_t cache_data_length)
|
||||
{
|
||||
return std::make_unique<SWPipeline>();
|
||||
}
|
||||
|
@ -33,7 +33,9 @@ public:
|
||||
size_t length) override;
|
||||
std::unique_ptr<NativeVertexFormat>
|
||||
CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) override;
|
||||
std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config) override;
|
||||
std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config,
|
||||
const void* cache_data = nullptr,
|
||||
size_t cache_data_length = 0) override;
|
||||
|
||||
u32 AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) override;
|
||||
void PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num_points) override {}
|
||||
|
@ -74,6 +74,8 @@ void VideoSoftware::InitBackendInfo()
|
||||
g_Config.backend_info.bSupportsFramebufferFetch = false;
|
||||
g_Config.backend_info.bSupportsBackgroundCompiling = false;
|
||||
g_Config.backend_info.bSupportsLogicOp = true;
|
||||
g_Config.backend_info.bSupportsShaderBinaries = false;
|
||||
g_Config.backend_info.bSupportsPipelineCacheData = false;
|
||||
|
||||
// aamodes
|
||||
g_Config.backend_info.AAModes = {1};
|
||||
|
@ -112,7 +112,9 @@ Renderer::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl)
|
||||
return std::make_unique<VertexFormat>(vtx_decl);
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractPipeline> Renderer::CreatePipeline(const AbstractPipelineConfig& config)
|
||||
std::unique_ptr<AbstractPipeline> Renderer::CreatePipeline(const AbstractPipelineConfig& config,
|
||||
const void* cache_data,
|
||||
size_t cache_data_length)
|
||||
{
|
||||
return VKPipeline::Create(config);
|
||||
}
|
||||
|
@ -48,7 +48,9 @@ public:
|
||||
size_t length) override;
|
||||
std::unique_ptr<NativeVertexFormat>
|
||||
CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) override;
|
||||
std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config) override;
|
||||
std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config,
|
||||
const void* cache_data = nullptr,
|
||||
size_t cache_data_length = 0) override;
|
||||
|
||||
SwapChain* GetSwapChain() const { return m_swap_chain.get(); }
|
||||
BoundingBox* GetBoundingBox() const { return m_bounding_box.get(); }
|
||||
|
@ -32,12 +32,6 @@ VKShader::~VKShader()
|
||||
vkDestroyPipeline(g_vulkan_context->GetDevice(), m_compute_pipeline, nullptr);
|
||||
}
|
||||
|
||||
bool VKShader::HasBinary() const
|
||||
{
|
||||
ASSERT(!m_spv.empty());
|
||||
return true;
|
||||
}
|
||||
|
||||
AbstractShader::BinaryData VKShader::GetBinary() const
|
||||
{
|
||||
BinaryData ret(sizeof(u32) * m_spv.size());
|
||||
|
@ -23,7 +23,6 @@ public:
|
||||
|
||||
VkShaderModule GetShaderModule() const { return m_module; }
|
||||
VkPipeline GetComputePipeline() const { return m_compute_pipeline; }
|
||||
bool HasBinary() const override;
|
||||
BinaryData GetBinary() const override;
|
||||
|
||||
static std::unique_ptr<VKShader> CreateFromSource(ShaderStage stage, const char* source,
|
||||
|
@ -266,6 +266,8 @@ void VulkanContext::PopulateBackendInfo(VideoConfig* config)
|
||||
config->backend_info.bSupportsGPUTextureDecoding = true; // Assumed support.
|
||||
config->backend_info.bSupportsBitfield = true; // Assumed support.
|
||||
config->backend_info.bSupportsPartialDepthCopies = true; // Assumed support.
|
||||
config->backend_info.bSupportsShaderBinaries = true; // Assumed support.
|
||||
config->backend_info.bSupportsPipelineCacheData = false; // Handled via pipeline caches.
|
||||
config->backend_info.bSupportsDynamicSamplerIndexing = true; // Assumed support.
|
||||
config->backend_info.bSupportsPostProcessing = true; // Assumed support.
|
||||
config->backend_info.bSupportsBackgroundCompiling = true; // Assumed support.
|
||||
|
@ -75,4 +75,10 @@ class AbstractPipeline
|
||||
public:
|
||||
AbstractPipeline() = default;
|
||||
virtual ~AbstractPipeline() = default;
|
||||
|
||||
// "Cache data" can be used to assist a driver with creating pipelines by using previously
|
||||
// compiled shader ISA. The abstract shaders and creation struct are still required to create
|
||||
// pipeline objects, the cache is optionally used by the driver to speed up compilation.
|
||||
using CacheData = std::vector<u8>;
|
||||
virtual CacheData GetCacheData() const { return {}; }
|
||||
};
|
||||
|
@ -25,9 +25,11 @@ public:
|
||||
virtual ~AbstractShader() = default;
|
||||
|
||||
ShaderStage GetStage() const { return m_stage; }
|
||||
|
||||
// Shader binaries represent the input source code in a lower-level form. e.g. SPIR-V or DXBC.
|
||||
// The shader source code is not required to create a shader object from the binary.
|
||||
using BinaryData = std::vector<u8>;
|
||||
virtual bool HasBinary() const = 0;
|
||||
virtual BinaryData GetBinary() const = 0;
|
||||
virtual BinaryData GetBinary() const { return {}; }
|
||||
|
||||
protected:
|
||||
ShaderStage m_stage;
|
||||
|
@ -130,8 +130,9 @@ public:
|
||||
CreateShaderFromBinary(ShaderStage stage, const void* data, size_t length) = 0;
|
||||
virtual std::unique_ptr<NativeVertexFormat>
|
||||
CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) = 0;
|
||||
virtual std::unique_ptr<AbstractPipeline>
|
||||
CreatePipeline(const AbstractPipelineConfig& config) = 0;
|
||||
virtual std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config,
|
||||
const void* cache_data = nullptr,
|
||||
size_t cache_data_length = 0) = 0;
|
||||
std::unique_ptr<AbstractShader> CreateShaderFromSource(ShaderStage stage,
|
||||
const std::string& source);
|
||||
|
||||
|
@ -334,7 +334,7 @@ const AbstractShader* ShaderCache::InsertVertexShader(const VertexShaderUid& uid
|
||||
|
||||
if (shader && !entry.shader)
|
||||
{
|
||||
if (g_ActiveConfig.bShaderCache && shader->HasBinary())
|
||||
if (g_ActiveConfig.bShaderCache && g_ActiveConfig.backend_info.bSupportsShaderBinaries)
|
||||
{
|
||||
auto binary = shader->GetBinary();
|
||||
if (!binary.empty())
|
||||
@ -356,7 +356,7 @@ const AbstractShader* ShaderCache::InsertVertexUberShader(const UberShader::Vert
|
||||
|
||||
if (shader && !entry.shader)
|
||||
{
|
||||
if (g_ActiveConfig.bShaderCache && shader->HasBinary())
|
||||
if (g_ActiveConfig.bShaderCache && g_ActiveConfig.backend_info.bSupportsShaderBinaries)
|
||||
{
|
||||
auto binary = shader->GetBinary();
|
||||
if (!binary.empty())
|
||||
@ -378,7 +378,7 @@ const AbstractShader* ShaderCache::InsertPixelShader(const PixelShaderUid& uid,
|
||||
|
||||
if (shader && !entry.shader)
|
||||
{
|
||||
if (g_ActiveConfig.bShaderCache && shader->HasBinary())
|
||||
if (g_ActiveConfig.bShaderCache && g_ActiveConfig.backend_info.bSupportsShaderBinaries)
|
||||
{
|
||||
auto binary = shader->GetBinary();
|
||||
if (!binary.empty())
|
||||
@ -400,7 +400,7 @@ const AbstractShader* ShaderCache::InsertPixelUberShader(const UberShader::Pixel
|
||||
|
||||
if (shader && !entry.shader)
|
||||
{
|
||||
if (g_ActiveConfig.bShaderCache && shader->HasBinary())
|
||||
if (g_ActiveConfig.bShaderCache && g_ActiveConfig.backend_info.bSupportsShaderBinaries)
|
||||
{
|
||||
auto binary = shader->GetBinary();
|
||||
if (!binary.empty())
|
||||
@ -425,7 +425,7 @@ const AbstractShader* ShaderCache::CreateGeometryShader(const GeometryShaderUid&
|
||||
|
||||
if (shader && !entry.shader)
|
||||
{
|
||||
if (g_ActiveConfig.bShaderCache && shader->HasBinary())
|
||||
if (g_ActiveConfig.bShaderCache && g_ActiveConfig.backend_info.bSupportsShaderBinaries)
|
||||
{
|
||||
auto binary = shader->GetBinary();
|
||||
if (!binary.empty())
|
||||
|
@ -219,6 +219,8 @@ struct VideoConfig final
|
||||
bool bSupportsBackgroundCompiling;
|
||||
bool bSupportsLargePoints;
|
||||
bool bSupportsPartialDepthCopies;
|
||||
bool bSupportsShaderBinaries;
|
||||
bool bSupportsPipelineCacheData;
|
||||
} backend_info;
|
||||
|
||||
// Utility
|
||||
|
Loading…
x
Reference in New Issue
Block a user