From 5bef54618a2850e42f7bab45120dab9166468a25 Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Sat, 15 May 2021 20:34:20 -0400 Subject: perf_stats: Rework FPS counter to be more accurate The FPS counter was based on metrics in the nvdisp swapbuffers call. This metric would be accurate if the gpu thread/renderer were synchronous with the nvdisp service, but that's no longer the case. This commit moves the frame counting responsibility onto the concrete renderers after their frame draw calls. Resulting in more meaningful metrics. The displayed FPS is now made up of the average framerate between the previous and most recent update, in order to avoid distracting FPS counter updates when framerate is oscillating between close values. The status bar update frequency was also changed from 2 seconds to 500ms. --- src/core/perf_stats.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/core/perf_stats.cpp') diff --git a/src/core/perf_stats.cpp b/src/core/perf_stats.cpp index c92337079..526c017cd 100644 --- a/src/core/perf_stats.cpp +++ b/src/core/perf_stats.cpp @@ -69,9 +69,7 @@ void PerfStats::EndSystemFrame() { } void PerfStats::EndGameFrame() { - std::lock_guard lock{object_mutex}; - - game_frames += 1; + game_frames.fetch_add(1, std::memory_order_relaxed); } double PerfStats::GetMeanFrametime() const { @@ -94,10 +92,11 @@ PerfStatsResults PerfStats::GetAndResetStats(microseconds current_system_time_us const auto interval = duration_cast(now - reset_point).count(); const auto system_us_per_second = (current_system_time_us - reset_point_system_us) / interval; - + const auto current_frames = static_cast(game_frames.load(std::memory_order_relaxed)); + const auto current_fps = current_frames / interval; const PerfStatsResults results{ .system_fps = static_cast(system_frames) / interval, - .game_fps = static_cast(game_frames) / interval, + .average_game_fps = (current_fps + previous_fps) / 2.0, .frametime = duration_cast(accumulated_frametime).count() / static_cast(system_frames), .emulation_speed = system_us_per_second.count() / 1'000'000.0, @@ -108,7 +107,8 @@ PerfStatsResults PerfStats::GetAndResetStats(microseconds current_system_time_us reset_point_system_us = current_system_time_us; accumulated_frametime = Clock::duration::zero(); system_frames = 0; - game_frames = 0; + game_frames.store(0, std::memory_order_relaxed); + previous_fps = current_fps; return results; } -- cgit v1.2.3