Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- Makefile.am | 1 + include/private/vkd3d_common.h | 3 +++ libs/vkd3d-common/error.c | 43 ++++++++++++++++++++++++++++++++++ libs/vkd3d/utils.c | 23 ------------------ 4 files changed, 47 insertions(+), 23 deletions(-) create mode 100644 libs/vkd3d-common/error.c
diff --git a/Makefile.am b/Makefile.am index 07426fb4..6f8af578 100644 --- a/Makefile.am +++ b/Makefile.am @@ -67,6 +67,7 @@ libvkd3d_common_la_SOURCES = \ include/private/vkd3d_debug.h \ libs/vkd3d-common/blob.c \ libs/vkd3d-common/debug.c \ + libs/vkd3d-common/error.c \ libs/vkd3d-common/memory.c \ libs/vkd3d-common/utf8.c
diff --git a/include/private/vkd3d_common.h b/include/private/vkd3d_common.h index ac217e9e..ed80f48a 100644 --- a/include/private/vkd3d_common.h +++ b/include/private/vkd3d_common.h @@ -21,6 +21,7 @@
#include "config.h" #include "vkd3d_windows.h" +#include "vkd3d_types.h"
#include <ctype.h> #include <limits.h> @@ -183,4 +184,6 @@ static inline void vkd3d_parse_version(const char *version, int *major, int *min *minor = atoi(version); }
+HRESULT hresult_from_vkd3d_result(int vkd3d_result) DECLSPEC_HIDDEN; + #endif /* __VKD3D_COMMON_H */ diff --git a/libs/vkd3d-common/error.c b/libs/vkd3d-common/error.c new file mode 100644 index 00000000..81c1fd97 --- /dev/null +++ b/libs/vkd3d-common/error.c @@ -0,0 +1,43 @@ +/* + * Copyright 2018 Józef Kucia for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "vkd3d_common.h" +#include "vkd3d_debug.h" + +HRESULT hresult_from_vkd3d_result(int vkd3d_result) +{ + switch (vkd3d_result) + { + case VKD3D_OK: + return S_OK; + case VKD3D_ERROR_INVALID_SHADER: + WARN("Invalid shader bytecode.\n"); + /* fall-through */ + case VKD3D_ERROR: + return E_FAIL; + case VKD3D_ERROR_OUT_OF_MEMORY: + return E_OUTOFMEMORY; + case VKD3D_ERROR_INVALID_ARGUMENT: + return E_INVALIDARG; + case VKD3D_ERROR_NOT_IMPLEMENTED: + return E_NOTIMPL; + default: + FIXME("Unhandled vkd3d result %d.\n", vkd3d_result); + return E_FAIL; + } +} diff --git a/libs/vkd3d/utils.c b/libs/vkd3d/utils.c index f9f26635..08e6af93 100644 --- a/libs/vkd3d/utils.c +++ b/libs/vkd3d/utils.c @@ -770,29 +770,6 @@ HRESULT hresult_from_vk_result(VkResult vr) } }
-HRESULT hresult_from_vkd3d_result(int vkd3d_result) -{ - switch (vkd3d_result) - { - case VKD3D_OK: - return S_OK; - case VKD3D_ERROR_INVALID_SHADER: - WARN("Invalid shader bytecode.\n"); - /* fall-through */ - case VKD3D_ERROR: - return E_FAIL; - case VKD3D_ERROR_OUT_OF_MEMORY: - return E_OUTOFMEMORY; - case VKD3D_ERROR_INVALID_ARGUMENT: - return E_INVALIDARG; - case VKD3D_ERROR_NOT_IMPLEMENTED: - return E_NOTIMPL; - default: - FIXME("Unhandled vkd3d result %d.\n", vkd3d_result); - return E_FAIL; - } -} - #define LOAD_GLOBAL_PFN(name) \ if (!(procs->name = (void *)vkGetInstanceProcAddr(NULL, #name))) \ { \
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- 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 + 7 files changed, 210 insertions(+)
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"
On Tue, 29 Sep 2020 at 07:11, Zebediah Figura zfigura@codeweavers.com wrote:
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 + 7 files changed, 210 insertions(+)
This requires linking with libvkd3d-shader.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- include/vkd3d_d3dcompiler.h | 2 + include/vkd3d_utils.h | 3 ++ libs/vkd3d-utils/vkd3d_utils.map | 1 + libs/vkd3d-utils/vkd3d_utils_main.c | 66 +++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+)
diff --git a/include/vkd3d_d3dcompiler.h b/include/vkd3d_d3dcompiler.h index 7137294f..c70a7d7c 100644 --- a/include/vkd3d_d3dcompiler.h +++ b/include/vkd3d_d3dcompiler.h @@ -67,6 +67,8 @@ HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filen const void *secondary_data, SIZE_T secondary_data_size, ID3DBlob **shader, ID3DBlob **error_messages); HRESULT WINAPI D3DCreateBlob(SIZE_T size, ID3D10Blob **blob); +HRESULT WINAPI D3DPreprocess(const void *data, SIZE_T size, const char *filename, const D3D_SHADER_MACRO *macros, + ID3DInclude *include, ID3DBlob **shader, ID3DBlob **error_messages);
#endif /* __D3DCOMPILER_H__ */ #endif /* __VKD3D_D3DCOMPILER_H */ diff --git a/include/vkd3d_utils.h b/include/vkd3d_utils.h index c005d4e9..a694de6c 100644 --- a/include/vkd3d_utils.h +++ b/include/vkd3d_utils.h @@ -64,6 +64,9 @@ HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filen const void *secondary_data, SIZE_T secondary_data_size, ID3DBlob **shader, ID3DBlob **error_messages); HRESULT WINAPI D3DCreateBlob(SIZE_T data_size, ID3D10Blob **blob); +HRESULT WINAPI D3DPreprocess(const void *data, SIZE_T size, const char *filename, + const D3D_SHADER_MACRO *defines, ID3DInclude *include, + ID3DBlob **shader, ID3DBlob **error_messages);
#ifdef __cplusplus } diff --git a/libs/vkd3d-utils/vkd3d_utils.map b/libs/vkd3d-utils/vkd3d_utils.map index 337409ee..1e46cd86 100644 --- a/libs/vkd3d-utils/vkd3d_utils.map +++ b/libs/vkd3d-utils/vkd3d_utils.map @@ -11,6 +11,7 @@ global: D3DCompile; D3DCompile2; D3DCreateBlob; + D3DPreprocess; vkd3d_create_event; vkd3d_destroy_event; vkd3d_signal_event; diff --git a/libs/vkd3d-utils/vkd3d_utils_main.c b/libs/vkd3d-utils/vkd3d_utils_main.c index 8f54ac86..c8aa854f 100644 --- a/libs/vkd3d-utils/vkd3d_utils_main.c +++ b/libs/vkd3d-utils/vkd3d_utils_main.c @@ -250,6 +250,72 @@ HRESULT WINAPI D3DCompile(const void *data, SIZE_T data_size, const char *filena effect_flags, 0, NULL, 0, shader, error_messages); }
+HRESULT WINAPI D3DPreprocess(const void *data, SIZE_T size, const char *filename, + const D3D_SHADER_MACRO *macros, ID3DInclude *include, + ID3DBlob **preprocessed_blob, ID3DBlob **messages_blob) +{ + struct vkd3d_shader_preprocess_info preprocess_info; + struct vkd3d_shader_compile_info compile_info; + struct vkd3d_shader_code preprocessed_code; + const D3D_SHADER_MACRO *macro; + char *messages; + HRESULT hr; + int ret; + + TRACE("data %p, size %lu, filename %s, macros %p, include %p, preprocessed_blob %p, messages_blob %p.\n", + data, size, debugstr_a(filename), macros, include, preprocessed_blob, messages_blob); + + compile_info.type = VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO; + compile_info.next = &preprocess_info; + compile_info.source.code = data; + compile_info.source.size = size; + compile_info.source_type = VKD3D_SHADER_SOURCE_HLSL; + compile_info.target_type = VKD3D_SHADER_SOURCE_HLSL; + compile_info.options = NULL; + 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 = NULL; + 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; + + ret = vkd3d_shader_preprocess(&compile_info, &preprocessed_code, &messages); + if (messages) + { + if (messages_blob) + { + if (FAILED(hr = vkd3d_blob_create(messages, strlen(messages), messages_blob))) + { + vkd3d_shader_free_shader_code(&preprocessed_code); + return hr; + } + } + else + vkd3d_shader_free_messages(messages); + } + + if (!ret) + { + if (FAILED(hr = vkd3d_blob_create((void *)preprocessed_code.code, preprocessed_code.size, preprocessed_blob))) + { + vkd3d_shader_free_shader_code(&preprocessed_code); + return hr; + } + } + + return hresult_from_vkd3d_result(ret); +} + /* Events */ HANDLE vkd3d_create_event(void) {
On Tue, 29 Sep 2020 at 07:11, Zebediah Figura zfigura@codeweavers.com wrote:
+HRESULT WINAPI D3DPreprocess(const void *data, SIZE_T size, const char *filename,
const D3D_SHADER_MACRO *macros, ID3DInclude *include,
ID3DBlob **preprocessed_blob, ID3DBlob **messages_blob)
+{
- struct vkd3d_shader_preprocess_info preprocess_info;
- struct vkd3d_shader_compile_info compile_info;
- struct vkd3d_shader_code preprocessed_code;
- const D3D_SHADER_MACRO *macro;
- char *messages;
- HRESULT hr;
- int ret;
- TRACE("data %p, size %lu, filename %s, macros %p, include %p, preprocessed_blob %p, messages_blob %p.\n",
data, size, debugstr_a(filename), macros, include, preprocessed_blob, messages_blob);
- compile_info.type = VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO;
- compile_info.next = &preprocess_info;
- compile_info.source.code = data;
- compile_info.source.size = size;
- compile_info.source_type = VKD3D_SHADER_SOURCE_HLSL;
- compile_info.target_type = VKD3D_SHADER_SOURCE_HLSL;
That's not a valid target type, and will be interpreted as VKD3D_SHADER_TARGET_SPIRV_TEXT. We should probably just pass VKD3D_SHADER_TARGET_NONE here and specify "target_type" as ignored for vkd3d_shader_preprocess(), but it would also be fine to introduce VKD3D_SHADER_TARGET_HLSL.
On 9/29/20 9:44 AM, Henri Verbeet wrote:
On Tue, 29 Sep 2020 at 07:11, Zebediah Figura zfigura@codeweavers.com wrote:
+HRESULT WINAPI D3DPreprocess(const void *data, SIZE_T size, const char *filename,
const D3D_SHADER_MACRO *macros, ID3DInclude *include,
ID3DBlob **preprocessed_blob, ID3DBlob **messages_blob)
+{
- struct vkd3d_shader_preprocess_info preprocess_info;
- struct vkd3d_shader_compile_info compile_info;
- struct vkd3d_shader_code preprocessed_code;
- const D3D_SHADER_MACRO *macro;
- char *messages;
- HRESULT hr;
- int ret;
- TRACE("data %p, size %lu, filename %s, macros %p, include %p, preprocessed_blob %p, messages_blob %p.\n",
data, size, debugstr_a(filename), macros, include, preprocessed_blob, messages_blob);
- compile_info.type = VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO;
- compile_info.next = &preprocess_info;
- compile_info.source.code = data;
- compile_info.source.size = size;
- compile_info.source_type = VKD3D_SHADER_SOURCE_HLSL;
- compile_info.target_type = VKD3D_SHADER_SOURCE_HLSL;
That's not a valid target type, and will be interpreted as VKD3D_SHADER_TARGET_SPIRV_TEXT. We should probably just pass VKD3D_SHADER_TARGET_NONE here and specify "target_type" as ignored for vkd3d_shader_preprocess(), but it would also be fine to introduce VKD3D_SHADER_TARGET_HLSL.
Yes, that was probably a copy-paste error.
I'm rather inclined to like the first option better.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- programs/vkd3d-compiler/main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/programs/vkd3d-compiler/main.c b/programs/vkd3d-compiler/main.c index 8480c4f8..a5aff57c 100644 --- a/programs/vkd3d-compiler/main.c +++ b/programs/vkd3d-compiler/main.c @@ -52,12 +52,17 @@ static const struct source_type_info enum vkd3d_shader_source_type type; const char *name; const char *description; + bool is_binary; } source_type_info[] = { {VKD3D_SHADER_SOURCE_DXBC_TPF, "dxbc-tpf", "A 'Tokenized Program Format' shader embedded in a DXBC container.\n" - " This is the format used for Direct3D shader model 4 and 5 shaders.\n"}, + " This is the format used for Direct3D shader model 4 and 5 shaders.\n", + true}, + {VKD3D_SHADER_SOURCE_HLSL, + "hlsl", "High Level Shader Language source code.\n", + false}, };
static const struct target_type_info @@ -594,7 +599,7 @@ int main(int argc, char **argv) if (!(input = open_input(options.filename, &close_input))) goto done;
- if (!options.filename && isatty(fileno(input))) + if (!options.filename && get_source_type_info(options.source_type)->is_binary && isatty(fileno(input))) { fprintf(stderr, "Input is a tty and input format is binary, exiting.\n" "If this is really what you intended, specify the input explicitly.\n");
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=79428
Your paranoid android.
=== debiant (build log) ===
Task: Patch failed to apply
=== debiant (build log) ===
Task: Patch failed to apply
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- programs/vkd3d-compiler/main.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/programs/vkd3d-compiler/main.c b/programs/vkd3d-compiler/main.c index a5aff57c..dd2ce930 100644 --- a/programs/vkd3d-compiler/main.c +++ b/programs/vkd3d-compiler/main.c @@ -84,6 +84,10 @@ target_type_info[] = {VKD3D_SHADER_TARGET_D3D_ASM, "d3d-asm", "A shader in Direct3D assembly form.\n", false}, + {VKD3D_SHADER_TARGET_DXBC_TPF, + "dxbc-tpf", "A 'Tokenized Program Format' shader embedded in a DXBC container.\n" + " This is the format used for Direct3D shader model 4 and 5 shaders.\n", + true}, };
static bool read_shader(struct vkd3d_shader_code *shader, FILE *f)
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=79429
Your paranoid android.
=== debiant (build log) ===
Task: Patch failed to apply
=== debiant (build log) ===
Task: Patch failed to apply
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- programs/vkd3d-compiler/main.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/programs/vkd3d-compiler/main.c b/programs/vkd3d-compiler/main.c index dd2ce930..dbc6469b 100644 --- a/programs/vkd3d-compiler/main.c +++ b/programs/vkd3d-compiler/main.c @@ -42,6 +42,7 @@ enum OPTION_OUTPUT, OPTION_PRINT_SOURCE_TYPES, OPTION_PRINT_TARGET_TYPES, + OPTION_PROFILE, OPTION_STRIP_DEBUG, OPTION_VERSION, OPTION_TEXT_FORMATTING, @@ -171,6 +172,7 @@ static void print_usage(const char *program_name) " --print-source-types Display the supported source types and exit.\n" " --print-target-types Display the supported target types for the specified\n" " source type and exit.\n" + " -p, --profile=<name> Specify the target shader profile for HLSL shaders.\n" " --strip-debug Strip debug information from the output.\n" " -V, --version Display version information and exit.\n" " -x <type> Specify the type of the source. Valid values are\n" @@ -188,6 +190,7 @@ struct options { const char *filename; const char *output_filename; + const char *profile; enum vkd3d_shader_source_type source_type; enum vkd3d_shader_target_type target_type; bool print_version; @@ -381,6 +384,7 @@ static bool parse_command_line(int argc, char **argv, struct options *options) {"formatting", required_argument, NULL, OPTION_TEXT_FORMATTING}, {"print-source-types", no_argument, NULL, OPTION_PRINT_SOURCE_TYPES}, {"print-target-types", no_argument, NULL, OPTION_PRINT_TARGET_TYPES}, + {"profile", required_argument, NULL, OPTION_PROFILE}, {"strip-debug", no_argument, NULL, OPTION_STRIP_DEBUG}, {"version", no_argument, NULL, OPTION_VERSION}, {NULL, 0, NULL, 0}, @@ -394,7 +398,7 @@ static bool parse_command_line(int argc, char **argv, struct options *options)
for (;;) { - if ((option = getopt_long(argc, argv, "b:ho:Vx:", long_options, NULL)) == -1) + if ((option = getopt_long(argc, argv, "b:ho:p:Vx:", long_options, NULL)) == -1) break;
switch (option) @@ -421,6 +425,11 @@ static bool parse_command_line(int argc, char **argv, struct options *options) options->output_filename = optarg; break;
+ case OPTION_PROFILE: + case 'p': + options->profile = optarg; + break; + case OPTION_TEXT_FORMATTING: if (!parse_formatting(&options->formatting, &options->explicit_colour, optarg)) return false; @@ -565,6 +574,7 @@ static bool has_colour(FILE *f)
int main(int argc, char **argv) { + struct vkd3d_shader_hlsl_source_info hlsl_source_info = {0}; bool close_input = false, close_output = false; struct vkd3d_shader_compile_info info; struct vkd3d_shader_code spirv; @@ -626,7 +636,7 @@ int main(int argc, char **argv) add_compile_option(&options, VKD3D_SHADER_COMPILE_OPTION_FORMATTING, options.formatting);
info.type = VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO; - info.next = NULL; + info.next = &hlsl_source_info; info.source_type = options.source_type; info.target_type = options.target_type; info.options = options.compile_options; @@ -634,6 +644,9 @@ int main(int argc, char **argv) info.log_level = VKD3D_SHADER_LOG_INFO; info.source_name = options.filename;
+ hlsl_source_info.type = VKD3D_SHADER_STRUCTURE_TYPE_HLSL_SOURCE_INFO; + hlsl_source_info.profile = options.profile; + if (!read_shader(&info.source, input)) { fprintf(stderr, "Failed to read input shader.\n");
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=79430
Your paranoid android.
=== debiant (build log) ===
Task: Patch failed to apply
=== debiant (build log) ===
Task: Patch failed to apply
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- programs/vkd3d-compiler/main.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/programs/vkd3d-compiler/main.c b/programs/vkd3d-compiler/main.c index dbc6469b..8b9d7c26 100644 --- a/programs/vkd3d-compiler/main.c +++ b/programs/vkd3d-compiler/main.c @@ -39,6 +39,7 @@ enum { OPTION_HELP = CHAR_MAX + 1, OPTION_BUFFER_UAV, + OPTION_ENTRY, OPTION_OUTPUT, OPTION_PRINT_SOURCE_TYPES, OPTION_PRINT_TARGET_TYPES, @@ -161,6 +162,7 @@ static void print_usage(const char *program_name) " --buffer-uav=<type> Specify the buffer type to use for buffer UAV bindings.\n" " Valid values are 'buffer-texture' (default) and\n" " 'storage-buffer'.\n" + " -e, --entry=<name> Use <name> as the entry point (default is "main").\n" " -o, --output=<file> Write the output to <file>. If <file> is '-' or no\n" " output file is specified, output will be written to\n" " standard output.\n" @@ -190,6 +192,7 @@ struct options { const char *filename; const char *output_filename; + const char *entry_point; const char *profile; enum vkd3d_shader_source_type source_type; enum vkd3d_shader_target_type target_type; @@ -380,6 +383,7 @@ static bool parse_command_line(int argc, char **argv, struct options *options) { {"help", no_argument, NULL, OPTION_HELP}, {"buffer-uav", required_argument, NULL, OPTION_BUFFER_UAV}, + {"entry", required_argument, NULL, OPTION_ENTRY}, {"output", required_argument, NULL, OPTION_OUTPUT}, {"formatting", required_argument, NULL, OPTION_TEXT_FORMATTING}, {"print-source-types", no_argument, NULL, OPTION_PRINT_SOURCE_TYPES}, @@ -398,7 +402,7 @@ static bool parse_command_line(int argc, char **argv, struct options *options)
for (;;) { - if ((option = getopt_long(argc, argv, "b:ho:p:Vx:", long_options, NULL)) == -1) + if ((option = getopt_long(argc, argv, "b:e:ho:p:Vx:", long_options, NULL)) == -1) break;
switch (option) @@ -420,6 +424,11 @@ static bool parse_command_line(int argc, char **argv, struct options *options) add_compile_option(options, VKD3D_SHADER_COMPILE_OPTION_BUFFER_UAV, buffer_uav); break;
+ case OPTION_ENTRY: + case 'e': + options->entry_point = optarg; + break; + case OPTION_OUTPUT: case 'o': options->output_filename = optarg; @@ -646,6 +655,7 @@ int main(int argc, char **argv)
hlsl_source_info.type = VKD3D_SHADER_STRUCTURE_TYPE_HLSL_SOURCE_INFO; hlsl_source_info.profile = options.profile; + hlsl_source_info.entry_point = options.entry_point;
if (!read_shader(&info.source, input)) {
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=79431
Your paranoid android.
=== debiant (build log) ===
Task: Patch failed to apply
=== debiant (build log) ===
Task: Patch failed to apply
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
On Tue, 29 Sep 2020 at 07:12, Zebediah Figura zfigura@codeweavers.com wrote:
@@ -161,6 +162,7 @@ static void print_usage(const char *program_name) " --buffer-uav=<type> Specify the buffer type to use for buffer UAV bindings.\n" " Valid values are 'buffer-texture' (default) and\n" " 'storage-buffer'.\n"
" -e, --entry=<name> Use <name> as the entry point (default is \"main\").\n" " -o, --output=<file> Write the output to <file>. If <file> is '-' or no\n" " output file is specified, output will be written to\n" " standard output.\n"
This is fine, but note that the SPIR-V target also allows the entry point to be specified.