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:
Stenzek
2019-04-15 21:55:26 +10:00
parent 2863183532
commit 61a656570e
29 changed files with 68 additions and 51 deletions

View File

@ -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 {}; }
};

View File

@ -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;

View File

@ -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);

View File

@ -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())

View File

@ -219,6 +219,8 @@ struct VideoConfig final
bool bSupportsBackgroundCompiling;
bool bSupportsLargePoints;
bool bSupportsPartialDepthCopies;
bool bSupportsShaderBinaries;
bool bSupportsPipelineCacheData;
} backend_info;
// Utility