Skip to content

Commit cb7a696

Browse files
authored
PIX: Use DebugLoc for filenames instead of file list (#4077)
This fix is for shaders (in particular those for materials from Unreal Engine) that feature #line directives. In the UE case, for example, there is one source file called hlsl.hlsl, with many #line directives pointing to the original HLSL files from which the source was assembled via UE's material system. At the start of shader debugging, all the filenames from DebugLoc are returned from code near here to PIX. Those filenames are the ones from the #line directives. The previous code would iterate over source file names (which in the UE case would be just hlsl.hlsl), and fail to find the filename that PIX is now asking to find the instructions for. Instead, we now gather the filenames from the DebugLoc. Note that the filename comparison is done after the line number comparison for performance's sake.
1 parent e4ddf78 commit cb7a696

1 file changed

Lines changed: 16 additions & 24 deletions

File tree

lib/DxilDia/DxcPixDxilDebugInfo.cpp

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -172,32 +172,24 @@ dxil_debug_info::DxcPixDxilInstructionOffsets::DxcPixDxilInstructionOffsets(
172172
{
173173
assert(SourceColumn == 0);
174174
(void)SourceColumn;
175-
176-
auto files = pSession->Contents()->operands();
177-
for (const auto& file : files)
178-
{
179-
auto candidateFilename = llvm::dyn_cast<llvm::MDString>(file->getOperand(0))
180-
->getString();
181-
182-
if (CompareFilenames(FileName, candidateFilename.str().c_str()))
183-
{
184-
185-
auto Fn = pSession->DxilModuleRef().GetEntryFunction();
186-
auto &Blocks = Fn->getBasicBlockList();
187-
for (auto& CurrentBlock : Blocks) {
188-
auto& Is = CurrentBlock.getInstList();
189-
for (auto& Inst : Is) {
190-
auto & debugLoc = Inst.getDebugLoc();
191-
if (debugLoc)
175+
auto Fn = pSession->DxilModuleRef().GetEntryFunction();
176+
auto &Blocks = Fn->getBasicBlockList();
177+
for (auto& CurrentBlock : Blocks) {
178+
auto& Is = CurrentBlock.getInstList();
179+
for (auto& Inst : Is) {
180+
auto & debugLoc = Inst.getDebugLoc();
181+
if (debugLoc)
182+
{
183+
unsigned line = debugLoc.getLine();
184+
if (line == SourceLine)
185+
{
186+
auto file = debugLoc.get()->getFilename();
187+
if (CompareFilenames(FileName, file.str().c_str()))
192188
{
193-
unsigned line = debugLoc.getLine();
194-
if (line == SourceLine)
189+
std::uint32_t InstructionNumber;
190+
if (pix_dxil::PixDxilInstNum::FromInst(&Inst, &InstructionNumber))
195191
{
196-
std::uint32_t InstructionNumber;
197-
if (pix_dxil::PixDxilInstNum::FromInst(&Inst, &InstructionNumber))
198-
{
199-
m_offsets.push_back(InstructionNumber);
200-
}
192+
m_offsets.push_back(InstructionNumber);
201193
}
202194
}
203195
}

0 commit comments

Comments
 (0)