Process fake OpModuleProcessed comments in non-semantic debug source

This commit is contained in:
baldurk
2025-09-19 16:03:18 +01:00
parent f17604df26
commit 5f95354737
2 changed files with 50 additions and 41 deletions
@@ -580,47 +580,7 @@ void Reflector::RegisterOp(Iter it)
{
OpSource source(it);
// glslang based tools output fake OpModuleProcessed comments at the start of pre-1.3
// shaders source before OpModuleProcessed existed (in SPIR-V 1.1)
if(m_MajorVersion == 1 && m_MinorVersion < 1 && HasCommandLineInModuleProcessed(m_Generator))
{
rdcstr &src = source.source;
const char compileFlagPrefix[] = "// OpModuleProcessed ";
const char endMarker[] = "#line 1\n";
if(src.find(compileFlagPrefix) == 0)
{
// process compile flags
int32_t nextLine = src.indexOf('\n');
while(nextLine > 0)
{
bool finished = false;
if(src.find(compileFlagPrefix) == 0)
{
size_t offs = sizeof(compileFlagPrefix) - 1;
cmdline += " --" + src.substr(offs, nextLine - offs);
}
else if(src.find(endMarker) == 0)
{
finished = true;
}
else
{
RDCERR("Unexpected preamble line with OpModuleProcessed: %s",
src.substr(0, nextLine).c_str());
break;
}
// erase this line
src.erase(0, nextLine + 1);
nextLine = src.indexOf('\n');
if(finished)
break;
}
}
}
ProcessFakeModuleProcessed(source.source);
sourceLanguage = source.sourceLanguage;
@@ -664,6 +624,8 @@ void Reflector::RegisterOp(Iter it)
rdcstr name = strings[dbg.arg<Id>(0)];
rdcstr source = dbg.params.size() > 1 ? strings[dbg.arg<Id>(1)] : rdcstr();
ProcessFakeModuleProcessed(source);
// don't add empty source statements as actual files
if(!name.empty() || !source.empty())
{
@@ -729,6 +691,49 @@ void Reflector::UnregisterOp(Iter it)
RDCFATAL("Reflector should not be used for editing! UnregisterOp() call invalid");
}
void Reflector::ProcessFakeModuleProcessed(rdcstr &src)
{
// glslang based tools output fake OpModuleProcessed comments at the start of pre-1.3
// shaders source before OpModuleProcessed existed (in SPIR-V 1.1)
if(m_MajorVersion == 1 && m_MinorVersion < 1 && HasCommandLineInModuleProcessed(m_Generator))
{
const char compileFlagPrefix[] = "// OpModuleProcessed ";
const char endMarker[] = "#line 1\n";
if(src.find(compileFlagPrefix) == 0)
{
// process compile flags
int32_t nextLine = src.indexOf('\n');
while(nextLine > 0)
{
bool finished = false;
if(src.find(compileFlagPrefix) == 0)
{
size_t offs = sizeof(compileFlagPrefix) - 1;
cmdline += " --" + src.substr(offs, nextLine - offs);
}
else if(src.find(endMarker) == 0)
{
finished = true;
}
else
{
RDCERR("Unexpected preamble line with OpModuleProcessed: %s",
src.substr(0, nextLine).c_str());
break;
}
// erase this line
src.erase(0, nextLine + 1);
nextLine = src.indexOf('\n');
if(finished)
break;
}
}
}
}
void Reflector::CalculateArrayTypeName(DataType &type)
{
// prefer the name
@@ -2429,6 +2434,8 @@ TEST_CASE("Validate SPIR-V reflection", "[spirv][reflection]")
REQUIRE(!spirv.empty());
FileIO::WriteAll("T:/tmp/a.spv", spirv);
rdcspv::Reflector spv;
spv.Parse(spirv);
@@ -118,6 +118,8 @@ private:
virtual void RegisterOp(Iter iter);
virtual void UnregisterOp(Iter iter);
void ProcessFakeModuleProcessed(rdcstr &src);
void CalculateArrayTypeName(DataType &type);
rdcstr StringiseConstant(rdcspv::Id id) const;