From 70442294c01142820f902af697c81be04eacdc8d Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Sat, 12 Feb 2022 09:10:55 +0000 Subject: [PATCH] steamcompmgr: Only allow one latent buffer when falling behind --- src/steamcompmgr.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp index 355a1a0..01560b4 100644 --- a/src/steamcompmgr.cpp +++ b/src/steamcompmgr.cpp @@ -237,6 +237,9 @@ static const uint64_t g_uDynamicRefreshDelay = 600'000'000; // 600ms bool g_bFSRActive = false; +int g_nAppBufferCount = 0; +int g_nMaxAppBufferCount = 0; + bool steamcompmgr_window_should_limit_fps( win *w ) { return g_nSteamCompMgrTargetFPS != 0 && w && !w->isSteam && w->appID != 769 && !w->isOverlay && !w->isExternalOverlay; @@ -245,14 +248,22 @@ bool steamcompmgr_window_should_limit_fps( win *w ) void steamcompmgr_fpslimit_add_commit( std::shared_ptr commit ) { std::unique_lock lock(g_FrameLimitCommitsMutex); + g_nAppBufferCount++; + g_nMaxAppBufferCount = std::max( g_nMaxAppBufferCount, g_nAppBufferCount ); g_FrameLimitCommits.push( commit ); } void steamcompmgr_fpslimit_release_commit() { std::unique_lock lock(g_FrameLimitCommitsMutex); - if ( !g_FrameLimitCommits.empty() ) - g_FrameLimitCommits.pop(); + // Only allow 1 latent buffer -- essentially go to only "double + // buffering" when we are falling behind. + if ( g_nAppBufferCount >= g_nMaxAppBufferCount - 1 ) + { + if ( !g_FrameLimitCommits.empty() ) + g_FrameLimitCommits.pop(); + g_nAppBufferCount--; + } } @@ -260,6 +271,8 @@ void steamcompmgr_fpslimit_release_all() { std::unique_lock lock(g_FrameLimitCommitsMutex); g_FrameLimitCommits = std::queue< std::shared_ptr >(); + g_nAppBufferCount = 0; + g_nMaxAppBufferCount = 0; } void steamcompmgr_set_target_fps( int nTarget )