diff --git a/retroarch.c b/retroarch.c index 1a3644c87d..9a1203671b 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1381,11 +1381,8 @@ static void driver_adjust_system_rates( video_driver_state_t *video_st, settings_t *settings) { - struct retro_system_av_info *av_info = &video_st->av_info; - const struct retro_system_timing *info = - (const struct retro_system_timing*)&av_info->timing; - double input_sample_rate = info->sample_rate; - double input_fps = info->fps; + double input_sample_rate = video_st->av_info.timing.sample_rate; + double input_fps = video_st->av_info.timing.fps; float video_refresh_rate = settings->floats.video_refresh_rate; float audio_max_timing_skew = settings->floats.audio_max_timing_skew; unsigned video_swap_interval = settings->uints.video_swap_interval; @@ -1396,17 +1393,8 @@ static void driver_adjust_system_rates( /* Update video swap interval if automatic * switching is enabled */ - runloop_set_video_swap_interval( - vrr_runloop_enable, - (video_st->flags & VIDEO_FLAG_CRT_SWITCHING_ACTIVE) ? true : false, - video_swap_interval, - black_frame_insertion, - shader_subframes, - audio_max_timing_skew, - video_refresh_rate, - input_fps); - video_swap_interval = runloop_get_video_swap_interval( - video_swap_interval); + runloop_set_video_swap_interval(settings); + video_swap_interval = runloop_get_video_swap_interval(video_swap_interval); if (input_sample_rate > 0.0) { @@ -1559,6 +1547,9 @@ void drivers_init( menu_st->flags |= MENU_ST_FLAG_DATA_OWN; #endif + /* Content av_info based automatic swap interval must be set early. */ + runloop_set_video_swap_interval(settings); + /* Initialize video driver */ if (flags & DRIVER_VIDEO_MASK) { @@ -1583,16 +1574,15 @@ void drivers_init( runloop_st->frame_time_last = 0; } - /* Regular display refresh rate startup autoswitch based on content av_info */ + /* Regular display refresh rate startup autoswitch based on content av_info. */ if ( flags & (DRIVER_VIDEO_MASK | DRIVER_AUDIO_MASK) && !(runloop_st->flags & RUNLOOP_FLAG_IS_INITED)) { - struct retro_system_av_info *av_info = &video_st->av_info; - float refresh_rate = av_info->timing.fps; - unsigned autoswitch_refresh_rate = settings->uints.video_autoswitch_refresh_rate; - bool exclusive_fullscreen = settings->bools.video_fullscreen && !settings->bools.video_windowed_fullscreen; - bool windowed_fullscreen = settings->bools.video_fullscreen && settings->bools.video_windowed_fullscreen; - bool all_fullscreen = settings->bools.video_fullscreen || settings->bools.video_windowed_fullscreen; + float refresh_rate = video_st->av_info.timing.fps; + unsigned autoswitch_refresh_rate = settings->uints.video_autoswitch_refresh_rate; + bool exclusive_fullscreen = settings->bools.video_fullscreen && !settings->bools.video_windowed_fullscreen; + bool windowed_fullscreen = settings->bools.video_fullscreen && settings->bools.video_windowed_fullscreen; + bool all_fullscreen = settings->bools.video_fullscreen || settings->bools.video_windowed_fullscreen; /* Making a switch from PC standard 60 Hz to NTSC 59.94 is excluded by the last condition. */ if ( (refresh_rate > 0.0f) diff --git a/runloop.c b/runloop.c index 55313076f0..68393a588d 100644 --- a/runloop.c +++ b/runloop.c @@ -4390,29 +4390,28 @@ float runloop_get_fastforward_ratio( } void runloop_set_video_swap_interval( - bool vrr_runloop_enable, - bool crt_switching_active, - unsigned swap_interval_config, - unsigned black_frame_insertion, - unsigned shader_subframes, - float audio_max_timing_skew, - float video_refresh_rate, - double input_fps) + settings_t *settings) { - runloop_state_t *runloop_st = &runloop_state; - float core_hz = input_fps; - float timing_hz = crt_switching_active ? - input_fps : video_refresh_rate; - float swap_ratio; - unsigned swap_integer; - float timing_skew; + runloop_state_t *runloop_st = &runloop_state; + video_driver_state_t *video_st = video_state_get_ptr(); + float video_refresh_rate = settings->floats.video_refresh_rate; + float audio_max_timing_skew = settings->floats.audio_max_timing_skew; + float input_fps = video_st->av_info.timing.fps; + float timing_fps = (video_st->flags & VIDEO_FLAG_CRT_SWITCHING_ACTIVE) + ? input_fps : video_refresh_rate; + float swap_ratio = 1; + float timing_skew = 0; + unsigned swap_interval_config = settings->uints.video_swap_interval; + unsigned black_frame_insertion = settings->uints.video_black_frame_insertion; + unsigned shader_subframes = settings->uints.video_shader_subframes; + unsigned swap_integer = 1; + bool vrr_runloop_enable = settings->bools.vrr_runloop_enable; /* If automatic swap interval selection is * disabled, just record user-set value */ if (swap_interval_config != 0) { - runloop_st->video_swap_interval_auto = - swap_interval_config; + runloop_st->video_swap_interval_auto = swap_interval_config; return; } @@ -4425,11 +4424,12 @@ void runloop_set_video_swap_interval( * > If BFI is active set swap interval to 1 * > If Shader Subframes active, set swap interval to 1 */ if ( (vrr_runloop_enable) - || (core_hz > timing_hz) - || (core_hz <= 0.0f) - || (timing_hz <= 0.0f) || (black_frame_insertion) - || (shader_subframes > 1)) + || (shader_subframes > 1) + || (input_fps > timing_fps) + || (input_fps <= 0.0f) + || (timing_fps <= 0.0f) + ) { runloop_st->video_swap_interval_auto = 1; return; @@ -4437,7 +4437,7 @@ void runloop_set_video_swap_interval( /* Check whether display refresh rate is an integer * multiple of core fps (within timing skew tolerance) */ - swap_ratio = timing_hz / core_hz; + swap_ratio = timing_fps / input_fps; swap_integer = (unsigned)(swap_ratio + 0.5f); /* > Sanity check: swap interval must be in the @@ -4449,7 +4449,7 @@ void runloop_set_video_swap_interval( return; } - timing_skew = fabs(1.0f - core_hz / (timing_hz / (float)swap_integer)); + timing_skew = fabs(1.0f - input_fps / (timing_fps / (float)swap_integer)); runloop_st->video_swap_interval_auto = (timing_skew <= audio_max_timing_skew) ? diff --git a/runloop.h b/runloop.h index 40f104e28b..e9c72b72dc 100644 --- a/runloop.h +++ b/runloop.h @@ -394,14 +394,8 @@ float runloop_get_fastforward_ratio( struct retro_fastforwarding_override *fastmotion_override); void runloop_set_video_swap_interval( - bool vrr_runloop_enable, - bool crt_switching_active, - unsigned swap_interval_config, - unsigned black_frame_insertion, - unsigned shader_subframes, - float audio_max_timing_skew, - float video_refresh_rate, - double input_fps); + settings_t *settings); + unsigned runloop_get_video_swap_interval( unsigned swap_interval_config);