Skip to content

Commit 0b1c006

Browse files
tex3dadam-yang
andauthored
Internal validator error messages don't need /Zi anymore. (#3606) (#3615)
(cherry picked from commit 86104f4) Co-authored-by: Adam Yang <[email protected]>
1 parent 3d5e8b9 commit 0b1c006

40 files changed

Lines changed: 209 additions & 92 deletions

include/dxc/HLSL/DxilValidation.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,13 @@ HRESULT ValidateDxilContainer(_In_reads_bytes_(ContainerSize) const void *pConta
347347
_In_ uint32_t ContainerSize,
348348
_In_ llvm::raw_ostream &DiagStream);
349349

350+
// Full container validation, including ValidateDxilModule, with debug module
351+
HRESULT ValidateDxilContainer(_In_reads_bytes_(ContainerSize) const void *pContainer,
352+
_In_ uint32_t ContainerSize,
353+
const void *pOptDebugBitcode,
354+
uint32_t OptDebugBitcodeSize,
355+
_In_ llvm::raw_ostream &DiagStream);
356+
350357
class PrintDiagnosticContext {
351358
private:
352359
llvm::DiagnosticPrinter &m_Printer;

include/dxc/dxcapi.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,17 @@ struct IDxcValidator : public IUnknown {
511511
) = 0;
512512
};
513513

514+
CROSS_PLATFORM_UUIDOF(IDxcValidator2, "458e1fd1-b1b2-4750-a6e1-9c10f03bed92")
515+
struct IDxcValidator2 : public IDxcValidator {
516+
// Validate a shader.
517+
virtual HRESULT STDMETHODCALLTYPE ValidateWithDebug(
518+
_In_ IDxcBlob *pShader, // Shader to validate.
519+
_In_ UINT32 Flags, // Validation flags.
520+
_In_opt_ DxcBuffer *pOptDebugBitcode, // Optional debug module bitcode to provide line numbers
521+
_COM_Outptr_ IDxcOperationResult **ppResult // Validation output status, buffer, and errors
522+
) = 0;
523+
};
524+
514525
CROSS_PLATFORM_UUIDOF(IDxcContainerBuilder, "334b1f50-2292-4b35-99a1-25588d8c17fe")
515526
struct IDxcContainerBuilder : public IUnknown {
516527
virtual HRESULT STDMETHODCALLTYPE Load(_In_ IDxcBlob *pDxilContainerHeader) = 0; // Loads DxilContainer to the builder

include/llvm/IR/DebugInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ bool stripDebugInfo(Function &F);
6060

6161
/// \brief Return Debug Info Metadata Version by checking module flags.
6262
unsigned getDebugMetadataVersionFromModule(const Module &M);
63+
bool hasDebugInfo(const Module &M); // HLSL Change - Helper function to check if there's real debug info (variables, types)
6364

6465
/// \brief Utility to find all debug info in a module.
6566
///

lib/DXIL/DxilUtil.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ static void EmitWarningOrErrorOnGlobalVariable(llvm::LLVMContext &Ctx, GlobalVar
314314

315315
if (GV) {
316316
Module &M = *GV->getParent();
317-
if (getDebugMetadataVersionFromModule(M) != 0) {
317+
if (hasDebugInfo(M)) {
318318
DebugInfoFinder FinderObj;
319319
DebugInfoFinder &Finder = FinderObj;
320320
// Debug modules have no dxil modules. Use it if you got it.

lib/DxilContainer/DxilContainerAssembler.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,15 +1531,10 @@ DxilContainerWriter *hlsl::NewDxilContainerWriter() {
15311531
return new DxilContainerWriter_impl();
15321532
}
15331533

1534-
static bool HasDebugInfo(const Module &M) {
1535-
for (Module::const_named_metadata_iterator NMI = M.named_metadata_begin(),
1536-
NME = M.named_metadata_end();
1537-
NMI != NME; ++NMI) {
1538-
if (NMI->getName().startswith("llvm.dbg.")) {
1539-
return true;
1540-
}
1541-
}
1542-
return false;
1534+
static bool HasDebugInfoOrLineNumbers(const Module &M) {
1535+
return
1536+
llvm::getDebugMetadataVersionFromModule(M) != 0 ||
1537+
llvm::hasDebugInfo(M);
15431538
}
15441539

15451540
static void GetPaddedProgramPartSize(AbstractMemoryStream *pStream,
@@ -1776,8 +1771,7 @@ void hlsl::SerializeDxilContainerForModule(DxilModule *pModule,
17761771
// If we have debug information present, serialize it to a debug part, then use the stripped version as the canonical program version.
17771772
CComPtr<AbstractMemoryStream> pProgramStream = pInputProgramStream;
17781773
bool bModuleStripped = false;
1779-
bool bHasDebugInfo = HasDebugInfo(*pModule->GetModule());
1780-
if (bHasDebugInfo) {
1774+
if (HasDebugInfoOrLineNumbers(*pModule->GetModule())) {
17811775
uint32_t debugInUInt32, debugPaddingBytes;
17821776
GetPaddedProgramPartSize(pInputProgramStream, debugInUInt32, debugPaddingBytes);
17831777
if (Flags & SerializeDxilFlags::IncludeDebugInfoPart) {

lib/HLSL/DxilCondenseResources.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ class DxilLowerCreateHandleForLib : public ModulePass {
560560

561561
// Load up debug information, to cross-reference values and the instructions
562562
// used to load them.
563-
m_HasDbgInfo = getDebugMetadataVersionFromModule(M) != 0;
563+
m_HasDbgInfo = hasDebugInfo(M);
564564

565565
GenerateDxilResourceHandles();
566566

lib/HLSL/DxilGenerationPass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class DxilGenerationPass : public ModulePass {
201201

202202
// Load up debug information, to cross-reference values and the instructions
203203
// used to load them.
204-
m_HasDbgInfo = getDebugMetadataVersionFromModule(M) != 0;
204+
m_HasDbgInfo = hasDebugInfo(M);
205205

206206
// EntrySig for shader functions.
207207
DxilEntryPropsMap EntryPropsMap;

lib/HLSL/DxilValidation.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6287,6 +6287,8 @@ _Use_decl_annotations_ HRESULT ValidateLoadModuleFromContainerLazy(
62876287
_Use_decl_annotations_
62886288
HRESULT ValidateDxilContainer(const void *pContainer,
62896289
uint32_t ContainerSize,
6290+
const void *pOptDebugBitcode,
6291+
uint32_t OptDebugBitcodeSize,
62906292
llvm::raw_ostream &DiagStream) {
62916293
LLVMContext Ctx, DbgCtx;
62926294
std::unique_ptr<llvm::Module> pModule, pDebugModule;
@@ -6301,6 +6303,12 @@ HRESULT ValidateDxilContainer(const void *pContainer,
63016303
IFR(ValidateLoadModuleFromContainer(pContainer, ContainerSize, pModule, pDebugModule,
63026304
Ctx, DbgCtx, DiagStream));
63036305

6306+
if (!pDebugModule && pOptDebugBitcode) {
6307+
// TODO: lazy load for perf
6308+
IFR(ValidateLoadModule((const char *)pOptDebugBitcode, OptDebugBitcodeSize,
6309+
pDebugModule, DbgCtx, DiagStream, /*bLazyLoad*/false));
6310+
}
6311+
63046312
// Validate DXIL Module
63056313
IFR(ValidateDxilModule(pModule.get(), pDebugModule.get()));
63066314

@@ -6312,4 +6320,10 @@ HRESULT ValidateDxilContainer(const void *pContainer,
63126320
IsDxilContainerLike(pContainer, ContainerSize), ContainerSize);
63136321
}
63146322

6323+
_Use_decl_annotations_
6324+
HRESULT ValidateDxilContainer(const void *pContainer,
6325+
uint32_t ContainerSize,
6326+
llvm::raw_ostream &DiagStream) {
6327+
return ValidateDxilContainer(pContainer, ContainerSize, nullptr, 0, DiagStream);
6328+
}
63156329
} // namespace hlsl

lib/HLSL/HLMatrixLowerPass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ bool HLMatrixLowerPass::runOnModule(Module &M) {
197197
m_pHLModule = &m_pModule->GetOrCreateHLModule();
198198
// Load up debug information, to cross-reference values and the instructions
199199
// used to load them.
200-
m_HasDbgInfo = getDebugMetadataVersionFromModule(M) != 0;
200+
m_HasDbgInfo = hasDebugInfo(M);
201201
m_matToVecStubs = &matToVecStubs;
202202
m_vecToMatStubs = &vecToMatStubs;
203203

lib/IR/DebugInfo.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,21 @@ unsigned llvm::getDebugMetadataVersionFromModule(const Module &M) {
379379
return 0;
380380
}
381381

382+
// HLSL Change - begin
383+
bool llvm::hasDebugInfo(const Module &M) {
384+
// We might just get away with checking if there's "llvm.dbg.cu",
385+
// but this is more robust.
386+
for (Module::const_named_metadata_iterator NMI = M.named_metadata_begin(),
387+
NME = M.named_metadata_end();
388+
NMI != NME; ++NMI) {
389+
if (NMI->getName().startswith("llvm.dbg.")) {
390+
return true;
391+
}
392+
}
393+
return false;
394+
}
395+
// HLSL Change - end
396+
382397
DenseMap<const llvm::Function *, DISubprogram *>
383398
llvm::makeSubprogramMap(const Module &M) {
384399
DenseMap<const Function *, DISubprogram *> R;

0 commit comments

Comments
 (0)