summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp10
-rw-r--r--src/video_core/renderer_vulkan/vk_rasterizer.cpp12
-rw-r--r--src/video_core/shader/async_shaders.cpp13
-rw-r--r--src/video_core/shader/async_shaders.h2
4 files changed, 14 insertions, 23 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index cb284db77..4af5824cd 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -177,15 +177,7 @@ RasterizerOpenGL::RasterizerOpenGL(Core::System& system, Core::Frontend::EmuWind
177 } 177 }
178 178
179 if (device.UseAsynchronousShaders()) { 179 if (device.UseAsynchronousShaders()) {
180 // Max worker threads we should allow 180 async_shaders.AllocateWorkers();
181 constexpr u32 MAX_THREADS = 4;
182 // Deduce how many threads we can use
183 const u32 threads_used = std::thread::hardware_concurrency() / 4;
184 // Always allow at least 1 thread regardless of our settings
185 const auto max_worker_count = std::max(1U, threads_used);
186 // Don't use more than MAX_THREADS
187 const auto worker_count = std::min(max_worker_count, MAX_THREADS);
188 async_shaders.AllocateWorkers(worker_count);
189 } 181 }
190} 182}
191 183
diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp
index 720802ad5..936f76195 100644
--- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp
+++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp
@@ -405,17 +405,7 @@ RasterizerVulkan::RasterizerVulkan(Core::System& system, Core::Frontend::EmuWind
405 wfi_event{device.GetLogical().CreateNewEvent()}, async_shaders{renderer} { 405 wfi_event{device.GetLogical().CreateNewEvent()}, async_shaders{renderer} {
406 scheduler.SetQueryCache(query_cache); 406 scheduler.SetQueryCache(query_cache);
407 if (device.UseAsynchronousShaders()) { 407 if (device.UseAsynchronousShaders()) {
408 // The following is subject to move into the allocate workers method, to be api agnostic 408 async_shaders.AllocateWorkers();
409
410 // Max worker threads we should allow
411 constexpr u32 MAX_THREADS = 4;
412 // Deduce how many threads we can use
413 const auto threads_used = std::thread::hardware_concurrency() / 4;
414 // Always allow at least 1 thread regardless of our settings
415 const auto max_worker_count = std::max(1U, threads_used);
416 // Don't use more than MAX_THREADS
417 const auto worker_count = std::min(max_worker_count, MAX_THREADS);
418 async_shaders.AllocateWorkers(worker_count);
419 } 409 }
420} 410}
421 411
diff --git a/src/video_core/shader/async_shaders.cpp b/src/video_core/shader/async_shaders.cpp
index ea813d506..6a1b8999c 100644
--- a/src/video_core/shader/async_shaders.cpp
+++ b/src/video_core/shader/async_shaders.cpp
@@ -19,9 +19,18 @@ AsyncShaders::~AsyncShaders() {
19 KillWorkers(); 19 KillWorkers();
20} 20}
21 21
22void AsyncShaders::AllocateWorkers(std::size_t num_workers) { 22void AsyncShaders::AllocateWorkers() {
23 // Max worker threads we should allow
24 constexpr u32 MAX_THREADS = 4;
25 // Deduce how many threads we can use
26 const u32 threads_used = std::thread::hardware_concurrency() / 4;
27 // Always allow at least 1 thread regardless of our settings
28 const auto max_worker_count = std::max(1U, threads_used);
29 // Don't use more than MAX_THREADS
30 const auto num_workers = std::min(max_worker_count, MAX_THREADS);
31
23 // If we're already have workers queued or don't want to queue workers, ignore 32 // If we're already have workers queued or don't want to queue workers, ignore
24 if (num_workers == worker_threads.size() || num_workers == 0) { 33 if (num_workers == worker_threads.size()) {
25 return; 34 return;
26 } 35 }
27 36
diff --git a/src/video_core/shader/async_shaders.h b/src/video_core/shader/async_shaders.h
index 7c10bd63f..5b58dd9bd 100644
--- a/src/video_core/shader/async_shaders.h
+++ b/src/video_core/shader/async_shaders.h
@@ -62,7 +62,7 @@ public:
62 ~AsyncShaders(); 62 ~AsyncShaders();
63 63
64 /// Start up shader worker threads 64 /// Start up shader worker threads
65 void AllocateWorkers(std::size_t num_workers); 65 void AllocateWorkers();
66 66
67 /// Clear the shader queue and kill all worker threads 67 /// Clear the shader queue and kill all worker threads
68 void FreeWorkers(); 68 void FreeWorkers();