dxcapi.h 29 KB

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