DxilMetadataHelper.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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. // Function props.
  73. static const char kDxilFunctionPropertiesMDName[];
  74. static const char kDxilEntrySignaturesMDName[];
  75. static const unsigned kDxilEntryPointNumFields = 5;
  76. static const unsigned kDxilEntryPointFunction = 0; // Entry point function symbol.
  77. static const unsigned kDxilEntryPointName = 1; // Entry point unmangled name.
  78. static const unsigned kDxilEntryPointSignatures = 2; // Entry point signature tuple.
  79. static const unsigned kDxilEntryPointResources = 3; // Entry point resource tuple.
  80. static const unsigned kDxilEntryPointProperties = 4; // Entry point properties tuple.
  81. // Signatures.
  82. static const unsigned kDxilNumSignatureFields = 3;
  83. static const unsigned kDxilInputSignature = 0; // Shader input signature.
  84. static const unsigned kDxilOutputSignature = 1; // Shader output signature.
  85. static const unsigned kDxilPatchConstantSignature = 2; // Shader patch constant (PC) signature.
  86. // Signature Element.
  87. static const unsigned kDxilSignatureElementNumFields = 11;
  88. static const unsigned kDxilSignatureElementID = 0; // Unique element ID.
  89. static const unsigned kDxilSignatureElementName = 1; // Element name.
  90. static const unsigned kDxilSignatureElementType = 2; // Element type.
  91. static const unsigned kDxilSignatureElementSystemValue = 3; // Effective system value.
  92. static const unsigned kDxilSignatureElementIndexVector = 4; // Semantic index vector.
  93. static const unsigned kDxilSignatureElementInterpMode = 5; // Interpolation mode.
  94. static const unsigned kDxilSignatureElementRows = 6; // Number of rows.
  95. static const unsigned kDxilSignatureElementCols = 7; // Number of columns.
  96. static const unsigned kDxilSignatureElementStartRow = 8; // Element packing start row.
  97. static const unsigned kDxilSignatureElementStartCol = 9; // Element packing start column.
  98. static const unsigned kDxilSignatureElementNameValueList = 10; // Name-value list for extended properties.
  99. // Signature Element Extended Properties.
  100. static const unsigned kDxilSignatureElementOutputStreamTag = 0;
  101. static const unsigned kHLSignatureElementGlobalSymbolTag = 1;
  102. static const unsigned kDxilSignatureElementDynIdxCompMaskTag = 2;
  103. // Resources.
  104. static const char kDxilResourcesMDName[];
  105. static const char kDxilResourcesLinkInfoMDName[];
  106. static const unsigned kDxilNumResourceFields = 4;
  107. static const unsigned kDxilResourceSRVs = 0;
  108. static const unsigned kDxilResourceUAVs = 1;
  109. static const unsigned kDxilResourceCBuffers = 2;
  110. static const unsigned kDxilResourceSamplers = 3;
  111. // ResourceBase.
  112. static const unsigned kDxilResourceBaseNumFields = 6;
  113. static const unsigned kDxilResourceBaseID = 0; // Unique (per type) resource ID.
  114. static const unsigned kDxilResourceBaseVariable = 1; // Resource global variable.
  115. static const unsigned kDxilResourceBaseName = 2; // Original (HLSL) name of the resource.
  116. static const unsigned kDxilResourceBaseSpaceID = 3; // Resource range space ID.
  117. static const unsigned kDxilResourceBaseLowerBound = 4; // Resource range lower bound.
  118. static const unsigned kDxilResourceBaseRangeSize = 5; // Resource range size.
  119. // SRV-specific.
  120. static const unsigned kDxilSRVNumFields = 9;
  121. static const unsigned kDxilSRVShape = 6; // SRV shape.
  122. static const unsigned kDxilSRVSampleCount = 7; // SRV sample count.
  123. static const unsigned kDxilSRVNameValueList = 8; // Name-value list for extended properties.
  124. // UAV-specific.
  125. static const unsigned kDxilUAVNumFields = 11;
  126. static const unsigned kDxilUAVShape = 6; // UAV shape.
  127. static const unsigned kDxilUAVGloballyCoherent = 7; // Globally-coherent UAV.
  128. static const unsigned kDxilUAVCounter = 8; // UAV with a counter.
  129. static const unsigned kDxilUAVRasterizerOrderedView = 9; // UAV that is a ROV.
  130. static const unsigned kDxilUAVNameValueList = 10; // Name-value list for extended properties.
  131. // CBuffer-specific.
  132. static const unsigned kDxilCBufferNumFields = 8;
  133. static const unsigned kDxilCBufferSizeInBytes = 6; // CBuffer size in bytes.
  134. static const unsigned kDxilCBufferNameValueList = 7; // Name-value list for extended properties.
  135. // CBuffer extended properties
  136. static const unsigned kHLCBufferIsTBufferTag = 0; // CBuffer is actually TBuffer, not yet converted to SRV.
  137. // Sampler-specific.
  138. static const unsigned kDxilSamplerNumFields = 8;
  139. static const unsigned kDxilSamplerType = 6; // Sampler type.
  140. static const unsigned kDxilSamplerNameValueList = 7; // Name-value list for extended properties.
  141. // Resource extended property tags.
  142. static const unsigned kDxilTypedBufferElementTypeTag = 0;
  143. static const unsigned kDxilStructuredBufferElementStrideTag = 1;
  144. // Type system.
  145. static const char kDxilTypeSystemMDName[];
  146. static const char kDxilTypeSystemHelperVariablePrefix[];
  147. static const unsigned kDxilTypeSystemStructTag = 0;
  148. static const unsigned kDxilTypeSystemFunctionTag = 1;
  149. static const unsigned kDxilFieldAnnotationSNormTag = 0;
  150. static const unsigned kDxilFieldAnnotationUNormTag = 1;
  151. static const unsigned kDxilFieldAnnotationMatrixTag = 2;
  152. static const unsigned kDxilFieldAnnotationCBufferOffsetTag = 3;
  153. static const unsigned kDxilFieldAnnotationSemanticStringTag = 4;
  154. static const unsigned kDxilFieldAnnotationInterpolationModeTag = 5;
  155. static const unsigned kDxilFieldAnnotationFieldNameTag = 6;
  156. static const unsigned kDxilFieldAnnotationCompTypeTag = 7;
  157. static const unsigned kDxilFieldAnnotationPreciseTag = 8;
  158. // Control flow hint.
  159. static const char kDxilControlFlowHintMDName[];
  160. // Resource attribute.
  161. static const char kHLDxilResourceAttributeMDName[];
  162. static const unsigned kHLDxilResourceAttributeNumFields = 2;
  163. static const unsigned kHLDxilResourceAttributeClass = 0;
  164. static const unsigned kHLDxilResourceAttributeMeta = 1;
  165. // Precise attribute.
  166. static const char kDxilPreciseAttributeMDName[];
  167. // Validator version.
  168. static const char kDxilValidatorVersionMDName[];
  169. // Validator version uses the same constants for fields as kDxilVersion*
  170. // Extended shader property tags.
  171. static const unsigned kDxilShaderFlagsTag = 0;
  172. static const unsigned kDxilGSStateTag = 1;
  173. static const unsigned kDxilDSStateTag = 2;
  174. static const unsigned kDxilHSStateTag = 3;
  175. static const unsigned kDxilNumThreadsTag = 4;
  176. // GSState.
  177. static const unsigned kDxilGSStateNumFields = 5;
  178. static const unsigned kDxilGSStateInputPrimitive = 0;
  179. static const unsigned kDxilGSStateMaxVertexCount = 1;
  180. static const unsigned kDxilGSStateActiveStreamMask = 2;
  181. static const unsigned kDxilGSStateOutputStreamTopology = 3;
  182. static const unsigned kDxilGSStateGSInstanceCount = 4;
  183. // DSState.
  184. static const unsigned kDxilDSStateNumFields = 2;
  185. static const unsigned kDxilDSStateTessellatorDomain = 0;
  186. static const unsigned kDxilDSStateInputControlPointCount = 1;
  187. // HSState.
  188. static const unsigned kDxilHSStateNumFields = 7;
  189. static const unsigned kDxilHSStatePatchConstantFunction = 0;
  190. static const unsigned kDxilHSStateInputControlPointCount = 1;
  191. static const unsigned kDxilHSStateOutputControlPointCount = 2;
  192. static const unsigned kDxilHSStateTessellatorDomain = 3;
  193. static const unsigned kDxilHSStateTessellatorPartitioning = 4;
  194. static const unsigned kDxilHSStateTessellatorOutputPrimitive= 5;
  195. static const unsigned kDxilHSStateMaxTessellationFactor = 6;
  196. public:
  197. /// Use this class to manipulate metadata of DXIL or high-level DX IR specific fields in the record.
  198. class ExtraPropertyHelper {
  199. public:
  200. ExtraPropertyHelper(llvm::Module *pModule);
  201. virtual ~ExtraPropertyHelper() {}
  202. virtual void EmitSRVProperties(const DxilResource &SRV, std::vector<llvm::Metadata *> &MDVals) = 0;
  203. virtual void LoadSRVProperties(const llvm::MDOperand &MDO, DxilResource &SRV) = 0;
  204. virtual void EmitUAVProperties(const DxilResource &UAV, std::vector<llvm::Metadata *> &MDVals) = 0;
  205. virtual void LoadUAVProperties(const llvm::MDOperand &MDO, DxilResource &UAV) = 0;
  206. virtual void EmitCBufferProperties(const DxilCBuffer &CB, std::vector<llvm::Metadata *> &MDVals) = 0;
  207. virtual void LoadCBufferProperties(const llvm::MDOperand &MDO, DxilCBuffer &CB) = 0;
  208. virtual void EmitSamplerProperties(const DxilSampler &S, std::vector<llvm::Metadata *> &MDVals) = 0;
  209. virtual void LoadSamplerProperties(const llvm::MDOperand &MDO, DxilSampler &S) = 0;
  210. virtual void EmitSignatureElementProperties(const DxilSignatureElement &SE, std::vector<llvm::Metadata *> &MDVals) = 0;
  211. virtual void LoadSignatureElementProperties(const llvm::MDOperand &MDO, DxilSignatureElement &SE) = 0;
  212. protected:
  213. llvm::LLVMContext &m_Ctx;
  214. llvm::Module *m_pModule;
  215. };
  216. public:
  217. DxilMDHelper(llvm::Module *pModule, std::unique_ptr<ExtraPropertyHelper> EPH);
  218. ~DxilMDHelper();
  219. void SetShaderModel(const ShaderModel *pSM);
  220. const ShaderModel *GetShaderModel() const;
  221. // Dxil version.
  222. void EmitDxilVersion(unsigned Major, unsigned Minor);
  223. void LoadDxilVersion(unsigned &Major, unsigned &Minor);
  224. // Validator version.
  225. void EmitValidatorVersion(unsigned Major, unsigned Minor);
  226. void LoadValidatorVersion(unsigned &Major, unsigned &Minor);
  227. // Shader model.
  228. void EmitDxilShaderModel(const ShaderModel *pSM);
  229. void LoadDxilShaderModel(const ShaderModel *&pSM);
  230. // Entry points.
  231. void EmitDxilEntryPoints(std::vector<llvm::MDNode *> &MDEntries);
  232. void UpdateDxilEntryPoints(std::vector<llvm::MDNode *> &MDEntries);
  233. const llvm::NamedMDNode *GetDxilEntryPoints();
  234. llvm::MDTuple *EmitDxilEntryPointTuple(llvm::Function *pFunc, const std::string &Name, llvm::MDTuple *pSignatures,
  235. llvm::MDTuple *pResources, llvm::MDTuple *pProperties);
  236. void GetDxilEntryPoint(const llvm::MDNode *MDO, llvm::Function *&pFunc, std::string &Name,
  237. const llvm::MDOperand *&pSignatures, const llvm::MDOperand *&pResources,
  238. const llvm::MDOperand *&pProperties);
  239. // Signatures.
  240. llvm::MDTuple *EmitDxilSignatures(const DxilEntrySignature &EntrySig);
  241. void LoadDxilSignatures(const llvm::MDOperand &MDO,
  242. DxilEntrySignature &EntrySig);
  243. llvm::MDTuple *EmitSignatureMetadata(const DxilSignature &Sig);
  244. void EmitRootSignature(RootSignatureHandle &RootSig);
  245. void LoadSignatureMetadata(const llvm::MDOperand &MDO, DxilSignature &Sig);
  246. llvm::MDTuple *EmitSignatureElement(const DxilSignatureElement &SE);
  247. void LoadSignatureElement(const llvm::MDOperand &MDO, DxilSignatureElement &SE);
  248. void LoadRootSignature(RootSignatureHandle &RootSig);
  249. // Resources.
  250. llvm::MDTuple *EmitDxilResourceTuple(llvm::MDTuple *pSRVs, llvm::MDTuple *pUAVs,
  251. llvm::MDTuple *pCBuffers, llvm::MDTuple *pSamplers);
  252. void EmitDxilResources(llvm::MDTuple *pDxilResourceTuple);
  253. void UpdateDxilResources(llvm::MDTuple *pDxilResourceTuple);
  254. void GetDxilResources(const llvm::MDOperand &MDO, const llvm::MDTuple *&pSRVs, const llvm::MDTuple *&pUAVs,
  255. const llvm::MDTuple *&pCBuffers, const llvm::MDTuple *&pSamplers);
  256. void EmitDxilResourceLinkInfoTuple(llvm::MDTuple *pSRVs, llvm::MDTuple *pUAVs,
  257. llvm::MDTuple *pCBuffers,
  258. llvm::MDTuple *pSamplers);
  259. void LoadDxilResourceLinkInfoTuple(const llvm::MDTuple *&pSRVs,
  260. const llvm::MDTuple *&pUAVs,
  261. const llvm::MDTuple *&pCBuffers,
  262. 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. llvm::Function *F);
  294. llvm::Function *LoadDxilFunctionProps(llvm::MDTuple *pProps,
  295. hlsl::DxilFunctionProps *props);
  296. // ViewId state.
  297. void EmitDxilViewIdState(DxilViewIdState &ViewIdState);
  298. void LoadDxilViewIdState(DxilViewIdState &ViewIdState);
  299. // Control flow hints.
  300. static llvm::MDNode *EmitControlFlowHints(llvm::LLVMContext &Ctx, std::vector<DXIL::ControlFlowHint> &hints);
  301. // Shader specific.
  302. llvm::MDTuple *EmitDxilGSState(DXIL::InputPrimitive Primitive, unsigned MaxVertexCount,
  303. unsigned ActiveStreamMask, DXIL::PrimitiveTopology StreamPrimitiveTopology,
  304. unsigned GSInstanceCount);
  305. void LoadDxilGSState(const llvm::MDOperand &MDO, DXIL::InputPrimitive &Primitive, unsigned &MaxVertexCount,
  306. unsigned &ActiveStreamMask, DXIL::PrimitiveTopology &StreamPrimitiveTopology,
  307. unsigned &GSInstanceCount);
  308. llvm::MDTuple *EmitDxilDSState(DXIL::TessellatorDomain Domain, unsigned InputControlPointCount);
  309. void LoadDxilDSState(const llvm::MDOperand &MDO, DXIL::TessellatorDomain &Domain, unsigned &InputControlPointCount);
  310. llvm::MDTuple *EmitDxilHSState(llvm::Function *pPatchConstantFunction,
  311. unsigned InputControlPointCount,
  312. unsigned OutputControlPointCount,
  313. DXIL::TessellatorDomain TessDomain,
  314. DXIL::TessellatorPartitioning TessPartitioning,
  315. DXIL::TessellatorOutputPrimitive TessOutputPrimitive,
  316. float MaxTessFactor);
  317. void LoadDxilHSState(const llvm::MDOperand &MDO,
  318. 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. // Utility functions.
  326. static bool IsKnownNamedMetaData(llvm::NamedMDNode &Node);
  327. static llvm::ConstantAsMetadata *Int32ToConstMD(int32_t v, llvm::LLVMContext &Ctx);
  328. llvm::ConstantAsMetadata *Int32ToConstMD(int32_t v);
  329. static llvm::ConstantAsMetadata *Uint32ToConstMD(unsigned v, llvm::LLVMContext &Ctx);
  330. llvm::ConstantAsMetadata *Uint32ToConstMD(unsigned v);
  331. static llvm::ConstantAsMetadata *Uint64ToConstMD(uint64_t v, llvm::LLVMContext &Ctx);
  332. llvm::ConstantAsMetadata *Uint64ToConstMD(uint64_t v);
  333. llvm::ConstantAsMetadata *Int8ToConstMD(int8_t v);
  334. llvm::ConstantAsMetadata *Uint8ToConstMD(uint8_t v);
  335. static llvm::ConstantAsMetadata *BoolToConstMD(bool v, llvm::LLVMContext &Ctx);
  336. llvm::ConstantAsMetadata *BoolToConstMD(bool v);
  337. llvm::ConstantAsMetadata *FloatToConstMD(float v);
  338. static int32_t ConstMDToInt32(const llvm::MDOperand &MDO);
  339. static unsigned ConstMDToUint32(const llvm::MDOperand &MDO);
  340. static uint64_t ConstMDToUint64(const llvm::MDOperand &MDO);
  341. static int8_t ConstMDToInt8(const llvm::MDOperand &MDO);
  342. static uint8_t ConstMDToUint8(const llvm::MDOperand &MDO);
  343. static bool ConstMDToBool(const llvm::MDOperand &MDO);
  344. static float ConstMDToFloat(const llvm::MDOperand &MDO);
  345. static std::string StringMDToString(const llvm::MDOperand &MDO);
  346. static llvm::Value *ValueMDToValue(const llvm::MDOperand &MDO);
  347. llvm::MDTuple *Uint32VectorToConstMDTuple(const std::vector<unsigned> &Vec);
  348. void ConstMDTupleToUint32Vector(llvm::MDTuple *pTupleMD, std::vector<unsigned> &Vec);
  349. static bool IsMarkedPrecise(const llvm::Instruction *inst);
  350. static void MarkPrecise(llvm::Instruction *inst);
  351. private:
  352. llvm::LLVMContext &m_Ctx;
  353. llvm::Module *m_pModule;
  354. const ShaderModel *m_pSM;
  355. std::unique_ptr<ExtraPropertyHelper> m_ExtraPropertyHelper;
  356. };
  357. /// Use this class to manipulate metadata of extra metadata record properties that are specific to DXIL.
  358. class DxilExtraPropertyHelper : public DxilMDHelper::ExtraPropertyHelper {
  359. public:
  360. DxilExtraPropertyHelper(llvm::Module *pModule);
  361. virtual ~DxilExtraPropertyHelper() {}
  362. virtual void EmitSRVProperties(const DxilResource &SRV, std::vector<llvm::Metadata *> &MDVals);
  363. virtual void LoadSRVProperties(const llvm::MDOperand &MDO, DxilResource &SRV);
  364. virtual void EmitUAVProperties(const DxilResource &UAV, std::vector<llvm::Metadata *> &MDVals);
  365. virtual void LoadUAVProperties(const llvm::MDOperand &MDO, DxilResource &UAV);
  366. virtual void EmitCBufferProperties(const DxilCBuffer &CB, std::vector<llvm::Metadata *> &MDVals);
  367. virtual void LoadCBufferProperties(const llvm::MDOperand &MDO, DxilCBuffer &CB);
  368. virtual void EmitSamplerProperties(const DxilSampler &S, std::vector<llvm::Metadata *> &MDVals);
  369. virtual void LoadSamplerProperties(const llvm::MDOperand &MDO, DxilSampler &S);
  370. virtual void EmitSignatureElementProperties(const DxilSignatureElement &SE, std::vector<llvm::Metadata *> &MDVals);
  371. virtual void LoadSignatureElementProperties(const llvm::MDOperand &MDO, DxilSignatureElement &SE);
  372. };
  373. } // namespace hlsl