From 3b921ffbfa83a34b329526174f229b26dacb20d9 Mon Sep 17 00:00:00 2001 From: sonninnos <45124675+sonninnos@users.noreply.github.com> Date: Tue, 15 Nov 2022 23:14:09 +0200 Subject: [PATCH] Fix shader toggle and add hotkey + sublabel (#14628) --- command.h | 2 ++ config.def.keybinds.h | 21 +++++++++++++++++++++ configuration.c | 1 + gfx/video_shader_parse.c | 23 +++++++++++++++++++++++ gfx/video_shader_parse.h | 5 ++++- input/input_defines.h | 1 + intl/msg_hash_us.h | 12 ++++++++++++ menu/cbs/menu_cbs_sublabel.c | 8 ++++++++ menu/menu_driver.c | 8 +++++++- menu/menu_setting.c | 22 ++-------------------- msg_hash.h | 3 +++ retroarch.c | 5 +++++ retroarch.cfg | 1 + runloop.c | 10 ++++++---- 14 files changed, 96 insertions(+), 26 deletions(-) diff --git a/command.h b/command.h index f065c71571..c064c8f979 100644 --- a/command.h +++ b/command.h @@ -255,6 +255,7 @@ enum event_command CMD_EVENT_BSV_RECORDING_TOGGLE, CMD_EVENT_SHADER_NEXT, CMD_EVENT_SHADER_PREV, + CMD_EVENT_SHADER_TOGGLE, CMD_EVENT_CHEAT_INDEX_PLUS, CMD_EVENT_CHEAT_INDEX_MINUS, CMD_EVENT_CHEAT_TOGGLE, @@ -463,6 +464,7 @@ static const struct cmd_map map[] = { { "RESET", RARCH_RESET }, { "SHADER_NEXT", RARCH_SHADER_NEXT }, { "SHADER_PREV", RARCH_SHADER_PREV }, + { "SHADER_TOGGLE", RARCH_SHADER_TOGGLE }, { "CHEAT_INDEX_PLUS", RARCH_CHEAT_INDEX_PLUS }, { "CHEAT_INDEX_MINUS", RARCH_CHEAT_INDEX_MINUS }, { "CHEAT_TOGGLE", RARCH_CHEAT_TOGGLE }, diff --git a/config.def.keybinds.h b/config.def.keybinds.h index 8ad3fce221..09c5269c4c 100644 --- a/config.def.keybinds.h +++ b/config.def.keybinds.h @@ -409,6 +409,13 @@ static const struct retro_keybind retro_keybinds_1[] = { RARCH_SHADER_PREV, NO_BTN, NO_BTN, 0, true }, + { + NULL, NULL, + AXIS_NONE, AXIS_NONE, AXIS_NONE, + MENU_ENUM_LABEL_VALUE_INPUT_META_SHADER_TOGGLE, RETROK_UNKNOWN, + RARCH_SHADER_TOGGLE, NO_BTN, NO_BTN, 0, + true + }, { NULL, NULL, AXIS_NONE, AXIS_NONE, AXIS_NONE, @@ -998,6 +1005,13 @@ static const struct retro_keybind retro_keybinds_1[] = { RARCH_SHADER_PREV, NO_BTN, NO_BTN, 0, true }, + { + NULL, NULL, + AXIS_NONE, AXIS_NONE, AXIS_NONE, + MENU_ENUM_LABEL_VALUE_INPUT_META_SHADER_TOGGLE, RETROK_UNKNOWN, + RARCH_SHADER_TOGGLE, NO_BTN, NO_BTN, 0, + true + }, { NULL, NULL, AXIS_NONE, AXIS_NONE, AXIS_NONE, @@ -1597,6 +1611,13 @@ static const struct retro_keybind retro_keybinds_1[] = { RARCH_SHADER_PREV, NO_BTN, NO_BTN, 0, true }, + { + NULL, NULL, + AXIS_NONE, AXIS_NONE, AXIS_NONE, + MENU_ENUM_LABEL_VALUE_INPUT_META_SHADER_TOGGLE, RETROK_COMMA, + RARCH_SHADER_TOGGLE, NO_BTN, NO_BTN, 0, + true + }, { NULL, NULL, AXIS_NONE, AXIS_NONE, AXIS_NONE, diff --git a/configuration.c b/configuration.c index a64d3ccd8c..168d42be57 100644 --- a/configuration.c +++ b/configuration.c @@ -329,6 +329,7 @@ const struct input_bind_map input_config_bind_map[RARCH_BIND_LIST_END_NULL] = { DECLARE_META_BIND(2, reset, RARCH_RESET, MENU_ENUM_LABEL_VALUE_INPUT_META_RESET), DECLARE_META_BIND(2, shader_next, RARCH_SHADER_NEXT, MENU_ENUM_LABEL_VALUE_INPUT_META_SHADER_NEXT), DECLARE_META_BIND(2, shader_prev, RARCH_SHADER_PREV, MENU_ENUM_LABEL_VALUE_INPUT_META_SHADER_PREV), + DECLARE_META_BIND(2, shader_toggle, RARCH_SHADER_TOGGLE, MENU_ENUM_LABEL_VALUE_INPUT_META_SHADER_TOGGLE), DECLARE_META_BIND(2, cheat_index_plus, RARCH_CHEAT_INDEX_PLUS, MENU_ENUM_LABEL_VALUE_INPUT_META_CHEAT_INDEX_PLUS), DECLARE_META_BIND(2, cheat_index_minus, RARCH_CHEAT_INDEX_MINUS, MENU_ENUM_LABEL_VALUE_INPUT_META_CHEAT_INDEX_MINUS), DECLARE_META_BIND(2, cheat_toggle, RARCH_CHEAT_TOGGLE, MENU_ENUM_LABEL_VALUE_INPUT_META_CHEAT_TOGGLE), diff --git a/gfx/video_shader_parse.c b/gfx/video_shader_parse.c index 29820bc574..0d2104bfae 100644 --- a/gfx/video_shader_parse.c +++ b/gfx/video_shader_parse.c @@ -2653,3 +2653,26 @@ const char *retroarch_get_shader_preset(void) return NULL; } + +void video_shader_toggle(settings_t *settings) +{ + bool toggle = !settings->bools.video_shader_enable; + bool refresh = false; + struct video_shader *shader = menu_shader_get(); + + shader->flags |= SHDR_FLAG_MODIFIED; + if (toggle) + shader->flags &= ~SHDR_FLAG_DISABLED; + else + shader->flags |= SHDR_FLAG_DISABLED; + + menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh); + menu_driver_ctl(RARCH_MENU_CTL_SET_PREVENT_POPULATE, NULL); + + command_event(CMD_EVENT_SHADERS_APPLY_CHANGES, NULL); + + /* TODO/FIXME: Due to general_write_handler being called twice, + * this has be done in this order in order to truly disable */ + if (!toggle) + configuration_set_bool(settings, settings->bools.video_shader_enable, toggle); +} diff --git a/gfx/video_shader_parse.h b/gfx/video_shader_parse.h index e1defe8b8f..8aa5361fbd 100644 --- a/gfx/video_shader_parse.h +++ b/gfx/video_shader_parse.h @@ -153,7 +153,8 @@ enum video_shader_flags SHDR_FLAG_MODERN = (1 << 0), /* Only used for XML shaders. */ /* Indicative of whether shader was modified - * for instance from the menus */ - SHDR_FLAG_MODIFIED = (1 << 1) + SHDR_FLAG_MODIFIED = (1 << 1), + SHDR_FLAG_DISABLED = (1 << 2) }; /* This is pretty big, shouldn't be put on the stack. @@ -316,6 +317,8 @@ bool apply_shader( const char *video_shader_get_preset_extension(enum rarch_shader_type type); +void video_shader_toggle(settings_t *settings); + RETRO_END_DECLS #endif diff --git a/input/input_defines.h b/input/input_defines.h index 2a4255a285..1a2ee0b51a 100644 --- a/input/input_defines.h +++ b/input/input_defines.h @@ -93,6 +93,7 @@ enum RARCH_RESET, RARCH_SHADER_NEXT, RARCH_SHADER_PREV, + RARCH_SHADER_TOGGLE, RARCH_CHEAT_INDEX_PLUS, RARCH_CHEAT_INDEX_MINUS, RARCH_CHEAT_TOGGLE, diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index 1e600e56fb..ec41756d7e 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -2898,6 +2898,14 @@ MSG_HASH( MENU_ENUM_SUBLABEL_INPUT_META_SHADER_PREV, "Loads and applies the previous shader preset file in the root of the 'Video Shaders' directory." ) +MSG_HASH( + MENU_ENUM_LABEL_VALUE_INPUT_META_SHADER_TOGGLE, + "Shader (Toggle)" + ) +MSG_HASH( + MENU_ENUM_SUBLABEL_INPUT_META_SHADER_TOGGLE, + "Switches the currently selected shader on/off." + ) MSG_HASH( MENU_ENUM_LABEL_VALUE_INPUT_META_CHEAT_INDEX_PLUS, "Next Cheat Index" @@ -7974,6 +7982,10 @@ MSG_HASH( MENU_ENUM_LABEL_VALUE_VIDEO_SHADERS_ENABLE, "Video Shaders" ) +MSG_HASH( + MENU_ENUM_SUBLABEL_VIDEO_SHADERS_ENABLE, + "Enable video shader pipeline." + ) MSG_HASH( MENU_ENUM_LABEL_VALUE_SHADER_WATCH_FOR_CHANGES, "Watch Shader Files for Changes" diff --git a/menu/cbs/menu_cbs_sublabel.c b/menu/cbs/menu_cbs_sublabel.c index 6b246045e6..a1fd2b8539 100644 --- a/menu/cbs/menu_cbs_sublabel.c +++ b/menu/cbs/menu_cbs_sublabel.c @@ -392,6 +392,7 @@ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_meta_frameadvance, ME DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_meta_reset, MENU_ENUM_SUBLABEL_INPUT_META_RESET) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_meta_shader_next, MENU_ENUM_SUBLABEL_INPUT_META_SHADER_NEXT) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_meta_shader_prev, MENU_ENUM_SUBLABEL_INPUT_META_SHADER_PREV) +DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_meta_shader_toggle, MENU_ENUM_SUBLABEL_INPUT_META_SHADER_TOGGLE) #ifdef HAVE_CHEATS DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_meta_cheat_index_plus, MENU_ENUM_SUBLABEL_INPUT_META_CHEAT_INDEX_PLUS) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_meta_cheat_index_minus, MENU_ENUM_SUBLABEL_INPUT_META_CHEAT_INDEX_MINUS) @@ -1037,6 +1038,7 @@ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_shader_directory, DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_recording_output_directory, MENU_ENUM_SUBLABEL_RECORDING_OUTPUT_DIRECTORY) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_recording_config_directory, MENU_ENUM_SUBLABEL_RECORDING_CONFIG_DIRECTORY) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_font_path, MENU_ENUM_SUBLABEL_VIDEO_FONT_PATH) +DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_shaders_enable, MENU_ENUM_SUBLABEL_VIDEO_SHADERS_ENABLE) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_shader_apply_changes, MENU_ENUM_SUBLABEL_SHADER_APPLY_CHANGES) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_shader_watch_for_changes, MENU_ENUM_SUBLABEL_SHADER_WATCH_FOR_CHANGES) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_shader_remember_last_dir, MENU_ENUM_SUBLABEL_VIDEO_SHADER_REMEMBER_LAST_DIR) @@ -2130,6 +2132,9 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs, case RARCH_SHADER_PREV: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_meta_shader_prev); return 0; + case RARCH_SHADER_TOGGLE: + BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_meta_shader_toggle); + return 0; case RARCH_CHEAT_INDEX_PLUS: #ifdef HAVE_CHEATS BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_meta_cheat_index_plus); @@ -2452,6 +2457,9 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs, case MENU_ENUM_LABEL_VIDEO_SHADER_NUM_PASSES: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_shader_num_passes); break; + case MENU_ENUM_LABEL_VIDEO_SHADERS_ENABLE: + BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_video_shaders_enable); + break; case MENU_ENUM_LABEL_SHADER_APPLY_CHANGES: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_shader_apply_changes); break; diff --git a/menu/menu_driver.c b/menu/menu_driver.c index fc159c68e2..2eb83c5256 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -2908,7 +2908,9 @@ void menu_shader_manager_apply_changes( type = menu_shader_manager_get_type(shader); - if (shader->passes && type != RARCH_SHADER_NONE) + if (shader->passes + && type != RARCH_SHADER_NONE + && !(shader->flags & SHDR_FLAG_DISABLED)) { menu_shader_manager_save_preset(shader, NULL, dir_video_shader, dir_menu_config, true); @@ -3554,8 +3556,12 @@ bool rarch_menu_init( } #endif +#if 0 + /* TODO: No reason to do this here since shaders need + * content, and this is called in content_load() */ #if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL) menu_shader_manager_init(); +#endif #endif return true; diff --git a/menu/menu_setting.c b/menu/menu_setting.c index ba34c1c3f5..e3f93ac84e 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -7863,26 +7863,8 @@ static void general_write_handler(rarch_setting_t *setting) case MENU_ENUM_LABEL_VIDEO_SHADERS_ENABLE: #if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL) { - if (*setting->value.target.boolean) - { - bool refresh = false; - menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh); - menu_driver_ctl(RARCH_MENU_CTL_SET_PREVENT_POPULATE, NULL); - } - else - { - bool refresh = false; - settings_t *settings = config_get_ptr(); - struct video_shader *shader = menu_shader_get(); - - shader->passes = 0; - shader->flags |= SHDR_FLAG_MODIFIED; - - menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh); - menu_driver_ctl(RARCH_MENU_CTL_SET_PREVENT_POPULATE, NULL); - command_event(CMD_EVENT_SHADERS_APPLY_CHANGES, NULL); - configuration_set_bool(settings, settings->bools.video_shader_enable, false); - } + settings_t *settings = config_get_ptr(); + video_shader_toggle(settings); } #endif break; diff --git a/msg_hash.h b/msg_hash.h index 134d3db280..201d653c64 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -914,6 +914,7 @@ enum msg_hash_enums MENU_ENUM_LABEL_VALUE_INPUT_META_RESET, MENU_ENUM_LABEL_VALUE_INPUT_META_SHADER_NEXT, MENU_ENUM_LABEL_VALUE_INPUT_META_SHADER_PREV, + MENU_ENUM_LABEL_VALUE_INPUT_META_SHADER_TOGGLE, MENU_ENUM_LABEL_VALUE_INPUT_META_CHEAT_INDEX_PLUS, MENU_ENUM_LABEL_VALUE_INPUT_META_CHEAT_INDEX_MINUS, MENU_ENUM_LABEL_VALUE_INPUT_META_CHEAT_TOGGLE, @@ -976,6 +977,7 @@ enum msg_hash_enums MENU_ENUM_SUBLABEL_INPUT_META_RESET, MENU_ENUM_SUBLABEL_INPUT_META_SHADER_NEXT, MENU_ENUM_SUBLABEL_INPUT_META_SHADER_PREV, + MENU_ENUM_SUBLABEL_INPUT_META_SHADER_TOGGLE, MENU_ENUM_SUBLABEL_INPUT_META_CHEAT_INDEX_PLUS, MENU_ENUM_SUBLABEL_INPUT_META_CHEAT_INDEX_MINUS, MENU_ENUM_SUBLABEL_INPUT_META_CHEAT_TOGGLE, @@ -1886,6 +1888,7 @@ enum msg_hash_enums MENU_LABEL(CHEAT_INDEX_PLUS), MENU_LABEL(SHADER_NEXT), MENU_LABEL(SHADER_PREV), + MENU_LABEL(SHADER_TOGGLE), MENU_LABEL(FRAME_ADVANCE), MENU_LABEL(FPS_SHOW), MENU_LABEL(FPS_UPDATE_INTERVAL), diff --git a/retroarch.c b/retroarch.c index b1aacdcbb4..956616b0b9 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1533,6 +1533,11 @@ bool command_event(enum event_command cmd, void *data) dir_check_shader(NULL, settings, &video_st->dir_shader_list, false, true); #endif +#endif + break; + case CMD_EVENT_SHADER_TOGGLE: +#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL) + video_shader_toggle(settings); #endif break; case CMD_EVENT_BSV_RECORDING_TOGGLE: diff --git a/retroarch.cfg b/retroarch.cfg index 21052c2541..ce951b282e 100644 --- a/retroarch.cfg +++ b/retroarch.cfg @@ -580,6 +580,7 @@ # Applies next and previous shader in directory. # input_shader_next = m # input_shader_prev = n +# input_shader_toggle = comma # Hold button down to rewind. Rewinding must be enabled. # input_rewind = r diff --git a/runloop.c b/runloop.c index ae2a72b3e2..5e9c1b0b85 100644 --- a/runloop.c +++ b/runloop.c @@ -7565,10 +7565,6 @@ static enum runloop_state_enum runloop_check_state( /* Check movie record toggle */ HOTKEY_CHECK(RARCH_BSV_RECORD_TOGGLE, CMD_EVENT_BSV_RECORDING_TOGGLE, true, NULL); - /* Check shader prev/next */ - HOTKEY_CHECK(RARCH_SHADER_NEXT, CMD_EVENT_SHADER_NEXT, true, NULL); - HOTKEY_CHECK(RARCH_SHADER_PREV, CMD_EVENT_SHADER_PREV, true, NULL); - /* Check if we have pressed any of the disk buttons */ HOTKEY_CHECK3( RARCH_DISK_EJECT_TOGGLE, CMD_EVENT_DISK_EJECT_TOGGLE, @@ -7585,6 +7581,12 @@ static enum runloop_state_enum runloop_check_state( RARCH_CHEAT_TOGGLE, CMD_EVENT_CHEAT_TOGGLE); #if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL) + /* Check shader prev/next/toggle */ + HOTKEY_CHECK3( + RARCH_SHADER_NEXT, CMD_EVENT_SHADER_NEXT, + RARCH_SHADER_PREV, CMD_EVENT_SHADER_PREV, + RARCH_SHADER_TOGGLE, CMD_EVENT_SHADER_TOGGLE); + if (settings->bools.video_shader_watch_files) { static rarch_timer_t timer = {0};