mirror of
https://github.com/torvalds/linux.git
synced 2024-11-26 06:02:05 +00:00
drm/amd/display: Fix frames_to_insert math
[Why] The math on deciding on how many "frames to insert" sometimes sent us over the max refresh rate. Also integer overflow can occur if we have high refresh rates. [How] Instead of clipping the frame duration such that it doesn’t go below the min, just remove a frame from the number of frames to insert. + Use unsigned long long for intermediate calculations to prevent integer overflow. Signed-off-by: Bayan Zabihiyan <bayan.zabihiyan@amd.com> Reviewed-by: Aric Cyr <Aric.Cyr@amd.com> Acked-by: Leo Li <sunpeng.li@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
This commit is contained in:
parent
1cbcfc9751
commit
a463b26303
@ -435,6 +435,12 @@ static void apply_below_the_range(struct core_freesync *core_freesync,
|
||||
/* Either we've calculated the number of frames to insert,
|
||||
* or we need to insert min duration frames
|
||||
*/
|
||||
if (last_render_time_in_us / frames_to_insert <
|
||||
in_out_vrr->min_duration_in_us){
|
||||
frames_to_insert -= (frames_to_insert > 1) ?
|
||||
1 : 0;
|
||||
}
|
||||
|
||||
if (frames_to_insert > 0)
|
||||
inserted_frame_duration_in_us = last_render_time_in_us /
|
||||
frames_to_insert;
|
||||
@ -887,8 +893,8 @@ void mod_freesync_build_vrr_params(struct mod_freesync *mod_freesync,
|
||||
struct core_freesync *core_freesync = NULL;
|
||||
unsigned long long nominal_field_rate_in_uhz = 0;
|
||||
unsigned int refresh_range = 0;
|
||||
unsigned int min_refresh_in_uhz = 0;
|
||||
unsigned int max_refresh_in_uhz = 0;
|
||||
unsigned long long min_refresh_in_uhz = 0;
|
||||
unsigned long long max_refresh_in_uhz = 0;
|
||||
|
||||
if (mod_freesync == NULL)
|
||||
return;
|
||||
@ -915,7 +921,7 @@ void mod_freesync_build_vrr_params(struct mod_freesync *mod_freesync,
|
||||
min_refresh_in_uhz = nominal_field_rate_in_uhz;
|
||||
|
||||
if (!vrr_settings_require_update(core_freesync,
|
||||
in_config, min_refresh_in_uhz, max_refresh_in_uhz,
|
||||
in_config, (unsigned int)min_refresh_in_uhz, (unsigned int)max_refresh_in_uhz,
|
||||
in_out_vrr))
|
||||
return;
|
||||
|
||||
@ -931,15 +937,15 @@ void mod_freesync_build_vrr_params(struct mod_freesync *mod_freesync,
|
||||
return;
|
||||
|
||||
} else {
|
||||
in_out_vrr->min_refresh_in_uhz = min_refresh_in_uhz;
|
||||
in_out_vrr->min_refresh_in_uhz = (unsigned int)min_refresh_in_uhz;
|
||||
in_out_vrr->max_duration_in_us =
|
||||
calc_duration_in_us_from_refresh_in_uhz(
|
||||
min_refresh_in_uhz);
|
||||
(unsigned int)min_refresh_in_uhz);
|
||||
|
||||
in_out_vrr->max_refresh_in_uhz = max_refresh_in_uhz;
|
||||
in_out_vrr->max_refresh_in_uhz = (unsigned int)max_refresh_in_uhz;
|
||||
in_out_vrr->min_duration_in_us =
|
||||
calc_duration_in_us_from_refresh_in_uhz(
|
||||
max_refresh_in_uhz);
|
||||
(unsigned int)max_refresh_in_uhz);
|
||||
|
||||
refresh_range = in_out_vrr->max_refresh_in_uhz -
|
||||
in_out_vrr->min_refresh_in_uhz;
|
||||
@ -950,17 +956,18 @@ void mod_freesync_build_vrr_params(struct mod_freesync *mod_freesync,
|
||||
in_out_vrr->fixed.ramping_active = in_config->ramping;
|
||||
|
||||
in_out_vrr->btr.btr_enabled = in_config->btr;
|
||||
|
||||
if (in_out_vrr->max_refresh_in_uhz <
|
||||
2 * in_out_vrr->min_refresh_in_uhz)
|
||||
in_out_vrr->btr.btr_enabled = false;
|
||||
|
||||
in_out_vrr->btr.btr_active = false;
|
||||
in_out_vrr->btr.inserted_duration_in_us = 0;
|
||||
in_out_vrr->btr.frames_to_insert = 0;
|
||||
in_out_vrr->btr.frame_counter = 0;
|
||||
in_out_vrr->btr.mid_point_in_us =
|
||||
in_out_vrr->min_duration_in_us +
|
||||
(in_out_vrr->max_duration_in_us -
|
||||
in_out_vrr->min_duration_in_us) / 2;
|
||||
(in_out_vrr->min_duration_in_us +
|
||||
in_out_vrr->max_duration_in_us) / 2;
|
||||
|
||||
if (in_out_vrr->state == VRR_STATE_UNSUPPORTED) {
|
||||
in_out_vrr->adjust.v_total_min = stream->timing.v_total;
|
||||
|
Loading…
Reference in New Issue
Block a user