From 13942b75ad601f931088c3d6841321baa2c70071 Mon Sep 17 00:00:00 2001 From: notaz Date: Wed, 28 Jan 2026 02:46:28 +0200 Subject: [PATCH] libretro: update frameskip logic As PSX usually runs at 20fps or so, underruns were not noticed because the following frame after underrun libretro would indicate none, but the core's logic would only evaluate it when the game flips the buffers, which is like every 3rd frame or so. With that frameskip on slow devices was pretty much ineffective. --- frontend/libretro.c | 32 +++++++++++++++++--------------- frontend/libretro_core_options.h | 4 ++++ plugins/gpulib/gpu.c | 1 + plugins/gpulib/gpu.h | 2 +- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/frontend/libretro.c b/frontend/libretro.c index aad3c00b..a7ad22ed 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -1777,7 +1777,7 @@ static void retro_audio_buff_status_cb( { retro_audio_buff_active = active; retro_audio_buff_occupancy = occupancy; - retro_audio_buff_underrun = underrun_likely; + retro_audio_buff_underrun |= underrun_likely; } static void retro_set_audio_buff_status_cb(void) @@ -1815,8 +1815,8 @@ static void retro_set_audio_buff_status_cb(void) * buffer underruns */ uint32_t frame_time_usec = 1000000.0 / (is_pal_mode ? 50.0 : 60.0); - /* Set latency to 6x current frame time... */ - retro_audio_latency = (unsigned)(6 * frame_time_usec / 1000); + /* Set latency... */ + retro_audio_latency = (unsigned)((4 + frameskip_interval * 2) * frame_time_usec / 1000); /* ...then round up to nearest multiple of 32 */ retro_audio_latency = (retro_audio_latency + 0x1F) & ~0x1F; @@ -1825,6 +1825,7 @@ static void retro_set_audio_buff_status_cb(void) update_audio_latency = true; frameskip_counter = 0; + pl_rearmed_cbs.fskip_force = 0; } static void update_variables(bool in_flight); @@ -3353,12 +3354,9 @@ void retro_run(void) set_vout_fb(); print_internal_fps(); - /* Check whether current frame should - * be skipped */ - pl_rearmed_cbs.fskip_force = 0; - pl_rearmed_cbs.fskip_dirty = 0; - - if (frameskip_type != FRAMESKIP_NONE) + /* Check whether current frame should be skipped */ + if (frameskip_type != FRAMESKIP_NONE && !pl_rearmed_cbs.fskip_force && + frameskip_counter < frameskip_interval) { bool skip_frame = false; @@ -3377,8 +3375,7 @@ void retro_run(void) break; } - if (skip_frame && frameskip_counter < frameskip_interval) - pl_rearmed_cbs.fskip_force = 1; + pl_rearmed_cbs.fskip_force = skip_frame; } /* If frameskip/timing settings have changed, @@ -3404,11 +3401,16 @@ void retro_run(void) psxRegs.stop = 0; psxCpu->Execute(&psxRegs); - if (pl_rearmed_cbs.fskip_dirty == 1) { - if (frameskip_counter < frameskip_interval) - frameskip_counter++; - else if (frameskip_counter >= frameskip_interval || !pl_rearmed_cbs.fskip_force) + if (pl_rearmed_cbs.fskip_dirty) { + if (frameskip_counter >= frameskip_interval || !pl_rearmed_cbs.fskip_force) frameskip_counter = 0; + else + frameskip_counter++; + + if (pl_rearmed_cbs.fskip_force) + retro_audio_buff_underrun = false; + pl_rearmed_cbs.fskip_force = 0; + pl_rearmed_cbs.fskip_dirty = 0; } video_cb((vout_fb_dirty || !vout_can_dupe) ? vout_buf_ptr : NULL, diff --git a/frontend/libretro_core_options.h b/frontend/libretro_core_options.h index dc0d4d7a..46b18831 100644 --- a/frontend/libretro_core_options.h +++ b/frontend/libretro_core_options.h @@ -385,6 +385,10 @@ struct retro_core_option_v2_definition option_defs_us[] = { { "54", NULL }, { "57", NULL }, { "60", NULL }, + { "65", NULL }, + { "70", NULL }, + { "75", NULL }, + { "80", NULL }, { NULL, NULL }, }, "33" diff --git a/plugins/gpulib/gpu.c b/plugins/gpulib/gpu.c index dca0e806..adbfad6b 100644 --- a/plugins/gpulib/gpu.c +++ b/plugins/gpulib/gpu.c @@ -228,6 +228,7 @@ static noinline void decide_frameskip(struct psx_gpu *gpu, uint32_t flip_delay) gpu->frameskip.frame_ready = 1; } + // note: frontend/libretro only uses 'force' if (*gpu->frameskip.force) gpu->frameskip.active = 1; else if (!gpu->frameskip.active && *gpu->frameskip.advice) diff --git a/plugins/gpulib/gpu.h b/plugins/gpulib/gpu.h index 66d2e398..16bfedf9 100644 --- a/plugins/gpulib/gpu.h +++ b/plugins/gpulib/gpu.h @@ -18,7 +18,7 @@ //#define RAW_FB_DISPLAY #define gpu_log(gpu, fmt, ...) \ - printf("%d:%03d: " fmt, *(gpu)->state.frame_count, *(gpu)->state.hcnt, ##__VA_ARGS__) + SysPrintf("%d:%03d: " fmt, *(gpu)->state.frame_count, *(gpu)->state.hcnt, ##__VA_ARGS__) #ifdef LOG_UNHANDLED #define log_anomaly gpu_log -- 2.47.3