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 ;
0 commit comments