Skip to content

Commit

Permalink
Revert "Frame limiting improvements"
Browse files Browse the repository at this point in the history
This reverts commit c723710.
  • Loading branch information
LibretroAdmin committed Jun 18, 2023
1 parent edecf0c commit 244c86f
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 125 deletions.
14 changes: 8 additions & 6 deletions audio/audio_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,8 +797,10 @@ bool audio_driver_init_internal(
#endif

/* Threaded driver is initially stopped. */
if ( (audio_driver_st.flags & AUDIO_FLAG_ACTIVE)
&& audio_cb_inited)
if (
(audio_driver_st.flags & AUDIO_FLAG_ACTIVE)
&& audio_cb_inited
)
audio_driver_start(false);

return true;
Expand Down Expand Up @@ -1442,8 +1444,7 @@ void audio_driver_load_system_sounds(void)
task_push_audio_mixer_load(path_ok, NULL, NULL, true, AUDIO_MIXER_SLOT_SELECTION_MANUAL, AUDIO_MIXER_SYSTEM_SLOT_OK);
if (path_cancel && audio_enable_menu_cancel)
task_push_audio_mixer_load(path_cancel, NULL, NULL, true, AUDIO_MIXER_SLOT_SELECTION_MANUAL, AUDIO_MIXER_SYSTEM_SLOT_CANCEL);
if (audio_enable_menu_notice)
{
if (audio_enable_menu_notice) {
if (path_notice)
task_push_audio_mixer_load(path_notice, NULL, NULL, true, AUDIO_MIXER_SLOT_SELECTION_MANUAL, AUDIO_MIXER_SYSTEM_SLOT_NOTICE);
if (path_notice_back)
Expand Down Expand Up @@ -1881,10 +1882,11 @@ void audio_driver_menu_sample(void)
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;
unsigned sample_count = floor(info->sample_rate / info->fps) * 2;
unsigned sample_count = (info->sample_rate / info->fps) * 2;
audio_driver_state_t *audio_st = &audio_driver_st;
bool check_flush = !(
!(audio_st->flags & AUDIO_FLAG_ACTIVE)
(runloop_flags & RUNLOOP_FLAG_PAUSED)
|| !(audio_st->flags & AUDIO_FLAG_ACTIVE)
|| !audio_st->output_samples_buf);
if ((audio_st->flags & AUDIO_FLAG_SUSPENDED))
check_flush = false;
Expand Down
7 changes: 4 additions & 3 deletions audio/audio_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ typedef struct
* up to (but excluding) the point where it's converted to 16-bit audio
* to give to the driver.
*/
float *output_samples_buf;
float *output_samples_buf;
size_t output_samples_buf_length;
#ifdef HAVE_REWIND
int16_t *rewind_buf;
Expand Down Expand Up @@ -229,7 +229,8 @@ typedef struct
size_t buffer_size;
size_t data_ptr;

unsigned free_samples_buf[AUDIO_BUFFER_FREE_SAMPLES_COUNT];
unsigned free_samples_buf[
AUDIO_BUFFER_FREE_SAMPLES_COUNT];

#ifdef HAVE_AUDIOMIXER
float mixer_volume_gain;
Expand All @@ -251,7 +252,7 @@ typedef struct
#endif

/* Sample the flush delta-time when fast forwarding to find the correct
resample ratio. */
ressample ratio. */
retro_time_t last_flush_time;
/* Exponential moving average */
retro_time_t avg_flush_delta;
Expand Down
80 changes: 19 additions & 61 deletions gfx/video_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
#include "../menu/menu_driver.h"
#endif

#ifdef HAVE_NETWORKING
#include "../network/netplay/netplay.h"
#endif

#ifdef _WIN32
#include "common/win32_common.h"
#endif
Expand Down Expand Up @@ -1685,6 +1681,7 @@ void video_driver_set_size(unsigned width, unsigned height)
* false (0) if:
* a) threaded video mode is enabled
* b) less than 2 frame time samples.
* c) FPS monitor enable is off.
**/
bool video_monitor_fps_statistics(double *refresh_rate,
double *deviation, unsigned *sample_points)
Expand Down Expand Up @@ -2532,34 +2529,8 @@ void video_driver_build_info(video_frame_info_t *video_info)
video_info->runloop_is_slowmotion = runloop_st->flags & RUNLOOP_FLAG_SLOWMOTION;
video_info->fastforward_frameskip = settings->bools.fastforward_frameskip;

#ifdef _WIN32
#ifdef HAVE_VULKAN
/* Vulkan in Windows does mailbox emulation
* in fullscreen with vsync, effectively
* discarding frames that can't be shown,
* therefore do not do it twice. */
if ( string_is_equal(video_driver_get_ident(), "vulkan")
&& settings->bools.video_vsync
&& video_info->fullscreen)
video_info->fastforward_frameskip = false;
#endif
#endif

#ifdef HAVE_MENU
/* Count paused running menu also as paused runloop. */
if (video_info->menu_is_alive)
{
#ifdef HAVE_NETWORKING
video_info->runloop_is_paused |= settings->bools.menu_pause_libretro &&
netplay_driver_ctl(RARCH_NETPLAY_CTL_ALLOW_PAUSE, NULL);
#else
video_info->runloop_is_paused |= settings->bools.menu_pause_libretro;
#endif
video_info->runloop_is_paused |= !video_info->libretro_running;
}
#endif

video_info->input_driver_nonblock_state = input_st ? (input_st->flags & INP_FLAG_NONBLOCKING) : false;
video_info->input_driver_nonblock_state = input_st
? (input_st->flags & INP_FLAG_NONBLOCKING) : false;
video_info->input_driver_grab_mouse_state = (input_st->flags & INP_FLAG_GRAB_MOUSE_STATE);
video_info->disp_userdata = disp_get_ptr();

Expand Down Expand Up @@ -3291,7 +3262,6 @@ void video_driver_frame(const void *data, unsigned width,
video_st->frame_cache_width = width;
video_st->frame_cache_height = height;
video_st->frame_cache_pitch = pitch;
video_st->frame_discard = false;

if (
video_st->scaler_ptr
Expand All @@ -3310,30 +3280,23 @@ 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, and when
* paused or menu active, drop any frames
* that occur at a rate higher than display
* frame skipping is enabled, drop any frames
* that occur at a rate higher than the core-set
* refresh rate. However: We must always render
* the current frame when:
* - The menu is open
* - The last frame was NULL and the
* current frame is not (i.e. if core was
* previously sending duped frames, ensure
* that the next frame update is captured) */
if ( ( video_info.input_driver_nonblock_state
&& video_info.fastforward_frameskip
&& !(last_frame_duped && !!data)
)
|| video_info.runloop_is_paused
)
if ( video_info.input_driver_nonblock_state
&& video_info.fastforward_frameskip
&& !(video_info.menu_is_alive
|| (last_frame_duped && !!data)))
{
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 */
Expand All @@ -3342,10 +3305,6 @@ void video_driver_frame(const void *data, unsigned width,
else if (nonblock_active < 0)
nonblock_active = 1;

/* Plain paused and unrestricted menu rendering require harsh limiting */
if (video_info.runloop_is_paused)
video_st->frame_discard = true;

/* Accumulate the elapsed time since the
* last frame */
if (nonblock_active > 0)
Expand All @@ -3354,18 +3313,18 @@ void video_driver_frame(const void *data, unsigned width,
/* Render frame if the accumulated time is
* greater than or equal to the expected
* core frame time */
render_frame = frame_time_accumulator >= frame_time_target;
render_frame = frame_time_accumulator >=
video_st->core_frame_time;

/* If frame is to be rendered, subtract
* expected frame time from accumulator */
if (render_frame)
{
video_st->frame_discard = false;
frame_time_accumulator -= frame_time_target;
frame_time_accumulator -= video_st->core_frame_time;

/* Prevent external frame limiters from
* pushing fast forward ratio down to 1x */
if (frame_time_accumulator + frame_time_accumulator_prev < frame_time_target)
if (frame_time_accumulator + frame_time_accumulator_prev < video_st->core_frame_time)
frame_time_accumulator -= frame_time_delta;

/* If fast forward is working correctly,
Expand All @@ -3377,7 +3336,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 > frame_time_target)
if (frame_time_accumulator > video_st->core_frame_time)
frame_time_accumulator = 0;
}
}
Expand All @@ -3390,9 +3349,6 @@ void video_driver_frame(const void *data, unsigned width,
last_time = new_time;
last_frame_duped = !data;

if (video_st->frame_discard)
return;

/* Get the amount of frames per seconds. */
if (video_st->frame_count)
{
Expand Down Expand Up @@ -3698,7 +3654,6 @@ void video_driver_frame(const void *data, unsigned width,
audio_stats.close_to_underrun = 0.0f;
audio_stats.close_to_blocking = 0.0f;

audio_compute_buffer_statistics(&audio_stats);
video_monitor_fps_statistics(NULL, &stddev, NULL);

video_info.osd_stat_params.x = 0.008f;
Expand All @@ -3710,7 +3665,10 @@ void video_driver_frame(const void *data, unsigned width,
video_info.osd_stat_params.drop_y = (video_info.font_size / DEFAULT_FONT_SIZE) * -3;
video_info.osd_stat_params.drop_mod = 0.1f;
video_info.osd_stat_params.drop_alpha = 0.9f;
video_info.osd_stat_params.color = COLOR_ABGR(alpha, blue, green, red);
video_info.osd_stat_params.color = COLOR_ABGR(
alpha, blue, green, red);

audio_compute_buffer_statistics(&audio_stats);

latency_stats[0] = '\0';
tmp[0] = '\0';
Expand Down
2 changes: 1 addition & 1 deletion gfx/video_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@ 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;
Expand Down Expand Up @@ -867,7 +868,6 @@ typedef struct
uint8_t frame_delay_effective;
bool frame_delay_pause;

bool frame_discard;
bool threaded;
} video_driver_state_t;

Expand Down
Loading

0 comments on commit 244c86f

Please sign in to comment.