mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-10-18 18:19:12 +00:00
Scroll shader viewer to entry point file & line using debug info
This commit is contained in:
12 files changed
+133
-20
No files matched your search
@@ -1401,6 +1401,22 @@ The first entry in the list is always the file where the entry point is.
|
||||
)");
|
||||
rdcarray<ShaderSourceFile> files;
|
||||
|
||||
DOCUMENT(R"(The source location of the first executable line or the entry point.
|
||||
|
||||
.. note::
|
||||
|
||||
The information is not guaranteed to be available depending on the underlying shader format, so
|
||||
all of the elements are optional.
|
||||
)");
|
||||
LineColumnInfo entryLocation;
|
||||
|
||||
DOCUMENT(R"(The index of the file which should be used for re-editing this shader's entry point.
|
||||
|
||||
This is an optional value, and if set to ``-1`` you should fall back to using the file specified
|
||||
in :data:`entryLocation`, and if no file is specified there then use the first file listed.
|
||||
)");
|
||||
int32_t editBaseFile = -1;
|
||||
|
||||
DOCUMENT("The :class:`ShaderEncoding` of the source. See :data:`files`.");
|
||||
ShaderEncoding encoding = ShaderEncoding::Unknown;
|
||||
|
||||
|
||||
@@ -299,6 +299,8 @@ void MakeShaderReflection(DXBC::DXBCContainer *dxbc, ShaderReflection *refl,
|
||||
|
||||
refl->debugInfo.files = dxbc->GetDebugInfo()->Files;
|
||||
|
||||
dxbc->GetDebugInfo()->GetLineInfo(~0U, ~0U, refl->debugInfo.entryLocation);
|
||||
|
||||
rdcstr entry = dxbc->GetDebugInfo()->GetEntryFunction();
|
||||
if(entry.empty())
|
||||
entry = "main";
|
||||
|
||||
@@ -94,8 +94,11 @@ SDBGChunk::SDBGChunk(void *data)
|
||||
m_HasDebugInfo = true;
|
||||
}
|
||||
|
||||
void SDBGChunk::GetLineInfo(size_t instruction, uintptr_t offset, LineColumnInfo &lineInfo) const
|
||||
void SDBGChunk::GetLineInfo(size_t instruction, uintptr_t, LineColumnInfo &lineInfo) const
|
||||
{
|
||||
if(instruction == ~0U)
|
||||
instruction = 0;
|
||||
|
||||
if(instruction < m_Instructions.size())
|
||||
{
|
||||
int32_t symID = m_Instructions[instruction].symbol;
|
||||
|
||||
@@ -1698,6 +1698,12 @@ SPDBChunk::SPDBChunk(byte *data, uint32_t spdblength)
|
||||
|
||||
void SPDBChunk::GetLineInfo(size_t, uintptr_t offset, LineColumnInfo &lineInfo) const
|
||||
{
|
||||
if(offset == ~0U && !m_InstructionInfo.empty())
|
||||
{
|
||||
lineInfo = m_InstructionInfo.begin()->second.lineInfo;
|
||||
return;
|
||||
}
|
||||
|
||||
auto it = m_InstructionInfo.lower_bound((uint32_t)offset);
|
||||
|
||||
if(it != m_InstructionInfo.end() && (uintptr_t)it->first <= offset)
|
||||
|
||||
@@ -576,10 +576,27 @@ void Reflector::RegisterOp(Iter it)
|
||||
{
|
||||
sources.back().contents += strings[dbg.arg<Id>(0)];
|
||||
}
|
||||
else if(dbg.inst == ShaderDbg::Function)
|
||||
{
|
||||
LineColumnInfo &info = debugFuncToLocation[dbg.result];
|
||||
|
||||
info.fileIndex = (int32_t)debugSources[dbg.arg<Id>(2)];
|
||||
info.lineStart = info.lineEnd = EvaluateConstant(dbg.arg<Id>(3), {}).value.u32v[0];
|
||||
}
|
||||
else if(dbg.inst == ShaderDbg::FunctionDefinition)
|
||||
{
|
||||
funcToLocation[dbg.arg<Id>(1)] = debugFuncToLocation[dbg.arg<Id>(0)];
|
||||
}
|
||||
else if(dbg.inst == ShaderDbg::CompilationUnit)
|
||||
{
|
||||
sources[debugSources[dbg.arg<Id>(2)]].lang =
|
||||
(SourceLanguage)EvaluateConstant(dbg.arg<Id>(3), {}).value.u32v[0];
|
||||
|
||||
compUnitToFileIndex[dbg.result] = debugSources[dbg.arg<Id>(2)];
|
||||
}
|
||||
else if(dbg.inst == ShaderDbg::EntryPoint)
|
||||
{
|
||||
funcToBaseFile[dbg.arg<Id>(0)] = compUnitToFileIndex[dbg.arg<Id>(1)];
|
||||
}
|
||||
else if(dbg.inst == ShaderDbg::GlobalVariable)
|
||||
{
|
||||
@@ -837,6 +854,18 @@ void Reflector::MakeReflection(const GraphicsAPI sourceAPI, const ShaderStage st
|
||||
reflection.debugInfo.files.push_back({sources[i].name, sources[i].contents});
|
||||
}
|
||||
|
||||
{
|
||||
auto it = funcToLocation.find(entry->id);
|
||||
if(it != funcToLocation.end())
|
||||
reflection.debugInfo.entryLocation = it->second;
|
||||
}
|
||||
|
||||
{
|
||||
auto it = funcToBaseFile.find(entry->id);
|
||||
if(it != funcToBaseFile.end())
|
||||
reflection.debugInfo.editBaseFile = (int32_t)it->second;
|
||||
}
|
||||
|
||||
PreprocessLineDirectives(reflection.debugInfo.files);
|
||||
|
||||
// we do a mini-preprocess of the files from the debug info to handle #line directives.
|
||||
|
||||
@@ -129,6 +129,10 @@ private:
|
||||
DenseIdMap<rdcstr> strings;
|
||||
rdcarray<SourceFile> sources;
|
||||
SparseIdMap<size_t> debugSources;
|
||||
SparseIdMap<size_t> compUnitToFileIndex;
|
||||
SparseIdMap<size_t> funcToBaseFile;
|
||||
SparseIdMap<LineColumnInfo> debugFuncToLocation;
|
||||
SparseIdMap<LineColumnInfo> funcToLocation;
|
||||
|
||||
Id curBlock;
|
||||
std::set<Id> loopBlocks;
|
||||
|
||||
@@ -265,11 +265,13 @@ void DoSerialise(SerialiserType &ser, ShaderDebugInfo &el)
|
||||
{
|
||||
SERIALISE_MEMBER(compileFlags);
|
||||
SERIALISE_MEMBER(files);
|
||||
SERIALISE_MEMBER(entryLocation);
|
||||
SERIALISE_MEMBER(editBaseFile);
|
||||
SERIALISE_MEMBER(encoding);
|
||||
SERIALISE_MEMBER(debuggable);
|
||||
SERIALISE_MEMBER(debugStatus);
|
||||
|
||||
SIZE_CHECK(80);
|
||||
SIZE_CHECK(112);
|
||||
}
|
||||
|
||||
template <typename SerialiserType>
|
||||
@@ -301,7 +303,7 @@ void DoSerialise(SerialiserType &ser, ShaderReflection &el)
|
||||
|
||||
SERIALISE_MEMBER(pointerTypes);
|
||||
|
||||
SIZE_CHECK(360);
|
||||
SIZE_CHECK(392);
|
||||
}
|
||||
|
||||
template <typename SerialiserType>
|
||||
|
||||
Reference in new issue
Block a user