Skip to content

Commit

Permalink
Vulkan: Load shaders/pipelines on thread.
Browse files Browse the repository at this point in the history
In case it's slow when not reading raw cache data.
  • Loading branch information
unknownbrackets committed Mar 17, 2018
1 parent 99af1d5 commit 7ae4a9e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
12 changes: 11 additions & 1 deletion GPU/Vulkan/GPU_Vulkan.cpp
Expand Up @@ -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"

Expand Down Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions GPU/Vulkan/GPU_Vulkan.h
Expand Up @@ -38,6 +38,8 @@ class GPU_Vulkan : public GPUCommon {
// 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;
Expand Down Expand Up @@ -105,4 +107,5 @@ class GPU_Vulkan : public GPUCommon {
FrameData frameData_[VulkanContext::MAX_INFLIGHT_FRAMES]{};

std::string shaderCachePath_;
bool shaderCacheLoaded_ = false;
};
2 changes: 1 addition & 1 deletion GPU/Vulkan/PipelineManagerVulkan.cpp
Expand Up @@ -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.
Expand Down

0 comments on commit 7ae4a9e

Please sign in to comment.