From 7ae4a9e9776321c3932d9e767b71060a52716267 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 Mar 2018 07:42:07 -0700 Subject: [PATCH] Vulkan: Load shaders/pipelines on thread. In case it's slow when not reading raw cache data. --- GPU/Vulkan/GPU_Vulkan.cpp | 12 +++++++++++- GPU/Vulkan/GPU_Vulkan.h | 3 +++ GPU/Vulkan/PipelineManagerVulkan.cpp | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/GPU/Vulkan/GPU_Vulkan.cpp b/GPU/Vulkan/GPU_Vulkan.cpp index c073f8d95..30598c92e 100644 --- a/GPU/Vulkan/GPU_Vulkan.cpp +++ b/GPU/Vulkan/GPU_Vulkan.cpp @@ -16,6 +16,7 @@ // Official git repository and contact information can be found at // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. +#include #include "base/logging.h" #include "profiler/profiler.h" @@ -101,11 +102,20 @@ GPU_Vulkan::GPU_Vulkan(GraphicsContext *gfxCtx, Draw::DrawContext *draw) if (discID.size()) { File::CreateFullPath(GetSysDirectory(DIRECTORY_APP_CACHE)); shaderCachePath_ = GetSysDirectory(DIRECTORY_APP_CACHE) + "/" + discID + ".vkshadercache"; + shaderCacheLoaded_ = false; - LoadCache(shaderCachePath_); + std::thread th([&] { + LoadCache(shaderCachePath_); + shaderCacheLoaded_ = true; + }); + th.detach(); } } +bool GPU_Vulkan::IsReady() { + return shaderCacheLoaded_; +} + void GPU_Vulkan::LoadCache(std::string filename) { PSP_SetLoading("Loading shader cache..."); // Actually precompiled by IsReady() since we're single-threaded. diff --git a/GPU/Vulkan/GPU_Vulkan.h b/GPU/Vulkan/GPU_Vulkan.h index 7e81e6c27..d4ce2151a 100644 --- a/GPU/Vulkan/GPU_Vulkan.h +++ b/GPU/Vulkan/GPU_Vulkan.h @@ -38,6 +38,8 @@ public: // This gets called on startup and when we get back from settings. void CheckGPUFeatures() override; + bool IsReady() override; + // These are where we can reset command buffers etc. void BeginHostFrame() override; void EndHostFrame() override; @@ -105,4 +107,5 @@ private: FrameData frameData_[VulkanContext::MAX_INFLIGHT_FRAMES]{}; std::string shaderCachePath_; + bool shaderCacheLoaded_ = false; }; diff --git a/GPU/Vulkan/PipelineManagerVulkan.cpp b/GPU/Vulkan/PipelineManagerVulkan.cpp index 9fd4ba254..6e9a62aeb 100644 --- a/GPU/Vulkan/PipelineManagerVulkan.cpp +++ b/GPU/Vulkan/PipelineManagerVulkan.cpp @@ -602,12 +602,12 @@ bool PipelineManagerVulkan::LoadCache(FILE *file, bool loadRawPipelineCache, Sha } else { vkMergePipelineCaches(vulkan_->GetDevice(), pipelineCache_, 1, &cache); } + NOTICE_LOG(G3D, "Loaded Vulkan pipeline cache (%d bytes).", (int)size); } else { if (!pipelineCache_) { VkPipelineCacheCreateInfo pc{ VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO }; VkResult res = vkCreatePipelineCache(vulkan_->GetDevice(), &pc, nullptr, &pipelineCache_); } - NOTICE_LOG(G3D, "Loaded Vulkan pipeline cache (%d bytes).", (int)size); } // Read the number of pipelines.