From f7b7267993db376dffc250fe3dbdedacd67869b2 Mon Sep 17 00:00:00 2001 From: Dentomologist Date: Thu, 5 Feb 2026 13:35:37 -0800 Subject: [PATCH] PerformanceMetrics: Fix automatic graph resizing Fix a bug causing the performance graph to not resize when the render window changed size: * When changing the render window size during emulation the performance graph wouldn't update its size until the next emulation session. * When changing the render window size with no emulation active (by changing the Internal Resolution with Auto-Adjust Window Size enabled) the performance graph wouldn't update its size until the second emulation session after the change. Before explaining why the bug happened, here are some details about Dear ImGui (henceforth ImGui) for context: * In order to allow programs to specify initial ImGui window sizes while also allowing the user to resize them, `SetNextWindowSize` takes a flag from the `ImGuiCond_` enum specifying under what circumstances that function should actually have any effect. * ImGuiCond_FirstUseEver causes ImGui to only apply the command when the window doesn't have any saved size information for that session or in the ini file specified by `ImGui::GetIO().IniFilename`. Since we set that filename to `nullptr`, in practice the resize command is applied on the first frame of each ImGui/emulation session. * Qt saves the most recent size of the render window across emulation (and even Dolphin) sessions, which is then used to set the initial value of `ImGui::GetIO().DisplaySize` in the next emulation session. * It takes multiple frames for the size of the render window to update when changed by setting the internal resolution. This means that `ImGui::GetIO().DisplaySize` will have a stale value in the intervening frames, and specifically for the first few frames of emulation if the resolution was changed beforehand. When changing the resolution during emulation the call to `SetNextWindowSize` had no effect because of the `ImGuiCond_FirstUseEver` flag. `DisplaySize` would be updated several frames later, and then the next emulation session would update the graph size on its first frame. When changing the resolution outside emulation and then starting a game, the call to SetNextWindowSize on the first frame took effect but used the stale value of `DisplaySize`. `DisplaySize` would be updated a few frames later, but the graph wouldn't be resized until the first frame of the second emulation session. This commit fixes the issue by using the `ImGuiCond_Always` flag in the performance graph's call to `SetNextWindowSize` when the render window size changes. --- Source/Core/VideoCommon/PerformanceMetrics.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Source/Core/VideoCommon/PerformanceMetrics.cpp b/Source/Core/VideoCommon/PerformanceMetrics.cpp index 8b47db53c3..bee2de40a2 100644 --- a/Source/Core/VideoCommon/PerformanceMetrics.cpp +++ b/Source/Core/VideoCommon/PerformanceMetrics.cpp @@ -143,6 +143,9 @@ void PerformanceMetrics::DrawImGuiStats(const float backbuffer_scale) // the layout to default. Hopefully users aren't changing window sizes or resolutions too often. const ImGuiCond set_next_position_condition = (display_size_changed || !movable_overlays) ? ImGuiCond_Always : ImGuiCond_FirstUseEver; + // Reset the graph size when changing resolutions, and otherwise let the user manually resize it. + const ImGuiCond set_next_size_condition = + display_size_changed ? ImGuiCond_Always : ImGuiCond_FirstUseEver; float window_y = window_padding; float window_x = display_size.x - window_padding; @@ -187,7 +190,7 @@ void PerformanceMetrics::DrawImGuiStats(const float backbuffer_scale) // Position in the top-right corner of the screen. ImGui::SetNextWindowPos(ImVec2(window_x, window_y), set_next_position_condition, ImVec2(1.0f, 0.0f)); - ImGui::SetNextWindowSize(ImVec2(graph_width, graph_height), ImGuiCond_FirstUseEver); + ImGui::SetNextWindowSize(ImVec2(graph_width, graph_height), set_next_size_condition); ImGui::SetNextWindowBgAlpha(bg_alpha); if (ImGui::Begin("PerformanceGraphs", nullptr, graph_flags)) {