Path: blob/21.2-virgl/src/microsoft/compiler/dxcapi.h
4564 views
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///////////////////////////////////////////////////////////////////////////////1112#ifndef __DXC_API__13#define __DXC_API__1415#ifdef _WIN3216#ifndef DXC_API_IMPORT17#define DXC_API_IMPORT __declspec(dllimport)18#endif19#else20#ifndef DXC_API_IMPORT21#define DXC_API_IMPORT __attribute__ ((visibility ("default")))22#endif23#endif2425#ifdef _WIN322627#ifndef CROSS_PLATFORM_UUIDOF28// Warning: This macro exists in WinAdapter.h as well29#define CROSS_PLATFORM_UUIDOF(interface, spec) \30struct __declspec(uuid(spec)) interface;31#endif3233#else3435constexpr uint8_t nybble_from_hex(char c) {36return ((c >= '0' && c <= '9')37? (c - '0')38: ((c >= 'a' && c <= 'f')39? (c - 'a' + 10)40: ((c >= 'A' && c <= 'F') ? (c - 'A' + 10)41: /* Should be an error */ -1)));42}4344constexpr uint8_t byte_from_hex(char c1, char c2) {45return nybble_from_hex(c1) << 4 | nybble_from_hex(c2);46}4748constexpr uint8_t byte_from_hexstr(const char str[2]) {49return nybble_from_hex(str[0]) << 4 | nybble_from_hex(str[1]);50}5152constexpr GUID guid_from_string(const char str[37]) {53return GUID{ static_cast<uint32_t>(byte_from_hexstr(str)) << 24 |54static_cast<uint32_t>(byte_from_hexstr(str + 2)) << 16 |55static_cast<uint32_t>(byte_from_hexstr(str + 4)) << 8 |56byte_from_hexstr(str + 6),57static_cast<uint16_t>(58static_cast<uint16_t>(byte_from_hexstr(str + 9)) << 8 |59byte_from_hexstr(str + 11)),60static_cast<uint16_t>(61static_cast<uint16_t>(byte_from_hexstr(str + 14)) << 8 |62byte_from_hexstr(str + 16)),63{byte_from_hexstr(str + 19), byte_from_hexstr(str + 21),64byte_from_hexstr(str + 24), byte_from_hexstr(str + 26),65byte_from_hexstr(str + 28), byte_from_hexstr(str + 30),66byte_from_hexstr(str + 32), byte_from_hexstr(str + 34)} };67}6869#define CROSS_PLATFORM_UUIDOF(interface, spec) \70struct interface; \71template <> constexpr GUID uuidof<interface>() { \72constexpr IID _IID = guid_from_string(spec); \73return _IID; \74}757677CROSS_PLATFORM_UUIDOF(INoMarshal, "ECC8691B-C1DB-4DC0-855E-65F6C551AF49")78struct INoMarshal : public IUnknown {};7980CROSS_PLATFORM_UUIDOF(IMalloc, "00000002-0000-0000-C000-000000000046")81struct IMalloc : public IUnknown {82virtual void *Alloc(size_t size);83virtual void *Realloc(void *ptr, size_t size);84virtual void Free(void *ptr);85virtual HRESULT QueryInterface(REFIID riid, void **ppvObject);86};8788CROSS_PLATFORM_UUIDOF(ISequentialStream, "0C733A30-2A1C-11CE-ADE5-00AA0044773D")89struct ISequentialStream : public IUnknown {90virtual HRESULT Read(void *pv, ULONG cb, ULONG *pcbRead) = 0;91virtual HRESULT Write(const void *pv, ULONG cb, ULONG *pcbWritten) = 0;92};9394CROSS_PLATFORM_UUIDOF(IStream, "0000000c-0000-0000-C000-000000000046")95struct IStream : public ISequentialStream {96virtual HRESULT Seek(LARGE_INTEGER dlibMove, DWORD dwOrigin,97ULARGE_INTEGER *plibNewPosition) = 0;98virtual HRESULT SetSize(ULARGE_INTEGER libNewSize) = 0;99virtual HRESULT CopyTo(IStream *pstm, ULARGE_INTEGER cb,100ULARGE_INTEGER *pcbRead,101ULARGE_INTEGER *pcbWritten) = 0;102103virtual HRESULT Commit(DWORD grfCommitFlags) = 0;104105virtual HRESULT Revert(void) = 0;106107virtual HRESULT LockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb,108DWORD dwLockType) = 0;109110virtual HRESULT UnlockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb,111DWORD dwLockType) = 0;112113virtual HRESULT Stat(STATSTG *pstatstg, DWORD grfStatFlag) = 0;114115virtual HRESULT Clone(IStream **ppstm) = 0;116};117118#endif119120struct IMalloc;121122struct IDxcIncludeHandler;123124typedef HRESULT (__stdcall *DxcCreateInstanceProc)(125_In_ REFCLSID rclsid,126_In_ REFIID riid,127_Out_ LPVOID* ppv128);129130typedef HRESULT(__stdcall *DxcCreateInstance2Proc)(131_In_ IMalloc *pMalloc,132_In_ REFCLSID rclsid,133_In_ REFIID riid,134_Out_ LPVOID* ppv135);136137/// <summary>138/// Creates a single uninitialized object of the class associated with a specified CLSID.139/// </summary>140/// <param name="rclsid">141/// The CLSID associated with the data and code that will be used to create the object.142/// </param>143/// <param name="riid">144/// A reference to the identifier of the interface to be used to communicate145/// with the object.146/// </param>147/// <param name="ppv">148/// Address of pointer variable that receives the interface pointer requested149/// in riid. Upon successful return, *ppv contains the requested interface150/// pointer. Upon failure, *ppv contains NULL.</param>151/// <remarks>152/// While this function is similar to CoCreateInstance, there is no COM involvement.153/// </remarks>154155extern "C"156DXC_API_IMPORT HRESULT __stdcall DxcCreateInstance(157_In_ REFCLSID rclsid,158_In_ REFIID riid,159_Out_ LPVOID* ppv160);161162extern "C"163DXC_API_IMPORT HRESULT __stdcall DxcCreateInstance2(164_In_ IMalloc *pMalloc,165_In_ REFCLSID rclsid,166_In_ REFIID riid,167_Out_ LPVOID* ppv168);169170// For convenience, equivalent definitions to CP_UTF8 and CP_UTF16.171#define DXC_CP_UTF8 65001172#define DXC_CP_UTF16 1200173// Use DXC_CP_ACP for: Binary; ANSI Text; Autodetect UTF with BOM174#define DXC_CP_ACP 0175176// This flag indicates that the shader hash was computed taking into account source information (-Zss)177#define DXC_HASHFLAG_INCLUDES_SOURCE 1178179// Hash digest type for ShaderHash180typedef struct DxcShaderHash {181UINT32 Flags; // DXC_HASHFLAG_*182BYTE HashDigest[16];183} DxcShaderHash;184185#define DXC_FOURCC(ch0, ch1, ch2, ch3) ( \186(UINT32)(UINT8)(ch0) | (UINT32)(UINT8)(ch1) << 8 | \187(UINT32)(UINT8)(ch2) << 16 | (UINT32)(UINT8)(ch3) << 24 \188)189#define DXC_PART_PDB DXC_FOURCC('I', 'L', 'D', 'B')190#define DXC_PART_PDB_NAME DXC_FOURCC('I', 'L', 'D', 'N')191#define DXC_PART_PRIVATE_DATA DXC_FOURCC('P', 'R', 'I', 'V')192#define DXC_PART_ROOT_SIGNATURE DXC_FOURCC('R', 'T', 'S', '0')193#define DXC_PART_DXIL DXC_FOURCC('D', 'X', 'I', 'L')194#define DXC_PART_REFLECTION_DATA DXC_FOURCC('S', 'T', 'A', 'T')195#define DXC_PART_SHADER_HASH DXC_FOURCC('H', 'A', 'S', 'H')196#define DXC_PART_INPUT_SIGNATURE DXC_FOURCC('I', 'S', 'G', '1')197#define DXC_PART_OUTPUT_SIGNATURE DXC_FOURCC('O', 'S', 'G', '1')198#define DXC_PART_PATCH_CONSTANT_SIGNATURE DXC_FOURCC('P', 'S', 'G', '1')199200// Some option arguments are defined here for continuity with D3DCompile interface201#define DXC_ARG_DEBUG L"-Zi"202#define DXC_ARG_SKIP_VALIDATION L"-Vd"203#define DXC_ARG_SKIP_OPTIMIZATIONS L"-Od"204#define DXC_ARG_PACK_MATRIX_ROW_MAJOR L"-Zpr"205#define DXC_ARG_PACK_MATRIX_COLUMN_MAJOR L"-Zpc"206#define DXC_ARG_AVOID_FLOW_CONTROL L"-Gfa"207#define DXC_ARG_PREFER_FLOW_CONTROL L"-Gfp"208#define DXC_ARG_ENABLE_STRICTNESS L"-Ges"209#define DXC_ARG_ENABLE_BACKWARDS_COMPATIBILITY L"-Gec"210#define DXC_ARG_IEEE_STRICTNESS L"-Gis"211#define DXC_ARG_OPTIMIZATION_LEVEL0 L"-O0"212#define DXC_ARG_OPTIMIZATION_LEVEL1 L"-O1"213#define DXC_ARG_OPTIMIZATION_LEVEL2 L"-O2"214#define DXC_ARG_OPTIMIZATION_LEVEL3 L"-O3"215#define DXC_ARG_WARNINGS_ARE_ERRORS L"-WX"216#define DXC_ARG_RESOURCES_MAY_ALIAS L"-res_may_alias"217#define DXC_ARG_ALL_RESOURCES_BOUND L"-all_resources_bound"218#define DXC_ARG_DEBUG_NAME_FOR_SOURCE L"-Zss"219#define DXC_ARG_DEBUG_NAME_FOR_BINARY L"-Zsb"220221// IDxcBlob is an alias of ID3D10Blob and ID3DBlob222CROSS_PLATFORM_UUIDOF(IDxcBlob, "8BA5FB08-5195-40e2-AC58-0D989C3A0102")223struct IDxcBlob : public IUnknown {224public:225virtual LPVOID STDMETHODCALLTYPE GetBufferPointer(void) = 0;226virtual SIZE_T STDMETHODCALLTYPE GetBufferSize(void) = 0;227};228229CROSS_PLATFORM_UUIDOF(IDxcBlobEncoding, "7241d424-2646-4191-97c0-98e96e42fc68")230struct IDxcBlobEncoding : public IDxcBlob {231public:232virtual HRESULT STDMETHODCALLTYPE GetEncoding(_Out_ BOOL *pKnown,233_Out_ UINT32 *pCodePage) = 0;234};235236// Notes on IDxcBlobUtf16 and IDxcBlobUtf8237// These guarantee null-terminated text and the stated encoding.238// GetBufferSize() will return the size in bytes, including null-terminator239// GetStringLength() will return the length in characters, excluding the null-terminator240// Name strings will use IDxcBlobUtf16, while other string output blobs,241// such as errors/warnings, preprocessed HLSL, or other text will be based242// on the -encoding option.243244// The API will use this interface for output name strings245CROSS_PLATFORM_UUIDOF(IDxcBlobUtf16, "A3F84EAB-0FAA-497E-A39C-EE6ED60B2D84")246struct IDxcBlobUtf16 : public IDxcBlobEncoding {247public:248virtual LPCWSTR STDMETHODCALLTYPE GetStringPointer(void) = 0;249virtual SIZE_T STDMETHODCALLTYPE GetStringLength(void) = 0;250};251CROSS_PLATFORM_UUIDOF(IDxcBlobUtf8, "3DA636C9-BA71-4024-A301-30CBF125305B")252struct IDxcBlobUtf8 : public IDxcBlobEncoding {253public:254virtual LPCSTR STDMETHODCALLTYPE GetStringPointer(void) = 0;255virtual SIZE_T STDMETHODCALLTYPE GetStringLength(void) = 0;256};257258CROSS_PLATFORM_UUIDOF(IDxcIncludeHandler, "7f61fc7d-950d-467f-b3e3-3c02fb49187c")259struct IDxcIncludeHandler : public IUnknown {260virtual HRESULT STDMETHODCALLTYPE LoadSource(261_In_z_ LPCWSTR pFilename, // Candidate filename.262_COM_Outptr_result_maybenull_ IDxcBlob **ppIncludeSource // Resultant source object for included file, nullptr if not found.263) = 0;264};265266// Structure for supplying bytes or text input to Dxc APIs.267// Use Encoding = 0 for non-text bytes, ANSI text, or unknown with BOM.268typedef struct DxcBuffer {269LPCVOID Ptr;270SIZE_T Size;271UINT Encoding;272} DxcText;273274struct DxcDefine {275LPCWSTR Name;276_Maybenull_ LPCWSTR Value;277};278279CROSS_PLATFORM_UUIDOF(IDxcCompilerArgs, "73EFFE2A-70DC-45F8-9690-EFF64C02429D")280struct IDxcCompilerArgs : public IUnknown {281// Pass GetArguments() and GetCount() to Compile282virtual LPCWSTR* STDMETHODCALLTYPE GetArguments() = 0;283virtual UINT32 STDMETHODCALLTYPE GetCount() = 0;284285// Add additional arguments or defines here, if desired.286virtual HRESULT STDMETHODCALLTYPE AddArguments(287_In_opt_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments to add288_In_ UINT32 argCount // Number of arguments to add289) = 0;290virtual HRESULT STDMETHODCALLTYPE AddArgumentsUTF8(291_In_opt_count_(argCount)LPCSTR *pArguments, // Array of pointers to UTF-8 arguments to add292_In_ UINT32 argCount // Number of arguments to add293) = 0;294virtual HRESULT STDMETHODCALLTYPE AddDefines(295_In_count_(defineCount) const DxcDefine *pDefines, // Array of defines296_In_ UINT32 defineCount // Number of defines297) = 0;298};299300//////////////////////////301// Legacy Interfaces302/////////////////////////303304// NOTE: IDxcUtils replaces IDxcLibrary305CROSS_PLATFORM_UUIDOF(IDxcLibrary, "e5204dc7-d18c-4c3c-bdfb-851673980fe7")306struct IDxcLibrary : public IUnknown {307virtual HRESULT STDMETHODCALLTYPE SetMalloc(_In_opt_ IMalloc *pMalloc) = 0;308virtual HRESULT STDMETHODCALLTYPE CreateBlobFromBlob(309_In_ IDxcBlob *pBlob, UINT32 offset, UINT32 length, _COM_Outptr_ IDxcBlob **ppResult) = 0;310virtual HRESULT STDMETHODCALLTYPE CreateBlobFromFile(311_In_z_ LPCWSTR pFileName, _In_opt_ UINT32* codePage,312_COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;313virtual HRESULT STDMETHODCALLTYPE CreateBlobWithEncodingFromPinned(314_In_bytecount_(size) LPCVOID pText, UINT32 size, UINT32 codePage,315_COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;316virtual HRESULT STDMETHODCALLTYPE CreateBlobWithEncodingOnHeapCopy(317_In_bytecount_(size) LPCVOID pText, UINT32 size, UINT32 codePage,318_COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;319virtual HRESULT STDMETHODCALLTYPE CreateBlobWithEncodingOnMalloc(320_In_bytecount_(size) LPCVOID pText, IMalloc *pIMalloc, UINT32 size, UINT32 codePage,321_COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;322virtual HRESULT STDMETHODCALLTYPE CreateIncludeHandler(323_COM_Outptr_ IDxcIncludeHandler **ppResult) = 0;324virtual HRESULT STDMETHODCALLTYPE CreateStreamFromBlobReadOnly(325_In_ IDxcBlob *pBlob, _COM_Outptr_ IStream **ppStream) = 0;326virtual HRESULT STDMETHODCALLTYPE GetBlobAsUtf8(327_In_ IDxcBlob *pBlob, _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;328virtual HRESULT STDMETHODCALLTYPE GetBlobAsUtf16(329_In_ IDxcBlob *pBlob, _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;330};331332// NOTE: IDxcResult replaces IDxcOperationResult333CROSS_PLATFORM_UUIDOF(IDxcOperationResult, "CEDB484A-D4E9-445A-B991-CA21CA157DC2")334struct IDxcOperationResult : public IUnknown {335virtual HRESULT STDMETHODCALLTYPE GetStatus(_Out_ HRESULT *pStatus) = 0;336337// GetResult returns the main result of the operation.338// This corresponds to:339// DXC_OUT_OBJECT - Compile() with shader or library target340// DXC_OUT_DISASSEMBLY - Disassemble()341// DXC_OUT_HLSL - Compile() with -P342// DXC_OUT_ROOT_SIGNATURE - Compile() with rootsig_* target343virtual HRESULT STDMETHODCALLTYPE GetResult(_COM_Outptr_result_maybenull_ IDxcBlob **ppResult) = 0;344345// GetErrorBuffer Corresponds to DXC_OUT_ERRORS.346virtual HRESULT STDMETHODCALLTYPE GetErrorBuffer(_COM_Outptr_result_maybenull_ IDxcBlobEncoding **ppErrors) = 0;347};348349// NOTE: IDxcCompiler3 replaces IDxcCompiler and IDxcCompiler2350CROSS_PLATFORM_UUIDOF(IDxcCompiler, "8c210bf3-011f-4422-8d70-6f9acb8db617")351struct IDxcCompiler : public IUnknown {352// Compile a single entry point to the target shader model353virtual HRESULT STDMETHODCALLTYPE Compile(354_In_ IDxcBlob *pSource, // Source text to compile355_In_opt_z_ LPCWSTR pSourceName, // Optional file name for pSource. Used in errors and include handlers.356_In_opt_z_ LPCWSTR pEntryPoint, // entry point name357_In_z_ LPCWSTR pTargetProfile, // shader profile to compile358_In_opt_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments359_In_ UINT32 argCount, // Number of arguments360_In_count_(defineCount)361const DxcDefine *pDefines, // Array of defines362_In_ UINT32 defineCount, // Number of defines363_In_opt_ IDxcIncludeHandler *pIncludeHandler, // user-provided interface to handle #include directives (optional)364_COM_Outptr_ IDxcOperationResult **ppResult // Compiler output status, buffer, and errors365) = 0;366367// Preprocess source text368virtual HRESULT STDMETHODCALLTYPE Preprocess(369_In_ IDxcBlob *pSource, // Source text to preprocess370_In_opt_z_ LPCWSTR pSourceName, // Optional file name for pSource. Used in errors and include handlers.371_In_opt_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments372_In_ UINT32 argCount, // Number of arguments373_In_count_(defineCount)374const DxcDefine *pDefines, // Array of defines375_In_ UINT32 defineCount, // Number of defines376_In_opt_ IDxcIncludeHandler *pIncludeHandler, // user-provided interface to handle #include directives (optional)377_COM_Outptr_ IDxcOperationResult **ppResult // Preprocessor output status, buffer, and errors378) = 0;379380// Disassemble a program.381virtual HRESULT STDMETHODCALLTYPE Disassemble(382_In_ IDxcBlob *pSource, // Program to disassemble.383_COM_Outptr_ IDxcBlobEncoding **ppDisassembly // Disassembly text.384) = 0;385};386387// NOTE: IDxcCompiler3 replaces IDxcCompiler and IDxcCompiler2388CROSS_PLATFORM_UUIDOF(IDxcCompiler2, "A005A9D9-B8BB-4594-B5C9-0E633BEC4D37")389struct IDxcCompiler2 : public IDxcCompiler {390// Compile a single entry point to the target shader model with debug information.391virtual HRESULT STDMETHODCALLTYPE CompileWithDebug(392_In_ IDxcBlob *pSource, // Source text to compile393_In_opt_z_ LPCWSTR pSourceName, // Optional file name for pSource. Used in errors and include handlers.394_In_opt_z_ LPCWSTR pEntryPoint, // Entry point name395_In_z_ LPCWSTR pTargetProfile, // Shader profile to compile396_In_opt_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments397_In_ UINT32 argCount, // Number of arguments398_In_count_(defineCount)399const DxcDefine *pDefines, // Array of defines400_In_ UINT32 defineCount, // Number of defines401_In_opt_ IDxcIncludeHandler *pIncludeHandler, // user-provided interface to handle #include directives (optional)402_COM_Outptr_ IDxcOperationResult **ppResult, // Compiler output status, buffer, and errors403_Outptr_opt_result_z_ LPWSTR *ppDebugBlobName,// Suggested file name for debug blob. (Must be HeapFree()'d!)404_COM_Outptr_opt_ IDxcBlob **ppDebugBlob // Debug blob405) = 0;406};407408CROSS_PLATFORM_UUIDOF(IDxcLinker, "F1B5BE2A-62DD-4327-A1C2-42AC1E1E78E6")409struct IDxcLinker : public IUnknown {410public:411// Register a library with name to ref it later.412virtual HRESULT RegisterLibrary(413_In_opt_ LPCWSTR pLibName, // Name of the library.414_In_ IDxcBlob *pLib // Library blob.415) = 0;416417// Links the shader and produces a shader blob that the Direct3D runtime can418// use.419virtual HRESULT STDMETHODCALLTYPE Link(420_In_opt_ LPCWSTR pEntryName, // Entry point name421_In_ LPCWSTR pTargetProfile, // shader profile to link422_In_count_(libCount)423const LPCWSTR *pLibNames, // Array of library names to link424_In_ UINT32 libCount, // Number of libraries to link425_In_opt_count_(argCount) const LPCWSTR *pArguments, // Array of pointers to arguments426_In_ UINT32 argCount, // Number of arguments427_COM_Outptr_428IDxcOperationResult **ppResult // Linker output status, buffer, and errors429) = 0;430};431432/////////////////////////433// Latest interfaces. Please use these434////////////////////////435436// NOTE: IDxcUtils replaces IDxcLibrary437CROSS_PLATFORM_UUIDOF(IDxcUtils, "4605C4CB-2019-492A-ADA4-65F20BB7D67F")438struct IDxcUtils : public IUnknown {439// Create a sub-blob that holds a reference to the outer blob and points to its memory.440virtual HRESULT STDMETHODCALLTYPE CreateBlobFromBlob(441_In_ IDxcBlob *pBlob, UINT32 offset, UINT32 length, _COM_Outptr_ IDxcBlob **ppResult) = 0;442443// For codePage, use 0 (or DXC_CP_ACP) for raw binary or ANSI code page444445// Creates a blob referencing existing memory, with no copy.446// User must manage the memory lifetime separately.447// (was: CreateBlobWithEncodingFromPinned)448virtual HRESULT STDMETHODCALLTYPE CreateBlobFromPinned(449_In_bytecount_(size) LPCVOID pData, UINT32 size, UINT32 codePage,450_COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;451452// Create blob, taking ownership of memory allocated with supplied allocator.453// (was: CreateBlobWithEncodingOnMalloc)454virtual HRESULT STDMETHODCALLTYPE MoveToBlob(455_In_bytecount_(size) LPCVOID pData, IMalloc *pIMalloc, UINT32 size, UINT32 codePage,456_COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;457458////459// New blobs and copied contents are allocated with the current allocator460461// Copy blob contents to memory owned by the new blob.462// (was: CreateBlobWithEncodingOnHeapCopy)463virtual HRESULT STDMETHODCALLTYPE CreateBlob(464_In_bytecount_(size) LPCVOID pData, UINT32 size, UINT32 codePage,465_COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;466467// (was: CreateBlobFromFile)468virtual HRESULT STDMETHODCALLTYPE LoadFile(469_In_z_ LPCWSTR pFileName, _In_opt_ UINT32* pCodePage,470_COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;471472virtual HRESULT STDMETHODCALLTYPE CreateReadOnlyStreamFromBlob(473_In_ IDxcBlob *pBlob, _COM_Outptr_ IStream **ppStream) = 0;474475// Create default file-based include handler476virtual HRESULT STDMETHODCALLTYPE CreateDefaultIncludeHandler(477_COM_Outptr_ IDxcIncludeHandler **ppResult) = 0;478479// Convert or return matching encoded text blobs480virtual HRESULT STDMETHODCALLTYPE GetBlobAsUtf8(481_In_ IDxcBlob *pBlob, _COM_Outptr_ IDxcBlobUtf8 **pBlobEncoding) = 0;482virtual HRESULT STDMETHODCALLTYPE GetBlobAsUtf16(483_In_ IDxcBlob *pBlob, _COM_Outptr_ IDxcBlobUtf16 **pBlobEncoding) = 0;484485virtual HRESULT STDMETHODCALLTYPE GetDxilContainerPart(486_In_ const DxcBuffer *pShader,487_In_ UINT32 DxcPart,488_Outptr_result_nullonfailure_ void **ppPartData,489_Out_ UINT32 *pPartSizeInBytes) = 0;490491// Create reflection interface from serialized Dxil container, or DXC_PART_REFLECTION_DATA.492// TBD: Require part header for RDAT? (leaning towards yes)493virtual HRESULT STDMETHODCALLTYPE CreateReflection(494_In_ const DxcBuffer *pData, REFIID iid, void **ppvReflection) = 0;495496virtual HRESULT STDMETHODCALLTYPE BuildArguments(497_In_opt_z_ LPCWSTR pSourceName, // Optional file name for pSource. Used in errors and include handlers.498_In_opt_z_ LPCWSTR pEntryPoint, // Entry point name. (-E)499_In_z_ LPCWSTR pTargetProfile, // Shader profile to compile. (-T)500_In_opt_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments501_In_ UINT32 argCount, // Number of arguments502_In_count_(defineCount)503const DxcDefine *pDefines, // Array of defines504_In_ UINT32 defineCount, // Number of defines505_COM_Outptr_ IDxcCompilerArgs **ppArgs // Arguments you can use with Compile() method506) = 0;507508// Takes the shader PDB and returns the hash and the container inside it509virtual HRESULT STDMETHODCALLTYPE GetPDBContents(510_In_ IDxcBlob *pPDBBlob, _COM_Outptr_ IDxcBlob **ppHash, _COM_Outptr_ IDxcBlob **ppContainer) = 0;511};512513// For use with IDxcResult::[Has|Get]Output dxcOutKind argument514// Note: text outputs returned from version 2 APIs are UTF-8 or UTF-16 based on -encoding option515typedef enum DXC_OUT_KIND {516DXC_OUT_NONE = 0,517DXC_OUT_OBJECT = 1, // IDxcBlob - Shader or library object518DXC_OUT_ERRORS = 2, // IDxcBlobUtf8 or IDxcBlobUtf16519DXC_OUT_PDB = 3, // IDxcBlob520DXC_OUT_SHADER_HASH = 4, // IDxcBlob - DxcShaderHash of shader or shader with source info (-Zsb/-Zss)521DXC_OUT_DISASSEMBLY = 5, // IDxcBlobUtf8 or IDxcBlobUtf16 - from Disassemble522DXC_OUT_HLSL = 6, // IDxcBlobUtf8 or IDxcBlobUtf16 - from Preprocessor or Rewriter523DXC_OUT_TEXT = 7, // IDxcBlobUtf8 or IDxcBlobUtf16 - other text, such as -ast-dump or -Odump524DXC_OUT_REFLECTION = 8, // IDxcBlob - RDAT part with reflection data525DXC_OUT_ROOT_SIGNATURE = 9, // IDxcBlob - Serialized root signature output526DXC_OUT_EXTRA_OUTPUTS = 10,// IDxcExtraResults - Extra outputs527528DXC_OUT_FORCE_DWORD = 0xFFFFFFFF529} DXC_OUT_KIND;530531CROSS_PLATFORM_UUIDOF(IDxcResult, "58346CDA-DDE7-4497-9461-6F87AF5E0659")532struct IDxcResult : public IDxcOperationResult {533virtual BOOL STDMETHODCALLTYPE HasOutput(_In_ DXC_OUT_KIND dxcOutKind) = 0;534virtual HRESULT STDMETHODCALLTYPE GetOutput(_In_ DXC_OUT_KIND dxcOutKind,535_In_ REFIID iid, _COM_Outptr_opt_result_maybenull_ void **ppvObject,536_COM_Outptr_ IDxcBlobUtf16 **ppOutputName) = 0;537538virtual UINT32 GetNumOutputs() = 0;539virtual DXC_OUT_KIND GetOutputByIndex(UINT32 Index) = 0;540virtual DXC_OUT_KIND PrimaryOutput() = 0;541};542543// Special names for extra output that should get written to specific streams544#define DXC_EXTRA_OUTPUT_NAME_STDOUT L"*stdout*"545#define DXC_EXTRA_OUTPUT_NAME_STDERR L"*stderr*"546547CROSS_PLATFORM_UUIDOF(IDxcExtraOutputs, "319b37a2-a5c2-494a-a5de-4801b2faf989")548struct IDxcExtraOutputs : public IUnknown {549550virtual UINT32 STDMETHODCALLTYPE GetOutputCount() = 0;551virtual HRESULT STDMETHODCALLTYPE GetOutput(_In_ UINT32 uIndex,552_In_ REFIID iid, _COM_Outptr_opt_result_maybenull_ void **ppvObject,553_COM_Outptr_opt_result_maybenull_ IDxcBlobUtf16 **ppOutputType,554_COM_Outptr_opt_result_maybenull_ IDxcBlobUtf16 **ppOutputName) = 0;555};556557CROSS_PLATFORM_UUIDOF(IDxcCompiler3, "228B4687-5A6A-4730-900C-9702B2203F54")558struct IDxcCompiler3 : public IUnknown {559// Compile a single entry point to the target shader model,560// Compile a library to a library target (-T lib_*),561// Compile a root signature (-T rootsig_*), or562// Preprocess HLSL source (-P)563virtual HRESULT STDMETHODCALLTYPE Compile(564_In_ const DxcBuffer *pSource, // Source text to compile565_In_opt_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments566_In_ UINT32 argCount, // Number of arguments567_In_opt_ IDxcIncludeHandler *pIncludeHandler, // user-provided interface to handle #include directives (optional)568_In_ REFIID riid, _Out_ LPVOID *ppResult // IDxcResult: status, buffer, and errors569) = 0;570571// Disassemble a program.572virtual HRESULT STDMETHODCALLTYPE Disassemble(573_In_ const DxcBuffer *pObject, // Program to disassemble: dxil container or bitcode.574_In_ REFIID riid, _Out_ LPVOID *ppResult // IDxcResult: status, disassembly text, and errors575) = 0;576};577578static const UINT32 DxcValidatorFlags_Default = 0;579static const UINT32 DxcValidatorFlags_InPlaceEdit = 1; // Validator is allowed to update shader blob in-place.580static const UINT32 DxcValidatorFlags_RootSignatureOnly = 2;581static const UINT32 DxcValidatorFlags_ModuleOnly = 4;582static const UINT32 DxcValidatorFlags_ValidMask = 0x7;583584CROSS_PLATFORM_UUIDOF(IDxcValidator, "A6E82BD2-1FD7-4826-9811-2857E797F49A")585struct IDxcValidator : public IUnknown {586// Validate a shader.587virtual HRESULT STDMETHODCALLTYPE Validate(588_In_ IDxcBlob *pShader, // Shader to validate.589_In_ UINT32 Flags, // Validation flags.590_COM_Outptr_ IDxcOperationResult **ppResult // Validation output status, buffer, and errors591) = 0;592};593594CROSS_PLATFORM_UUIDOF(IDxcContainerBuilder, "334b1f50-2292-4b35-99a1-25588d8c17fe")595struct IDxcContainerBuilder : public IUnknown {596virtual HRESULT STDMETHODCALLTYPE Load(_In_ IDxcBlob *pDxilContainerHeader) = 0; // Loads DxilContainer to the builder597virtual HRESULT STDMETHODCALLTYPE AddPart(_In_ UINT32 fourCC, _In_ IDxcBlob *pSource) = 0; // Part to add to the container598virtual HRESULT STDMETHODCALLTYPE RemovePart(_In_ UINT32 fourCC) = 0; // Remove the part with fourCC599virtual HRESULT STDMETHODCALLTYPE SerializeContainer(_Out_ IDxcOperationResult **ppResult) = 0; // Builds a container of the given container builder state600};601602CROSS_PLATFORM_UUIDOF(IDxcAssembler, "091f7a26-1c1f-4948-904b-e6e3a8a771d5")603struct IDxcAssembler : public IUnknown {604// Assemble dxil in ll or llvm bitcode to DXIL container.605virtual HRESULT STDMETHODCALLTYPE AssembleToContainer(606_In_ IDxcBlob *pShader, // Shader to assemble.607_COM_Outptr_ IDxcOperationResult **ppResult // Assembly output status, buffer, and errors608) = 0;609};610611CROSS_PLATFORM_UUIDOF(IDxcContainerReflection, "d2c21b26-8350-4bdc-976a-331ce6f4c54c")612struct IDxcContainerReflection : public IUnknown {613virtual HRESULT STDMETHODCALLTYPE Load(_In_ IDxcBlob *pContainer) = 0; // Container to load.614virtual HRESULT STDMETHODCALLTYPE GetPartCount(_Out_ UINT32 *pResult) = 0;615virtual HRESULT STDMETHODCALLTYPE GetPartKind(UINT32 idx, _Out_ UINT32 *pResult) = 0;616virtual HRESULT STDMETHODCALLTYPE GetPartContent(UINT32 idx, _COM_Outptr_ IDxcBlob **ppResult) = 0;617virtual HRESULT STDMETHODCALLTYPE FindFirstPartKind(UINT32 kind, _Out_ UINT32 *pResult) = 0;618virtual HRESULT STDMETHODCALLTYPE GetPartReflection(UINT32 idx, REFIID iid, void **ppvObject) = 0;619};620621CROSS_PLATFORM_UUIDOF(IDxcOptimizerPass, "AE2CD79F-CC22-453F-9B6B-B124E7A5204C")622struct IDxcOptimizerPass : public IUnknown {623virtual HRESULT STDMETHODCALLTYPE GetOptionName(_COM_Outptr_ LPWSTR *ppResult) = 0;624virtual HRESULT STDMETHODCALLTYPE GetDescription(_COM_Outptr_ LPWSTR *ppResult) = 0;625virtual HRESULT STDMETHODCALLTYPE GetOptionArgCount(_Out_ UINT32 *pCount) = 0;626virtual HRESULT STDMETHODCALLTYPE GetOptionArgName(UINT32 argIndex, _COM_Outptr_ LPWSTR *ppResult) = 0;627virtual HRESULT STDMETHODCALLTYPE GetOptionArgDescription(UINT32 argIndex, _COM_Outptr_ LPWSTR *ppResult) = 0;628};629630CROSS_PLATFORM_UUIDOF(IDxcOptimizer, "25740E2E-9CBA-401B-9119-4FB42F39F270")631struct IDxcOptimizer : public IUnknown {632virtual HRESULT STDMETHODCALLTYPE GetAvailablePassCount(_Out_ UINT32 *pCount) = 0;633virtual HRESULT STDMETHODCALLTYPE GetAvailablePass(UINT32 index, _COM_Outptr_ IDxcOptimizerPass** ppResult) = 0;634virtual HRESULT STDMETHODCALLTYPE RunOptimizer(IDxcBlob *pBlob,635_In_count_(optionCount) LPCWSTR *ppOptions, UINT32 optionCount,636_COM_Outptr_ IDxcBlob **pOutputModule,637_COM_Outptr_opt_ IDxcBlobEncoding **ppOutputText) = 0;638};639640static const UINT32 DxcVersionInfoFlags_None = 0;641static const UINT32 DxcVersionInfoFlags_Debug = 1; // Matches VS_FF_DEBUG642static const UINT32 DxcVersionInfoFlags_Internal = 2; // Internal Validator (non-signing)643644CROSS_PLATFORM_UUIDOF(IDxcVersionInfo, "b04f5b50-2059-4f12-a8ff-a1e0cde1cc7e")645struct IDxcVersionInfo : public IUnknown {646virtual HRESULT STDMETHODCALLTYPE GetVersion(_Out_ UINT32 *pMajor, _Out_ UINT32 *pMinor) = 0;647virtual HRESULT STDMETHODCALLTYPE GetFlags(_Out_ UINT32 *pFlags) = 0;648};649650CROSS_PLATFORM_UUIDOF(IDxcVersionInfo2, "fb6904c4-42f0-4b62-9c46-983af7da7c83")651struct IDxcVersionInfo2 : public IDxcVersionInfo {652virtual HRESULT STDMETHODCALLTYPE GetCommitInfo(_Out_ UINT32 *pCommitCount, _Out_ char **pCommitHash) = 0;653};654655// Note: __declspec(selectany) requires 'extern'656// On Linux __declspec(selectany) is removed and using 'extern' results in link error.657#ifdef _MSC_VER658#define CLSID_SCOPE __declspec(selectany) extern659#else660#define CLSID_SCOPE661#endif662663CLSID_SCOPE const CLSID CLSID_DxcCompiler = {6640x73e22d93,6650xe6ce,6660x47f3,667{0xb5, 0xbf, 0xf0, 0x66, 0x4f, 0x39, 0xc1, 0xb0}};668669// {EF6A8087-B0EA-4D56-9E45-D07E1A8B7806}670CLSID_SCOPE const GUID CLSID_DxcLinker = {6710xef6a8087,6720xb0ea,6730x4d56,674{0x9e, 0x45, 0xd0, 0x7e, 0x1a, 0x8b, 0x78, 0x6}};675676// {CD1F6B73-2AB0-484D-8EDC-EBE7A43CA09F}677CLSID_SCOPE const CLSID CLSID_DxcDiaDataSource = {6780xcd1f6b73,6790x2ab0,6800x484d,681{0x8e, 0xdc, 0xeb, 0xe7, 0xa4, 0x3c, 0xa0, 0x9f}};682683// {3E56AE82-224D-470F-A1A1-FE3016EE9F9D}684CLSID_SCOPE const CLSID CLSID_DxcCompilerArgs = {6850x3e56ae82,6860x224d,6870x470f,688{0xa1, 0xa1, 0xfe, 0x30, 0x16, 0xee, 0x9f, 0x9d}};689690// {6245D6AF-66E0-48FD-80B4-4D271796748C}691CLSID_SCOPE const GUID CLSID_DxcLibrary = {6920x6245d6af,6930x66e0,6940x48fd,695{0x80, 0xb4, 0x4d, 0x27, 0x17, 0x96, 0x74, 0x8c}};696697CLSID_SCOPE const GUID CLSID_DxcUtils = CLSID_DxcLibrary;698699// {8CA3E215-F728-4CF3-8CDD-88AF917587A1}700CLSID_SCOPE const GUID CLSID_DxcValidator = {7010x8ca3e215,7020xf728,7030x4cf3,704{0x8c, 0xdd, 0x88, 0xaf, 0x91, 0x75, 0x87, 0xa1}};705706// {D728DB68-F903-4F80-94CD-DCCF76EC7151}707CLSID_SCOPE const GUID CLSID_DxcAssembler = {7080xd728db68,7090xf903,7100x4f80,711{0x94, 0xcd, 0xdc, 0xcf, 0x76, 0xec, 0x71, 0x51}};712713// {b9f54489-55b8-400c-ba3a-1675e4728b91}714CLSID_SCOPE const GUID CLSID_DxcContainerReflection = {7150xb9f54489,7160x55b8,7170x400c,718{0xba, 0x3a, 0x16, 0x75, 0xe4, 0x72, 0x8b, 0x91}};719720// {AE2CD79F-CC22-453F-9B6B-B124E7A5204C}721CLSID_SCOPE const GUID CLSID_DxcOptimizer = {7220xae2cd79f,7230xcc22,7240x453f,725{0x9b, 0x6b, 0xb1, 0x24, 0xe7, 0xa5, 0x20, 0x4c}};726727// {94134294-411f-4574-b4d0-8741e25240d2}728CLSID_SCOPE const GUID CLSID_DxcContainerBuilder = {7290x94134294,7300x411f,7310x4574,732{0xb4, 0xd0, 0x87, 0x41, 0xe2, 0x52, 0x40, 0xd2}};733#endif734735736