From 06ecc507972acc13b6257aaa75cb01f66c391804 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Fri, 5 Aug 2022 17:17:29 +1000 Subject: [PATCH] System: Fix CPU usage not showing for sw-renderer-for-readbacks --- src/core/gpu.h | 6 ++++++ src/core/gpu_hw.cpp | 5 +++++ src/core/gpu_hw.h | 2 ++ src/core/gpu_sw.cpp | 5 +++++ src/core/gpu_sw.h | 1 + src/core/system.cpp | 24 ++++++++---------------- src/frontend-common/imgui_overlays.cpp | 2 +- 7 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/core/gpu.h b/src/core/gpu.h index db90f3080..69906598a 100644 --- a/src/core/gpu.h +++ b/src/core/gpu.h @@ -20,6 +20,11 @@ class HostDisplayTexture; class TimingEvent; class Timers; +namespace Threading +{ +class Thread; +} + class GPU { public: @@ -74,6 +79,7 @@ public: virtual ~GPU(); virtual GPURenderer GetRendererType() const = 0; + virtual const Threading::Thread* GetSWThread() const = 0; virtual bool Initialize(); virtual void Reset(bool clear_vram); diff --git a/src/core/gpu_hw.cpp b/src/core/gpu_hw.cpp index 6f13b8f34..84ecdfd09 100644 --- a/src/core/gpu_hw.cpp +++ b/src/core/gpu_hw.cpp @@ -44,6 +44,11 @@ GPU_HW::~GPU_HW() } } +const Threading::Thread* GPU_HW::GetSWThread() const +{ + return m_sw_renderer ? m_sw_renderer->GetThread() : nullptr; +} + bool GPU_HW::Initialize() { if (!GPU::Initialize()) diff --git a/src/core/gpu_hw.h b/src/core/gpu_hw.h index 4e8484cc2..a1e7052e6 100644 --- a/src/core/gpu_hw.h +++ b/src/core/gpu_hw.h @@ -33,6 +33,8 @@ public: GPU_HW(); virtual ~GPU_HW(); + const Threading::Thread* GetSWThread() const; + virtual bool Initialize() override; virtual void Reset(bool clear_vram) override; virtual bool DoState(StateWrapper& sw, HostDisplayTexture** host_texture, bool update_display) override; diff --git a/src/core/gpu_sw.cpp b/src/core/gpu_sw.cpp index 513238d2c..a8dd47987 100644 --- a/src/core/gpu_sw.cpp +++ b/src/core/gpu_sw.cpp @@ -45,6 +45,11 @@ GPURenderer GPU_SW::GetRendererType() const return GPURenderer::Software; } +const Threading::Thread* GPU_SW::GetSWThread() const +{ + return m_backend.GetThread(); +} + bool GPU_SW::Initialize() { // we need something to draw in.. but keep the current api if we have one diff --git a/src/core/gpu_sw.h b/src/core/gpu_sw.h index 40155a849..4b35b9694 100644 --- a/src/core/gpu_sw.h +++ b/src/core/gpu_sw.h @@ -23,6 +23,7 @@ public: ALWAYS_INLINE const GPU_SW_Backend& GetBackend() const { return m_backend; } GPURenderer GetRendererType() const override; + const Threading::Thread* GetSWThread() const; bool Initialize() override; bool DoState(StateWrapper& sw, HostDisplayTexture** host_texture, bool update_display) override; diff --git a/src/core/system.cpp b/src/core/system.cpp index 3b4a54fc2..ffea7d180 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -20,7 +20,6 @@ #include "fmt/format.h" #include "game_database.h" #include "gpu.h" -#include "gpu_sw.h" #include "gte.h" #include "host.h" #include "host_display.h" @@ -2149,9 +2148,8 @@ void System::UpdatePerformanceCounters() 100.0f; s_last_global_tick_counter = global_tick_counter; - const Threading::Thread* sw_thread = - g_gpu->IsHardwareRenderer() ? nullptr : static_cast(g_gpu.get())->GetBackend().GetThread(); - const u64 cpu_time = s_cpu_thread_handle.GetCPUTime(); + const Threading::Thread* sw_thread = g_gpu->GetSWThread(); + const u64 cpu_time = s_cpu_thread_handle ? s_cpu_thread_handle.GetCPUTime() : 0; const u64 sw_time = sw_thread ? sw_thread->GetCPUTime() : 0; const u64 cpu_delta = cpu_time - s_last_cpu_time; const u64 sw_delta = sw_time - s_last_sw_time; @@ -2176,20 +2174,14 @@ void System::ResetPerformanceCounters() s_last_frame_number = s_frame_number; s_last_internal_frame_number = s_internal_frame_number; s_last_global_tick_counter = TimingEvents::GetGlobalTickCounter(); - s_last_cpu_time = s_cpu_thread_handle.GetCPUTime(); - s_last_sw_time = 0; - if (!g_gpu->IsHardwareRenderer()) - { - const Threading::Thread* sw_thread = static_cast(g_gpu.get())->GetBackend().GetThread(); - if (sw_thread) - s_last_sw_time = sw_thread->GetCPUTime(); - } + s_last_cpu_time = s_cpu_thread_handle ? s_cpu_thread_handle.GetCPUTime() : 0; + if (const Threading::Thread* sw_thread = g_gpu->GetSWThread(); sw_thread) + s_last_sw_time = sw_thread->GetCPUTime(); + else + s_last_sw_time = 0; + s_average_frame_time_accumulator = 0.0f; s_worst_frame_time_accumulator = 0.0f; - s_cpu_thread_usage = 0.0f; - s_cpu_thread_time = 0.0f; - s_sw_thread_usage = 0.0f; - s_sw_thread_time = 0.0f; s_fps_timer.Reset(); ResetThrottler(); } diff --git a/src/frontend-common/imgui_overlays.cpp b/src/frontend-common/imgui_overlays.cpp index 0753159b3..c46b06005 100644 --- a/src/frontend-common/imgui_overlays.cpp +++ b/src/frontend-common/imgui_overlays.cpp @@ -168,7 +168,7 @@ void ImGuiManager::DrawPerformanceOverlay() FormatProcessorStat(text, System::GetCPUThreadUsage(), System::GetCPUThreadAverageTime()); DRAW_LINE(fixed_font, text, IM_COL32(255, 255, 255, 255)); - if (!g_gpu->IsHardwareRenderer() && g_settings.gpu_use_thread) + if (g_gpu->GetSWThread()) { text.Assign("SW: "); FormatProcessorStat(text, System::GetSWThreadUsage(), System::GetSWThreadAverageTime());