Simplified parameter parsing to have all shader formats use the same slang method

(when HAVE_SLANG and HAVE_SPIRV_CROSS are defined) - backport of HyperSpaceMadness' PR
This commit is contained in:
libretroadmin 2024-09-08 15:24:53 +02:00
parent 42f66adbf2
commit d60d320e76
3 changed files with 20 additions and 24 deletions

View File

@ -150,9 +150,9 @@ bool glslang_read_shader_file(const char *path,
if (lines.size < 1)
goto error;
/* If this is the 'parent' shader file, ensure that first
* line is a 'VERSION' string */
if (root_file)
/* If this is the 'parent' shader file and a slang file,
* ensure that first line is a 'VERSION' string */
if (root_file && string_is_equal(path_get_extension(path), "slang"))
{
const char *line = lines.elems[0].data;
@ -166,9 +166,9 @@ bool glslang_read_shader_file(const char *path,
if (!string_list_append(output, line, attr))
goto error;
/* Allows us to use #line to make dealing with shader
/* Allows us to use #line to make dealing with shader
* errors easier.
* This is supported by glslang, but since we always
* This is supported by glslang, but since we always
* use glslang statically, this is fine. */
if (!string_list_append(output,
"#extension GL_GOOGLE_cpp_style_line_directive : require",

View File

@ -120,6 +120,14 @@ const char *glslang_format_to_string(glslang_format fmt);
enum glslang_format glslang_find_format(const char *fmt);
/* Reads a shader file and outputs its contents as a string list.
Takes the path of the shader file and appends each line of the file
to the output string list.
If the root_file argument is set to true, it expects the first line of the file
to be a valid '#version' string
Handles '#include' statements by recursively parsing included files and appending their contents.
Returns a Bool indicating if parsing was successful.
*/
bool glslang_read_shader_file(const char *path,
struct string_list *output, bool root_file);

View File

@ -870,28 +870,15 @@ void video_shader_resolve_parameters(struct video_shader *shader)
uint8_t *buf = NULL;
int64_t buf_len = 0;
if (string_is_empty(path))
if (string_is_empty(path) || !path_is_valid(path))
continue;
if (!path_is_valid(path))
continue;
/* First try to use the more robust slang implementation
* to support #includes. */
#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
/* FIXME: The check for slang can be removed
* if it's sufficiently tested for GLSL/Cg as well,
* it should be the same implementation.
* The problem with switching currently is that it looks
* for a #version string in the first line of the file
* which glsl doesn't have */
if ( string_is_equal(path_get_extension(path), "slang")
&& slang_preprocess_parse_parameters(path, shader))
continue;
#endif
/* Now uses the same slang parsing for parameters since
* it should be the same implementation, but supporting
* #include directives */
slang_preprocess_parse_parameters(path, shader);
#else
/* Read file contents */
if (filestream_read_file(path, (void**)&buf, &buf_len))
{
@ -956,6 +943,7 @@ void video_shader_resolve_parameters(struct video_shader *shader)
string_list_deinitialize(&lines);
}
#endif
}
}