summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorRobin Kertels <robin.kertels@gmail.com>2023-01-27 15:06:35 +0100
committerRobin Kertels <robin.kertels@gmail.com>2023-03-20 16:40:32 +0100
commitc1be9628fc1237ffbae14f2d1a15ed1895be2eda (patch)
tree243f160f232846a32f45a61b554890600b59119f /Source
parent9d422d14d501df6ca3876ac500056dad923f4537 (diff)
VideoBackends:Vulkan: Use WorkQueueThread
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/VideoBackends/Vulkan/CommandBufferManager.cpp43
-rw-r--r--Source/Core/VideoBackends/Vulkan/CommandBufferManager.h6
2 files changed, 10 insertions, 39 deletions
diff --git a/Source/Core/VideoBackends/Vulkan/CommandBufferManager.cpp b/Source/Core/VideoBackends/Vulkan/CommandBufferManager.cpp
index 9c460905f7..be02034f67 100644
--- a/Source/Core/VideoBackends/Vulkan/CommandBufferManager.cpp
+++ b/Source/Core/VideoBackends/Vulkan/CommandBufferManager.cpp
@@ -26,8 +26,7 @@ CommandBufferManager::~CommandBufferManager()
if (m_use_threaded_submission)
{
WaitForWorkerThreadIdle();
- m_submit_loop->Stop();
- m_submit_thread.join();
+ m_submit_thread.Shutdown();
}
DestroyCommandBuffers();
@@ -221,32 +220,11 @@ VkDescriptorSet CommandBufferManager::AllocateDescriptorSet(VkDescriptorSetLayou
bool CommandBufferManager::CreateSubmitThread()
{
- m_submit_loop = std::make_unique<Common::BlockingLoop>();
- m_submit_thread = std::thread([this]() {
- Common::SetCurrentThreadName("Vulkan CommandBufferManager SubmitThread");
-
- m_submit_loop->Run([this]() {
- while (true)
- {
- PendingCommandBufferSubmit submit;
- {
- 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();
- }
-
- 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);
- }
- });
+ m_submit_thread.Reset("VK submission thread", [this](PendingCommandBufferSubmit submit) {
+ 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);
});
return true;
@@ -257,7 +235,7 @@ void CommandBufferManager::WaitForWorkerThreadIdle()
if (!m_use_threaded_submission)
return;
- m_submit_loop->Wait();
+ m_submit_thread.WaitForCompletion();
}
void CommandBufferManager::WaitForFenceCounter(u64 fence_counter)
@@ -343,12 +321,7 @@ void CommandBufferManager::SubmitCommandBuffer(bool submit_on_worker_thread,
{
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);
- 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();
- }
+ m_submit_thread.Push({present_swap_chain, present_image_index, m_current_cmd_buffer});
}
else
{
diff --git a/Source/Core/VideoBackends/Vulkan/CommandBufferManager.h b/Source/Core/VideoBackends/Vulkan/CommandBufferManager.h
index 398f56e4ce..0249097423 100644
--- a/Source/Core/VideoBackends/Vulkan/CommandBufferManager.h
+++ b/Source/Core/VideoBackends/Vulkan/CommandBufferManager.h
@@ -14,6 +14,7 @@
#include <utility>
#include <vector>
+#include <Common/WorkQueueThread.h>
#include "Common/BlockingLoop.h"
#include "Common/Flag.h"
#include "Common/Semaphore.h"
@@ -146,17 +147,14 @@ private:
u32 m_current_cmd_buffer = 0;
// Threaded command buffer execution
- std::thread m_submit_thread;
- std::unique_ptr<Common::BlockingLoop> m_submit_loop;
struct PendingCommandBufferSubmit
{
VkSwapchainKHR present_swap_chain;
u32 present_image_index;
u32 command_buffer_index;
};
+ Common::WorkQueueThread<PendingCommandBufferSubmit> m_submit_thread;
VkSemaphore m_present_semaphore = VK_NULL_HANDLE;
- std::deque<PendingCommandBufferSubmit> m_pending_submits;
- std::mutex m_pending_submit_lock;
Common::Flag m_last_present_failed;
Common::Flag m_last_present_done;
VkResult m_last_present_result = VK_SUCCESS;