Skip to content
Merged
7 changes: 7 additions & 0 deletions include/dxc/HLSL/DxilValidation.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,13 @@ HRESULT ValidateDxilContainer(_In_reads_bytes_(ContainerSize) const void *pConta
_In_ uint32_t ContainerSize,
_In_ llvm::raw_ostream &DiagStream);

// Full container validation, including ValidateDxilModule, with debug module
HRESULT ValidateDxilContainer(_In_reads_bytes_(ContainerSize) const void *pContainer,
_In_ uint32_t ContainerSize,
const void *pOptDebugBitcode,
uint32_t OptDebugBitcodeSize,
_In_ llvm::raw_ostream &DiagStream);

class PrintDiagnosticContext {
private:
llvm::DiagnosticPrinter &m_Printer;
Expand Down
11 changes: 11 additions & 0 deletions include/dxc/dxcapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,17 @@ struct IDxcValidator : public IUnknown {
) = 0;
};

CROSS_PLATFORM_UUIDOF(IDxcValidator2, "458e1fd1-b1b2-4750-a6e1-9c10f03bed92")
struct IDxcValidator2 : public IDxcValidator {
// Validate a shader.
virtual HRESULT STDMETHODCALLTYPE ValidateWithDebug(
_In_ IDxcBlob *pShader, // Shader to validate.
_In_ UINT32 Flags, // Validation flags.
_In_opt_ DxcBuffer *pOptDebugBitcode, // Optional debug module bitcode to provide line numbers
_COM_Outptr_ IDxcOperationResult **ppResult // Validation output status, buffer, and errors
) = 0;
};

CROSS_PLATFORM_UUIDOF(IDxcContainerBuilder, "334b1f50-2292-4b35-99a1-25588d8c17fe")
struct IDxcContainerBuilder : public IUnknown {
virtual HRESULT STDMETHODCALLTYPE Load(_In_ IDxcBlob *pDxilContainerHeader) = 0; // Loads DxilContainer to the builder
Expand Down
1 change: 1 addition & 0 deletions include/llvm/IR/DebugInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ bool stripDebugInfo(Function &F);

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

/// \brief Utility to find all debug info in a module.
///
Expand Down
2 changes: 1 addition & 1 deletion lib/DXIL/DxilUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ static void EmitWarningOrErrorOnGlobalVariable(llvm::LLVMContext &Ctx, GlobalVar

if (GV) {
Module &M = *GV->getParent();
if (getDebugMetadataVersionFromModule(M) != 0) {
if (hasDebugInfo(M)) {
DebugInfoFinder FinderObj;
DebugInfoFinder &Finder = FinderObj;
// Debug modules have no dxil modules. Use it if you got it.
Expand Down
16 changes: 5 additions & 11 deletions lib/DxilContainer/DxilContainerAssembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1531,15 +1531,10 @@ DxilContainerWriter *hlsl::NewDxilContainerWriter() {
return new DxilContainerWriter_impl();
}

static bool HasDebugInfo(const Module &M) {
for (Module::const_named_metadata_iterator NMI = M.named_metadata_begin(),
NME = M.named_metadata_end();
NMI != NME; ++NMI) {
if (NMI->getName().startswith("llvm.dbg.")) {
return true;
}
}
return false;
static bool HasDebugInfoOrLineNumbers(const Module &M) {
return
llvm::getDebugMetadataVersionFromModule(M) != 0 ||
llvm::hasDebugInfo(M);
}

static void GetPaddedProgramPartSize(AbstractMemoryStream *pStream,
Expand Down Expand Up @@ -1776,8 +1771,7 @@ void hlsl::SerializeDxilContainerForModule(DxilModule *pModule,
// If we have debug information present, serialize it to a debug part, then use the stripped version as the canonical program version.
CComPtr<AbstractMemoryStream> pProgramStream = pInputProgramStream;
bool bModuleStripped = false;
bool bHasDebugInfo = HasDebugInfo(*pModule->GetModule());
if (bHasDebugInfo) {
if (HasDebugInfoOrLineNumbers(*pModule->GetModule())) {
uint32_t debugInUInt32, debugPaddingBytes;
GetPaddedProgramPartSize(pInputProgramStream, debugInUInt32, debugPaddingBytes);
if (Flags & SerializeDxilFlags::IncludeDebugInfoPart) {
Expand Down
2 changes: 1 addition & 1 deletion lib/HLSL/DxilCondenseResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ class DxilLowerCreateHandleForLib : public ModulePass {

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

GenerateDxilResourceHandles();

Expand Down
2 changes: 1 addition & 1 deletion lib/HLSL/DxilGenerationPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class DxilGenerationPass : public ModulePass {

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

// EntrySig for shader functions.
DxilEntryPropsMap EntryPropsMap;
Expand Down
14 changes: 14 additions & 0 deletions lib/HLSL/DxilValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6246,6 +6246,8 @@ _Use_decl_annotations_ HRESULT ValidateLoadModuleFromContainerLazy(
_Use_decl_annotations_
HRESULT ValidateDxilContainer(const void *pContainer,
uint32_t ContainerSize,
const void *pOptDebugBitcode,
uint32_t OptDebugBitcodeSize,
llvm::raw_ostream &DiagStream) {
LLVMContext Ctx, DbgCtx;
std::unique_ptr<llvm::Module> pModule, pDebugModule;
Expand All @@ -6260,6 +6262,12 @@ HRESULT ValidateDxilContainer(const void *pContainer,
IFR(ValidateLoadModuleFromContainer(pContainer, ContainerSize, pModule, pDebugModule,
Ctx, DbgCtx, DiagStream));

if (!pDebugModule && pOptDebugBitcode) {
// TODO: lazy load for perf
IFR(ValidateLoadModule((const char *)pOptDebugBitcode, OptDebugBitcodeSize,
pDebugModule, DbgCtx, DiagStream, /*bLazyLoad*/false));
}

// Validate DXIL Module
IFR(ValidateDxilModule(pModule.get(), pDebugModule.get()));

Expand All @@ -6271,4 +6279,10 @@ HRESULT ValidateDxilContainer(const void *pContainer,
IsDxilContainerLike(pContainer, ContainerSize), ContainerSize);
}

_Use_decl_annotations_
HRESULT ValidateDxilContainer(const void *pContainer,
uint32_t ContainerSize,
llvm::raw_ostream &DiagStream) {
return ValidateDxilContainer(pContainer, ContainerSize, nullptr, 0, DiagStream);
}
} // namespace hlsl
2 changes: 1 addition & 1 deletion lib/HLSL/HLMatrixLowerPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ bool HLMatrixLowerPass::runOnModule(Module &M) {
m_pHLModule = &m_pModule->GetOrCreateHLModule();
// Load up debug information, to cross-reference values and the instructions
// used to load them.
m_HasDbgInfo = getDebugMetadataVersionFromModule(M) != 0;
m_HasDbgInfo = hasDebugInfo(M);
m_matToVecStubs = &matToVecStubs;
m_vecToMatStubs = &vecToMatStubs;

Expand Down
15 changes: 15 additions & 0 deletions lib/IR/DebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,21 @@ unsigned llvm::getDebugMetadataVersionFromModule(const Module &M) {
return 0;
}

// HLSL Change - begin
bool llvm::hasDebugInfo(const Module &M) {
// We might just get away with checking if there's "llvm.dbg.cu",
// but this is more robust.
for (Module::const_named_metadata_iterator NMI = M.named_metadata_begin(),
NME = M.named_metadata_end();
NMI != NME; ++NMI) {
if (NMI->getName().startswith("llvm.dbg.")) {
return true;
}
}
return false;
}
// HLSL Change - end

DenseMap<const llvm::Function *, DISubprogram *>
llvm::makeSubprogramMap(const Module &M) {
DenseMap<const Function *, DISubprogram *> R;
Expand Down
7 changes: 2 additions & 5 deletions lib/IR/DiagnosticInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,12 @@ void DiagnosticInfoDxil::print(DiagnosticPrinter &DP) const {
DP << "Function: " << Func->getName() << ": ";
}

bool ZiPrompt = true;
switch (getSeverity()) {
case DiagnosticSeverity::DS_Note: DP << "note: "; ZiPrompt = false; break;
case DiagnosticSeverity::DS_Remark: DP << "remark: "; ZiPrompt = false; break;
case DiagnosticSeverity::DS_Note: DP << "note: "; break;
case DiagnosticSeverity::DS_Remark: DP << "remark: "; break;
case DiagnosticSeverity::DS_Warning: DP << "warning: "; break;
case DiagnosticSeverity::DS_Error: DP << "error: "; break;
}
DP << getMsgStr();
if (!DLoc && ZiPrompt)
DP << " Use /Zi for source location.";
}
// HLSL Change end - Dxil Diagnostic Info reporter
2 changes: 1 addition & 1 deletion lib/Transforms/Scalar/LowerTypePasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ bool LowerTypePass::runOnModule(Module &M) {
initialize(M);
// Load up debug information, to cross-reference values and the instructions
// used to load them.
bool HasDbgInfo = getDebugMetadataVersionFromModule(M) != 0;
bool HasDbgInfo = llvm::hasDebugInfo(M);
llvm::DebugInfoFinder Finder;
if (HasDbgInfo) {
Finder.processModule(M);
Expand Down
2 changes: 1 addition & 1 deletion lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3905,7 +3905,7 @@ class SROA_Parameter_HLSL : public ModulePass {
const DataLayout &DL = M.getDataLayout();
// Load up debug information, to cross-reference values and the instructions
// used to load them.
m_HasDbgInfo = getDebugMetadataVersionFromModule(M) != 0;
m_HasDbgInfo = nullptr != M.getNamedMetadata("llvm.dbg.cu");

InjectReturnAfterNoReturnPreserveOutput(*m_pHLModule);

Expand Down
2 changes: 1 addition & 1 deletion lib/Transforms/Scalar/Scalarizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ bool Scalarizer::finish() {
Module &M = *Gathered.front().first->getModule();
LLVMContext &Ctx = M.getContext();
const DataLayout &DL = M.getDataLayout();
bool HasDbgInfo = getDebugMetadataVersionFromModule(M) != 0;
bool HasDbgInfo = hasDebugInfo(M);
// Map from an extract element inst to a Value which replaced it.
DenseMap<Instruction *, Value*> EltMap;
// HLSL Change Ends.
Expand Down
4 changes: 1 addition & 3 deletions tools/clang/lib/CodeGen/CodeGenAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,8 @@ BackendConsumer::DxilDiagHandler(const llvm::DiagnosticInfoDxil &D) {
}
FullSourceLoc Loc(DILoc, SourceMgr);

// If no location information is available, prompt for debug flag
// and add function name to give some information
// If no location information is available, add function name
if (Loc.isInvalid()) {
Message += " Use /Zi for source location.";
auto *DiagClient = dynamic_cast<TextDiagnosticPrinter*>(Diags.getClient());
auto *func = D.getFunction();
if (DiagClient && func)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// RUN: %dxilver 1.6 | %dxc -E main -T as_6_5 %s | FileCheck %s -check-prefix=CHK_NODB

// CHK_DB: 23:5: error: For amplification shader with entry 'main', payload size 16400 is greater than maximum size of 16384 bytes.
// CHK_NODB: For amplification shader with entry 'main', payload size 16400 is greater than maximum size of 16384 bytes.
// CHK_NODB: 23:5: error: For amplification shader with entry 'main', payload size 16400 is greater than maximum size of 16384 bytes.

#define NUM_THREADS 32

Expand Down
4 changes: 2 additions & 2 deletions tools/clang/test/CodeGenHLSL/mesh-val/msOversizePayload.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// RUN: %dxilver 1.6 | %dxc -E main -T ms_6_5 %s | FileCheck %s -check-prefix=CHK_NODB

// CHK_DB: :29: error: For mesh shader with entry 'main', payload size 16404 is greater than maximum size of 16384 bytes.
// CHK_NODB: error: For mesh shader with entry 'main', payload size 16404 is greater than maximum size of 16384 bytes. Use /Zi for source location.
// CHK_NODB: :29: error: For mesh shader with entry 'main', payload size 16404 is greater than maximum size of 16384 bytes.

#define MAX_VERT 32
#define MAX_PRIM 16
Expand Down Expand Up @@ -62,4 +62,4 @@ void main(
prims[tig / 3] = op;
}
verts[tig] = ov;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s -check-prefix=CHK_NODB

// CHK_DB: 8:12: error: AddUint64 can only be applied to uint2 and uint4 operands.
// CHK_NODB: error: AddUint64 can only be applied to uint2 and uint4 operands. Use /Zi for source location.
// CHK_NODB: 8:12: error: AddUint64 can only be applied to uint2 and uint4 operands.

float4 main(uint4 a : A, uint4 b :B) : SV_TARGET {
uint c = AddUint64(a.x, b.x);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

// CHK_DB: 11:1: error: Parameter with semantic SV_InnerCoverage has overlapping semantic index at 0.
// CHK_DB: 11:1: error: Pixel shader inputs SV_Coverage and SV_InnerCoverage are mutually exclusive.
// CHK_NODB: error: Parameter with semantic SV_InnerCoverage has overlapping semantic index at 0. Use /Zi for source location.
// CHK_NODB: error: Pixel shader inputs SV_Coverage and SV_InnerCoverage are mutually exclusive. Use /Zi for source location.
// CHK_NODB: 11:1: error: Parameter with semantic SV_InnerCoverage has overlapping semantic index at 0.
// CHK_NODB: 11:1: error: Pixel shader inputs SV_Coverage and SV_InnerCoverage are mutually exclusive.

void main(snorm float b : B, uint c:C,
#ifndef GENLL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

// CHK_DB: 9:1: error: i64(type for I) cannot be used as shader inputs or outputs.
// CHK_DB: 9:1: error: double(type for SV_Target) cannot be used as shader inputs or outputs.
// CHK_NODB: cannot be used as shader inputs or outputs. Use /Zi for source location.
// CHK_NODB: cannot be used as shader inputs or outputs. Use /Zi for source location.
// CHK_NODB: 9:1: error: i64(type for I) cannot be used as shader inputs or outputs.
// CHK_NODB: 9:1: error: double(type for SV_Target) cannot be used as shader inputs or outputs.

double main(uint64_t i:I) : SV_Target {
return 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// RUN: %dxc -E main -Od -T ps_6_0 %s | FileCheck %s -check-prefix=CHK_NODB

// CHK_DB: 9:10: error: local resource not guaranteed to map to unique global resource.
// CHK_NODB: error: local resource not guaranteed to map to unique global resource. Use /Zi for source location.
// CHK_NODB: 9:10: error: local resource not guaranteed to map to unique global resource.

float4 Tex2D(Texture2D<float4> t,
SamplerState s, float2 c) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// RUN: %dxc -E main -Od -T ps_6_0 %s | FileCheck %s -check-prefix=CHK_NODB

// CHK_DB: 9:10: error: local resource not guaranteed to map to unique global resource.
// CHK_NODB: error: local resource not guaranteed to map to unique global resource. Use /Zi for source location.
// CHK_NODB: 9:10: error: local resource not guaranteed to map to unique global resource.

float4 Tex2D(Texture2D<float4> t,
SamplerState s, float2 c) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s -check-prefix=CHK_NODB

// CHK_DB: 17:7: error: local resource not guaranteed to map to unique global resource.
// CHK_NODB: error: local resource not guaranteed to map to unique global resource. Use /Zi for source location.
// CHK_NODB: 17:7: error: local resource not guaranteed to map to unique global resource.

float4 Tex2D(Texture2D<float4> t,
SamplerState s, float2 c) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// RUN: %dxc -E main -Od -T ps_6_0 %s | FileCheck %s -check-prefix=CHK_NODB

// CHK_DB: 9:10: error: local resource not guaranteed to map to unique global resource.
// CHK_NODB: error: local resource not guaranteed to map to unique global resource. Use /Zi for source location.
// CHK_NODB: 9:10: error: local resource not guaranteed to map to unique global resource.

float4 Tex2D(Texture2D<float4> t,
SamplerState s, float2 c) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s -check-prefix=CHK_NODB

// CHK_DB: 18:7: error: local resource not guaranteed to map to unique global resource.
// CHK_NODB: error: local resource not guaranteed to map to unique global resource. Use /Zi for source location.
// CHK_NODB: 18:7: error: local resource not guaranteed to map to unique global resource.

float4 Tex2D(Texture2D<float4> t,
SamplerState s, float2 c) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// RUN: %dxc -E main -Od -T ps_6_0 %s | FileCheck %s -check-prefix=CHK_NODB

// CHK_DB: 9:10: error: local resource not guaranteed to map to unique global resource.
// CHK_NODB: error: local resource not guaranteed to map to unique global resource. Use /Zi for source location.
// CHK_NODB: 9:10: error: local resource not guaranteed to map to unique global resource.

float4 Tex2D(Texture2D<float4> t,
SamplerState s, float2 c) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// RUN: %dxc -Zi -E main -Od -T ps_6_0 %s | FileCheck %s -check-prefix=CHK_DB
// RUN: %dxc -E main -Od -T ps_6_0 %s | FileCheck %s -check-prefix=CHK_NODB

// CHK_DB: 17:7: error: Offsets to texture access operations must be immediate values
// CHK_DB: 16:7: error: Offsets to texture access operations must be immediate values
// CHK_NODB: Offsets to texture access operations must be immediate values.
// CHK_NODB-SAME Use /Zi for source location.

SamplerState samp1 : register(s5);
Texture2D<float4> text1 : register(t3);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// RUN: %dxc -Zi -E main -Od -T ps_6_0 %s | FileCheck %s -check-prefix=CHK_DB
// RUN: %dxc -E main -Od -T ps_6_0 %s | FileCheck %s -check-prefix=CHK_NODB

// CHK_DB: 21:10: error: Offsets to texture access operations must be immediate values. Unrolling the loop containing the offset value manually and using -O3 may help in some cases.
// CHK_DB: 21:10: error: Offsets to texture access operations must be immediate values. Unrolling the loop containing the offset value manually and using -O3 may help in some cases.
// CHK_DB: 19:10: error: Offsets to texture access operations must be immediate values. Unrolling the loop containing the offset value manually and using -O3 may help in some cases.
// CHK_DB: 19:10: error: Offsets to texture access operations must be immediate values. Unrolling the loop containing the offset value manually and using -O3 may help in some cases.

// CHK_NODB: error: Offsets to texture access operations must be immediate values. Unrolling the loop containing the offset value manually and using -O3 may help in some cases.
// CHK_NODB-SAME Use /Zi for source location.
// CHK_NODB: error: Offsets to texture access operations must be immediate values. Unrolling the loop containing the offset value manually and using -O3 may help in some cases.
// CHK_NODB-SAME Use /Zi for source location.

SamplerState samp1 : register(s5);
Texture2D<float4> text1 : register(t3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Regression test for a crash when lowering unsupported intrinsics

// CHK_DB: 10:50: error: Unsupported intrinsic
// CHK_NODB: error: Unsupported intrinsic. Use /Zi for source location.
// CHK_NODB: 10:50: error: Unsupported intrinsic

sampler TextureSampler;
float4 main(float2 uv : UV) : SV_Target { return tex2D(TextureSampler, uv); }
float4 main(float2 uv : UV) : SV_Target { return tex2D(TextureSampler, uv); }
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

// Make sure the specified warning gets turned off

// CHECK: 9:1: error: Semantic must be defined

// This function has no output semantic on purpose in order to produce an error,
// otherwise, the warnings will not be captured in the output for FileCheck.
float main() {
Expand All @@ -14,4 +16,3 @@ float main() {
return 0;
}

// CHECK: error: Semantic must be defined
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
float main() {

// comma expression used where a constructor list may have been intended
// CHECK-NOT: comma
// CHECK-NOT: comma expression
int a = 1, b = 2;
int c = (a, b);

Expand Down
Loading