dxcapi.internal.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // dxcapi.internal.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. // Provides non-public declarations for the DirectX Compiler component. //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #ifndef __DXC_API_INTERNAL__
  12. #define __DXC_API_INTERNAL__
  13. #include "dxcapi.h"
  14. ///////////////////////////////////////////////////////////////////////////////
  15. // Forward declarations.
  16. typedef struct ITextFont ITextFont;
  17. typedef struct IEnumSTATSTG IEnumSTATSTG;
  18. typedef struct ID3D10Blob ID3D10Blob;
  19. ///////////////////////////////////////////////////////////////////////////////
  20. // Intrinsic definitions.
  21. #define AR_QUAL_IN 0x0000000000000010ULL
  22. #define AR_QUAL_OUT 0x0000000000000020ULL
  23. #define AR_QUAL_CONST 0x0000000000000200ULL
  24. #define AR_QUAL_ROWMAJOR 0x0000000000000400ULL
  25. #define AR_QUAL_COLMAJOR 0x0000000000000800ULL
  26. #define AR_QUAL_IN_OUT (AR_QUAL_IN | AR_QUAL_OUT)
  27. static const BYTE INTRIN_TEMPLATE_FROM_TYPE = 0xff;
  28. static const BYTE INTRIN_TEMPLATE_VARARGS = 0xfe;
  29. static const BYTE INTRIN_TEMPLATE_FROM_FUNCTION = 0xfd;
  30. // Use this enumeration to describe allowed templates (layouts) in intrinsics.
  31. enum LEGAL_INTRINSIC_TEMPLATES {
  32. LITEMPLATE_VOID = 0, // No return type.
  33. LITEMPLATE_SCALAR = 1, // Scalar types.
  34. LITEMPLATE_VECTOR = 2, // Vector types (eg. float3).
  35. LITEMPLATE_MATRIX = 3, // Matrix types (eg. float3x3).
  36. LITEMPLATE_ANY = 4, // Any one of scalar, vector or matrix types (but not object).
  37. LITEMPLATE_OBJECT = 5, // Object types.
  38. LITEMPLATE_COUNT = 6
  39. };
  40. // INTRIN_COMPTYPE_FROM_TYPE_ELT0 is for object method intrinsics to indicate
  41. // that the component type of the type is taken from the first subelement of the
  42. // object's template type; see for example Texture2D.Gather
  43. static const BYTE INTRIN_COMPTYPE_FROM_TYPE_ELT0 = 0xff;
  44. enum LEGAL_INTRINSIC_COMPTYPES {
  45. LICOMPTYPE_VOID = 0, // void, used for function returns
  46. LICOMPTYPE_BOOL = 1, // bool
  47. LICOMPTYPE_INT = 2, // i32, int-literal
  48. LICOMPTYPE_UINT = 3, // u32, int-literal
  49. LICOMPTYPE_ANY_INT = 4, // i32, u32, i64, u64, int-literal
  50. LICOMPTYPE_ANY_INT32 = 5, // i32, u32, int-literal
  51. LICOMPTYPE_UINT_ONLY = 6, // u32, u64, int-literal; no casts allowed
  52. LICOMPTYPE_FLOAT = 7, // f32, partial-precision-f32, float-literal
  53. LICOMPTYPE_ANY_FLOAT = 8, // f32, partial-precision-f32, f64, float-literal, min10-float, min16-float, half
  54. LICOMPTYPE_FLOAT_LIKE = 9, // f32, partial-precision-f32, float-literal, min10-float, min16-float, half
  55. LICOMPTYPE_FLOAT_DOUBLE = 10, // f32, partial-precision-f32, f64, float-literal
  56. LICOMPTYPE_DOUBLE = 11, // f64, float-literal
  57. LICOMPTYPE_DOUBLE_ONLY = 12, // f64; no casts allowed
  58. LICOMPTYPE_NUMERIC = 13, // float-literal, f32, partial-precision-f32, f64, min10-float, min16-float, int-literal, i32, u32, min12-int, min16-int, min16-uint, i64, u64
  59. LICOMPTYPE_NUMERIC32 = 14, // float-literal, f32, partial-precision-f32, int-literal, i32, u32
  60. LICOMPTYPE_NUMERIC32_ONLY = 15, // float-literal, f32, partial-precision-f32, int-literal, i32, u32; no casts allowed
  61. LICOMPTYPE_ANY = 16, // float-literal, f32, partial-precision-f32, f64, min10-float, min16-float, int-literal, i32, u32, min12-int, min16-int, min16-uint, bool, i64, u64
  62. LICOMPTYPE_SAMPLER1D = 17,
  63. LICOMPTYPE_SAMPLER2D = 18,
  64. LICOMPTYPE_SAMPLER3D = 19,
  65. LICOMPTYPE_SAMPLERCUBE = 20,
  66. LICOMPTYPE_SAMPLERCMP = 21,
  67. LICOMPTYPE_SAMPLER = 22,
  68. LICOMPTYPE_STRING = 23,
  69. LICOMPTYPE_WAVE = 24,
  70. LICOMPTYPE_UINT64 = 25, // u64, int-literal
  71. LICOMPTYPE_FLOAT16 = 26,
  72. LICOMPTYPE_INT16 = 27,
  73. LICOMPTYPE_UINT16 = 28,
  74. LICOMPTYPE_NUMERIC16_ONLY = 29,
  75. LICOMPTYPE_RAYDESC = 30,
  76. LICOMPTYPE_ACCELERATION_STRUCT = 31,
  77. LICOMPTYPE_USER_DEFINED_TYPE = 32,
  78. LICOMPTYPE_TEXTURE2D = 33,
  79. LICOMPTYPE_TEXTURE2DARRAY = 34,
  80. LICOMPTYPE_RESOURCE = 35,
  81. LICOMPTYPE_INT32_ONLY = 36,
  82. LICOMPTYPE_INT64_ONLY = 37,
  83. LICOMPTYPE_ANY_INT64 = 38,
  84. LICOMPTYPE_FLOAT32_ONLY = 39,
  85. LICOMPTYPE_INT8_4PACKED = 40,
  86. LICOMPTYPE_UINT8_4PACKED = 41,
  87. LICOMPTYPE_ANY_INT16_OR_32 = 42,
  88. LICOMPTYPE_SINT16_OR_32_ONLY = 43,
  89. LICOMPTYPE_COUNT = 44
  90. };
  91. static const BYTE IA_SPECIAL_BASE = 0xf0;
  92. static const BYTE IA_R = 0xf0;
  93. static const BYTE IA_C = 0xf1;
  94. static const BYTE IA_R2 = 0xf2;
  95. static const BYTE IA_C2 = 0xf3;
  96. static const BYTE IA_SPECIAL_SLOTS = 4;
  97. struct HLSL_INTRINSIC_ARGUMENT {
  98. LPCSTR pName; // Name of the argument; the first argument has the function name.
  99. UINT64 qwUsage; // A combination of AR_QUAL_IN|AR_QUAL_OUT|AR_QUAL_COLMAJOR|AR_QUAL_ROWMAJOR in parameter tables; other values possible elsewhere.
  100. BYTE uTemplateId; // One of INTRIN_TEMPLATE_FROM_TYPE, INTRIN_TEMPLATE_VARARGS or the argument # the template (layout) must match (trivially itself).
  101. BYTE uLegalTemplates; // A LEGAL_INTRINSIC_TEMPLATES value for allowed templates.
  102. BYTE uComponentTypeId; // INTRIN_COMPTYPE_FROM_TYPE_ELT0, or the argument # the component (element type) must match (trivially itself).
  103. BYTE uLegalComponentTypes; // A LEGAL_INTRINSIC_COMPTYPES value for allowed components.
  104. BYTE uRows; // Required number of rows, or one of IA_R/IA_C/IA_R2/IA_C2 for matching input constraints.
  105. BYTE uCols; // Required number of cols, or one of IA_R/IA_C/IA_R2/IA_C2 for matching input constraints.
  106. };
  107. struct HLSL_INTRINSIC {
  108. UINT Op; // Intrinsic Op ID
  109. BOOL bReadOnly; // Only read memory
  110. BOOL bReadNone; // Not read memory
  111. BOOL bIsWave; // Is a wave-sensitive op
  112. INT iOverloadParamIndex; // Parameter decide the overload type, -1 means ret type
  113. UINT uNumArgs; // Count of arguments in pArgs.
  114. const HLSL_INTRINSIC_ARGUMENT* pArgs; // Pointer to first argument.
  115. };
  116. ///////////////////////////////////////////////////////////////////////////////
  117. // Interfaces.
  118. CROSS_PLATFORM_UUIDOF(IDxcIntrinsicTable, "f0d4da3f-f863-4660-b8b4-dfd94ded6215")
  119. struct IDxcIntrinsicTable : public IUnknown
  120. {
  121. public:
  122. virtual HRESULT STDMETHODCALLTYPE GetTableName(_Outptr_ LPCSTR *pTableName) = 0;
  123. virtual HRESULT STDMETHODCALLTYPE LookupIntrinsic(
  124. LPCWSTR typeName, LPCWSTR functionName,
  125. const HLSL_INTRINSIC** pIntrinsic,
  126. _Inout_ UINT64* pLookupCookie) = 0;
  127. // Get the lowering strategy for an hlsl extension intrinsic.
  128. virtual HRESULT STDMETHODCALLTYPE GetLoweringStrategy(UINT opcode, LPCSTR *pStrategy) = 0;
  129. // Callback to support custom naming of hlsl extension intrinsic functions in dxil.
  130. // Return the empty string to get the default intrinsic name, which is the mangled
  131. // name of the high level intrinsic function.
  132. //
  133. // Overloaded intrinsics are supported by use of an overload place holder in the
  134. // name. The string "$o" in the name will be replaced by the return type of the
  135. // intrinsic.
  136. virtual HRESULT STDMETHODCALLTYPE GetIntrinsicName(UINT opcode, LPCSTR *pName) = 0;
  137. // Callback to support the 'dxil' lowering strategy.
  138. // Returns the dxil opcode that the intrinsic should use for lowering.
  139. virtual HRESULT STDMETHODCALLTYPE GetDxilOpCode(UINT opcode, UINT *pDxilOpcode) = 0;
  140. };
  141. CROSS_PLATFORM_UUIDOF(IDxcSemanticDefineValidator, "1d063e4f-515a-4d57-a12a-431f6a44cfb9")
  142. struct IDxcSemanticDefineValidator : public IUnknown
  143. {
  144. public:
  145. virtual HRESULT STDMETHODCALLTYPE GetSemanticDefineWarningsAndErrors(LPCSTR pName, LPCSTR pValue, IDxcBlobEncoding **ppWarningBlob, IDxcBlobEncoding **ppErrorBlob) = 0;
  146. };
  147. CROSS_PLATFORM_UUIDOF(IDxcLangExtensions, "282a56b4-3f56-4360-98c7-9ea04a752272")
  148. struct IDxcLangExtensions : public IUnknown
  149. {
  150. public:
  151. /// <summary>
  152. /// Registers the name of a preprocessor define that has semantic meaning
  153. /// and should be preserved for downstream consumers.
  154. /// </summary>
  155. virtual HRESULT STDMETHODCALLTYPE RegisterSemanticDefine(LPCWSTR name) = 0;
  156. /// <summary>Registers a name to exclude from semantic defines.</summary>
  157. virtual HRESULT STDMETHODCALLTYPE RegisterSemanticDefineExclusion(LPCWSTR name) = 0;
  158. /// <summary>Registers a definition for compilation.</summary>
  159. virtual HRESULT STDMETHODCALLTYPE RegisterDefine(LPCWSTR name) = 0;
  160. /// <summary>Registers a table of built-in intrinsics.</summary>
  161. virtual HRESULT STDMETHODCALLTYPE RegisterIntrinsicTable(_In_ IDxcIntrinsicTable* pTable) = 0;
  162. /// <summary>Sets an (optional) validator for parsed semantic defines.<summary>
  163. /// This provides a hook to check that the semantic defines present in the source
  164. /// contain valid data. One validator is used to validate all parsed semantic defines.
  165. virtual HRESULT STDMETHODCALLTYPE SetSemanticDefineValidator(_In_ IDxcSemanticDefineValidator* pValidator) = 0;
  166. /// <summary>Sets the name for the root metadata node used in DXIL to hold the semantic defines.</summary>
  167. virtual HRESULT STDMETHODCALLTYPE SetSemanticDefineMetaDataName(LPCSTR name) = 0;
  168. };
  169. CROSS_PLATFORM_UUIDOF(IDxcLangExtensions2, "2490C368-89EE-4491-A4B2-C6547B6C9381")
  170. struct IDxcLangExtensions2 : public IDxcLangExtensions {
  171. public:
  172. virtual HRESULT STDMETHODCALLTYPE SetTargetTriple(LPCSTR name) = 0;
  173. };
  174. CROSS_PLATFORM_UUIDOF(IDxcSystemAccess, "454b764f-3549-475b-958c-a7a6fcd05fbc")
  175. struct IDxcSystemAccess : public IUnknown
  176. {
  177. public:
  178. virtual HRESULT STDMETHODCALLTYPE EnumFiles(LPCWSTR fileName, IEnumSTATSTG** pResult) = 0;
  179. virtual HRESULT STDMETHODCALLTYPE OpenStorage(
  180. _In_ LPCWSTR lpFileName,
  181. _In_ DWORD dwDesiredAccess,
  182. _In_ DWORD dwShareMode,
  183. _In_ DWORD dwCreationDisposition,
  184. _In_ DWORD dwFlagsAndAttributes, IUnknown** pResult) = 0;
  185. virtual HRESULT STDMETHODCALLTYPE SetStorageTime(_In_ IUnknown* storage,
  186. _In_opt_ const FILETIME *lpCreationTime,
  187. _In_opt_ const FILETIME *lpLastAccessTime,
  188. _In_opt_ const FILETIME *lpLastWriteTime) = 0;
  189. virtual HRESULT STDMETHODCALLTYPE GetFileInformationForStorage(_In_ IUnknown* storage, _Out_ LPBY_HANDLE_FILE_INFORMATION lpFileInformation) = 0;
  190. virtual HRESULT STDMETHODCALLTYPE GetFileTypeForStorage(_In_ IUnknown* storage, _Out_ DWORD* fileType) = 0;
  191. virtual HRESULT STDMETHODCALLTYPE CreateHardLinkInStorage(_In_ LPCWSTR lpFileName, _In_ LPCWSTR lpExistingFileName) = 0;
  192. virtual HRESULT STDMETHODCALLTYPE MoveStorage(_In_ LPCWSTR lpExistingFileName, _In_opt_ LPCWSTR lpNewFileName, _In_ DWORD dwFlags) = 0;
  193. virtual HRESULT STDMETHODCALLTYPE GetFileAttributesForStorage(_In_ LPCWSTR lpFileName, _Out_ DWORD* pResult) = 0;
  194. virtual HRESULT STDMETHODCALLTYPE DeleteStorage(_In_ LPCWSTR lpFileName) = 0;
  195. virtual HRESULT STDMETHODCALLTYPE RemoveDirectoryStorage(LPCWSTR lpFileName) = 0;
  196. virtual HRESULT STDMETHODCALLTYPE CreateDirectoryStorage(_In_ LPCWSTR lpPathName) = 0;
  197. virtual HRESULT STDMETHODCALLTYPE GetCurrentDirectoryForStorage(DWORD nBufferLength, _Out_writes_(nBufferLength) LPWSTR lpBuffer, _Out_ DWORD* written) = 0;
  198. virtual HRESULT STDMETHODCALLTYPE GetMainModuleFileNameW(DWORD nBufferLength, _Out_writes_(nBufferLength) LPWSTR lpBuffer, _Out_ DWORD* written) = 0;
  199. virtual HRESULT STDMETHODCALLTYPE GetTempStoragePath(DWORD nBufferLength, _Out_writes_(nBufferLength) LPWSTR lpBuffer, _Out_ DWORD* written) = 0;
  200. virtual HRESULT STDMETHODCALLTYPE SupportsCreateSymbolicLink(_Out_ BOOL* pResult) = 0;
  201. virtual HRESULT STDMETHODCALLTYPE CreateSymbolicLinkInStorage(_In_ LPCWSTR lpSymlinkFileName, _In_ LPCWSTR lpTargetFileName, DWORD dwFlags) = 0;
  202. virtual HRESULT STDMETHODCALLTYPE CreateStorageMapping(
  203. _In_ IUnknown* hFile,
  204. _In_ DWORD flProtect,
  205. _In_ DWORD dwMaximumSizeHigh,
  206. _In_ DWORD dwMaximumSizeLow,
  207. _Outptr_ IUnknown** pResult) = 0;
  208. virtual HRESULT MapViewOfFile(
  209. _In_ IUnknown* hFileMappingObject,
  210. _In_ DWORD dwDesiredAccess,
  211. _In_ DWORD dwFileOffsetHigh,
  212. _In_ DWORD dwFileOffsetLow,
  213. _In_ SIZE_T dwNumberOfBytesToMap,
  214. _Outptr_ ID3D10Blob** pResult) = 0;
  215. virtual HRESULT STDMETHODCALLTYPE OpenStdStorage(int standardFD, _Outptr_ IUnknown** pResult) = 0;
  216. virtual HRESULT STDMETHODCALLTYPE GetStreamDisplay(_COM_Outptr_result_maybenull_ ITextFont** textFont, _Out_ unsigned* columnCount) = 0;
  217. };
  218. CROSS_PLATFORM_UUIDOF(IDxcContainerEventsHandler, "e991ca8d-2045-413c-a8b8-788b2c06e14d")
  219. struct IDxcContainerEventsHandler : public IUnknown
  220. {
  221. public:
  222. virtual HRESULT STDMETHODCALLTYPE OnDxilContainerBuilt(_In_ IDxcBlob *pSource, _Out_ IDxcBlob **ppTarget) = 0;
  223. };
  224. CROSS_PLATFORM_UUIDOF(IDxcContainerEvent, "0cfc5058-342b-4ff2-83f7-04c12aad3d01")
  225. struct IDxcContainerEvent : public IUnknown
  226. {
  227. public:
  228. virtual HRESULT STDMETHODCALLTYPE RegisterDxilContainerEventHandler(IDxcContainerEventsHandler *pHandler, UINT64 *pCookie) = 0;
  229. virtual HRESULT STDMETHODCALLTYPE UnRegisterDxilContainerEventHandler(UINT64 cookie) = 0;
  230. };
  231. #endif