From 8a1f23ef24f2cb2daba6132e882f22d0804f9130 Mon Sep 17 00:00:00 2001 From: notaz Date: Tue, 15 Oct 2024 03:10:44 +0300 Subject: [PATCH] libretro: show the actual fps, some extra stats --- frontend/libretro.c | 63 ++++++++++++++++++--------- frontend/libretro_core_options.h | 20 +-------- frontend/main.c | 1 + libpcsxcore/cdrom-async.c | 20 +++++++++ libpcsxcore/cdrom-async.h | 1 + libpcsxcore/new_dynarec/new_dynarec.c | 2 +- 6 files changed, 67 insertions(+), 40 deletions(-) diff --git a/frontend/libretro.c b/frontend/libretro.c index ce0e7427..c932625f 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -72,8 +72,6 @@ #define ISHEXDEC ((buf[cursor] >= '0') && (buf[cursor] <= '9')) || ((buf[cursor] >= 'a') && (buf[cursor] <= 'f')) || ((buf[cursor] >= 'A') && (buf[cursor] <= 'F')) -#define INTERNAL_FPS_SAMPLE_PERIOD 64 - //hack to prevent retroarch freezing when reseting in the menu but not while running with the hot key static int rebootemu = 0; @@ -102,8 +100,7 @@ static int vout_fb_dirty; static int psx_w, psx_h; static bool vout_can_dupe; static bool found_bios; -static bool display_internal_fps = false; -static unsigned frame_count = 0; +static int display_internal_fps; static bool libretro_supports_bitmasks = false; static bool libretro_supports_option_categories = false; static bool show_input_settings = true; @@ -1769,8 +1766,6 @@ bool retro_load_game(const struct retro_game_info *info) { 0 }, }; - frame_count = 0; - environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc); #ifdef FRONTEND_SUPPORTS_RGB565 @@ -2232,14 +2227,16 @@ static void update_variables(bool in_flight) #endif var.value = NULL; - var.key = "pcsx_rearmed_display_internal_fps"; + var.key = "pcsx_rearmed_display_fps_v2"; if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { - if (strcmp(var.value, "disabled") == 0) - display_internal_fps = false; + if (strcmp(var.value, "extra") == 0) + display_internal_fps = 2; else if (strcmp(var.value, "enabled") == 0) - display_internal_fps = true; + display_internal_fps = 1; + else + display_internal_fps = 0; } var.value = NULL; @@ -3164,24 +3161,50 @@ static void print_internal_fps(void) { if (display_internal_fps) { - frame_count++; + static u32 fps, frame_count_s; + static time_t last_time; + static u32 psx_vsync_count; + u32 psx_vsync_rate = is_pal_mode ? 50 : 60; + time_t now; - if (frame_count % INTERNAL_FPS_SAMPLE_PERIOD == 0) + psx_vsync_count++; + frame_count_s++; + now = time(NULL); + if (now != last_time) { - unsigned internal_fps = pl_rearmed_cbs.flip_cnt * (is_pal_mode ? 50 : 60) / INTERNAL_FPS_SAMPLE_PERIOD; - char str[64]; - const char *strc = (const char *)str; + fps = frame_count_s; + frame_count_s = 0; + last_time = now; + } - str[0] = '\0'; + if (psx_vsync_count >= psx_vsync_rate) + { + int pos = 0, cd_count; + char str[64]; - snprintf(str, sizeof(str), "Internal FPS: %2d", internal_fps); + if (display_internal_fps > 1) { +#if !defined(DRC_DISABLE) && !defined(LIGHTREC) + if (ndrc_g.did_compile) { + pos = snprintf(str, sizeof(str), "DRC: %d ", ndrc_g.did_compile); + ndrc_g.did_compile = 0; + } +#endif + cd_count = cdra_get_buf_count(); + if (cd_count) { + pos += snprintf(str + pos, sizeof(str) - pos, "CD: %2d/%d ", + cdra_get_buf_cached_approx(), cd_count); + } + } + snprintf(str + pos, sizeof(str) - pos, "FPS: %2d/%2d", + pl_rearmed_cbs.flip_cnt, fps); pl_rearmed_cbs.flip_cnt = 0; + psx_vsync_count = 0; if (msg_interface_version >= 1) { struct retro_message_ext msg = { - strc, + str, 3000, 1, RETRO_LOG_INFO, @@ -3194,15 +3217,13 @@ static void print_internal_fps(void) else { struct retro_message msg = { - strc, + str, 180 }; environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, &msg); } } } - else - frame_count = 0; } void retro_run(void) diff --git a/frontend/libretro_core_options.h b/frontend/libretro_core_options.h index 8910ad23..384c58a5 100644 --- a/frontend/libretro_core_options.h +++ b/frontend/libretro_core_options.h @@ -163,23 +163,6 @@ struct retro_core_option_v2_definition option_defs_us[] = { }, "disabled", }, -#if 0 // ndef _WIN32 // currently disabled, see USE_READ_THREAD in libpcsxcore/cdriso.c - { - "pcsx_rearmed_async_cd", - "CD Access Method (Restart)", - NULL, - "Select method used to read data from content disk images. 'Synchronous' mimics original hardware. 'Asynchronous' can reduce stuttering on devices with slow storage. 'Pre-Cache (CHD)' loads disk image into memory for faster access (CHD files only).", - NULL, - "system", - { - { "sync", "Synchronous" }, - { "async", "Asynchronous" }, - { "precache", "Pre-Cache (CHD)" }, - { NULL, NULL}, - }, - "sync", - }, -#endif #if defined(HAVE_CDROM) || defined(USE_ASYNC_CDROM) #define V(x) { #x, NULL } { @@ -437,7 +420,7 @@ struct retro_core_option_v2_definition option_defs_us[] = { "3" }, { - "pcsx_rearmed_display_internal_fps", + "pcsx_rearmed_display_fps_v2", "Display Internal FPS", NULL, "Show the internal frame rate at which the emulated PlayStation system is rendering content. Note: Requires on-screen notifications to be enabled in the libretro frontend.", @@ -446,6 +429,7 @@ struct retro_core_option_v2_definition option_defs_us[] = { { { "disabled", NULL }, { "enabled", NULL }, + { "extra", NULL }, { NULL, NULL }, }, "disabled", diff --git a/frontend/main.c b/frontend/main.c index 949ba65b..607426b8 100644 --- a/frontend/main.c +++ b/frontend/main.c @@ -513,6 +513,7 @@ int emu_core_preinit(void) int emu_core_init(void) { SysPrintf("Starting PCSX-ReARMed " REV "%s\n", get_build_info()); + SysPrintf("build time: " __DATE__ " " __TIME__ "\n"); pcsxr_sthread_init(); #ifndef NO_FRONTEND diff --git a/libpcsxcore/cdrom-async.c b/libpcsxcore/cdrom-async.c index 81b2e12a..fadb774a 100644 --- a/libpcsxcore/cdrom-async.c +++ b/libpcsxcore/cdrom-async.c @@ -490,6 +490,25 @@ int cdra_get_buf_count(void) { return acdrom.buf_cnt; } + +int cdra_get_buf_cached_approx(void) +{ + u32 buf_cnt = acdrom.buf_cnt, lba = acdrom.prefetch_lba; + u32 total = acdrom.total_lba; + u32 left = buf_cnt; + int buf_use = 0; + + if (left > total) + left = total; + for (; lba < total && left > 0; lba++, left--) + if (lba == acdrom.buf_cache[lba % buf_cnt].lba) + buf_use++; + for (lba = 0; left > 0; lba++, left--) + if (lba == acdrom.buf_cache[lba % buf_cnt].lba) + buf_use++; + + return buf_use; +} #else // phys. CD-ROM without a cache is unusable so not implemented @@ -565,6 +584,7 @@ int cdra_check_eject(int *inserted) { return 0; } void cdra_stop_thread(void) {} void cdra_set_buf_count(int newcount) {} int cdra_get_buf_count(void) { return 0; } +int cdra_get_buf_cached_approx(void) { return 0; } #endif diff --git a/libpcsxcore/cdrom-async.h b/libpcsxcore/cdrom-async.h index 22747a85..c72ca9c7 100644 --- a/libpcsxcore/cdrom-async.h +++ b/libpcsxcore/cdrom-async.h @@ -22,6 +22,7 @@ int cdra_check_eject(int *inserted); void cdra_stop_thread(void); void cdra_set_buf_count(int count); int cdra_get_buf_count(void); +int cdra_get_buf_cached_approx(void); void *cdra_getBuffer(void); diff --git a/libpcsxcore/new_dynarec/new_dynarec.c b/libpcsxcore/new_dynarec/new_dynarec.c index c2899e42..6243db46 100644 --- a/libpcsxcore/new_dynarec/new_dynarec.c +++ b/libpcsxcore/new_dynarec/new_dynarec.c @@ -9018,7 +9018,7 @@ static int new_recompile_block(u_int addr) } start = addr; - ndrc_g.did_compile = 1; + ndrc_g.did_compile++; if (Config.HLE && start == 0x80001000) // hlecall { void *beginning = start_block(); -- 2.39.5