From 31a610358f47f5c3c981a5c4f953e141e4b08c86 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Tue, 22 Sep 2026 00:46:18 +1000 Subject: [PATCH] Settings: Turn debug window visiblity into a bitmask Prevents video thread settings reload on every change, and stops it from reading achievements state. --- src/core/imgui_overlays.cpp | 20 ++++++++------------ src/core/imgui_overlays.h | 6 +++--- src/core/settings.cpp | 6 +++++- src/core/settings.h | 2 ++ src/core/spu.cpp | 4 ++-- src/core/system.cpp | 6 +----- src/core/video_thread.cpp | 15 ++------------- 7 files changed, 23 insertions(+), 36 deletions(-) diff --git a/src/core/imgui_overlays.cpp b/src/core/imgui_overlays.cpp index ee5fc2ef6..883cf2b9d 100644 --- a/src/core/imgui_overlays.cpp +++ b/src/core/imgui_overlays.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: CC-BY-NC-ND-4.0 #include "imgui_overlays.h" -#include "achievements.h" #include "cdrom.h" #include "controller.h" #include "core.h" @@ -127,30 +126,27 @@ static InputOverlayState s_input_overlay_state = {}; } // namespace ImGuiManager -bool ImGuiManager::AreAnyDebugWindowsEnabled(const SettingsInterface& si) +u8 ImGuiManager::LoadDebugWindowVisibility(const SettingsInterface& si) { - const bool block_all = Achievements::IsHardcoreModeActive(); - if (block_all) - return false; + u8 visible = 0; for (size_t i = 0; i < NUM_DEBUG_WINDOWS; i++) { const DebugWindowInfo& info = s_debug_window_info[i]; if (si.GetBoolValue(DEBUG_WINDOW_CONFIG_SECTION, info.name, false)) - return true; + visible |= (1u << i); } - return false; + return visible; } -bool ImGuiManager::IsSPUDebugWindowEnabled() +bool ImGuiManager::IsSPUDebugWindowVisible(u8 debug_window_visibility) { - return (s_debug_window_state[1].window_handle != nullptr); + return ((debug_window_visibility & (1u << 1)) != 0); } -bool ImGuiManager::UpdateDebugWindowConfig() +bool ImGuiManager::UpdateDebugWindowConfig(u8 debug_window_visibility) { - const bool block_all = Achievements::IsHardcoreModeActive(); bool was_changed = false; for (size_t i = 0; i < NUM_DEBUG_WINDOWS; i++) @@ -159,7 +155,7 @@ bool ImGuiManager::UpdateDebugWindowConfig() const DebugWindowInfo& info = s_debug_window_info[i]; const bool current = (state.window_handle != nullptr); - const bool enabled = (!block_all && Core::GetBaseBoolSettingValue(DEBUG_WINDOW_CONFIG_SECTION, info.name, false)); + const bool enabled = ((debug_window_visibility & (1u << i)) != 0); if (enabled == current) continue; diff --git a/src/core/imgui_overlays.h b/src/core/imgui_overlays.h index 030f8690d..78ba80c26 100644 --- a/src/core/imgui_overlays.h +++ b/src/core/imgui_overlays.h @@ -17,10 +17,10 @@ inline constexpr const char* LOGO_IMAGE_NAME = "images/duck.png"; void UpdateInputOverlay(); void RenderTextOverlays(const GPUBackend* gpu); -bool AreAnyDebugWindowsEnabled(const SettingsInterface& si); -bool IsSPUDebugWindowEnabled(); +u8 LoadDebugWindowVisibility(const SettingsInterface& si); +bool IsSPUDebugWindowVisible(u8 debug_window_visibility); void RenderDebugWindows(); -bool UpdateDebugWindowConfig(); +bool UpdateDebugWindowConfig(u8 debug_window_visibility); void DestroyAllDebugWindows(); void RenderOverlayWindows(); diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 8fe929835..8760d1495 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -582,6 +582,8 @@ void Settings::Load(const SettingsInterface& si, const SettingsInterface& contro pcdrv_enable_writes = si.GetBoolValue("PCDrv", "EnableWrites", false); pcdrv_root = Path::ToNativePath(si.GetStringViewValue("PCDrv", "Root")); + debug_window_visibility = ImGuiManager::LoadDebugWindowVisibility(si); + texture_replacements.enable_texture_replacements = si.GetBoolValue("TextureReplacements", "EnableTextureReplacements", false); texture_replacements.enable_vram_write_replacements = @@ -1205,6 +1207,8 @@ void Settings::ApplySettingRestrictions() gpu_show_vram = false; gpu_dump_cpu_to_vram_copies = false; gpu_dump_vram_to_cpu_copies = false; + + debug_window_visibility = 0; } } @@ -1248,7 +1252,7 @@ void Settings::FixIncompatibleSettings(const SettingsInterface& si, bool display texture_replacements.enable_vram_write_replacements &= (gpu_renderer != GPURenderer::Software); // GPU thread should be disabled if any debug windows are active, since they will be racing to read CPU thread state. - if (gpu_use_thread && gpu_max_queued_frames > 0 && ImGuiManager::AreAnyDebugWindowsEnabled(si)) + if (debug_window_visibility != 0 && gpu_use_thread && gpu_max_queued_frames > 0) { WARNING_LOG("Setting maximum queued frames to 0 because one or more debug windows are enabled."); gpu_max_queued_frames = 0; diff --git a/src/core/settings.h b/src/core/settings.h index be86e739b..c5d1ac912 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -127,6 +127,8 @@ struct GPUSettings bool achievements_rich_presence_monitor : 1 = false; + u8 debug_window_visibility = 0; + NotificationLocation display_osd_message_location = DEFAULT_OSD_MESSAGE_LOCATION; // achievements diff --git a/src/core/spu.cpp b/src/core/spu.cpp index a902b6204..1944060a6 100644 --- a/src/core/spu.cpp +++ b/src/core/spu.cpp @@ -451,9 +451,9 @@ ALIGN_TO_CACHE_LINE static std::array s_muted_output_buff #ifdef SPU_ENABLE_VU_METER -static bool IsVUMeterActive() +ALWAYS_INLINE static bool IsVUMeterActive() { - return ImGuiManager::IsSPUDebugWindowEnabled(); + return ImGuiManager::IsSPUDebugWindowVisible(g_settings.debug_window_visibility); } ALWAYS_INLINE_RELEASE static void UpdateDebugPeaks(s16 peaks[2], s32 left, s32 right) diff --git a/src/core/system.cpp b/src/core/system.cpp index 6ef9e58a7..5a1d05a61 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -4663,6 +4663,7 @@ void System::CheckForSettingsChanges(const Settings& old_settings) g_settings.display_line_start_offset != old_settings.display_line_start_offset || g_settings.display_line_end_offset != old_settings.display_line_end_offset || g_settings.gpu_show_vram != old_settings.gpu_show_vram || + g_settings.debug_window_visibility != old_settings.debug_window_visibility || g_settings.rewind_enable != old_settings.rewind_enable || g_settings.runahead_frames != old_settings.runahead_frames || g_settings.texture_replacements != old_settings.texture_replacements) @@ -4749,11 +4750,6 @@ void System::CheckForSettingsChanges(const Settings& old_settings) VideoThread::UpdateSettings(true, false, false); } } - else - { - // still need to update debug windows - VideoThread::UpdateSettings(false, false, false); - } if (g_settings.gpu_widescreen_hack != old_settings.gpu_widescreen_hack || g_settings.display_aspect_ratio != old_settings.display_aspect_ratio) diff --git a/src/core/video_thread.cpp b/src/core/video_thread.cpp index 25196f263..05732999a 100644 --- a/src/core/video_thread.cpp +++ b/src/core/video_thread.cpp @@ -858,7 +858,7 @@ bool VideoThread::CreateGPUBackendOnThread(bool hardware_renderer, bool upload_v } } - ImGuiManager::UpdateDebugWindowConfig(); + ImGuiManager::UpdateDebugWindowConfig(g_gpu_settings.debug_window_visibility); if (hardware_renderer) s_state.gpu_backend = GPUBackend::CreateHardwareBackend(); @@ -1162,7 +1162,7 @@ void VideoThread::UpdateSettingsOnThread(GPUSettings&& new_settings) return; } - if (ImGuiManager::UpdateDebugWindowConfig()) + if (ImGuiManager::UpdateDebugWindowConfig(g_gpu_settings.debug_window_visibility)) PresentFrameAndRestoreContext(); else s_state.gpu_backend->RestoreDeviceContext(); @@ -1256,17 +1256,6 @@ void VideoThread::UpdateSettings(bool gpu_settings_changed, bool device_settings UpdateSettingsOnThread(GPUSettings(g_settings)); } } - else - { - // still need to update debug window visibility - RunOnThread([]() { - if (s_state.gpu_backend) - { - if (ImGuiManager::UpdateDebugWindowConfig()) - PresentFrameAndRestoreContext(); - } - }); - } } void VideoThread::UpdateGameInfo(const std::string& title, const std::string& serial, const std::string& path,