summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon
diff options
context:
space:
mode:
authorAdmiral H. Curtiss <pikachu025@gmail.com>2022-11-23 00:24:45 +0100
committerGitHub <noreply@github.com>2022-11-23 00:24:45 +0100
commit31458259b67fe67d4feb0b2d425f629e3792fdf7 (patch)
treebc30c5e0272fb545ecc01e97ac3921b2958a389c /Source/Core/VideoCommon
parent5e442f6ffa7664dbc696e18693c1a4dd872fae8d (diff)
parentedb2c90b38f6b32cf6f687ed0d00b272fc5a5793 (diff)
Merge pull request #11212 from Sam-Belliveau/realtime-fps-and-vps-counter
VideoCommon: Improve FPS/VPS Counting with Euler + Moving Averages and Colors
Diffstat (limited to 'Source/Core/VideoCommon')
-rw-r--r--Source/Core/VideoCommon/FPSCounter.cpp63
-rw-r--r--Source/Core/VideoCommon/FPSCounter.h29
-rw-r--r--Source/Core/VideoCommon/RenderBase.cpp49
-rw-r--r--Source/Core/VideoCommon/RenderBase.h3
-rw-r--r--Source/Core/VideoCommon/VideoConfig.cpp4
-rw-r--r--Source/Core/VideoCommon/VideoConfig.h4
6 files changed, 106 insertions, 46 deletions
diff --git a/Source/Core/VideoCommon/FPSCounter.cpp b/Source/Core/VideoCommon/FPSCounter.cpp
index e38305eb7f..e5f396a094 100644
--- a/Source/Core/VideoCommon/FPSCounter.cpp
+++ b/Source/Core/VideoCommon/FPSCounter.cpp
@@ -3,7 +3,7 @@
#include "VideoCommon/FPSCounter.h"
-#include <fstream>
+#include <cmath>
#include <iomanip>
#include "Common/CommonTypes.h"
@@ -12,11 +12,15 @@
#include "Core/Core.h"
#include "VideoCommon/VideoConfig.h"
-static constexpr u64 FPS_REFRESH_INTERVAL_US = 250000;
+static constexpr double US_TO_MS = 1000.0;
+static constexpr double US_TO_S = 1000000.0;
-FPSCounter::FPSCounter()
+static constexpr double FPS_SAMPLE_RC_RATIO = 0.25;
+
+FPSCounter::FPSCounter(const char* log_name)
{
m_last_time = Common::Timer::NowUs();
+ m_log_name = log_name;
m_on_state_changed_handle = Core::AddOnStateChangedCallback([this](Core::State state) {
if (state == Core::State::Paused)
@@ -31,47 +35,64 @@ FPSCounter::~FPSCounter()
Core::RemoveOnStateChangedCallback(&m_on_state_changed_handle);
}
-void FPSCounter::LogRenderTimeToFile(u64 val)
+void FPSCounter::LogRenderTimeToFile(s64 val)
{
if (!m_bench_file.is_open())
{
- File::OpenFStream(m_bench_file, File::GetUserPath(D_LOGS_IDX) + "render_time.txt",
- std::ios_base::out);
+ File::OpenFStream(m_bench_file, File::GetUserPath(D_LOGS_IDX) + m_log_name, std::ios_base::out);
}
- m_bench_file << std::fixed << std::setprecision(8) << (val / 1000.0) << std::endl;
+ m_bench_file << std::fixed << std::setprecision(8) << (val / US_TO_MS) << std::endl;
}
void FPSCounter::Update()
{
- const u64 time = Common::Timer::NowUs();
- const u64 diff = time - m_last_time;
- m_time_diff_secs = static_cast<double>(diff / 1000000.0);
- if (g_ActiveConfig.bLogRenderTimeToFile)
- LogRenderTimeToFile(diff);
+ if (m_paused)
+ return;
- m_frame_counter++;
- m_time_since_update += diff;
+ const s64 time = Common::Timer::NowUs();
+ const s64 diff = std::max<s64>(0, time - m_last_time);
+ const s64 window = std::max(1, g_ActiveConfig.iPerfSampleUSec);
+
+ m_raw_dt = diff / US_TO_S;
m_last_time = time;
- if (m_time_since_update >= FPS_REFRESH_INTERVAL_US)
+ m_dt_total += diff;
+ m_dt_queue.push_back(diff);
+
+ while (window <= m_dt_total - m_dt_queue.front())
{
- m_fps = m_frame_counter / (m_time_since_update / 1000000.0);
- m_frame_counter = 0;
- m_time_since_update = 0;
+ m_dt_total -= m_dt_queue.front();
+ m_dt_queue.pop_front();
}
+
+ // This frame count takes into account frames that are partially in the sample window
+ const double fps = (m_dt_queue.size() * US_TO_S) / m_dt_total;
+ const double rc = FPS_SAMPLE_RC_RATIO * std::min(window, m_dt_total) / US_TO_S;
+ const double a = std::max(0.0, 1.0 - std::exp(-m_raw_dt / rc));
+
+ // Sometimes euler averages can break when the average is inf/nan
+ // This small check makes sure that if it does break, it gets fixed
+ if (std::isfinite(m_avg_fps))
+ m_avg_fps += a * (fps - m_avg_fps);
+ else
+ m_avg_fps = fps;
+
+ if (g_ActiveConfig.bLogRenderTimeToFile)
+ LogRenderTimeToFile(diff);
}
void FPSCounter::SetPaused(bool paused)
{
- if (paused)
+ m_paused = paused;
+ if (m_paused)
{
m_last_time_pause = Common::Timer::NowUs();
}
else
{
- const u64 time = Common::Timer::NowUs();
- const u64 diff = time - m_last_time_pause;
+ const s64 time = Common::Timer::NowUs();
+ const s64 diff = time - m_last_time_pause;
m_last_time += diff;
}
}
diff --git a/Source/Core/VideoCommon/FPSCounter.h b/Source/Core/VideoCommon/FPSCounter.h
index 8cd559a1de..852c39fd3b 100644
--- a/Source/Core/VideoCommon/FPSCounter.h
+++ b/Source/Core/VideoCommon/FPSCounter.h
@@ -3,6 +3,7 @@
#pragma once
+#include <deque>
#include <fstream>
#include "Common/CommonTypes.h"
@@ -10,7 +11,7 @@
class FPSCounter
{
public:
- FPSCounter();
+ explicit FPSCounter(const char* log_name = "log.txt");
~FPSCounter();
FPSCounter(const FPSCounter&) = delete;
FPSCounter& operator=(const FPSCounter&) = delete;
@@ -20,20 +21,26 @@ public:
// Called when a frame is rendered (updated every second).
void Update();
- float GetFPS() const { return m_fps; }
- double GetDeltaTime() const { return m_time_diff_secs; }
+ double GetFPS() const { return m_avg_fps; }
+
+ double GetDeltaTime() const { return m_raw_dt; }
private:
+ void LogRenderTimeToFile(s64 val);
void SetPaused(bool paused);
- u64 m_last_time = 0;
- u64 m_time_since_update = 0;
- u64 m_last_time_pause = 0;
- u32 m_frame_counter = 0;
- int m_on_state_changed_handle = -1;
- float m_fps = 0.f;
+ const char* m_log_name;
std::ofstream m_bench_file;
- double m_time_diff_secs = 0.0;
- void LogRenderTimeToFile(u64 val);
+ bool m_paused = false;
+ s64 m_last_time = 0;
+
+ double m_avg_fps = 0.0;
+ double m_raw_dt = 0.0;
+
+ s64 m_dt_total = 0;
+ std::deque<s64> m_dt_queue;
+
+ int m_on_state_changed_handle = -1;
+ s64 m_last_time_pause = 0;
};
diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp
index c2fdcbaa3d..792160f195 100644
--- a/Source/Core/VideoCommon/RenderBase.cpp
+++ b/Source/Core/VideoCommon/RenderBase.cpp
@@ -590,21 +590,42 @@ void Renderer::CheckForConfigChanges()
// Create On-Screen-Messages
void Renderer::DrawDebugText()
{
- if (g_ActiveConfig.bShowFPS)
+ if (g_ActiveConfig.bShowFPS || g_ActiveConfig.bShowVPS || g_ActiveConfig.bShowSpeed)
{
// Position in the top-right corner of the screen.
ImGui::SetNextWindowPos(ImVec2(ImGui::GetIO().DisplaySize.x - (10.0f * m_backbuffer_scale),
- 10.0f * m_backbuffer_scale),
+ 10.f * m_backbuffer_scale),
ImGuiCond_Always, ImVec2(1.0f, 0.0f));
- ImGui::SetNextWindowSize(ImVec2(100.0f * m_backbuffer_scale, 30.0f * m_backbuffer_scale));
- if (ImGui::Begin("FPS", nullptr,
+ int count = g_ActiveConfig.bShowFPS + g_ActiveConfig.bShowVPS + g_ActiveConfig.bShowSpeed;
+ ImGui::SetNextWindowSize(
+ ImVec2(94.f * m_backbuffer_scale, (12.f + 17.f * count) * m_backbuffer_scale));
+
+ if (ImGui::Begin("Performance", nullptr,
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoInputs |
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings |
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoNav |
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoFocusOnAppearing))
{
- ImGui::TextColored(ImVec4(0.0f, 1.0f, 1.0f, 1.0f), "FPS: %.2f", m_fps_counter.GetFPS());
+ const double fps = m_fps_counter.GetFPS();
+ const double vps = m_vps_counter.GetFPS();
+ const double speed = 100.0 * vps / VideoInterface::GetTargetRefreshRate();
+
+ // Change Color based on % Speed
+ float r = 0.0f, g = 1.0f, b = 1.0f;
+ if (g_ActiveConfig.bShowSpeedColors)
+ {
+ r = 1.0 - (speed - 80.0) / 20.0;
+ g = speed / 80.0;
+ b = (speed - 90.0) / 10.0;
+ }
+
+ if (g_ActiveConfig.bShowFPS)
+ ImGui::TextColored(ImVec4(r, g, b, 1.0f), "FPS:%7.2lf", fps);
+ if (g_ActiveConfig.bShowVPS)
+ ImGui::TextColored(ImVec4(r, g, b, 1.0f), "VPS:%7.2lf", vps);
+ if (g_ActiveConfig.bShowSpeed)
+ ImGui::TextColored(ImVec4(r, g, b, 1.0f), "Speed:%4.0lf%%", speed);
}
ImGui::End();
}
@@ -616,9 +637,9 @@ void Renderer::DrawDebugText()
if (show_movie_window)
{
// Position under the FPS display.
- ImGui::SetNextWindowPos(ImVec2(ImGui::GetIO().DisplaySize.x - (10.0f * m_backbuffer_scale),
- 50.0f * m_backbuffer_scale),
- ImGuiCond_FirstUseEver, ImVec2(1.0f, 0.0f));
+ ImGui::SetNextWindowPos(
+ ImVec2(ImGui::GetIO().DisplaySize.x - 10.f * m_backbuffer_scale, 80.f * m_backbuffer_scale),
+ ImGuiCond_FirstUseEver, ImVec2(1.0f, 0.0f));
ImGui::SetNextWindowSizeConstraints(
ImVec2(150.0f * m_backbuffer_scale, 20.0f * m_backbuffer_scale),
ImGui::GetIO().DisplaySize);
@@ -1363,10 +1384,14 @@ void Renderer::Swap(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height, u6
MathUtil::Rectangle<int> xfb_rect;
const auto* xfb_entry =
g_texture_cache->GetXFBTexture(xfb_addr, fb_width, fb_height, fb_stride, &xfb_rect);
- if (xfb_entry &&
- (!g_ActiveConfig.bSkipPresentingDuplicateXFBs || xfb_entry->id != m_last_xfb_id))
+ const bool is_duplicate_frame = xfb_entry->id == m_last_xfb_id;
+
+ m_vps_counter.Update();
+ if (!is_duplicate_frame)
+ m_fps_counter.Update();
+
+ if (xfb_entry && (!g_ActiveConfig.bSkipPresentingDuplicateXFBs || !is_duplicate_frame))
{
- const bool is_duplicate_frame = xfb_entry->id == m_last_xfb_id;
m_last_xfb_id = xfb_entry->id;
// Since we use the common pipelines here and draw vertices if a batch is currently being
@@ -1416,8 +1441,6 @@ void Renderer::Swap(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height, u6
if (!is_duplicate_frame)
{
- m_fps_counter.Update();
-
DolphinAnalytics::PerformanceSample perf_sample;
perf_sample.speed_ratio = SystemTimers::GetEstimatedEmulationPerformance();
perf_sample.num_prims = g_stats.this_frame.num_prims + g_stats.this_frame.num_dl_prims;
diff --git a/Source/Core/VideoCommon/RenderBase.h b/Source/Core/VideoCommon/RenderBase.h
index 0553d59f73..c44e2ebabe 100644
--- a/Source/Core/VideoCommon/RenderBase.h
+++ b/Source/Core/VideoCommon/RenderBase.h
@@ -338,7 +338,8 @@ protected:
MathUtil::Rectangle<int> m_target_rectangle = {};
int m_frame_count = 0;
- FPSCounter m_fps_counter;
+ FPSCounter m_fps_counter = FPSCounter("render_times.txt");
+ FPSCounter m_vps_counter = FPSCounter("v_blank_times.txt");
std::unique_ptr<VideoCommon::PostProcessing> m_post_processor;
diff --git a/Source/Core/VideoCommon/VideoConfig.cpp b/Source/Core/VideoCommon/VideoConfig.cpp
index 40d5841714..4e66c9d822 100644
--- a/Source/Core/VideoCommon/VideoConfig.cpp
+++ b/Source/Core/VideoCommon/VideoConfig.cpp
@@ -64,6 +64,10 @@ void VideoConfig::Refresh()
bCrop = Config::Get(Config::GFX_CROP);
iSafeTextureCache_ColorSamples = Config::Get(Config::GFX_SAFE_TEXTURE_CACHE_COLOR_SAMPLES);
bShowFPS = Config::Get(Config::GFX_SHOW_FPS);
+ bShowVPS = Config::Get(Config::GFX_SHOW_VPS);
+ bShowSpeed = Config::Get(Config::GFX_SHOW_SPEED);
+ bShowSpeedColors = Config::Get(Config::GFX_SHOW_SPEED_COLORS);
+ iPerfSampleUSec = Config::Get(Config::GFX_PERF_SAMP_WINDOW) * 1000;
bShowNetPlayPing = Config::Get(Config::GFX_SHOW_NETPLAY_PING);
bShowNetPlayMessages = Config::Get(Config::GFX_SHOW_NETPLAY_MESSAGES);
bLogRenderTimeToFile = Config::Get(Config::GFX_LOG_RENDER_TIME_TO_FILE);
diff --git a/Source/Core/VideoCommon/VideoConfig.h b/Source/Core/VideoCommon/VideoConfig.h
index 05d86a18f4..2bdf4b2835 100644
--- a/Source/Core/VideoCommon/VideoConfig.h
+++ b/Source/Core/VideoCommon/VideoConfig.h
@@ -82,6 +82,10 @@ struct VideoConfig final
// Information
bool bShowFPS = false;
+ bool bShowVPS = false;
+ bool bShowSpeed = false;
+ bool bShowSpeedColors = false;
+ int iPerfSampleUSec = 0;
bool bShowNetPlayPing = false;
bool bShowNetPlayMessages = false;
bool bOverlayStats = false;