From fc670b667f34489933893d8962390f192a6a8f68 Mon Sep 17 00:00:00 2001 From: sonninnos Date: Fri, 10 Nov 2023 14:26:41 +0200 Subject: [PATCH 1/2] Enforce swap interval 1 in menu if vsync is on --- menu/menu_driver.c | 12 ++++++++++++ runloop.c | 6 +++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/menu/menu_driver.c b/menu/menu_driver.c index d816b65c5341..af4d8ee4a6cd 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -6323,6 +6323,9 @@ void menu_driver_toggle( if (menu_driver_alive) { + video_adaptive_vsync = settings->bools.video_adaptive_vsync + && video_driver_test_all_flags(GFX_CTX_FLAGS_ADAPTIVE_VSYNC); + #ifdef WIIU /* Enable burn-in protection menu is running */ IMEnableDim(); @@ -6340,6 +6343,15 @@ void menu_driver_toggle( input_state_get_ptr()->flags &= ~INP_FLAG_NONBLOCKING; driver_set_nonblock_state(); + /* Menu should always run with swap interval 1 if vsync is on. */ + if ( settings->bools.video_vsync + && current_video->set_nonblock_state) + current_video->set_nonblock_state( + video_driver_data, + false, + video_adaptive_vsync, + 1); + /* Stop all rumbling before entering the menu. */ command_event(CMD_EVENT_RUMBLE_STOP, NULL); diff --git a/runloop.c b/runloop.c index 79d57d8dc592..ca10d599dcae 100644 --- a/runloop.c +++ b/runloop.c @@ -6950,10 +6950,10 @@ int runloop_iterate(void) /* Always run menu in video refresh rate speed. */ if (menu_state_get_ptr()->flags & MENU_ST_FLAG_ALIVE) { - float refresh_rate = video_driver_get_refresh_rate(); + float refresh_rate = (video_st->video_refresh_rate_original) + ? video_st->video_refresh_rate_original : settings->floats.video_refresh_rate; - runloop_st->frame_limit_minimum_time = (retro_time_t) - roundf(1000000.0f / ((refresh_rate) ? refresh_rate : settings->floats.video_refresh_rate)); + runloop_st->frame_limit_minimum_time = (retro_time_t)roundf(1000000.0f / refresh_rate); } else runloop_set_frame_limit(&video_st->av_info, settings->floats.fastforward_ratio); From 4bc27c334e88e018b3b1ad00bb0647ff6c40a94d Mon Sep 17 00:00:00 2001 From: sonninnos Date: Fri, 10 Nov 2023 20:04:58 +0200 Subject: [PATCH 2/2] Restore menu_throttle_framerate option --- configuration.c | 1 + configuration.h | 1 + intl/msg_hash_lbl.h | 8 ++++++++ menu/cbs/menu_cbs_sublabel.c | 4 ++++ menu/drivers/ozone.c | 1 + menu/drivers/xmb.c | 1 + menu/menu_displaylist.c | 15 +++++++++++++++ menu/menu_setting.c | 19 +++++++++++++++++++ msg_hash.h | 3 ++- runloop.c | 14 ++++++++++---- runloop.h | 2 +- 11 files changed, 63 insertions(+), 6 deletions(-) diff --git a/configuration.c b/configuration.c index 89e9fe44f791..fd5d0638064b 100644 --- a/configuration.c +++ b/configuration.c @@ -1702,6 +1702,7 @@ static struct config_bool_setting *populate_settings_bool( SETTING_BOOL("rewind_enable", &settings->bools.rewind_enable, true, DEFAULT_REWIND_ENABLE, false); SETTING_BOOL("fastforward_frameskip", &settings->bools.fastforward_frameskip, true, DEFAULT_FASTFORWARD_FRAMESKIP, false); SETTING_BOOL("vrr_runloop_enable", &settings->bools.vrr_runloop_enable, true, DEFAULT_VRR_RUNLOOP_ENABLE, false); + SETTING_BOOL("menu_throttle_framerate", &settings->bools.menu_throttle_framerate, true, true, false); SETTING_BOOL("run_ahead_enabled", &settings->bools.run_ahead_enabled, true, false, false); SETTING_BOOL("run_ahead_secondary_instance", &settings->bools.run_ahead_secondary_instance, true, DEFAULT_RUN_AHEAD_SECONDARY_INSTANCE, false); SETTING_BOOL("run_ahead_hide_warnings", &settings->bools.run_ahead_hide_warnings, true, DEFAULT_RUN_AHEAD_HIDE_WARNINGS, false); diff --git a/configuration.h b/configuration.h index 0a8613b5319e..3478a4cccfac 100644 --- a/configuration.h +++ b/configuration.h @@ -923,6 +923,7 @@ typedef struct settings bool rewind_enable; bool fastforward_frameskip; bool vrr_runloop_enable; + bool menu_throttle_framerate; bool apply_cheats_after_toggle; bool apply_cheats_after_load; bool run_ahead_enabled; diff --git a/intl/msg_hash_lbl.h b/intl/msg_hash_lbl.h index b0dedb079542..21a182628040 100644 --- a/intl/msg_hash_lbl.h +++ b/intl/msg_hash_lbl.h @@ -3323,6 +3323,14 @@ MSG_HASH( MENU_ENUM_LABEL_VRR_RUNLOOP_ENABLE, "vrr_runloop_enable" ) +MSG_HASH( + MENU_ENUM_LABEL_MENU_THROTTLE_FRAMERATE, + "menu_throttle_framerate" + ) +MSG_HASH( + MENU_ENUM_LABEL_MENU_ENUM_THROTTLE_FRAMERATE, + "menu_throttle_framerate" + ) MSG_HASH( MENU_ENUM_LABEL_CHEAT_SETTINGS, "cheat_settings" diff --git a/menu/cbs/menu_cbs_sublabel.c b/menu/cbs/menu_cbs_sublabel.c index 6a534fbd7ae4..b85b0a0a5e7e 100644 --- a/menu/cbs/menu_cbs_sublabel.c +++ b/menu/cbs/menu_cbs_sublabel.c @@ -698,6 +698,7 @@ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_block_sram_overwrite, MENU_ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_fastforward_ratio, MENU_ENUM_SUBLABEL_FASTFORWARD_RATIO) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_fastforward_frameskip, MENU_ENUM_SUBLABEL_FASTFORWARD_FRAMESKIP) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_vrr_runloop_enable, MENU_ENUM_SUBLABEL_VRR_RUNLOOP_ENABLE) +DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_menu_throttle_framerate, MENU_ENUM_SUBLABEL_MENU_ENUM_THROTTLE_FRAMERATE) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_slowmotion_ratio, MENU_ENUM_SUBLABEL_SLOWMOTION_RATIO) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_run_ahead_unsupported, MENU_ENUM_SUBLABEL_RUN_AHEAD_UNSUPPORTED) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_run_ahead_enabled, MENU_ENUM_SUBLABEL_RUN_AHEAD_ENABLED) @@ -4068,6 +4069,9 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs, case MENU_ENUM_LABEL_VRR_RUNLOOP_ENABLE: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_vrr_runloop_enable); break; + case MENU_ENUM_LABEL_MENU_THROTTLE_FRAMERATE: + BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_menu_throttle_framerate); + break; case MENU_ENUM_LABEL_BLOCK_SRAM_OVERWRITE: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_block_sram_overwrite); break; diff --git a/menu/drivers/ozone.c b/menu/drivers/ozone.c index 6cf056ee68ce..f8d5287ef925 100644 --- a/menu/drivers/ozone.c +++ b/menu/drivers/ozone.c @@ -1980,6 +1980,7 @@ static uintptr_t ozone_entries_icon_get_texture( case MENU_ENUM_LABEL_LATENCY_SETTINGS: case MENU_ENUM_LABEL_CONTENT_SHOW_LATENCY: case MENU_ENUM_LABEL_SETTINGS_SHOW_LATENCY: + case MENU_ENUM_LABEL_MENU_THROTTLE_FRAMERATE: case MENU_ENUM_LABEL_VIDEO_FRAME_REST: return ozone->icons_textures[OZONE_ENTRIES_ICONS_TEXTURE_LATENCY]; case MENU_ENUM_LABEL_SAVING_SETTINGS: diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index 841fa7e92c8b..7f91925a0877 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -3186,6 +3186,7 @@ static uintptr_t xmb_icon_get_id(xmb_handle_t *xmb, case MENU_ENUM_LABEL_LATENCY_SETTINGS: case MENU_ENUM_LABEL_CONTENT_SHOW_LATENCY: case MENU_ENUM_LABEL_SETTINGS_SHOW_LATENCY: + case MENU_ENUM_LABEL_MENU_THROTTLE_FRAMERATE: case MENU_ENUM_LABEL_VIDEO_FRAME_REST: return xmb->textures.list[XMB_TEXTURE_LATENCY]; case MENU_ENUM_LABEL_SAVING_SETTINGS: diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index b42fba836143..f384749d631c 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -10920,6 +10920,7 @@ unsigned menu_displaylist_build_list( {MENU_ENUM_LABEL_FASTFORWARD_FRAMESKIP, PARSE_ONLY_BOOL, true}, {MENU_ENUM_LABEL_SLOWMOTION_RATIO, PARSE_ONLY_FLOAT, true}, {MENU_ENUM_LABEL_VRR_RUNLOOP_ENABLE, PARSE_ONLY_BOOL, true}, + {MENU_ENUM_LABEL_MENU_THROTTLE_FRAMERATE, PARSE_ONLY_BOOL, false}, {MENU_ENUM_LABEL_VIDEO_FRAME_REST, PARSE_ONLY_BOOL, true}, }; @@ -10941,6 +10942,20 @@ unsigned menu_displaylist_build_list( } } #endif + + for (i = 0; i < ARRAY_SIZE(build_list); i++) + { + switch (build_list[i].enum_idx) + { + case MENU_ENUM_LABEL_MENU_THROTTLE_FRAMERATE: + if (settings->bools.vrr_runloop_enable) + build_list[i].checked = true; + break; + default: + break; + } + } + for (i = 0; i < ARRAY_SIZE(build_list); i++) { if (!build_list[i].checked && !include_everything) diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 786e163eedac..bbd60c77d505 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -15494,6 +15494,25 @@ static bool setting_append_list( general_read_handler, SD_FLAG_NONE ); + (*list)[list_info->index - 1].action_ok = &setting_bool_action_left_with_refresh; + (*list)[list_info->index - 1].action_left = &setting_bool_action_left_with_refresh; + (*list)[list_info->index - 1].action_right = &setting_bool_action_right_with_refresh; + + CONFIG_BOOL( + list, list_info, + &settings->bools.menu_throttle_framerate, + MENU_ENUM_LABEL_MENU_THROTTLE_FRAMERATE, + MENU_ENUM_LABEL_VALUE_MENU_ENUM_THROTTLE_FRAMERATE, + true, + MENU_ENUM_LABEL_VALUE_OFF, + MENU_ENUM_LABEL_VALUE_ON, + &group_info, + &subgroup_info, + parent_group, + general_write_handler, + general_read_handler, + SD_FLAG_ADVANCED + ); CONFIG_FLOAT( list, list_info, diff --git a/msg_hash.h b/msg_hash.h index e1776cd664be..bade27472b53 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -1739,7 +1739,8 @@ enum msg_hash_enums MENU_ENUM_LABEL_CONNECT_NETPLAY_LAN, MENU_LABEL(MENU_ENUM_LINEAR_FILTER), - MENU_LABEL(MENU_ENUM_THROTTLE_FRAMERATE), /* deprecated */ + MENU_LABEL(MENU_THROTTLE_FRAMERATE), + MENU_LABEL(MENU_ENUM_THROTTLE_FRAMERATE), MENU_LABEL(STATE_SLOT), MENU_ENUM_LABEL_PLAYLIST_SETTINGS_BEGIN, diff --git a/runloop.c b/runloop.c index ca10d599dcae..7a620ac2e5fb 100644 --- a/runloop.c +++ b/runloop.c @@ -6201,7 +6201,7 @@ static enum runloop_state_enum runloop_check_state( #ifdef HAVE_MENU /* Stop checking the rest of the hotkeys if menu is alive */ if (menu_st->flags & MENU_ST_FLAG_ALIVE) - return RUNLOOP_STATE_END; + return RUNLOOP_STATE_MENU; #endif #ifdef HAVE_NETWORKING @@ -6777,7 +6777,7 @@ static enum runloop_state_enum runloop_check_state( } if (menu_was_alive) - return RUNLOOP_STATE_END; + return RUNLOOP_STATE_MENU; return RUNLOOP_STATE_ITERATE; } @@ -6936,7 +6936,7 @@ int runloop_iterate(void) #endif video_driver_cached_frame(); return 1; - case RUNLOOP_STATE_END: + case RUNLOOP_STATE_MENU: #ifdef HAVE_NETWORKING #ifdef HAVE_MENU /* FIXME: This is an ugly way to tell Netplay this... */ @@ -6947,7 +6947,13 @@ int runloop_iterate(void) #endif #endif #ifdef HAVE_MENU - /* Always run menu in video refresh rate speed. */ + /* Rely on vsync throttling unless VRR is enabled and menu throttle is disabled. */ + if (vrr_runloop_enable && !settings->bools.menu_throttle_framerate) + return 0; + else if (settings->bools.video_vsync) + goto end; + + /* Otherwise run menu in video refresh rate speed. */ if (menu_state_get_ptr()->flags & MENU_ST_FLAG_ALIVE) { float refresh_rate = (video_st->video_refresh_rate_original) diff --git a/runloop.h b/runloop.h index 9a8db87ed06c..0376644c5a7d 100644 --- a/runloop.h +++ b/runloop.h @@ -81,7 +81,7 @@ enum runloop_state_enum RUNLOOP_STATE_ITERATE = 0, RUNLOOP_STATE_POLLED_AND_SLEEP, RUNLOOP_STATE_PAUSE, - RUNLOOP_STATE_END, + RUNLOOP_STATE_MENU, RUNLOOP_STATE_QUIT };