From 3350741e2423e5e598b5e862f84a3a480ae2c1cc Mon Sep 17 00:00:00 2001 From: Grigory Dzhavadyan Date: Thu, 12 Apr 2018 14:35:24 -0700 Subject: [PATCH 1/3] Make glslang validator support files ending in .glsl This patch makes the validator accept *..[g/h]lsl pattern for file names. This patch preserves previous behavior (i.e. *.vert/*.frag/etc. in file names still work). --- StandAlone/StandAlone.cpp | 55 +++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/StandAlone/StandAlone.cpp b/StandAlone/StandAlone.cpp index 044662fe..4602184a 100644 --- a/StandAlone/StandAlone.cpp +++ b/StandAlone/StandAlone.cpp @@ -1196,38 +1196,47 @@ int C_DECL main(int argc, char* argv[]) // .frag = fragment // .comp = compute // -EShLanguage FindLanguage(const std::string& name, bool parseSuffix) +// Additionally, the file names may end in ..glsl and ..hlsl +// where is one of the stages listed above. +// +EShLanguage FindLanguage(const std::string& name, bool parseStageName) { - size_t ext = 0; - std::string suffix; + std::string stage_name; - if (shaderStageName) - suffix = shaderStageName; - else { - // Search for a suffix on a filename: e.g, "myfile.frag". If given - // the suffix directly, we skip looking for the '.' - if (parseSuffix) { - ext = name.rfind('.'); - if (ext == std::string::npos) { - usage(); - return EShLangVertex; - } - ++ext; + if (shaderStageName) { + stage_name = shaderStageName; + } else if (parseStageName) { + // Note: "first" extension means "first from the end", i.e. + // if the file is named foo.vert.glsl, then "glsl" is first, + // "vert" is second. + size_t first_ext_start = name.find_last_of("."); + bool has_first_ext = first_ext_start != std::string::npos; + size_t second_ext_start = + has_first_ext ? name.find_last_of(".", first_ext_start - 1) : std::string::npos; + bool has_second_ext = second_ext_start != std::string::npos; + bool uses_unified_ext = has_first_ext && (first_ext == "glsl" || + first_ext == "hlsl"); + std::string first_ext = name.substr(first_ext_start + 1, std::string::npos); + if (has_first_ext && !uses_unified_ext) { + stage_name = first_ext; + } else if (uses_unified_ext && has_second_ext) { + stage_name = name.substr(second_ext_start + 1, first_ext_start - second_ext_start - 1); + } else { + usage(); + return EShLangVertex; } - suffix = name.substr(ext, std::string::npos); } - - if (suffix == "vert") + if (stage_name == "vert") return EShLangVertex; - else if (suffix == "tesc") + else if (stage_name == "tesc") return EShLangTessControl; - else if (suffix == "tese") + else if (stage_name == "tese") return EShLangTessEvaluation; - else if (suffix == "geom") + else if (stage_name == "geom") return EShLangGeometry; - else if (suffix == "frag") + else if (stage_name == "frag") return EShLangFragment; - else if (suffix == "comp") + else if (stage_name == "comp") return EShLangCompute; usage(); From ef203bfa3859c193b531677dd5ab7fb9f67e5a8b Mon Sep 17 00:00:00 2001 From: Grigory Dzhavadyan Date: Thu, 12 Apr 2018 19:29:26 -0700 Subject: [PATCH 2/3] Fix build error --- StandAlone/StandAlone.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StandAlone/StandAlone.cpp b/StandAlone/StandAlone.cpp index 4602184a..a3e01370 100644 --- a/StandAlone/StandAlone.cpp +++ b/StandAlone/StandAlone.cpp @@ -1214,9 +1214,9 @@ EShLanguage FindLanguage(const std::string& name, bool parseStageName) size_t second_ext_start = has_first_ext ? name.find_last_of(".", first_ext_start - 1) : std::string::npos; bool has_second_ext = second_ext_start != std::string::npos; + std::string first_ext = name.substr(first_ext_start + 1, std::string::npos); bool uses_unified_ext = has_first_ext && (first_ext == "glsl" || first_ext == "hlsl"); - std::string first_ext = name.substr(first_ext_start + 1, std::string::npos); if (has_first_ext && !uses_unified_ext) { stage_name = first_ext; } else if (uses_unified_ext && has_second_ext) { From 33ddaaafc1b8e4fa3b55ceb9b5a1130e1c6028ee Mon Sep 17 00:00:00 2001 From: Grigory Dzhavadyan Date: Thu, 12 Apr 2018 20:31:27 -0700 Subject: [PATCH 3/3] Make FindLanguage use the entire name if parseStageName is false --- StandAlone/StandAlone.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/StandAlone/StandAlone.cpp b/StandAlone/StandAlone.cpp index a3e01370..cfbfe3fb 100644 --- a/StandAlone/StandAlone.cpp +++ b/StandAlone/StandAlone.cpp @@ -1202,7 +1202,6 @@ int C_DECL main(int argc, char* argv[]) EShLanguage FindLanguage(const std::string& name, bool parseStageName) { std::string stage_name; - if (shaderStageName) { stage_name = shaderStageName; } else if (parseStageName) { @@ -1225,6 +1224,8 @@ EShLanguage FindLanguage(const std::string& name, bool parseStageName) usage(); return EShLangVertex; } + } else { + stage_name = name; } if (stage_name == "vert") return EShLangVertex;