diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2023-03-10 14:19:48 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-10 14:19:48 -0500 |
| commit | 3fea56ef77a33273bf5af6f432163b30c0a0e1dc (patch) | |
| tree | 446df8ddd73521b33e836facaea2c27ef84c47fe /source/compiler-core | |
| parent | e39893e8eb1a9411fca4e5f885456a27a770d3a2 (diff) | |
Support for PDB output from DXC (#2693)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Add versioning to CompileOptions for DownstreamCompiler so we can add new options without breaking binary interface.
* Add support for debug info format to API/command line processing.
* Small simplification.
* Add support for adding PDB output from a compilation.
* Use builtin offset of directly.
* Fix typo in debug.
Diffstat (limited to 'source/compiler-core')
| -rw-r--r-- | source/compiler-core/slang-artifact-desc-util.cpp | 9 | ||||
| -rw-r--r-- | source/compiler-core/slang-artifact.h | 2 | ||||
| -rw-r--r-- | source/compiler-core/slang-downstream-compiler.h | 3 | ||||
| -rw-r--r-- | source/compiler-core/slang-dxc-compiler.cpp | 49 | ||||
| -rw-r--r-- | source/compiler-core/slang-visual-studio-compiler-util.cpp | 2 |
5 files changed, 61 insertions, 4 deletions
diff --git a/source/compiler-core/slang-artifact-desc-util.cpp b/source/compiler-core/slang-artifact-desc-util.cpp index 7e274794f..fff68738c 100644 --- a/source/compiler-core/slang-artifact-desc-util.cpp +++ b/source/compiler-core/slang-artifact-desc-util.cpp @@ -219,6 +219,7 @@ SLANG_HIERARCHICAL_ENUM(ArtifactKind, SLANG_ARTIFACT_KIND, SLANG_ARTIFACT_KIND_E x(CompileResults, Base) \ x(Metadata, Base) \ x(DebugInfo, Metadata) \ + x(PdbDebugInfo, DebugInfo) \ x(Diagnostics, Metadata) \ x(Miscellaneous, Base) \ x(Log, Miscellaneous) \ @@ -549,6 +550,12 @@ static const KindExtension g_cpuKindExts[] = return ArtifactDesc::make(ArtifactKind::Assembly, ArtifactPayload::HostCPU); } + if (slice == toSlice("pdb")) + { + // Program database + return ArtifactDesc::make(ArtifactKind::Assembly, ArtifactPayload::PdbDebugInfo); + } + for (const auto& kindExt : g_cpuKindExts) { if (slice == kindExt.ext) @@ -613,6 +620,8 @@ static UnownedStringSlice _getPayloadExtension(ArtifactPayload payload) case Payload::MetalAIR: return toSlice("air"); + case Payload::PdbDebugInfo: return toSlice("pdb"); + default: break; } return UnownedStringSlice(); diff --git a/source/compiler-core/slang-artifact.h b/source/compiler-core/slang-artifact.h index 222b902a5..df0bb21d5 100644 --- a/source/compiler-core/slang-artifact.h +++ b/source/compiler-core/slang-artifact.h @@ -178,6 +178,8 @@ enum class ArtifactPayload : uint8_t Log, ///< Log file Lock, ///< Typically some kind of 'lock' file. Contents is typically not important. + PdbDebugInfo, ///< PDB debug info + CountOf, }; diff --git a/source/compiler-core/slang-downstream-compiler.h b/source/compiler-core/slang-downstream-compiler.h index b1f1b7b11..3cd27138f 100644 --- a/source/compiler-core/slang-downstream-compiler.h +++ b/source/compiler-core/slang-downstream-compiler.h @@ -252,6 +252,9 @@ struct DownstreamCompileOptions /// NOTE! Not all downstream compilers can use the fileSystemExt/sourceManager. This option will be ignored in those scenarios. ISlangFileSystemExt* fileSystemExt = nullptr; SourceManager* sourceManager = nullptr; + + // The debug info format to use. + SlangDebugInfoFormat m_debugInfoFormat = SLANG_DEBUG_INFO_FORMAT_DEFAULT; }; #define SLANG_ALIAS_DEPRECIATED_VERSION(name, id, firstField, lastField) \ diff --git a/source/compiler-core/slang-dxc-compiler.cpp b/source/compiler-core/slang-dxc-compiler.cpp index 9df2a4f3f..248d8d118 100644 --- a/source/compiler-core/slang-dxc-compiler.cpp +++ b/source/compiler-core/slang-dxc-compiler.cpp @@ -451,6 +451,8 @@ SlangResult DXCDownstreamCompiler::compile(const CompileOptions& inOptions, IArt break; } + + switch (options.optimizationLevel) { default: @@ -549,7 +551,7 @@ SlangResult DXCDownstreamCompiler::compile(const CompileOptions& inOptions, IArt DxcIncludeHandler includeHandler(&searchDirectories, options.fileSystemExt, options.sourceManager); - ComPtr<IDxcOperationResult> dxcResult; + ComPtr<IDxcOperationResult> dxcOperationResult; SLANG_RETURN_ON_FAIL(dxcCompiler->Compile(dxcSourceBlob, wideSourcePath.begin(), wideEntryPointName.begin(), @@ -559,13 +561,13 @@ SlangResult DXCDownstreamCompiler::compile(const CompileOptions& inOptions, IArt nullptr, // `#define`s 0, // `#define` count &includeHandler, // `#include` handler - dxcResult.writeRef())); + dxcOperationResult.writeRef())); auto diagnostics = ArtifactDiagnostics::create(); ComPtr<IDxcBlob> dxcResultBlob; - SLANG_RETURN_ON_FAIL(_handleOperationResult(dxcResult, diagnostics, dxcResultBlob)); + SLANG_RETURN_ON_FAIL(_handleOperationResult(dxcOperationResult, diagnostics, dxcResultBlob)); // If we have libraries then we need to link... if (libraries.getCount()) @@ -629,6 +631,11 @@ SlangResult DXCDownstreamCompiler::compile(const CompileOptions& inOptions, IArt ComPtr<IDxcBlob> linkedBlob; SLANG_RETURN_ON_FAIL(_handleOperationResult(linkDxcResult, diagnostics, linkedBlob)); + // When we've linked we make that the overall operation result + // As presumably it can contain pdb and perhaps other information + dxcOperationResult = linkDxcResult; + + // Set the result blob dxcResultBlob = linkedBlob; } @@ -639,6 +646,42 @@ SlangResult DXCDownstreamCompiler::compile(const CompileOptions& inOptions, IArt artifact->addRepresentationUnknown((ISlangBlob*)dxcResultBlob.get()); } + // If asking for PDB extract it. + if (options.m_debugInfoFormat == SLANG_DEBUG_INFO_FORMAT_PDB) + { + ComPtr<IDxcResult> dxcResult; + if (SLANG_SUCCEEDED(dxcOperationResult->QueryInterface(dxcResult.writeRef()))) + { + if (dxcResult->HasOutput(DXC_OUT_PDB)) + { + ComPtr<IDxcBlob> pdbBlob; + ComPtr<IDxcBlobWide> nameBlob; + + if (SLANG_SUCCEEDED(dxcResult->GetOutput(DXC_OUT_PDB, __uuidof(pdbBlob), (void**)pdbBlob.writeRef(), nameBlob.writeRef()))) + { + auto pdbArtifact = ArtifactUtil::createArtifact(ArtifactDesc::make(ArtifactDesc::Kind::BinaryFormat, ArtifactDesc::Payload::PdbDebugInfo)); + + if (nameBlob) + { + const auto wideName = (const WCHAR*)nameBlob->GetBufferPointer(); + + const auto name = String::fromWString(wideName); + if (name.getLength()) + { + // Set the name on the artifact. This is the name that must be used for the PDB to be loadable as a file by other tooling. + pdbArtifact->setName(name.getBuffer()); + } + } + + pdbArtifact->addRepresentationUnknown((ISlangBlob*)pdbBlob.get()); + + // Associate it + artifact->addAssociated(pdbArtifact); + } + } + } + } + *outArtifact = artifact.detach(); return SLANG_OK; } diff --git a/source/compiler-core/slang-visual-studio-compiler-util.cpp b/source/compiler-core/slang-visual-studio-compiler-util.cpp index 2d5b37c50..32b4d7f25 100644 --- a/source/compiler-core/slang-visual-studio-compiler-util.cpp +++ b/source/compiler-core/slang-visual-studio-compiler-util.cpp @@ -66,7 +66,7 @@ static void _addFile(const String& path, const ArtifactDesc& desc, IOSFileArtifa if (flags & ProductFlag::Debug) { // TODO(JS): Could try and determine based on debug information - _addFile(modulePath + ".pdb", ArtifactDesc::make(ArtifactKind::BinaryFormat, ArtifactPayload::DebugInfo, targetDesc), lockFile, outArtifacts); + _addFile(modulePath + ".pdb", ArtifactDesc::make(ArtifactKind::BinaryFormat, ArtifactPayload::PdbDebugInfo, targetDesc), lockFile, outArtifacts); } return SLANG_OK; |
