1
0
mirror of https://github.com/EduApps-CDG/OpenDX synced 2024-12-30 09:45:37 +01:00
OpenDX/src/dxvk/dxvk_queue.cpp
Philip Rebohle 1fe5b74762 Optimized command submission
Command submission now does not synchronize with the device every single
time. Instead, the command list and the fence that was created for it are
added to a queue. A separate thread will then wait for the execution to
complete and return the command list to the device.
2017-12-16 18:10:55 +01:00

62 lines
1.4 KiB
C++

#include "dxvk_device.h"
#include "dxvk_queue.h"
namespace dxvk {
DxvkSubmissionQueue::DxvkSubmissionQueue(DxvkDevice* device)
: m_device(device),
m_thread([this] () { this->threadFunc(); }) {
}
DxvkSubmissionQueue::~DxvkSubmissionQueue() {
m_stopped.store(true);
m_condOnAdd.notify_one();
m_thread.join();
}
void DxvkSubmissionQueue::submit(
const Rc<DxvkFence>& fence,
const Rc<DxvkCommandList>& cmdList) {
{ std::unique_lock<std::mutex> lock(m_mutex);
m_condOnTake.wait(lock, [this] {
return m_entries.size() < 4;
});
m_entries.push({ fence, cmdList });
}
m_condOnAdd.notify_one();
}
void DxvkSubmissionQueue::threadFunc() {
while (!m_stopped.load()) {
Entry entry;
{ std::unique_lock<std::mutex> lock(m_mutex);
m_condOnAdd.wait(lock, [this] {
return m_stopped.load() || (m_entries.size() != 0);
});
if (m_entries.size() != 0) {
entry = std::move(m_entries.front());
m_entries.pop();
}
}
m_condOnTake.notify_one();
if (entry.fence != nullptr) {
entry.fence->wait(std::numeric_limits<uint64_t>::max());
entry.cmdList->reset();
m_device->recycleCommandList(entry.cmdList);
}
}
}
}