Skip to content

Commit

Permalink
Report and handle source-level entry point name from exported name
Browse files Browse the repository at this point in the history
* The compiler could compile an entry point "foo" into an export "bar". We use
  the exported name in most places as that's guaranteed to be unique by the API
  and used for cross-referencing, but when recompiling we pass the original
  source name as in the debug info.
  • Loading branch information
baldurk committed Mar 5, 2024
1 parent c1f775e commit b9fd432
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion qrenderdoc/Windows/PipelineState/PipelineStateViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ IShaderViewer *PipelineStateViewer::EditOriginalShaderSource(ResourceId id,
files.push_back(make_rdcpair(s.filename, s.contents));
}

return EditShader(id, shaderDetails->stage, shaderDetails->entryPoint,
return EditShader(id, shaderDetails->stage, shaderDetails->debugInfo.entrySourceName,
shaderDetails->debugInfo.compileFlags, shaderDetails->debugInfo.compiler,
shaderDetails->debugInfo.encoding, files);
}
Expand Down
7 changes: 7 additions & 0 deletions renderdoc/api/replay/shader_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,13 @@ The first entry in the list is always the file where the entry point is.
)");
rdcarray<ShaderSourceFile> files;

DOCUMENT(R"(The name of the entry point in the source code, not necessarily the same as the
entry point name exported to the API.
:type: str
)");
rdcstr entrySourceName;

DOCUMENT(R"(The source location of the first executable line or the entry point.
.. note::
Expand Down
2 changes: 1 addition & 1 deletion renderdoc/driver/gl/gl_shader_refl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ void MakeShaderReflection(GLenum shadType, GLuint sepProg, ShaderReflection &ref
const FixedFunctionVertexOutputs &outputUsage)
{
refl.stage = MakeShaderStage(shadType);
refl.entryPoint = "main";
refl.debugInfo.entrySourceName = refl.entryPoint = "main";
refl.encoding = ShaderEncoding::GLSL;
refl.debugInfo.compiler = KnownShaderTool::Unknown;
refl.debugInfo.encoding = ShaderEncoding::GLSL;
Expand Down
4 changes: 2 additions & 2 deletions renderdoc/driver/shaders/dxbc/dxbc_reflect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,11 @@ void MakeShaderReflection(DXBC::DXBCContainer *dxbc, ShaderReflection *refl,
break;
}

refl->entryPoint = "main";
refl->debugInfo.entrySourceName = refl->entryPoint = "main";

if(dxbc->GetDebugInfo())
{
refl->entryPoint = dxbc->GetDebugInfo()->GetEntryFunction();
refl->debugInfo.entrySourceName = refl->entryPoint = dxbc->GetDebugInfo()->GetEntryFunction();

refl->debugInfo.encoding = ShaderEncoding::HLSL;

Expand Down
7 changes: 7 additions & 0 deletions renderdoc/driver/shaders/spirv/spirv_reflect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,8 @@ void Reflector::RegisterOp(Iter it)
{
LineColumnInfo &info = debugFuncToLocation[dbg.result];

debugFuncName[dbg.result] = strings[dbg.arg<Id>(0)];

// check this source file exists - we won't have registered it if there was no source code
auto srcit = debugSources.find(dbg.arg<Id>(2));
if(srcit != debugSources.end())
Expand Down Expand Up @@ -1029,10 +1031,15 @@ void Reflector::MakeReflection(const GraphicsAPI sourceAPI, const ShaderStage st
reflection.debugInfo.compileFlags.flags.push_back(
{"@spirver", StringFormat::Fmt("spirv%d.%d", m_MajorVersion, m_MinorVersion)});

reflection.debugInfo.entrySourceName = entryPoint;

{
auto it = funcToDebugFunc.find(entry->id);
if(it != funcToDebugFunc.end())
{
rdcstr debugEntryName = debugFuncName[it->second];
if(!debugEntryName.empty())
reflection.debugInfo.entrySourceName = debugEntryName;
reflection.debugInfo.entryLocation = debugFuncToLocation[it->second];
if(debugFuncToCmdLine.find(it->second) != debugFuncToCmdLine.end())
reflection.debugInfo.compileFlags.flags = {{"@cmdline", debugFuncToCmdLine[it->second]}};
Expand Down
1 change: 1 addition & 0 deletions renderdoc/driver/shaders/spirv/spirv_reflect.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class Reflector : public Processor
SparseIdMap<size_t> debugFuncToBaseFile;
SparseIdMap<rdcstr> debugFuncToCmdLine;
SparseIdMap<LineColumnInfo> debugFuncToLocation;
SparseIdMap<rdcstr> debugFuncName;
SparseIdMap<Id> funcToDebugFunc;

Id curBlock;
Expand Down
4 changes: 2 additions & 2 deletions renderdoc/replay/renderdoc_serialise.inl
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ void DoSerialise(SerialiserType &ser, ShaderDebugInfo &el)
SERIALISE_MEMBER(sourceDebugInformation);
SERIALISE_MEMBER(debugStatus);

SIZE_CHECK(112);
SIZE_CHECK(136);
}

template <typename SerialiserType>
Expand Down Expand Up @@ -310,7 +310,7 @@ void DoSerialise(SerialiserType &ser, ShaderReflection &el)

SERIALISE_MEMBER(taskPayload);

SIZE_CHECK(456);
SIZE_CHECK(480);
}

template <typename SerialiserType>
Expand Down

0 comments on commit b9fd432

Please sign in to comment.