From b26e0cfa91f249a4ab9cda97359bd43fa0b33cda Mon Sep 17 00:00:00 2001 From: kd-11 Date: Tue, 6 Oct 2026 21:20:19 +0300 Subject: [PATCH] vk: Pause the driver manager routine when capturing media - These are out-of-band events and should not be treated as 'real' sync points. --- rpcs3/Emu/RSX/VK/VKCommandStream.cpp | 11 +++++++++++ rpcs3/Emu/RSX/VK/VKCommandStream.h | 4 ++++ rpcs3/Emu/RSX/VK/VKPresent.cpp | 10 +++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/rpcs3/Emu/RSX/VK/VKCommandStream.cpp b/rpcs3/Emu/RSX/VK/VKCommandStream.cpp index 4925d8830f..c33ad4c762 100644 --- a/rpcs3/Emu/RSX/VK/VKCommandStream.cpp +++ b/rpcs3/Emu/RSX/VK/VKCommandStream.cpp @@ -96,6 +96,12 @@ namespace vk void driver_manager_t::notify_completed(u64 eid) { + if (!m_enabled) + { + // Do not wake + return; + } + m_eid_ctr.atomic_op([eid](u64& value) { value = std::max(value, eid); @@ -133,4 +139,9 @@ namespace vk thread_ctrl::wait_on(m_completed_signal, completion_token); } } + + void driver_manager_t::set_enabled(bool state) + { + m_enabled.store(state); + } } diff --git a/rpcs3/Emu/RSX/VK/VKCommandStream.h b/rpcs3/Emu/RSX/VK/VKCommandStream.h index 72c0fee56b..444e1619bc 100644 --- a/rpcs3/Emu/RSX/VK/VKCommandStream.h +++ b/rpcs3/Emu/RSX/VK/VKCommandStream.h @@ -56,12 +56,16 @@ namespace vk void notify_completed(u64 eid); void drain(); + void set_enabled(bool state); + private: atomic_t m_eid_ctr = 0ull; atomic_t m_last_completed_eid = 0ull; atomic_t m_wake_event = 0u; atomic_t m_completed_signal = 0u; //<- Works around atomic_engine's lack of 64-bit observables support + + atomic_t m_enabled = true; }; using driver_manager_thread = named_thread; diff --git a/rpcs3/Emu/RSX/VK/VKPresent.cpp b/rpcs3/Emu/RSX/VK/VKPresent.cpp index c1db90ad06..559c43d51a 100644 --- a/rpcs3/Emu/RSX/VK/VKPresent.cpp +++ b/rpcs3/Emu/RSX/VK/VKPresent.cpp @@ -1,4 +1,5 @@ #include "stdafx.h" +#include "VKCommandStream.h" #include "VKGSRender.h" #include "vkutils/buffer_object.h" #include "vkutils/memory.h" @@ -752,14 +753,21 @@ void VKGSRender::flip(const rsx::display_flip_info_t& info) vk::copy_image_to_buffer(*m_current_command_buffer, image_to_copy, &sshot_vkbuf, copy_info); image_to_copy->pop_layout(*m_current_command_buffer); + // We need to disable the driver manager temporarily as this next section is out of sequence. + // We're not supposed to be halting the GPU here and we certainly do not want to run driver management as we will end up deleting temp resources too early. + auto& driver_manager = g_fxo->get(); + driver_manager.set_enabled(false); + flush_command_queue(true); const auto src = sshot_vkbuf.map(0, sshot_size); std::vector sshot_frame(sshot_size); memcpy(sshot_frame.data(), src, sshot_size); sshot_vkbuf.unmap(); - const bool is_bgra = image_to_copy->format() == VK_FORMAT_B8G8R8A8_UNORM; + // Restore the driver manager state to keep things from crashing... + driver_manager.set_enabled(true); + const bool is_bgra = image_to_copy->format() == VK_FORMAT_B8G8R8A8_UNORM; if (user_asked_for_screenshot) { m_frame->take_screenshot(std::move(sshot_frame), buffer_width, buffer_height, is_bgra);