Vulkan: Properly shut down compilation threads

This commit is contained in:
Exzap 2023-12-06 02:16:17 +01:00
parent bffeb818d1
commit e7fa8ec0c6
3 changed files with 28 additions and 3 deletions

View File

@ -139,7 +139,7 @@ public:
}
}
~_ShaderVkThreadPool()
void StopThreads()
{
m_shutdownThread.store(true);
for (uint32 i = 0; i < s_threads.size(); ++i)
@ -149,6 +149,11 @@ public:
s_threads.clear();
}
~_ShaderVkThreadPool()
{
StopThreads();
}
void CompilerThreadFunc()
{
while (!m_shutdownThread.load(std::memory_order::relaxed))
@ -176,6 +181,8 @@ public:
}
}
bool HasThreadsRunning() const { return !m_shutdownThread; }
public:
std::vector<std::thread> s_threads;
@ -195,8 +202,8 @@ RendererShaderVk::RendererShaderVk(ShaderType type, uint64 baseHash, uint64 auxH
m_compilationState.setValue(COMPILATION_STATE::QUEUED);
ShaderVkThreadPool.s_compilationQueue.push_back(this);
ShaderVkThreadPool.s_compilationQueueCount.increment();
ShaderVkThreadPool.StartThreads();
ShaderVkThreadPool.s_compilationQueueMutex.unlock();
cemu_assert_debug(ShaderVkThreadPool.HasThreadsRunning()); // make sure .StartThreads() was called
}
RendererShaderVk::~RendererShaderVk()
@ -204,6 +211,16 @@ RendererShaderVk::~RendererShaderVk()
VulkanRenderer::GetInstance()->destroyShader(this);
}
void RendererShaderVk::Init()
{
ShaderVkThreadPool.StartThreads();
}
void RendererShaderVk::Shutdown()
{
ShaderVkThreadPool.StopThreads();
}
sint32 RendererShaderVk::GetUniformLocation(const char* name)
{
cemu_assert_suspicious();

View File

@ -28,6 +28,9 @@ public:
RendererShaderVk(ShaderType type, uint64 baseHash, uint64 auxHash, bool isGameShader, bool isGfxPackShader, const std::string& glslCode);
virtual ~RendererShaderVk();
static void Init();
static void Shutdown();
sint32 GetUniformLocation(const char* name) override;
void SetUniform1iv(sint32 location, void* data, sint32 count) override;
void SetUniform2fv(sint32 location, void* data, sint32 count) override;

View File

@ -591,6 +591,9 @@ VulkanRenderer::VulkanRenderer()
{
//cemuLog_log(LogType::Force, "Disable surface copies via buffer (Requires 2GB. Has only {}MB available)", availableSurfaceCopyBufferMem / 1024ull / 1024ull);
}
// start compilation threads
RendererShaderVk::Init();
}
VulkanRenderer::~VulkanRenderer()
@ -598,6 +601,8 @@ VulkanRenderer::~VulkanRenderer()
SubmitCommandBuffer();
WaitDeviceIdle();
WaitCommandBufferFinished(GetCurrentCommandBufferId());
// shut down compilation threads
RendererShaderVk::Shutdown();
// shut down pipeline save thread
m_destructionRequested = true;
m_pipeline_cache_semaphore.notify();