summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/Vulkan/CommandBufferManager.cpp
diff options
context:
space:
mode:
authorTellowKrinkle <tellowkrinkle@gmail.com>2022-08-10 23:46:36 -0500
committerTellowKrinkle <tellowkrinkle@gmail.com>2022-10-17 00:05:35 -0500
commit6fd933915bb21bd487c8e9dd8481e8e05b4c0011 (patch)
tree4b2abad1e963ba8c986a80479a026a267b5f1794 /Source/Core/VideoBackends/Vulkan/CommandBufferManager.cpp
parent10f973a87f921d277a7a9514f2a5dd59d04b7ca6 (diff)
VideoBackends:Vulkan: Improve backend multithreading
Makes the multiple threads actually able to run at the same time
Diffstat (limited to 'Source/Core/VideoBackends/Vulkan/CommandBufferManager.cpp')
-rw-r--r--Source/Core/VideoBackends/Vulkan/CommandBufferManager.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/Source/Core/VideoBackends/Vulkan/CommandBufferManager.cpp b/Source/Core/VideoBackends/Vulkan/CommandBufferManager.cpp
index d8ef681b56..5c1df797c0 100644
--- a/Source/Core/VideoBackends/Vulkan/CommandBufferManager.cpp
+++ b/Source/Core/VideoBackends/Vulkan/CommandBufferManager.cpp
@@ -239,6 +239,8 @@ bool CommandBufferManager::CreateSubmitThread()
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);
@@ -284,11 +286,16 @@ void CommandBufferManager::WaitForFenceCounter(u64 fence_counter)
void CommandBufferManager::WaitForCommandBufferCompletion(u32 index)
{
- // Ensure this command buffer has been submitted.
- WaitForWorkerThreadIdle();
-
CmdBufferResources& resources = m_command_buffers[index];
+ // Ensure this command buffer has been submitted.
+ if (resources.waiting_for_submit.load(std::memory_order_acquire))
+ {
+ WaitForWorkerThreadIdle();
+ ASSERT_MSG(VIDEO, !resources.waiting_for_submit.load(std::memory_order_relaxed),
+ "Submit thread is idle but command buffer is still waiting for submission!");
+ }
+
// Wait for this command buffer to be completed.
VkResult res =
vkWaitForFences(g_vulkan_context->GetDevice(), 1, &resources.fence, VK_TRUE, UINT64_MAX);
@@ -339,6 +346,7 @@ void CommandBufferManager::SubmitCommandBuffer(bool submit_on_worker_thread,
// Submitting off-thread?
if (m_use_threaded_submission && submit_on_worker_thread && !wait_for_completion)
{
+ resources.waiting_for_submit.store(true, std::memory_order_relaxed);
// Push to the pending submit queue.
{
std::lock_guard<std::mutex> guard(m_pending_submit_lock);