VideoBackends:Vulkan: Clean up submission thread BlockingLoop usage

This commit is contained in:
Robin Kertels 2023-01-07 23:52:36 +01:00
parent 002a96adb0
commit 9186050daa
No known key found for this signature in database
GPG Key ID: 3824904F14D40757
2 changed files with 18 additions and 31 deletions

View File

@ -226,33 +226,25 @@ bool CommandBufferManager::CreateSubmitThread()
Common::SetCurrentThreadName("Vulkan CommandBufferManager SubmitThread");
m_submit_loop->Run([this]() {
PendingCommandBufferSubmit submit;
while (true)
{
std::lock_guard<std::mutex> guard(m_pending_submit_lock);
if (m_pending_submits.empty())
PendingCommandBufferSubmit submit;
{
m_submit_loop->AllowSleep();
m_submit_worker_idle = true;
m_submit_worker_condvar.notify_all();
return;
std::lock_guard<std::mutex> guard(m_pending_submit_lock);
if (m_pending_submits.empty())
{
m_submit_loop->AllowSleep();
return;
}
submit = m_pending_submits.front();
m_pending_submits.pop_front();
}
submit = m_pending_submits.front();
m_pending_submits.pop_front();
}
SubmitCommandBuffer(submit.command_buffer_index, submit.present_swap_chain,
submit.present_image_index);
CmdBufferResources& resources = m_command_buffers[submit.command_buffer_index];
resources.waiting_for_submit.store(false, std::memory_order_release);
{
std::lock_guard<std::mutex> guard(m_pending_submit_lock);
if (m_pending_submits.empty())
{
m_submit_worker_idle = true;
m_submit_worker_condvar.notify_all();
}
SubmitCommandBuffer(submit.command_buffer_index, submit.present_swap_chain,
submit.present_image_index);
CmdBufferResources& resources = m_command_buffers[submit.command_buffer_index];
resources.waiting_for_submit.store(false, std::memory_order_release);
}
});
});
@ -265,8 +257,7 @@ void CommandBufferManager::WaitForWorkerThreadIdle()
if (!m_use_threaded_submission)
return;
std::unique_lock lock{m_pending_submit_lock};
m_submit_worker_condvar.wait(lock, [&] { return m_submit_worker_idle; });
m_submit_loop->Wait();
}
void CommandBufferManager::WaitForFenceCounter(u64 fence_counter)
@ -354,12 +345,10 @@ void CommandBufferManager::SubmitCommandBuffer(bool submit_on_worker_thread,
// Push to the pending submit queue.
{
std::lock_guard<std::mutex> guard(m_pending_submit_lock);
m_submit_worker_idle = false;
m_pending_submits.push_back({present_swap_chain, present_image_index, m_current_cmd_buffer});
// Wake up the worker thread for a single iteration.
m_submit_loop->Wakeup();
}
// Wake up the worker thread for a single iteration.
m_submit_loop->Wakeup();
}
else
{

View File

@ -157,8 +157,6 @@ private:
VkSemaphore m_present_semaphore = VK_NULL_HANDLE;
std::deque<PendingCommandBufferSubmit> m_pending_submits;
std::mutex m_pending_submit_lock;
std::condition_variable m_submit_worker_condvar;
bool m_submit_worker_idle = true;
Common::Flag m_last_present_failed;
Common::Flag m_last_present_done;
VkResult m_last_present_result = VK_SUCCESS;