diff options
| author | Stenzek <stenzek@gmail.com> | 2017-07-27 13:15:38 +1000 |
|---|---|---|
| committer | Stenzek <stenzek@gmail.com> | 2017-07-30 17:43:59 +1000 |
| commit | c8f31656cb1c5f5e3c83a5b977fd822e987cb596 (patch) | |
| tree | 533941c3211604f5550bffb9b56930c141efd6ae /Source/Core/VideoCommon/AsyncShaderCompiler.cpp | |
| parent | e17efb1d8dcff32e7db915a53dc95df0bf329692 (diff) | |
VideoBackends: Support a different number of threads for precompiling
At runtime, we only really want a single shader compiler thread.
However, for initial boots, we can use a higher number to speed things
up.
Diffstat (limited to 'Source/Core/VideoCommon/AsyncShaderCompiler.cpp')
| -rw-r--r-- | Source/Core/VideoCommon/AsyncShaderCompiler.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/Source/Core/VideoCommon/AsyncShaderCompiler.cpp b/Source/Core/VideoCommon/AsyncShaderCompiler.cpp index 15eececc4c..59ef9762f1 100644 --- a/Source/Core/VideoCommon/AsyncShaderCompiler.cpp +++ b/Source/Core/VideoCommon/AsyncShaderCompiler.cpp @@ -106,8 +106,11 @@ void AsyncShaderCompiler::WaitUntilCompletion( } } -void AsyncShaderCompiler::StartWorkerThreads(u32 num_worker_threads) +bool AsyncShaderCompiler::StartWorkerThreads(u32 num_worker_threads) { + if (num_worker_threads == 0) + return true; + for (u32 i = 0; i < num_worker_threads; i++) { void* thread_param = nullptr; @@ -131,6 +134,17 @@ void AsyncShaderCompiler::StartWorkerThreads(u32 num_worker_threads) m_worker_threads.push_back(std::move(thr)); } + + return HasWorkerThreads(); +} + +bool AsyncShaderCompiler::ResizeWorkerThreads(u32 num_worker_threads) +{ + if (m_worker_threads.size() == num_worker_threads) + return true; + + StopWorkerThreads(); + return StartWorkerThreads(num_worker_threads); } bool AsyncShaderCompiler::HasWorkerThreads() const @@ -140,6 +154,9 @@ bool AsyncShaderCompiler::HasWorkerThreads() const void AsyncShaderCompiler::StopWorkerThreads() { + if (!HasWorkerThreads()) + return; + // Signal worker threads to stop, and wake all of them. { std::lock_guard<std::mutex> guard(m_pending_work_lock); @@ -151,6 +168,7 @@ void AsyncShaderCompiler::StopWorkerThreads() for (std::thread& thr : m_worker_threads) thr.join(); m_worker_threads.clear(); + m_exit_flag.Clear(); } bool AsyncShaderCompiler::WorkerThreadInitMainThread(void** param) |
