DxilModule.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // DxilModule.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. // The main class to work with DXIL, similar to LLVM module. //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #pragma once
  12. #include "dxc/HLSL/DxilMetadataHelper.h"
  13. #include "dxc/HLSL/DxilCBuffer.h"
  14. #include "dxc/HLSL/DxilResource.h"
  15. #include "dxc/HLSL/DxilSampler.h"
  16. #include "dxc/HLSL/DxilSignature.h"
  17. #include "dxc/HLSL/DxilConstants.h"
  18. #include "dxc/HLSL/DxilTypeSystem.h"
  19. #include "dxc/HLSL/ComputeViewIdState.h"
  20. #include <memory>
  21. #include <string>
  22. #include <vector>
  23. #include <unordered_map>
  24. namespace llvm {
  25. class LLVMContext;
  26. class Module;
  27. class Function;
  28. class Instruction;
  29. class MDTuple;
  30. class MDOperand;
  31. class DebugInfoFinder;
  32. };
  33. namespace hlsl {
  34. class ShaderModel;
  35. class OP;
  36. class RootSignatureHandle;
  37. struct DxilFunctionProps;
  38. /// Use this class to manipulate DXIL of a shader.
  39. class DxilModule {
  40. public:
  41. DxilModule(llvm::Module *pModule);
  42. ~DxilModule();
  43. // Subsystems.
  44. llvm::LLVMContext &GetCtx() const;
  45. llvm::Module *GetModule() const;
  46. OP *GetOP() const;
  47. void SetShaderModel(const ShaderModel *pSM);
  48. const ShaderModel *GetShaderModel() const;
  49. void GetDxilVersion(unsigned &DxilMajor, unsigned &DxilMinor) const;
  50. void SetValidatorVersion(unsigned ValMajor, unsigned ValMinor);
  51. bool UpgradeValidatorVersion(unsigned ValMajor, unsigned ValMinor);
  52. void GetValidatorVersion(unsigned &ValMajor, unsigned &ValMinor) const;
  53. // Return true on success, requires valid shader model and CollectShaderFlags to have been set
  54. bool GetMinValidatorVersion(unsigned &ValMajor, unsigned &ValMinor) const;
  55. // Update validator version to minimum if higher than current (ex: after CollectShaderFlags)
  56. bool UpgradeToMinValidatorVersion();
  57. // Entry functions.
  58. llvm::Function *GetEntryFunction();
  59. const llvm::Function *GetEntryFunction() const;
  60. void SetEntryFunction(llvm::Function *pEntryFunc);
  61. const std::string &GetEntryFunctionName() const;
  62. void SetEntryFunctionName(const std::string &name);
  63. llvm::Function *GetPatchConstantFunction();
  64. const llvm::Function *GetPatchConstantFunction() const;
  65. void SetPatchConstantFunction(llvm::Function *pFunc);
  66. // Flags.
  67. unsigned GetGlobalFlags() const;
  68. // TODO: move out of DxilModule as a util.
  69. void CollectShaderFlags();
  70. // Resources.
  71. unsigned AddCBuffer(std::unique_ptr<DxilCBuffer> pCB);
  72. DxilCBuffer &GetCBuffer(unsigned idx);
  73. const DxilCBuffer &GetCBuffer(unsigned idx) const;
  74. const std::vector<std::unique_ptr<DxilCBuffer> > &GetCBuffers() const;
  75. unsigned AddSampler(std::unique_ptr<DxilSampler> pSampler);
  76. DxilSampler &GetSampler(unsigned idx);
  77. const DxilSampler &GetSampler(unsigned idx) const;
  78. const std::vector<std::unique_ptr<DxilSampler> > &GetSamplers() const;
  79. unsigned AddSRV(std::unique_ptr<DxilResource> pSRV);
  80. DxilResource &GetSRV(unsigned idx);
  81. const DxilResource &GetSRV(unsigned idx) const;
  82. const std::vector<std::unique_ptr<DxilResource> > &GetSRVs() const;
  83. unsigned AddUAV(std::unique_ptr<DxilResource> pUAV);
  84. DxilResource &GetUAV(unsigned idx);
  85. const DxilResource &GetUAV(unsigned idx) const;
  86. const std::vector<std::unique_ptr<DxilResource> > &GetUAVs() const;
  87. void CreateResourceLinkInfo();
  88. struct ResourceLinkInfo;
  89. const ResourceLinkInfo &GetResourceLinkInfo(DXIL::ResourceClass resClass,
  90. unsigned rangeID) const;
  91. void LoadDxilResourceBaseFromMDNode(llvm::MDNode *MD, DxilResourceBase &R);
  92. void LoadDxilResourceFromMDNode(llvm::MDNode *MD, DxilResource &R);
  93. void LoadDxilSamplerFromMDNode(llvm::MDNode *MD, DxilSampler &S);
  94. void RemoveUnusedResources();
  95. void RemoveFunction(llvm::Function *F);
  96. // Signatures.
  97. DxilSignature &GetInputSignature();
  98. const DxilSignature &GetInputSignature() const;
  99. DxilSignature &GetOutputSignature();
  100. const DxilSignature &GetOutputSignature() const;
  101. DxilSignature &GetPatchConstantSignature();
  102. const DxilSignature &GetPatchConstantSignature() const;
  103. const RootSignatureHandle &GetRootSignature() const;
  104. bool HasDxilEntrySignature(llvm::Function *F) const;
  105. DxilEntrySignature &GetDxilEntrySignature(llvm::Function *F);
  106. // Move DxilEntrySignature of F to NewF.
  107. void ReplaceDxilEntrySignature(llvm::Function *F, llvm::Function *NewF);
  108. // DxilFunctionProps.
  109. bool HasDxilFunctionProps(llvm::Function *F) const;
  110. DxilFunctionProps &GetDxilFunctionProps(llvm::Function *F);
  111. // Move DxilFunctionProps of F to NewF.
  112. void ReplaceDxilFunctionProps(llvm::Function *F, llvm::Function *NewF);
  113. // Remove Root Signature from module metadata
  114. void StripRootSignatureFromMetadata();
  115. // Update validator version metadata to current setting
  116. void UpdateValidatorVersionMetadata();
  117. // DXIL type system.
  118. DxilTypeSystem &GetTypeSystem();
  119. /// Emit llvm.used array to make sure that optimizations do not remove unreferenced globals.
  120. void EmitLLVMUsed();
  121. std::vector<llvm::GlobalVariable* > &GetLLVMUsed();
  122. // ViewId state.
  123. DxilViewIdState &GetViewIdState();
  124. const DxilViewIdState &GetViewIdState() const;
  125. // DXIL metadata manipulation.
  126. /// Serialize DXIL in-memory form to metadata form.
  127. void EmitDxilMetadata();
  128. /// Update resource metadata.
  129. void ReEmitDxilResources();
  130. /// Deserialize DXIL metadata form into in-memory form.
  131. void LoadDxilMetadata();
  132. /// Check if a Named meta data node is known by dxil module.
  133. static bool IsKnownNamedMetaData(llvm::NamedMDNode &Node);
  134. // Reset functions used to transfer ownership.
  135. void ResetEntrySignature(DxilEntrySignature *pValue);
  136. void ResetRootSignature(RootSignatureHandle *pValue);
  137. void ResetTypeSystem(DxilTypeSystem *pValue);
  138. void ResetOP(hlsl::OP *hlslOP);
  139. void ResetFunctionPropsMap(
  140. std::unordered_map<llvm::Function *, std::unique_ptr<DxilFunctionProps>>
  141. &&propsMap);
  142. void ResetEntrySignatureMap(
  143. std::unordered_map<llvm::Function *, std::unique_ptr<DxilEntrySignature>>
  144. &&SigMap);
  145. void StripDebugRelatedCode();
  146. llvm::DebugInfoFinder &GetOrCreateDebugInfoFinder();
  147. static DxilModule *TryGetDxilModule(llvm::Module *pModule);
  148. // Helpers for working with precise.
  149. // Return true if the instruction should be considered precise.
  150. //
  151. // An instruction can be marked precise in the following ways:
  152. //
  153. // 1. Global refactoring is disabled.
  154. // 2. The instruction has a precise metadata annotation.
  155. // 3. The instruction has precise fast math flags set.
  156. //
  157. bool IsPrecise(const llvm::Instruction *inst) const;
  158. // Check if the instruction has fast math flags configured to indicate
  159. // the instruction is precise.
  160. static bool HasPreciseFastMathFlags(const llvm::Instruction *inst);
  161. // Set fast math flags configured to indicate the instruction is precise.
  162. static void SetPreciseFastMathFlags(llvm::Instruction *inst);
  163. // True if fast math flags are preserved across serialize/deserialize.
  164. static bool PreservesFastMathFlags(const llvm::Instruction *inst);
  165. public:
  166. // Shader properties.
  167. class ShaderFlags {
  168. public:
  169. ShaderFlags();
  170. unsigned GetGlobalFlags() const;
  171. void SetDisableOptimizations(bool flag) { m_bDisableOptimizations = flag; }
  172. bool GetDisableOptimizations() const { return m_bDisableOptimizations; }
  173. void SetDisableMathRefactoring(bool flag) { m_bDisableMathRefactoring = flag; }
  174. bool GetDisableMathRefactoring() const { return m_bDisableMathRefactoring; }
  175. void SetEnableDoublePrecision(bool flag) { m_bEnableDoublePrecision = flag; }
  176. bool GetEnableDoublePrecision() const { return m_bEnableDoublePrecision; }
  177. void SetForceEarlyDepthStencil(bool flag) { m_bForceEarlyDepthStencil = flag; }
  178. bool GetForceEarlyDepthStencil() const { return m_bForceEarlyDepthStencil; }
  179. void SetEnableRawAndStructuredBuffers(bool flag) { m_bEnableRawAndStructuredBuffers = flag; }
  180. bool GetEnableRawAndStructuredBuffers() const { return m_bEnableRawAndStructuredBuffers; }
  181. void SetLowPrecisionPresent(bool flag) { m_bLowPrecisionPresent = flag; }
  182. bool GetLowPrecisionPresent() const { return m_bLowPrecisionPresent; }
  183. void SetEnableDoubleExtensions(bool flag) { m_bEnableDoubleExtensions = flag; }
  184. bool GetEnableDoubleExtensions() const { return m_bEnableDoubleExtensions; }
  185. void SetEnableMSAD(bool flag) { m_bEnableMSAD = flag; }
  186. bool GetEnableMSAD() const { return m_bEnableMSAD; }
  187. void SetAllResourcesBound(bool flag) { m_bAllResourcesBound = flag; }
  188. bool GetAllResourcesBound() const { return m_bAllResourcesBound; }
  189. uint64_t GetFeatureInfo() const;
  190. void SetCSRawAndStructuredViaShader4X(bool flag) { m_bCSRawAndStructuredViaShader4X = flag; }
  191. bool GetCSRawAndStructuredViaShader4X() const { return m_bCSRawAndStructuredViaShader4X; }
  192. void SetROVs(bool flag) { m_bROVS = flag; }
  193. bool GetROVs() const { return m_bROVS; }
  194. void SetWaveOps(bool flag) { m_bWaveOps = flag; }
  195. bool GetWaveOps() const { return m_bWaveOps; }
  196. void SetInt64Ops(bool flag) { m_bInt64Ops = flag; }
  197. bool GetInt64Ops() const { return m_bInt64Ops; }
  198. void SetTiledResources(bool flag) { m_bTiledResources = flag; }
  199. bool GetTiledResources() const { return m_bTiledResources; }
  200. void SetStencilRef(bool flag) { m_bStencilRef = flag; }
  201. bool GetStencilRef() const { return m_bStencilRef; }
  202. void SetInnerCoverage(bool flag) { m_bInnerCoverage = flag; }
  203. bool GetInnerCoverage() const { return m_bInnerCoverage; }
  204. void SetViewportAndRTArrayIndex(bool flag) { m_bViewportAndRTArrayIndex = flag; }
  205. bool GetViewportAndRTArrayIndex() const { return m_bViewportAndRTArrayIndex; }
  206. void SetUAVLoadAdditionalFormats(bool flag) { m_bUAVLoadAdditionalFormats = flag; }
  207. bool GetUAVLoadAdditionalFormats() const { return m_bUAVLoadAdditionalFormats; }
  208. void SetLevel9ComparisonFiltering(bool flag) { m_bLevel9ComparisonFiltering = flag; }
  209. bool GetLevel9ComparisonFiltering() const { return m_bLevel9ComparisonFiltering; }
  210. void Set64UAVs(bool flag) { m_b64UAVs = flag; }
  211. bool Get64UAVs() const { return m_b64UAVs; }
  212. void SetUAVsAtEveryStage(bool flag) { m_UAVsAtEveryStage = flag; }
  213. bool GetUAVsAtEveryStage() const { return m_UAVsAtEveryStage; }
  214. void SetViewID(bool flag) { m_bViewID = flag; }
  215. bool GetViewID() const { return m_bViewID; }
  216. void SetBarycentrics(bool flag) { m_bBarycentrics = flag; }
  217. bool GetBarycentrics() const { return m_bBarycentrics; }
  218. void SetUseNativeLowPrecision(bool flag) { m_bUseNativeLowPrecision = flag; }
  219. bool GetUseNativeLowPrecision() const { return m_bUseNativeLowPrecision; }
  220. static uint64_t GetShaderFlagsRawForCollection(); // some flags are collected (eg use 64-bit), some provided (eg allow refactoring)
  221. uint64_t GetShaderFlagsRaw() const;
  222. void SetShaderFlagsRaw(uint64_t data);
  223. private:
  224. unsigned m_bDisableOptimizations :1; // D3D11_1_SB_GLOBAL_FLAG_SKIP_OPTIMIZATION
  225. unsigned m_bDisableMathRefactoring :1; //~D3D10_SB_GLOBAL_FLAG_REFACTORING_ALLOWED
  226. unsigned m_bEnableDoublePrecision :1; // D3D11_SB_GLOBAL_FLAG_ENABLE_DOUBLE_PRECISION_FLOAT_OPS
  227. unsigned m_bForceEarlyDepthStencil :1; // D3D11_SB_GLOBAL_FLAG_FORCE_EARLY_DEPTH_STENCIL
  228. unsigned m_bEnableRawAndStructuredBuffers :1; // D3D11_SB_GLOBAL_FLAG_ENABLE_RAW_AND_STRUCTURED_BUFFERS
  229. unsigned m_bLowPrecisionPresent :1; // D3D11_1_SB_GLOBAL_FLAG_ENABLE_MINIMUM_PRECISION
  230. unsigned m_bEnableDoubleExtensions :1; // D3D11_1_SB_GLOBAL_FLAG_ENABLE_DOUBLE_EXTENSIONS
  231. unsigned m_bEnableMSAD :1; // D3D11_1_SB_GLOBAL_FLAG_ENABLE_SHADER_EXTENSIONS
  232. unsigned m_bAllResourcesBound :1; // D3D12_SB_GLOBAL_FLAG_ALL_RESOURCES_BOUND
  233. unsigned m_bViewportAndRTArrayIndex :1; // SHADER_FEATURE_VIEWPORT_AND_RT_ARRAY_INDEX_FROM_ANY_SHADER_FEEDING_RASTERIZER
  234. unsigned m_bInnerCoverage :1; // SHADER_FEATURE_INNER_COVERAGE
  235. unsigned m_bStencilRef :1; // SHADER_FEATURE_STENCIL_REF
  236. unsigned m_bTiledResources :1; // SHADER_FEATURE_TILED_RESOURCES
  237. unsigned m_bUAVLoadAdditionalFormats :1; // SHADER_FEATURE_TYPED_UAV_LOAD_ADDITIONAL_FORMATS
  238. unsigned m_bLevel9ComparisonFiltering :1; // SHADER_FEATURE_LEVEL_9_COMPARISON_FILTERING
  239. // SHADER_FEATURE_11_1_SHADER_EXTENSIONS shared with EnableMSAD
  240. unsigned m_b64UAVs :1; // SHADER_FEATURE_64_UAVS
  241. unsigned m_UAVsAtEveryStage :1; // SHADER_FEATURE_UAVS_AT_EVERY_STAGE
  242. unsigned m_bCSRawAndStructuredViaShader4X : 1; // SHADER_FEATURE_COMPUTE_SHADERS_PLUS_RAW_AND_STRUCTURED_BUFFERS_VIA_SHADER_4_X
  243. // SHADER_FEATURE_COMPUTE_SHADERS_PLUS_RAW_AND_STRUCTURED_BUFFERS_VIA_SHADER_4_X is specifically
  244. // about shader model 4.x.
  245. unsigned m_bROVS :1; // SHADER_FEATURE_ROVS
  246. unsigned m_bWaveOps :1; // SHADER_FEATURE_WAVE_OPS
  247. unsigned m_bInt64Ops :1; // SHADER_FEATURE_INT64_OPS
  248. unsigned m_bViewID : 1; // SHADER_FEATURE_VIEWID
  249. unsigned m_bBarycentrics : 1; // SHADER_FEATURE_BARYCENTRICS
  250. unsigned m_bUseNativeLowPrecision : 1;
  251. unsigned m_align0 : 8; // align to 32 bit.
  252. uint32_t m_align1; // align to 64 bit.
  253. };
  254. ShaderFlags m_ShaderFlags;
  255. void CollectShaderFlags(ShaderFlags &Flags);
  256. // Check if DxilModule contains multi component UAV Loads.
  257. // This funciton must be called after unused resources are removed from DxilModule
  258. bool ModuleHasMulticomponentUAVLoads();
  259. // Compute shader.
  260. unsigned m_NumThreads[3];
  261. // Geometry shader.
  262. DXIL::InputPrimitive GetInputPrimitive() const;
  263. void SetInputPrimitive(DXIL::InputPrimitive IP);
  264. unsigned GetMaxVertexCount() const;
  265. void SetMaxVertexCount(unsigned Count);
  266. DXIL::PrimitiveTopology GetStreamPrimitiveTopology() const;
  267. void SetStreamPrimitiveTopology(DXIL::PrimitiveTopology Topology);
  268. bool HasMultipleOutputStreams() const;
  269. unsigned GetOutputStream() const;
  270. unsigned GetGSInstanceCount() const;
  271. void SetGSInstanceCount(unsigned Count);
  272. bool IsStreamActive(unsigned Stream) const;
  273. void SetStreamActive(unsigned Stream, bool bActive);
  274. void SetActiveStreamMask(unsigned Mask);
  275. unsigned GetActiveStreamMask() const;
  276. // Hull and Domain shaders.
  277. unsigned GetInputControlPointCount() const;
  278. void SetInputControlPointCount(unsigned NumICPs);
  279. DXIL::TessellatorDomain GetTessellatorDomain() const;
  280. void SetTessellatorDomain(DXIL::TessellatorDomain TessDomain);
  281. // Hull shader.
  282. unsigned GetOutputControlPointCount() const;
  283. void SetOutputControlPointCount(unsigned NumOCPs);
  284. DXIL::TessellatorPartitioning GetTessellatorPartitioning() const;
  285. void SetTessellatorPartitioning(DXIL::TessellatorPartitioning TessPartitioning);
  286. DXIL::TessellatorOutputPrimitive GetTessellatorOutputPrimitive() const;
  287. void SetTessellatorOutputPrimitive(DXIL::TessellatorOutputPrimitive TessOutputPrimitive);
  288. float GetMaxTessellationFactor() const;
  289. void SetMaxTessellationFactor(float MaxTessellationFactor);
  290. void SetShaderProperties(DxilFunctionProps *props);
  291. // Shader resource information only needed before linking.
  292. // Use constant as rangeID for resource in a library.
  293. // When link the library, replace these constants with real rangeID.
  294. struct ResourceLinkInfo {
  295. llvm::Constant *ResRangeID;
  296. };
  297. private:
  298. // Signatures.
  299. std::unique_ptr<DxilEntrySignature> m_EntrySignature;
  300. std::unique_ptr<RootSignatureHandle> m_RootSignature;
  301. // Shader resources.
  302. std::vector<std::unique_ptr<DxilResource> > m_SRVs;
  303. std::vector<std::unique_ptr<DxilResource> > m_UAVs;
  304. std::vector<std::unique_ptr<DxilCBuffer> > m_CBuffers;
  305. std::vector<std::unique_ptr<DxilSampler> > m_Samplers;
  306. // Save resource link for library, when link replace it with real resource ID.
  307. std::vector<ResourceLinkInfo> m_SRVsLinkInfo;
  308. std::vector<ResourceLinkInfo> m_UAVsLinkInfo;
  309. std::vector<ResourceLinkInfo> m_CBuffersLinkInfo;
  310. std::vector<ResourceLinkInfo> m_SamplersLinkInfo;
  311. // Geometry shader.
  312. DXIL::InputPrimitive m_InputPrimitive;
  313. unsigned m_MaxVertexCount;
  314. DXIL::PrimitiveTopology m_StreamPrimitiveTopology;
  315. unsigned m_ActiveStreamMask;
  316. unsigned m_NumGSInstances;
  317. // Hull and Domain shaders.
  318. unsigned m_InputControlPointCount;
  319. DXIL::TessellatorDomain m_TessellatorDomain;
  320. // Hull shader.
  321. unsigned m_OutputControlPointCount;
  322. DXIL::TessellatorPartitioning m_TessellatorPartitioning;
  323. DXIL::TessellatorOutputPrimitive m_TessellatorOutputPrimitive;
  324. float m_MaxTessellationFactor;
  325. private:
  326. llvm::LLVMContext &m_Ctx;
  327. llvm::Module *m_pModule;
  328. llvm::Function *m_pEntryFunc;
  329. llvm::Function *m_pPatchConstantFunc;
  330. std::string m_EntryName;
  331. std::unique_ptr<DxilMDHelper> m_pMDHelper;
  332. std::unique_ptr<llvm::DebugInfoFinder> m_pDebugInfoFinder;
  333. const ShaderModel *m_pSM;
  334. unsigned m_DxilMajor;
  335. unsigned m_DxilMinor;
  336. unsigned m_ValMajor;
  337. unsigned m_ValMinor;
  338. std::unique_ptr<OP> m_pOP;
  339. size_t m_pUnused;
  340. // LLVM used.
  341. std::vector<llvm::GlobalVariable*> m_LLVMUsed;
  342. // Type annotations.
  343. std::unique_ptr<DxilTypeSystem> m_pTypeSystem;
  344. // Function properties for shader functions.
  345. std::unordered_map<llvm::Function *, std::unique_ptr<DxilFunctionProps>>
  346. m_DxilFunctionPropsMap;
  347. // EntrySig for shader functions.
  348. std::unordered_map<llvm::Function *, std::unique_ptr<DxilEntrySignature>>
  349. m_DxilEntrySignatureMap;
  350. // ViewId state.
  351. std::unique_ptr<DxilViewIdState> m_pViewIdState;
  352. // DXIL metadata serialization/deserialization.
  353. llvm::MDTuple *EmitDxilResources();
  354. void LoadDxilResources(const llvm::MDOperand &MDO);
  355. void EmitDxilResourcesLinkInfo();
  356. void LoadDxilResourcesLinkInfo();
  357. llvm::MDTuple *EmitDxilShaderProperties();
  358. void LoadDxilShaderProperties(const llvm::MDOperand &MDO);
  359. // Helpers.
  360. template<typename T> unsigned AddResource(std::vector<std::unique_ptr<T> > &Vec, std::unique_ptr<T> pRes);
  361. void LoadDxilSignature(const llvm::MDTuple *pSigTuple, DxilSignature &Sig, bool bInput);
  362. };
  363. } // namespace hlsl