diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 70cbeb3c46..bf66875688 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -3409,6 +3409,10 @@ void video_driver_frame(const void *data, unsigned width, video_driver_build_info(&video_info); + /* Take target refresh rate as initial FPS value instead of 0.00 */ + if (!last_fps) + last_fps = video_info.refresh_rate; + /* If fast forward is active and fast forward * frame skipping is enabled, drop any frames * that occur at a rate higher than the core-set @@ -3426,6 +3430,7 @@ void video_driver_frame(const void *data, unsigned width, { retro_time_t frame_time_accumulator_prev = frame_time_accumulator; retro_time_t frame_time_delta = new_time - last_time; + retro_time_t frame_time_target = 1000000.0f / video_info.refresh_rate; /* Ignore initial previous frame time * to prevent rubber band startup */ @@ -3434,28 +3439,29 @@ void video_driver_frame(const void *data, unsigned width, else if (nonblock_active < 0) nonblock_active = 1; - /* Accumulate the elapsed time since the - * last frame */ + /* Accumulate the elapsed time since the last frame */ if (nonblock_active > 0) frame_time_accumulator += frame_time_delta; /* Render frame if the accumulated time is * greater than or equal to the expected * core frame time */ - render_frame = frame_time_accumulator >= - video_st->core_frame_time; + render_frame = frame_time_accumulator >= frame_time_target; /* If frame is to be rendered, subtract * expected frame time from accumulator */ if (render_frame) { - frame_time_accumulator -= video_st->core_frame_time; + frame_time_accumulator -= frame_time_target; /* Prevent external frame limiters from * pushing fast forward ratio down to 1x */ - if (frame_time_accumulator + frame_time_accumulator_prev < video_st->core_frame_time) + if (frame_time_accumulator_prev - frame_time_accumulator >= frame_time_delta) frame_time_accumulator -= frame_time_delta; + if (frame_time_accumulator < 0) + frame_time_accumulator = 0; + /* If fast forward is working correctly, * the actual frame time will always be * less than the expected frame time. @@ -3465,7 +3471,7 @@ void video_driver_frame(const void *data, unsigned width, * will never empty and may potentially * overflow. If a 'runaway' accumulator * is detected, we simply reset it */ - if (frame_time_accumulator > video_st->core_frame_time) + if (frame_time_accumulator > frame_time_target) frame_time_accumulator = 0; } } diff --git a/gfx/video_driver.h b/gfx/video_driver.h index 5544499742..3a3cbacb20 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -772,7 +772,6 @@ typedef struct #endif struct retro_system_av_info av_info; /* double alignment */ retro_time_t frame_time_samples[MEASURE_FRAME_TIME_SAMPLES_COUNT]; - retro_time_t core_frame_time; uint64_t frame_time_count; uint64_t frame_count; uint8_t *record_gpu_buffer; diff --git a/runloop.c b/runloop.c index 53dd8f3a64..11fab65fb5 100644 --- a/runloop.c +++ b/runloop.c @@ -2674,9 +2674,6 @@ bool runloop_environment_cb(unsigned cmd, void *data) (*info)->timing.sample_rate); memcpy(av_info, *info, sizeof(*av_info)); - video_st->core_frame_time = 1000000 / - ((video_st->av_info.timing.fps > 0.0) ? - video_st->av_info.timing.fps : 60.0); command_event(CMD_EVENT_REINIT, &reinit_flags); @@ -4587,9 +4584,6 @@ static bool runloop_event_load_core(runloop_state_t *runloop_st, core_init_libretro_cbs(runloop_st, &runloop_st->retro_ctx); runloop_st->current_core.retro_get_system_av_info(&video_st->av_info); - video_st->core_frame_time = 1000000 / - ((video_st->av_info.timing.fps > 0.0) ? - video_st->av_info.timing.fps : 60.0); RARCH_LOG("[Core]: Geometry: %ux%u, Aspect: %.3f, FPS: %.2f, Sample rate: %.2f Hz.\n", video_st->av_info.geometry.base_width, video_st->av_info.geometry.base_height,