diff --git a/gfx/drivers_shader/glslang_util.c b/gfx/drivers_shader/glslang_util.c index 7426b5208e..c18a776125 100644 --- a/gfx/drivers_shader/glslang_util.c +++ b/gfx/drivers_shader/glslang_util.c @@ -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", diff --git a/gfx/drivers_shader/glslang_util.h b/gfx/drivers_shader/glslang_util.h index fe2cfb3912..53d421fad8 100644 --- a/gfx/drivers_shader/glslang_util.h +++ b/gfx/drivers_shader/glslang_util.h @@ -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); diff --git a/gfx/video_shader_parse.c b/gfx/video_shader_parse.c index 18c421f3c6..ef4a31564e 100644 --- a/gfx/video_shader_parse.c +++ b/gfx/video_shader_parse.c @@ -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 } }