Skip to content

Commit

Permalink
Enforce swap interval 1 in menu if vsync is on + Restore menu_throttl…
Browse files Browse the repository at this point in the history
…e_framerate option (#15889)

* Enforce swap interval 1 in menu if vsync is on

* Restore menu_throttle_framerate option
  • Loading branch information
sonninnos authored Nov 11, 2023
1 parent b5303e3 commit 9b97b40
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 9 deletions.
1 change: 1 addition & 0 deletions configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions intl/msg_hash_lbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions menu/cbs/menu_cbs_sublabel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions menu/drivers/ozone.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions menu/drivers/xmb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 15 additions & 0 deletions menu/menu_displaylist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};

Expand All @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions menu/menu_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);

Expand Down
19 changes: 19 additions & 0 deletions menu/menu_setting.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion msg_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 13 additions & 7 deletions runloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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... */
Expand All @@ -6947,13 +6947,19 @@ 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_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);
Expand Down
2 changes: 1 addition & 1 deletion runloop.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down

0 comments on commit 9b97b40

Please sign in to comment.