1
0
mirror of https://github.com/EduApps-CDG/OpenDX synced 2024-12-30 09:45:37 +01:00
OpenDX/src/dxvk/dxvk_pipecompiler.cpp
Philip Rebohle 7f619d9051 [dxvk] Use only one extra thread for async pipeline compilation
With the benefits of asynchronous compilation being generally low and
compilation in advance not being feasible, there is no reason to create
more threads.
2018-05-22 00:32:44 +02:00

70 lines
1.9 KiB
C++

#include "dxvk_graphics.h"
#include "dxvk_pipecompiler.h"
namespace dxvk {
DxvkPipelineCompiler::DxvkPipelineCompiler() {
constexpr uint32_t threadCount = 1u;
Logger::debug(str::format(
"DxvkPipelineCompiler: Using ", threadCount, " workers"));
// Start the compiler threads
m_compilerThreads.resize(threadCount);
for (uint32_t i = 0; i < threadCount; i++) {
m_compilerThreads.at(i) = std::thread(
[this, i] { this->runCompilerThread(i); });
}
}
DxvkPipelineCompiler::~DxvkPipelineCompiler() {
{ std::unique_lock<std::mutex> lock(m_compilerLock);
m_compilerStop.store(true);
}
m_compilerCond.notify_all();
for (auto& thread : m_compilerThreads)
thread.join();
}
void DxvkPipelineCompiler::queueCompilation(
const Rc<DxvkGraphicsPipeline>& pipeline,
const Rc<DxvkGraphicsPipelineInstance>& instance) {
std::unique_lock<std::mutex> lock(m_compilerLock);
m_compilerQueue.push({ pipeline, instance });
m_compilerCond.notify_one();
}
void DxvkPipelineCompiler::runCompilerThread(uint32_t workerId) {
Logger::debug(str::format(
"DxvkPipelineCompiler: Worker #", workerId, " started"));
while (!m_compilerStop.load()) {
PipelineEntry entry;
{ std::unique_lock<std::mutex> lock(m_compilerLock);
m_compilerCond.wait(lock, [this] {
return m_compilerStop.load()
|| m_compilerQueue.size() != 0;
});
if (m_compilerQueue.size() != 0) {
entry = std::move(m_compilerQueue.front());
m_compilerQueue.pop();
}
}
if (entry.pipeline != nullptr && entry.instance != nullptr)
entry.pipeline->compileInstance(entry.instance);
}
Logger::debug(str::format(
"DxvkPipelineCompiler: Worker #", workerId, " stopped"));
}
}