-
Notifications
You must be signed in to change notification settings - Fork 2
[Driver][DirectX] Add /Qembed_debug and /Fd flags #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dx-debug
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,15 +39,12 @@ using namespace llvm; | |
| using namespace llvm::dxil; | ||
| using namespace llvm::mcdxbc; | ||
|
|
||
| static cl::opt<std::string> | ||
| PdbFileName("dx-pdb-file", | ||
| cl::desc("Specify the PDB output file path for DirectX target"), | ||
| cl::value_desc("filename")); | ||
| static cl::opt<std::string> PdbOutputDir( | ||
| "dx-pdb-dir", | ||
| cl::desc("Specify the PDB output directory for DirectX target. The file " | ||
| "name is derived from the shader hash"), | ||
| cl::value_desc("directory")); | ||
| extern llvm::cl::opt<bool> EmbedDebug; | ||
| cl::opt<std::string> PdbDebugPath( | ||
| "dx-Fd", | ||
| cl::desc("Write debug information to the given file, or automatically " | ||
| "named file in directory when ending in '\\'"), | ||
| cl::value_desc("filename")); | ||
|
Comment on lines
41
to
+47
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. /Fd is an option of original DXC to specify output PDB file name.
As of my knowledge, llc does not have any existing flag which has similar behavior (changing what we do depending on whether a directory path or a file path is provided as a value for the same argument).
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we always generate
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I implemented this logic in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Then the driver would need to modify the content of llc's output files, because PDB file name is baked into PDB file and into the main llc output file. |
||
| static cl::opt<bool> ShaderHashDependsOnSource( | ||
| "dx-Zss", cl::desc("Compute Shader Hash considering source information")); | ||
| extern cl::opt<bool> SourceInDebugModule; | ||
|
|
@@ -149,9 +146,9 @@ void DXContainerGlobals::computeShaderHashAndDebugName( | |
| } | ||
|
|
||
| Digest.update(DXILConstant->getRawDataValues()); | ||
| MD5::MD5Result Result = Digest.final(); | ||
| MD5::MD5Result MD5 = Digest.final(); | ||
|
|
||
| memcpy(reinterpret_cast<void *>(&HashData.Digest), Result.data(), 16); | ||
| memcpy(reinterpret_cast<void *>(&HashData.Digest), MD5.data(), 16); | ||
| if (sys::IsBigEndianHost) | ||
| HashData.swapBytes(); | ||
| StringRef Data(reinterpret_cast<char *>(&HashData), sizeof(dxbc::ShaderHash)); | ||
|
|
@@ -168,38 +165,40 @@ void DXContainerGlobals::computeShaderHashAndDebugName( | |
| if (!MMI.SourceInfo) | ||
| return; | ||
|
|
||
| if (!PdbFileName.empty() && !PdbOutputDir.empty()) | ||
| report_fatal_error( | ||
| "--dx-pdb-file and --dx-pdb-dir are mutually exclusive options"); | ||
| if (!EmbedDebug && PdbDebugPath.empty()) | ||
| return; | ||
|
Comment on lines
+168
to
+169
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ILDN (Shader debug name) part must be emitted when debug info is emitted, regardless of whether
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't sure where to put this yet, since we don't have a
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we only have /Zi, as for now. |
||
|
|
||
| SmallString<40> DebugNameStr; | ||
| mcdxbc::DebugName DebugName; | ||
| if (PdbFileName.empty()) { | ||
| // TODO Add an option to compute hash based on ILDB. | ||
| Digest.stringifyResult(Result, DebugNameStr); | ||
| DebugNameStr += ".pdb"; | ||
| } else { | ||
| // Use user-provided PDB file name. | ||
| DebugNameStr = PdbFileName; | ||
| } | ||
| DebugName.setFilename(DebugNameStr); | ||
| Digest.stringifyResult(MD5, DebugNameStr); | ||
| DebugNameStr += ".pdb"; | ||
| if (!PdbDebugPath.empty()) { | ||
| StringRef DebugFile = PdbDebugPath.getValue(); | ||
| SmallString<256> AbsoluteDebugName; | ||
| if (sys::path::is_separator(DebugFile.back())) { | ||
| // If /Fd was specified as a directory, put the MD5.pdb file there. | ||
| AbsoluteDebugName = DebugFile; | ||
| sys::path::append(AbsoluteDebugName, DebugNameStr); | ||
| } else { | ||
| // Otherwise, use /Fd value as a user-provided PDB file name. | ||
| DebugNameStr = DebugFile; | ||
| AbsoluteDebugName = DebugNameStr; | ||
| } | ||
|
|
||
| SmallString<256> AbsoluteDebugName(PdbOutputDir); | ||
| sys::path::append(AbsoluteDebugName, DebugNameStr); | ||
| // Pass PDB name to DXContainerPDBPass via PDBNAME section. | ||
| addSection(M, Globals, AbsoluteDebugName, "dx.pdb.name", | ||
| PdbFileNameSectionName); | ||
| // Pass module hash to DXContainerPDBPass. | ||
| Globals.emplace_back(buildContainerGlobal( | ||
| M, ConstantDataArray::get(M.getContext(), ArrayRef(HashData.Digest)), | ||
| "dx.pdb.hash", ModuleHashSectionName)); | ||
| } | ||
|
|
||
| mcdxbc::DebugName DebugName; | ||
| DebugName.setFilename(DebugNameStr); | ||
| SmallString<64> ILDNData; | ||
| raw_svector_ostream OS(ILDNData); | ||
| DebugName.write(OS); | ||
| addSection(M, Globals, ILDNData, "dx.ildn", "ILDN"); | ||
|
|
||
| // TODO Do not create PDB in embedded mode. | ||
| // Pass PDB name to DXContainerPDBPass via PDBNAME section. | ||
| addSection(M, Globals, AbsoluteDebugName, "dx.pdb.name", | ||
| PdbFileNameSectionName); | ||
| // Pass module hash to DXContainerPDBPass. | ||
| Globals.emplace_back(buildContainerGlobal( | ||
| M, ConstantDataArray::get(M.getContext(), ArrayRef(HashData.Digest)), | ||
| "dx.pdb.hash", ModuleHashSectionName)); | ||
| } | ||
|
|
||
| GlobalVariable *DXContainerGlobals::buildContainerGlobal( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More sections need to be filtered out (such as VERS). Please refer to the PDB doc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VERS is still output there when compiled as a library (which we do in all tests), I'm not sure how to check for this or if we even need to. The other sections are dependent on other flags, as I understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point about VERS.
Yet SRCI should be always filtered out here.