Skip to content

Commit ded6119

Browse files
Amanda Liualexdeucher
authored andcommitted
drm/amd/display: Reinstate LFC optimization
[why] We want to streamline the calculations made when entering LFC. Previously, the optimizations led to screen tearing and were backed out to unblock development. [how] Integrate other calculations parameters, as well as screen tearing, fixes with the original LFC calculation optimizations. Signed-off-by: Amanda Liu <amanda.liu@amd.com> Reviewed-by: Aric Cyr <Aric.Cyr@amd.com> Acked-by: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 993dca3 commit ded6119

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

drivers/gpu/drm/amd/display/modules/freesync/freesync.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
#define STATIC_SCREEN_RAMP_DELTA_REFRESH_RATE_PER_FRAME ((1000 / 60) * 65)
3838
/* Number of elements in the render times cache array */
3939
#define RENDER_TIMES_MAX_COUNT 10
40-
/* Threshold to exit BTR (to avoid frequent enter-exits at the lower limit) */
41-
#define BTR_EXIT_MARGIN 2000
40+
/* Threshold to exit/exit BTR (to avoid frequent enter-exits at the lower limit) */
41+
#define BTR_MAX_MARGIN 2500
4242
/* Threshold to change BTR multiplier (to avoid frequent changes) */
4343
#define BTR_DRIFT_MARGIN 2000
4444
/*Threshold to exit fixed refresh rate*/
@@ -254,24 +254,22 @@ static void apply_below_the_range(struct core_freesync *core_freesync,
254254
unsigned int delta_from_mid_point_in_us_1 = 0xFFFFFFFF;
255255
unsigned int delta_from_mid_point_in_us_2 = 0xFFFFFFFF;
256256
unsigned int frames_to_insert = 0;
257-
unsigned int min_frame_duration_in_ns = 0;
258-
unsigned int max_render_time_in_us = in_out_vrr->max_duration_in_us;
259257
unsigned int delta_from_mid_point_delta_in_us;
260-
261-
min_frame_duration_in_ns = ((unsigned int) (div64_u64(
262-
(1000000000ULL * 1000000),
263-
in_out_vrr->max_refresh_in_uhz)));
258+
unsigned int max_render_time_in_us =
259+
in_out_vrr->max_duration_in_us - in_out_vrr->btr.margin_in_us;
264260

265261
/* Program BTR */
266-
if (last_render_time_in_us + BTR_EXIT_MARGIN < max_render_time_in_us) {
262+
if ((last_render_time_in_us + in_out_vrr->btr.margin_in_us / 2) < max_render_time_in_us) {
267263
/* Exit Below the Range */
268264
if (in_out_vrr->btr.btr_active) {
269265
in_out_vrr->btr.frame_counter = 0;
270266
in_out_vrr->btr.btr_active = false;
271267
}
272-
} else if (last_render_time_in_us > max_render_time_in_us) {
268+
} else if (last_render_time_in_us > (max_render_time_in_us + in_out_vrr->btr.margin_in_us / 2)) {
273269
/* Enter Below the Range */
274-
in_out_vrr->btr.btr_active = true;
270+
if (!in_out_vrr->btr.btr_active) {
271+
in_out_vrr->btr.btr_active = true;
272+
}
275273
}
276274

277275
/* BTR set to "not active" so disengage */
@@ -327,7 +325,9 @@ static void apply_below_the_range(struct core_freesync *core_freesync,
327325
/* Choose number of frames to insert based on how close it
328326
* can get to the mid point of the variable range.
329327
*/
330-
if (delta_from_mid_point_in_us_1 < delta_from_mid_point_in_us_2) {
328+
if ((frame_time_in_us / mid_point_frames_ceil) > in_out_vrr->min_duration_in_us &&
329+
(delta_from_mid_point_in_us_1 < delta_from_mid_point_in_us_2 ||
330+
mid_point_frames_floor < 2)) {
331331
frames_to_insert = mid_point_frames_ceil;
332332
delta_from_mid_point_delta_in_us = delta_from_mid_point_in_us_2 -
333333
delta_from_mid_point_in_us_1;
@@ -343,7 +343,7 @@ static void apply_below_the_range(struct core_freesync *core_freesync,
343343
if (in_out_vrr->btr.frames_to_insert != 0 &&
344344
delta_from_mid_point_delta_in_us < BTR_DRIFT_MARGIN) {
345345
if (((last_render_time_in_us / in_out_vrr->btr.frames_to_insert) <
346-
in_out_vrr->max_duration_in_us) &&
346+
max_render_time_in_us) &&
347347
((last_render_time_in_us / in_out_vrr->btr.frames_to_insert) >
348348
in_out_vrr->min_duration_in_us))
349349
frames_to_insert = in_out_vrr->btr.frames_to_insert;
@@ -796,6 +796,11 @@ void mod_freesync_build_vrr_params(struct mod_freesync *mod_freesync,
796796
refresh_range = in_out_vrr->max_refresh_in_uhz -
797797
in_out_vrr->min_refresh_in_uhz;
798798

799+
in_out_vrr->btr.margin_in_us = in_out_vrr->max_duration_in_us -
800+
2 * in_out_vrr->min_duration_in_us;
801+
if (in_out_vrr->btr.margin_in_us > BTR_MAX_MARGIN)
802+
in_out_vrr->btr.margin_in_us = BTR_MAX_MARGIN;
803+
799804
in_out_vrr->supported = true;
800805
}
801806

@@ -811,6 +816,7 @@ void mod_freesync_build_vrr_params(struct mod_freesync *mod_freesync,
811816
in_out_vrr->btr.inserted_duration_in_us = 0;
812817
in_out_vrr->btr.frames_to_insert = 0;
813818
in_out_vrr->btr.frame_counter = 0;
819+
814820
in_out_vrr->btr.mid_point_in_us =
815821
(in_out_vrr->min_duration_in_us +
816822
in_out_vrr->max_duration_in_us) / 2;

drivers/gpu/drm/amd/display/modules/inc/mod_freesync.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ struct mod_vrr_params_btr {
9292
uint32_t inserted_duration_in_us;
9393
uint32_t frames_to_insert;
9494
uint32_t frame_counter;
95+
uint32_t margin_in_us;
9596
};
9697

9798
struct mod_vrr_params_fixed_refresh {

0 commit comments

Comments
 (0)