DxilMetadataHelper.h 23 KB

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