diff --git a/src/Backends/DRMBackend.cpp b/src/Backends/DRMBackend.cpp index ee2cbd3d90..c7420a26a8 100644 --- a/src/Backends/DRMBackend.cpp +++ b/src/Backends/DRMBackend.cpp @@ -2952,6 +2952,8 @@ bool drm_update_color_mgmt(struct drm_t *drm) return true; } +int g_nDynamicRefreshHz = 0; + static void drm_unset_mode( struct drm_t *drm ) { drm->pending.mode_id = 0; @@ -2967,6 +2969,7 @@ static void drm_unset_mode( struct drm_t *drm ) g_nOutputRefresh = drm->preferred_refresh; if (g_nOutputRefresh == 0) g_nOutputRefresh = gamescope::ConvertHztomHz( 60 ); + g_nDynamicRefreshHz = 0; g_bRotated = false; } @@ -2982,6 +2985,7 @@ bool drm_set_mode( struct drm_t *drm, const drmModeModeInfo *mode ) drm->needs_modeset = true; g_nOutputRefresh = gamescope::GetModeRefresh( mode ); + g_nDynamicRefreshHz = 0; update_drm_effective_orientations(drm, mode); @@ -3044,7 +3048,13 @@ bool drm_set_refresh( struct drm_t *drm, int refresh ) mode.type = DRM_MODE_TYPE_USERDEF; - return drm_set_mode(drm, &mode); + bool bSuccess = drm_set_mode(drm, &mode); + if ( !bSuccess ) + return false; + + g_nDynamicRefreshHz = refresh; + + return true; } bool drm_set_resolution( struct drm_t *drm, int width, int height ) diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp index e4738f951e..eea63c38e2 100644 --- a/src/steamcompmgr.cpp +++ b/src/steamcompmgr.cpp @@ -143,6 +143,8 @@ gamescope_color_mgmt_luts g_ScreenshotColorMgmtLutsHDR[ EOTF_Count ]; static lut1d_t g_tmpLut1d; static lut3d_t g_tmpLut3d; +extern int g_nDynamicRefreshHz; + bool g_bForceHDRSupportDebug = false; extern float g_flInternalDisplayBrightnessNits; extern float g_flHDRItmSdrNits; @@ -2482,11 +2484,15 @@ paint_all(bool async) uint64_t now = get_time_in_nanos(); - // Compare in Hz, as the actual resulting clocks from the mode generation - // may give us eg. 90'004 vs 90'000 - int32_t nOutputRefreshHz = gamescope::ConvertmHzToHz( g_nOutputRefresh ); + // The actual output hz generated by the mode, could be off by one either side, due to rounding. + // + // Check what we cached for the current dynamic refresh Hz we put in -- otherwise, convert + // g_nOutputRefresh -> Hz rounded. + int32_t nCurrentDynamicOutputHz = g_nDynamicRefreshHz + ? g_nDynamicRefreshHz + : gamescope::ConvertmHzToHz( g_nOutputRefresh ); - if ( nOutputRefreshHz == nTargetRefreshHz ) + if ( nCurrentDynamicOutputHz == nTargetRefreshHz ) { g_uDynamicRefreshEqualityTime = now; }