DxilValidation.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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, // 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 be 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 be 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 be 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 be 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. InstrUndefinedValueForUAVStore, // Assignment of undefined values to UAV.
  132. InstrWriteMaskForTypedUAVStore, // store on typed uav must write to all four components of the UAV.
  133. InstrWriteMaskMatchValueForUAVStore, // uav store write mask must match store value mask, write mask is %0 and store value mask is %1.
  134. // Metadata
  135. MetaBarycentricsFloat3, // only 'float3' type is allowed for SV_Barycentrics.
  136. MetaBarycentricsInterpolation, // SV_Barycentrics cannot be used with 'nointerpolation' type.
  137. MetaBarycentricsTwoPerspectives, // There can only be up to two input attributes of SV_Barycentrics with different perspective interpolation mode.
  138. MetaBranchFlatten, // Can't use branch and flatten attributes together.
  139. MetaClipCullMaxComponents, // Combined elements of SV_ClipDistance and SV_CullDistance must fit in 8 components
  140. MetaClipCullMaxRows, // Combined elements of SV_ClipDistance and SV_CullDistance must fit in two rows.
  141. MetaControlFlowHintNotOnControlFlow, // Control flow hint only works on control flow inst.
  142. MetaDenseResIDs, // Resource identifiers must be zero-based and dense.
  143. MetaDuplicateSysValue, // System value may only appear once in signature
  144. MetaEntryFunction, // entrypoint not found.
  145. MetaFlagsUsage, // Flags must match usage.
  146. MetaForceCaseOnSwitch, // Attribute forcecase only works for switch.
  147. MetaGlcNotOnAppendConsume, // globallycoherent cannot be used with append/consume buffers: '%0'.
  148. MetaIntegerInterpMode, // Interpolation mode on integer must be Constant
  149. MetaInterpModeInOneRow, // Interpolation mode must be identical for all elements packed into the same row.
  150. MetaInterpModeValid, // Interpolation mode must be valid
  151. MetaInvalidControlFlowHint, // Invalid control flow hint.
  152. MetaKnown, // Named metadata should be known
  153. MetaMaxTessFactor, // Hull Shader MaxTessFactor must be [%0..%1]. %2 specified.
  154. MetaNoEntryPropsForEntry, // Entry point %0 must have entry properties.
  155. MetaNoSemanticOverlap, // Semantics must not overlap
  156. MetaRequired, // Required metadata missing.
  157. MetaSemaKindMatchesName, // Semantic name must match system value, when defined.
  158. MetaSemaKindValid, // Semantic kind must be valid
  159. MetaSemanticCompType, // %0 must be %1.
  160. MetaSemanticIndexMax, // System value semantics have a maximum valid semantic index
  161. MetaSemanticLen, // Semantic length must be at least 1 and at most 64.
  162. MetaSemanticShouldBeAllocated, // Semantic should have a valid packing location
  163. MetaSemanticShouldNotBeAllocated, // Semantic should have a packing location of -1
  164. MetaSignatureCompType, // signature %0 specifies unrecognized or invalid component type.
  165. MetaSignatureDataWidth, // Data width must be identical for all elements packed into the same row.
  166. MetaSignatureIllegalComponentOrder, // Component ordering for packed elements must be: arbitrary < system value < system generated value
  167. MetaSignatureIndexConflict, // Only elements with compatible indexing rules may be packed together
  168. MetaSignatureOutOfRange, // Signature elements must fit within maximum signature size
  169. MetaSignatureOverlap, // Signature elements may not overlap in packing location.
  170. MetaStructBufAlignment, // StructuredBuffer stride not aligned
  171. MetaStructBufAlignmentOutOfBound, // StructuredBuffer stride out of bounds
  172. MetaSystemValueRows, // System value may only have 1 row
  173. MetaTarget, // Target triple must be 'dxil-ms-dx'
  174. MetaTessellatorOutputPrimitive, // Invalid Tessellator Output Primitive specified. Must be point, line, triangleCW or triangleCCW.
  175. MetaTessellatorPartition, // Invalid Tessellator Partitioning specified. Must be integer, pow2, fractional_odd or fractional_even.
  176. MetaTextureType, // elements of typed buffers and textures must fit in four 32-bit quantities.
  177. MetaUsed, // All metadata must be used by dxil.
  178. MetaValidSamplerMode, // Invalid sampler mode on sampler .
  179. MetaValueRange, // Metadata value must be within range.
  180. MetaVersionSupported, // Version in metadata must be supported.
  181. MetaWellFormed, // Metadata must be well-formed in operand count and types.
  182. // Program flow
  183. FlowDeadLoop, // Loop must have break.
  184. FlowFunctionCall, // Function with parameter is not permitted
  185. FlowNoRecusion, // Recursion is not permitted.
  186. FlowReducible, // Execution flow must be reducible.
  187. // Shader model
  188. Sm64bitRawBufferLoadStore, // i64/f64 rawBufferLoad/Store overloads are allowed after SM 6.3.
  189. SmAmplificationShaderPayloadSize, // For amplification shader with entry '%0', payload size %1 is greater than maximum size of %2 bytes.
  190. SmAmplificationShaderPayloadSizeDeclared, // For amplification shader with entry '%0', payload size %1 is greater than declared size of %2 bytes.
  191. SmAppendAndConsumeOnSameUAV, // BufferUpdateCounter inc and dec on a given UAV (%d) cannot both be in the same shader for shader model less than 5.1.
  192. SmCBufferArrayOffsetAlignment, // CBuffer array offset must be aligned to 16-bytes
  193. SmCBufferElementOverflow, // CBuffer elements must not overflow
  194. SmCBufferOffsetOverlap, // CBuffer offsets must not overlap
  195. SmCBufferSize, // CBuffer size must not exceed 65536 bytes
  196. SmCBufferTemplateTypeMustBeStruct, // D3D12 constant/texture buffer template element can only be a struct.
  197. SmCSNoSignatures, // Compute shaders must not have shader signatures.
  198. SmCompletePosition, // Not all elements of SV_Position were written.
  199. SmConstantInterpMode, // Interpolation mode must be constant for MS primitive output.
  200. SmCounterOnlyOnStructBuf, // BufferUpdateCounter valid only on structured buffers.
  201. SmDSInputControlPointCountRange, // DS input control point count must be [0..%0]. %1 specified.
  202. SmDomainLocationIdxOOB, // DomainLocation component index out of bounds for the domain.
  203. SmDxilVersion, // Target shader model requires specific Dxil Version
  204. SmGSInstanceCountRange, // GS instance count must be [1..%0]. %1 specified.
  205. SmGSOutputVertexCountRange, // GS output vertex count must be [0..%0]. %1 specified.
  206. 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.
  207. SmGSValidInputPrimitive, // GS input primitive unrecognized.
  208. SmGSValidOutputPrimitiveTopology, // GS output primitive topology unrecognized.
  209. SmHSInputControlPointCountRange, // HS input control point count must be [0..%0]. %1 specified.
  210. SmHullPassThruControlPointCountMatch, // For pass thru hull shader, input control point count must match output control point count
  211. SmInsideTessFactorSizeMatchDomain, // InsideTessFactor rows, columns (%0, %1) invalid for domain %2. Expected %3 rows and 1 column.
  212. SmInvalidResourceCompType, // Invalid resource return type.
  213. SmInvalidResourceKind, // Invalid resources kind.
  214. SmInvalidSamplerFeedbackType, // Invalid sampler feedback type.
  215. SmInvalidTextureKindOnUAV, // Texture2DMS[Array] or TextureCube[Array] resources are not supported with UAVs.
  216. 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.
  217. SmMaxMSSMSize, // Total Thread Group Shared Memory storage is %0, exceeded %1.
  218. SmMaxTGSMSize, // Total Thread Group Shared Memory storage is %0, exceeded %1.
  219. SmMaxTheadGroup, // Declared Thread Group Count %0 (X*Y*Z) is beyond the valid maximum of %1.
  220. SmMeshPSigRowCount, // For shader '%0', primitive output signatures are taking up more than %1 rows.
  221. SmMeshShaderInOutSize, // For shader '%0', payload plus output size is greater than %1.
  222. SmMeshShaderMaxPrimitiveCount, // MS max primitive output count must be [0..%0]. %1 specified.
  223. SmMeshShaderMaxVertexCount, // MS max vertex output count must be [0..%0]. %1 specified.
  224. SmMeshShaderOutputSize, // For shader '%0', vertex plus primitive output size is greater than %1.
  225. SmMeshShaderPayloadSize, // For mesh shader with entry '%0', payload size %1 is greater than maximum size of %2 bytes.
  226. SmMeshShaderPayloadSizeDeclared, // For mesh shader with entry '%0', payload size %1 is greater than declared size of %2 bytes.
  227. SmMeshTotalSigRowCount, // For shader '%0', vertex and primitive output signatures are taking up more than %1 rows.
  228. SmMeshVSigRowCount, // For shader '%0', vertex output signatures are taking up more than %1 rows.
  229. SmMultiStreamMustBePoint, // When multiple GS output streams are used they must be pointlists
  230. SmName, // Target shader model name must be known
  231. SmNoInterpMode, // Interpolation mode must be undefined for VS input/PS output/patch constant.
  232. SmNoPSOutputIdx, // Pixel shader output registers are not indexable.
  233. SmOpcode, // Opcode must be defined in target shader model
  234. SmOpcodeInInvalidFunction, // Invalid DXIL opcode usage like StorePatchConstant in patch constant function
  235. SmOperand, // Operand must be defined in target shader model.
  236. SmOutputControlPointCountRange, // output control point count must be [0..%0]. %1 specified.
  237. SmOutputControlPointsTotalScalars, // Total number of scalars across all HS output control points must not exceed .
  238. 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).
  239. SmPSCoverageAndInnerCoverage, // InnerCoverage and Coverage are mutually exclusive.
  240. SmPSMultipleDepthSemantic, // Pixel Shader only allows one type of depth semantic to be declared.
  241. SmPSOutputSemantic, // Pixel Shader allows output semantics to be SV_Target, SV_Depth, SV_DepthGreaterEqual, SV_DepthLessEqual, SV_Coverage or SV_StencilRef, %0 found.
  242. SmPSTargetCol0, // SV_Target packed location must start at column 0.
  243. SmPSTargetIndexMatchesRow, // SV_Target semantic index must match packed row location.
  244. SmPatchConstantOnlyForHSDS, // patch constant signature only valid in HS and DS.
  245. SmROVOnlyInPS, // RasterizerOrdered objects are only allowed in 5.0+ pixel shaders.
  246. SmRayShaderPayloadSize, // For shader '%0', %1 size is smaller than argument's allocation size.
  247. SmRayShaderSignatures, // Ray tracing shader '%0' should not have any shader signatures.
  248. SmResourceRangeOverlap, // Resource ranges must not overlap
  249. SmSampleCountOnlyOn2DMS, // Only Texture2DMS/2DMSArray could has sample count.
  250. SmSemantic, // Semantic must be defined in target shader model
  251. SmStreamIndexRange, // Stream index (%0) must between 0 and %1.
  252. SmTGSMUnsupported, // Thread Group Shared Memory not supported %0.
  253. SmTessFactorForDomain, // Required TessFactor for domain not found declared anywhere in Patch Constant data.
  254. SmTessFactorSizeMatchDomain, // TessFactor rows, columns (%0, %1) invalid for domain %2. Expected %3 rows and 1 column.
  255. SmThreadGroupChannelRange, // Declared Thread Group %0 size %1 outside valid range [%2..%3].
  256. 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.
  257. SmUndefinedOutput, // Not all elements of output %0 were written.
  258. SmValidDomain, // Invalid Tessellator Domain specified. Must be isoline, tri or quad.
  259. SmViewIDNeedsSlot, // ViewID requires compatible space in pixel shader input signature
  260. SmWaveSizeNeedsDxil16Plus, // WaveSize is valid only for DXIL version 1.6 and higher.
  261. SmWaveSizeValue, // Declared WaveSize %0 outside valid range [%1..%2], or not a power of 2.
  262. SmZeroHSInputControlPointWithInput, // When HS input control point count is 0, no input signature should exist.
  263. // Type system
  264. TypesDefined, // Type must be defined based on DXIL primitives
  265. TypesI8, // I8 can only be used as immediate value for intrinsic or as i8* via bitcast by lifetime intrinsics.
  266. TypesIntWidth, // Int type must be of valid width
  267. TypesNoMultiDim, // Only one dimension allowed for array type.
  268. TypesNoPtrToPtr, // Pointers to pointers, or pointers in structures are not allowed.
  269. TypesNoVector, // Vector types must not be present
  270. };
  271. // VALRULE-ENUM:END
  272. const char *GetValidationRuleText(ValidationRule value);
  273. void GetValidationVersion(_Out_ unsigned *pMajor, _Out_ unsigned *pMinor);
  274. HRESULT ValidateDxilModule(_In_ llvm::Module *pModule,
  275. _In_opt_ llvm::Module *pDebugModule);
  276. // DXIL Container Verification Functions (return false on failure)
  277. bool VerifySignatureMatches(_In_ llvm::Module *pModule,
  278. hlsl::DXIL::SignatureKind SigKind,
  279. _In_reads_bytes_(SigSize) const void *pSigData,
  280. _In_ uint32_t SigSize);
  281. // PSV = data for Pipeline State Validation
  282. bool VerifyPSVMatches(_In_ llvm::Module *pModule,
  283. _In_reads_bytes_(PSVSize) const void *pPSVData,
  284. _In_ uint32_t PSVSize);
  285. // PSV = data for Pipeline State Validation
  286. bool VerifyRDATMatches(_In_ llvm::Module *pModule,
  287. _In_reads_bytes_(RDATSize) const void *pRDATData,
  288. _In_ uint32_t RDATSize);
  289. bool VerifyFeatureInfoMatches(_In_ llvm::Module *pModule,
  290. _In_reads_bytes_(FeatureInfoSize) const void *pFeatureInfoData,
  291. _In_ uint32_t FeatureInfoSize);
  292. // Validate the container parts, assuming supplied module is valid, loaded from the container provided
  293. struct DxilContainerHeader;
  294. HRESULT ValidateDxilContainerParts(_In_ llvm::Module *pModule,
  295. _In_opt_ llvm::Module *pDebugModule,
  296. _In_reads_bytes_(ContainerSize) const DxilContainerHeader *pContainer,
  297. _In_ uint32_t ContainerSize);
  298. // Loads module, validating load, but not module.
  299. HRESULT ValidateLoadModule(_In_reads_bytes_(ILLength) const char *pIL,
  300. _In_ uint32_t ILLength,
  301. _In_ std::unique_ptr<llvm::Module> &pModule,
  302. _In_ llvm::LLVMContext &Ctx,
  303. _In_ llvm::raw_ostream &DiagStream,
  304. _In_ unsigned bLazyLoad);
  305. // Loads module from container, validating load, but not module.
  306. HRESULT ValidateLoadModuleFromContainer(
  307. _In_reads_bytes_(ContainerSize) const void *pContainer,
  308. _In_ uint32_t ContainerSize, _In_ std::unique_ptr<llvm::Module> &pModule,
  309. _In_ std::unique_ptr<llvm::Module> &pDebugModule,
  310. _In_ llvm::LLVMContext &Ctx, llvm::LLVMContext &DbgCtx,
  311. _In_ llvm::raw_ostream &DiagStream);
  312. // Lazy loads module from container, validating load, but not module.
  313. HRESULT ValidateLoadModuleFromContainerLazy(
  314. _In_reads_bytes_(ContainerSize) const void *pContainer,
  315. _In_ uint32_t ContainerSize, _In_ std::unique_ptr<llvm::Module> &pModule,
  316. _In_ std::unique_ptr<llvm::Module> &pDebugModule,
  317. _In_ llvm::LLVMContext &Ctx, llvm::LLVMContext &DbgCtx,
  318. _In_ llvm::raw_ostream &DiagStream);
  319. // Load and validate Dxil module from bitcode.
  320. HRESULT ValidateDxilBitcode(_In_reads_bytes_(ILLength) const char *pIL,
  321. _In_ uint32_t ILLength,
  322. _In_ llvm::raw_ostream &DiagStream);
  323. // Full container validation, including ValidateDxilModule
  324. HRESULT ValidateDxilContainer(_In_reads_bytes_(ContainerSize) const void *pContainer,
  325. _In_ uint32_t ContainerSize,
  326. _In_ llvm::raw_ostream &DiagStream);
  327. // Full container validation, including ValidateDxilModule, with debug module
  328. HRESULT ValidateDxilContainer(_In_reads_bytes_(ContainerSize) const void *pContainer,
  329. _In_ uint32_t ContainerSize,
  330. const void *pOptDebugBitcode,
  331. uint32_t OptDebugBitcodeSize,
  332. _In_ llvm::raw_ostream &DiagStream);
  333. class PrintDiagnosticContext {
  334. private:
  335. llvm::DiagnosticPrinter &m_Printer;
  336. bool m_errorsFound;
  337. bool m_warningsFound;
  338. public:
  339. PrintDiagnosticContext(llvm::DiagnosticPrinter &printer);
  340. bool HasErrors() const;
  341. bool HasWarnings() const;
  342. void Handle(const llvm::DiagnosticInfo &DI);
  343. static void PrintDiagnosticHandler(const llvm::DiagnosticInfo &DI,
  344. void *Context);
  345. };
  346. }