summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--external/dxc/dxcapi.h674
-rw-r--r--source/compiler-core/slang-downstream-compiler.h3
-rw-r--r--source/compiler-core/slang-dxc-compiler.cpp51
-rw-r--r--source/compiler-core/slang-glslang-compiler.cpp41
-rw-r--r--source/core/slang-md5.cpp5
-rw-r--r--source/core/slang-md5.h2
-rw-r--r--source/slang/slang-ast-base.h2
-rw-r--r--source/slang/slang-ast-type.cpp1
-rw-r--r--source/slang/slang-ast-type.h3
-rw-r--r--source/slang/slang-ast-val.h2
-rw-r--r--source/slang/slang-hash-utils.h9
-rw-r--r--source/slang/slang.cpp12
-rw-r--r--tools/gfx-unit-test/shader-cache-shader.slang2
-rw-r--r--tools/slang-unit-test/unit-test-checksum.cpp2
-rw-r--r--tools/slang-unit-test/unit-test-md5.cpp10
15 files changed, 660 insertions, 159 deletions
diff --git a/external/dxc/dxcapi.h b/external/dxc/dxcapi.h
index 70f93e834..0e16bb003 100644
--- a/external/dxc/dxcapi.h
+++ b/external/dxc/dxcapi.h
@@ -13,30 +13,34 @@
#ifndef __DXC_API__
#define __DXC_API__
+#ifdef _WIN32
#ifndef DXC_API_IMPORT
#define DXC_API_IMPORT __declspec(dllimport)
#endif
+#else
+#ifndef DXC_API_IMPORT
+#define DXC_API_IMPORT __attribute__ ((visibility ("default")))
+#endif
+#endif
+
+#ifdef _WIN32
+
+#ifndef CROSS_PLATFORM_UUIDOF
+// Warning: This macro exists in WinAdapter.h as well
+#define CROSS_PLATFORM_UUIDOF(interface, spec) \
+ struct __declspec(uuid(spec)) interface;
+#endif
+
+#else
+
+#include <dlfcn.h>
+#include "dxc/Support/WinAdapter.h"
+#endif
struct IMalloc;
+
struct IDxcIncludeHandler;
-/// <summary>
-/// Creates a single uninitialized object of the class associated with a specified CLSID.
-/// </summary>
-/// <param name="rclsid">
-/// The CLSID associated with the data and code that will be used to create the object.
-/// </param>
-/// <param name="riid">
-/// A reference to the identifier of the interface to be used to communicate
-/// with the object.
-/// </param>
-/// <param name="ppv">
-/// Address of pointer variable that receives the interface pointer requested
-/// in riid. Upon successful return, *ppv contains the requested interface
-/// pointer. Upon failure, *ppv contains NULL.</param>
-/// <remarks>
-/// While this function is similar to CoCreateInstance, there is no COM involvement.
-/// </remarks>
typedef HRESULT (__stdcall *DxcCreateInstanceProc)(
_In_ REFCLSID rclsid,
_In_ REFIID riid,
@@ -57,7 +61,7 @@ typedef HRESULT(__stdcall *DxcCreateInstance2Proc)(
/// The CLSID associated with the data and code that will be used to create the object.
/// </param>
/// <param name="riid">
-/// A reference to the identifier of the interface to be used to communicate
+/// A reference to the identifier of the interface to be used to communicate
/// with the object.
/// </param>
/// <param name="ppv">
@@ -67,12 +71,15 @@ typedef HRESULT(__stdcall *DxcCreateInstance2Proc)(
/// <remarks>
/// While this function is similar to CoCreateInstance, there is no COM involvement.
/// </remarks>
+
+extern "C"
DXC_API_IMPORT HRESULT __stdcall DxcCreateInstance(
_In_ REFCLSID rclsid,
_In_ REFIID riid,
_Out_ LPVOID* ppv
);
+extern "C"
DXC_API_IMPORT HRESULT __stdcall DxcCreateInstance2(
_In_ IMalloc *pMalloc,
_In_ REFCLSID rclsid,
@@ -80,80 +87,220 @@ DXC_API_IMPORT HRESULT __stdcall DxcCreateInstance2(
_Out_ LPVOID* ppv
);
+// For convenience, equivalent definitions to CP_UTF8 and CP_UTF16.
+#define DXC_CP_UTF8 65001
+#define DXC_CP_UTF16 1200
+#define DXC_CP_UTF32 12000
+// Use DXC_CP_ACP for: Binary; ANSI Text; Autodetect UTF with BOM
+#define DXC_CP_ACP 0
+
+#ifdef _WIN32
+#define DXC_CP_WIDE DXC_CP_UTF16
+#else
+#define DXC_CP_WIDE DXC_CP_UTF32
+#endif
+
+// This flag indicates that the shader hash was computed taking into account source information (-Zss)
+#define DXC_HASHFLAG_INCLUDES_SOURCE 1
+
+// Hash digest type for ShaderHash
+typedef struct DxcShaderHash {
+ UINT32 Flags; // DXC_HASHFLAG_*
+ BYTE HashDigest[16];
+} DxcShaderHash;
+
+#define DXC_FOURCC(ch0, ch1, ch2, ch3) ( \
+ (UINT32)(UINT8)(ch0) | (UINT32)(UINT8)(ch1) << 8 | \
+ (UINT32)(UINT8)(ch2) << 16 | (UINT32)(UINT8)(ch3) << 24 \
+ )
+#define DXC_PART_PDB DXC_FOURCC('I', 'L', 'D', 'B')
+#define DXC_PART_PDB_NAME DXC_FOURCC('I', 'L', 'D', 'N')
+#define DXC_PART_PRIVATE_DATA DXC_FOURCC('P', 'R', 'I', 'V')
+#define DXC_PART_ROOT_SIGNATURE DXC_FOURCC('R', 'T', 'S', '0')
+#define DXC_PART_DXIL DXC_FOURCC('D', 'X', 'I', 'L')
+#define DXC_PART_REFLECTION_DATA DXC_FOURCC('S', 'T', 'A', 'T')
+#define DXC_PART_SHADER_HASH DXC_FOURCC('H', 'A', 'S', 'H')
+#define DXC_PART_INPUT_SIGNATURE DXC_FOURCC('I', 'S', 'G', '1')
+#define DXC_PART_OUTPUT_SIGNATURE DXC_FOURCC('O', 'S', 'G', '1')
+#define DXC_PART_PATCH_CONSTANT_SIGNATURE DXC_FOURCC('P', 'S', 'G', '1')
+
+// Some option arguments are defined here for continuity with D3DCompile interface
+#define DXC_ARG_DEBUG L"-Zi"
+#define DXC_ARG_SKIP_VALIDATION L"-Vd"
+#define DXC_ARG_SKIP_OPTIMIZATIONS L"-Od"
+#define DXC_ARG_PACK_MATRIX_ROW_MAJOR L"-Zpr"
+#define DXC_ARG_PACK_MATRIX_COLUMN_MAJOR L"-Zpc"
+#define DXC_ARG_AVOID_FLOW_CONTROL L"-Gfa"
+#define DXC_ARG_PREFER_FLOW_CONTROL L"-Gfp"
+#define DXC_ARG_ENABLE_STRICTNESS L"-Ges"
+#define DXC_ARG_ENABLE_BACKWARDS_COMPATIBILITY L"-Gec"
+#define DXC_ARG_IEEE_STRICTNESS L"-Gis"
+#define DXC_ARG_OPTIMIZATION_LEVEL0 L"-O0"
+#define DXC_ARG_OPTIMIZATION_LEVEL1 L"-O1"
+#define DXC_ARG_OPTIMIZATION_LEVEL2 L"-O2"
+#define DXC_ARG_OPTIMIZATION_LEVEL3 L"-O3"
+#define DXC_ARG_WARNINGS_ARE_ERRORS L"-WX"
+#define DXC_ARG_RESOURCES_MAY_ALIAS L"-res_may_alias"
+#define DXC_ARG_ALL_RESOURCES_BOUND L"-all_resources_bound"
+#define DXC_ARG_DEBUG_NAME_FOR_SOURCE L"-Zss"
+#define DXC_ARG_DEBUG_NAME_FOR_BINARY L"-Zsb"
// IDxcBlob is an alias of ID3D10Blob and ID3DBlob
-struct __declspec(uuid("8BA5FB08-5195-40e2-AC58-0D989C3A0102"))
-IDxcBlob : public IUnknown {
+CROSS_PLATFORM_UUIDOF(IDxcBlob, "8BA5FB08-5195-40e2-AC58-0D989C3A0102")
+struct IDxcBlob : public IUnknown {
public:
virtual LPVOID STDMETHODCALLTYPE GetBufferPointer(void) = 0;
virtual SIZE_T STDMETHODCALLTYPE GetBufferSize(void) = 0;
};
-struct __declspec(uuid("7241d424-2646-4191-97c0-98e96e42fc68"))
-IDxcBlobEncoding : public IDxcBlob {
+CROSS_PLATFORM_UUIDOF(IDxcBlobEncoding, "7241d424-2646-4191-97c0-98e96e42fc68")
+struct IDxcBlobEncoding : public IDxcBlob {
public:
virtual HRESULT STDMETHODCALLTYPE GetEncoding(_Out_ BOOL *pKnown,
_Out_ UINT32 *pCodePage) = 0;
};
-struct __declspec(uuid("e5204dc7-d18c-4c3c-bdfb-851673980fe7"))
-IDxcLibrary : public IUnknown {
+// Notes on IDxcBlobWide and IDxcBlobUtf8
+// These guarantee null-terminated text and eithre utf8 or the native wide char encoding.
+// GetBufferSize() will return the size in bytes, including null-terminator
+// GetStringLength() will return the length in characters, excluding the null-terminator
+// Name strings will use IDxcBlobWide, while other string output blobs,
+// such as errors/warnings, preprocessed HLSL, or other text will be based
+// on the -encoding option.
+
+// The API will use this interface for output name strings
+CROSS_PLATFORM_UUIDOF(IDxcBlobWide, "A3F84EAB-0FAA-497E-A39C-EE6ED60B2D84")
+struct IDxcBlobWide : public IDxcBlobEncoding {
+public:
+ virtual LPCWSTR STDMETHODCALLTYPE GetStringPointer(void) = 0;
+ virtual SIZE_T STDMETHODCALLTYPE GetStringLength(void) = 0;
+};
+CROSS_PLATFORM_UUIDOF(IDxcBlobUtf8, "3DA636C9-BA71-4024-A301-30CBF125305B")
+struct IDxcBlobUtf8 : public IDxcBlobEncoding {
+public:
+ virtual LPCSTR STDMETHODCALLTYPE GetStringPointer(void) = 0;
+ virtual SIZE_T STDMETHODCALLTYPE GetStringLength(void) = 0;
+};
+
+// Define legacy name IDxcBlobUtf16 as IDxcBlobWide for Win32
+#ifdef _WIN32
+typedef IDxcBlobWide IDxcBlobUtf16;
+#endif
+
+CROSS_PLATFORM_UUIDOF(IDxcIncludeHandler, "7f61fc7d-950d-467f-b3e3-3c02fb49187c")
+struct IDxcIncludeHandler : public IUnknown {
+ virtual HRESULT STDMETHODCALLTYPE LoadSource(
+ _In_z_ LPCWSTR pFilename, // Candidate filename.
+ _COM_Outptr_result_maybenull_ IDxcBlob **ppIncludeSource // Resultant source object for included file, nullptr if not found.
+ ) = 0;
+};
+
+// Structure for supplying bytes or text input to Dxc APIs.
+// Use Encoding = 0 for non-text bytes, ANSI text, or unknown with BOM.
+typedef struct DxcBuffer {
+ LPCVOID Ptr;
+ SIZE_T Size;
+ UINT Encoding;
+} DxcText;
+
+struct DxcDefine {
+ LPCWSTR Name;
+ _Maybenull_ LPCWSTR Value;
+};
+
+CROSS_PLATFORM_UUIDOF(IDxcCompilerArgs, "73EFFE2A-70DC-45F8-9690-EFF64C02429D")
+struct IDxcCompilerArgs : public IUnknown {
+ // Pass GetArguments() and GetCount() to Compile
+ virtual LPCWSTR* STDMETHODCALLTYPE GetArguments() = 0;
+ virtual UINT32 STDMETHODCALLTYPE GetCount() = 0;
+
+ // Add additional arguments or defines here, if desired.
+ virtual HRESULT STDMETHODCALLTYPE AddArguments(
+ _In_opt_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments to add
+ _In_ UINT32 argCount // Number of arguments to add
+ ) = 0;
+ virtual HRESULT STDMETHODCALLTYPE AddArgumentsUTF8(
+ _In_opt_count_(argCount)LPCSTR *pArguments, // Array of pointers to UTF-8 arguments to add
+ _In_ UINT32 argCount // Number of arguments to add
+ ) = 0;
+ virtual HRESULT STDMETHODCALLTYPE AddDefines(
+ _In_count_(defineCount) const DxcDefine *pDefines, // Array of defines
+ _In_ UINT32 defineCount // Number of defines
+ ) = 0;
+};
+
+//////////////////////////
+// Legacy Interfaces
+/////////////////////////
+
+// NOTE: IDxcUtils replaces IDxcLibrary
+CROSS_PLATFORM_UUIDOF(IDxcLibrary, "e5204dc7-d18c-4c3c-bdfb-851673980fe7")
+struct IDxcLibrary : public IUnknown {
virtual HRESULT STDMETHODCALLTYPE SetMalloc(_In_opt_ IMalloc *pMalloc) = 0;
virtual HRESULT STDMETHODCALLTYPE CreateBlobFromBlob(
_In_ IDxcBlob *pBlob, UINT32 offset, UINT32 length, _COM_Outptr_ IDxcBlob **ppResult) = 0;
virtual HRESULT STDMETHODCALLTYPE CreateBlobFromFile(
- LPCWSTR pFileName, _In_opt_ UINT32* codePage,
+ _In_z_ LPCWSTR pFileName, _In_opt_ UINT32* codePage,
_COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
virtual HRESULT STDMETHODCALLTYPE CreateBlobWithEncodingFromPinned(
- LPBYTE pText, UINT32 size, UINT32 codePage,
+ _In_bytecount_(size) LPCVOID pText, UINT32 size, UINT32 codePage,
_COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
virtual HRESULT STDMETHODCALLTYPE CreateBlobWithEncodingOnHeapCopy(
- _In_bytecount_(size) LPCVOID pText, UINT32 size, UINT32 codePage,
- _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
+ _In_bytecount_(size) LPCVOID pText, UINT32 size, UINT32 codePage,
+ _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
virtual HRESULT STDMETHODCALLTYPE CreateBlobWithEncodingOnMalloc(
_In_bytecount_(size) LPCVOID pText, IMalloc *pIMalloc, UINT32 size, UINT32 codePage,
_COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
virtual HRESULT STDMETHODCALLTYPE CreateIncludeHandler(
- _COM_Outptr_ IDxcIncludeHandler **ppResult) = 0;
+ _COM_Outptr_ IDxcIncludeHandler **ppResult) = 0;
virtual HRESULT STDMETHODCALLTYPE CreateStreamFromBlobReadOnly(
- _In_ IDxcBlob *pBlob, _COM_Outptr_ IStream **ppStream) = 0;
+ _In_ IDxcBlob *pBlob, _COM_Outptr_ IStream **ppStream) = 0;
virtual HRESULT STDMETHODCALLTYPE GetBlobAsUtf8(
- _In_ IDxcBlob *pBlob, _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetBlobAsUtf16(
- _In_ IDxcBlob *pBlob, _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
+ _In_ IDxcBlob *pBlob, _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
+
+ // Renamed from GetBlobAsUtf16 to GetBlobAsWide
+ virtual HRESULT STDMETHODCALLTYPE GetBlobAsWide(
+ _In_ IDxcBlob *pBlob, _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
+
+#ifdef _WIN32
+ // Alias to GetBlobAsWide on Win32
+ inline HRESULT GetBlobAsUtf16(
+ _In_ IDxcBlob *pBlob, _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) {
+ return this->GetBlobAsWide(pBlob, pBlobEncoding);
+ }
+#endif
};
-struct __declspec(uuid("CEDB484A-D4E9-445A-B991-CA21CA157DC2"))
-IDxcOperationResult : public IUnknown {
+// NOTE: IDxcResult replaces IDxcOperationResult
+CROSS_PLATFORM_UUIDOF(IDxcOperationResult, "CEDB484A-D4E9-445A-B991-CA21CA157DC2")
+struct IDxcOperationResult : public IUnknown {
virtual HRESULT STDMETHODCALLTYPE GetStatus(_Out_ HRESULT *pStatus) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetResult(_COM_Outptr_result_maybenull_ IDxcBlob **pResult) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetErrorBuffer(_COM_Outptr_result_maybenull_ IDxcBlobEncoding **pErrors) = 0;
-};
-struct __declspec(uuid("7f61fc7d-950d-467f-b3e3-3c02fb49187c"))
-IDxcIncludeHandler : public IUnknown {
- virtual HRESULT STDMETHODCALLTYPE LoadSource(
- _In_ LPCWSTR pFilename, // Candidate filename.
- _COM_Outptr_result_maybenull_ IDxcBlob **ppIncludeSource // Resultant source object for included file, nullptr if not found.
- ) = 0;
-};
+ // GetResult returns the main result of the operation.
+ // This corresponds to:
+ // DXC_OUT_OBJECT - Compile() with shader or library target
+ // DXC_OUT_DISASSEMBLY - Disassemble()
+ // DXC_OUT_HLSL - Compile() with -P
+ // DXC_OUT_ROOT_SIGNATURE - Compile() with rootsig_* target
+ virtual HRESULT STDMETHODCALLTYPE GetResult(_COM_Outptr_result_maybenull_ IDxcBlob **ppResult) = 0;
-struct DxcDefine {
- LPCWSTR Name;
- _Maybenull_ LPCWSTR Value;
+ // GetErrorBuffer Corresponds to DXC_OUT_ERRORS.
+ virtual HRESULT STDMETHODCALLTYPE GetErrorBuffer(_COM_Outptr_result_maybenull_ IDxcBlobEncoding **ppErrors) = 0;
};
-struct __declspec(uuid("8c210bf3-011f-4422-8d70-6f9acb8db617"))
-IDxcCompiler : public IUnknown {
+// NOTE: IDxcCompiler3 replaces IDxcCompiler and IDxcCompiler2
+CROSS_PLATFORM_UUIDOF(IDxcCompiler, "8c210bf3-011f-4422-8d70-6f9acb8db617")
+struct IDxcCompiler : public IUnknown {
// Compile a single entry point to the target shader model
virtual HRESULT STDMETHODCALLTYPE Compile(
_In_ IDxcBlob *pSource, // Source text to compile
- _In_opt_ LPCWSTR pSourceName, // Optional file name for pSource. Used in errors and include handlers.
- _In_ LPCWSTR pEntryPoint, // entry point name
- _In_ LPCWSTR pTargetProfile, // shader profile to compile
- _In_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments
+ _In_opt_z_ LPCWSTR pSourceName, // Optional file name for pSource. Used in errors and include handlers.
+ _In_opt_z_ LPCWSTR pEntryPoint, // entry point name
+ _In_z_ LPCWSTR pTargetProfile, // shader profile to compile
+ _In_opt_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments
_In_ UINT32 argCount, // Number of arguments
- _In_count_(defineCount) const DxcDefine *pDefines, // Array of defines
+ _In_count_(defineCount)
+ const DxcDefine *pDefines, // Array of defines
_In_ UINT32 defineCount, // Number of defines
_In_opt_ IDxcIncludeHandler *pIncludeHandler, // user-provided interface to handle #include directives (optional)
_COM_Outptr_ IDxcOperationResult **ppResult // Compiler output status, buffer, and errors
@@ -162,10 +309,11 @@ IDxcCompiler : public IUnknown {
// Preprocess source text
virtual HRESULT STDMETHODCALLTYPE Preprocess(
_In_ IDxcBlob *pSource, // Source text to preprocess
- _In_opt_ LPCWSTR pSourceName, // Optional file name for pSource. Used in errors and include handlers.
- _In_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments
+ _In_opt_z_ LPCWSTR pSourceName, // Optional file name for pSource. Used in errors and include handlers.
+ _In_opt_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments
_In_ UINT32 argCount, // Number of arguments
- _In_count_(defineCount) const DxcDefine *pDefines, // Array of defines
+ _In_count_(defineCount)
+ const DxcDefine *pDefines, // Array of defines
_In_ UINT32 defineCount, // Number of defines
_In_opt_ IDxcIncludeHandler *pIncludeHandler, // user-provided interface to handle #include directives (optional)
_COM_Outptr_ IDxcOperationResult **ppResult // Preprocessor output status, buffer, and errors
@@ -178,58 +326,216 @@ IDxcCompiler : public IUnknown {
) = 0;
};
-struct __declspec(uuid("A005A9D9-B8BB-4594-B5C9-0E633BEC4D37"))
-IDxcCompiler2 : public IDxcCompiler {
+// NOTE: IDxcCompiler3 replaces IDxcCompiler and IDxcCompiler2
+CROSS_PLATFORM_UUIDOF(IDxcCompiler2, "A005A9D9-B8BB-4594-B5C9-0E633BEC4D37")
+struct IDxcCompiler2 : public IDxcCompiler {
// Compile a single entry point to the target shader model with debug information.
virtual HRESULT STDMETHODCALLTYPE CompileWithDebug(
_In_ IDxcBlob *pSource, // Source text to compile
- _In_opt_ LPCWSTR pSourceName, // Optional file name for pSource. Used in errors and include handlers.
- _In_ LPCWSTR pEntryPoint, // Entry point name
- _In_ LPCWSTR pTargetProfile, // Shader profile to compile
- _In_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments
+ _In_opt_z_ LPCWSTR pSourceName, // Optional file name for pSource. Used in errors and include handlers.
+ _In_opt_z_ LPCWSTR pEntryPoint, // Entry point name
+ _In_z_ LPCWSTR pTargetProfile, // Shader profile to compile
+ _In_opt_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments
_In_ UINT32 argCount, // Number of arguments
- _In_count_(defineCount) const DxcDefine *pDefines, // Array of defines
+ _In_count_(defineCount)
+ const DxcDefine *pDefines, // Array of defines
_In_ UINT32 defineCount, // Number of defines
_In_opt_ IDxcIncludeHandler *pIncludeHandler, // user-provided interface to handle #include directives (optional)
_COM_Outptr_ IDxcOperationResult **ppResult, // Compiler output status, buffer, and errors
- _Outptr_opt_result_z_ LPWSTR *ppDebugBlobName,// Suggested file name for debug blob.
+ _Outptr_opt_result_z_ LPWSTR *ppDebugBlobName,// Suggested file name for debug blob. (Must be CoTaskMemFree()'d!)
_COM_Outptr_opt_ IDxcBlob **ppDebugBlob // Debug blob
) = 0;
};
-struct __declspec(uuid("F1B5BE2A-62DD-4327-A1C2-42AC1E1E78E6"))
-IDxcLinker : public IUnknown {
+CROSS_PLATFORM_UUIDOF(IDxcLinker, "F1B5BE2A-62DD-4327-A1C2-42AC1E1E78E6")
+struct IDxcLinker : public IUnknown {
public:
// Register a library with name to ref it later.
virtual HRESULT RegisterLibrary(
- _In_opt_ LPCWSTR pLibName, // Name of the library.
- _In_ IDxcBlob *pLib // Library blob.
+ _In_opt_ LPCWSTR pLibName, // Name of the library.
+ _In_ IDxcBlob *pLib // Library blob.
) = 0;
// Links the shader and produces a shader blob that the Direct3D runtime can
// use.
virtual HRESULT STDMETHODCALLTYPE Link(
- _In_opt_ LPCWSTR pEntryName, // Entry point name
- _In_ LPCWSTR pTargetProfile, // shader profile to link
- _In_count_(libCount)
- const LPCWSTR *pLibNames, // Array of library names to link
- UINT32 libCount, // Number of libraries to link
- _In_count_(argCount)
- const LPCWSTR *pArguments, // Array of pointers to arguments
- _In_ UINT32 argCount, // Number of arguments
- _COM_Outptr_ IDxcOperationResult *
- *ppResult // Linker output status, buffer, and errors
+ _In_opt_ LPCWSTR pEntryName, // Entry point name
+ _In_ LPCWSTR pTargetProfile, // shader profile to link
+ _In_count_(libCount)
+ const LPCWSTR *pLibNames, // Array of library names to link
+ _In_ UINT32 libCount, // Number of libraries to link
+ _In_opt_count_(argCount) const LPCWSTR *pArguments, // Array of pointers to arguments
+ _In_ UINT32 argCount, // Number of arguments
+ _COM_Outptr_
+ IDxcOperationResult **ppResult // Linker output status, buffer, and errors
) = 0;
};
+/////////////////////////
+// Latest interfaces. Please use these
+////////////////////////
+
+// NOTE: IDxcUtils replaces IDxcLibrary
+CROSS_PLATFORM_UUIDOF(IDxcUtils, "4605C4CB-2019-492A-ADA4-65F20BB7D67F")
+struct IDxcUtils : public IUnknown {
+ // Create a sub-blob that holds a reference to the outer blob and points to its memory.
+ virtual HRESULT STDMETHODCALLTYPE CreateBlobFromBlob(
+ _In_ IDxcBlob *pBlob, UINT32 offset, UINT32 length, _COM_Outptr_ IDxcBlob **ppResult) = 0;
+
+ // For codePage, use 0 (or DXC_CP_ACP) for raw binary or ANSI code page
+
+ // Creates a blob referencing existing memory, with no copy.
+ // User must manage the memory lifetime separately.
+ // (was: CreateBlobWithEncodingFromPinned)
+ virtual HRESULT STDMETHODCALLTYPE CreateBlobFromPinned(
+ _In_bytecount_(size) LPCVOID pData, UINT32 size, UINT32 codePage,
+ _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
+
+ // Create blob, taking ownership of memory allocated with supplied allocator.
+ // (was: CreateBlobWithEncodingOnMalloc)
+ virtual HRESULT STDMETHODCALLTYPE MoveToBlob(
+ _In_bytecount_(size) LPCVOID pData, IMalloc *pIMalloc, UINT32 size, UINT32 codePage,
+ _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
+
+ ////
+ // New blobs and copied contents are allocated with the current allocator
+
+ // Copy blob contents to memory owned by the new blob.
+ // (was: CreateBlobWithEncodingOnHeapCopy)
+ virtual HRESULT STDMETHODCALLTYPE CreateBlob(
+ _In_bytecount_(size) LPCVOID pData, UINT32 size, UINT32 codePage,
+ _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
+
+ // (was: CreateBlobFromFile)
+ virtual HRESULT STDMETHODCALLTYPE LoadFile(
+ _In_z_ LPCWSTR pFileName, _In_opt_ UINT32* pCodePage,
+ _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE CreateReadOnlyStreamFromBlob(
+ _In_ IDxcBlob *pBlob, _COM_Outptr_ IStream **ppStream) = 0;
+
+ // Create default file-based include handler
+ virtual HRESULT STDMETHODCALLTYPE CreateDefaultIncludeHandler(
+ _COM_Outptr_ IDxcIncludeHandler **ppResult) = 0;
+
+ // Convert or return matching encoded text blobs
+ virtual HRESULT STDMETHODCALLTYPE GetBlobAsUtf8(
+ _In_ IDxcBlob *pBlob, _COM_Outptr_ IDxcBlobUtf8 **pBlobEncoding) = 0;
+
+ // Renamed from GetBlobAsUtf16 to GetBlobAsWide
+ virtual HRESULT STDMETHODCALLTYPE GetBlobAsWide(
+ _In_ IDxcBlob *pBlob, _COM_Outptr_ IDxcBlobWide **pBlobEncoding) = 0;
+
+#ifdef _WIN32
+ // Alias to GetBlobAsWide on Win32
+ inline HRESULT GetBlobAsUtf16(
+ _In_ IDxcBlob *pBlob, _COM_Outptr_ IDxcBlobWide **pBlobEncoding) {
+ return this->GetBlobAsWide(pBlob, pBlobEncoding);
+ }
+#endif
+
+ virtual HRESULT STDMETHODCALLTYPE GetDxilContainerPart(
+ _In_ const DxcBuffer *pShader,
+ _In_ UINT32 DxcPart,
+ _Outptr_result_nullonfailure_ void **ppPartData,
+ _Out_ UINT32 *pPartSizeInBytes) = 0;
+
+ // Create reflection interface from serialized Dxil container, or DXC_PART_REFLECTION_DATA.
+ // TBD: Require part header for RDAT? (leaning towards yes)
+ virtual HRESULT STDMETHODCALLTYPE CreateReflection(
+ _In_ const DxcBuffer *pData, REFIID iid, void **ppvReflection) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE BuildArguments(
+ _In_opt_z_ LPCWSTR pSourceName, // Optional file name for pSource. Used in errors and include handlers.
+ _In_opt_z_ LPCWSTR pEntryPoint, // Entry point name. (-E)
+ _In_z_ LPCWSTR pTargetProfile, // Shader profile to compile. (-T)
+ _In_opt_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments
+ _In_ UINT32 argCount, // Number of arguments
+ _In_count_(defineCount)
+ const DxcDefine *pDefines, // Array of defines
+ _In_ UINT32 defineCount, // Number of defines
+ _COM_Outptr_ IDxcCompilerArgs **ppArgs // Arguments you can use with Compile() method
+ ) = 0;
+
+ // Takes the shader PDB and returns the hash and the container inside it
+ virtual HRESULT STDMETHODCALLTYPE GetPDBContents(
+ _In_ IDxcBlob *pPDBBlob, _COM_Outptr_ IDxcBlob **ppHash, _COM_Outptr_ IDxcBlob **ppContainer) = 0;
+};
+
+// For use with IDxcResult::[Has|Get]Output dxcOutKind argument
+// Note: text outputs returned from version 2 APIs are UTF-8 or UTF-16 based on -encoding option
+typedef enum DXC_OUT_KIND {
+ DXC_OUT_NONE = 0,
+ DXC_OUT_OBJECT = 1, // IDxcBlob - Shader or library object
+ DXC_OUT_ERRORS = 2, // IDxcBlobUtf8 or IDxcBlobWide
+ DXC_OUT_PDB = 3, // IDxcBlob
+ DXC_OUT_SHADER_HASH = 4, // IDxcBlob - DxcShaderHash of shader or shader with source info (-Zsb/-Zss)
+ DXC_OUT_DISASSEMBLY = 5, // IDxcBlobUtf8 or IDxcBlobWide - from Disassemble
+ DXC_OUT_HLSL = 6, // IDxcBlobUtf8 or IDxcBlobWide - from Preprocessor or Rewriter
+ DXC_OUT_TEXT = 7, // IDxcBlobUtf8 or IDxcBlobWide - other text, such as -ast-dump or -Odump
+ DXC_OUT_REFLECTION = 8, // IDxcBlob - RDAT part with reflection data
+ DXC_OUT_ROOT_SIGNATURE = 9, // IDxcBlob - Serialized root signature output
+ DXC_OUT_EXTRA_OUTPUTS = 10,// IDxcExtraResults - Extra outputs
+ DXC_OUT_REMARKS = 11, // IDxcBlobUtf8 or IDxcBlobUtf16 - text directed at stdout
+
+ DXC_OUT_FORCE_DWORD = 0xFFFFFFFF
+} DXC_OUT_KIND;
+
+CROSS_PLATFORM_UUIDOF(IDxcResult, "58346CDA-DDE7-4497-9461-6F87AF5E0659")
+struct IDxcResult : public IDxcOperationResult {
+ virtual BOOL STDMETHODCALLTYPE HasOutput(_In_ DXC_OUT_KIND dxcOutKind) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetOutput(_In_ DXC_OUT_KIND dxcOutKind,
+ _In_ REFIID iid, _COM_Outptr_opt_result_maybenull_ void **ppvObject,
+ _COM_Outptr_ IDxcBlobWide **ppOutputName) = 0;
+
+ virtual UINT32 GetNumOutputs() = 0;
+ virtual DXC_OUT_KIND GetOutputByIndex(UINT32 Index) = 0;
+ virtual DXC_OUT_KIND PrimaryOutput() = 0;
+};
+
+// Special names for extra output that should get written to specific streams
+#define DXC_EXTRA_OUTPUT_NAME_STDOUT L"*stdout*"
+#define DXC_EXTRA_OUTPUT_NAME_STDERR L"*stderr*"
+
+CROSS_PLATFORM_UUIDOF(IDxcExtraOutputs, "319b37a2-a5c2-494a-a5de-4801b2faf989")
+struct IDxcExtraOutputs : public IUnknown {
+
+ virtual UINT32 STDMETHODCALLTYPE GetOutputCount() = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetOutput(_In_ UINT32 uIndex,
+ _In_ REFIID iid, _COM_Outptr_opt_result_maybenull_ void **ppvObject,
+ _COM_Outptr_opt_result_maybenull_ IDxcBlobWide **ppOutputType,
+ _COM_Outptr_opt_result_maybenull_ IDxcBlobWide **ppOutputName) = 0;
+};
+
+CROSS_PLATFORM_UUIDOF(IDxcCompiler3, "228B4687-5A6A-4730-900C-9702B2203F54")
+struct IDxcCompiler3 : public IUnknown {
+ // Compile a single entry point to the target shader model,
+ // Compile a library to a library target (-T lib_*),
+ // Compile a root signature (-T rootsig_*), or
+ // Preprocess HLSL source (-P)
+ virtual HRESULT STDMETHODCALLTYPE Compile(
+ _In_ const DxcBuffer *pSource, // Source text to compile
+ _In_opt_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments
+ _In_ UINT32 argCount, // Number of arguments
+ _In_opt_ IDxcIncludeHandler *pIncludeHandler, // user-provided interface to handle #include directives (optional)
+ _In_ REFIID riid, _Out_ LPVOID *ppResult // IDxcResult: status, buffer, and errors
+ ) = 0;
+
+ // Disassemble a program.
+ virtual HRESULT STDMETHODCALLTYPE Disassemble(
+ _In_ const DxcBuffer *pObject, // Program to disassemble: dxil container or bitcode.
+ _In_ REFIID riid, _Out_ LPVOID *ppResult // IDxcResult: status, disassembly text, and errors
+ ) = 0;
+};
+
static const UINT32 DxcValidatorFlags_Default = 0;
static const UINT32 DxcValidatorFlags_InPlaceEdit = 1; // Validator is allowed to update shader blob in-place.
static const UINT32 DxcValidatorFlags_RootSignatureOnly = 2;
static const UINT32 DxcValidatorFlags_ModuleOnly = 4;
static const UINT32 DxcValidatorFlags_ValidMask = 0x7;
-struct __declspec(uuid("A6E82BD2-1FD7-4826-9811-2857E797F49A"))
-IDxcValidator : public IUnknown {
+CROSS_PLATFORM_UUIDOF(IDxcValidator, "A6E82BD2-1FD7-4826-9811-2857E797F49A")
+struct IDxcValidator : public IUnknown {
// Validate a shader.
virtual HRESULT STDMETHODCALLTYPE Validate(
_In_ IDxcBlob *pShader, // Shader to validate.
@@ -238,16 +544,27 @@ IDxcValidator : public IUnknown {
) = 0;
};
-struct __declspec(uuid("334b1f50-2292-4b35-99a1-25588d8c17fe"))
-IDxcContainerBuilder : public IUnknown {
+CROSS_PLATFORM_UUIDOF(IDxcValidator2, "458e1fd1-b1b2-4750-a6e1-9c10f03bed92")
+struct IDxcValidator2 : public IDxcValidator {
+ // Validate a shader.
+ virtual HRESULT STDMETHODCALLTYPE ValidateWithDebug(
+ _In_ IDxcBlob *pShader, // Shader to validate.
+ _In_ UINT32 Flags, // Validation flags.
+ _In_opt_ DxcBuffer *pOptDebugBitcode, // Optional debug module bitcode to provide line numbers
+ _COM_Outptr_ IDxcOperationResult **ppResult // Validation output status, buffer, and errors
+ ) = 0;
+};
+
+CROSS_PLATFORM_UUIDOF(IDxcContainerBuilder, "334b1f50-2292-4b35-99a1-25588d8c17fe")
+struct IDxcContainerBuilder : public IUnknown {
virtual HRESULT STDMETHODCALLTYPE Load(_In_ IDxcBlob *pDxilContainerHeader) = 0; // Loads DxilContainer to the builder
virtual HRESULT STDMETHODCALLTYPE AddPart(_In_ UINT32 fourCC, _In_ IDxcBlob *pSource) = 0; // Part to add to the container
virtual HRESULT STDMETHODCALLTYPE RemovePart(_In_ UINT32 fourCC) = 0; // Remove the part with fourCC
virtual HRESULT STDMETHODCALLTYPE SerializeContainer(_Out_ IDxcOperationResult **ppResult) = 0; // Builds a container of the given container builder state
};
-struct __declspec(uuid("091f7a26-1c1f-4948-904b-e6e3a8a771d5"))
-IDxcAssembler : public IUnknown {
+CROSS_PLATFORM_UUIDOF(IDxcAssembler, "091f7a26-1c1f-4948-904b-e6e3a8a771d5")
+struct IDxcAssembler : public IUnknown {
// Assemble dxil in ll or llvm bitcode to DXIL container.
virtual HRESULT STDMETHODCALLTYPE AssembleToContainer(
_In_ IDxcBlob *pShader, // Shader to assemble.
@@ -255,8 +572,8 @@ IDxcAssembler : public IUnknown {
) = 0;
};
-struct __declspec(uuid("d2c21b26-8350-4bdc-976a-331ce6f4c54c"))
-IDxcContainerReflection : public IUnknown {
+CROSS_PLATFORM_UUIDOF(IDxcContainerReflection, "d2c21b26-8350-4bdc-976a-331ce6f4c54c")
+struct IDxcContainerReflection : public IUnknown {
virtual HRESULT STDMETHODCALLTYPE Load(_In_ IDxcBlob *pContainer) = 0; // Container to load.
virtual HRESULT STDMETHODCALLTYPE GetPartCount(_Out_ UINT32 *pResult) = 0;
virtual HRESULT STDMETHODCALLTYPE GetPartKind(UINT32 idx, _Out_ UINT32 *pResult) = 0;
@@ -265,8 +582,8 @@ IDxcContainerReflection : public IUnknown {
virtual HRESULT STDMETHODCALLTYPE GetPartReflection(UINT32 idx, REFIID iid, void **ppvObject) = 0;
};
-struct __declspec(uuid("AE2CD79F-CC22-453F-9B6B-B124E7A5204C"))
-IDxcOptimizerPass : public IUnknown {
+CROSS_PLATFORM_UUIDOF(IDxcOptimizerPass, "AE2CD79F-CC22-453F-9B6B-B124E7A5204C")
+struct IDxcOptimizerPass : public IUnknown {
virtual HRESULT STDMETHODCALLTYPE GetOptionName(_COM_Outptr_ LPWSTR *ppResult) = 0;
virtual HRESULT STDMETHODCALLTYPE GetDescription(_COM_Outptr_ LPWSTR *ppResult) = 0;
virtual HRESULT STDMETHODCALLTYPE GetOptionArgCount(_Out_ UINT32 *pCount) = 0;
@@ -274,8 +591,8 @@ IDxcOptimizerPass : public IUnknown {
virtual HRESULT STDMETHODCALLTYPE GetOptionArgDescription(UINT32 argIndex, _COM_Outptr_ LPWSTR *ppResult) = 0;
};
-struct __declspec(uuid("25740E2E-9CBA-401B-9119-4FB42F39F270"))
-IDxcOptimizer : public IUnknown {
+CROSS_PLATFORM_UUIDOF(IDxcOptimizer, "25740E2E-9CBA-401B-9119-4FB42F39F270")
+struct IDxcOptimizer : public IUnknown {
virtual HRESULT STDMETHODCALLTYPE GetAvailablePassCount(_Out_ UINT32 *pCount) = 0;
virtual HRESULT STDMETHODCALLTYPE GetAvailablePass(UINT32 index, _COM_Outptr_ IDxcOptimizerPass** ppResult) = 0;
virtual HRESULT STDMETHODCALLTYPE RunOptimizer(IDxcBlob *pBlob,
@@ -288,81 +605,154 @@ static const UINT32 DxcVersionInfoFlags_None = 0;
static const UINT32 DxcVersionInfoFlags_Debug = 1; // Matches VS_FF_DEBUG
static const UINT32 DxcVersionInfoFlags_Internal = 2; // Internal Validator (non-signing)
-struct __declspec(uuid("b04f5b50-2059-4f12-a8ff-a1e0cde1cc7e"))
-IDxcVersionInfo : public IUnknown {
+CROSS_PLATFORM_UUIDOF(IDxcVersionInfo, "b04f5b50-2059-4f12-a8ff-a1e0cde1cc7e")
+struct IDxcVersionInfo : public IUnknown {
virtual HRESULT STDMETHODCALLTYPE GetVersion(_Out_ UINT32 *pMajor, _Out_ UINT32 *pMinor) = 0;
virtual HRESULT STDMETHODCALLTYPE GetFlags(_Out_ UINT32 *pFlags) = 0;
};
-// {73e22d93-e6ce-47f3-b5bf-f0664f39c1b0}
-__declspec(selectany) extern const CLSID CLSID_DxcCompiler = {
- 0x73e22d93,
- 0xe6ce,
- 0x47f3,
- { 0xb5, 0xbf, 0xf0, 0x66, 0x4f, 0x39, 0xc1, 0xb0 }
+CROSS_PLATFORM_UUIDOF(IDxcVersionInfo2, "fb6904c4-42f0-4b62-9c46-983af7da7c83")
+struct IDxcVersionInfo2 : public IDxcVersionInfo {
+ virtual HRESULT STDMETHODCALLTYPE GetCommitInfo(
+ _Out_ UINT32 *pCommitCount, // The total number commits.
+ _Outptr_result_z_ char **pCommitHash // The SHA of the latest commit. (Must be CoTaskMemFree()'d!)
+ ) = 0;
+};
+
+CROSS_PLATFORM_UUIDOF(IDxcVersionInfo3, "5e13e843-9d25-473c-9ad2-03b2d0b44b1e")
+struct IDxcVersionInfo3 : public IUnknown {
+ virtual HRESULT STDMETHODCALLTYPE GetCustomVersionString(
+ _Outptr_result_z_ char **pVersionString // Custom version string for compiler. (Must be CoTaskMemFree()'d!)
+ ) = 0;
+};
+
+struct DxcArgPair {
+ const WCHAR *pName;
+ const WCHAR *pValue;
};
+CROSS_PLATFORM_UUIDOF(IDxcPdbUtils, "E6C9647E-9D6A-4C3B-B94C-524B5A6C343D")
+struct IDxcPdbUtils : public IUnknown {
+ virtual HRESULT STDMETHODCALLTYPE Load(_In_ IDxcBlob *pPdbOrDxil) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE GetSourceCount(_Out_ UINT32 *pCount) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetSource(_In_ UINT32 uIndex, _COM_Outptr_ IDxcBlobEncoding **ppResult) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetSourceName(_In_ UINT32 uIndex, _Outptr_result_z_ BSTR *pResult) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE GetFlagCount(_Out_ UINT32 *pCount) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetFlag(_In_ UINT32 uIndex, _Outptr_result_z_ BSTR *pResult) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE GetArgCount(_Out_ UINT32 *pCount) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetArg(_In_ UINT32 uIndex, _Outptr_result_z_ BSTR *pResult) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE GetArgPairCount(_Out_ UINT32 *pCount) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetArgPair(_In_ UINT32 uIndex, _Outptr_result_z_ BSTR *pName, _Outptr_result_z_ BSTR *pValue) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE GetDefineCount(_Out_ UINT32 *pCount) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetDefine(_In_ UINT32 uIndex, _Outptr_result_z_ BSTR *pResult) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE GetTargetProfile(_Outptr_result_z_ BSTR *pResult) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetEntryPoint(_Outptr_result_z_ BSTR *pResult) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetMainFileName(_Outptr_result_z_ BSTR *pResult) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE GetHash(_COM_Outptr_ IDxcBlob **ppResult) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetName(_Outptr_result_z_ BSTR *pResult) = 0;
+
+ virtual BOOL STDMETHODCALLTYPE IsFullPDB() = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetFullPDB(_COM_Outptr_ IDxcBlob **ppFullPDB) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE GetVersionInfo(_COM_Outptr_ IDxcVersionInfo **ppVersionInfo) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE SetCompiler(_In_ IDxcCompiler3 *pCompiler) = 0;
+ virtual HRESULT STDMETHODCALLTYPE CompileForFullPDB(_COM_Outptr_ IDxcResult **ppResult) = 0;
+ virtual HRESULT STDMETHODCALLTYPE OverrideArgs(_In_ DxcArgPair *pArgPairs, UINT32 uNumArgPairs) = 0;
+ virtual HRESULT STDMETHODCALLTYPE OverrideRootSignature(_In_ const WCHAR *pRootSignature) = 0;
+};
+
+// Note: __declspec(selectany) requires 'extern'
+// On Linux __declspec(selectany) is removed and using 'extern' results in link error.
+#ifdef _MSC_VER
+#define CLSID_SCOPE __declspec(selectany) extern
+#else
+#define CLSID_SCOPE
+#endif
+
+CLSID_SCOPE const CLSID CLSID_DxcCompiler = {
+ 0x73e22d93,
+ 0xe6ce,
+ 0x47f3,
+ {0xb5, 0xbf, 0xf0, 0x66, 0x4f, 0x39, 0xc1, 0xb0}};
+
// {EF6A8087-B0EA-4D56-9E45-D07E1A8B7806}
-__declspec(selectany) extern const GUID CLSID_DxcLinker = {
+CLSID_SCOPE const GUID CLSID_DxcLinker = {
0xef6a8087,
0xb0ea,
0x4d56,
- {0x9e, 0x45, 0xd0, 0x7e, 0x1a, 0x8b, 0x78, 0x6}
-};
+ {0x9e, 0x45, 0xd0, 0x7e, 0x1a, 0x8b, 0x78, 0x6}};
// {CD1F6B73-2AB0-484D-8EDC-EBE7A43CA09F}
-__declspec(selectany) extern const CLSID CLSID_DxcDiaDataSource = {
- 0xcd1f6b73,
- 0x2ab0,
- 0x484d,
- { 0x8e, 0xdc, 0xeb, 0xe7, 0xa4, 0x3c, 0xa0, 0x9f }
-};
+CLSID_SCOPE const CLSID CLSID_DxcDiaDataSource = {
+ 0xcd1f6b73,
+ 0x2ab0,
+ 0x484d,
+ {0x8e, 0xdc, 0xeb, 0xe7, 0xa4, 0x3c, 0xa0, 0x9f}};
+
+// {3E56AE82-224D-470F-A1A1-FE3016EE9F9D}
+CLSID_SCOPE const CLSID CLSID_DxcCompilerArgs = {
+ 0x3e56ae82,
+ 0x224d,
+ 0x470f,
+ {0xa1, 0xa1, 0xfe, 0x30, 0x16, 0xee, 0x9f, 0x9d}};
// {6245D6AF-66E0-48FD-80B4-4D271796748C}
-__declspec(selectany) extern const GUID CLSID_DxcLibrary = {
- 0x6245d6af,
- 0x66e0,
- 0x48fd,
- { 0x80, 0xb4, 0x4d, 0x27, 0x17, 0x96, 0x74, 0x8c }
-};
+CLSID_SCOPE const GUID CLSID_DxcLibrary = {
+ 0x6245d6af,
+ 0x66e0,
+ 0x48fd,
+ {0x80, 0xb4, 0x4d, 0x27, 0x17, 0x96, 0x74, 0x8c}};
+
+CLSID_SCOPE const GUID CLSID_DxcUtils = CLSID_DxcLibrary;
// {8CA3E215-F728-4CF3-8CDD-88AF917587A1}
-__declspec(selectany) extern const GUID CLSID_DxcValidator = {
- 0x8ca3e215,
- 0xf728,
- 0x4cf3,
- { 0x8c, 0xdd, 0x88, 0xaf, 0x91, 0x75, 0x87, 0xa1 }
-};
+CLSID_SCOPE const GUID CLSID_DxcValidator = {
+ 0x8ca3e215,
+ 0xf728,
+ 0x4cf3,
+ {0x8c, 0xdd, 0x88, 0xaf, 0x91, 0x75, 0x87, 0xa1}};
// {D728DB68-F903-4F80-94CD-DCCF76EC7151}
-__declspec(selectany) extern const GUID CLSID_DxcAssembler = {
- 0xd728db68,
- 0xf903,
- 0x4f80,
- { 0x94, 0xcd, 0xdc, 0xcf, 0x76, 0xec, 0x71, 0x51 }
-};
+CLSID_SCOPE const GUID CLSID_DxcAssembler = {
+ 0xd728db68,
+ 0xf903,
+ 0x4f80,
+ {0x94, 0xcd, 0xdc, 0xcf, 0x76, 0xec, 0x71, 0x51}};
// {b9f54489-55b8-400c-ba3a-1675e4728b91}
-__declspec(selectany) extern const GUID CLSID_DxcContainerReflection = {
- 0xb9f54489,
- 0x55b8,
- 0x400c,
- { 0xba, 0x3a, 0x16, 0x75, 0xe4, 0x72, 0x8b, 0x91 }
-};
+CLSID_SCOPE const GUID CLSID_DxcContainerReflection = {
+ 0xb9f54489,
+ 0x55b8,
+ 0x400c,
+ {0xba, 0x3a, 0x16, 0x75, 0xe4, 0x72, 0x8b, 0x91}};
// {AE2CD79F-CC22-453F-9B6B-B124E7A5204C}
-__declspec(selectany) extern const GUID CLSID_DxcOptimizer = {
+CLSID_SCOPE const GUID CLSID_DxcOptimizer = {
0xae2cd79f,
0xcc22,
0x453f,
- {0x9b, 0x6b, 0xb1, 0x24, 0xe7, 0xa5, 0x20, 0x4c}
-};
+ {0x9b, 0x6b, 0xb1, 0x24, 0xe7, 0xa5, 0x20, 0x4c}};
// {94134294-411f-4574-b4d0-8741e25240d2}
-__declspec(selectany) extern const GUID CLSID_DxcContainerBuilder = {
- 0x94134294,
- 0x411f,
- 0x4574,
- { 0xb4, 0xd0, 0x87, 0x41, 0xe2, 0x52, 0x40, 0xd2 }
-};
+CLSID_SCOPE const GUID CLSID_DxcContainerBuilder = {
+ 0x94134294,
+ 0x411f,
+ 0x4574,
+ {0xb4, 0xd0, 0x87, 0x41, 0xe2, 0x52, 0x40, 0xd2}};
+
+// {54621dfb-f2ce-457e-ae8c-ec355faeec7c}
+CLSID_SCOPE const GUID CLSID_DxcPdbUtils = {
+ 0x54621dfb,
+ 0xf2ce,
+ 0x457e,
+ {0xae, 0x8c, 0xec, 0x35, 0x5f, 0xae, 0xec, 0x7c}};
+
#endif
diff --git a/source/compiler-core/slang-downstream-compiler.h b/source/compiler-core/slang-downstream-compiler.h
index a543f8e46..e7ab4ddad 100644
--- a/source/compiler-core/slang-downstream-compiler.h
+++ b/source/compiler-core/slang-downstream-compiler.h
@@ -191,6 +191,8 @@ public:
virtual SLANG_NO_THROW bool SLANG_MCALL canConvert(const ArtifactDesc& from, const ArtifactDesc& to) = 0;
/// Converts an artifact `from` to a desc of `to` and puts the result in outArtifact
virtual SLANG_NO_THROW SlangResult SLANG_MCALL convert(IArtifact* from, const ArtifactDesc& to, IArtifact** outArtifact) = 0;
+ /// Get the version of this compiler
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL getVersionString(slang::IBlob** outVersionString) = 0;
/// True if underlying compiler uses file system to communicate source
virtual SLANG_NO_THROW bool SLANG_MCALL isFileBased() = 0;
@@ -208,6 +210,7 @@ public:
virtual SLANG_NO_THROW const Desc& SLANG_MCALL getDesc() SLANG_OVERRIDE { return m_desc; }
virtual SLANG_NO_THROW bool SLANG_MCALL canConvert(const ArtifactDesc& from, const ArtifactDesc& to) SLANG_OVERRIDE { SLANG_UNUSED(from); SLANG_UNUSED(to); return false; }
virtual SLANG_NO_THROW SlangResult SLANG_MCALL convert(IArtifact* from, const ArtifactDesc& to, IArtifact** outArtifact) SLANG_OVERRIDE;
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL getVersionString(slang::IBlob** outVersionString) SLANG_OVERRIDE { *outVersionString = nullptr; return SLANG_FAIL; }
DownstreamCompilerBase(const Desc& desc):
m_desc(desc)
diff --git a/source/compiler-core/slang-dxc-compiler.cpp b/source/compiler-core/slang-dxc-compiler.cpp
index c92eea47b..6619d000c 100644
--- a/source/compiler-core/slang-dxc-compiler.cpp
+++ b/source/compiler-core/slang-dxc-compiler.cpp
@@ -14,6 +14,8 @@
#include "../core/slang-semantic-version.h"
#include "../core/slang-char-util.h"
+#include "../core/slang-digest.h"
+
#include "slang-include-system.h"
#include "slang-source-loc.h"
@@ -168,6 +170,7 @@ public:
virtual SLANG_NO_THROW bool SLANG_MCALL canConvert(const ArtifactDesc& from, const ArtifactDesc& to) SLANG_OVERRIDE;
virtual SLANG_NO_THROW SlangResult SLANG_MCALL convert(IArtifact* from, const ArtifactDesc& to, IArtifact** outArtifact) SLANG_OVERRIDE;
virtual SLANG_NO_THROW bool SLANG_MCALL isFileBased() SLANG_OVERRIDE { return false; }
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL getVersionString(slang::IBlob** outVersionString) SLANG_OVERRIDE;
/// Must be called before use
SlangResult init(ISlangSharedLibrary* library);
@@ -191,7 +194,7 @@ SlangResult DXCDownstreamCompiler::init(ISlangSharedLibrary* library)
return SLANG_FAIL;
}
- m_desc = Desc(SLANG_PASS_THROUGH_DXC);
+ m_desc = Desc(SLANG_PASS_THROUGH_DXC);
return SLANG_OK;
}
@@ -572,6 +575,52 @@ SlangResult DXCDownstreamCompiler::convert(IArtifact* from, const ArtifactDesc&
return SLANG_OK;
}
+SlangResult DXCDownstreamCompiler::getVersionString(slang::IBlob** outVersionString)
+{
+ ComPtr<IDxcCompiler> dxcCompiler;
+ SLANG_RETURN_ON_FAIL(m_createInstance(CLSID_DxcCompiler, __uuidof(dxcCompiler), (LPVOID*)dxcCompiler.writeRef()));
+
+ ComPtr<ISlangBlob> version;
+ ComPtr<IDxcVersionInfo> versionInfo;
+ if (SLANG_SUCCEEDED(dxcCompiler->QueryInterface(versionInfo.writeRef())))
+ {
+ // Because the major/minor version alone does not necessarily capture different releases
+ // of the DX compiler, we also need to query for the commit hash. If we are unable to
+ // obtain the commit hash, then we return the shared library timestamp instead.
+ ComPtr<IDxcVersionInfo2> versionInfo2;
+ if (SLANG_SUCCEEDED(dxcCompiler->QueryInterface(versionInfo2.writeRef())))
+ {
+ uint32_t major;
+ uint32_t minor;
+ versionInfo->GetVersion(&major, &minor);
+
+ StringBuilder versionString;
+ versionString.append(major);
+ versionString.append(".");
+ versionString.append(minor);
+
+ char* commitHash;
+ uint32_t unused;
+ versionInfo2->GetCommitInfo(&unused, &commitHash);
+
+ versionString.append(commitHash);
+ CoTaskMemFree(commitHash);
+
+ version = StringBlob::create(versionString.getBuffer());
+ *outVersionString = version.detach();
+ return SLANG_OK;
+ }
+ }
+
+ // If either of the QueryInterface calls fails, we return the shared library timestamp
+ // as the version instead.
+ auto timestamp = SharedLibraryUtils::getSharedLibraryTimestamp(m_createInstance);
+ auto timestampString = String(timestamp);
+ version = StringBlob::create(timestampString.getBuffer());
+ *outVersionString = version.detach();
+ return SLANG_OK;
+}
+
/* static */SlangResult DXCDownstreamCompilerUtil::locateCompilers(const String& path, ISlangSharedLibraryLoader* loader, DownstreamCompilerSet* set)
{
ComPtr<ISlangSharedLibrary> library;
diff --git a/source/compiler-core/slang-glslang-compiler.cpp b/source/compiler-core/slang-glslang-compiler.cpp
index d6ae59690..26cbf3292 100644
--- a/source/compiler-core/slang-glslang-compiler.cpp
+++ b/source/compiler-core/slang-glslang-compiler.cpp
@@ -14,6 +14,8 @@
#include "../core/slang-semantic-version.h"
#include "../core/slang-char-util.h"
+#include "../core/slang-digest.h"
+
#include "slang-artifact-associated-impl.h"
#include "slang-artifact-desc-util.h"
@@ -47,6 +49,7 @@ public:
virtual SLANG_NO_THROW bool SLANG_MCALL canConvert(const ArtifactDesc& from, const ArtifactDesc& to) SLANG_OVERRIDE;
virtual SLANG_NO_THROW SlangResult SLANG_MCALL convert(IArtifact* from, const ArtifactDesc& to, IArtifact** outArtifact) SLANG_OVERRIDE;
virtual SLANG_NO_THROW bool SLANG_MCALL isFileBased() SLANG_OVERRIDE { return false; }
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL getVersionString(slang::IBlob** outVersionString) SLANG_OVERRIDE;
/// Must be called before use
SlangResult init(ISlangSharedLibrary* library);
@@ -60,7 +63,7 @@ protected:
glslang_CompileFunc_1_0 m_compile_1_0 = nullptr;
glslang_CompileFunc_1_1 m_compile_1_1 = nullptr;
- ComPtr<ISlangSharedLibrary> m_sharedLibrary;
+ ComPtr<ISlangSharedLibrary> m_sharedLibrary;
};
SlangResult GlslangDownstreamCompiler::init(ISlangSharedLibrary* library)
@@ -78,6 +81,20 @@ SlangResult GlslangDownstreamCompiler::init(ISlangSharedLibrary* library)
// It's not clear how to query for a version, but we can get a version number from the header
m_desc = Desc(SLANG_PASS_THROUGH_GLSLANG);
+ Slang::String filename;
+ if (m_compile_1_1)
+ {
+ filename = Slang::SharedLibraryUtils::getSharedLibraryFileName((void*)m_compile_1_1);
+ }
+ else if (m_compile_1_0)
+ {
+ filename = Slang::SharedLibraryUtils::getSharedLibraryFileName((void*)m_compile_1_0);
+ }
+ else
+ {
+ return SLANG_FAIL;
+ }
+
return SLANG_OK;
}
@@ -277,6 +294,28 @@ SlangResult GlslangDownstreamCompiler::convert(IArtifact* from, const ArtifactDe
return SLANG_OK;
}
+SlangResult GlslangDownstreamCompiler::getVersionString(slang::IBlob** outVersionString)
+{
+ uint64_t timestamp;
+ if (m_compile_1_1)
+ {
+ timestamp = SharedLibraryUtils::getSharedLibraryTimestamp((void*)m_compile_1_1);
+ }
+ else if (m_compile_1_0)
+ {
+ timestamp = SharedLibraryUtils::getSharedLibraryTimestamp((void*)m_compile_1_0);
+ }
+ else
+ {
+ return SLANG_FAIL;
+ }
+
+ auto timestampString = String(timestamp);
+ ComPtr<ISlangBlob> version = StringBlob::create(timestampString.getBuffer());
+ *outVersionString = version.detach();
+ return SLANG_OK;
+}
+
/* static */SlangResult GlslangDownstreamCompilerUtil::locateCompilers(const String& path, ISlangSharedLibraryLoader* loader, DownstreamCompilerSet* set)
{
ComPtr<ISlangSharedLibrary> library;
diff --git a/source/core/slang-md5.cpp b/source/core/slang-md5.cpp
index 95b4816bf..7371b21d2 100644
--- a/source/core/slang-md5.cpp
+++ b/source/core/slang-md5.cpp
@@ -232,6 +232,11 @@ namespace Slang
update(ctx, hash.values, sizeof(hash.values));
}
+ void MD5HashGen::update(MD5Context* ctx, ISlangBlob* blob)
+ {
+ update(ctx, blob->getBufferPointer(), blob->getBufferSize());
+ }
+
void MD5HashGen::update(MD5Context* ctx, const void* data, SlangInt size)
{
MD5_u32plus saved_lo;
diff --git a/source/core/slang-md5.h b/source/core/slang-md5.h
index 8c51a03ec..2e99fb667 100644
--- a/source/core/slang-md5.h
+++ b/source/core/slang-md5.h
@@ -70,6 +70,8 @@ namespace Slang
void update(MD5Context* ctx, String str);
// Helper update function for Checksums
void update(MD5Context* ctx, const slang::Digest& checksum);
+ // Helper update function for ISlangBlob
+ void update(MD5Context* ctx, ISlangBlob* blob);
void finalize(MD5Context* ctx, slang::Digest* result);
diff --git a/source/slang/slang-ast-base.h b/source/slang/slang-ast-base.h
index dea02afbb..04788340a 100644
--- a/source/slang/slang-ast-base.h
+++ b/source/slang/slang-ast-base.h
@@ -9,6 +9,8 @@
#include "slang-serialize-reflection.h"
+#include "../core/slang-digest.h"
+
// This file defines the primary base classes for the hierarchy of
// AST nodes and related objects. For example, this is where the
// basic `Decl`, `Stmt`, `Expr`, `type`, etc. definitions come from.
diff --git a/source/slang/slang-ast-type.cpp b/source/slang/slang-ast-type.cpp
index 39b7a8e04..480589af4 100644
--- a/source/slang/slang-ast-type.cpp
+++ b/source/slang/slang-ast-type.cpp
@@ -1089,7 +1089,6 @@ Val* AndType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet su
// ModifiedType
-
void ModifiedType::_toTextOverride(StringBuilder& out)
{
for( auto modifier : modifiers )
diff --git a/source/slang/slang-ast-type.h b/source/slang/slang-ast-type.h
index 5bb91e5da..895b64f35 100644
--- a/source/slang/slang-ast-type.h
+++ b/source/slang/slang-ast-type.h
@@ -26,7 +26,6 @@ class InitializerListType : public Type
{
SLANG_AST_CLASS(InitializerListType)
-
// Overrides should be public so base classes can access
void _toTextOverride(StringBuilder& out);
Type* _createCanonicalTypeOverride();
@@ -694,7 +693,7 @@ class NamespaceType : public Type
void _toTextOverride(StringBuilder& out);
bool _equalsImplOverride(Type* type);
HashCode _getHashCodeOverride();
- Type* _createCanonicalTypeOverride();
+ Type* _createCanonicalTypeOverride();
};
// The concrete type for a value wrapped in an existential, accessible
diff --git a/source/slang/slang-ast-val.h b/source/slang/slang-ast-val.h
index a67d62e3b..49189f65c 100644
--- a/source/slang/slang-ast-val.h
+++ b/source/slang/slang-ast-val.h
@@ -3,6 +3,7 @@
#pragma once
#include "slang-ast-base.h"
+#include "../core/slang-digest.h"
namespace Slang {
@@ -379,7 +380,6 @@ class TaggedUnionSubtypeWitness : public SubtypeWitness
//
List<Val*> caseWitnesses;
-
// Overrides should be public so base classes can access
bool _equalsValOverride(Val* val);
void _toTextOverride(StringBuilder& out);
diff --git a/source/slang/slang-hash-utils.h b/source/slang/slang-hash-utils.h
index 62232dd21..c354e43f0 100644
--- a/source/slang/slang-hash-utils.h
+++ b/source/slang/slang-hash-utils.h
@@ -29,12 +29,13 @@ namespace Slang
{
StringBuilder filename;
- for (Index i = 0; i < 4; ++i)
+ uint8_t* uint8Hash = (uint8_t*)hash.values;
+
+ for (Index i = 0; i < 16; ++i)
{
- auto hashSegmentString = String(hash.values[i], 16);
+ auto hashSegmentString = String(uint8Hash[i], 16);
- auto leadingZeroCount = 8 - hashSegmentString.getLength();
- for (Index j = 0; j < leadingZeroCount; ++j)
+ if (hashSegmentString.getLength() == 1)
{
filename.append("0");
}
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index 20cad2465..3fb89c549 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -1367,6 +1367,18 @@ void Linkage::updateDependencyBasedHash(
{
builder.addToDigest(capability);
}
+
+ // Add the downstream compiler version (if it exists) to the hash
+ auto passThroughMode = getDownstreamCompilerRequiredForTarget(targetReq->getTarget());
+ auto downstreamCompiler = getSessionImpl()->getOrLoadDownstreamCompiler(passThroughMode, nullptr);
+ if (downstreamCompiler)
+ {
+ ComPtr<ISlangBlob> versionString;
+ if (SLANG_SUCCEEDED(downstreamCompiler->getVersionString(versionString.writeRef())))
+ {
+ builder.addToDigest(versionString);
+ }
+ }
}
SlangResult Linkage::addSearchPath(
diff --git a/tools/gfx-unit-test/shader-cache-shader.slang b/tools/gfx-unit-test/shader-cache-shader.slang
index c2dbe56f0..341e32893 100644
--- a/tools/gfx-unit-test/shader-cache-shader.slang
+++ b/tools/gfx-unit-test/shader-cache-shader.slang
@@ -6,5 +6,5 @@ uniform RWStructuredBuffer<float> buffer;
uint3 sv_dispatchThreadID : SV_DispatchThreadID)
{
var input = buffer[sv_dispatchThreadID.x];
- buffer[sv_dispatchThreadID.x] = input + 3.0f;
+ buffer[sv_dispatchThreadID.x] = input + 1.0f;
} \ No newline at end of file
diff --git a/tools/slang-unit-test/unit-test-checksum.cpp b/tools/slang-unit-test/unit-test-checksum.cpp
index 8980bd31f..90f426f94 100644
--- a/tools/slang-unit-test/unit-test-checksum.cpp
+++ b/tools/slang-unit-test/unit-test-checksum.cpp
@@ -16,7 +16,7 @@ SLANG_UNIT_TEST(checksum)
testA.values[3] = 4;
String testAString = hashToString(testA);
- SLANG_CHECK(testAString.equals(String("00000001000000020000000300000004")));
+ SLANG_CHECK(testAString.equals(String("01000000020000000300000004000000")));
}
{
diff --git a/tools/slang-unit-test/unit-test-md5.cpp b/tools/slang-unit-test/unit-test-md5.cpp
index 95235e0ed..0e7fef57c 100644
--- a/tools/slang-unit-test/unit-test-md5.cpp
+++ b/tools/slang-unit-test/unit-test-md5.cpp
@@ -24,7 +24,7 @@ SLANG_UNIT_TEST(md5hash)
testHashGen.finalize(&testCtx, &testA);
String testAString = hashToString(testA);
- SLANG_CHECK(testAString.equals(String("E271A15BD2BD98081390630579266F74")));
+ SLANG_CHECK(testAString.equals(String("5BA171E20898BDD205639013746F2679")));
}
{
@@ -44,7 +44,7 @@ SLANG_UNIT_TEST(md5hash)
testHashGen.finalize(&testCtx, &testB);
String testBString = hashToString(testB);
- SLANG_CHECK(testBString.equals(String("8AD852437539AA78D60CF70BA5CA7BF2")));
+ SLANG_CHECK(testBString.equals(String("4352D88A78AA39750BF70CD6F27BCAA5")));
}
{
@@ -60,7 +60,7 @@ SLANG_UNIT_TEST(md5hash)
testHashGen.finalize(&testCtx, &testC);
String testCString = hashToString(testC);
- SLANG_CHECK(testCString.equals(String("8EC56C5DDFA424183957CFD01633605B")));
+ SLANG_CHECK(testCString.equals(String("5D6CC58E1824A4DFD0CF57395B603316")));
}
{
@@ -76,7 +76,7 @@ SLANG_UNIT_TEST(md5hash)
testHashGen.finalize(&testCtx, &testD);
String testDString = hashToString(testD);
- SLANG_CHECK(testDString.equals(String("CC795ADF40C7702106A5F01C24CEB0CE")));
+ SLANG_CHECK(testDString.equals(String("DF5A79CC2170C7401CF0A506CEB0CE24")));
}
{
@@ -92,6 +92,6 @@ SLANG_UNIT_TEST(md5hash)
testHashGen.finalize(&testCtx, &testE);
String testEString = hashToString(testE);
- SLANG_CHECK(testEString.equals(String("3613E74ABFF94BE42E75D279A5184823")));
+ SLANG_CHECK(testEString.equals(String("4AE71336E44BF9BF79D2752E234818A5")));
}
}