summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar David Marcec2020-07-16 18:38:35 +1000
committerGravatar David Marcec2020-07-17 14:26:17 +1000
commitf48187449ed4772044da55a8a3745d578c1b8c48 (patch)
tree4dc7eea4e3e88b30b3b1af22326dc723811f2352
parentDrop max workers from 8->2 for testing (diff)
downloadyuzu-f48187449ed4772044da55a8a3745d578c1b8c48.tar.gz
yuzu-f48187449ed4772044da55a8a3745d578c1b8c48.tar.xz
yuzu-f48187449ed4772044da55a8a3745d578c1b8c48.zip
Use conditional var
Diffstat (limited to '')
-rw-r--r--src/video_core/shader/async_shaders.cpp14
-rw-r--r--src/video_core/shader/async_shaders.h10
2 files changed, 15 insertions, 9 deletions
diff --git a/src/video_core/shader/async_shaders.cpp b/src/video_core/shader/async_shaders.cpp
index fb94ac2e7..84d86c32f 100644
--- a/src/video_core/shader/async_shaders.cpp
+++ b/src/video_core/shader/async_shaders.cpp
@@ -59,7 +59,6 @@ void AsyncShaders::KillWorkers() {
59} 59}
60 60
61bool AsyncShaders::HasWorkQueued() { 61bool AsyncShaders::HasWorkQueued() {
62 std::shared_lock lock(queue_mutex);
63 return !pending_queue.empty(); 62 return !pending_queue.empty();
64} 63}
65 64
@@ -118,26 +117,31 @@ void AsyncShaders::QueueOpenGLShader(const OpenGL::Device& device,
118 cpu_addr}; 117 cpu_addr};
119 std::unique_lock lock(queue_mutex); 118 std::unique_lock lock(queue_mutex);
120 pending_queue.push_back(std::move(params)); 119 pending_queue.push_back(std::move(params));
120 cv.notify_one();
121} 121}
122 122
123void AsyncShaders::ShaderCompilerThread(Core::Frontend::GraphicsContext* context) { 123void AsyncShaders::ShaderCompilerThread(Core::Frontend::GraphicsContext* context) {
124 using namespace std::chrono_literals; 124 using namespace std::chrono_literals;
125 while (!is_thread_exiting.load(std::memory_order_relaxed)) { 125 while (!is_thread_exiting.load(std::memory_order_relaxed)) {
126 std::unique_lock<std::mutex> lock(queue_mutex);
127 cv.wait(lock, [&] { return HasWorkQueued() || is_thread_exiting; });
128 if (is_thread_exiting) {
129 return;
130 }
131
126 // Partial lock to allow all threads to read at the same time 132 // Partial lock to allow all threads to read at the same time
127 if (!HasWorkQueued()) { 133 if (!HasWorkQueued()) {
128 continue; 134 continue;
129 } 135 }
130 // Complete lock for pulling workload
131 queue_mutex.lock();
132 // Another thread beat us, just unlock and wait for the next load 136 // Another thread beat us, just unlock and wait for the next load
133 if (pending_queue.empty()) { 137 if (pending_queue.empty()) {
134 queue_mutex.unlock();
135 continue; 138 continue;
136 } 139 }
137 // Pull work from queue 140 // Pull work from queue
138 WorkerParams work = std::move(pending_queue.front()); 141 WorkerParams work = std::move(pending_queue.front());
139 pending_queue.pop_front(); 142 pending_queue.pop_front();
140 queue_mutex.unlock(); 143
144 lock.unlock();
141 145
142 if (work.backend == AsyncShaders::Backend::OpenGL || 146 if (work.backend == AsyncShaders::Backend::OpenGL ||
143 work.backend == AsyncShaders::Backend::GLASM) { 147 work.backend == AsyncShaders::Backend::GLASM) {
diff --git a/src/video_core/shader/async_shaders.h b/src/video_core/shader/async_shaders.h
index 26bc38326..2f5ee94ad 100644
--- a/src/video_core/shader/async_shaders.h
+++ b/src/video_core/shader/async_shaders.h
@@ -4,6 +4,7 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <condition_variable>
7#include <deque> 8#include <deque>
8#include <memory> 9#include <memory>
9#include <shared_mutex> 10#include <shared_mutex>
@@ -59,9 +60,6 @@ public:
59 // Force end all threads 60 // Force end all threads
60 void KillWorkers(); 61 void KillWorkers();
61 62
62 /// Check our worker queue to see if we have any work queued already
63 bool HasWorkQueued();
64
65 /// Check to see if any shaders have actually been compiled 63 /// Check to see if any shaders have actually been compiled
66 bool HasCompletedWork(); 64 bool HasCompletedWork();
67 65
@@ -81,6 +79,9 @@ public:
81private: 79private:
82 void ShaderCompilerThread(Core::Frontend::GraphicsContext* context); 80 void ShaderCompilerThread(Core::Frontend::GraphicsContext* context);
83 81
82 /// Check our worker queue to see if we have any work queued already
83 bool HasWorkQueued();
84
84 struct WorkerParams { 85 struct WorkerParams {
85 AsyncShaders::Backend backend; 86 AsyncShaders::Backend backend;
86 OpenGL::Device device; 87 OpenGL::Device device;
@@ -94,7 +95,8 @@ private:
94 VAddr cpu_address; 95 VAddr cpu_address;
95 }; 96 };
96 97
97 std::shared_mutex queue_mutex; 98 std::condition_variable cv;
99 std::mutex queue_mutex;
98 std::shared_mutex completed_mutex; 100 std::shared_mutex completed_mutex;
99 std::atomic<bool> is_thread_exiting{}; 101 std::atomic<bool> is_thread_exiting{};
100 std::vector<std::unique_ptr<Core::Frontend::GraphicsContext>> context_list; 102 std::vector<std::unique_ptr<Core::Frontend::GraphicsContext>> context_list;