DxilMetadataHelper.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // DxilMetadataHelper.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. // Helper to serialize/desialize metadata for DxilModule. //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #pragma once
  12. #include "dxc/DXIL/DxilConstants.h"
  13. #include <memory>
  14. #include <string>
  15. #include <vector>
  16. namespace llvm {
  17. class LLVMContext;
  18. class Module;
  19. class Function;
  20. class Instruction;
  21. class Value;
  22. class MDOperand;
  23. class Metadata;
  24. class ConstantAsMetadata;
  25. class MDTuple;
  26. class MDNode;
  27. class NamedMDNode;
  28. class GlobalVariable;
  29. class StringRef;
  30. }
  31. namespace hlsl {
  32. class ShaderModel;
  33. class DxilSignature;
  34. struct DxilEntrySignature;
  35. class DxilSignatureElement;
  36. class DxilModule;
  37. class DxilResourceBase;
  38. class DxilCBuffer;
  39. class DxilResource;
  40. class DxilSampler;
  41. class DxilTypeSystem;
  42. class DxilStructAnnotation;
  43. class DxilFieldAnnotation;
  44. class DxilFunctionAnnotation;
  45. class DxilParameterAnnotation;
  46. class RootSignatureHandle;
  47. struct DxilFunctionProps;
  48. class DxilSubobjects;
  49. class DxilSubobject;
  50. /// Use this class to manipulate DXIL-spcific metadata.
  51. // In our code, only DxilModule and HLModule should use this class.
  52. class DxilMDHelper {
  53. public:
  54. //
  55. // Constants for metadata names and field positions.
  56. //
  57. // Dxil version.
  58. static const char kDxilVersionMDName[];
  59. static const unsigned kDxilVersionNumFields = 2;
  60. static const unsigned kDxilVersionMajorIdx = 0; // DXIL version major.
  61. static const unsigned kDxilVersionMinorIdx = 1; // DXIL version minor.
  62. // Shader model.
  63. static const char kDxilShaderModelMDName[];
  64. static const unsigned kDxilShaderModelNumFields = 3;
  65. static const unsigned kDxilShaderModelTypeIdx = 0; // Shader type (vs,ps,cs,gs,ds,hs).
  66. static const unsigned kDxilShaderModelMajorIdx = 1; // Shader model major.
  67. static const unsigned kDxilShaderModelMinorIdx = 2; // Shader model minor.
  68. // Intermediate codegen/optimizer options, not valid in final DXIL module.
  69. static const char kDxilIntermediateOptionsMDName[];
  70. static const unsigned kDxilIntermediateOptionsFlags = 0; // Unique element ID.
  71. // Entry points.
  72. static const char kDxilEntryPointsMDName[];
  73. // Root Signature, for intermediate use, not valid in final DXIL module.
  74. static const char kDxilRootSignatureMDName[];
  75. // ViewId state.
  76. static const char kDxilViewIdStateMDName[];
  77. // Subobjects
  78. static const char kDxilSubobjectsMDName[];
  79. // Source info.
  80. static const char kDxilSourceContentsMDName[];
  81. static const char kDxilSourceDefinesMDName[];
  82. static const char kDxilSourceMainFileNameMDName[];
  83. static const char kDxilSourceArgsMDName[];
  84. static const unsigned kDxilEntryPointNumFields = 5;
  85. static const unsigned kDxilEntryPointFunction = 0; // Entry point function symbol.
  86. static const unsigned kDxilEntryPointName = 1; // Entry point unmangled name.
  87. static const unsigned kDxilEntryPointSignatures = 2; // Entry point signature tuple.
  88. static const unsigned kDxilEntryPointResources = 3; // Entry point resource tuple.
  89. static const unsigned kDxilEntryPointProperties = 4; // Entry point properties tuple.
  90. // Signatures.
  91. static const unsigned kDxilNumSignatureFields = 3;
  92. static const unsigned kDxilInputSignature = 0; // Shader input signature.
  93. static const unsigned kDxilOutputSignature = 1; // Shader output signature.
  94. static const unsigned kDxilPatchConstantSignature = 2; // Shader patch constant (PC) signature.
  95. // Signature Element.
  96. static const unsigned kDxilSignatureElementNumFields = 11;
  97. static const unsigned kDxilSignatureElementID = 0; // Unique element ID.
  98. static const unsigned kDxilSignatureElementName = 1; // Element name.
  99. static const unsigned kDxilSignatureElementType = 2; // Element type.
  100. static const unsigned kDxilSignatureElementSystemValue = 3; // Effective system value.
  101. static const unsigned kDxilSignatureElementIndexVector = 4; // Semantic index vector.
  102. static const unsigned kDxilSignatureElementInterpMode = 5; // Interpolation mode.
  103. static const unsigned kDxilSignatureElementRows = 6; // Number of rows.
  104. static const unsigned kDxilSignatureElementCols = 7; // Number of columns.
  105. static const unsigned kDxilSignatureElementStartRow = 8; // Element packing start row.
  106. static const unsigned kDxilSignatureElementStartCol = 9; // Element packing start column.
  107. static const unsigned kDxilSignatureElementNameValueList = 10; // Name-value list for extended properties.
  108. // Signature Element Extended Properties.
  109. static const unsigned kDxilSignatureElementOutputStreamTag = 0;
  110. static const unsigned kHLSignatureElementGlobalSymbolTag = 1;
  111. static const unsigned kDxilSignatureElementDynIdxCompMaskTag = 2;
  112. // Resources.
  113. static const char kDxilResourcesMDName[];
  114. static const unsigned kDxilNumResourceFields = 4;
  115. static const unsigned kDxilResourceSRVs = 0;
  116. static const unsigned kDxilResourceUAVs = 1;
  117. static const unsigned kDxilResourceCBuffers = 2;
  118. static const unsigned kDxilResourceSamplers = 3;
  119. // ResourceBase.
  120. static const unsigned kDxilResourceBaseNumFields = 6;
  121. static const unsigned kDxilResourceBaseID = 0; // Unique (per type) resource ID.
  122. static const unsigned kDxilResourceBaseVariable = 1; // Resource global variable.
  123. static const unsigned kDxilResourceBaseName = 2; // Original (HLSL) name of the resource.
  124. static const unsigned kDxilResourceBaseSpaceID = 3; // Resource range space ID.
  125. static const unsigned kDxilResourceBaseLowerBound = 4; // Resource range lower bound.
  126. static const unsigned kDxilResourceBaseRangeSize = 5; // Resource range size.
  127. // SRV-specific.
  128. static const unsigned kDxilSRVNumFields = 9;
  129. static const unsigned kDxilSRVShape = 6; // SRV shape.
  130. static const unsigned kDxilSRVSampleCount = 7; // SRV sample count.
  131. static const unsigned kDxilSRVNameValueList = 8; // Name-value list for extended properties.
  132. // UAV-specific.
  133. static const unsigned kDxilUAVNumFields = 11;
  134. static const unsigned kDxilUAVShape = 6; // UAV shape.
  135. static const unsigned kDxilUAVGloballyCoherent = 7; // Globally-coherent UAV.
  136. static const unsigned kDxilUAVCounter = 8; // UAV with a counter.
  137. static const unsigned kDxilUAVRasterizerOrderedView = 9; // UAV that is a ROV.
  138. static const unsigned kDxilUAVNameValueList = 10; // Name-value list for extended properties.
  139. // CBuffer-specific.
  140. static const unsigned kDxilCBufferNumFields = 8;
  141. static const unsigned kDxilCBufferSizeInBytes = 6; // CBuffer size in bytes.
  142. static const unsigned kDxilCBufferNameValueList = 7; // Name-value list for extended properties.
  143. // CBuffer extended properties
  144. static const unsigned kHLCBufferIsTBufferTag = 0; // CBuffer is actually TBuffer, not yet converted to SRV.
  145. // Sampler-specific.
  146. static const unsigned kDxilSamplerNumFields = 8;
  147. static const unsigned kDxilSamplerType = 6; // Sampler type.
  148. static const unsigned kDxilSamplerNameValueList = 7; // Name-value list for extended properties.
  149. // Resource extended property tags.
  150. static const unsigned kDxilTypedBufferElementTypeTag = 0;
  151. static const unsigned kDxilStructuredBufferElementStrideTag = 1;
  152. // Type system.
  153. static const char kDxilTypeSystemMDName[];
  154. static const char kDxilTypeSystemHelperVariablePrefix[];
  155. static const unsigned kDxilTypeSystemStructTag = 0;
  156. static const unsigned kDxilTypeSystemFunctionTag = 1;
  157. static const unsigned kDxilFieldAnnotationSNormTag = 0;
  158. static const unsigned kDxilFieldAnnotationUNormTag = 1;
  159. static const unsigned kDxilFieldAnnotationMatrixTag = 2;
  160. static const unsigned kDxilFieldAnnotationCBufferOffsetTag = 3;
  161. static const unsigned kDxilFieldAnnotationSemanticStringTag = 4;
  162. static const unsigned kDxilFieldAnnotationInterpolationModeTag = 5;
  163. static const unsigned kDxilFieldAnnotationFieldNameTag = 6;
  164. static const unsigned kDxilFieldAnnotationCompTypeTag = 7;
  165. static const unsigned kDxilFieldAnnotationPreciseTag = 8;
  166. // Control flow hint.
  167. static const char kDxilControlFlowHintMDName[];
  168. // Resource attribute.
  169. static const char kHLDxilResourceAttributeMDName[];
  170. static const unsigned kHLDxilResourceAttributeNumFields = 2;
  171. static const unsigned kHLDxilResourceAttributeClass = 0;
  172. static const unsigned kHLDxilResourceAttributeMeta = 1;
  173. // Precise attribute.
  174. static const char kDxilPreciseAttributeMDName[];
  175. // NonUniform attribute.
  176. static const char kDxilNonUniformAttributeMDName[];
  177. // Validator version.
  178. static const char kDxilValidatorVersionMDName[];
  179. // Validator version uses the same constants for fields as kDxilVersion*
  180. // Extended shader property tags.
  181. static const unsigned kDxilShaderFlagsTag = 0;
  182. static const unsigned kDxilGSStateTag = 1;
  183. static const unsigned kDxilDSStateTag = 2;
  184. static const unsigned kDxilHSStateTag = 3;
  185. static const unsigned kDxilNumThreadsTag = 4;
  186. static const unsigned kDxilAutoBindingSpaceTag = 5;
  187. static const unsigned kDxilRayPayloadSizeTag = 6;
  188. static const unsigned kDxilRayAttribSizeTag = 7;
  189. static const unsigned kDxilShaderKindTag = 8;
  190. // GSState.
  191. static const unsigned kDxilGSStateNumFields = 5;
  192. static const unsigned kDxilGSStateInputPrimitive = 0;
  193. static const unsigned kDxilGSStateMaxVertexCount = 1;
  194. static const unsigned kDxilGSStateActiveStreamMask = 2;
  195. static const unsigned kDxilGSStateOutputStreamTopology = 3;
  196. static const unsigned kDxilGSStateGSInstanceCount = 4;
  197. // DSState.
  198. static const unsigned kDxilDSStateNumFields = 2;
  199. static const unsigned kDxilDSStateTessellatorDomain = 0;
  200. static const unsigned kDxilDSStateInputControlPointCount = 1;
  201. // HSState.
  202. static const unsigned kDxilHSStateNumFields = 7;
  203. static const unsigned kDxilHSStatePatchConstantFunction = 0;
  204. static const unsigned kDxilHSStateInputControlPointCount = 1;
  205. static const unsigned kDxilHSStateOutputControlPointCount = 2;
  206. static const unsigned kDxilHSStateTessellatorDomain = 3;
  207. static const unsigned kDxilHSStateTessellatorPartitioning = 4;
  208. static const unsigned kDxilHSStateTessellatorOutputPrimitive= 5;
  209. static const unsigned kDxilHSStateMaxTessellationFactor = 6;
  210. public:
  211. /// Use this class to manipulate metadata of DXIL or high-level DX IR specific fields in the record.
  212. class ExtraPropertyHelper {
  213. public:
  214. ExtraPropertyHelper(llvm::Module *pModule);
  215. virtual ~ExtraPropertyHelper() {}
  216. virtual void EmitSRVProperties(const DxilResource &SRV, std::vector<llvm::Metadata *> &MDVals) = 0;
  217. virtual void LoadSRVProperties(const llvm::MDOperand &MDO, DxilResource &SRV) = 0;
  218. virtual void EmitUAVProperties(const DxilResource &UAV, std::vector<llvm::Metadata *> &MDVals) = 0;
  219. virtual void LoadUAVProperties(const llvm::MDOperand &MDO, DxilResource &UAV) = 0;
  220. virtual void EmitCBufferProperties(const DxilCBuffer &CB, std::vector<llvm::Metadata *> &MDVals) = 0;
  221. virtual void LoadCBufferProperties(const llvm::MDOperand &MDO, DxilCBuffer &CB) = 0;
  222. virtual void EmitSamplerProperties(const DxilSampler &S, std::vector<llvm::Metadata *> &MDVals) = 0;
  223. virtual void LoadSamplerProperties(const llvm::MDOperand &MDO, DxilSampler &S) = 0;
  224. virtual void EmitSignatureElementProperties(const DxilSignatureElement &SE, std::vector<llvm::Metadata *> &MDVals) = 0;
  225. virtual void LoadSignatureElementProperties(const llvm::MDOperand &MDO, DxilSignatureElement &SE) = 0;
  226. protected:
  227. llvm::LLVMContext &m_Ctx;
  228. llvm::Module *m_pModule;
  229. };
  230. public:
  231. DxilMDHelper(llvm::Module *pModule, std::unique_ptr<ExtraPropertyHelper> EPH);
  232. ~DxilMDHelper();
  233. void SetShaderModel(const ShaderModel *pSM);
  234. const ShaderModel *GetShaderModel() const;
  235. // Dxil version.
  236. void EmitDxilVersion(unsigned Major, unsigned Minor);
  237. void LoadDxilVersion(unsigned &Major, unsigned &Minor);
  238. // Validator version.
  239. void EmitValidatorVersion(unsigned Major, unsigned Minor);
  240. void LoadValidatorVersion(unsigned &Major, unsigned &Minor);
  241. // Shader model.
  242. void EmitDxilShaderModel(const ShaderModel *pSM);
  243. void LoadDxilShaderModel(const ShaderModel *&pSM);
  244. // Intermediate flags
  245. void EmitDxilIntermediateOptions(uint32_t flags);
  246. void LoadDxilIntermediateOptions(uint32_t &flags);
  247. // Entry points.
  248. void EmitDxilEntryPoints(std::vector<llvm::MDNode *> &MDEntries);
  249. void UpdateDxilEntryPoints(std::vector<llvm::MDNode *> &MDEntries);
  250. const llvm::NamedMDNode *GetDxilEntryPoints();
  251. llvm::MDTuple *EmitDxilEntryPointTuple(llvm::Function *pFunc, const std::string &Name, llvm::MDTuple *pSignatures,
  252. llvm::MDTuple *pResources, llvm::MDTuple *pProperties);
  253. void GetDxilEntryPoint(const llvm::MDNode *MDO, llvm::Function *&pFunc, std::string &Name,
  254. const llvm::MDOperand *&pSignatures, const llvm::MDOperand *&pResources,
  255. const llvm::MDOperand *&pProperties);
  256. // Signatures.
  257. llvm::MDTuple *EmitDxilSignatures(const DxilEntrySignature &EntrySig);
  258. void LoadDxilSignatures(const llvm::MDOperand &MDO,
  259. DxilEntrySignature &EntrySig);
  260. llvm::MDTuple *EmitSignatureMetadata(const DxilSignature &Sig);
  261. void EmitRootSignature(std::vector<uint8_t> &SerializedRootSignature);
  262. void LoadSignatureMetadata(const llvm::MDOperand &MDO, DxilSignature &Sig);
  263. llvm::MDTuple *EmitSignatureElement(const DxilSignatureElement &SE);
  264. void LoadSignatureElement(const llvm::MDOperand &MDO, DxilSignatureElement &SE);
  265. void LoadRootSignature(std::vector<uint8_t> &SerializedRootSignature);
  266. // Resources.
  267. llvm::MDTuple *EmitDxilResourceTuple(llvm::MDTuple *pSRVs, llvm::MDTuple *pUAVs,
  268. llvm::MDTuple *pCBuffers, llvm::MDTuple *pSamplers);
  269. void EmitDxilResources(llvm::MDTuple *pDxilResourceTuple);
  270. void UpdateDxilResources(llvm::MDTuple *pDxilResourceTuple);
  271. void GetDxilResources(const llvm::MDOperand &MDO, const llvm::MDTuple *&pSRVs, const llvm::MDTuple *&pUAVs,
  272. const llvm::MDTuple *&pCBuffers, const llvm::MDTuple *&pSamplers);
  273. void EmitDxilResourceBase(const DxilResourceBase &R, llvm::Metadata *ppMDVals[]);
  274. void LoadDxilResourceBase(const llvm::MDOperand &MDO, DxilResourceBase &R);
  275. llvm::MDTuple *EmitDxilSRV(const DxilResource &SRV);
  276. void LoadDxilSRV(const llvm::MDOperand &MDO, DxilResource &SRV);
  277. llvm::MDTuple *EmitDxilUAV(const DxilResource &UAV);
  278. void LoadDxilUAV(const llvm::MDOperand &MDO, DxilResource &UAV);
  279. llvm::MDTuple *EmitDxilCBuffer(const DxilCBuffer &CB);
  280. void LoadDxilCBuffer(const llvm::MDOperand &MDO, DxilCBuffer &CB);
  281. llvm::MDTuple *EmitDxilSampler(const DxilSampler &S);
  282. void LoadDxilSampler(const llvm::MDOperand &MDO, DxilSampler &S);
  283. const llvm::MDOperand &GetResourceClass(llvm::MDNode *MD, DXIL::ResourceClass &RC);
  284. void LoadDxilResourceBaseFromMDNode(llvm::MDNode *MD, DxilResourceBase &R);
  285. void LoadDxilResourceFromMDNode(llvm::MDNode *MD, DxilResource &R);
  286. void LoadDxilSamplerFromMDNode(llvm::MDNode *MD, DxilSampler &S);
  287. // Type system.
  288. void EmitDxilTypeSystem(DxilTypeSystem &TypeSystem, std::vector<llvm::GlobalVariable *> &LLVMUsed);
  289. void LoadDxilTypeSystemNode(const llvm::MDTuple &MDT, DxilTypeSystem &TypeSystem);
  290. void LoadDxilTypeSystem(DxilTypeSystem &TypeSystem);
  291. llvm::Metadata *EmitDxilStructAnnotation(const DxilStructAnnotation &SA);
  292. void LoadDxilStructAnnotation(const llvm::MDOperand &MDO, DxilStructAnnotation &SA);
  293. llvm::Metadata *EmitDxilFieldAnnotation(const DxilFieldAnnotation &FA);
  294. void LoadDxilFieldAnnotation(const llvm::MDOperand &MDO, DxilFieldAnnotation &FA);
  295. llvm::Metadata *EmitDxilFunctionAnnotation(const DxilFunctionAnnotation &FA);
  296. void LoadDxilFunctionAnnotation(const llvm::MDOperand &MDO, DxilFunctionAnnotation &FA);
  297. llvm::Metadata *EmitDxilParamAnnotation(const DxilParameterAnnotation &PA);
  298. void LoadDxilParamAnnotation(const llvm::MDOperand &MDO, DxilParameterAnnotation &PA);
  299. llvm::Metadata *EmitDxilParamAnnotations(const DxilFunctionAnnotation &FA);
  300. void LoadDxilParamAnnotations(const llvm::MDOperand &MDO, DxilFunctionAnnotation &FA);
  301. // Function props.
  302. llvm::MDTuple *EmitDxilFunctionProps(const hlsl::DxilFunctionProps *props,
  303. const llvm::Function *F);
  304. const llvm::Function *LoadDxilFunctionProps(const llvm::MDTuple *pProps,
  305. hlsl::DxilFunctionProps *props);
  306. llvm::MDTuple *EmitDxilEntryProperties(uint64_t rawShaderFlag,
  307. const hlsl::DxilFunctionProps &props,
  308. uint32_t autoBindingSpace);
  309. void LoadDxilEntryProperties(const llvm::MDOperand &MDO,
  310. uint64_t &rawShaderFlag,
  311. hlsl::DxilFunctionProps &props,
  312. uint32_t &autoBindingSpace);
  313. // ViewId state.
  314. void EmitDxilViewIdState(std::vector<unsigned> &SerializedState);
  315. void LoadDxilViewIdState(std::vector<unsigned> &SerializedState);
  316. // Control flow hints.
  317. static llvm::MDNode *EmitControlFlowHints(llvm::LLVMContext &Ctx, std::vector<DXIL::ControlFlowHint> &hints);
  318. // Subobjects
  319. void EmitSubobjects(const DxilSubobjects &Subobjects);
  320. void LoadSubobjects(DxilSubobjects &Subobjects);
  321. llvm::Metadata *EmitSubobject(const DxilSubobject &obj);
  322. void LoadSubobject(const llvm::MDNode &MDO, DxilSubobjects &Subobjects);
  323. // Shader specific.
  324. private:
  325. llvm::MDTuple *EmitDxilGSState(DXIL::InputPrimitive Primitive, unsigned MaxVertexCount,
  326. unsigned ActiveStreamMask, DXIL::PrimitiveTopology StreamPrimitiveTopology,
  327. unsigned GSInstanceCount);
  328. void LoadDxilGSState(const llvm::MDOperand &MDO, DXIL::InputPrimitive &Primitive, unsigned &MaxVertexCount,
  329. unsigned &ActiveStreamMask, DXIL::PrimitiveTopology &StreamPrimitiveTopology,
  330. unsigned &GSInstanceCount);
  331. llvm::MDTuple *EmitDxilDSState(DXIL::TessellatorDomain Domain, unsigned InputControlPointCount);
  332. void LoadDxilDSState(const llvm::MDOperand &MDO, DXIL::TessellatorDomain &Domain, unsigned &InputControlPointCount);
  333. llvm::MDTuple *EmitDxilHSState(llvm::Function *pPatchConstantFunction,
  334. unsigned InputControlPointCount,
  335. unsigned OutputControlPointCount,
  336. DXIL::TessellatorDomain TessDomain,
  337. DXIL::TessellatorPartitioning TessPartitioning,
  338. DXIL::TessellatorOutputPrimitive TessOutputPrimitive,
  339. float MaxTessFactor);
  340. void LoadDxilHSState(const llvm::MDOperand &MDO,
  341. llvm::Function *&pPatchConstantFunction,
  342. unsigned &InputControlPointCount,
  343. unsigned &OutputControlPointCount,
  344. DXIL::TessellatorDomain &TessDomain,
  345. DXIL::TessellatorPartitioning &TessPartitioning,
  346. DXIL::TessellatorOutputPrimitive &TessOutputPrimitive,
  347. float &MaxTessFactor);
  348. public:
  349. // Utility functions.
  350. static bool IsKnownNamedMetaData(const llvm::NamedMDNode &Node);
  351. static void combineDxilMetadata(llvm::Instruction *K, const llvm::Instruction *J);
  352. static llvm::ConstantAsMetadata *Int32ToConstMD(int32_t v, llvm::LLVMContext &Ctx);
  353. llvm::ConstantAsMetadata *Int32ToConstMD(int32_t v);
  354. static llvm::ConstantAsMetadata *Uint32ToConstMD(unsigned v, llvm::LLVMContext &Ctx);
  355. llvm::ConstantAsMetadata *Uint32ToConstMD(unsigned v);
  356. static llvm::ConstantAsMetadata *Uint64ToConstMD(uint64_t v, llvm::LLVMContext &Ctx);
  357. llvm::ConstantAsMetadata *Uint64ToConstMD(uint64_t v);
  358. llvm::ConstantAsMetadata *Int8ToConstMD(int8_t v);
  359. llvm::ConstantAsMetadata *Uint8ToConstMD(uint8_t v);
  360. static llvm::ConstantAsMetadata *BoolToConstMD(bool v, llvm::LLVMContext &Ctx);
  361. llvm::ConstantAsMetadata *BoolToConstMD(bool v);
  362. llvm::ConstantAsMetadata *FloatToConstMD(float v);
  363. static int32_t ConstMDToInt32(const llvm::MDOperand &MDO);
  364. static unsigned ConstMDToUint32(const llvm::MDOperand &MDO);
  365. static uint64_t ConstMDToUint64(const llvm::MDOperand &MDO);
  366. static int8_t ConstMDToInt8(const llvm::MDOperand &MDO);
  367. static uint8_t ConstMDToUint8(const llvm::MDOperand &MDO);
  368. static bool ConstMDToBool(const llvm::MDOperand &MDO);
  369. static float ConstMDToFloat(const llvm::MDOperand &MDO);
  370. static std::string StringMDToString(const llvm::MDOperand &MDO);
  371. static llvm::StringRef StringMDToStringRef(const llvm::MDOperand &MDO);
  372. static llvm::Value *ValueMDToValue(const llvm::MDOperand &MDO);
  373. llvm::MDTuple *Uint32VectorToConstMDTuple(const std::vector<unsigned> &Vec);
  374. void ConstMDTupleToUint32Vector(llvm::MDTuple *pTupleMD, std::vector<unsigned> &Vec);
  375. static bool IsMarkedPrecise(const llvm::Instruction *inst);
  376. static void MarkPrecise(llvm::Instruction *inst);
  377. static bool IsMarkedNonUniform(const llvm::Instruction *inst);
  378. static void MarkNonUniform(llvm::Instruction *inst);
  379. private:
  380. llvm::LLVMContext &m_Ctx;
  381. llvm::Module *m_pModule;
  382. const ShaderModel *m_pSM;
  383. std::unique_ptr<ExtraPropertyHelper> m_ExtraPropertyHelper;
  384. };
  385. /// Use this class to manipulate metadata of extra metadata record properties that are specific to DXIL.
  386. class DxilExtraPropertyHelper : public DxilMDHelper::ExtraPropertyHelper {
  387. public:
  388. DxilExtraPropertyHelper(llvm::Module *pModule);
  389. virtual ~DxilExtraPropertyHelper() {}
  390. virtual void EmitSRVProperties(const DxilResource &SRV, std::vector<llvm::Metadata *> &MDVals);
  391. virtual void LoadSRVProperties(const llvm::MDOperand &MDO, DxilResource &SRV);
  392. virtual void EmitUAVProperties(const DxilResource &UAV, std::vector<llvm::Metadata *> &MDVals);
  393. virtual void LoadUAVProperties(const llvm::MDOperand &MDO, DxilResource &UAV);
  394. virtual void EmitCBufferProperties(const DxilCBuffer &CB, std::vector<llvm::Metadata *> &MDVals);
  395. virtual void LoadCBufferProperties(const llvm::MDOperand &MDO, DxilCBuffer &CB);
  396. virtual void EmitSamplerProperties(const DxilSampler &S, std::vector<llvm::Metadata *> &MDVals);
  397. virtual void LoadSamplerProperties(const llvm::MDOperand &MDO, DxilSampler &S);
  398. virtual void EmitSignatureElementProperties(const DxilSignatureElement &SE, std::vector<llvm::Metadata *> &MDVals);
  399. virtual void LoadSignatureElementProperties(const llvm::MDOperand &MDO, DxilSignatureElement &SE);
  400. };
  401. } // namespace hlsl