From 3fea56ef77a33273bf5af6f432163b30c0a0e1dc Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Fri, 10 Mar 2023 14:19:48 -0500 Subject: 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. --- source/compiler-core/slang-dxc-compiler.cpp | 49 +++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) (limited to 'source/compiler-core/slang-dxc-compiler.cpp') 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 dxcResult; + ComPtr 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 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 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 dxcResult; + if (SLANG_SUCCEEDED(dxcOperationResult->QueryInterface(dxcResult.writeRef()))) + { + if (dxcResult->HasOutput(DXC_OUT_PDB)) + { + ComPtr pdbBlob; + ComPtr 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; } -- cgit v1.2.3