Skip to content

Commit 6599661

Browse files
adam-yangtex3d
authored andcommitted
Made -Zs the flag for slim PDB. Added -Qpdb_in_private. (#3541)
1 parent b23c015 commit 6599661

8 files changed

Lines changed: 133 additions & 56 deletions

File tree

include/dxc/Support/HLSLOptions.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ class DxcOpts {
172172
bool RecompileFromBinary = false; // OPT _Recompile (Recompiling the DXBC binary file not .hlsl file)
173173
bool StripDebug = false; // OPT Qstrip_debug
174174
bool EmbedDebug = false; // OPT Qembed_debug
175-
bool SourceInDebugModule = false; // OPT Qsource_in_debug_module
175+
bool SourceInDebugModule = false; // OPT Zs
176176
bool SourceOnlyDebug = false; // OPT Qsource_only_debug
177-
bool FullDebug = false; // OPT Qfull_debug
177+
bool PdbInPrivate = false; // OPT Qpdb_in_private
178178
bool StripRootSignature = false; // OPT_Qstrip_rootsignature
179179
bool StripPrivate = false; // OPT_Qstrip_priv
180180
bool StripReflection = false; // OPT_Qstrip_reflect
@@ -210,7 +210,8 @@ class DxcOpts {
210210
bool IsLibraryProfile();
211211

212212
// Helpers to clarify interpretation of flags for behavior in implementation
213-
bool IsDebugInfoEnabled(); // Zi
213+
bool GenerateFullDebugInfo(); // Zi
214+
bool GeneratePDB(); // Zi or Zs
214215
bool EmbedDebugInfo(); // Qembed_debug
215216
bool EmbedPDBName(); // Zi or Fd
216217
bool DebugFileIsDirectory(); // Fd ends in '\\'

include/dxc/Support/HLSLOptions.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,10 @@ def Qstrip_priv : Flag<["-", "/"], "Qstrip_priv">, Flags<[DriverOption]>, Group<
411411
HelpText<"Strip private data from shader bytecode (must be used with /Fo <file>)">;
412412
def Qsource_in_debug_module : Flag<["-", "/"], "Qsource_in_debug_module">, Flags<[CoreOption, HelpHidden]>, Group<hlslutil_Group>,
413413
HelpText<"Generate old PDB format.">;
414-
def Qsource_only_debug : Flag<["-", "/"], "Qsource_only_debug">, Flags<[CoreOption, HelpHidden]>, Group<hlslutil_Group>,
414+
def Zs : Flag<["-", "/"], "Zs">, Flags<[CoreOption]>, Group<hlslutil_Group>,
415415
HelpText<"Generate small PDB with just sources and compile options.">;
416-
def Qfull_debug : Flag<["-", "/"], "Qfull_debug">, Flags<[CoreOption, HelpHidden]>, Group<hlslutil_Group>,
417-
HelpText<"Generate full debug info for PDB.">;
416+
def Qpdb_in_private : Flag<["-", "/"], "Qpdb_in_private">, Flags<[CoreOption, HelpHidden]>, Group<hlslutil_Group>,
417+
HelpText<"Store PDB in private user data.">;
418418

419419
def Qstrip_rootsignature : Flag<["-", "/"], "Qstrip_rootsignature">, Flags<[CoreOption, DriverOption]>, Group<hlslutil_Group>, HelpText<"Strip root signature data from shader bytecode (must be used with /Fo <file>)">;
420420
def setrootsignature : JoinedOrSeparate<["-", "/"], "setrootsignature">, MetaVarName<"<file>">, Flags<[CoreOption, DriverOption]>, Group<hlslutil_Group>, HelpText<"Attach root signature to shader bytecode">;

lib/DxcSupport/HLSLOptions.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,20 @@ bool DxcOpts::IsLibraryProfile() {
138138
return TargetProfile.startswith("lib_");
139139
}
140140

141-
bool DxcOpts::IsDebugInfoEnabled() {
141+
bool DxcOpts::GenerateFullDebugInfo() {
142142
return DebugInfo;
143143
}
144144

145+
bool DxcOpts::GeneratePDB() {
146+
return DebugInfo || SourceOnlyDebug;
147+
}
148+
145149
bool DxcOpts::EmbedDebugInfo() {
146150
return EmbedDebug;
147151
}
148152

149153
bool DxcOpts::EmbedPDBName() {
150-
return IsDebugInfoEnabled() || !DebugFile.empty();
154+
return GeneratePDB() || !DebugFile.empty();
151155
}
152156

153157
bool DxcOpts::DebugFileIsDirectory() {
@@ -626,8 +630,8 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude,
626630
opts.StripDebug = Args.hasFlag(OPT_Qstrip_debug, OPT_INVALID, false);
627631
opts.EmbedDebug = Args.hasFlag(OPT_Qembed_debug, OPT_INVALID, false);
628632
opts.SourceInDebugModule = Args.hasFlag(OPT_Qsource_in_debug_module, OPT_INVALID, false);
629-
opts.SourceOnlyDebug = Args.hasFlag(OPT_Qsource_only_debug, OPT_INVALID, false);
630-
opts.FullDebug = Args.hasFlag(OPT_Qfull_debug, OPT_INVALID, false);
633+
opts.SourceOnlyDebug = Args.hasFlag(OPT_Zs, OPT_INVALID, false);
634+
opts.PdbInPrivate = Args.hasFlag(OPT_Qpdb_in_private, OPT_INVALID, false);
631635
opts.StripRootSignature = Args.hasFlag(OPT_Qstrip_rootsignature, OPT_INVALID, false);
632636
opts.StripPrivate = Args.hasFlag(OPT_Qstrip_priv, OPT_INVALID, false);
633637
opts.StripReflection = Args.hasFlag(OPT_Qstrip_reflect, OPT_INVALID, false);
@@ -922,13 +926,13 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude,
922926
return 1;
923927
}
924928

925-
if (opts.FullDebug && opts.SourceOnlyDebug) {
926-
errors << "Cannot specify both /Qfull_debug and /Qsource_only_debug";
929+
if (opts.DebugInfo && opts.SourceOnlyDebug) {
930+
errors << "Cannot specify both /Zi and /Zs";
927931
return 1;
928932
}
929933

930934
if (opts.SourceInDebugModule && opts.SourceOnlyDebug) {
931-
errors << "Cannot specify both /Qsource_in_debug_module and /Qsource_only_debug";
935+
errors << "Cannot specify both /Qsource_in_debug_module and /Zs";
932936
return 1;
933937
}
934938

@@ -939,8 +943,8 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude,
939943
return 1;
940944
}
941945

942-
if (opts.DebugNameForSource && !opts.DebugInfo) {
943-
errors << "/Zss requires debug info (/Zi)";
946+
if (opts.DebugNameForSource && (!opts.DebugInfo && !opts.SourceOnlyDebug)) {
947+
errors << "/Zss requires debug info (/Zi or /Zs)";
944948
return 1;
945949
}
946950

tools/clang/tools/dxclib/dxc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,9 @@ int DxcContext::ActOnBlob(IDxcBlob *pBlob, IDxcBlob *pDebugBlob, LPCWSTR pDebugB
293293

294294
// Extract and write the PDB/debug information.
295295
if (!m_Opts.DebugFile.empty()) {
296-
IFTBOOLMSG(m_Opts.DebugInfo, E_INVALIDARG, "/Fd specified, but no Debug Info was "
296+
IFTBOOLMSG(m_Opts.GeneratePDB(), E_INVALIDARG, "/Fd specified, but no Debug Info was "
297297
"found in the shader, please use the "
298-
"/Zi switch to generate debug "
298+
"/Zi or /Zs switch to generate debug "
299299
"information compiling this shader.");
300300
if (pDebugBlob != nullptr) {
301301
IFTBOOLMSG(pDebugBlobName && *pDebugBlobName, E_INVALIDARG,

tools/clang/tools/dxcompiler/dxcompilerobj.cpp

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,10 @@ struct CompilerVersionPartWriter {
161161
};
162162

163163
static 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);

tools/clang/tools/dxcompiler/dxcpdbutils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,11 +748,11 @@ struct DxcPdbUtils : public IDxcPdbUtils, public IDxcPixDxilDebugInfoFactory
748748

749749
std::vector<const WCHAR *> new_args;
750750
for (unsigned i = 0; i < m_Args.size(); i++) {
751-
if (m_Args[i] == L"/Qsource_only_debug" || m_Args[i] == L"-Qsource_only_debug")
751+
if (m_Args[i] == L"/Zs" || m_Args[i] == L"-Zs")
752752
continue;
753753
new_args.push_back(m_Args[i].c_str());
754754
}
755-
new_args.push_back(L"-Qfull_debug");
755+
new_args.push_back(L"-Zi");
756756

757757
assert(m_MainFileName.size());
758758
if (m_MainFileName.size())

0 commit comments

Comments
 (0)