From 8ea36ccffc30c4c2e5d2bae6e307c7e9aeac7b93 Mon Sep 17 00:00:00 2001 From: squidbus <175574877+squidbus@users.noreply.github.com> Date: Mon, 30 Nov 2026 20:44:06 -0800 Subject: [PATCH] debug: Add CPU frame profiler --- MarathonRecomp/gpu/video.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/MarathonRecomp/gpu/video.cpp b/MarathonRecomp/gpu/video.cpp index 93e1d7226..881e04e73 100644 --- a/MarathonRecomp/gpu/video.cpp +++ b/MarathonRecomp/gpu/video.cpp @@ -202,6 +202,7 @@ struct Profiler }; static double g_applicationValues[PROFILER_VALUE_COUNT]; +static Profiler g_cpuFrameProfiler; static Profiler g_gpuFrameProfiler; static Profiler g_presentProfiler; static Profiler g_frameFenceProfiler; @@ -1756,6 +1757,7 @@ static void DrawProfiler() g_applicationValues[g_profilerValueIndex] = App::s_deltaTime * 1000.0; const auto applicationAvg = std::accumulate(g_applicationValues, g_applicationValues + PROFILER_VALUE_COUNT, 0.0) / PROFILER_VALUE_COUNT; + const auto cpuFrameAvg = g_cpuFrameProfiler.UpdateAndReturnAverage(); const auto gpuFrameAvg = g_gpuFrameProfiler.UpdateAndReturnAverage(); const auto presentAvg = g_presentProfiler.UpdateAndReturnAverage(); const auto frameFenceAvg = g_frameFenceProfiler.UpdateAndReturnAverage(); @@ -1769,6 +1771,7 @@ static void DrawProfiler() ImPlot::SetupAxisLimits(ImAxis_Y1, 0.0, 20.0); ImPlot::SetupAxis(ImAxis_Y1, "ms", ImPlotAxisFlags_None); ImPlot::PlotLine("Application", g_applicationValues, PROFILER_VALUE_COUNT, 1.0, 0.0, ImPlotLineFlags_None, g_profilerValueIndex); + ImPlot::PlotLine("CPU Frame", g_cpuFrameProfiler.values, PROFILER_VALUE_COUNT, 1.0, 0.0, ImPlotLineFlags_None, g_profilerValueIndex); ImPlot::PlotLine("GPU Frame", g_gpuFrameProfiler.values, PROFILER_VALUE_COUNT, 1.0, 0.0, ImPlotLineFlags_None, g_profilerValueIndex); ImPlot::PlotLine("Present", g_presentProfiler.values, PROFILER_VALUE_COUNT, 1.0, 0.0, ImPlotLineFlags_None, g_profilerValueIndex); ImPlot::PlotLine("Present Wait", g_presentWaitProfiler.values, PROFILER_VALUE_COUNT, 1.0, 0.0, ImPlotLineFlags_None, g_profilerValueIndex); @@ -1809,6 +1812,7 @@ static void DrawProfiler() // -------- Name ---------------- Current Time --------------------------- Average Time -------- Current FPS ----------------------------- Average FPS ---------- // drawPerfRow("Application", App::s_deltaTime * 1000.0, applicationAvg, true, 1.0 / App::s_deltaTime, 1000.0 / applicationAvg); + drawPerfRow("CPU Frame", g_cpuFrameProfiler.value.load(), cpuFrameAvg, true, 1000.0 / g_cpuFrameProfiler.value.load(), 1000.0 / cpuFrameAvg ); drawPerfRow("GPU Frame", g_gpuFrameProfiler.value.load(), gpuFrameAvg, true, 1000.0 / g_gpuFrameProfiler.value.load(), 1000.0 / gpuFrameAvg ); drawPerfRow("Present", g_presentProfiler.value.load(), presentAvg, true, 1000.0 / g_presentProfiler.value.load(), 1000.0 / presentAvg ); drawPerfRow("Present Wait", g_presentWaitProfiler.value.load(), presentWaitAvg ); @@ -2492,6 +2496,8 @@ void Video::Present() g_executedCommandList.wait(false); g_executedCommandList = false; + g_cpuFrameProfiler.End(); + if (g_swapChainValid) { if (g_pendingWaitOnSwapChain) @@ -2562,6 +2568,8 @@ void Video::Present() s_next += 1000000000ns / Config::FPS; } + g_cpuFrameProfiler.Begin(); + g_presentProfiler.Reset(); }