dxcapi.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // dxcapi.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 declarations for the DirectX Compiler API entry point. //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #ifndef __DXC_API__
  12. #define __DXC_API__
  13. #ifdef _WIN32
  14. #ifndef DXC_API_IMPORT
  15. #define DXC_API_IMPORT __declspec(dllimport)
  16. #endif
  17. #else
  18. #ifndef DXC_API_IMPORT
  19. #define DXC_API_IMPORT __attribute__ ((visibility ("default")))
  20. #endif
  21. #endif
  22. #ifdef _WIN32
  23. #ifndef CROSS_PLATFORM_UUIDOF
  24. // Warning: This macro exists in WinAdapter.h as well
  25. #define CROSS_PLATFORM_UUIDOF(interface, spec) \
  26. struct __declspec(uuid(spec)) interface;
  27. #endif
  28. #else
  29. #include <dlfcn.h>
  30. #include "dxc/Support/WinAdapter.h"
  31. #endif
  32. struct IMalloc;
  33. struct IDxcIncludeHandler;
  34. typedef HRESULT (__stdcall *DxcCreateInstanceProc)(
  35. _In_ REFCLSID rclsid,
  36. _In_ REFIID riid,
  37. _Out_ LPVOID* ppv
  38. );
  39. typedef HRESULT(__stdcall *DxcCreateInstance2Proc)(
  40. _In_ IMalloc *pMalloc,
  41. _In_ REFCLSID rclsid,
  42. _In_ REFIID riid,
  43. _Out_ LPVOID* ppv
  44. );
  45. /// <summary>
  46. /// Creates a single uninitialized object of the class associated with a specified CLSID.
  47. /// </summary>
  48. /// <param name="rclsid">
  49. /// The CLSID associated with the data and code that will be used to create the object.
  50. /// </param>
  51. /// <param name="riid">
  52. /// A reference to the identifier of the interface to be used to communicate
  53. /// with the object.
  54. /// </param>
  55. /// <param name="ppv">
  56. /// Address of pointer variable that receives the interface pointer requested
  57. /// in riid. Upon successful return, *ppv contains the requested interface
  58. /// pointer. Upon failure, *ppv contains NULL.</param>
  59. /// <remarks>
  60. /// While this function is similar to CoCreateInstance, there is no COM involvement.
  61. /// </remarks>
  62. extern "C"
  63. DXC_API_IMPORT HRESULT __stdcall DxcCreateInstance(
  64. _In_ REFCLSID rclsid,
  65. _In_ REFIID riid,
  66. _Out_ LPVOID* ppv
  67. );
  68. extern "C"
  69. DXC_API_IMPORT HRESULT __stdcall DxcCreateInstance2(
  70. _In_ IMalloc *pMalloc,
  71. _In_ REFCLSID rclsid,
  72. _In_ REFIID riid,
  73. _Out_ LPVOID* ppv
  74. );
  75. // For convenience, equivalent definitions to CP_UTF8 and CP_UTF16.
  76. #define DXC_CP_UTF8 65001
  77. #define DXC_CP_UTF16 1200
  78. // Use DXC_CP_ACP for: Binary; ANSI Text; Autodetect UTF with BOM
  79. #define DXC_CP_ACP 0
  80. // This flag indicates that the shader hash was computed taking into account source information (-Zss)
  81. #define DXC_HASHFLAG_INCLUDES_SOURCE 1
  82. // Hash digest type for ShaderHash
  83. typedef struct DxcShaderHash {
  84. UINT32 Flags; // DXC_HASHFLAG_*
  85. BYTE HashDigest[16];
  86. } DxcShaderHash;
  87. #define DXC_FOURCC(ch0, ch1, ch2, ch3) ( \
  88. (UINT32)(UINT8)(ch0) | (UINT32)(UINT8)(ch1) << 8 | \
  89. (UINT32)(UINT8)(ch2) << 16 | (UINT32)(UINT8)(ch3) << 24 \
  90. )
  91. #define DXC_PART_PDB DXC_FOURCC('I', 'L', 'D', 'B')
  92. #define DXC_PART_PDB_NAME DXC_FOURCC('I', 'L', 'D', 'N')
  93. #define DXC_PART_PRIVATE_DATA DXC_FOURCC('P', 'R', 'I', 'V')
  94. #define DXC_PART_ROOT_SIGNATURE DXC_FOURCC('R', 'T', 'S', '0')
  95. #define DXC_PART_DXIL DXC_FOURCC('D', 'X', 'I', 'L')
  96. #define DXC_PART_REFLECTION_DATA DXC_FOURCC('S', 'T', 'A', 'T')
  97. #define DXC_PART_SHADER_HASH DXC_FOURCC('H', 'A', 'S', 'H')
  98. #define DXC_PART_INPUT_SIGNATURE DXC_FOURCC('I', 'S', 'G', '1')
  99. #define DXC_PART_OUTPUT_SIGNATURE DXC_FOURCC('O', 'S', 'G', '1')
  100. #define DXC_PART_PATCH_CONSTANT_SIGNATURE DXC_FOURCC('P', 'S', 'G', '1')
  101. // Some option arguments are defined here for continuity with D3DCompile interface
  102. #define DXC_ARG_DEBUG L"-Zi"
  103. #define DXC_ARG_SKIP_VALIDATION L"-Vd"
  104. #define DXC_ARG_SKIP_OPTIMIZATIONS L"-Od"
  105. #define DXC_ARG_PACK_MATRIX_ROW_MAJOR L"-Zpr"
  106. #define DXC_ARG_PACK_MATRIX_COLUMN_MAJOR L"-Zpc"
  107. #define DXC_ARG_AVOID_FLOW_CONTROL L"-Gfa"
  108. #define DXC_ARG_PREFER_FLOW_CONTROL L"-Gfp"
  109. #define DXC_ARG_ENABLE_STRICTNESS L"-Ges"
  110. #define DXC_ARG_ENABLE_BACKWARDS_COMPATIBILITY L"-Gec"
  111. #define DXC_ARG_IEEE_STRICTNESS L"-Gis"
  112. #define DXC_ARG_OPTIMIZATION_LEVEL0 L"-O0"
  113. #define DXC_ARG_OPTIMIZATION_LEVEL1 L"-O1"
  114. #define DXC_ARG_OPTIMIZATION_LEVEL2 L"-O2"
  115. #define DXC_ARG_OPTIMIZATION_LEVEL3 L"-O3"
  116. #define DXC_ARG_WARNINGS_ARE_ERRORS L"-WX"
  117. #define DXC_ARG_RESOURCES_MAY_ALIAS L"-res_may_alias"
  118. #define DXC_ARG_ALL_RESOURCES_BOUND L"-all_resources_bound"
  119. #define DXC_ARG_DEBUG_NAME_FOR_SOURCE L"-Zss"
  120. #define DXC_ARG_DEBUG_NAME_FOR_BINARY L"-Zsb"
  121. // IDxcBlob is an alias of ID3D10Blob and ID3DBlob
  122. CROSS_PLATFORM_UUIDOF(IDxcBlob, "8BA5FB08-5195-40e2-AC58-0D989C3A0102")
  123. struct IDxcBlob : public IUnknown {
  124. public:
  125. virtual LPVOID STDMETHODCALLTYPE GetBufferPointer(void) = 0;
  126. virtual SIZE_T STDMETHODCALLTYPE GetBufferSize(void) = 0;
  127. };
  128. CROSS_PLATFORM_UUIDOF(IDxcBlobEncoding, "7241d424-2646-4191-97c0-98e96e42fc68")
  129. struct IDxcBlobEncoding : public IDxcBlob {
  130. public:
  131. virtual HRESULT STDMETHODCALLTYPE GetEncoding(_Out_ BOOL *pKnown,
  132. _Out_ UINT32 *pCodePage) = 0;
  133. };
  134. // Notes on IDxcBlobUtf16 and IDxcBlobUtf8
  135. // These guarantee null-terminated text and the stated encoding.
  136. // GetBufferSize() will return the size in bytes, including null-terminator
  137. // GetStringLength() will return the length in characters, excluding the null-terminator
  138. // Name strings will use IDxcBlobUtf16, while other string output blobs,
  139. // such as errors/warnings, preprocessed HLSL, or other text will be based
  140. // on the -encoding option.
  141. // The API will use this interface for output name strings
  142. CROSS_PLATFORM_UUIDOF(IDxcBlobUtf16, "A3F84EAB-0FAA-497E-A39C-EE6ED60B2D84")
  143. struct IDxcBlobUtf16 : public IDxcBlobEncoding {
  144. public:
  145. virtual LPCWSTR STDMETHODCALLTYPE GetStringPointer(void) = 0;
  146. virtual SIZE_T STDMETHODCALLTYPE GetStringLength(void) = 0;
  147. };
  148. CROSS_PLATFORM_UUIDOF(IDxcBlobUtf8, "3DA636C9-BA71-4024-A301-30CBF125305B")
  149. struct IDxcBlobUtf8 : public IDxcBlobEncoding {
  150. public:
  151. virtual LPCSTR STDMETHODCALLTYPE GetStringPointer(void) = 0;
  152. virtual SIZE_T STDMETHODCALLTYPE GetStringLength(void) = 0;
  153. };
  154. CROSS_PLATFORM_UUIDOF(IDxcIncludeHandler, "7f61fc7d-950d-467f-b3e3-3c02fb49187c")
  155. struct IDxcIncludeHandler : public IUnknown {
  156. virtual HRESULT STDMETHODCALLTYPE LoadSource(
  157. _In_z_ LPCWSTR pFilename, // Candidate filename.
  158. _COM_Outptr_result_maybenull_ IDxcBlob **ppIncludeSource // Resultant source object for included file, nullptr if not found.
  159. ) = 0;
  160. };
  161. // Structure for supplying bytes or text input to Dxc APIs.
  162. // Use Encoding = 0 for non-text bytes, ANSI text, or unknown with BOM.
  163. typedef struct DxcBuffer {
  164. LPCVOID Ptr;
  165. SIZE_T Size;
  166. UINT Encoding;
  167. } DxcText;
  168. struct DxcDefine {
  169. LPCWSTR Name;
  170. _Maybenull_ LPCWSTR Value;
  171. };
  172. CROSS_PLATFORM_UUIDOF(IDxcCompilerArgs, "73EFFE2A-70DC-45F8-9690-EFF64C02429D")
  173. struct IDxcCompilerArgs : public IUnknown {
  174. // Pass GetArguments() and GetCount() to Compile
  175. virtual LPCWSTR* STDMETHODCALLTYPE GetArguments() = 0;
  176. virtual UINT32 STDMETHODCALLTYPE GetCount() = 0;
  177. // Add additional arguments or defines here, if desired.
  178. virtual HRESULT STDMETHODCALLTYPE AddArguments(
  179. _In_opt_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments to add
  180. _In_ UINT32 argCount // Number of arguments to add
  181. ) = 0;
  182. virtual HRESULT STDMETHODCALLTYPE AddArgumentsUTF8(
  183. _In_opt_count_(argCount)LPCSTR *pArguments, // Array of pointers to UTF-8 arguments to add
  184. _In_ UINT32 argCount // Number of arguments to add
  185. ) = 0;
  186. virtual HRESULT STDMETHODCALLTYPE AddDefines(
  187. _In_count_(defineCount) const DxcDefine *pDefines, // Array of defines
  188. _In_ UINT32 defineCount // Number of defines
  189. ) = 0;
  190. };
  191. //////////////////////////
  192. // Legacy Interfaces
  193. /////////////////////////
  194. // NOTE: IDxcUtils replaces IDxcLibrary
  195. CROSS_PLATFORM_UUIDOF(IDxcLibrary, "e5204dc7-d18c-4c3c-bdfb-851673980fe7")
  196. struct IDxcLibrary : public IUnknown {
  197. virtual HRESULT STDMETHODCALLTYPE SetMalloc(_In_opt_ IMalloc *pMalloc) = 0;
  198. virtual HRESULT STDMETHODCALLTYPE CreateBlobFromBlob(
  199. _In_ IDxcBlob *pBlob, UINT32 offset, UINT32 length, _COM_Outptr_ IDxcBlob **ppResult) = 0;
  200. virtual HRESULT STDMETHODCALLTYPE CreateBlobFromFile(
  201. _In_z_ LPCWSTR pFileName, _In_opt_ UINT32* codePage,
  202. _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
  203. virtual HRESULT STDMETHODCALLTYPE CreateBlobWithEncodingFromPinned(
  204. _In_bytecount_(size) LPCVOID pText, UINT32 size, UINT32 codePage,
  205. _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
  206. virtual HRESULT STDMETHODCALLTYPE CreateBlobWithEncodingOnHeapCopy(
  207. _In_bytecount_(size) LPCVOID pText, UINT32 size, UINT32 codePage,
  208. _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
  209. virtual HRESULT STDMETHODCALLTYPE CreateBlobWithEncodingOnMalloc(
  210. _In_bytecount_(size) LPCVOID pText, IMalloc *pIMalloc, UINT32 size, UINT32 codePage,
  211. _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
  212. virtual HRESULT STDMETHODCALLTYPE CreateIncludeHandler(
  213. _COM_Outptr_ IDxcIncludeHandler **ppResult) = 0;
  214. virtual HRESULT STDMETHODCALLTYPE CreateStreamFromBlobReadOnly(
  215. _In_ IDxcBlob *pBlob, _COM_Outptr_ IStream **ppStream) = 0;
  216. virtual HRESULT STDMETHODCALLTYPE GetBlobAsUtf8(
  217. _In_ IDxcBlob *pBlob, _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
  218. virtual HRESULT STDMETHODCALLTYPE GetBlobAsUtf16(
  219. _In_ IDxcBlob *pBlob, _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
  220. };
  221. // NOTE: IDxcResult replaces IDxcOperationResult
  222. CROSS_PLATFORM_UUIDOF(IDxcOperationResult, "CEDB484A-D4E9-445A-B991-CA21CA157DC2")
  223. struct IDxcOperationResult : public IUnknown {
  224. virtual HRESULT STDMETHODCALLTYPE GetStatus(_Out_ HRESULT *pStatus) = 0;
  225. // GetResult returns the main result of the operation.
  226. // This corresponds to:
  227. // DXC_OUT_OBJECT - Compile() with shader or library target
  228. // DXC_OUT_DISASSEMBLY - Disassemble()
  229. // DXC_OUT_HLSL - Compile() with -P
  230. // DXC_OUT_ROOT_SIGNATURE - Compile() with rootsig_* target
  231. virtual HRESULT STDMETHODCALLTYPE GetResult(_COM_Outptr_result_maybenull_ IDxcBlob **ppResult) = 0;
  232. // GetErrorBuffer Corresponds to DXC_OUT_ERRORS.
  233. virtual HRESULT STDMETHODCALLTYPE GetErrorBuffer(_COM_Outptr_result_maybenull_ IDxcBlobEncoding **ppErrors) = 0;
  234. };
  235. // NOTE: IDxcCompiler3 replaces IDxcCompiler and IDxcCompiler2
  236. CROSS_PLATFORM_UUIDOF(IDxcCompiler, "8c210bf3-011f-4422-8d70-6f9acb8db617")
  237. struct IDxcCompiler : public IUnknown {
  238. // Compile a single entry point to the target shader model
  239. virtual HRESULT STDMETHODCALLTYPE Compile(
  240. _In_ IDxcBlob *pSource, // Source text to compile
  241. _In_opt_z_ LPCWSTR pSourceName, // Optional file name for pSource. Used in errors and include handlers.
  242. _In_opt_z_ LPCWSTR pEntryPoint, // entry point name
  243. _In_z_ LPCWSTR pTargetProfile, // shader profile to compile
  244. _In_opt_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments
  245. _In_ UINT32 argCount, // Number of arguments
  246. _In_count_(defineCount)
  247. const DxcDefine *pDefines, // Array of defines
  248. _In_ UINT32 defineCount, // Number of defines
  249. _In_opt_ IDxcIncludeHandler *pIncludeHandler, // user-provided interface to handle #include directives (optional)
  250. _COM_Outptr_ IDxcOperationResult **ppResult // Compiler output status, buffer, and errors
  251. ) = 0;
  252. // Preprocess source text
  253. virtual HRESULT STDMETHODCALLTYPE Preprocess(
  254. _In_ IDxcBlob *pSource, // Source text to preprocess
  255. _In_opt_z_ LPCWSTR pSourceName, // Optional file name for pSource. Used in errors and include handlers.
  256. _In_opt_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments
  257. _In_ UINT32 argCount, // Number of arguments
  258. _In_count_(defineCount)
  259. const DxcDefine *pDefines, // Array of defines
  260. _In_ UINT32 defineCount, // Number of defines
  261. _In_opt_ IDxcIncludeHandler *pIncludeHandler, // user-provided interface to handle #include directives (optional)
  262. _COM_Outptr_ IDxcOperationResult **ppResult // Preprocessor output status, buffer, and errors
  263. ) = 0;
  264. // Disassemble a program.
  265. virtual HRESULT STDMETHODCALLTYPE Disassemble(
  266. _In_ IDxcBlob *pSource, // Program to disassemble.
  267. _COM_Outptr_ IDxcBlobEncoding **ppDisassembly // Disassembly text.
  268. ) = 0;
  269. };
  270. // NOTE: IDxcCompiler3 replaces IDxcCompiler and IDxcCompiler2
  271. CROSS_PLATFORM_UUIDOF(IDxcCompiler2, "A005A9D9-B8BB-4594-B5C9-0E633BEC4D37")
  272. struct IDxcCompiler2 : public IDxcCompiler {
  273. // Compile a single entry point to the target shader model with debug information.
  274. virtual HRESULT STDMETHODCALLTYPE CompileWithDebug(
  275. _In_ IDxcBlob *pSource, // Source text to compile
  276. _In_opt_z_ LPCWSTR pSourceName, // Optional file name for pSource. Used in errors and include handlers.
  277. _In_opt_z_ LPCWSTR pEntryPoint, // Entry point name
  278. _In_z_ LPCWSTR pTargetProfile, // Shader profile to compile
  279. _In_opt_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments
  280. _In_ UINT32 argCount, // Number of arguments
  281. _In_count_(defineCount)
  282. const DxcDefine *pDefines, // Array of defines
  283. _In_ UINT32 defineCount, // Number of defines
  284. _In_opt_ IDxcIncludeHandler *pIncludeHandler, // user-provided interface to handle #include directives (optional)
  285. _COM_Outptr_ IDxcOperationResult **ppResult, // Compiler output status, buffer, and errors
  286. _Outptr_opt_result_z_ LPWSTR *ppDebugBlobName,// Suggested file name for debug blob. (Must be CoTaskMemFree()'d!)
  287. _COM_Outptr_opt_ IDxcBlob **ppDebugBlob // Debug blob
  288. ) = 0;
  289. };
  290. CROSS_PLATFORM_UUIDOF(IDxcLinker, "F1B5BE2A-62DD-4327-A1C2-42AC1E1E78E6")
  291. struct IDxcLinker : public IUnknown {
  292. public:
  293. // Register a library with name to ref it later.
  294. virtual HRESULT RegisterLibrary(
  295. _In_opt_ LPCWSTR pLibName, // Name of the library.
  296. _In_ IDxcBlob *pLib // Library blob.
  297. ) = 0;
  298. // Links the shader and produces a shader blob that the Direct3D runtime can
  299. // use.
  300. virtual HRESULT STDMETHODCALLTYPE Link(
  301. _In_opt_ LPCWSTR pEntryName, // Entry point name
  302. _In_ LPCWSTR pTargetProfile, // shader profile to link
  303. _In_count_(libCount)
  304. const LPCWSTR *pLibNames, // Array of library names to link
  305. _In_ UINT32 libCount, // Number of libraries to link
  306. _In_opt_count_(argCount) const LPCWSTR *pArguments, // Array of pointers to arguments
  307. _In_ UINT32 argCount, // Number of arguments
  308. _COM_Outptr_
  309. IDxcOperationResult **ppResult // Linker output status, buffer, and errors
  310. ) = 0;
  311. };
  312. /////////////////////////
  313. // Latest interfaces. Please use these
  314. ////////////////////////
  315. // NOTE: IDxcUtils replaces IDxcLibrary
  316. CROSS_PLATFORM_UUIDOF(IDxcUtils, "4605C4CB-2019-492A-ADA4-65F20BB7D67F")
  317. struct IDxcUtils : public IUnknown {
  318. // Create a sub-blob that holds a reference to the outer blob and points to its memory.
  319. virtual HRESULT STDMETHODCALLTYPE CreateBlobFromBlob(
  320. _In_ IDxcBlob *pBlob, UINT32 offset, UINT32 length, _COM_Outptr_ IDxcBlob **ppResult) = 0;
  321. // For codePage, use 0 (or DXC_CP_ACP) for raw binary or ANSI code page
  322. // Creates a blob referencing existing memory, with no copy.
  323. // User must manage the memory lifetime separately.
  324. // (was: CreateBlobWithEncodingFromPinned)
  325. virtual HRESULT STDMETHODCALLTYPE CreateBlobFromPinned(
  326. _In_bytecount_(size) LPCVOID pData, UINT32 size, UINT32 codePage,
  327. _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
  328. // Create blob, taking ownership of memory allocated with supplied allocator.
  329. // (was: CreateBlobWithEncodingOnMalloc)
  330. virtual HRESULT STDMETHODCALLTYPE MoveToBlob(
  331. _In_bytecount_(size) LPCVOID pData, IMalloc *pIMalloc, UINT32 size, UINT32 codePage,
  332. _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
  333. ////
  334. // New blobs and copied contents are allocated with the current allocator
  335. // Copy blob contents to memory owned by the new blob.
  336. // (was: CreateBlobWithEncodingOnHeapCopy)
  337. virtual HRESULT STDMETHODCALLTYPE CreateBlob(
  338. _In_bytecount_(size) LPCVOID pData, UINT32 size, UINT32 codePage,
  339. _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
  340. // (was: CreateBlobFromFile)
  341. virtual HRESULT STDMETHODCALLTYPE LoadFile(
  342. _In_z_ LPCWSTR pFileName, _In_opt_ UINT32* pCodePage,
  343. _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
  344. virtual HRESULT STDMETHODCALLTYPE CreateReadOnlyStreamFromBlob(
  345. _In_ IDxcBlob *pBlob, _COM_Outptr_ IStream **ppStream) = 0;
  346. // Create default file-based include handler
  347. virtual HRESULT STDMETHODCALLTYPE CreateDefaultIncludeHandler(
  348. _COM_Outptr_ IDxcIncludeHandler **ppResult) = 0;
  349. // Convert or return matching encoded text blobs
  350. virtual HRESULT STDMETHODCALLTYPE GetBlobAsUtf8(
  351. _In_ IDxcBlob *pBlob, _COM_Outptr_ IDxcBlobUtf8 **pBlobEncoding) = 0;
  352. virtual HRESULT STDMETHODCALLTYPE GetBlobAsUtf16(
  353. _In_ IDxcBlob *pBlob, _COM_Outptr_ IDxcBlobUtf16 **pBlobEncoding) = 0;
  354. virtual HRESULT STDMETHODCALLTYPE GetDxilContainerPart(
  355. _In_ const DxcBuffer *pShader,
  356. _In_ UINT32 DxcPart,
  357. _Outptr_result_nullonfailure_ void **ppPartData,
  358. _Out_ UINT32 *pPartSizeInBytes) = 0;
  359. // Create reflection interface from serialized Dxil container, or DXC_PART_REFLECTION_DATA.
  360. // TBD: Require part header for RDAT? (leaning towards yes)
  361. virtual HRESULT STDMETHODCALLTYPE CreateReflection(
  362. _In_ const DxcBuffer *pData, REFIID iid, void **ppvReflection) = 0;
  363. virtual HRESULT STDMETHODCALLTYPE BuildArguments(
  364. _In_opt_z_ LPCWSTR pSourceName, // Optional file name for pSource. Used in errors and include handlers.
  365. _In_opt_z_ LPCWSTR pEntryPoint, // Entry point name. (-E)
  366. _In_z_ LPCWSTR pTargetProfile, // Shader profile to compile. (-T)
  367. _In_opt_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments
  368. _In_ UINT32 argCount, // Number of arguments
  369. _In_count_(defineCount)
  370. const DxcDefine *pDefines, // Array of defines
  371. _In_ UINT32 defineCount, // Number of defines
  372. _COM_Outptr_ IDxcCompilerArgs **ppArgs // Arguments you can use with Compile() method
  373. ) = 0;
  374. // Takes the shader PDB and returns the hash and the container inside it
  375. virtual HRESULT STDMETHODCALLTYPE GetPDBContents(
  376. _In_ IDxcBlob *pPDBBlob, _COM_Outptr_ IDxcBlob **ppHash, _COM_Outptr_ IDxcBlob **ppContainer) = 0;
  377. };
  378. // For use with IDxcResult::[Has|Get]Output dxcOutKind argument
  379. // Note: text outputs returned from version 2 APIs are UTF-8 or UTF-16 based on -encoding option
  380. typedef enum DXC_OUT_KIND {
  381. DXC_OUT_NONE = 0,
  382. DXC_OUT_OBJECT = 1, // IDxcBlob - Shader or library object
  383. DXC_OUT_ERRORS = 2, // IDxcBlobUtf8 or IDxcBlobUtf16
  384. DXC_OUT_PDB = 3, // IDxcBlob
  385. DXC_OUT_SHADER_HASH = 4, // IDxcBlob - DxcShaderHash of shader or shader with source info (-Zsb/-Zss)
  386. DXC_OUT_DISASSEMBLY = 5, // IDxcBlobUtf8 or IDxcBlobUtf16 - from Disassemble
  387. DXC_OUT_HLSL = 6, // IDxcBlobUtf8 or IDxcBlobUtf16 - from Preprocessor or Rewriter
  388. DXC_OUT_TEXT = 7, // IDxcBlobUtf8 or IDxcBlobUtf16 - other text, such as -ast-dump or -Odump
  389. DXC_OUT_REFLECTION = 8, // IDxcBlob - RDAT part with reflection data
  390. DXC_OUT_ROOT_SIGNATURE = 9, // IDxcBlob - Serialized root signature output
  391. DXC_OUT_EXTRA_OUTPUTS = 10,// IDxcExtraResults - Extra outputs
  392. DXC_OUT_FORCE_DWORD = 0xFFFFFFFF
  393. } DXC_OUT_KIND;
  394. CROSS_PLATFORM_UUIDOF(IDxcResult, "58346CDA-DDE7-4497-9461-6F87AF5E0659")
  395. struct IDxcResult : public IDxcOperationResult {
  396. virtual BOOL STDMETHODCALLTYPE HasOutput(_In_ DXC_OUT_KIND dxcOutKind) = 0;
  397. virtual HRESULT STDMETHODCALLTYPE GetOutput(_In_ DXC_OUT_KIND dxcOutKind,
  398. _In_ REFIID iid, _COM_Outptr_opt_result_maybenull_ void **ppvObject,
  399. _COM_Outptr_ IDxcBlobUtf16 **ppOutputName) = 0;
  400. virtual UINT32 GetNumOutputs() = 0;
  401. virtual DXC_OUT_KIND GetOutputByIndex(UINT32 Index) = 0;
  402. virtual DXC_OUT_KIND PrimaryOutput() = 0;
  403. };
  404. // Special names for extra output that should get written to specific streams
  405. #define DXC_EXTRA_OUTPUT_NAME_STDOUT L"*stdout*"
  406. #define DXC_EXTRA_OUTPUT_NAME_STDERR L"*stderr*"
  407. CROSS_PLATFORM_UUIDOF(IDxcExtraOutputs, "319b37a2-a5c2-494a-a5de-4801b2faf989")
  408. struct IDxcExtraOutputs : public IUnknown {
  409. virtual UINT32 STDMETHODCALLTYPE GetOutputCount() = 0;
  410. virtual HRESULT STDMETHODCALLTYPE GetOutput(_In_ UINT32 uIndex,
  411. _In_ REFIID iid, _COM_Outptr_opt_result_maybenull_ void **ppvObject,
  412. _COM_Outptr_opt_result_maybenull_ IDxcBlobUtf16 **ppOutputType,
  413. _COM_Outptr_opt_result_maybenull_ IDxcBlobUtf16 **ppOutputName) = 0;
  414. };
  415. CROSS_PLATFORM_UUIDOF(IDxcCompiler3, "228B4687-5A6A-4730-900C-9702B2203F54")
  416. struct IDxcCompiler3 : public IUnknown {
  417. // Compile a single entry point to the target shader model,
  418. // Compile a library to a library target (-T lib_*),
  419. // Compile a root signature (-T rootsig_*), or
  420. // Preprocess HLSL source (-P)
  421. virtual HRESULT STDMETHODCALLTYPE Compile(
  422. _In_ const DxcBuffer *pSource, // Source text to compile
  423. _In_opt_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments
  424. _In_ UINT32 argCount, // Number of arguments
  425. _In_opt_ IDxcIncludeHandler *pIncludeHandler, // user-provided interface to handle #include directives (optional)
  426. _In_ REFIID riid, _Out_ LPVOID *ppResult // IDxcResult: status, buffer, and errors
  427. ) = 0;
  428. // Disassemble a program.
  429. virtual HRESULT STDMETHODCALLTYPE Disassemble(
  430. _In_ const DxcBuffer *pObject, // Program to disassemble: dxil container or bitcode.
  431. _In_ REFIID riid, _Out_ LPVOID *ppResult // IDxcResult: status, disassembly text, and errors
  432. ) = 0;
  433. };
  434. static const UINT32 DxcValidatorFlags_Default = 0;
  435. static const UINT32 DxcValidatorFlags_InPlaceEdit = 1; // Validator is allowed to update shader blob in-place.
  436. static const UINT32 DxcValidatorFlags_RootSignatureOnly = 2;
  437. static const UINT32 DxcValidatorFlags_ModuleOnly = 4;
  438. static const UINT32 DxcValidatorFlags_ValidMask = 0x7;
  439. CROSS_PLATFORM_UUIDOF(IDxcValidator, "A6E82BD2-1FD7-4826-9811-2857E797F49A")
  440. struct IDxcValidator : public IUnknown {
  441. // Validate a shader.
  442. virtual HRESULT STDMETHODCALLTYPE Validate(
  443. _In_ IDxcBlob *pShader, // Shader to validate.
  444. _In_ UINT32 Flags, // Validation flags.
  445. _COM_Outptr_ IDxcOperationResult **ppResult // Validation output status, buffer, and errors
  446. ) = 0;
  447. };
  448. CROSS_PLATFORM_UUIDOF(IDxcValidator2, "458e1fd1-b1b2-4750-a6e1-9c10f03bed92")
  449. struct IDxcValidator2 : public IDxcValidator {
  450. // Validate a shader.
  451. virtual HRESULT STDMETHODCALLTYPE ValidateWithDebug(
  452. _In_ IDxcBlob *pShader, // Shader to validate.
  453. _In_ UINT32 Flags, // Validation flags.
  454. _In_opt_ DxcBuffer *pOptDebugBitcode, // Optional debug module bitcode to provide line numbers
  455. _COM_Outptr_ IDxcOperationResult **ppResult // Validation output status, buffer, and errors
  456. ) = 0;
  457. };
  458. CROSS_PLATFORM_UUIDOF(IDxcContainerBuilder, "334b1f50-2292-4b35-99a1-25588d8c17fe")
  459. struct IDxcContainerBuilder : public IUnknown {
  460. virtual HRESULT STDMETHODCALLTYPE Load(_In_ IDxcBlob *pDxilContainerHeader) = 0; // Loads DxilContainer to the builder
  461. virtual HRESULT STDMETHODCALLTYPE AddPart(_In_ UINT32 fourCC, _In_ IDxcBlob *pSource) = 0; // Part to add to the container
  462. virtual HRESULT STDMETHODCALLTYPE RemovePart(_In_ UINT32 fourCC) = 0; // Remove the part with fourCC
  463. virtual HRESULT STDMETHODCALLTYPE SerializeContainer(_Out_ IDxcOperationResult **ppResult) = 0; // Builds a container of the given container builder state
  464. };
  465. CROSS_PLATFORM_UUIDOF(IDxcAssembler, "091f7a26-1c1f-4948-904b-e6e3a8a771d5")
  466. struct IDxcAssembler : public IUnknown {
  467. // Assemble dxil in ll or llvm bitcode to DXIL container.
  468. virtual HRESULT STDMETHODCALLTYPE AssembleToContainer(
  469. _In_ IDxcBlob *pShader, // Shader to assemble.
  470. _COM_Outptr_ IDxcOperationResult **ppResult // Assembly output status, buffer, and errors
  471. ) = 0;
  472. };
  473. CROSS_PLATFORM_UUIDOF(IDxcContainerReflection, "d2c21b26-8350-4bdc-976a-331ce6f4c54c")
  474. struct IDxcContainerReflection : public IUnknown {
  475. virtual HRESULT STDMETHODCALLTYPE Load(_In_ IDxcBlob *pContainer) = 0; // Container to load.
  476. virtual HRESULT STDMETHODCALLTYPE GetPartCount(_Out_ UINT32 *pResult) = 0;
  477. virtual HRESULT STDMETHODCALLTYPE GetPartKind(UINT32 idx, _Out_ UINT32 *pResult) = 0;
  478. virtual HRESULT STDMETHODCALLTYPE GetPartContent(UINT32 idx, _COM_Outptr_ IDxcBlob **ppResult) = 0;
  479. virtual HRESULT STDMETHODCALLTYPE FindFirstPartKind(UINT32 kind, _Out_ UINT32 *pResult) = 0;
  480. virtual HRESULT STDMETHODCALLTYPE GetPartReflection(UINT32 idx, REFIID iid, void **ppvObject) = 0;
  481. };
  482. CROSS_PLATFORM_UUIDOF(IDxcOptimizerPass, "AE2CD79F-CC22-453F-9B6B-B124E7A5204C")
  483. struct IDxcOptimizerPass : public IUnknown {
  484. virtual HRESULT STDMETHODCALLTYPE GetOptionName(_COM_Outptr_ LPWSTR *ppResult) = 0;
  485. virtual HRESULT STDMETHODCALLTYPE GetDescription(_COM_Outptr_ LPWSTR *ppResult) = 0;
  486. virtual HRESULT STDMETHODCALLTYPE GetOptionArgCount(_Out_ UINT32 *pCount) = 0;
  487. virtual HRESULT STDMETHODCALLTYPE GetOptionArgName(UINT32 argIndex, _COM_Outptr_ LPWSTR *ppResult) = 0;
  488. virtual HRESULT STDMETHODCALLTYPE GetOptionArgDescription(UINT32 argIndex, _COM_Outptr_ LPWSTR *ppResult) = 0;
  489. };
  490. CROSS_PLATFORM_UUIDOF(IDxcOptimizer, "25740E2E-9CBA-401B-9119-4FB42F39F270")
  491. struct IDxcOptimizer : public IUnknown {
  492. virtual HRESULT STDMETHODCALLTYPE GetAvailablePassCount(_Out_ UINT32 *pCount) = 0;
  493. virtual HRESULT STDMETHODCALLTYPE GetAvailablePass(UINT32 index, _COM_Outptr_ IDxcOptimizerPass** ppResult) = 0;
  494. virtual HRESULT STDMETHODCALLTYPE RunOptimizer(IDxcBlob *pBlob,
  495. _In_count_(optionCount) LPCWSTR *ppOptions, UINT32 optionCount,
  496. _COM_Outptr_ IDxcBlob **pOutputModule,
  497. _COM_Outptr_opt_ IDxcBlobEncoding **ppOutputText) = 0;
  498. };
  499. static const UINT32 DxcVersionInfoFlags_None = 0;
  500. static const UINT32 DxcVersionInfoFlags_Debug = 1; // Matches VS_FF_DEBUG
  501. static const UINT32 DxcVersionInfoFlags_Internal = 2; // Internal Validator (non-signing)
  502. CROSS_PLATFORM_UUIDOF(IDxcVersionInfo, "b04f5b50-2059-4f12-a8ff-a1e0cde1cc7e")
  503. struct IDxcVersionInfo : public IUnknown {
  504. virtual HRESULT STDMETHODCALLTYPE GetVersion(_Out_ UINT32 *pMajor, _Out_ UINT32 *pMinor) = 0;
  505. virtual HRESULT STDMETHODCALLTYPE GetFlags(_Out_ UINT32 *pFlags) = 0;
  506. };
  507. CROSS_PLATFORM_UUIDOF(IDxcVersionInfo2, "fb6904c4-42f0-4b62-9c46-983af7da7c83")
  508. struct IDxcVersionInfo2 : public IDxcVersionInfo {
  509. virtual HRESULT STDMETHODCALLTYPE GetCommitInfo(
  510. _Out_ UINT32 *pCommitCount, // The total number commits.
  511. _Outptr_result_z_ char **pCommitHash // The SHA of the latest commit. (Must be CoTaskMemFree()'d!)
  512. ) = 0;
  513. };
  514. CROSS_PLATFORM_UUIDOF(IDxcVersionInfo3, "5e13e843-9d25-473c-9ad2-03b2d0b44b1e")
  515. struct IDxcVersionInfo3 : public IUnknown {
  516. virtual HRESULT STDMETHODCALLTYPE GetCustomVersionString(
  517. _Outptr_result_z_ char **pVersionString // Custom version string for compiler. (Must be CoTaskMemFree()'d!)
  518. ) = 0;
  519. };
  520. struct DxcArgPair {
  521. const WCHAR *pName;
  522. const WCHAR *pValue;
  523. };
  524. CROSS_PLATFORM_UUIDOF(IDxcPdbUtils, "E6C9647E-9D6A-4C3B-B94C-524B5A6C343D")
  525. struct IDxcPdbUtils : public IUnknown {
  526. virtual HRESULT STDMETHODCALLTYPE Load(_In_ IDxcBlob *pPdbOrDxil) = 0;
  527. virtual HRESULT STDMETHODCALLTYPE GetSourceCount(_Out_ UINT32 *pCount) = 0;
  528. virtual HRESULT STDMETHODCALLTYPE GetSource(_In_ UINT32 uIndex, _COM_Outptr_ IDxcBlobEncoding **ppResult) = 0;
  529. virtual HRESULT STDMETHODCALLTYPE GetSourceName(_In_ UINT32 uIndex, _Outptr_result_z_ BSTR *pResult) = 0;
  530. virtual HRESULT STDMETHODCALLTYPE GetFlagCount(_Out_ UINT32 *pCount) = 0;
  531. virtual HRESULT STDMETHODCALLTYPE GetFlag(_In_ UINT32 uIndex, _Outptr_result_z_ BSTR *pResult) = 0;
  532. virtual HRESULT STDMETHODCALLTYPE GetArgCount(_Out_ UINT32 *pCount) = 0;
  533. virtual HRESULT STDMETHODCALLTYPE GetArg(_In_ UINT32 uIndex, _Outptr_result_z_ BSTR *pResult) = 0;
  534. virtual HRESULT STDMETHODCALLTYPE GetArgPairCount(_Out_ UINT32 *pCount) = 0;
  535. virtual HRESULT STDMETHODCALLTYPE GetArgPair(_In_ UINT32 uIndex, _Outptr_result_z_ BSTR *pName, _Outptr_result_z_ BSTR *pValue) = 0;
  536. virtual HRESULT STDMETHODCALLTYPE GetDefineCount(_Out_ UINT32 *pCount) = 0;
  537. virtual HRESULT STDMETHODCALLTYPE GetDefine(_In_ UINT32 uIndex, _Outptr_result_z_ BSTR *pResult) = 0;
  538. virtual HRESULT STDMETHODCALLTYPE GetTargetProfile(_Outptr_result_z_ BSTR *pResult) = 0;
  539. virtual HRESULT STDMETHODCALLTYPE GetEntryPoint(_Outptr_result_z_ BSTR *pResult) = 0;
  540. virtual HRESULT STDMETHODCALLTYPE GetMainFileName(_Outptr_result_z_ BSTR *pResult) = 0;
  541. virtual HRESULT STDMETHODCALLTYPE GetHash(_COM_Outptr_ IDxcBlob **ppResult) = 0;
  542. virtual HRESULT STDMETHODCALLTYPE GetName(_Outptr_result_z_ BSTR *pResult) = 0;
  543. virtual BOOL STDMETHODCALLTYPE IsFullPDB() = 0;
  544. virtual HRESULT STDMETHODCALLTYPE GetFullPDB(_COM_Outptr_ IDxcBlob **ppFullPDB) = 0;
  545. virtual HRESULT STDMETHODCALLTYPE GetVersionInfo(_COM_Outptr_ IDxcVersionInfo **ppVersionInfo) = 0;
  546. virtual HRESULT STDMETHODCALLTYPE SetCompiler(_In_ IDxcCompiler3 *pCompiler) = 0;
  547. virtual HRESULT STDMETHODCALLTYPE CompileForFullPDB(_COM_Outptr_ IDxcResult **ppResult) = 0;
  548. virtual HRESULT STDMETHODCALLTYPE OverrideArgs(_In_ DxcArgPair *pArgPairs, UINT32 uNumArgPairs) = 0;
  549. virtual HRESULT STDMETHODCALLTYPE OverrideRootSignature(_In_ const WCHAR *pRootSignature) = 0;
  550. };
  551. // Note: __declspec(selectany) requires 'extern'
  552. // On Linux __declspec(selectany) is removed and using 'extern' results in link error.
  553. #ifdef _MSC_VER
  554. #define CLSID_SCOPE __declspec(selectany) extern
  555. #else
  556. #define CLSID_SCOPE
  557. #endif
  558. CLSID_SCOPE const CLSID CLSID_DxcCompiler = {
  559. 0x73e22d93,
  560. 0xe6ce,
  561. 0x47f3,
  562. {0xb5, 0xbf, 0xf0, 0x66, 0x4f, 0x39, 0xc1, 0xb0}};
  563. // {EF6A8087-B0EA-4D56-9E45-D07E1A8B7806}
  564. CLSID_SCOPE const GUID CLSID_DxcLinker = {
  565. 0xef6a8087,
  566. 0xb0ea,
  567. 0x4d56,
  568. {0x9e, 0x45, 0xd0, 0x7e, 0x1a, 0x8b, 0x78, 0x6}};
  569. // {CD1F6B73-2AB0-484D-8EDC-EBE7A43CA09F}
  570. CLSID_SCOPE const CLSID CLSID_DxcDiaDataSource = {
  571. 0xcd1f6b73,
  572. 0x2ab0,
  573. 0x484d,
  574. {0x8e, 0xdc, 0xeb, 0xe7, 0xa4, 0x3c, 0xa0, 0x9f}};
  575. // {3E56AE82-224D-470F-A1A1-FE3016EE9F9D}
  576. CLSID_SCOPE const CLSID CLSID_DxcCompilerArgs = {
  577. 0x3e56ae82,
  578. 0x224d,
  579. 0x470f,
  580. {0xa1, 0xa1, 0xfe, 0x30, 0x16, 0xee, 0x9f, 0x9d}};
  581. // {6245D6AF-66E0-48FD-80B4-4D271796748C}
  582. CLSID_SCOPE const GUID CLSID_DxcLibrary = {
  583. 0x6245d6af,
  584. 0x66e0,
  585. 0x48fd,
  586. {0x80, 0xb4, 0x4d, 0x27, 0x17, 0x96, 0x74, 0x8c}};
  587. CLSID_SCOPE const GUID CLSID_DxcUtils = CLSID_DxcLibrary;
  588. // {8CA3E215-F728-4CF3-8CDD-88AF917587A1}
  589. CLSID_SCOPE const GUID CLSID_DxcValidator = {
  590. 0x8ca3e215,
  591. 0xf728,
  592. 0x4cf3,
  593. {0x8c, 0xdd, 0x88, 0xaf, 0x91, 0x75, 0x87, 0xa1}};
  594. // {D728DB68-F903-4F80-94CD-DCCF76EC7151}
  595. CLSID_SCOPE const GUID CLSID_DxcAssembler = {
  596. 0xd728db68,
  597. 0xf903,
  598. 0x4f80,
  599. {0x94, 0xcd, 0xdc, 0xcf, 0x76, 0xec, 0x71, 0x51}};
  600. // {b9f54489-55b8-400c-ba3a-1675e4728b91}
  601. CLSID_SCOPE const GUID CLSID_DxcContainerReflection = {
  602. 0xb9f54489,
  603. 0x55b8,
  604. 0x400c,
  605. {0xba, 0x3a, 0x16, 0x75, 0xe4, 0x72, 0x8b, 0x91}};
  606. // {AE2CD79F-CC22-453F-9B6B-B124E7A5204C}
  607. CLSID_SCOPE const GUID CLSID_DxcOptimizer = {
  608. 0xae2cd79f,
  609. 0xcc22,
  610. 0x453f,
  611. {0x9b, 0x6b, 0xb1, 0x24, 0xe7, 0xa5, 0x20, 0x4c}};
  612. // {94134294-411f-4574-b4d0-8741e25240d2}
  613. CLSID_SCOPE const GUID CLSID_DxcContainerBuilder = {
  614. 0x94134294,
  615. 0x411f,
  616. 0x4574,
  617. {0xb4, 0xd0, 0x87, 0x41, 0xe2, 0x52, 0x40, 0xd2}};
  618. // {54621dfb-f2ce-457e-ae8c-ec355faeec7c}
  619. CLSID_SCOPE const GUID CLSID_DxcPdbUtils = {
  620. 0x54621dfb,
  621. 0xf2ce,
  622. 0x457e,
  623. {0xae, 0x8c, 0xec, 0x35, 0x5f, 0xae, 0xec, 0x7c}};
  624. #endif