Vulkan: Move clear shader from Renderer to ShaderCache
This commit is contained in:
parent
e2cf238ec4
commit
3b033bf3f0
|
@ -76,12 +76,6 @@ bool Renderer::Initialize()
|
||||||
|
|
||||||
BindEFBToStateTracker();
|
BindEFBToStateTracker();
|
||||||
|
|
||||||
if (!CompileShaders())
|
|
||||||
{
|
|
||||||
PanicAlert("Failed to compile shaders.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_bounding_box = std::make_unique<BoundingBox>();
|
m_bounding_box = std::make_unique<BoundingBox>();
|
||||||
if (!m_bounding_box->Initialize())
|
if (!m_bounding_box->Initialize())
|
||||||
{
|
{
|
||||||
|
@ -117,8 +111,6 @@ bool Renderer::Initialize()
|
||||||
void Renderer::Shutdown()
|
void Renderer::Shutdown()
|
||||||
{
|
{
|
||||||
::Renderer::Shutdown();
|
::Renderer::Shutdown();
|
||||||
|
|
||||||
DestroyShaders();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<AbstractTexture> Renderer::CreateTexture(const TextureConfig& config)
|
std::unique_ptr<AbstractTexture> Renderer::CreateTexture(const TextureConfig& config)
|
||||||
|
@ -447,7 +439,8 @@ void Renderer::ClearScreen(const EFBRectangle& rc, bool color_enable, bool alpha
|
||||||
g_object_cache->GetPipelineLayout(PIPELINE_LAYOUT_STANDARD),
|
g_object_cache->GetPipelineLayout(PIPELINE_LAYOUT_STANDARD),
|
||||||
FramebufferManager::GetInstance()->GetEFBLoadRenderPass(),
|
FramebufferManager::GetInstance()->GetEFBLoadRenderPass(),
|
||||||
g_shader_cache->GetPassthroughVertexShader(),
|
g_shader_cache->GetPassthroughVertexShader(),
|
||||||
g_shader_cache->GetPassthroughGeometryShader(), m_clear_fragment_shader);
|
g_shader_cache->GetPassthroughGeometryShader(),
|
||||||
|
g_shader_cache->GetClearFragmentShader());
|
||||||
|
|
||||||
draw.SetMultisamplingState(FramebufferManager::GetInstance()->GetEFBMultisamplingState());
|
draw.SetMultisamplingState(FramebufferManager::GetInstance()->GetEFBMultisamplingState());
|
||||||
draw.SetDepthState(depth_state);
|
draw.SetDepthState(depth_state);
|
||||||
|
@ -658,7 +651,6 @@ void Renderer::OnConfigChanged(u32 bits)
|
||||||
if (bits & (CONFIG_CHANGE_BIT_HOST_CONFIG | CONFIG_CHANGE_BIT_MULTISAMPLES))
|
if (bits & (CONFIG_CHANGE_BIT_HOST_CONFIG | CONFIG_CHANGE_BIT_MULTISAMPLES))
|
||||||
{
|
{
|
||||||
RecreateEFBFramebuffer();
|
RecreateEFBFramebuffer();
|
||||||
RecompileShaders();
|
|
||||||
FramebufferManager::GetInstance()->RecompileShaders();
|
FramebufferManager::GetInstance()->RecompileShaders();
|
||||||
g_shader_cache->ReloadPipelineCache();
|
g_shader_cache->ReloadPipelineCache();
|
||||||
g_shader_cache->RecompileSharedShaders();
|
g_shader_cache->RecompileSharedShaders();
|
||||||
|
@ -892,45 +884,4 @@ void Renderer::DrawIndexed(u32 base_index, u32 num_indices, u32 base_vertex)
|
||||||
vkCmdDrawIndexed(g_command_buffer_mgr->GetCurrentCommandBuffer(), num_indices, 1, base_index,
|
vkCmdDrawIndexed(g_command_buffer_mgr->GetCurrentCommandBuffer(), num_indices, 1, base_index,
|
||||||
base_vertex, 0);
|
base_vertex, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::RecompileShaders()
|
|
||||||
{
|
|
||||||
DestroyShaders();
|
|
||||||
if (!CompileShaders())
|
|
||||||
PanicAlert("Failed to recompile shaders.");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Renderer::CompileShaders()
|
|
||||||
{
|
|
||||||
static const char CLEAR_FRAGMENT_SHADER_SOURCE[] = R"(
|
|
||||||
layout(location = 0) in float3 uv0;
|
|
||||||
layout(location = 1) in float4 col0;
|
|
||||||
layout(location = 0) out float4 ocol0;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
ocol0 = col0;
|
|
||||||
}
|
|
||||||
|
|
||||||
)";
|
|
||||||
|
|
||||||
std::string source = g_shader_cache->GetUtilityShaderHeader() + CLEAR_FRAGMENT_SHADER_SOURCE;
|
|
||||||
m_clear_fragment_shader = Util::CompileAndCreateFragmentShader(source);
|
|
||||||
|
|
||||||
return m_clear_fragment_shader != VK_NULL_HANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::DestroyShaders()
|
|
||||||
{
|
|
||||||
auto DestroyShader = [this](VkShaderModule& shader) {
|
|
||||||
if (shader != VK_NULL_HANDLE)
|
|
||||||
{
|
|
||||||
vkDestroyShaderModule(g_vulkan_context->GetDevice(), shader, nullptr);
|
|
||||||
shader = VK_NULL_HANDLE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
DestroyShader(m_clear_fragment_shader);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Vulkan
|
} // namespace Vulkan
|
||||||
|
|
|
@ -104,17 +104,10 @@ private:
|
||||||
void RecreateEFBFramebuffer();
|
void RecreateEFBFramebuffer();
|
||||||
void BindFramebuffer(const VKFramebuffer* fb);
|
void BindFramebuffer(const VKFramebuffer* fb);
|
||||||
|
|
||||||
void RecompileShaders();
|
|
||||||
bool CompileShaders();
|
|
||||||
void DestroyShaders();
|
|
||||||
|
|
||||||
std::unique_ptr<SwapChain> m_swap_chain;
|
std::unique_ptr<SwapChain> m_swap_chain;
|
||||||
std::unique_ptr<BoundingBox> m_bounding_box;
|
std::unique_ptr<BoundingBox> m_bounding_box;
|
||||||
|
|
||||||
// Keep a copy of sampler states to avoid cache lookups every draw
|
// Keep a copy of sampler states to avoid cache lookups every draw
|
||||||
std::array<SamplerState, NUM_PIXEL_SHADER_SAMPLERS> m_sampler_states = {};
|
std::array<SamplerState, NUM_PIXEL_SHADER_SAMPLERS> m_sampler_states = {};
|
||||||
|
|
||||||
// Shaders used for clear/blit.
|
|
||||||
VkShaderModule m_clear_fragment_shader = VK_NULL_HANDLE;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -795,7 +795,19 @@ bool ShaderCache::CompileSharedShaders()
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
|
|
||||||
std::string header = GetUtilityShaderHeader();
|
static const char CLEAR_FRAGMENT_SHADER_SOURCE[] = R"(
|
||||||
|
layout(location = 0) in float3 uv0;
|
||||||
|
layout(location = 1) in float4 col0;
|
||||||
|
layout(location = 0) out float4 ocol0;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
ocol0 = col0;
|
||||||
|
}
|
||||||
|
|
||||||
|
)";
|
||||||
|
|
||||||
|
const std::string header = GetUtilityShaderHeader();
|
||||||
|
|
||||||
m_screen_quad_vertex_shader =
|
m_screen_quad_vertex_shader =
|
||||||
Util::CompileAndCreateVertexShader(header + SCREEN_QUAD_VERTEX_SHADER_SOURCE);
|
Util::CompileAndCreateVertexShader(header + SCREEN_QUAD_VERTEX_SHADER_SOURCE);
|
||||||
|
@ -820,6 +832,11 @@ bool ShaderCache::CompileSharedShaders()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_clear_fragment_shader =
|
||||||
|
Util::CompileAndCreateFragmentShader(header + CLEAR_FRAGMENT_SHADER_SOURCE);
|
||||||
|
if (m_clear_fragment_shader == VK_NULL_HANDLE)
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -837,5 +854,6 @@ void ShaderCache::DestroySharedShaders()
|
||||||
DestroyShader(m_passthrough_vertex_shader);
|
DestroyShader(m_passthrough_vertex_shader);
|
||||||
DestroyShader(m_screen_quad_geometry_shader);
|
DestroyShader(m_screen_quad_geometry_shader);
|
||||||
DestroyShader(m_passthrough_geometry_shader);
|
DestroyShader(m_passthrough_geometry_shader);
|
||||||
|
DestroyShader(m_clear_fragment_shader);
|
||||||
}
|
}
|
||||||
}
|
} // namespace Vulkan
|
||||||
|
|
|
@ -116,6 +116,7 @@ public:
|
||||||
VkShaderModule GetPassthroughVertexShader() const { return m_passthrough_vertex_shader; }
|
VkShaderModule GetPassthroughVertexShader() const { return m_passthrough_vertex_shader; }
|
||||||
VkShaderModule GetScreenQuadGeometryShader() const { return m_screen_quad_geometry_shader; }
|
VkShaderModule GetScreenQuadGeometryShader() const { return m_screen_quad_geometry_shader; }
|
||||||
VkShaderModule GetPassthroughGeometryShader() const { return m_passthrough_geometry_shader; }
|
VkShaderModule GetPassthroughGeometryShader() const { return m_passthrough_geometry_shader; }
|
||||||
|
VkShaderModule GetClearFragmentShader() const { return m_clear_fragment_shader; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool CreatePipelineCache();
|
bool CreatePipelineCache();
|
||||||
|
@ -136,6 +137,7 @@ private:
|
||||||
VkShaderModule m_passthrough_vertex_shader = VK_NULL_HANDLE;
|
VkShaderModule m_passthrough_vertex_shader = VK_NULL_HANDLE;
|
||||||
VkShaderModule m_screen_quad_geometry_shader = VK_NULL_HANDLE;
|
VkShaderModule m_screen_quad_geometry_shader = VK_NULL_HANDLE;
|
||||||
VkShaderModule m_passthrough_geometry_shader = VK_NULL_HANDLE;
|
VkShaderModule m_passthrough_geometry_shader = VK_NULL_HANDLE;
|
||||||
|
VkShaderModule m_clear_fragment_shader = VK_NULL_HANDLE;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern std::unique_ptr<ShaderCache> g_shader_cache;
|
extern std::unique_ptr<ShaderCache> g_shader_cache;
|
||||||
|
|
Loading…
Reference in New Issue