From c958dbc46cd93b24aa9c63332739b4040880c711 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Fri, 19 Jun 2026 12:27:38 +0200 Subject: [PATCH] VideoCommon: Use XFB for internal resolution stats fb4ff3e added a statistics option to show the internal resolution, but it just showed the total size of the EFB (which is always 640x528) times the IR scale, so it didn't convey any useful information. This commit instead makes the option use the size of the last XFB copy (not multiplied by the IR scale), which changes based on the game's rendering resolution. --- Source/Core/Core/Core.cpp | 3 +++ .../Core/VideoCommon/PerformanceMetrics.cpp | 25 ++++++------------- Source/Core/VideoCommon/PerformanceMetrics.h | 10 ++++++-- Source/Core/VideoCommon/Present.cpp | 4 +++ Source/Core/VideoCommon/VideoEvents.h | 3 +++ 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index cebcc748ec..1b50796e34 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -863,6 +863,9 @@ void Callback_FramePresented(const PresentInfo& present_info) present_info.actual_present_time - present_info.intended_present_time; perf_metrics.SetLatestFramePresentationOffset(presentation_offset); + perf_metrics.SetLatestFrameBufferSize(present_info.frame_buffer_width, + present_info.frame_buffer_height); + if (present_info.reason == PresentInfo::PresentReason::VideoInterfaceDuplicate) return; diff --git a/Source/Core/VideoCommon/PerformanceMetrics.cpp b/Source/Core/VideoCommon/PerformanceMetrics.cpp index fccc8ae38e..b94fc6fade 100644 --- a/Source/Core/VideoCommon/PerformanceMetrics.cpp +++ b/Source/Core/VideoCommon/PerformanceMetrics.cpp @@ -11,7 +11,6 @@ #include "Common/HookableEvent.h" #include "Core/Config/GraphicsSettings.h" #include "Core/Core.h" -#include "VideoCommon/FramebufferManager.h" #include "VideoCommon/VideoConfig.h" PerformanceMetrics::PerformanceMetrics() @@ -89,20 +88,6 @@ double PerformanceMetrics::GetFPS() const return m_fps_counter.GetHzAvg(); } -u32 PerformanceMetrics::GetEFBWidth() const -{ - if (g_framebuffer_manager) - return g_framebuffer_manager->GetEFBWidth(); - return 0; -} - -u32 PerformanceMetrics::GetEFBHeight() const -{ - if (g_framebuffer_manager) - return g_framebuffer_manager->GetEFBHeight(); - return 0; -} - double PerformanceMetrics::GetVPS() const { return m_vps_counter.GetHzAvg(); @@ -123,6 +108,11 @@ void PerformanceMetrics::SetLatestFramePresentationOffset(DT offset) m_frame_presentation_offset.store(offset, std::memory_order_relaxed); } +void PerformanceMetrics::SetLatestFrameBufferSize(u32 width, u32 height) +{ + m_frame_buffer_size.store(FrameBufferSize{width, height}, std::memory_order_relaxed); +} + void PerformanceMetrics::DrawImGuiStats(const float backbuffer_scale) { m_vps_counter.UpdateStats(); @@ -139,8 +129,6 @@ void PerformanceMetrics::DrawImGuiStats(const float backbuffer_scale) const double fps = GetFPS(); const double vps = GetVPS(); const double speed = GetSpeed(); - const u32 width = GetEFBWidth(); - const u32 height = GetEFBHeight(); static ImVec2 last_display_size(-1.0f, -1.0f); @@ -350,7 +338,8 @@ void PerformanceMetrics::DrawImGuiStats(const float backbuffer_scale) clamp_window_position(); - ImGui::TextColored(ImVec4(r, g, b, 1.0f), "Res: %ux%u", width, height); + const FrameBufferSize size = m_frame_buffer_size.load(std::memory_order_relaxed); + ImGui::TextColored(ImVec4(r, g, b, 1.0f), "XFB res: %ux%u", size.width, size.height); } ImGui::End(); } diff --git a/Source/Core/VideoCommon/PerformanceMetrics.h b/Source/Core/VideoCommon/PerformanceMetrics.h index 538360a05b..b24c6f6659 100644 --- a/Source/Core/VideoCommon/PerformanceMetrics.h +++ b/Source/Core/VideoCommon/PerformanceMetrics.h @@ -41,15 +41,20 @@ public: double GetVPS() const; double GetSpeed() const; double GetMaxSpeed() const; - u32 GetEFBWidth() const; - u32 GetEFBHeight() const; // Call from any thread. void SetLatestFramePresentationOffset(DT offset); + void SetLatestFrameBufferSize(u32 width, u32 height); // ImGui Functions void DrawImGuiStats(const float backbuffer_scale); private: + struct FrameBufferSize + { + u32 width = 0; + u32 height = 0; + }; + PerformanceTracker m_fps_counter{"render_times.txt"}; PerformanceTracker m_vps_counter{"vblank_times.txt"}; @@ -59,6 +64,7 @@ private: std::atomic m_max_speed{}; std::atomic
m_frame_presentation_offset{}; + std::atomic m_frame_buffer_size{}; struct PerfSample { diff --git a/Source/Core/VideoCommon/Present.cpp b/Source/Core/VideoCommon/Present.cpp index f74b9a8fa4..41d05f3652 100644 --- a/Source/Core/VideoCommon/Present.cpp +++ b/Source/Core/VideoCommon/Present.cpp @@ -174,6 +174,8 @@ void Presenter::ViSwap(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height, .present_count = m_present_count++, .emulated_timestamp = ticks, .intended_present_time = presentation_time, + .frame_buffer_width = fb_width, + .frame_buffer_height = fb_height, }; if (is_duplicate) @@ -237,6 +239,8 @@ void Presenter::ImmediateSwap(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_ .emulated_timestamp = ticks, .intended_present_time = m_next_swap_estimated_time, .reason = PresentInfo::PresentReason::Immediate, + .frame_buffer_width = fb_width, + .frame_buffer_height = fb_height, }; auto& video_events = GetVideoEvents(); diff --git a/Source/Core/VideoCommon/VideoEvents.h b/Source/Core/VideoCommon/VideoEvents.h index f07ac631e4..f037dc266d 100644 --- a/Source/Core/VideoCommon/VideoEvents.h +++ b/Source/Core/VideoCommon/VideoEvents.h @@ -61,6 +61,9 @@ struct PresentInfo // Where the presentation of the frame was triggered from PresentReason reason = PresentReason::Immediate; + u32 frame_buffer_width; + u32 frame_buffer_height; + std::vector xfb_copy_hashes; };