From 75c66e35c68a791ab5415b1a120cc07321ad2e79 Mon Sep 17 00:00:00 2001 From: iwubcode Date: Thu, 20 Nov 2025 22:12:09 -0600 Subject: [PATCH] VideoCommon: add method to async shader compiler to clear pending/completed work (used on shutdown), this will in turn clear up any resources that the worker items may have held onto --- Source/Core/VideoCommon/AsyncShaderCompiler.cpp | 13 +++++++++++++ Source/Core/VideoCommon/AsyncShaderCompiler.h | 3 +++ .../GraphicsModSystem/Runtime/CustomShaderCache.cpp | 6 ++++++ Source/Core/VideoCommon/ShaderCache.cpp | 3 +++ 4 files changed, 25 insertions(+) diff --git a/Source/Core/VideoCommon/AsyncShaderCompiler.cpp b/Source/Core/VideoCommon/AsyncShaderCompiler.cpp index c69354628d..e312525eb9 100644 --- a/Source/Core/VideoCommon/AsyncShaderCompiler.cpp +++ b/Source/Core/VideoCommon/AsyncShaderCompiler.cpp @@ -68,6 +68,19 @@ bool AsyncShaderCompiler::HasCompletedWork() return !m_completed_work.empty(); } +void AsyncShaderCompiler::ClearAllWork() +{ + { + std::lock_guard guard(m_pending_work_lock); + m_pending_work.clear(); + } + + { + std::lock_guard guard(m_completed_work_lock); + m_completed_work.clear(); + } +} + bool AsyncShaderCompiler::WaitUntilCompletion( const std::function& progress_callback) { diff --git a/Source/Core/VideoCommon/AsyncShaderCompiler.h b/Source/Core/VideoCommon/AsyncShaderCompiler.h index 8773891d61..ffcca0c4ec 100644 --- a/Source/Core/VideoCommon/AsyncShaderCompiler.h +++ b/Source/Core/VideoCommon/AsyncShaderCompiler.h @@ -49,6 +49,9 @@ public: bool HasPendingWork(); bool HasCompletedWork(); + // Clears both pending and completed work + void ClearAllWork(); + // Calls progress_callback periodically, with completed_items, and total_items. // Returns false if interrupted. bool WaitUntilCompletion(const std::function& progress_callback); diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/CustomShaderCache.cpp b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/CustomShaderCache.cpp index a3c98ee9d7..0c4cf43227 100644 --- a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/CustomShaderCache.cpp +++ b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/CustomShaderCache.cpp @@ -24,10 +24,16 @@ CustomShaderCache::CustomShaderCache() CustomShaderCache::~CustomShaderCache() { if (m_async_shader_compiler) + { m_async_shader_compiler->StopWorkerThreads(); + m_async_shader_compiler->ClearAllWork(); + } if (m_async_uber_shader_compiler) + { m_async_uber_shader_compiler->StopWorkerThreads(); + m_async_uber_shader_compiler->ClearAllWork(); + } } void CustomShaderCache::RetrieveAsyncShaders() diff --git a/Source/Core/VideoCommon/ShaderCache.cpp b/Source/Core/VideoCommon/ShaderCache.cpp index a3d07368f6..03dc21c937 100644 --- a/Source/Core/VideoCommon/ShaderCache.cpp +++ b/Source/Core/VideoCommon/ShaderCache.cpp @@ -109,7 +109,10 @@ void ShaderCache::Shutdown() // This may leave shaders uncommitted to the cache, but it's better than blocking shutdown // until everything has finished compiling. if (m_async_shader_compiler) + { m_async_shader_compiler->StopWorkerThreads(); + m_async_shader_compiler->ClearAllWork(); + } ClosePipelineUIDCache(); }