Skip to content

Commit

Permalink
DRMBackend: Cache requested dynamic refresh rate and compare against …
Browse files Browse the repository at this point in the history
…that

Otherwise 51Hz -> 51.60Hz does not compare back to 51Hz, as it rounds to 52Hz.

Closes: ValveSoftware#1398
  • Loading branch information
misyltoad committed Aug 7, 2024
1 parent f222c19 commit 4ccc664
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
12 changes: 11 additions & 1 deletion src/Backends/DRMBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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);

Expand Down Expand Up @@ -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 )
Expand Down
14 changes: 10 additions & 4 deletions src/steamcompmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 4ccc664

Please sign in to comment.