Files
DroidDeck/tools/gamescope/patches/0120-nested-refresh-follows-host.patch
T
The412Banner 43a0ce93f9 fix: Frame Limit sync and refresh follow on a still screen (review follow-ups) (#1663)
The Steam helper checked the Frame Limit only when the offered frame
rates changed. With the limit off during a refresh change, turning it
back on left a value the new rate does not offer, and a failed write was
not tried again. It now checks on every state change and every 5 s, and
waits for Steam's settings write so a rejected write is caught and tried
again on the next check.

gamescope 3.16.29-p16 (0120 changed): gamescope took a new host refresh
only from the presentation feedback of a frame it drew, so with nothing
moving on screen it kept the old rate. It now presents once when the
host's wl_output mode changes and keeps presenting while a new rate is
pending, so the 300 ms check runs on a still screen too.

Found by CodeRabbit in the reviews of #1650 and #1663.
2026-10-27 05:08:21 -04:00

109 lines
4.3 KiB
Diff

diff --git a/src/Backends/WaylandBackend.cpp b/src/Backends/WaylandBackend.cpp
index 40164ba..1b85e63 100644
--- a/src/Backends/WaylandBackend.cpp
+++ b/src/Backends/WaylandBackend.cpp
@@ -1698,6 +1698,52 @@ namespace gamescope
}
}
+ // -r sets the refresh gamescope starts with. With GAMESCOPE_NESTED_REFRESH_FOLLOWS_HOST=1 a refresh
+ // the host compositor reports later replaces it, so pacing and the frame limiter follow a panel
+ // switched to another mode during the session.
+ static bool NestedRefreshFollowsHost()
+ {
+ static const bool s_bFollow = []
+ {
+ const char *pszFollow = getenv( "GAMESCOPE_NESTED_REFRESH_FOLLOWS_HOST" );
+ return pszFollow && atoi( pszFollow ) != 0;
+ }();
+ return s_bFollow;
+ }
+
+ // A mode switch on the host can report a passing rate for a few frames (72 Hz between 144 and
+ // 120 on an AYANEO Pocket FIT); a new rate is taken once it has been reported for 300 ms.
+ // Until then gamescope keeps presenting, so a still screen also gets the feedback that takes it.
+ static bool HostRefreshChanged( int32_t nRefreshmHz, uint64_t ulPresentedNs )
+ {
+ static int32_t s_nPendingmHz = 0;
+ static uint64_t s_ulPendingSinceNs = 0;
+ if ( !nRefreshmHz || nRefreshmHz == g_nOutputRefresh )
+ {
+ s_nPendingmHz = 0;
+ return false;
+ }
+ if ( !NestedRefreshFollowsHost() )
+ return true;
+ if ( nRefreshmHz != s_nPendingmHz )
+ {
+ s_nPendingmHz = nRefreshmHz;
+ s_ulPendingSinceNs = ulPresentedNs;
+ }
+ if ( ulPresentedNs - s_ulPendingSinceNs >= 300'000'000ul )
+ return true;
+ force_repaint();
+ return false;
+ }
+
+ static void FollowHostRefresh( int32_t nRefreshmHz )
+ {
+ if ( !NestedRefreshFollowsHost() || !g_nNestedRefresh || g_nNestedRefresh == nRefreshmHz )
+ return;
+ xdg_log.infof( "Nested refresh follows the host: %.3fhz", ConvertmHzToHz( (float) nRefreshmHz ) );
+ g_nNestedRefresh = nRefreshmHz;
+ }
+
void CWaylandPlane::UpdateVRRRefreshRate()
{
if ( m_pParent )
@@ -1724,6 +1770,7 @@ namespace gamescope
// TODO(strategy): We should pick the largest refresh rate.
xdg_log.infof( "Changed refresh to: %.3fhz", ConvertmHzToHz( (float) nLargestRefreshRateMhz ) );
g_nOutputRefresh = nLargestRefreshRateMhz;
+ FollowHostRefresh( nLargestRefreshRateMhz );
}
}
@@ -1794,10 +1841,11 @@ namespace gamescope
if ( uRefreshCycle )
{
int32_t nRefresh = RefreshCycleTomHz( uRefreshCycle );
- if ( nRefresh && nRefresh != g_nOutputRefresh )
+ if ( HostRefreshChanged( nRefresh, ulTime ) )
{
xdg_log.infof( "Changed refresh to: %.3fhz", ConvertmHzToHz( (float) nRefresh ) );
g_nOutputRefresh = nRefresh;
+ FollowHostRefresh( nRefresh );
}
m_pConnector->SetHostCompositorIsCurrentlyVRR( false );
@@ -2636,6 +2684,9 @@ namespace gamescope
}
void CWaylandBackend::Wayland_Output_Mode( wl_output *pOutput, uint32_t uFlags, int32_t nWidth, int32_t nHeight, int32_t nRefresh )
{
+ // The followed rate comes from presentation feedback, so a still screen presents once for it.
+ if ( NestedRefreshFollowsHost() && m_pOutputs[ pOutput ].nRefresh != nRefresh )
+ force_repaint();
m_pOutputs[ pOutput ].nRefresh = nRefresh;
}
void CWaylandBackend::Wayland_Output_Done( wl_output *pOutput )
diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp
index 6c9299d..5fb9086 100644
--- a/src/steamcompmgr.cpp
+++ b/src/steamcompmgr.cpp
@@ -9254,6 +9254,15 @@ void update_vrr_atoms(xwayland_ctx_t *root_ctx, bool force, bool* needs_flush =
g_nCurrentRefreshRate_CachedValue = g_nOutputRefresh;
if (needs_flush)
*needs_flush = true;
+
+ // Steam reads the display's refresh rates from gamescope_control when it binds; send them again.
+ if ( !force )
+ {
+ wlserver_lock();
+ for ( const auto &control : wlserver.gamescope_controls )
+ wlserver_send_gamescope_control( control );
+ wlserver_unlock();
+ }
}
// Don't update this in-sync with DRM vrr usage.