glslang
glslang copied to clipboard
Failed assertion when using `emitNonSemanticShaderDebugSource` on multiple source files
I'm attempting to add support for emitting this information in https://github.com/dpjudas/VkDoom/. This project handles user-defined shaders by passing multiple source files to setStringsWithLengthsAndNames
, since there's a fair bit of shader source code that is added before the user's shader, such as material structures and utility functions.
When enabling emitNonSemanticShaderDebugSource
alongside EShMsgDebugInfo
, I get a failed assertion:
SPIRV/SpvBuilder.cpp:1083: spv::Id spv::Builder::makeDebugSource(spv::Id): Assertion `incItr != includeFiles.end()' failed.
As far as I can tell, this is because glslang
currently assumes for this purpose that there is only one source file:
if (fileName == sourceFileStringId) {
If this check fails, it tries to look up the file as an included one. Since it hasn't been included either, the assertion fails.
If this is considered incorrect API usage, a better approach would be appreciated.
Could you provide a reproduction case or detailed instructions about how to reproduce this? Also, just in case, could you confirm that you are using the latest version of glslang, as we have fixed some bugs in nonsemantic debug info generation recently.
Sure, here's a modification to StandAlone.cpp
which makes it exhibit this behaviour:
diff --git a/StandAlone/StandAlone.cpp b/StandAlone/StandAlone.cpp
index 8833e38e..b9bf374f 100644
--- a/StandAlone/StandAlone.cpp
+++ b/StandAlone/StandAlone.cpp
@@ -1217,7 +1217,7 @@ void StderrIfNonEmpty(const char* str)
// and separation of handling file IO versus API (programmatic) compilation.
struct ShaderCompUnit {
EShLanguage stage;
- static const int maxCount = 1;
+ static const int maxCount = 2;
int count; // live number of strings/names
const char* text[maxCount]; // memory owned/managed externally
std::string fileName[maxCount]; // hold's the memory, but...
@@ -1613,6 +1613,8 @@ void CompileAndLinkShaderFiles(glslang::TWorklist& Worklist)
char* fileText = ReadFileData(workItem->name.c_str());
if (fileText == nullptr)
usage();
+ auto p = std::string("prefix");
+ compUnit.addString(p, strdup("#version 450\nvec2 something() { return vec2(0.0); }"));
compUnit.addString(workItem->name, fileText);
compUnits.push_back(compUnit);
}
Tested on this vertex shader:
void main() {
gl_Position = vec4(something(), 0.0, 1.0);
}
With the following command:
./build/Debug/StandAlone/glslangValidator -gVS -V -H -l main.vert
Giving this output:
SpvBuilder.cpp:1083: spv::Id spv::Builder::makeDebugSource(spv::Id): Assertion `incItr != includeFiles.end()' failed.
Without -gVS
, the compile works fine.