Skip to content
Permalink
Browse files

AbstractPipeline: Support returning "cache data"

"Cache data" can be used to assist a driver with creating pipelines by
using previously-compiled shader ISA.
  • Loading branch information...
stenzek committed Apr 15, 2019
1 parent 2863183 commit 61a656570e2afc7a474c44de5795f5d564043c6c
Showing with 68 additions and 51 deletions.
  1. +3 −1 Source/Core/VideoBackends/D3D/Render.cpp
  2. +3 −1 Source/Core/VideoBackends/D3D/Render.h
  3. +2 −0 Source/Core/VideoBackends/D3D/main.cpp
  4. +3 −1 Source/Core/VideoBackends/D3D12/Renderer.cpp
  5. +3 −1 Source/Core/VideoBackends/D3D12/Renderer.h
  6. +2 −0 Source/Core/VideoBackends/D3D12/VideoBackend.cpp
  7. +0 −5 Source/Core/VideoBackends/D3DCommon/Shader.cpp
  8. +0 −1 Source/Core/VideoBackends/D3DCommon/Shader.h
  9. +2 −0 Source/Core/VideoBackends/Null/NullBackend.cpp
  10. +3 −4 Source/Core/VideoBackends/Null/Render.cpp
  11. +3 −1 Source/Core/VideoBackends/Null/Render.h
  12. +0 −11 Source/Core/VideoBackends/OGL/OGLShader.cpp
  13. +0 −2 Source/Core/VideoBackends/OGL/OGLShader.h
  14. +3 −1 Source/Core/VideoBackends/OGL/Render.cpp
  15. +3 −1 Source/Core/VideoBackends/OGL/Render.h
  16. +2 −0 Source/Core/VideoBackends/OGL/main.cpp
  17. +3 −2 Source/Core/VideoBackends/Software/SWRenderer.cpp
  18. +3 −1 Source/Core/VideoBackends/Software/SWRenderer.h
  19. +2 −0 Source/Core/VideoBackends/Software/SWmain.cpp
  20. +3 −1 Source/Core/VideoBackends/Vulkan/Renderer.cpp
  21. +3 −1 Source/Core/VideoBackends/Vulkan/Renderer.h
  22. +0 −6 Source/Core/VideoBackends/Vulkan/VKShader.cpp
  23. +0 −1 Source/Core/VideoBackends/Vulkan/VKShader.h
  24. +2 −0 Source/Core/VideoBackends/Vulkan/VulkanContext.cpp
  25. +6 −0 Source/Core/VideoCommon/AbstractPipeline.h
  26. +4 −2 Source/Core/VideoCommon/AbstractShader.h
  27. +3 −2 Source/Core/VideoCommon/RenderBase.h
  28. +5 −5 Source/Core/VideoCommon/ShaderCache.cpp
  29. +2 −0 Source/Core/VideoCommon/VideoConfig.h
@@ -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 @@ class Renderer : public ::Renderer
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 @@ class Renderer final : public ::Renderer
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 @@ class Shader : public AbstractShader

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 @@ class NullPipeline final : public AbstractPipeline
~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 @@ class Renderer : public ::Renderer
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 @@ class OGLShader final : public AbstractShader
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 @@ class Renderer : public ::Renderer
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 @@ class SWShader final : public AbstractShader
explicit SWShader(ShaderStage stage) : AbstractShader(stage) {}
~SWShader() = default;

bool HasBinary() const override { return false; }
BinaryData GetBinary() const override { return {}; }
};

@@ -87,7 +86,9 @@ class SWPipeline final : public AbstractPipeline
~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 @@ class SWRenderer final : public Renderer
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 @@ class Renderer : public ::Renderer
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 @@ class VKShader final : public AbstractShader

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 @@ class AbstractShader
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 @@ class Renderer
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

0 comments on commit 61a6565

Please sign in to comment.
You can’t perform that action at this time.