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

View File

@ -157,8 +157,6 @@ private:
VkSemaphore m_present_semaphore = VK_NULL_HANDLE; VkSemaphore m_present_semaphore = VK_NULL_HANDLE;
std::deque<PendingCommandBufferSubmit> m_pending_submits; std::deque<PendingCommandBufferSubmit> m_pending_submits;
std::mutex m_pending_submit_lock; 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_failed;
Common::Flag m_last_present_done; Common::Flag m_last_present_done;
VkResult m_last_present_result = VK_SUCCESS; VkResult m_last_present_result = VK_SUCCESS;