From 33f66685440e038811f37a8b8328942563227bd0 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Thu, 20 Jul 2017 15:25:38 +1000 Subject: [PATCH] Vulkan: Multithreaded creation of UID pipeline caches Should give a decent speedup to boot time. --- Source/Core/VideoBackends/Vulkan/Renderer.cpp | 3 --- .../VideoBackends/Vulkan/StateTracker.cpp | 20 +++++++++++++++---- Source/Core/VideoBackends/Vulkan/main.cpp | 3 +++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Source/Core/VideoBackends/Vulkan/Renderer.cpp b/Source/Core/VideoBackends/Vulkan/Renderer.cpp index de281e7e38..682fb8885c 100644 --- a/Source/Core/VideoBackends/Vulkan/Renderer.cpp +++ b/Source/Core/VideoBackends/Vulkan/Renderer.cpp @@ -113,9 +113,6 @@ bool Renderer::Initialize() m_bounding_box->GetGPUBufferSize()); } - // Ensure all pipelines previously used by the game have been created. - StateTracker::GetInstance()->ReloadPipelineUIDCache(); - // Initialize post processing. m_post_processor = std::make_unique(); if (!static_cast(m_post_processor.get()) diff --git a/Source/Core/VideoBackends/Vulkan/StateTracker.cpp b/Source/Core/VideoBackends/Vulkan/StateTracker.cpp index c0661422f1..7d7ed0d956 100644 --- a/Source/Core/VideoBackends/Vulkan/StateTracker.cpp +++ b/Source/Core/VideoBackends/Vulkan/StateTracker.cpp @@ -156,6 +156,10 @@ void StateTracker::ReloadPipelineUIDCache() PipelineInserter inserter(this); m_uid_cache.OpenAndRead(filename, inserter); } + + // If we were using background compilation, ensure everything is ready before continuing. + if (g_ActiveConfig.bBackgroundShaderCompiling) + g_shader_cache->WaitForBackgroundCompilesToComplete(); } void StateTracker::AppendToPipelineUIDCache(const PipelineInfo& info) @@ -212,11 +216,19 @@ bool StateTracker::PrecachePipelineUID(const SerializedPipelineUID& uid) pinfo.blend_state.hex = uid.blend_state_bits; pinfo.primitive_topology = uid.primitive_topology; - VkPipeline pipeline = g_shader_cache->GetPipeline(pinfo); - if (pipeline == VK_NULL_HANDLE) + if (g_ActiveConfig.bBackgroundShaderCompiling) { - WARN_LOG(VIDEO, "Failed to get pipeline from cached UID."); - return false; + // Use async for multithreaded compilation. + g_shader_cache->GetPipelineWithCacheResultAsync(pinfo); + } + else + { + VkPipeline pipeline = g_shader_cache->GetPipeline(pinfo); + if (pipeline == VK_NULL_HANDLE) + { + WARN_LOG(VIDEO, "Failed to get pipeline from cached UID."); + return false; + } } // We don't need to do anything with this pipeline, just make sure it exists. diff --git a/Source/Core/VideoBackends/Vulkan/main.cpp b/Source/Core/VideoBackends/Vulkan/main.cpp index 3fecc914c1..f507d6cf05 100644 --- a/Source/Core/VideoBackends/Vulkan/main.cpp +++ b/Source/Core/VideoBackends/Vulkan/main.cpp @@ -263,6 +263,9 @@ bool VideoBackend::Initialize(void* window_handle) return false; } + // Ensure all pipelines previously used by the game have been created. + StateTracker::GetInstance()->ReloadPipelineUIDCache(); + // Lastly, precompile ubershaders, if requested. // This has to be done after the texture cache and shader cache are initialized. if (g_ActiveConfig.CanPrecompileUberShaders())