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/slang-dxc-compiler.cpp | |
| 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/slang-dxc-compiler.cpp')
| -rw-r--r-- | source/compiler-core/slang-dxc-compiler.cpp | 49 |
1 files changed, 46 insertions, 3 deletions
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; } |
