Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com>
---
Makefile.am | 2 +-
include/vkd3d_d3dcommon.idl | 26 +++++
include/vkd3d_d3dcompiler.h | 46 +++++++++
include/vkd3d_utils.h | 8 ++
include/vkd3d_windows.h | 2 +
libs/vkd3d-utils/vkd3d_utils.map | 2 +
libs/vkd3d-utils/vkd3d_utils_main.c | 125 +++++++++++++++++++++++++
libs/vkd3d-utils/vkd3d_utils_private.h | 1 +
8 files changed, 211 insertions(+), 1 deletion(-)
diff --git a/Makefile.am b/Makefile.am
index 6f8af578..22a245e9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -127,7 +127,7 @@ libvkd3d_utils_la_SOURCES = \
libs/vkd3d-utils/vkd3d_utils_main.c \
libs/vkd3d-utils/vkd3d_utils_private.h
libvkd3d_utils_la_LDFLAGS = $(AM_LDFLAGS) -version-info 2:0:1
-libvkd3d_utils_la_LIBADD = libvkd3d-common.la libvkd3d.la @PTHREAD_LIBS@
+libvkd3d_utils_la_LIBADD = libvkd3d-common.la libvkd3d-shader.la libvkd3d.la @PTHREAD_LIBS@
if HAVE_LD_VERSION_SCRIPT
libvkd3d_utils_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libs/vkd3d-utils/vkd3d_utils.map
EXTRA_libvkd3d_utils_la_DEPENDENCIES = $(srcdir)/libs/vkd3d-utils/vkd3d_utils.map
diff --git a/include/vkd3d_d3dcommon.idl b/include/vkd3d_d3dcommon.idl
index 8bfa567c..e43cbe41 100644
--- a/include/vkd3d_d3dcommon.idl
+++ b/include/vkd3d_d3dcommon.idl
@@ -93,3 +93,29 @@ interface ID3D10Blob : IUnknown
typedef ID3D10Blob ID3DBlob;
cpp_quote("#define IID_ID3DBlob IID_ID3D10Blob")
+
+typedef enum _D3D_INCLUDE_TYPE
+{
+ D3D_INCLUDE_LOCAL = 0,
+ D3D_INCLUDE_SYSTEM,
+ D3D10_INCLUDE_LOCAL = D3D_INCLUDE_LOCAL,
+ D3D10_INCLUDE_SYSTEM = D3D_INCLUDE_SYSTEM,
+ D3D_INCLUDE_FORCE_DWORD = 0x7fffffff,
+} D3D_INCLUDE_TYPE;
+
+[
+ object,
+ local,
+]
+interface ID3DInclude
+{
+ HRESULT Open(D3D_INCLUDE_TYPE include_type, const char *filename, const void *parent_data, const void **data,
+ UINT *size);
+ HRESULT Close(const void *data);
+}
+
+typedef struct _D3D_SHADER_MACRO
+{
+ const char *Name;
+ const char *Definition;
+} D3D_SHADER_MACRO;
diff --git a/include/vkd3d_d3dcompiler.h b/include/vkd3d_d3dcompiler.h
index 25f60449..7137294f 100644
--- a/include/vkd3d_d3dcompiler.h
+++ b/include/vkd3d_d3dcompiler.h
@@ -20,6 +20,52 @@
#define __VKD3D_D3DCOMPILER_H
#ifndef __D3DCOMPILER_H__
+#define D3DCOMPILE_DEBUG 0x00000001
+#define D3DCOMPILE_SKIP_VALIDATION 0x00000002
+#define D3DCOMPILE_SKIP_OPTIMIZATION 0x00000004
+#define D3DCOMPILE_PACK_MATRIX_ROW_MAJOR 0x00000008
+#define D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR 0x00000010
+#define D3DCOMPILE_PARTIAL_PRECISION 0x00000020
+#define D3DCOMPILE_FORCE_VS_SOFTWARE_NO_OPT 0x00000040
+#define D3DCOMPILE_FORCE_PS_SOFTWARE_NO_OPT 0x00000080
+#define D3DCOMPILE_NO_PRESHADER 0x00000100
+#define D3DCOMPILE_AVOID_FLOW_CONTROL 0x00000200
+#define D3DCOMPILE_PREFER_FLOW_CONTROL 0x00000400
+#define D3DCOMPILE_ENABLE_STRICTNESS 0x00000800
+#define D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY 0x00001000
+#define D3DCOMPILE_IEEE_STRICTNESS 0x00002000
+#define D3DCOMPILE_OPTIMIZATION_LEVEL0 0x00004000
+#define D3DCOMPILE_OPTIMIZATION_LEVEL1 0x00000000
+#define D3DCOMPILE_OPTIMIZATION_LEVEL2 0x0000c000
+#define D3DCOMPILE_OPTIMIZATION_LEVEL3 0x00008000
+#define D3DCOMPILE_RESERVED16 0x00010000
+#define D3DCOMPILE_RESERVED17 0x00020000
+#define D3DCOMPILE_WARNINGS_ARE_ERRORS 0x00040000
+#define D3DCOMPILE_RESOURCES_MAY_ALIAS 0x00080000
+#define D3DCOMPILE_ENABLE_UNBOUNDED_DESCRIPTOR_TABLES 0x00100000
+#define D3DCOMPILE_ALL_RESOURCES_BOUND 0x00200000
+#define D3DCOMPILE_DEBUG_NAME_FOR_SOURCE 0x00400000
+#define D3DCOMPILE_DEBUG_NAME_FOR_BINARY 0x00800000
+
+#define D3DCOMPILE_EFFECT_CHILD_EFFECT 0x00000001
+#define D3DCOMPILE_EFFECT_ALLOW_SLOW_OPS 0x00000002
+
+#define D3DCOMPILE_FLAGS2_FORCE_ROOT_SIGNATURE_LATEST 0x00000000
+#define D3DCOMPILE_FLAGS2_FORCE_ROOT_SIGNATURE_1_0 0x00000010
+#define D3DCOMPILE_FLAGS2_FORCE_ROOT_SIGNATURE_1_1 0x00000020
+
+#define D3DCOMPILE_SECDATA_MERGE_UAV_SLOTS 0x00000001
+#define D3DCOMPILE_SECDATA_PRESERVE_TEMPLATE_SLOTS 0x00000002
+#define D3DCOMPILE_SECDATA_REQUIRE_TEMPLATE_MATCH 0x00000004
+
+HRESULT WINAPI D3DCompile(const void *data, SIZE_T data_size, const char *filename,
+ const D3D_SHADER_MACRO *macros, ID3DInclude *include, const char *entrypoint,
+ const char *profile, UINT flags, UINT effect_flags, ID3DBlob **shader, ID3DBlob **error_messages);
+HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filename,
+ const D3D_SHADER_MACRO *macros, ID3DInclude *include, const char *entrypoint,
+ const char *profile, UINT flags, UINT effect_flags, UINT secondary_flags,
+ const void *secondary_data, SIZE_T secondary_data_size, ID3DBlob **shader,
+ ID3DBlob **error_messages);
HRESULT WINAPI D3DCreateBlob(SIZE_T size, ID3D10Blob **blob);
#endif /* __D3DCOMPILER_H__ */
diff --git a/include/vkd3d_utils.h b/include/vkd3d_utils.h
index f1fc4dbd..c005d4e9 100644
--- a/include/vkd3d_utils.h
+++ b/include/vkd3d_utils.h
@@ -55,6 +55,14 @@ HRESULT WINAPI D3D12SerializeVersionedRootSignature(const D3D12_VERSIONED_ROOT_S
ID3DBlob **blob, ID3DBlob **error_blob);
/* 1.3 */
+HRESULT WINAPI D3DCompile(const void *data, SIZE_T data_size, const char *filename,
+ const D3D_SHADER_MACRO *defines, ID3DInclude *include, const char *entrypoint,
+ const char *target, UINT flags, UINT effect_flags, ID3DBlob **shader, ID3DBlob **error_messages);
+HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filename,
+ const D3D_SHADER_MACRO *defines, ID3DInclude *include, const char *entrypoint,
+ const char *target, UINT flags, UINT effect_flags, UINT secondary_flags,
+ const void *secondary_data, SIZE_T secondary_data_size, ID3DBlob **shader,
+ ID3DBlob **error_messages);
HRESULT WINAPI D3DCreateBlob(SIZE_T data_size, ID3D10Blob **blob);
#ifdef __cplusplus
diff --git a/include/vkd3d_windows.h b/include/vkd3d_windows.h
index ad2f08a6..8398d403 100644
--- a/include/vkd3d_windows.h
+++ b/include/vkd3d_windows.h
@@ -65,6 +65,8 @@ typedef int HRESULT;
# define DXGI_ERROR_NOT_FOUND _HRESULT_TYPEDEF_(0x887a0002)
# define DXGI_ERROR_MORE_DATA _HRESULT_TYPEDEF_(0x887a0003)
+# define D3DERR_INVALIDCALL _HRESULT_TYPEDEF_(0x8876086c)
+
/* Basic types */
typedef unsigned char BYTE;
typedef unsigned int DWORD;
diff --git a/libs/vkd3d-utils/vkd3d_utils.map b/libs/vkd3d-utils/vkd3d_utils.map
index 20d182c5..337409ee 100644
--- a/libs/vkd3d-utils/vkd3d_utils.map
+++ b/libs/vkd3d-utils/vkd3d_utils.map
@@ -8,6 +8,8 @@ global:
D3D12GetDebugInterface;
D3D12SerializeRootSignature;
D3D12SerializeVersionedRootSignature;
+ D3DCompile;
+ D3DCompile2;
D3DCreateBlob;
vkd3d_create_event;
vkd3d_destroy_event;
diff --git a/libs/vkd3d-utils/vkd3d_utils_main.c b/libs/vkd3d-utils/vkd3d_utils_main.c
index ffb655f8..8f54ac86 100644
--- a/libs/vkd3d-utils/vkd3d_utils_main.c
+++ b/libs/vkd3d-utils/vkd3d_utils_main.c
@@ -125,6 +125,131 @@ HRESULT WINAPI D3D12SerializeVersionedRootSignature(const D3D12_VERSIONED_ROOT_S
return vkd3d_serialize_versioned_root_signature(desc, blob, error_blob);
}
+static int open_include(const char *filename, bool local, const char *parent_data, void *context,
+ struct vkd3d_shader_code *code)
+{
+ ID3DInclude *iface = context;
+ unsigned int size;
+
+ if (FAILED(ID3DInclude_Open(iface, local ? D3D_INCLUDE_LOCAL : D3D_INCLUDE_SYSTEM,
+ filename, parent_data, &code->code, &size)))
+ return VKD3D_ERROR;
+
+ code->size = size;
+ return VKD3D_OK;
+}
+
+static void close_include(const struct vkd3d_shader_code *code, void *context)
+{
+ ID3DInclude *iface = context;
+
+ ID3DInclude_Close(iface, code->code);
+}
+
+HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filename,
+ const D3D_SHADER_MACRO *macros, ID3DInclude *include, const char *entry_point,
+ const char *profile, UINT flags, UINT effect_flags, UINT secondary_flags,
+ const void *secondary_data, SIZE_T secondary_data_size, ID3DBlob **shader_blob,
+ ID3DBlob **messages_blob)
+{
+ struct vkd3d_shader_preprocess_info preprocess_info;
+ struct vkd3d_shader_hlsl_source_info hlsl_info;
+ struct vkd3d_shader_compile_option options[1];
+ struct vkd3d_shader_compile_info compile_info;
+ struct vkd3d_shader_code byte_code;
+ const D3D_SHADER_MACRO *macro;
+ char *messages;
+ HRESULT hr;
+ int ret;
+
+ TRACE("data %p, data_size %lu, filename %s, macros %p, include %p, entry_point %s, "
+ "profile %s, flags %#x, effect_flags %#x, secondary_flags %#x, secondary_data %p, "
+ "secondary_data_size %lu, shader_blob %p, messages_blob %p.\n",
+ data, data_size, debugstr_a(filename), macros, include, debugstr_a(entry_point),
+ debugstr_a(profile), flags, effect_flags, secondary_flags, secondary_data,
+ secondary_data_size, shader_blob, messages_blob);
+
+ if (flags & ~D3DCOMPILE_DEBUG)
+ FIXME("Ignoring flags %#x.\n", flags);
+ if (effect_flags)
+ FIXME("Ignoring effect flags %#x.\n", effect_flags);
+ if (secondary_flags)
+ FIXME("Ignoring secondary flags %#x.\n", secondary_flags);
+
+ compile_info.type = VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO;
+ compile_info.next = &preprocess_info;
+ compile_info.source.code = data;
+ compile_info.source.size = data_size;
+ compile_info.source_type = VKD3D_SHADER_SOURCE_HLSL;
+ compile_info.target_type = VKD3D_SHADER_TARGET_DXBC_TPF;
+ compile_info.options = options;
+ compile_info.option_count = 0;
+ compile_info.log_level = VKD3D_SHADER_LOG_INFO;
+ compile_info.source_name = filename;
+
+ preprocess_info.type = VKD3D_SHADER_STRUCTURE_TYPE_PREPROCESS_INFO;
+ preprocess_info.next = &hlsl_info;
+ preprocess_info.macros = (const struct vkd3d_shader_macro *)macros;
+ preprocess_info.macro_count = 0;
+ if (macros)
+ {
+ for (macro = macros; macro->Name; ++macro)
+ ++preprocess_info.macro_count;
+ }
+ preprocess_info.pfn_open_include = open_include;
+ preprocess_info.pfn_close_include = close_include;
+ preprocess_info.include_context = include;
+
+ hlsl_info.type = VKD3D_SHADER_STRUCTURE_TYPE_HLSL_SOURCE_INFO;
+ hlsl_info.next = NULL;
+ hlsl_info.profile = profile;
+ hlsl_info.entry_point = entry_point;
+ hlsl_info.secondary_code.code = secondary_data;
+ hlsl_info.secondary_code.size = secondary_data_size;
+
+ if (!(flags & D3DCOMPILE_DEBUG))
+ options[compile_info.option_count++].name = VKD3D_SHADER_COMPILE_OPTION_STRIP_DEBUG;
+
+ ret = vkd3d_shader_compile(&compile_info, &byte_code, &messages);
+ if (messages)
+ {
+ if (messages_blob)
+ {
+ if (FAILED(hr = vkd3d_blob_create(messages, strlen(messages), messages_blob)))
+ {
+ vkd3d_shader_free_shader_code(&byte_code);
+ return hr;
+ }
+ }
+ else
+ vkd3d_shader_free_messages(messages);
+ }
+
+ if (!ret)
+ {
+ if (FAILED(hr = vkd3d_blob_create((void *)byte_code.code, byte_code.size, shader_blob)))
+ {
+ vkd3d_shader_free_shader_code(&byte_code);
+ return hr;
+ }
+ }
+
+ return hresult_from_vkd3d_result(ret);
+}
+
+HRESULT WINAPI D3DCompile(const void *data, SIZE_T data_size, const char *filename,
+ const D3D_SHADER_MACRO *macros, ID3DInclude *include, const char *entrypoint,
+ const char *profile, UINT flags, UINT effect_flags, ID3DBlob **shader, ID3DBlob **error_messages)
+{
+ TRACE("data %p, data_size %lu, filename %s, macros %p, include %p, entrypoint %s, "
+ "profile %s, flags %#x, effect_flags %#x, shader %p, error_messages %p.\n",
+ data, data_size, debugstr_a(filename), macros, include, debugstr_a(entrypoint),
+ debugstr_a(profile), flags, effect_flags, shader, error_messages);
+
+ return D3DCompile2(data, data_size, filename, macros, include, entrypoint, profile, flags,
+ effect_flags, 0, NULL, 0, shader, error_messages);
+}
+
/* Events */
HANDLE vkd3d_create_event(void)
{
diff --git a/libs/vkd3d-utils/vkd3d_utils_private.h b/libs/vkd3d-utils/vkd3d_utils_private.h
index 3c73f421..06ac7e6b 100644
--- a/libs/vkd3d-utils/vkd3d_utils_private.h
+++ b/libs/vkd3d-utils/vkd3d_utils_private.h
@@ -26,6 +26,7 @@
#include <pthread.h>
#include <vkd3d.h>
#include <vkd3d_shader.h>
+#include <vkd3d_d3dcompiler.h>
#include "vkd3d_blob.h"
#include "vkd3d_memory.h"
--
2.28.0