Skip to content

Commit

Permalink
VideoBackends:Vulkan: Clean up submission thread BlockingLoop usage
Browse files Browse the repository at this point in the history
  • Loading branch information
K0bin committed Jan 7, 2023
1 parent dcded04 commit 56d14f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 31 deletions.
47 changes: 18 additions & 29 deletions Source/Core/VideoBackends/Vulkan/CommandBufferManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,33 +222,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);
}
});
});
Expand All @@ -261,8 +253,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)
Expand Down Expand Up @@ -350,12 +341,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
{
Expand Down
2 changes: 0 additions & 2 deletions Source/Core/VideoBackends/Vulkan/CommandBufferManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ class CommandBufferManager
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;
Expand Down

0 comments on commit 56d14f8

Please sign in to comment.