@@ -161,11 +161,10 @@ struct CompilerVersionPartWriter {
161161};
162162
163163static HRESULT CreateContainerForPDB (IMalloc *pMalloc,
164- llvm::Module *pModule,
165164 IDxcBlob *pOldContainer,
166165 IDxcBlob *pDebugBlob, IDxcVersionInfo *pVersionInfo,
167166 const hlsl::DxilSourceInfo *pSourceInfo,
168- AbstractMemoryStream *pReflectionStream, const uint32_t reflectionSizeInBytes,
167+ AbstractMemoryStream *pReflectionStream,
169168 IDxcBlob **ppNewContaner)
170169{
171170 // If the pContainer is not a valid container, give up.
@@ -244,15 +243,18 @@ static HRESULT CreateContainerForPDB(IMalloc *pMalloc,
244243 }
245244
246245 if (pReflectionStream) {
246+ const hlsl::DxilPartHeader *pReflectionPartHeader =
247+ (const hlsl::DxilPartHeader *)pReflectionStream->GetPtr ();
247248 Part NewPart (
248249 hlsl::DFCC_ShaderStatistics,
249- reflectionSizeInBytes,
250- [&pReflectionStream, pModule](IStream *pStream) {
251- hlsl::WriteProgramPart (pModule->GetOrCreateDxilModule ().GetShaderModel (), pReflectionStream, pStream);
250+ pReflectionPartHeader->PartSize ,
251+ [pReflectionPartHeader](IStream *pStream) {
252+ ULONG uBytesWritten = 0 ;
253+ pStream->Write (pReflectionPartHeader+1 , pReflectionPartHeader->PartSize , &uBytesWritten);
252254 return S_OK;
253255 }
254256 );
255- AddPart (NewPart, reflectionSizeInBytes );
257+ AddPart (NewPart, pReflectionPartHeader-> PartSize );
256258 }
257259
258260 CompilerVersionPartWriter versionWriter;
@@ -733,7 +735,8 @@ class DxcCompiler : public IDxcCompiler3,
733735 // Setup a compiler instance.
734736 raw_stream_ostream outStream (pOutputStream.p );
735737 llvm::LLVMContext llvmContext; // LLVMContext should outlive CompilerInstance
736- std::unique_ptr<llvm::Module> compiledModule;
738+ std::unique_ptr<llvm::Module> debugModule;
739+ CComPtr<AbstractMemoryStream> pReflectionStream;
737740 CompilerInstance compiler;
738741 std::unique_ptr<TextDiagnosticPrinter> diagPrinter =
739742 llvm::make_unique<TextDiagnosticPrinter>(w, &compiler.getDiagnosticOpts ());
@@ -945,19 +948,20 @@ class DxcCompiler : public IDxcCompiler3,
945948 // Do not create a container when there is only a a high-level representation in the module.
946949 if (compileOK && !opts.CodeGenHighLevel ) {
947950 HRESULT valHR = S_OK;
948- CComPtr<AbstractMemoryStream> pReflectionStream;
949951 CComPtr<AbstractMemoryStream> pRootSigStream;
950952 IFT (CreateMemoryStream (DxcGetThreadMallocNoRef (), &pReflectionStream));
951953 IFT (CreateMemoryStream (DxcGetThreadMallocNoRef (), &pRootSigStream));
952954
953955 std::unique_ptr<llvm::Module> serializeModule ( action.takeModule () );
954956
955957 // Clone and save the copy.
956- compiledModule.reset (llvm::CloneModule (serializeModule.get ()));
958+ if (opts.GenerateFullDebugInfo ()) {
959+ debugModule.reset (llvm::CloneModule (serializeModule.get ()));
960+ }
957961
958962 dxcutil::AssembleInputs inputs (
959963 std::move (serializeModule), pOutputBlob, m_pMalloc, SerializeFlags,
960- pOutputStream, opts.IsDebugInfoEnabled (),
964+ pOutputStream, opts.GenerateFullDebugInfo (),
961965 opts.GetPDBName (), &compiler.getDiagnostics (),
962966 &ShaderHashContent, pReflectionStream, pRootSigStream);
963967
@@ -1025,7 +1029,7 @@ class DxcCompiler : public IDxcCompiler3,
10251029
10261030 bool hasErrorOccurred = compiler.getDiagnostics ().hasErrorOccurred ();
10271031
1028- bool writePDB = opts.IsDebugInfoEnabled () && produceFullContainer;
1032+ bool writePDB = opts.GeneratePDB () && produceFullContainer;
10291033
10301034 // SPIRV change starts
10311035#if defined(ENABLE_SPIRV_CODEGEN)
@@ -1035,14 +1039,7 @@ class DxcCompiler : public IDxcCompiler3,
10351039
10361040 if (!hasErrorOccurred && writePDB) {
10371041 CComPtr<IDxcBlob> pStrippedContainer;
1038-
10391042 {
1040- // Version info to store in the PDB
1041- IDxcVersionInfo *pVersionInfo = nullptr ;
1042- if (opts.IsDebugInfoEnabled ()) { // Only put version info if embedding debug
1043- pVersionInfo = static_cast <IDxcVersionInfo *>(this );
1044- }
1045-
10461043 // Create the shader source information for PDB
10471044 hlsl::SourceInfoWriter debugSourceInfoWriter;
10481045 const hlsl::DxilSourceInfo *pSourceInfo = nullptr ;
@@ -1051,44 +1048,59 @@ class DxcCompiler : public IDxcCompiler3,
10511048 pSourceInfo = debugSourceInfoWriter.GetPart ();
10521049 }
10531050
1054- CComPtr<AbstractMemoryStream> pReflectionStream;
1055- uint32_t reflectionSizeInBytes = 0 ;
1056-
10571051 CComPtr<IDxcBlob> pDebugProgramBlob;
1052+ CComPtr<AbstractMemoryStream> pReflectionInPdb;
10581053 // Don't include the debug part if using source only PDB
10591054 if (opts.SourceOnlyDebug ) {
10601055 assert (pSourceInfo);
1061- hlsl::ReEmitLatestReflectionData (compiledModule.get ());
1062- hlsl::StripAndCreateReflectionStream (compiledModule.get (), &reflectionSizeInBytes, &pReflectionStream);
1056+ pReflectionInPdb = pReflectionStream;
10631057 }
10641058 else {
10651059 if (!opts.SourceInDebugModule ) {
10661060 // Strip out the source related metadata
1067- compiledModule ->GetOrCreateDxilModule ()
1061+ debugModule ->GetOrCreateDxilModule ()
10681062 .StripShaderSourcesAndCompileOptions (/* bReplaceWithDummyData */ true );
10691063 }
10701064 CComPtr<AbstractMemoryStream> pDebugBlobStorage;
10711065 IFT (CreateMemoryStream (DxcGetThreadMallocNoRef (), &pDebugBlobStorage));
10721066 raw_stream_ostream outStream (pDebugBlobStorage.p );
1073- WriteBitcodeToFile (compiledModule .get (), outStream, true );
1067+ WriteBitcodeToFile (debugModule .get (), outStream, true );
10741068 outStream.flush ();
10751069 IFT (pDebugBlobStorage.QueryInterface (&pDebugProgramBlob));
10761070 }
10771071
10781072 IFT (CreateContainerForPDB (
10791073 m_pMalloc,
1080- compiledModule.get (),
10811074 pOutputBlob, pDebugProgramBlob,
10821075 static_cast <IDxcVersionInfo *>(this ), pSourceInfo,
1083- pReflectionStream, reflectionSizeInBytes ,
1076+ pReflectionInPdb ,
10841077 &pStrippedContainer));
10851078 }
10861079
10871080 // Create the final PDB Blob
10881081 CComPtr<IDxcBlob> pPdbBlob;
10891082 IFT (hlsl::pdb::WriteDxilPDB (m_pMalloc, pStrippedContainer, ShaderHashContent.Digest , &pPdbBlob));
10901083 IFT (pResult->SetOutputObject (DXC_OUT_PDB, pPdbBlob));
1091- }
1084+
1085+ // If option Qpdb_in_private given, add the PDB to the DXC_OUT_OBJECT container output as a
1086+ // DFCC_PrivateData part.
1087+ if (opts.PdbInPrivate ) {
1088+ CComPtr<IDxcBlobEncoding> pContainerBlob;
1089+ hlsl::DxcCreateBlobWithEncodingFromPinned (pOutputBlob->GetBufferPointer (), pOutputBlob->GetBufferSize (), CP_ACP, &pContainerBlob);
1090+
1091+ CComPtr<IDxcContainerBuilder> pContainerBuilder;
1092+ DxcCreateInstance2 (this ->m_pMalloc , CLSID_DxcContainerBuilder, IID_PPV_ARGS (&pContainerBuilder));
1093+ IFT (pContainerBuilder->Load (pOutputBlob));
1094+ IFT (pContainerBuilder->AddPart (hlsl::DFCC_PrivateData, pPdbBlob));
1095+
1096+ CComPtr<IDxcOperationResult> pReserializeResult;
1097+ IFT (pContainerBuilder->SerializeContainer (&pReserializeResult));
1098+
1099+ CComPtr<IDxcBlob> pNewOutput;
1100+ IFT (pReserializeResult->GetResult (&pNewOutput));
1101+ pOutputBlob = pNewOutput;
1102+ } // PDB in private
1103+ } // Write PDB
10921104
10931105 IFT (primaryOutput.SetObject (pOutputBlob, opts.DefaultTextCodePage ));
10941106 IFT (pResult->SetOutput (primaryOutput));
@@ -1216,7 +1228,7 @@ class DxcCompiler : public IDxcCompiler3,
12161228
12171229 compiler.getFrontendOpts ().Inputs .push_back (FrontendInputFile (pMainFile, IK_HLSL));
12181230 // Setup debug information.
1219- if (Opts.IsDebugInfoEnabled ()) {
1231+ if (Opts.GenerateFullDebugInfo ()) {
12201232 CodeGenOptions &CGOpts = compiler.getCodeGenOpts ();
12211233 // HLSL Change - begin
12221234 CGOpts.setDebugInfo (CodeGenOptions::FullDebugInfo);
0 commit comments