From afe6e9c4fc1ba0e8ea6ee9ee0ccbe872fd33efad Mon Sep 17 00:00:00 2001 From: dankbaker Date: Sun, 21 Aug 2016 12:29:08 -0400 Subject: [PATCH] HLSL and standalone, modifying Standalone to send filename as string source, and HLSL backend will use this to print a better error mesage when things fail --- StandAlone/StandAlone.cpp | 23 +++++++++++++++++++++-- hlsl/hlslParseHelper.cpp | 9 ++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/StandAlone/StandAlone.cpp b/StandAlone/StandAlone.cpp index 0a8f395..0c54273 100644 --- a/StandAlone/StandAlone.cpp +++ b/StandAlone/StandAlone.cpp @@ -412,7 +412,26 @@ void StderrIfNonEmpty(const char* str) struct ShaderCompUnit { EShLanguage stage; std::string fileName; - char** text; // memory owned/managed externally + char** text; // memory owned/managed externally + const char* fileNameList[1]; + + //Need to have a special constructors to adjust the fileNameList, since back end needs a list of ptrs + ShaderCompUnit(EShLanguage istage, std::string &ifileName, char** itext) + { + stage = istage; + fileName = ifileName; + text = itext; + fileNameList[0] = fileName.c_str(); + } + + ShaderCompUnit(const ShaderCompUnit &rhs) + { + stage = rhs.stage; + fileName = rhs.fileName; + text = rhs.text; + fileNameList[0] = fileName.c_str(); + } + }; // @@ -439,7 +458,7 @@ void CompileAndLinkShaderUnits(std::vector compUnits) for (auto it = compUnits.cbegin(); it != compUnits.cend(); ++it) { const auto &compUnit = *it; glslang::TShader* shader = new glslang::TShader(compUnit.stage); - shader->setStrings(compUnit.text, 1); + shader->setStringsWithLengthsAndNames(compUnit.text, NULL, compUnit.fileNameList, 1); if (entryPointName) // HLSL todo: this needs to be tracked per compUnits shader->setEntryPoint(entryPointName); shaders.push_back(shader); diff --git a/hlsl/hlslParseHelper.cpp b/hlsl/hlslParseHelper.cpp index 2a79375..2662ea0 100755 --- a/hlsl/hlslParseHelper.cpp +++ b/hlsl/hlslParseHelper.cpp @@ -116,9 +116,12 @@ bool HlslParseContext::parseShaderStrings(TPpContext& ppContext, TInputScanner& HlslScanContext scanContext(*this, ppContext); HlslGrammar grammar(scanContext, *this); - if (! grammar.parse()) - printf("HLSL translation failed.\n"); - + if (!grammar.parse()) + { + //Print out a nicer error message that should be formated such that if you click on the message it will take you right to the line through most UIs + const glslang::TSourceLoc& sourceLoc = input.getSourceLoc(); + printf("\n%s(%i): error at column %i, HLSL translation failed.\n", sourceLoc.name, sourceLoc.line, sourceLoc.column); + } return numErrors == 0; } -- 2.7.4