1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-11-29 19:24:10 +01:00

[dxvk] Added DxvkPipelineCompiler

This commit is contained in:
Philip Rebohle 2018-05-10 14:29:13 +02:00
parent 3b132196d3
commit 517a7532be
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
3 changed files with 121 additions and 0 deletions

View File

@ -0,0 +1,65 @@
#include "dxvk_pipecompiler.h"
namespace dxvk {
DxvkPipelineCompiler::DxvkPipelineCompiler() {
// Use ~half the CPU cores for pipeline compilation
const uint32_t threadCount = std::max<uint32_t>(
1u, std::thread::hardware_concurrency() / 2);
Logger::debug(str::format(
"DxvkPipelineCompiler: Using ", threadCount, " threads"));
// Start the compiler threads
m_compilerThreads.resize(threadCount);
for (uint32_t i = 0; i < threadCount; i++) {
m_compilerThreads.at(i) = std::thread(
[this] { this->runCompilerThread(); });
}
}
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() {
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);
}
}
}

View File

@ -0,0 +1,55 @@
#pragma once
#include <atomic>
#include <condition_variable>
#include <mutex>
#include <queue>
#include <thread>
#include "dxvk_graphics.h"
namespace dxvk {
/**
* \brief Pipeline compiler
*
* asynchronous pipeline compiler, which is used
* to compile optimized versions of pipelines.
*/
class DxvkPipelineCompiler : public RcObject {
public:
DxvkPipelineCompiler();
~DxvkPipelineCompiler();
/**
* \brief Compiles a pipeline asynchronously
*
* This should be used to compile optimized
* graphics pipeline instances asynchronously.
* \param [in] pipeline The pipeline object
* \param [in] instance The pipeline instance
*/
void queueCompilation(
const Rc<DxvkGraphicsPipeline>& pipeline,
const Rc<DxvkGraphicsPipelineInstance>& instance);
private:
struct PipelineEntry {
Rc<DxvkGraphicsPipeline> pipeline;
Rc<DxvkGraphicsPipelineInstance> instance;
};
std::atomic<bool> m_compilerStop = { false };
std::mutex m_compilerLock;
std::condition_variable m_compilerCond;
std::queue<PipelineEntry> m_compilerQueue;
std::vector<std::thread> m_compilerThreads;
void runCompilerThread();
};
}

View File

@ -43,6 +43,7 @@ dxvk_src = files([
'dxvk_meta_clear.cpp',
'dxvk_meta_resolve.cpp',
'dxvk_pipecache.cpp',
'dxvk_pipecompiler.cpp',
'dxvk_pipelayout.cpp',
'dxvk_pipemanager.cpp',
'dxvk_query.cpp',