Skip to content

Commit 7e22fb0

Browse files
committed
GPU: Add #define'able PSX GPU stats
1 parent fec210b commit 7e22fb0

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/core/gpu.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ static void JoinScreenshotThreads();
4848
static std::deque<std::thread> s_screenshot_threads;
4949
static std::mutex s_screenshot_threads_mutex;
5050

51+
// #define PSX_GPU_STATS
52+
#ifdef PSX_GPU_STATS
53+
static u64 s_active_gpu_cycles = 0;
54+
static u32 s_active_gpu_cycles_frames = 0;
55+
#endif
56+
5157
GPU::GPU()
5258
{
5359
ResetStatistics();
@@ -88,6 +94,11 @@ bool GPU::Initialize()
8894

8995
g_gpu_device->SetGPUTimingEnabled(g_settings.display_show_gpu_usage);
9096

97+
#ifdef PSX_GPU_STATS
98+
s_active_gpu_cycles = 0;
99+
s_active_gpu_cycles_frames = 0;
100+
#endif
101+
91102
return true;
92103
}
93104

@@ -536,6 +547,9 @@ TickCount GPU::SystemTicksToCRTCTicks(TickCount sysclk_ticks, TickCount* fractio
536547
void GPU::AddCommandTicks(TickCount ticks)
537548
{
538549
m_pending_command_ticks += ticks;
550+
#ifdef PSX_GPU_STATS
551+
s_active_gpu_cycles += ticks;
552+
#endif
539553
}
540554

541555
void GPU::SynchronizeCRTC()
@@ -998,6 +1012,20 @@ void GPU::CRTCTickEvent(TickCount ticks)
9981012
m_crtc_state.interlaced_display_field = m_crtc_state.interlaced_field ^ 1u;
9991013
else
10001014
m_crtc_state.interlaced_display_field = 0;
1015+
1016+
#ifdef PSX_GPU_STATS
1017+
if ((++s_active_gpu_cycles_frames) == 60)
1018+
{
1019+
const double busy_frac =
1020+
static_cast<double>(s_active_gpu_cycles) /
1021+
static_cast<double>(SystemTicksToGPUTicks(System::ScaleTicksToOverclock(System::MASTER_CLOCK)) *
1022+
(ComputeVerticalFrequency() / 60.0f));
1023+
Log_DevFmt("PSX GPU Usage: {:.2f}% [{:.0f} cycles avg per frame]", busy_frac * 100,
1024+
static_cast<double>(s_active_gpu_cycles) / static_cast<double>(s_active_gpu_cycles_frames));
1025+
s_active_gpu_cycles = 0;
1026+
s_active_gpu_cycles_frames = 0;
1027+
}
1028+
#endif
10011029
}
10021030

10031031
Timers::SetGate(HBLANK_TIMER_INDEX, new_vblank);

0 commit comments

Comments
 (0)