Vulkan: Load shaders/pipelines on thread.

In case it's slow when not reading raw cache data.
This commit is contained in:
Unknown W. Brackets 2018-03-17 07:42:07 -07:00
parent 99af1d58ad
commit 7ae4a9e977
3 changed files with 15 additions and 2 deletions

View File

@ -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 <thread>
#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.

View File

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

View File

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