diff --git a/command.c b/command.c index 8b9d903622..dab3fbc862 100644 --- a/command.c +++ b/command.c @@ -1295,31 +1295,13 @@ static void command_event_disable_overrides(void) return; /* reload the original config */ - config_unload_override(); rarch_ctl(RARCH_CTL_UNSET_OVERRIDES_ACTIVE, NULL); } static void command_event_restore_default_shader_preset(void) { - if (!path_is_empty(RARCH_PATH_DEFAULT_SHADER_PRESET)) - { - /* auto shader preset: reload the original shader */ - settings_t *settings = config_get_ptr(); - const char *shader_preset = path_get(RARCH_PATH_DEFAULT_SHADER_PRESET); - - if (!string_is_empty(shader_preset)) - { - RARCH_LOG("%s %s\n", - msg_hash_to_str(MSG_RESTORING_DEFAULT_SHADER_PRESET_TO), - shader_preset); - strlcpy(settings->paths.path_shader, - shader_preset, - sizeof(settings->paths.path_shader)); - } - } - - path_clear(RARCH_PATH_DEFAULT_SHADER_PRESET); + retroarch_unset_shader_preset(); } static void command_event_restore_remaps(void) diff --git a/configuration.c b/configuration.c index 8c7b513302..7e4d3360a5 100644 --- a/configuration.c +++ b/configuration.c @@ -1070,6 +1070,8 @@ static struct config_path_setting *populate_settings_path(settings_t *settings, settings->paths.path_core_options, false, NULL, true); SETTING_PATH("libretro_info_path", settings->paths.path_libretro_info, false, NULL, true); + SETTING_PATH("video_shader", + settings->paths.path_shader, false, NULL, true); SETTING_PATH("content_database_path", settings->paths.path_content_database, false, NULL, true); SETTING_PATH("cheat_database_path", @@ -2873,41 +2875,28 @@ static bool config_load_file(const char *path, bool set_defaults, config_read_keybinds_conf(conf); - ret = true; - /* Find a compatible startup shader*/ - if (!string_is_empty(settings->paths.directory_video_shader)) + const char *shader_ext = path_get_extension(settings->paths.path_shader); + + if (!string_is_empty(shader_ext)) { - /* Get the config filename */ - const char *s = path_basename(path_get(RARCH_PATH_CONFIG)); - strlcpy (tmp_str, s, PATH_MAX_LENGTH); - path_remove_extension(tmp_str); - for(i = FILE_PATH_CGP_EXTENSION; i <= FILE_PATH_SLANGP_EXTENSION; i++) { - if (!check_shader_compatibility((enum file_path_enum)(i))) + enum file_path_enum ext = (enum file_path_enum)(i); + if(!strstr(file_path_str(ext), shader_ext)) continue; - /* Build up the startup shader path from the config name and the - supported extensions */ - fill_pathname_join_special_ext(settings->paths.path_shader, - settings->paths.directory_video_shader, "", tmp_str, - file_path_str((enum file_path_enum)(i)), - sizeof(settings->paths.path_shader)); - - /* Check if the shader exists */ - if (!path_is_valid(settings->paths.path_shader)) - { - RARCH_LOG("Shaders: no startup shader found at %s.\n", settings->paths.path_shader); + if (check_shader_compatibility(ext)) continue; - } - /* Game shader preset exists, load it */ - RARCH_LOG("Shaders: startup shader found at %s.\n", settings->paths.path_shader); - - path_set(RARCH_PATH_DEFAULT_SHADER_PRESET, settings->paths.path_shader); - } + RARCH_LOG("Incompatible shader for backend %s, clearing...\n", + settings->arrays.video_driver); + settings->paths.path_shader[0] = '\0'; + break; } +} + + ret = true; end: @@ -3302,9 +3291,7 @@ bool config_load_shader_preset(void) /* Game shader preset exists, load it. */ RARCH_LOG("Shaders: game-specific shader preset found at %s.\n", game_path); - - path_set(RARCH_PATH_DEFAULT_SHADER_PRESET, settings->paths.path_shader); - strlcpy(settings->paths.path_shader, game_path, sizeof(settings->paths.path_shader)); + retroarch_set_shader_preset(game_path); goto success; } @@ -3328,10 +3315,9 @@ bool config_load_shader_preset(void) continue; } - /* Core shader preset exists, load it. */ + /* Parent-dir shader preset exists, load it. */ RARCH_LOG("Shaders: parent-dir-specific shader preset found at %s.\n", parent_path); - path_set(RARCH_PATH_DEFAULT_SHADER_PRESET, settings->paths.path_shader); - strlcpy(settings->paths.path_shader, parent_path, sizeof(settings->paths.path_shader)); + retroarch_set_shader_preset(parent_path); goto success; } @@ -3357,8 +3343,7 @@ bool config_load_shader_preset(void) /* Core shader preset exists, load it. */ RARCH_LOG("Shaders: core-specific shader preset found at %s.\n", core_path); - path_set(RARCH_PATH_DEFAULT_SHADER_PRESET, settings->paths.path_shader); - strlcpy(settings->paths.path_shader, core_path, sizeof(settings->paths.path_shader)); + retroarch_set_shader_preset(core_path); goto success; } diff --git a/gfx/drivers/d3d9.c b/gfx/drivers/d3d9.c index 8a0c81cf83..a95ca5a9aa 100644 --- a/gfx/drivers/d3d9.c +++ b/gfx/drivers/d3d9.c @@ -56,6 +56,7 @@ #include "../../core.h" #include "../../verbosity.h" +#include "../../retroarch.h" static LPDIRECT3D9 g_pD3D9; @@ -1081,7 +1082,7 @@ static bool d3d9_init_internal(d3d_video_t *d3d, if (settings->bools.video_shader_enable) { enum rarch_shader_type type = - video_shader_parse_type(settings->paths.path_shader, + video_shader_parse_type(retroarch_get_shader_preset(), RARCH_SHADER_NONE); switch (type) @@ -1089,8 +1090,8 @@ static bool d3d9_init_internal(d3d_video_t *d3d, case RARCH_SHADER_CG: if (!string_is_empty(d3d->shader_path)) free(d3d->shader_path); - if (!string_is_empty(settings->paths.path_shader)) - d3d->shader_path = strdup(settings->paths.path_shader); + if (!string_is_empty(retroarch_get_shader_preset())) + d3d->shader_path = strdup(retroarch_get_shader_preset()); break; default: break; diff --git a/gfx/drivers/gl.c b/gfx/drivers/gl.c index 48a813a675..202e43ab4c 100644 --- a/gfx/drivers/gl.c +++ b/gfx/drivers/gl.c @@ -379,8 +379,7 @@ static bool gl_shader_init(gl_t *gl, const gfx_ctx_driver_t *ctx_driver, { video_shader_ctx_init_t init_data; settings_t *settings = config_get_ptr(); - const char *shader_path = (settings->bools.video_shader_enable - && *settings->paths.path_shader) ? settings->paths.path_shader : NULL; + const char *shader_path = retroarch_get_shader_preset(); enum rarch_shader_type type = video_shader_parse_type(shader_path, gl->core_context_in_use ? RARCH_SHADER_GLSL : DEFAULT_SHADER_TYPE); diff --git a/gfx/drivers/vulkan.c b/gfx/drivers/vulkan.c index 4351f5562d..5b2de52fa6 100644 --- a/gfx/drivers/vulkan.c +++ b/gfx/drivers/vulkan.c @@ -810,8 +810,7 @@ static bool vulkan_init_filter_chain_preset(vk_t *vk, const char *shader_path) static bool vulkan_init_filter_chain(vk_t *vk) { settings_t *settings = config_get_ptr(); - const char *shader_path = (settings->bools.video_shader_enable && *settings->paths.path_shader) ? - settings->paths.path_shader : NULL; + const char *shader_path = retroarch_get_shader_preset(); enum rarch_shader_type type = video_shader_parse_type(shader_path, RARCH_SHADER_NONE); diff --git a/gfx/drivers_renderchain/d3d9_hlsl_renderchain.c b/gfx/drivers_renderchain/d3d9_hlsl_renderchain.c index 4d8b433960..100f6c60d3 100644 --- a/gfx/drivers_renderchain/d3d9_hlsl_renderchain.c +++ b/gfx/drivers_renderchain/d3d9_hlsl_renderchain.c @@ -296,7 +296,7 @@ static bool hlsl_d3d9_renderchain_init_shader(void *data, init.shader_type = RARCH_SHADER_HLSL; init.data = data; - init.path = settings->paths.path_shader; + init.path = retroarch_get_shader_preset(); init.shader = &hlsl_backend; RARCH_LOG("D3D]: Using HLSL shader backend.\n"); diff --git a/menu/menu_shader.c b/menu/menu_shader.c index 2f3982c345..6fee9be4f2 100644 --- a/menu/menu_shader.c +++ b/menu/menu_shader.c @@ -130,7 +130,7 @@ bool menu_shader_manager_init(void) #ifdef HAVE_SHADER_MANAGER settings_t *settings = config_get_ptr(); const char *config_path = path_get(RARCH_PATH_CONFIG); - const char *path_shader = settings->paths.path_shader; + const char *path_shader = retroarch_get_shader_preset(); menu_shader_manager_free(); diff --git a/retroarch.c b/retroarch.c index a5afe79e6e..bc75699272 100644 --- a/retroarch.c +++ b/retroarch.c @@ -182,6 +182,7 @@ static jmp_buf error_sjlj_context; static enum rarch_core_type current_core_type = CORE_TYPE_PLAIN; static enum rarch_core_type explicit_current_core_type = CORE_TYPE_PLAIN; static char error_string[255] = {0}; +static char runtime_shader_preset[255] = {0}; #ifdef HAVE_THREAD_STORAGE static sthread_tls_t rarch_tls; @@ -1924,6 +1925,36 @@ void retroarch_unset_forced_fullscreen(void) rarch_force_fullscreen = false; } +/* set a runtime shader preset without overwriting the settings value */ +void retroarch_set_shader_preset(char* preset) +{ + if (!string_is_empty(preset)) + strlcpy(runtime_shader_preset, preset, sizeof(runtime_shader_preset)); + else + runtime_shader_preset[0] = '\0'; +} + +/* unset a runtime shader preset */ +void retroarch_unset_shader_preset(void) +{ + runtime_shader_preset[0] = '\0'; +} + +/* get the name of the current shader preset */ +char* retroarch_get_shader_preset(void) +{ + settings_t *settings = config_get_ptr(); + if (!settings->bools.video_shader_enable) + return ""; + + if (!string_is_empty(runtime_shader_preset)) + return runtime_shader_preset; + else if (!string_is_empty(settings->paths.path_shader)) + return settings->paths.path_shader; + else + return ""; +} + bool retroarch_override_setting_is_set(enum rarch_override_setting enum_idx, void *data) { switch (enum_idx) diff --git a/retroarch.h b/retroarch.h index 78c0459c0f..38b40cbe31 100644 --- a/retroarch.h +++ b/retroarch.h @@ -288,6 +288,12 @@ void retroarch_unset_forced_fullscreen(void); void retroarch_set_current_core_type(enum rarch_core_type type, bool explicitly_set); +void retroarch_set_shader_preset(char* preset); + +void retroarch_unset_shader_preset(void); + +char* retroarch_get_shader_preset(void); + /** * retroarch_fail: * @error_code : Error code.