DxilValidation.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // DxilValidation.h //
  4. // Copyright (C) Microsoft Corporation. All rights reserved. //
  5. // This file is distributed under the University of Illinois Open Source //
  6. // License. See LICENSE.TXT for details. //
  7. // //
  8. // This file provides support for validating DXIL shaders. //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #pragma once
  12. #include <memory>
  13. #include "dxc/Support/Global.h"
  14. #include "dxc/DXIL/DxilConstants.h"
  15. #include "dxc/Support/WinAdapter.h"
  16. namespace llvm {
  17. class Module;
  18. class LLVMContext;
  19. class raw_ostream;
  20. class DiagnosticPrinter;
  21. class DiagnosticInfo;
  22. }
  23. namespace hlsl {
  24. /* <py::lines('VALRULE-ENUM')>hctdb_instrhelp.get_valrule_enum()</py>*/
  25. // VALRULE-ENUM:BEGIN
  26. // Known validation rules
  27. enum class ValidationRule : unsigned {
  28. // Bitcode
  29. BitcodeValid, // TODO - Module must be bitcode-valid
  30. // Container
  31. ContainerPartInvalid, // DXIL Container must not contain unknown parts
  32. ContainerPartMatches, // DXIL Container Parts must match Module
  33. ContainerPartMissing, // DXIL Container requires certain parts, corresponding to module
  34. ContainerPartRepeated, // DXIL Container must have only one of each part type
  35. ContainerRootSignatureIncompatible, // Root Signature in DXIL Container must be compatible with shader
  36. // Declaration
  37. DeclAttrStruct, // Attributes parameter must be struct type
  38. DeclDxilFnExtern, // External function must be a DXIL function
  39. DeclDxilNsReserved, // The DXIL reserved prefixes must only be used by built-in functions and types
  40. DeclExtraArgs, // Extra arguments not allowed for shader functions
  41. DeclFnAttribute, // Functions should only contain known function attributes
  42. DeclFnFlattenParam, // Function parameters must not use struct types
  43. DeclFnIsCalled, // Functions can only be used by call instructions
  44. DeclNotUsedExternal, // External declaration should not be used
  45. DeclParamStruct, // Callable function parameter must be struct type
  46. DeclPayloadStruct, // Payload parameter must be struct type
  47. DeclResourceInFnSig, // Resources not allowed in function signatures
  48. DeclShaderMissingArg, // payload/params/attributes parameter is required for certain shader types
  49. DeclShaderReturnVoid, // Shader functions must return void
  50. DeclUsedExternalFunction, // External function must be used
  51. DeclUsedInternal, // Internal declaration must be used
  52. // Instruction
  53. InstrAllowed, // Instructions must be of an allowed type
  54. InstrAttributeAtVertexNoInterpolation, // Attribute %0 must have nointerpolation mode in order to use GetAttributeAtVertex function.
  55. InstrBarrierModeForNonCS, // sync in a non-Compute/Amplification/Mesh Shader must only sync UAV (sync_uglobal)
  56. InstrBarrierModeNoMemory, // sync must include some form of memory barrier - _u (UAV) and/or _g (Thread Group Shared Memory). Only _t (thread group sync) is optional.
  57. InstrBarrierModeUselessUGroup, // sync can't specify both _ugroup and _uglobal. If both are needed, just specify _uglobal.
  58. InstrBufferUpdateCounterOnResHasCounter, // BufferUpdateCounter valid only when HasCounter is true
  59. InstrBufferUpdateCounterOnUAV, // BufferUpdateCounter valid only on UAV
  60. InstrCBufferClassForCBufferHandle, // Expect Cbuffer for CBufferLoad handle
  61. InstrCBufferOutOfBound, // Cbuffer access out of bound
  62. InstrCallOload, // Call to DXIL intrinsic must match overload signature
  63. InstrCannotPullPosition, // pull-model evaluation of position disallowed
  64. InstrCheckAccessFullyMapped, // CheckAccessFullyMapped should only used on resource status
  65. InstrCoordinateCountForRawTypedBuf, // raw/typed buffer don't need 2 coordinates
  66. InstrCoordinateCountForStructBuf, // structured buffer require 2 coordinates
  67. InstrCreateHandleImmRangeID, // Local resource must map to global resource.
  68. InstrDxilStructUser, // Dxil struct types should only used by ExtractValue
  69. InstrDxilStructUserOutOfBound, // Index out of bound when extract value from dxil struct types
  70. InstrEvalInterpolationMode, // Interpolation mode on %0 used with eval_* instruction must be linear, linear_centroid, linear_noperspective, linear_noperspective_centroid, linear_sample or linear_noperspective_sample
  71. InstrExtractValue, // ExtractValue should only be used on dxil struct types and cmpxchg
  72. InstrFailToResloveTGSMPointer, // TGSM pointers must originate from an unambiguous TGSM global variable.
  73. InstrHandleNotFromCreateHandle, // Resource handle should returned by createHandle
  74. InstrImmBiasForSampleB, // bias amount for sample_b must be in the range [%0,%1], but %2 was specified as an immediate
  75. InstrInBoundsAccess, // Access to out-of-bounds memory is disallowed
  76. InstrMinPrecisionNotPrecise, // Instructions marked precise may not refer to minprecision values
  77. InstrMinPrecisonBitCast, // Bitcast on minprecison types is not allowed
  78. InstrMipLevelForGetDimension, // Use mip level on buffer when GetDimensions
  79. InstrMipOnUAVLoad, // uav load don't support mipLevel/sampleIndex
  80. InstrMissingSetMeshOutputCounts, // Missing SetMeshOutputCounts call.
  81. InstrMultipleGetMeshPayload, // GetMeshPayload cannot be called multiple times.
  82. InstrMultipleSetMeshOutputCounts, // SetMeshOUtputCounts cannot be called multiple times.
  83. InstrNoGenericPtrAddrSpaceCast, // Address space cast between pointer types must have one part to be generic address space
  84. InstrNoIDivByZero, // No signed integer division by zero
  85. InstrNoIndefiniteAcos, // No indefinite arccosine
  86. InstrNoIndefiniteAsin, // No indefinite arcsine
  87. InstrNoIndefiniteDsxy, // No indefinite derivative calculation
  88. InstrNoIndefiniteLog, // No indefinite logarithm
  89. InstrNoReadingUninitialized, // Instructions should not read uninitialized value
  90. InstrNoUDivByZero, // No unsigned integer division by zero
  91. InstrNonDominatingDispatchMesh, // Non-Dominating DispatchMesh call.
  92. InstrNonDominatingSetMeshOutputCounts, // Non-Dominating SetMeshOutputCounts call.
  93. InstrNotOnceDispatchMesh, // DispatchMesh must be called exactly once in an Amplification shader.
  94. InstrOffsetOnUAVLoad, // uav load don't support offset
  95. InstrOload, // DXIL intrinsic overload must be valid
  96. InstrOnlyOneAllocConsume, // RWStructuredBuffers may increment or decrement their counters, but not both.
  97. InstrOpCodeReserved, // Instructions must not reference reserved opcodes
  98. InstrOpConst, // DXIL intrinsic requires an immediate constant operand
  99. InstrOpConstRange, // Constant values must be in-range for operation
  100. InstrOperandRange, // DXIL intrinsic operand must be within defined range
  101. InstrPtrBitCast, // Pointer type bitcast must be have same size
  102. InstrResourceClassForLoad, // load can only run on UAV/SRV resource
  103. InstrResourceClassForSamplerGather, // sample, lod and gather should be on srv resource.
  104. InstrResourceClassForUAVStore, // store should be on uav resource.
  105. InstrResourceCoordinateMiss, // coord uninitialized
  106. InstrResourceCoordinateTooMany, // out of bound coord must be undef
  107. InstrResourceKindForBufferLoadStore, // buffer load/store only works on Raw/Typed/StructuredBuffer
  108. InstrResourceKindForCalcLOD, // lod requires resource declared as texture1D/2D/3D/Cube/CubeArray/1DArray/2DArray
  109. InstrResourceKindForGather, // gather requires resource declared as texture/2D/Cube/2DArray/CubeArray
  110. InstrResourceKindForGetDim, // Invalid resource kind on GetDimensions
  111. InstrResourceKindForSample, // sample/_l/_d requires resource declared as texture1D/2D/3D/Cube/1DArray/2DArray/CubeArray
  112. InstrResourceKindForSampleC, // samplec requires resource declared as texture1D/2D/Cube/1DArray/2DArray/CubeArray
  113. InstrResourceKindForTextureLoad, // texture load only works on Texture1D/1DArray/2D/2DArray/3D/MS2D/MS2DArray
  114. InstrResourceKindForTextureStore, // texture store only works on Texture1D/1DArray/2D/2DArray/3D
  115. InstrResourceKindForTraceRay, // TraceRay should only use RTAccelerationStructure
  116. InstrResourceMapToSingleEntry, // Fail to map resource to resource table
  117. InstrResourceOffsetMiss, // offset uninitialized
  118. InstrResourceOffsetTooMany, // out of bound offset must be undef
  119. InstrResourceUser, // Resource should only used by Load/GEP/Call
  120. InstrSampleCompType, // sample_* instructions require resource to be declared to return UNORM, SNORM or FLOAT.
  121. InstrSampleIndexForLoad2DMS, // load on Texture2DMS/2DMSArray require sampleIndex
  122. InstrSamplerModeForLOD, // lod instruction requires sampler declared in default mode
  123. InstrSamplerModeForSample, // sample/_l/_d/_cl_s/gather instruction requires sampler declared in default mode
  124. InstrSamplerModeForSampleC, // sample_c_*/gather_c instructions require sampler declared in comparison mode
  125. InstrSignatureOperationNotInEntry, // Dxil operation for input output signature must be in entryPoints.
  126. InstrStatus, // Resource status should only used by CheckAccessFullyMapped
  127. InstrStructBitCast, // Bitcast on struct types is not allowed
  128. InstrTGSMRaceCond, // Race condition writing to shared memory detected, consider making this write conditional
  129. InstrTextureOffset, // offset texture instructions must take offset which can resolve to integer literal in the range -8 to 7
  130. InstrUndefResultForGetDimension, // GetDimensions used undef dimension %0 on %1
  131. InstrWriteMaskForTypedUAVStore, // store on typed uav must write to all four components of the UAV
  132. InstrWriteMaskMatchValueForUAVStore, // uav store write mask must match store value mask, write mask is %0 and store value mask is %1
  133. // Metadata
  134. MetaBarycentricsFloat3, // only 'float3' type is allowed for SV_Barycentrics.
  135. MetaBarycentricsInterpolation, // SV_Barycentrics cannot be used with 'nointerpolation' type
  136. MetaBarycentricsTwoPerspectives, // There can only be up to two input attributes of SV_Barycentrics with different perspective interpolation mode.
  137. MetaBranchFlatten, // Can't use branch and flatten attributes together
  138. MetaClipCullMaxComponents, // Combined elements of SV_ClipDistance and SV_CullDistance must fit in 8 components
  139. MetaClipCullMaxRows, // Combined elements of SV_ClipDistance and SV_CullDistance must fit in two rows.
  140. MetaControlFlowHintNotOnControlFlow, // Control flow hint only works on control flow inst
  141. MetaDenseResIDs, // Resource identifiers must be zero-based and dense
  142. MetaDuplicateSysValue, // System value may only appear once in signature
  143. MetaEntryFunction, // entrypoint not found
  144. MetaFlagsUsage, // Flags must match usage
  145. MetaForceCaseOnSwitch, // Attribute forcecase only works for switch
  146. MetaGlcNotOnAppendConsume, // globallycoherent cannot be used with append/consume buffers
  147. MetaIntegerInterpMode, // Interpolation mode on integer must be Constant
  148. MetaInterpModeInOneRow, // Interpolation mode must be identical for all elements packed into the same row.
  149. MetaInterpModeValid, // Interpolation mode must be valid
  150. MetaInvalidControlFlowHint, // Invalid control flow hint
  151. MetaKnown, // Named metadata should be known
  152. MetaMaxTessFactor, // Hull Shader MaxTessFactor must be [%0..%1]. %2 specified
  153. MetaNoEntryPropsForEntry, // EntryPoints must have entry properties.
  154. MetaNoSemanticOverlap, // Semantics must not overlap
  155. MetaRequired, // TODO - Required metadata missing
  156. MetaSemaKindMatchesName, // Semantic name must match system value, when defined.
  157. MetaSemaKindValid, // Semantic kind must be valid
  158. MetaSemanticCompType, // %0 must be %1
  159. MetaSemanticIndexMax, // System value semantics have a maximum valid semantic index
  160. MetaSemanticLen, // Semantic length must be at least 1 and at most 64
  161. MetaSemanticShouldBeAllocated, // Semantic should have a valid packing location
  162. MetaSemanticShouldNotBeAllocated, // Semantic should have a packing location of -1
  163. MetaSignatureCompType, // signature %0 specifies unrecognized or invalid component type
  164. MetaSignatureDataWidth, // Data width must be identical for all elements packed into the same row.
  165. MetaSignatureIllegalComponentOrder, // Component ordering for packed elements must be: arbitrary < system value < system generated value
  166. MetaSignatureIndexConflict, // Only elements with compatible indexing rules may be packed together
  167. MetaSignatureOutOfRange, // Signature elements must fit within maximum signature size
  168. MetaSignatureOverlap, // Signature elements may not overlap in packing location.
  169. MetaStructBufAlignment, // StructuredBuffer stride not aligned
  170. MetaStructBufAlignmentOutOfBound, // StructuredBuffer stride out of bounds
  171. MetaSystemValueRows, // System value may only have 1 row
  172. MetaTarget, // Target triple must be 'dxil-ms-dx'
  173. MetaTessellatorOutputPrimitive, // Invalid Tessellator Output Primitive specified. Must be point, line, triangleCW or triangleCCW.
  174. MetaTessellatorPartition, // Invalid Tessellator Partitioning specified. Must be integer, pow2, fractional_odd or fractional_even.
  175. MetaTextureType, // elements of typed buffers and textures must fit in four 32-bit quantities
  176. MetaUsed, // All metadata must be used by dxil
  177. MetaValidSamplerMode, // Invalid sampler mode on sampler
  178. MetaValueRange, // Metadata value must be within range
  179. MetaWellFormed, // TODO - Metadata must be well-formed in operand count and types
  180. // Program flow
  181. FlowDeadLoop, // Loop must have break
  182. FlowFunctionCall, // Function with parameter is not permitted
  183. FlowNoRecusion, // Recursion is not permitted
  184. FlowReducible, // Execution flow must be reducible
  185. // Shader model
  186. Sm64bitRawBufferLoadStore, // i64/f64 rawBufferLoad/Store overloads are allowed after SM 6.3
  187. SmAmplificationShaderPayloadSize, // For shader '%0', payload size is greater than %1
  188. SmAmplificationShaderPayloadSizeDeclared, // For shader '%0', payload size %1 is greater than declared size of %2 bytes
  189. SmAppendAndConsumeOnSameUAV, // BufferUpdateCounter inc and dec on a given UAV (%d) cannot both be in the same shader for shader model less than 5.1.
  190. SmCBufferArrayOffsetAlignment, // CBuffer array offset must be aligned to 16-bytes
  191. SmCBufferElementOverflow, // CBuffer elements must not overflow
  192. SmCBufferOffsetOverlap, // CBuffer offsets must not overlap
  193. SmCBufferTemplateTypeMustBeStruct, // D3D12 constant/texture buffer template element can only be a struct
  194. SmCSNoSignatures, // Compute shaders must not have shader signatures.
  195. SmCompletePosition, // Not all elements of SV_Position were written
  196. SmConstantInterpMode, // Interpolation mode must be constant for MS primitive output.
  197. SmCounterOnlyOnStructBuf, // BufferUpdateCounter valid only on structured buffers
  198. SmDSInputControlPointCountRange, // DS input control point count must be [0..%0]. %1 specified
  199. SmDomainLocationIdxOOB, // DomainLocation component index out of bounds for the domain.
  200. SmDxilVersion, // Target shader model requires specific Dxil Version
  201. SmGSInstanceCountRange, // GS instance count must be [1..%0]. %1 specified
  202. SmGSOutputVertexCountRange, // GS output vertex count must be [0..%0]. %1 specified
  203. SmGSTotalOutputVertexDataRange, // Declared output vertex count (%0) multiplied by the total number of declared scalar components of output data (%1) equals %2. This value cannot be greater than %3
  204. SmGSValidInputPrimitive, // GS input primitive unrecognized
  205. SmGSValidOutputPrimitiveTopology, // GS output primitive topology unrecognized
  206. SmHSInputControlPointCountRange, // HS input control point count must be [0..%0]. %1 specified
  207. SmHullPassThruControlPointCountMatch, // For pass thru hull shader, input control point count must match output control point count
  208. SmInsideTessFactorSizeMatchDomain, // InsideTessFactor rows, columns (%0, %1) invalid for domain %2. Expected %3 rows and 1 column.
  209. SmInvalidResourceCompType, // Invalid resource return type
  210. SmInvalidResourceKind, // Invalid resources kind
  211. SmInvalidSamplerFeedbackType, // Invalid sampler feedback type
  212. SmInvalidTextureKindOnUAV, // Texture2DMS[Array] or TextureCube[Array] resources are not supported with UAVs
  213. SmIsoLineOutputPrimitiveMismatch, // Hull Shader declared with IsoLine Domain must specify output primitive point or line. Triangle_cw or triangle_ccw output are not compatible with the IsoLine Domain.
  214. SmMaxMSSMSize, // Total Thread Group Shared Memory storage is %0, exceeded %1
  215. SmMaxTGSMSize, // Total Thread Group Shared Memory storage is %0, exceeded %1
  216. SmMaxTheadGroup, // Declared Thread Group Count %0 (X*Y*Z) is beyond the valid maximum of %1
  217. SmMeshPSigRowCount, // For shader '%0', primitive output signatures are taking up more than %1 rows
  218. SmMeshShaderInOutSize, // For shader '%0', payload plus output size is greater than %1
  219. SmMeshShaderMaxPrimitiveCount, // MS max primitive output count must be [0..%0]. %1 specified
  220. SmMeshShaderMaxVertexCount, // MS max vertex output count must be [0..%0]. %1 specified
  221. SmMeshShaderOutputSize, // For shader '%0', vertex plus primitive output size is greater than %1
  222. SmMeshShaderPayloadSize, // For shader '%0', payload size is greater than %1
  223. SmMeshShaderPayloadSizeDeclared, // For shader '%0', payload size %1 is greater than declared size of %2 bytes
  224. SmMeshTotalSigRowCount, // For shader '%0', vertex and primitive output signatures are taking up more than %1 rows
  225. SmMeshVSigRowCount, // For shader '%0', vertex output signatures are taking up more than %1 rows
  226. SmMultiStreamMustBePoint, // When multiple GS output streams are used they must be pointlists
  227. SmName, // Target shader model name must be known
  228. SmNoInterpMode, // Interpolation mode must be undefined for VS input/PS output/patch constant.
  229. SmNoPSOutputIdx, // Pixel shader output registers are not indexable.
  230. SmOpcode, // Opcode must be defined in target shader model
  231. SmOpcodeInInvalidFunction, // Invalid DXIL opcode usage like StorePatchConstant in patch constant function
  232. SmOperand, // Operand must be defined in target shader model
  233. SmOutputControlPointCountRange, // output control point count must be [0..%0]. %1 specified
  234. SmOutputControlPointsTotalScalars, // Total number of scalars across all HS output control points must not exceed
  235. SmPSConsistentInterp, // Interpolation mode for PS input position must be linear_noperspective_centroid or linear_noperspective_sample when outputting oDepthGE or oDepthLE and not running at sample frequency (which is forced by inputting SV_SampleIndex or declaring an input linear_sample or linear_noperspective_sample)
  236. SmPSCoverageAndInnerCoverage, // InnerCoverage and Coverage are mutually exclusive.
  237. SmPSMultipleDepthSemantic, // Pixel Shader only allows one type of depth semantic to be declared
  238. SmPSOutputSemantic, // Pixel Shader allows output semantics to be SV_Target, SV_Depth, SV_DepthGreaterEqual, SV_DepthLessEqual, SV_Coverage or SV_StencilRef, %0 found
  239. SmPSTargetCol0, // SV_Target packed location must start at column 0
  240. SmPSTargetIndexMatchesRow, // SV_Target semantic index must match packed row location
  241. SmPatchConstantOnlyForHSDS, // patch constant signature only valid in HS and DS
  242. SmROVOnlyInPS, // RasterizerOrdered objects are only allowed in 5.0+ pixel shaders
  243. SmRayShaderPayloadSize, // For shader '%0', %1 size is smaller than argument's allocation size
  244. SmRayShaderSignatures, // Ray tracing shader '%0' should not have any shader signatures
  245. SmResourceRangeOverlap, // Resource ranges must not overlap
  246. SmSampleCountOnlyOn2DMS, // Only Texture2DMS/2DMSArray could has sample count
  247. SmSemantic, // Semantic must be defined in target shader model
  248. SmStreamIndexRange, // Stream index (%0) must between 0 and %1
  249. SmTessFactorForDomain, // Required TessFactor for domain not found declared anywhere in Patch Constant data
  250. SmTessFactorSizeMatchDomain, // TessFactor rows, columns (%0, %1) invalid for domain %2. Expected %3 rows and 1 column.
  251. SmThreadGroupChannelRange, // Declared Thread Group %0 size %1 outside valid range [%2..%3]
  252. SmTriOutputPrimitiveMismatch, // Hull Shader declared with Tri Domain must specify output primitive point, triangle_cw or triangle_ccw. Line output is not compatible with the Tri domain
  253. SmUndefinedOutput, // Not all elements of output %0 were written
  254. SmValidDomain, // Invalid Tessellator Domain specified. Must be isoline, tri or quad
  255. SmViewIDNeedsSlot, // ViewID requires compatible space in pixel shader input signature
  256. SmZeroHSInputControlPointWithInput, // When HS input control point count is 0, no input signature should exist
  257. // Type system
  258. TypesDefined, // Type must be defined based on DXIL primitives
  259. TypesI8, // I8 can only used as immediate value for intrinsic
  260. TypesIntWidth, // Int type must be of valid width
  261. TypesNoMultiDim, // Only one dimension allowed for array type
  262. TypesNoPtrToPtr, // Pointers to pointers, or pointers in structures are not allowed
  263. TypesNoVector, // Vector types must not be present
  264. };
  265. // VALRULE-ENUM:END
  266. const char *GetValidationRuleText(ValidationRule value);
  267. void GetValidationVersion(_Out_ unsigned *pMajor, _Out_ unsigned *pMinor);
  268. HRESULT ValidateDxilModule(_In_ llvm::Module *pModule,
  269. _In_opt_ llvm::Module *pDebugModule);
  270. // DXIL Container Verification Functions (return false on failure)
  271. bool VerifySignatureMatches(_In_ llvm::Module *pModule,
  272. hlsl::DXIL::SignatureKind SigKind,
  273. _In_reads_bytes_(SigSize) const void *pSigData,
  274. _In_ uint32_t SigSize);
  275. // PSV = data for Pipeline State Validation
  276. bool VerifyPSVMatches(_In_ llvm::Module *pModule,
  277. _In_reads_bytes_(PSVSize) const void *pPSVData,
  278. _In_ uint32_t PSVSize);
  279. // PSV = data for Pipeline State Validation
  280. bool VerifyRDATMatches(_In_ llvm::Module *pModule,
  281. _In_reads_bytes_(RDATSize) const void *pRDATData,
  282. _In_ uint32_t RDATSize);
  283. bool VerifyFeatureInfoMatches(_In_ llvm::Module *pModule,
  284. _In_reads_bytes_(FeatureInfoSize) const void *pFeatureInfoData,
  285. _In_ uint32_t FeatureInfoSize);
  286. // Validate the container parts, assuming supplied module is valid, loaded from the container provided
  287. struct DxilContainerHeader;
  288. HRESULT ValidateDxilContainerParts(_In_ llvm::Module *pModule,
  289. _In_opt_ llvm::Module *pDebugModule,
  290. _In_reads_bytes_(ContainerSize) const DxilContainerHeader *pContainer,
  291. _In_ uint32_t ContainerSize);
  292. // Loads module, validating load, but not module.
  293. HRESULT ValidateLoadModule(_In_reads_bytes_(ILLength) const char *pIL,
  294. _In_ uint32_t ILLength,
  295. _In_ std::unique_ptr<llvm::Module> &pModule,
  296. _In_ llvm::LLVMContext &Ctx,
  297. _In_ llvm::raw_ostream &DiagStream,
  298. _In_ unsigned bLazyLoad);
  299. // Loads module from container, validating load, but not module.
  300. HRESULT ValidateLoadModuleFromContainer(
  301. _In_reads_bytes_(ContainerSize) const void *pContainer,
  302. _In_ uint32_t ContainerSize, _In_ std::unique_ptr<llvm::Module> &pModule,
  303. _In_ std::unique_ptr<llvm::Module> &pDebugModule,
  304. _In_ llvm::LLVMContext &Ctx, llvm::LLVMContext &DbgCtx,
  305. _In_ llvm::raw_ostream &DiagStream);
  306. // Lazy loads module from container, validating load, but not module.
  307. HRESULT ValidateLoadModuleFromContainerLazy(
  308. _In_reads_bytes_(ContainerSize) const void *pContainer,
  309. _In_ uint32_t ContainerSize, _In_ std::unique_ptr<llvm::Module> &pModule,
  310. _In_ std::unique_ptr<llvm::Module> &pDebugModule,
  311. _In_ llvm::LLVMContext &Ctx, llvm::LLVMContext &DbgCtx,
  312. _In_ llvm::raw_ostream &DiagStream);
  313. // Load and validate Dxil module from bitcode.
  314. HRESULT ValidateDxilBitcode(_In_reads_bytes_(ILLength) const char *pIL,
  315. _In_ uint32_t ILLength,
  316. _In_ llvm::raw_ostream &DiagStream);
  317. // Full container validation, including ValidateDxilModule
  318. HRESULT ValidateDxilContainer(_In_reads_bytes_(ContainerSize) const void *pContainer,
  319. _In_ uint32_t ContainerSize,
  320. _In_ llvm::raw_ostream &DiagStream);
  321. class PrintDiagnosticContext {
  322. private:
  323. llvm::DiagnosticPrinter &m_Printer;
  324. bool m_errorsFound;
  325. bool m_warningsFound;
  326. public:
  327. PrintDiagnosticContext(llvm::DiagnosticPrinter &printer);
  328. bool HasErrors() const;
  329. bool HasWarnings() const;
  330. void Handle(const llvm::DiagnosticInfo &DI);
  331. static void PrintDiagnosticHandler(const llvm::DiagnosticInfo &DI,
  332. void *Context);
  333. };
  334. }