Join the shader cache load thread on exit

This commit is contained in:
Henrik Rydgård 2023-09-24 01:07:08 +02:00
parent 9a515c851f
commit dbd3045f87
3 changed files with 14 additions and 2 deletions

View file

@ -25,6 +25,7 @@
#include "Common/GraphicsContext.h"
#include "Common/Serialize/Serializer.h"
#include "Common/TimeUtil.h"
#include "Common/Thread/ThreadUtil.h"
#include "Core/Config.h"
#include "Core/Debugger/Breakpoints.h"
@ -94,11 +95,12 @@ GPU_Vulkan::GPU_Vulkan(GraphicsContext *gfxCtx, Draw::DrawContext *draw)
shaderCachePath_ = GetSysDirectory(DIRECTORY_APP_CACHE) / (discID + ".vkshadercache");
shaderCacheLoaded_ = false;
std::thread th([&] {
shaderCacheLoadThread_ = std::thread([&] {
SetCurrentThreadName("VulkanLoadCache");
AndroidJNIThreadContext ctx;
LoadCache(shaderCachePath_);
shaderCacheLoaded_ = true;
});
th.detach();
} else {
shaderCacheLoaded_ = true;
}
@ -180,6 +182,10 @@ void GPU_Vulkan::SaveCache(const Path &filename) {
}
GPU_Vulkan::~GPU_Vulkan() {
if (shaderCacheLoadThread_.joinable()) {
shaderCacheLoadThread_.join();
}
if (draw_) {
VulkanRenderManager *rm = (VulkanRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
rm->DrainAndBlockCompileQueue();

View file

@ -19,6 +19,7 @@
#include <string>
#include <vector>
#include <thread>
#include "Common/File/Path.h"
@ -84,4 +85,6 @@ private:
Path shaderCachePath_;
std::atomic<bool> shaderCacheLoaded_{};
std::thread shaderCacheLoadThread_;
};

View file

@ -239,6 +239,8 @@ void ShaderManagerVulkan::DeviceRestore(Draw::DrawContext *draw) {
}
void ShaderManagerVulkan::Clear() {
std::lock_guard<std::mutex> guard(cacheLock_);
fsCache_.Iterate([&](const FShaderID &key, VulkanFragmentShader *shader) {
delete shader;
});
@ -397,6 +399,7 @@ void ShaderManagerVulkan::GetShaders(int prim, VertexDecoder *decoder, VulkanVer
}
std::vector<std::string> ShaderManagerVulkan::DebugGetShaderIDs(DebugShaderType type) {
std::lock_guard<std::mutex> guard(cacheLock_);
std::vector<std::string> ids;
switch (type) {
case SHADER_TYPE_VERTEX: