summaryrefslogtreecommitdiffstats
path: root/src/video_core/renderer_vulkan
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2021-09-19 05:37:40 +0200
committerGitHub <noreply@github.com>2021-09-19 05:37:40 +0200
commita9c3619d26beaaae338c5e902635147b9237350a (patch)
treeb86f29a288fa5bc5a337ba61a6833fa1c89c2270 /src/video_core/renderer_vulkan
parentMerge pull request #6485 from MonsterDruide1/tas (diff)
parentvk_scheduler: Use std::jthread (diff)
downloadyuzu-a9c3619d26beaaae338c5e902635147b9237350a.tar
yuzu-a9c3619d26beaaae338c5e902635147b9237350a.tar.gz
yuzu-a9c3619d26beaaae338c5e902635147b9237350a.tar.bz2
yuzu-a9c3619d26beaaae338c5e902635147b9237350a.tar.lz
yuzu-a9c3619d26beaaae338c5e902635147b9237350a.tar.xz
yuzu-a9c3619d26beaaae338c5e902635147b9237350a.tar.zst
yuzu-a9c3619d26beaaae338c5e902635147b9237350a.zip
Diffstat (limited to 'src/video_core/renderer_vulkan')
-rw-r--r--src/video_core/renderer_vulkan/vk_scheduler.cpp19
-rw-r--r--src/video_core/renderer_vulkan/vk_scheduler.h7
2 files changed, 9 insertions, 17 deletions
diff --git a/src/video_core/renderer_vulkan/vk_scheduler.cpp b/src/video_core/renderer_vulkan/vk_scheduler.cpp
index 1d438787a..0c11c814f 100644
--- a/src/video_core/renderer_vulkan/vk_scheduler.cpp
+++ b/src/video_core/renderer_vulkan/vk_scheduler.cpp
@@ -43,17 +43,10 @@ VKScheduler::VKScheduler(const Device& device_, StateTracker& state_tracker_)
command_pool{std::make_unique<CommandPool>(*master_semaphore, device)} {
AcquireNewChunk();
AllocateWorkerCommandBuffer();
- worker_thread = std::thread(&VKScheduler::WorkerThread, this);
+ worker_thread = std::jthread([this](std::stop_token token) { WorkerThread(token); });
}
-VKScheduler::~VKScheduler() {
- {
- std::lock_guard lock{work_mutex};
- quit = true;
- }
- work_cv.notify_all();
- worker_thread.join();
-}
+VKScheduler::~VKScheduler() = default;
void VKScheduler::Flush(VkSemaphore signal_semaphore, VkSemaphore wait_semaphore) {
SubmitExecution(signal_semaphore, wait_semaphore);
@@ -135,7 +128,7 @@ bool VKScheduler::UpdateGraphicsPipeline(GraphicsPipeline* pipeline) {
return true;
}
-void VKScheduler::WorkerThread() {
+void VKScheduler::WorkerThread(std::stop_token stop_token) {
Common::SetCurrentThreadName("yuzu:VulkanWorker");
do {
if (work_queue.empty()) {
@@ -144,8 +137,8 @@ void VKScheduler::WorkerThread() {
std::unique_ptr<CommandChunk> work;
{
std::unique_lock lock{work_mutex};
- work_cv.wait(lock, [this] { return !work_queue.empty() || quit; });
- if (quit) {
+ work_cv.wait(lock, stop_token, [this] { return !work_queue.empty(); });
+ if (stop_token.stop_requested()) {
continue;
}
work = std::move(work_queue.front());
@@ -158,7 +151,7 @@ void VKScheduler::WorkerThread() {
}
std::lock_guard reserve_lock{reserve_mutex};
chunk_reserve.push_back(std::move(work));
- } while (!quit);
+ } while (!stop_token.stop_requested());
}
void VKScheduler::AllocateWorkerCommandBuffer() {
diff --git a/src/video_core/renderer_vulkan/vk_scheduler.h b/src/video_core/renderer_vulkan/vk_scheduler.h
index 759ed5a48..bd22e4e83 100644
--- a/src/video_core/renderer_vulkan/vk_scheduler.h
+++ b/src/video_core/renderer_vulkan/vk_scheduler.h
@@ -187,7 +187,7 @@ private:
GraphicsPipeline* graphics_pipeline = nullptr;
};
- void WorkerThread();
+ void WorkerThread(std::stop_token stop_token);
void AllocateWorkerCommandBuffer();
@@ -212,7 +212,7 @@ private:
vk::CommandBuffer current_cmdbuf;
std::unique_ptr<CommandChunk> chunk;
- std::thread worker_thread;
+ std::jthread worker_thread;
State state;
@@ -224,9 +224,8 @@ private:
std::vector<std::unique_ptr<CommandChunk>> chunk_reserve;
std::mutex reserve_mutex;
std::mutex work_mutex;
- std::condition_variable work_cv;
+ std::condition_variable_any work_cv;
std::condition_variable wait_cv;
- std::atomic_bool quit{};
};
} // namespace Vulkan