diff --git a/file_path_special.h b/file_path_special.h index 60449a4feb8..95bcae937dd 100644 --- a/file_path_special.h +++ b/file_path_special.h @@ -36,6 +36,7 @@ RETRO_BEGIN_DECLS #define FILE_PATH_CGP_EXTENSION ".cgp" #define FILE_PATH_GLSLP_EXTENSION ".glslp" #define FILE_PATH_SLANGP_EXTENSION ".slangp" +#define FILE_PATH_METAP_EXTENSION ".metap" #define FILE_PATH_AUTO_EXTENSION ".auto" #define FILE_PATH_BSV_EXTENSION ".bsv" #define FILE_PATH_OPT_EXTENSION ".opt" diff --git a/gfx/drivers/d3d10.c b/gfx/drivers/d3d10.c index c76b0dd25df..6e32f1b7477 100644 --- a/gfx/drivers/d3d10.c +++ b/gfx/drivers/d3d10.c @@ -408,6 +408,9 @@ static bool d3d10_gfx_set_shader(void* data, enum rarch_shader_type type, const if (string_is_empty(path)) return true; + // Need to get the shader type from the preset, it would be better if we passed in the preset and + // copied it instead of loading it, and test the root preset type + if (type != RARCH_SHADER_SLANG) { RARCH_WARN("[D3D10]: Only Slang shaders are supported. Falling back to stock.\n"); @@ -1056,6 +1059,7 @@ static void *d3d10_gfx_init(const video_info_t* video, video_context_driver_set(&d3d10_fake_context); #ifdef HAVE_SLANG const char *shader_preset = video_shader_get_current_shader_preset(); + // Need to set correct type here enum rarch_shader_type type = video_shader_parse_type(shader_preset); d3d10_gfx_set_shader(d3d10, type, shader_preset); #endif diff --git a/gfx/drivers_shader/shader_gl_cg.c b/gfx/drivers_shader/shader_gl_cg.c index 18386a9e5c4..e028b63b78a 100644 --- a/gfx/drivers_shader/shader_gl_cg.c +++ b/gfx/drivers_shader/shader_gl_cg.c @@ -975,8 +975,10 @@ static void *gl_cg_init(void *data, const char *path) { bool is_preset; - enum rarch_shader_type type = - video_shader_get_type_from_ext(path_get_extension(path), &is_preset); + // enum rarch_shader_type type = + // video_shader_get_type_from_ext(path_get_extension(path), &is_preset); + + enum rarch_shader_type type = video_shader_get_shader_type_from_preset_or_shader(path, &is_preset); if (!string_is_empty(path) && type != RARCH_SHADER_CG) { diff --git a/gfx/drivers_shader/shader_glsl.c b/gfx/drivers_shader/shader_glsl.c index d16244156cf..8b3829141bb 100644 --- a/gfx/drivers_shader/shader_glsl.c +++ b/gfx/drivers_shader/shader_glsl.c @@ -1020,8 +1020,9 @@ static void *gl_glsl_init(void *data, const char *path) { bool is_preset; - enum rarch_shader_type type = - video_shader_get_type_from_ext(path_get_extension(path), &is_preset); + // enum rarch_shader_type type = video_shader_parse_type(path); + // video_shader_get_type_from_ext(path_get_extension(path), &is_preset); + enum rarch_shader_type type = video_shader_get_shader_type_from_preset_or_shader(path, &is_preset); if (!string_is_empty(path) && type != RARCH_SHADER_GLSL) { diff --git a/gfx/video_shader_parse.c b/gfx/video_shader_parse.c index 1de9ad4bb3f..459fb54ce37 100644 --- a/gfx/video_shader_parse.c +++ b/gfx/video_shader_parse.c @@ -1320,6 +1320,25 @@ static config_file_t *video_shader_get_root_preset_config(const char *path) return conf; } + +enum rarch_shader_type video_shader_get_shader_type_from_preset_or_shader(const char *path, bool *is_preset) +{ + enum rarch_shader_type type = RARCH_SHADER_NONE; + type = video_shader_get_type_from_ext(path_get_extension(path), is_preset); + + if (is_preset) + { + config_file_t* conf = video_shader_get_root_preset_config(path); + + if (conf) + { + type = video_shader_get_type_from_ext(path_get_extension(conf->path), is_preset); + free(conf); + } + } + return type; +} + /** * video_shader_check_reference_chain: * @param path_to_save @@ -2457,6 +2476,9 @@ bool video_shader_is_supported(enum rarch_shader_type type) case RARCH_SHADER_HLSL: testflag = GFX_CTX_FLAGS_SHADERS_HLSL; break; + case RARCH_SHADER_META: + testflag = true; + break; case RARCH_SHADER_NONE: default: return false; @@ -2510,7 +2532,8 @@ enum rarch_shader_type video_shader_get_type_from_ext( *is_preset = string_is_equal_case_insensitive(ext, "cgp") || string_is_equal_case_insensitive(ext, "glslp") || - string_is_equal_case_insensitive(ext, "slangp"); + string_is_equal_case_insensitive(ext, "slangp") || + string_is_equal_case_insensitive(ext, "metap"); if (string_is_equal_case_insensitive(ext, "cgp") || string_is_equal_case_insensitive(ext, "cg") @@ -2527,6 +2550,9 @@ enum rarch_shader_type video_shader_get_type_from_ext( ) return RARCH_SHADER_SLANG; + if (string_is_equal_case_insensitive(ext, "metap")) + return RARCH_SHADER_META; + return RARCH_SHADER_NONE; } @@ -2848,7 +2874,7 @@ static bool video_shader_load_shader_preset_internal( { /* Shader preset priority, highest to lowest * only important for video drivers with multiple shader backends */ - RARCH_SHADER_GLSL, RARCH_SHADER_SLANG, RARCH_SHADER_CG, RARCH_SHADER_HLSL + RARCH_SHADER_GLSL, RARCH_SHADER_SLANG, RARCH_SHADER_CG, RARCH_SHADER_HLSL, RARCH_SHADER_META }; for (i = 0; i < ARRAY_SIZE(types); i++) diff --git a/gfx/video_shader_parse.h b/gfx/video_shader_parse.h index dc80de6844c..805fe9abb4b 100644 --- a/gfx/video_shader_parse.h +++ b/gfx/video_shader_parse.h @@ -51,7 +51,8 @@ enum rarch_shader_type RARCH_SHADER_HLSL, RARCH_SHADER_GLSL, RARCH_SHADER_SLANG, - RARCH_SHADER_METAL + RARCH_SHADER_METAL, + RARCH_SHADER_META }; enum gfx_scale_type @@ -178,14 +179,25 @@ struct video_shader char prefix[64]; - /* Path to the root preset */ + /* Path to the original preset loaded */ + char loaded_preset_path[PATH_MAX_LENGTH]; + + /* If this is a `Simple Preset` this means `loaded_preset_path` points to a preset with a #reference directive + * in it and 'path' will point to the preset used by the #reference directive + * If this is a `Full Preset` this means that `loaded_preset_path` will point to a preset with no #reference directive, + * in this case `path` will be the same as 'loaded_preset_path' + */ char path[PATH_MAX_LENGTH]; - /* Path to the original preset loaded, if this is a preset - * with the #reference directive, then this will be different - * than the path */ - char loaded_preset_path[PATH_MAX_LENGTH]; + /* Path to the final full preset to be loaded + * If 'path' points to a `Full Preset` then `root_preset_path` will be the same as `path` + * If `path` points to a `Simple Preset` then `root_preset_path` will point to the `Full Preset` + * at the end of the reference chain + */ + char root_preset_path[PATH_MAX_LENGTH]; + /* Shader Type defined by the root preset */ + enum rarch_shader_type shader_type; }; #define RARCH_WILDCARD_DELIMITER "$" @@ -266,6 +278,8 @@ bool video_shader_write_preset(const char *path, enum rarch_shader_type video_shader_get_type_from_ext(const char *ext, bool *is_preset); +enum rarch_shader_type video_shader_get_shader_type_from_preset_or_shader(const char *path, bool *is_preset); + /** * video_shader_parse_type: * @path : Shader path. @@ -275,7 +289,9 @@ enum rarch_shader_type video_shader_get_type_from_ext(const char *ext, bool *is_ * Returns: value of shader type if it could be determined, * otherwise RARCH_SHADER_NONE. **/ -#define video_shader_parse_type(path) video_shader_get_type_from_ext(path_get_extension((path)), NULL) +// #define video_shader_parse_type(path) video_shader_get_type_from_ext(path_get_extension((path)), NULL) + +#define video_shader_parse_type(path) video_shader_get_shader_type_from_preset_or_shader(path, NULL) bool video_shader_is_supported(enum rarch_shader_type type); diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index d7b24957519..2becb58d0dd 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -2087,10 +2087,13 @@ static int generic_action_ok(const char *path, menu_shader_manager_append_preset(shader, action_path, string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_VIDEO_SHADER_PRESET_PREPEND))); else + { + enum rarch_shader_type shader_type = menu_driver_get_last_shader_preset_type(); menu_shader_manager_set_preset(shader, - menu_driver_get_last_shader_preset_type(), - action_path, - true); + shader_type, + action_path, + true); + } } #endif break; diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 716cef84b01..9fca92e904f 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -14174,6 +14174,13 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, break; } + /* + Add the meta preset type which should be available for all video drivers + This preset type allows one preset to be used but call the other preset type + appropriate to the current video driver + */ + string_list_append(&str_list, "metap", attr); + string_list_join_concat(new_exts, sizeof(new_exts), &str_list, "|"); if (!string_is_empty(info->exts)) free(info->exts); @@ -14207,6 +14214,13 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, if (video_shader_is_supported(RARCH_SHADER_SLANG)) string_list_append(&str_list, "slangp", attr); + /* + Add the meta preset type which should be available for all video drivers + This preset type allows one preset to be used but call the other preset type + appropriate to the current video driver + */ + string_list_append(&str_list, "metap", attr); + string_list_join_concat(new_exts, sizeof(new_exts), &str_list, "|"); if (!string_is_empty(info->exts)) free(info->exts); @@ -14240,6 +14254,13 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, if (video_shader_is_supported(RARCH_SHADER_SLANG)) string_list_append(&str_list, "slangp", attr); + /* + Add the meta preset type which should be available for all video drivers + This preset type allows one preset to be used but call the other preset type + appropriate to the current video driver + */ + string_list_append(&str_list, "metap", attr); + string_list_join_concat(new_exts, sizeof(new_exts), &str_list, "|"); if (!string_is_empty(info->exts)) free(info->exts); diff --git a/menu/menu_driver.c b/menu/menu_driver.c index 7fbca319eb6..dece2ec4f50 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -3946,7 +3946,7 @@ bool menu_shader_manager_operate_auto_preset( char file[PATH_MAX_LENGTH]; static enum rarch_shader_type shader_types[] = { - RARCH_SHADER_GLSL, RARCH_SHADER_SLANG, RARCH_SHADER_CG + RARCH_SHADER_GLSL, RARCH_SHADER_SLANG, RARCH_SHADER_CG, RARCH_SHADER_META }; const char *core_name = system ? system->library_name : NULL; const char *rarch_path_basename = path_get(RARCH_PATH_BASENAME); @@ -4131,8 +4131,11 @@ void menu_driver_set_last_shader_path_int( /* Get shader type */ /* If type is invalid, do nothing */ + // Need to get shader type here if ((*type = video_shader_parse_type(shader_path)) == RARCH_SHADER_NONE) + { return; + } /* Cache parent directory */ fill_pathname_parent_dir(shader_dir, shader_path, dir_len); @@ -7355,8 +7358,7 @@ bool menu_shader_manager_init(void) if (string_is_empty(path_shader)) goto end; - type = video_shader_get_type_from_ext(path_get_extension(path_shader), - &is_preset); + type = video_shader_get_shader_type_from_preset_or_shader(path_shader, &is_preset); if (!video_shader_is_supported(type)) { diff --git a/retroarch.c b/retroarch.c index 5f18c27ab14..b3d0e0d9711 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1323,6 +1323,13 @@ struct string_list *dir_list_new_special(const char *input_dir, string_list_append(&str_list, "slang", attr); } + /* + Add the meta preset type which should be available for all video drivers + This preset type allows one preset to be used but call the other preset type + appropriate to the current video driver + */ + string_list_append(&str_list, "metap", attr); + string_list_join_concat(ext_shaders, sizeof(ext_shaders), &str_list, "|"); string_list_deinitialize(&str_list); exts = ext_shaders; diff --git a/ui/drivers/qt/qt_dialogs.cpp b/ui/drivers/qt/qt_dialogs.cpp index fb1497a0c09..a586c6bc9fc 100644 --- a/ui/drivers/qt/qt_dialogs.cpp +++ b/ui/drivers/qt/qt_dialogs.cpp @@ -1766,6 +1766,13 @@ void ShaderParamsDialog::onShaderLoadPresetClicked() filter.append(".slangp"); } + /* + Add the meta preset type which should be available for all video drivers + This preset type allows one preset to be used but call the other preset type + appropriate to the current video driver + */ + filter.append(".metap"); + filter.append(")"); path = QFileDialog::getOpenFileName( this,