Skip to content

Commit

Permalink
Meta Preset In Progress
Browse files Browse the repository at this point in the history
  • Loading branch information
HyperspaceMadness committed Mar 12, 2023
1 parent 152867d commit 9196800
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 19 deletions.
1 change: 1 addition & 0 deletions file_path_special.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions gfx/drivers/d3d10.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions gfx/drivers_shader/shader_gl_cg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
5 changes: 3 additions & 2 deletions gfx/drivers_shader/shader_glsl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
30 changes: 28 additions & 2 deletions gfx/video_shader_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand All @@ -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;
}

Expand Down Expand Up @@ -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++)
Expand Down
30 changes: 23 additions & 7 deletions gfx/video_shader_parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 "$"
Expand Down Expand Up @@ -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.
Expand All @@ -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);

Expand Down
9 changes: 6 additions & 3 deletions menu/cbs/menu_cbs_ok.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions menu/menu_displaylist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions menu/menu_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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))
{
Expand Down
7 changes: 7 additions & 0 deletions retroarch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions ui/drivers/qt/qt_dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 9196800

Please sign in to comment.