From dddf805d6a7aacd0ff66a4f7674608ff7b2468ae Mon Sep 17 00:00:00 2001 From: psucien Date: Sun, 9 Feb 2025 11:39:24 +0100 Subject: [PATCH] fix for crashes when debug tools used --- src/core/libraries/videoout/driver.h | 3 ++- src/core/libraries/videoout/video_out.cpp | 2 ++ src/imgui/renderer/imgui_core.cpp | 7 +------ src/imgui/renderer/imgui_core.h | 2 +- src/video_core/renderer_vulkan/vk_swapchain.cpp | 11 +++++++++-- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/core/libraries/videoout/driver.h b/src/core/libraries/videoout/driver.h index ad7c7bec2..e57b189b5 100644 --- a/src/core/libraries/videoout/driver.h +++ b/src/core/libraries/videoout/driver.h @@ -18,7 +18,6 @@ struct Frame; namespace Libraries::VideoOut { struct VideoOutPort { - bool is_open = false; SceVideoOutResolutionStatus resolution; std::array buffer_slots; std::array buffer_labels; // should be contiguous in memory @@ -33,6 +32,8 @@ struct VideoOutPort { std::condition_variable vo_cv; std::condition_variable vblank_cv; int flip_rate = 0; + bool is_open = false; + bool is_mode_changing = false; // Used to prevent flip during mode change s32 FindFreeGroup() const { s32 index = 0; diff --git a/src/core/libraries/videoout/video_out.cpp b/src/core/libraries/videoout/video_out.cpp index 4b334a8d3..090ed8624 100644 --- a/src/core/libraries/videoout/video_out.cpp +++ b/src/core/libraries/videoout/video_out.cpp @@ -391,7 +391,9 @@ s32 PS4_SYSV_ABI sceVideoOutConfigureOutputMode_(s32 handle, u32 reserved, const auto& game_info = Common::ElfInfo::Instance(); if (mode->colorimetry == OrbisVideoOutColorimetry::Bt2020PQ && game_info.GetPSFAttributes().support_hdr) { + port->is_mode_changing = true; presenter->SetHDR(true); + port->is_mode_changing = false; } else { return ORBIS_VIDEO_OUT_ERROR_INVALID_VALUE; } diff --git a/src/imgui/renderer/imgui_core.cpp b/src/imgui/renderer/imgui_core.cpp index c6b5fac13..50ce41ebf 100644 --- a/src/imgui/renderer/imgui_core.cpp +++ b/src/imgui/renderer/imgui_core.cpp @@ -118,12 +118,7 @@ void OnResize() { Sdl::OnResize(); } -void OnSurfaceFormatChange(const vk::Device& device, vk::Format surface_format) { - auto result = device.waitIdle(); - if (result != vk::Result::eSuccess) { - LOG_WARNING(ImGui, "Failed to wait for Vulkan device idle on shutdown: {}", - vk::to_string(result)); - } +void OnSurfaceFormatChange(vk::Format surface_format) { Vulkan::OnSurfaceFormatChange(surface_format); } diff --git a/src/imgui/renderer/imgui_core.h b/src/imgui/renderer/imgui_core.h index 02ee0c1e0..36ccff138 100644 --- a/src/imgui/renderer/imgui_core.h +++ b/src/imgui/renderer/imgui_core.h @@ -22,7 +22,7 @@ void Initialize(const Vulkan::Instance& instance, const Frontend::WindowSDL& win void OnResize(); -void OnSurfaceFormatChange(const vk::Device& device, vk::Format surface_format); +void OnSurfaceFormatChange(vk::Format surface_format); void Shutdown(const vk::Device& device); diff --git a/src/video_core/renderer_vulkan/vk_swapchain.cpp b/src/video_core/renderer_vulkan/vk_swapchain.cpp index 1ea53cab3..de7bec894 100644 --- a/src/video_core/renderer_vulkan/vk_swapchain.cpp +++ b/src/video_core/renderer_vulkan/vk_swapchain.cpp @@ -102,10 +102,17 @@ void Swapchain::SetHDR(bool hdr) { if (needs_hdr == hdr) { return; } + + auto result = instance.GetDevice().waitIdle(); + if (result != vk::Result::eSuccess) { + LOG_WARNING(ImGui, "Failed to wait for Vulkan device idle on mode change: {}", + vk::to_string(result)); + } + needs_hdr = hdr; Recreate(width, height); - ImGui::Core::OnSurfaceFormatChange(instance.GetDevice(), - needs_hdr ? SURFACE_FORMAT_HDR.format : surface_format.format); + ImGui::Core::OnSurfaceFormatChange(needs_hdr ? SURFACE_FORMAT_HDR.format + : surface_format.format); } bool Swapchain::AcquireNextImage() {