Merge pull request #11743 from HyperspaceMadness/Shaders_Fix_Simple_Preset_Relative_Texture_Paths

Shaders Load Refactor and Fix Referenced Texture Loading
This commit is contained in:
Autechre 2020-12-31 16:13:20 +01:00 committed by GitHub
commit 9797ba9f27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 1048 additions and 1077 deletions

View File

@ -1219,7 +1219,6 @@ typedef struct MTLALIGN(16)
[self _freeVideoShader:_shader];
_shader = nil;
config_file_t *conf = video_shader_read_preset(path.UTF8String);
struct video_shader *shader = (struct video_shader *)calloc(1, sizeof(*shader));
settings_t *settings = config_get_ptr();
const char *dir_video_shader = settings->paths.directory_video_shader;
@ -1229,7 +1228,7 @@ typedef struct MTLALIGN(16)
{
unsigned i;
texture_t *source = NULL;
if (!video_shader_read_conf_preset(conf, shader))
if (!video_shader_load_preset_into_shader(path.UTF8String, shader))
return NO;
source = &_engine.frame.texture[0];
@ -1429,8 +1428,6 @@ typedef struct MTLALIGN(16)
/* TODO(sgc): generate mip maps */
image_texture_free(&image);
}
video_shader_resolve_current_parameters(conf, shader);
_shader = shader;
shader = nil;
}
@ -1440,12 +1437,6 @@ typedef struct MTLALIGN(16)
{
[self _freeVideoShader:shader];
}
if (conf)
{
config_file_free(conf);
conf = nil;
}
}
resize_render_targets = YES;

View File

@ -336,7 +336,6 @@ static bool d3d10_gfx_set_shader(void* data, enum rarch_shader_type type, const
{
#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
unsigned i;
config_file_t* conf = NULL;
d3d10_texture_t* source = NULL;
d3d10_video_t* d3d10 = (d3d10_video_t*)data;
@ -355,12 +354,9 @@ static bool d3d10_gfx_set_shader(void* data, enum rarch_shader_type type, const
return false;
}
if (!(conf = video_shader_read_preset(path)))
return false;
d3d10->shader_preset = (struct video_shader*)calloc(1, sizeof(*d3d10->shader_preset));
if (!video_shader_read_conf_preset(conf, d3d10->shader_preset))
if (!video_shader_load_preset_into_shader(path, d3d10->shader_preset))
goto error;
source = &d3d10->frame.texture[0];
@ -508,9 +504,6 @@ static bool d3d10_gfx_set_shader(void* data, enum rarch_shader_type type, const
image_texture_free(&image);
}
video_shader_resolve_current_parameters(conf, d3d10->shader_preset);
config_file_free(conf);
d3d10->resize_render_targets = true;
d3d10->init_history = true;

View File

@ -359,7 +359,6 @@ static bool d3d11_gfx_set_shader(void* data, enum rarch_shader_type type, const
{
#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
unsigned i;
config_file_t* conf = NULL;
d3d11_texture_t* source = NULL;
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
@ -378,12 +377,9 @@ static bool d3d11_gfx_set_shader(void* data, enum rarch_shader_type type, const
return false;
}
if (!(conf = video_shader_read_preset(path)))
return false;
d3d11->shader_preset = (struct video_shader*)calloc(1, sizeof(*d3d11->shader_preset));
if (!video_shader_read_conf_preset(conf, d3d11->shader_preset))
if (!video_shader_load_preset_into_shader(path, d3d11->shader_preset))
goto error;
source = &d3d11->frame.texture[0];
@ -529,9 +525,6 @@ static bool d3d11_gfx_set_shader(void* data, enum rarch_shader_type type, const
image_texture_free(&image);
}
video_shader_resolve_current_parameters(conf, d3d11->shader_preset);
config_file_free(conf);
d3d11->resize_render_targets = true;
d3d11->init_history = true;

View File

@ -343,7 +343,6 @@ static bool d3d12_gfx_set_shader(void* data, enum rarch_shader_type type, const
{
#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
unsigned i;
config_file_t* conf = NULL;
d3d12_texture_t* source = NULL;
d3d12_video_t* d3d12 = (d3d12_video_t*)data;
@ -362,12 +361,9 @@ static bool d3d12_gfx_set_shader(void* data, enum rarch_shader_type type, const
return false;
}
if (!(conf = video_shader_read_preset(path)))
return false;
d3d12->shader_preset = (struct video_shader*)calloc(1, sizeof(*d3d12->shader_preset));
if (!video_shader_read_conf_preset(conf, d3d12->shader_preset))
if (!video_shader_load_preset_into_shader(path, d3d12->shader_preset))
goto error;
source = &d3d12->frame.texture[0];
@ -535,9 +531,6 @@ static bool d3d12_gfx_set_shader(void* data, enum rarch_shader_type type, const
image_texture_free(&image);
}
video_shader_resolve_current_parameters(conf, d3d12->shader_preset);
config_file_free(conf);
d3d12->resize_render_targets = true;
d3d12->init_history = true;

View File

@ -324,25 +324,15 @@ static bool d3d9_init_multipass(d3d9_video_t *d3d, const char *shader_path)
unsigned i;
bool use_extra_pass = false;
struct video_shader_pass *pass = NULL;
config_file_t *conf = video_shader_read_preset(shader_path);
if (!conf)
{
RARCH_ERR("[D3D9]: Failed to load preset.\n");
return false;
}
memset(&d3d->shader, 0, sizeof(d3d->shader));
if (!video_shader_read_conf_preset(conf, &d3d->shader))
if (!video_shader_load_preset_into_shader(shader_path, &d3d->shader))
{
config_file_free(conf);
RARCH_ERR("[D3D9]: Failed to parse shader preset.\n");
return false;
}
config_file_free(conf);
RARCH_LOG("[D3D9]: Found %u shaders.\n", d3d->shader.passes);
for (i = 0; i < d3d->shader.passes; i++)
@ -1732,7 +1722,7 @@ static bool d3d9_set_shader(void *data,
if (type != supported_shader_type)
{
RARCH_WARN("[D3D9]: Shader preset %s is using unsupported shader type %s, falling back to stock %s.\n",
path, video_shader_to_str(type), video_shader_to_str(supported_shader_type));
path, video_shader_type_to_str(type), video_shader_type_to_str(supported_shader_type));
break;
}

View File

@ -2041,7 +2041,7 @@ static bool gl2_shader_init(gl_t *gl, const gfx_ctx_driver_t *ctx_driver,
{
if (!string_is_empty(shader_path))
RARCH_WARN("[GL] Shader preset %s is using unsupported shader type %s, falling back to stock %s.\n",
shader_path, video_shader_to_str(parse_type), video_shader_to_str(type));
shader_path, video_shader_type_to_str(parse_type), video_shader_type_to_str(type));
shader_path = NULL;
}
@ -4089,7 +4089,7 @@ static bool gl2_set_shader(void *data,
if (type != fallback)
{
RARCH_ERR("[GL]: %s shader not supported, falling back to stock %s\n",
video_shader_to_str(type), video_shader_to_str(fallback));
video_shader_type_to_str(type), video_shader_type_to_str(fallback));
path = NULL;
}

View File

@ -1428,7 +1428,6 @@ static bool wiiu_gfx_set_shader(void *data,
enum rarch_shader_type type, const char *path)
{
unsigned i;
config_file_t *conf = NULL;
wiiu_video_t *wiiu = (wiiu_video_t *)data;
if (!wiiu)
@ -1446,24 +1445,15 @@ static bool wiiu_gfx_set_shader(void *data,
return false;
}
if (!(conf = video_shader_read_preset(path)))
return false;
wiiu->shader_preset = calloc(1, sizeof(*wiiu->shader_preset));
if (!video_shader_read_conf_preset(conf, wiiu->shader_preset))
if (!video_shader_load_preset_into_shader(path, wiiu->shader_preset))
{
free(wiiu->shader_preset);
wiiu->shader_preset = NULL;
return false;
}
for (i = 0; i < wiiu->shader_preset->passes; i++)
slang_preprocess_parse_parameters(wiiu->shader_preset->pass[i].source.path, wiiu->shader_preset);
video_shader_resolve_current_parameters(conf, wiiu->shader_preset);
config_file_free(conf);
for (i = 0; i < wiiu->shader_preset->passes; i++)
{
unsigned j;

View File

@ -664,7 +664,8 @@ static bool gl_cg_load_plain(void *data, const char *path)
return false;
}
video_shader_resolve_parameters(NULL, cg->shader);
video_shader_resolve_parameters(cg->shader);
video_shader_load_current_parameter_values(NULL, cg->shader);
return true;
}
@ -688,37 +689,25 @@ static bool gl_cg_load_shader(void *data, unsigned i)
static bool gl_cg_load_preset(void *data, const char *path)
{
unsigned i;
config_file_t *conf = NULL;
cg_shader_data_t *cg = (cg_shader_data_t*)data;
if (!gl_cg_load_stock(cg))
return false;
RARCH_LOG("[CG]: Loading Cg meta-shader: %s\n", path);
conf = video_shader_read_preset(path);
if (!conf)
{
RARCH_ERR("Failed to load preset.\n");
return false;
}
cg->shader = (struct video_shader*)calloc(1, sizeof(*cg->shader));
if (!cg->shader)
{
config_file_free(conf);
return false;
}
if (!video_shader_read_conf_preset(conf, cg->shader))
if (!video_shader_load_preset_into_shader(path, cg->shader))
{
RARCH_ERR("Failed to parse CGP file.\n");
config_file_free(conf);
return false;
}
video_shader_resolve_parameters(conf, cg->shader);
config_file_free(conf);
if (cg->shader->passes > GFX_MAX_SHADERS - 3)
{
RARCH_WARN("Too many shaders ... Capping shader amount to %d.\n",

View File

@ -2158,20 +2158,13 @@ gl_core_filter_chain_t *gl_core_filter_chain_create_from_preset(
const char *path, glslang_filter_chain_filter filter)
{
unsigned i;
config_file_t *conf = NULL;
unique_ptr<video_shader> shader{ new video_shader() };
if (!shader)
return nullptr;
if (!(conf = video_shader_read_preset(path)))
if (!video_shader_load_preset_into_shader(path, shader.get()))
return nullptr;
if (!video_shader_read_conf_preset(conf, shader.get()))
{
config_file_free(conf);
return nullptr;
}
bool last_pass_is_fbo = shader->pass[shader->passes - 1].fbo.valid;
unique_ptr<gl_core_filter_chain> chain{ new gl_core_filter_chain(shader->passes + (last_pass_is_fbo ? 1 : 0)) };
@ -2203,7 +2196,7 @@ gl_core_filter_chain_t *gl_core_filter_chain_create_from_preset(
if (!glslang_compile_shader(pass->source.path, &output))
{
RARCH_ERR("Failed to compile shader: \"%s\".\n",
RARCH_ERR("[GLCore]: Failed to compile shader: \"%s\".\n",
pass->source.path);
goto error;
}
@ -2212,7 +2205,7 @@ gl_core_filter_chain_t *gl_core_filter_chain_create_from_preset(
{
if (shader->num_parameters >= GFX_MAX_PARAMETERS)
{
RARCH_ERR("[GLCore]: Exceeded maximum number of parameters.\n");
RARCH_ERR("[GLCore]: Exceeded maximum number of parameters (%u).\n", GFX_MAX_PARAMETERS);
goto error;
}
@ -2243,11 +2236,6 @@ gl_core_filter_chain_t *gl_core_filter_chain_create_from_preset(
video_shader_parameter *param = &shader->parameters[shader->num_parameters];
strlcpy(param->id, meta_param.id.c_str(), sizeof(param->id));
strlcpy(param->desc, meta_param.desc.c_str(), sizeof(param->desc));
param->current = meta_param.initial;
param->initial = meta_param.initial;
param->minimum = meta_param.minimum;
param->maximum = meta_param.maximum;
param->step = meta_param.step;
chain->add_parameter(i, shader->num_parameters, meta_param.id);
shader->num_parameters++;
}
@ -2415,19 +2403,14 @@ gl_core_filter_chain_t *gl_core_filter_chain_create_from_preset(
sizeof(gl_core_shader::opaque_frag) / sizeof(uint32_t));
}
if (!video_shader_resolve_current_parameters(conf, shader.get()))
goto error;
chain->set_shader_preset(move(shader));
if (!chain->init())
goto error;
config_file_free(conf);
return chain.release();
error:
config_file_free(conf);
return nullptr;
}

View File

@ -856,7 +856,6 @@ static void *gl_glsl_init(void *data, const char *path)
#ifdef GLSL_DEBUG
char *error_string = NULL;
#endif
config_file_t *conf = NULL;
const char *stock_vertex = NULL;
const char *stock_fragment = NULL;
glsl_shader_data_t *glsl = (glsl_shader_data_t*)
@ -910,12 +909,8 @@ static void *gl_glsl_init(void *data, const char *path)
if (is_preset)
{
conf = video_shader_read_preset(path);
if (conf)
{
ret = video_shader_read_conf_preset(conf, glsl->shader);
glsl->shader->modern = true;
}
ret = video_shader_load_preset_into_shader(path, glsl->shader);
glsl->shader->modern = true;
}
else
{
@ -944,14 +939,6 @@ static void *gl_glsl_init(void *data, const char *path)
}
}
video_shader_resolve_parameters(conf, glsl->shader);
if (conf)
{
config_file_free(conf);
conf = NULL;
}
stock_vertex = (glsl->shader->modern) ?
stock_vertex_modern : stock_vertex_legacy;
stock_fragment = (glsl->shader->modern) ?
@ -1067,8 +1054,6 @@ static void *gl_glsl_init(void *data, const char *path)
error:
gl_glsl_destroy_resources(glsl);
if (conf)
config_file_free(conf);
if (glsl)
free(glsl);

View File

@ -2565,19 +2565,13 @@ vulkan_filter_chain_t *vulkan_filter_chain_create_from_preset(
const char *path, glslang_filter_chain_filter filter)
{
unsigned i;
config_file_t *conf = NULL;
unique_ptr<video_shader> shader{ new video_shader() };
if (!shader)
return nullptr;
if (!(conf = video_shader_read_preset(path)))
return nullptr;
if (!video_shader_read_conf_preset(conf, shader.get()))
{
config_file_free(conf);
return nullptr;
}
if (!video_shader_load_preset_into_shader(path, shader.get()))
return nullptr;
bool last_pass_is_fbo = shader->pass[shader->passes - 1].fbo.valid;
auto tmpinfo = *info;
@ -2612,7 +2606,7 @@ vulkan_filter_chain_t *vulkan_filter_chain_create_from_preset(
if (!glslang_compile_shader(pass->source.path, &output))
{
RARCH_ERR("Failed to compile shader: \"%s\".\n",
RARCH_ERR("[Vulkan]: Failed to compile shader: \"%s\".\n",
pass->source.path);
goto error;
}
@ -2621,7 +2615,7 @@ vulkan_filter_chain_t *vulkan_filter_chain_create_from_preset(
{
if (shader->num_parameters >= GFX_MAX_PARAMETERS)
{
RARCH_ERR("[Vulkan]: Exceeded maximum number of parameters.\n");
RARCH_ERR("[Vulkan]: Exceeded maximum number of parameters (%u).\n", GFX_MAX_PARAMETERS);
goto error;
}
@ -2652,11 +2646,6 @@ vulkan_filter_chain_t *vulkan_filter_chain_create_from_preset(
video_shader_parameter *param = &shader->parameters[shader->num_parameters];
strlcpy(param->id, meta_param.id.c_str(), sizeof(param->id));
strlcpy(param->desc, meta_param.desc.c_str(), sizeof(param->desc));
param->current = meta_param.initial;
param->initial = meta_param.initial;
param->minimum = meta_param.minimum;
param->maximum = meta_param.maximum;
param->step = meta_param.step;
chain->add_parameter(i, shader->num_parameters, meta_param.id);
shader->num_parameters++;
}
@ -2820,19 +2809,14 @@ vulkan_filter_chain_t *vulkan_filter_chain_create_from_preset(
sizeof(opaque_frag) / sizeof(uint32_t));
}
if (!video_shader_resolve_current_parameters(conf, shader.get()))
goto error;
chain->set_shader_preset(move(shader));
if (!chain->init())
goto error;
config_file_free(conf);
return chain.release();
error:
config_file_free(conf);
return nullptr;
}

File diff suppressed because it is too large Load Diff

View File

@ -33,10 +33,6 @@ RETRO_BEGIN_DECLS
#define GFX_MAX_TEXTURES 64
#endif
#ifndef GFX_MAX_VARIABLES
#define GFX_MAX_VARIABLES 64
#endif
#ifndef GFX_MAX_PARAMETERS
#define GFX_MAX_PARAMETERS 512
#endif
@ -167,47 +163,59 @@ struct video_shader
bool modified;
};
/**
* video_shader_write_preset:
* @path : File to write to
* @shader : Shader preset to write
* @reference : Whether a reference preset should be written
*
* Writes a preset to disk. Can be written as a reference preset.
* See: video_shader_read_preset
**/
bool video_shader_write_preset(const char *path,
const char *shader_dir,
const struct video_shader *shader, bool reference);
/**
* video_shader_read_preset:
* @path : File to read
*
* Reads a preset from disk.
* If the preset is a reference preset, the referenced preset
* is loaded instead.
*
* Returns: the read preset as a config object.
*
* The returned config object needs to be freed.
**/
config_file_t *video_shader_read_preset(const char *path);
/**
* video_shader_read_conf_preset:
* video_shader_resolve_parameters:
* @conf : Preset file to read from.
* @shader : Shader passes handle.
*
* Resolves all shader parameters belonging to shaders
* from the #pragma parameter lines in the shader for each pass.
*
* Returns: true (1) if successful, otherwise false (0).
**/
bool video_shader_resolve_parameters(struct video_shader *shader);
/**
* video_shader_load_current_parameter_values:
* @conf : Preset file to read from.
* @shader : Shader passes handle.
*
* Reads the current value for all parameters from config file.
*
* Returns: true (1) if successful, otherwise false (0).
**/
bool video_shader_load_current_parameter_values(config_file_t *conf, struct video_shader *shader);
/**
* video_shader_load_root_config_into_shader:
* @conf : Preset file to read from.
* @shader : Shader handle.
*
* Loads preset file and all associated state (passes,
* textures, imports, etc).
*
* Returns: true (1) if successful, otherwise false (0).
**/
bool video_shader_read_conf_preset(config_file_t *conf,
struct video_shader *shader);
bool video_shader_load_root_config_into_shader(config_file_t *conf, struct video_shader *shader);
/**
* video_shader_write_conf_preset:
* video_shader_load_preset_into_shader:
* @path : Path to preset file, could be a Simple Preset (including a #reference) or Full Preset
* @shader : Shader
*
* Loads preset file to a shader including passes, textures and parameters
*
* Returns: true (1) if successful, otherwise false (0).
**/
bool video_shader_load_preset_into_shader(const char *path, struct video_shader *shader);
/**
* video_shader_write_root_preset:
* @conf : Preset file to write to.
* @shader : Shader passes handle.
* @preset_path : Optional path to where the preset will be written.
@ -217,35 +225,24 @@ bool video_shader_read_conf_preset(config_file_t *conf,
* If @preset_path is not NULL, shader paths are saved
* relative to it.
**/
void video_shader_write_conf_preset(config_file_t *conf,
const struct video_shader *shader, const char *preset_path);
bool video_shader_write_root_preset(const struct video_shader *shader, const char *preset_path);
/**
* video_shader_resolve_parameters:
* @conf : Preset file to read from.
* @shader : Shader passes handle.
* video_shader_write_preset:
* @path : File to write to
* @shader : Shader to write
* @reference : Whether a simple preset should be written with the #reference to another preset in it
*
* Reads the current value for all parameters from config file.
*
* Returns: true (1) if successful, otherwise false (0).
* Writes a preset to disk. Can be written as a simple preset (With the #reference directive in it) or a full preset.
**/
bool video_shader_resolve_current_parameters(config_file_t *conf,
struct video_shader *shader);
bool video_shader_write_preset(const char *path,
const char *shader_dir,
const struct video_shader *shader,
bool reference);
/**
* video_shader_resolve_parameters:
* @conf : Preset file to read from.
* @shader : Shader passes handle.
*
* Resolves all shader parameters belonging to shaders.
*
* Returns: true (1) if successful, otherwise false (0).
**/
bool video_shader_resolve_parameters(config_file_t *conf,
struct video_shader *shader);
enum rarch_shader_type video_shader_get_type_from_ext(const char *ext,
bool *is_preset);
enum rarch_shader_type video_shader_get_type_from_ext(const char *ext, bool *is_preset);
/**
* video_shader_parse_type:
@ -264,7 +261,7 @@ bool video_shader_any_supported(void);
bool video_shader_check_for_changes(void);
const char *video_shader_to_str(enum rarch_shader_type type);
const char *video_shader_type_to_str(enum rarch_shader_type type);
const char *video_shader_get_preset_extension(enum rarch_shader_type type);

View File

@ -640,8 +640,12 @@ static int config_file_from_string_internal(
void config_file_set_reference_path(config_file_t *conf, char *path)
{
/* If a relative path the input path is desired the caller is
* responsible for preparing and supplying the relative path*/
/* It is expected that the conf has it's path already set */
char short_path[PATH_MAX_LENGTH];
short_path[0] = '\0';
if (!conf)
return;
@ -651,8 +655,9 @@ void config_file_set_reference_path(config_file_t *conf, char *path)
conf->reference = NULL;
}
conf->reference = strdup(path);
fill_pathname_abbreviated_or_relative(short_path, conf->path, path, sizeof(short_path));
conf->reference = strdup(short_path);
}
bool config_file_deinitialize(config_file_t *conf)
@ -1287,7 +1292,10 @@ void config_file_dump_orbis(config_file_t *conf, int fd)
struct config_include_list *includes = conf->includes;
if (conf->reference)
{
pathname_make_slashes_portable(conf->reference);
fprintf(file, "#reference \"%s\"\n", conf->reference);
}
list = config_file_merge_sort_linked_list(
@ -1330,7 +1338,10 @@ void config_file_dump(config_file_t *conf, FILE *file, bool sort)
struct config_include_list *includes = conf->includes;
if (conf->reference)
{
pathname_make_slashes_portable(conf->reference);
fprintf(file, "#reference \"%s\"\n", conf->reference);
}
if (sort)
list = config_file_merge_sort_linked_list(

View File

@ -1108,6 +1108,100 @@ void fill_pathname_abbreviate_special(char *out_path,
retro_assert(strlcpy(out_path, in_path, size) < size);
}
/* Changes the slashes to the correct kind for the os
* So forward slash on linux and backslash on Windows */
void pathname_conform_slashes_to_os(char *path)
{
/* Conform slashes to os standard so we get proper matching */
char* p;
for (p = path; *p; p++)
if (*p == '/' || *p == '\\')
*p = PATH_DEFAULT_SLASH_C();
}
/* Change all shashes to forward so they are more portable between windows and linux */
void pathname_make_slashes_portable(char *path)
{
/* Conform slashes to os standard so we get proper matching */
char* p;
for (p = path; *p; p++)
if (*p == '/' || *p == '\\')
*p = '/';
}
/* Get the number of slashes in a path, returns an integer */
int get_pathname_num_slashes(const char *in_path)
{
int num_slashes = 0;
int i = 0;
for (i = 0; i < PATH_MAX_LENGTH; i++)
{
if (PATH_CHAR_IS_SLASH(in_path[i]))
num_slashes++;
if (in_path[i] == '\0')
break;
}
return num_slashes;
}
/* Fills the supplied path with either the abbreviated path or the relative path, which ever
* one is has less depth / number of slashes
* If lengths of abbreviated and relative paths are the same the relative path will be used
* in_path can be an absolute, relative or abbreviated path */
void fill_pathname_abbreviated_or_relative(char *out_path, const char *in_refpath, const char *in_path, size_t size)
{
unsigned relative_length = 0;
unsigned abbreviated_length = 0;
char in_path_conformed[PATH_MAX_LENGTH];
char in_refpath_conformed[PATH_MAX_LENGTH];
char expanded_path[PATH_MAX_LENGTH];
char absolute_path[PATH_MAX_LENGTH];
char relative_path[PATH_MAX_LENGTH];
char abbreviated_path[PATH_MAX_LENGTH];
in_path_conformed[0] = '\0';
in_refpath_conformed[0] = '\0';
absolute_path[0] = '\0';
relative_path[0] = '\0';
abbreviated_path[0] = '\0';
strcpy(in_path_conformed, in_path);
strcpy(in_refpath_conformed, in_refpath);
pathname_conform_slashes_to_os(in_path_conformed);
pathname_conform_slashes_to_os(in_refpath_conformed);
/* Expand paths which start with :\ to an absolute path */
fill_pathname_expand_special(expanded_path, in_path_conformed, sizeof(expanded_path));
/* Get the absolute path if it is not already */
if (path_is_absolute(expanded_path))
strlcpy(absolute_path, expanded_path, PATH_MAX_LENGTH);
else
fill_pathname_resolve_relative(absolute_path, in_refpath_conformed, in_path_conformed, PATH_MAX_LENGTH);
pathname_conform_slashes_to_os(absolute_path);
/* Get the relative path and see how many directories long it is */
path_relative_to(relative_path, absolute_path, in_refpath_conformed, sizeof(relative_path));
/* Get the abbreviated path and see how many directories long it is */
fill_pathname_abbreviate_special(abbreviated_path, absolute_path, sizeof(abbreviated_path));
/* Use the shortest path, preferring the relative path*/
if (get_pathname_num_slashes(relative_path) <= get_pathname_num_slashes(abbreviated_path))
{
retro_assert(strlcpy(out_path, relative_path, size) < size);
}
else
{
retro_assert(strlcpy(out_path, abbreviated_path, size) < size);
}
}
/**
* path_basedir:
* @path : path

View File

@ -442,6 +442,12 @@ void fill_pathname_expand_special(char *out_path,
void fill_pathname_abbreviate_special(char *out_path,
const char *in_path, size_t size);
void fill_pathname_abbreviated_or_relative(char *out_path, const char *in_refpath, const char *in_path, size_t size);
void pathname_conform_slashes_to_os(char *path);
void pathname_make_slashes_portable(char *path);
/**
* path_basedir:
* @path : path

View File

@ -364,7 +364,7 @@ static int action_left_shader_num_passes(unsigned type, const char *label,
menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh);
menu_driver_ctl(RARCH_MENU_CTL_SET_PREVENT_POPULATE, NULL);
video_shader_resolve_parameters(NULL, shader);
video_shader_resolve_parameters(shader);
shader->modified = true;

View File

@ -1755,7 +1755,7 @@ static int generic_action_ok(const char *path,
shader_pass->source.path,
action_path,
sizeof(shader_pass->source.path));
video_shader_resolve_parameters(NULL, shader);
video_shader_resolve_parameters(shader);
shader->modified = true;
}
@ -5999,7 +5999,7 @@ static int action_ok_push_dropdown_item_video_shader_num_pass(const char *path,
shader->passes = idx;
video_shader_resolve_parameters(NULL, shader);
video_shader_resolve_parameters(shader);
shader->modified = true;

View File

@ -380,7 +380,7 @@ static int action_right_shader_num_passes(unsigned type, const char *label,
menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh);
menu_driver_ctl(RARCH_MENU_CTL_SET_PREVENT_POPULATE, NULL);
video_shader_resolve_parameters(NULL, shader);
video_shader_resolve_parameters(shader);
shader->modified = true;

View File

@ -5183,22 +5183,12 @@ bool menu_shader_manager_init(void)
if (is_preset)
{
config_file_t *conf = NULL;
conf = video_shader_read_preset(path_shader);
if (!conf)
if (!video_shader_load_preset_into_shader(path_shader, menu_shader))
{
ret = false;
goto end;
}
if (video_shader_read_conf_preset(conf, menu_shader))
video_shader_resolve_parameters(conf, menu_shader);
menu_shader->modified = false;
config_file_free(conf);
}
else
{
@ -5225,7 +5215,6 @@ end:
bool menu_shader_manager_set_preset(struct video_shader *shader,
enum rarch_shader_type type, const char *preset_path, bool apply)
{
config_file_t *conf = NULL;
bool refresh = false;
bool ret = false;
@ -5249,19 +5238,13 @@ bool menu_shader_manager_set_preset(struct video_shader *shader,
* No point in updating when the Preset was
* created from the menu itself. */
if ( !shader ||
!(conf = video_shader_read_preset(preset_path)))
!(video_shader_load_preset_into_shader(preset_path, shader)))
{
ret = false;
goto end;
}
RARCH_LOG("Setting Menu shader: %s.\n", preset_path);
if (video_shader_read_conf_preset(conf, shader))
video_shader_resolve_parameters(conf, shader);
if (conf)
config_file_free(conf);
RARCH_LOG("Menu shader set to: %s.\n", preset_path);
ret = true;
@ -5694,7 +5677,7 @@ int menu_shader_manager_clear_num_passes(struct video_shader *shader)
menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh);
#endif
video_shader_resolve_parameters(NULL, shader);
video_shader_resolve_parameters(shader);
shader->modified = true;
@ -10410,6 +10393,9 @@ bool retroarch_apply_shader(
if (!string_is_empty(preset_path))
preset_file = path_basename(preset_path);
/* TODO This loads the shader into the video driver
* But then we load the shader from disk twice more to put it in the menu
* We need to reconfigure this at some point to only load it once */
if (p_rarch->current_video->set_shader)
ret = p_rarch->current_video->set_shader(
p_rarch->video_driver_data, type, preset_path);

View File

@ -707,7 +707,7 @@ void ShaderParamsDialog::onShaderAddPassClicked()
menu_driver_set_last_shader_pass_dir(pathData);
#endif
video_shader_resolve_parameters(NULL, menu_shader);
video_shader_resolve_parameters(menu_shader);
command_event(CMD_EVENT_SHADERS_APPLY_CHANGES, NULL);
}