From 3fd6eeaf9fb42c942ffbc2a60a50dd8ebfd8dfee Mon Sep 17 00:00:00 2001 From: lizzie Date: Thu, 9 Jul 2026 19:02:26 +0200 Subject: Revert #3970 #4177 (#4187) 3970 revert fixes crash caused by scheduler 4177 fix mario galaxy and metroid prime 4 not booting Co-authored-by: CamilleLaVey Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4187 Reviewed-by: MaranBr --- src/video_core/renderer_vulkan/vk_scheduler.cpp | 105 ++++++++++++------------ 1 file changed, 54 insertions(+), 51 deletions(-) (limited to 'src/video_core/renderer_vulkan/vk_scheduler.cpp') diff --git a/src/video_core/renderer_vulkan/vk_scheduler.cpp b/src/video_core/renderer_vulkan/vk_scheduler.cpp index 48268df708..3bf7a9ac78 100644 --- a/src/video_core/renderer_vulkan/vk_scheduler.cpp +++ b/src/video_core/renderer_vulkan/vk_scheduler.cpp @@ -60,57 +60,7 @@ Scheduler::Scheduler(const Device& device_, StateTracker& state_tracker_) AcquireNewChunk(); AllocateWorkerCommandBuffer(); - worker_thread = std::jthread([this](std::stop_token stop_token) { - Common::SetCurrentThreadName("VulkanWorker"); - const auto TryPopQueue{[this](auto& work) -> bool { - if (work_queue.empty()) { - return false; - } - - work = std::move(work_queue.front()); - work_queue.pop(); - event_cv.notify_all(); - return true; - }}; - - while (!stop_token.stop_requested()) { - std::unique_ptr work; - - { - std::unique_lock lk{queue_mutex}; - - // Wait for work. - event_cv.wait(lk, stop_token, [&] { return TryPopQueue(work); }); - - // If we've been asked to stop, we're done. - if (stop_token.stop_requested()) { - return; - } - - // Exchange lock ownership so that we take the execution lock before - // the queue lock goes out of scope. This allows us to force execution - // to complete in the next step. - std::exchange(lk, std::unique_lock{execution_mutex}); - - // Perform the work, tracking whether the chunk was a submission - // before executing. - const bool has_submit = work->HasSubmit(); - work->ExecuteAll(current_cmdbuf, current_upload_cmdbuf); - - // If the chunk was a submission, reallocate the command buffer. - if (has_submit) { - AllocateWorkerCommandBuffer(); - } - } - - { - std::scoped_lock rl{reserve_mutex}; - - // Recycle the chunk back to the reserve. - chunk_reserve.emplace_back(std::move(work)); - } - } - }); + worker_thread = std::jthread([this](std::stop_token token) { WorkerThread(token); }); } Scheduler::~Scheduler() = default; @@ -248,6 +198,59 @@ bool Scheduler::UpdateRescaling(bool is_rescaling) { return true; } +void Scheduler::WorkerThread(std::stop_token stop_token) { + Common::SetCurrentThreadName("VulkanWorker"); + + const auto TryPopQueue{[this](auto& work) -> bool { + if (work_queue.empty()) { + return false; + } + + work = std::move(work_queue.front()); + work_queue.pop(); + event_cv.notify_all(); + return true; + }}; + + while (!stop_token.stop_requested()) { + std::unique_ptr work; + + { + std::unique_lock lk{queue_mutex}; + + // Wait for work. + event_cv.wait(lk, stop_token, [&] { return TryPopQueue(work); }); + + // If we've been asked to stop, we're done. + if (stop_token.stop_requested()) { + return; + } + + // Exchange lock ownership so that we take the execution lock before + // the queue lock goes out of scope. This allows us to force execution + // to complete in the next step. + std::exchange(lk, std::unique_lock{execution_mutex}); + + // Perform the work, tracking whether the chunk was a submission + // before executing. + const bool has_submit = work->HasSubmit(); + work->ExecuteAll(current_cmdbuf, current_upload_cmdbuf); + + // If the chunk was a submission, reallocate the command buffer. + if (has_submit) { + AllocateWorkerCommandBuffer(); + } + } + + { + std::scoped_lock rl{reserve_mutex}; + + // Recycle the chunk back to the reserve. + chunk_reserve.emplace_back(std::move(work)); + } + } +} + void Scheduler::AllocateWorkerCommandBuffer() { current_cmdbuf = vk::CommandBuffer(command_pool->Commit(), device.GetDispatchLoader()); current_cmdbuf.Begin({ -- cgit v1.2.3