Skip to content
Permalink
Browse files
Merge pull request #10977 from tellowkrinkle/FixBackendMultithreading
VideoBackends:Vulkan: Improve backend multithreading
  • Loading branch information
JMC47 committed Oct 25, 2022
2 parents 9ef7a3b + 6fd9339 commit 027e104
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
@@ -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);
@@ -117,6 +117,7 @@ class CommandBufferManager
u64 fence_counter = 0;
bool init_command_buffer_used = false;
bool semaphore_used = false;
std::atomic<bool> waiting_for_submit{false};
u32 frame_index = 0;

std::vector<std::function<void()>> cleanup_resources;

0 comments on commit 027e104

Please sign in to comment.