dxcapi.h 31 KB

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