summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/AsyncShaderCompiler.cpp
diff options
context:
space:
mode:
authorAdmiral H. Curtiss <pikachu025@gmail.com>2022-07-02 13:08:37 +0200
committerGitHub <noreply@github.com>2022-07-02 13:08:37 +0200
commit3bcd7aced92206d24ded30e0a595d2d87875e9f0 (patch)
tree1b582773b15ee262c1c8650d2ba6adcb40f9c73b /Source/Core/VideoCommon/AsyncShaderCompiler.cpp
parent2f228310affd10297d4e7d61ad2aa2c910b69eac (diff)
parent7faf5ea170f23de3b4a7b9362926490c5b7a97bc (diff)
Merge pull request #8467 from CookiePLMonster/interruptable-shader-precompile
Make shader precompilation interruptable
Diffstat (limited to 'Source/Core/VideoCommon/AsyncShaderCompiler.cpp')
-rw-r--r--Source/Core/VideoCommon/AsyncShaderCompiler.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/Source/Core/VideoCommon/AsyncShaderCompiler.cpp b/Source/Core/VideoCommon/AsyncShaderCompiler.cpp
index 7e13168f69..7e6f960d7f 100644
--- a/Source/Core/VideoCommon/AsyncShaderCompiler.cpp
+++ b/Source/Core/VideoCommon/AsyncShaderCompiler.cpp
@@ -9,6 +9,8 @@
#include "Common/Logging/Log.h"
#include "Common/Thread.h"
+#include "Core/Core.h"
+
namespace VideoCommon
{
AsyncShaderCompiler::AsyncShaderCompiler()
@@ -65,17 +67,11 @@ bool AsyncShaderCompiler::HasCompletedWork()
return !m_completed_work.empty();
}
-void AsyncShaderCompiler::WaitUntilCompletion()
-{
- while (HasPendingWork())
- std::this_thread::sleep_for(std::chrono::milliseconds(1));
-}
-
-void AsyncShaderCompiler::WaitUntilCompletion(
+bool AsyncShaderCompiler::WaitUntilCompletion(
const std::function<void(size_t, size_t)>& progress_callback)
{
if (!HasPendingWork())
- return;
+ return true;
// Wait a second before opening a progress dialog.
// This way, if the operation completes quickly, we don't annoy the user.
@@ -85,11 +81,11 @@ void AsyncShaderCompiler::WaitUntilCompletion(
{
std::this_thread::sleep_for(std::chrono::milliseconds(CHECK_INTERVAL));
if (!HasPendingWork())
- return;
+ return true;
}
// Grab the number of pending items. We use this to work out how many are left.
- size_t total_items = 0;
+ size_t total_items;
{
// Safe to hold both locks here, since nowhere else does.
std::lock_guard<std::mutex> pending_guard(m_pending_work_lock);
@@ -100,6 +96,9 @@ void AsyncShaderCompiler::WaitUntilCompletion(
// Update progress while the compiles complete.
for (;;)
{
+ if (Core::GetState() == Core::State::Stopping)
+ return false;
+
size_t remaining_items;
{
std::lock_guard<std::mutex> pending_guard(m_pending_work_lock);
@@ -111,6 +110,7 @@ void AsyncShaderCompiler::WaitUntilCompletion(
progress_callback(total_items - remaining_items, total_items);
std::this_thread::sleep_for(CHECK_INTERVAL);
}
+ return true;
}
bool AsyncShaderCompiler::StartWorkerThreads(u32 num_worker_threads)