Skip to content

Commit 1c10c06

Browse files
committed
Make DXIL GlobalVar names unique in the debugger and disassmbly
1 parent 9c31e01 commit 1c10c06

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

renderdoc/driver/shaders/dxil/dxil_bytecode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,6 +1850,7 @@ bool ShouldIgnoreSourceMapping(const Instruction &inst);
18501850
bool isUndef(const Value *v);
18511851

18521852
void SanitiseName(rdcstr &name);
1853+
rdcstr GetGlobalVarName(const GlobalVar *gv);
18531854

18541855
}; // namespace DXIL
18551856

renderdoc/driver/shaders/dxil/dxil_debug.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5406,6 +5406,8 @@ bool ThreadState::ExecuteInstruction(DebugAPIWrapper *apiWrapper,
54065406
case Operation::Alloca:
54075407
{
54085408
result.name = DXBC::BasicDemangle(result.name);
5409+
result.name += "_";
5410+
result.name += ToStr(resultId);
54095411
m_Memory.AllocateMemoryForType(inst.type, resultId, false, false, result);
54105412
break;
54115413
}
@@ -8944,8 +8946,7 @@ ShaderDebugTrace *Debugger::BeginDebug(uint32_t eventId, const DXBC::DXBCContain
89448946
for(const DXIL::GlobalVar *gv : m_Program->m_GlobalVars)
89458947
{
89468948
GlobalVariable globalVar;
8947-
rdcstr n = DXBC::BasicDemangle(gv->name);
8948-
DXIL::SanitiseName(n);
8949+
rdcstr n = DXIL::GetGlobalVarName(gv);
89498950
globalVar.var.name = n;
89508951
globalVar.id = gv->ssaId;
89518952
globalVar.gsm = (gv->type->addrSpace == DXIL::Type::PointerAddrSpace::GroupShared);

renderdoc/driver/shaders/dxil/dxil_disassemble.cpp

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,12 +1724,7 @@ rdcstr Program::DisassembleGlobalVars(int &instructionLine) const
17241724
{
17251725
const GlobalVar &g = *m_GlobalVars[i];
17261726

1727-
rdcstr n = g.name;
1728-
if(!m_DXCStyle)
1729-
{
1730-
n = DXBC::BasicDemangle(g.name);
1731-
DXIL::SanitiseName(n);
1732-
}
1727+
rdcstr n = !m_DXCStyle ? DXIL::GetGlobalVarName(&g) : g.name;
17331728
ret += StringFormat::Fmt("@%s = ", escapeStringIfNeeded(n).c_str());
17341729
switch(g.flags & GlobalFlags::LinkageMask)
17351730
{
@@ -1772,6 +1767,7 @@ rdcstr Program::DisassembleGlobalVars(int &instructionLine) const
17721767
if(g.section >= 0)
17731768
ret += StringFormat::Fmt(", section %s", escapeString(m_Sections[g.section]).c_str());
17741769

1770+
ret += " // " + escapeString(g.name);
17751771
ret += "\n";
17761772
instructionLine++;
17771773
}
@@ -4718,21 +4714,11 @@ void Program::MakeRDDisassemblyString(const DXBC::Reflection *reflection)
47184714
// arg[0] : ptr
47194715
if(cast<GlobalVar>(inst.args[0]))
47204716
{
4721-
lineStr += DXBC::BasicDemangle(cast<GlobalVar>(inst.args[0])->name);
4717+
lineStr += DXIL::GetGlobalVarName(cast<GlobalVar>(inst.args[0]));
47224718
}
47234719
else
47244720
{
4725-
rdcstr ptrStr = GetArgId(0);
4726-
// Simple demangle take string between first "?" and next "@"
4727-
int nameStart = ptrStr.indexOf('?');
4728-
if(nameStart > 0)
4729-
{
4730-
nameStart++;
4731-
int nameEnd = ptrStr.indexOf('@', nameStart);
4732-
if(nameEnd > nameStart)
4733-
ptrStr = ptrStr.substr(nameStart, nameEnd - nameStart);
4734-
lineStr += ptrStr;
4735-
}
4721+
lineStr += GetArgId(0);
47364722
}
47374723
// arg[1] : index 0
47384724
bool first = true;
@@ -6347,9 +6333,7 @@ SourceMappingInfo Program::ParseDbgOpDeclare(const DXIL::Instruction &inst) cons
63476333
else if(const GlobalVar *gv = cast<GlobalVar>(value))
63486334
{
63496335
ret.dbgVarId = gv->ssaId;
6350-
rdcstr n = DXBC::BasicDemangle(gv->name);
6351-
DXIL::SanitiseName(n);
6352-
ret.dbgVarName = n;
6336+
ret.dbgVarName = DXIL::GetGlobalVarName(gv);
63536337
}
63546338
else if(const Constant *c = cast<Constant>(value))
63556339
{
@@ -6376,4 +6360,13 @@ SourceMappingInfo Program::ParseDbgOpDeclare(const DXIL::Instruction &inst) cons
63766360
return ret;
63776361
}
63786362

6363+
rdcstr GetGlobalVarName(const GlobalVar *gv)
6364+
{
6365+
rdcstr n = DXBC::BasicDemangle(gv->name);
6366+
DXIL::SanitiseName(n);
6367+
n += "_";
6368+
n += ToStr(gv->ssaId);
6369+
return n;
6370+
}
6371+
63796372
}; // namespace DXIL

0 commit comments

Comments
 (0)