Signed-off-by: Zebediah Figura zfigura@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"
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..f5cb5b5f 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_TARGET_NONE; + 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) {
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
The format and parser are loosely based on piglit's shader_test format and shader_runner.c, respectively.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- Makefile.am | 18 ++- tests/.gitignore | 1 + tests/d3d12.c | 101 -------------- tests/d3d12_crosstest.h | 1 + tests/d3d12_test_utils.h | 103 ++++++++++++++- tests/shader_runner_d3d12.c | 254 ++++++++++++++++++++++++++++++++++++ 6 files changed, 371 insertions(+), 107 deletions(-) create mode 100644 tests/shader_runner_d3d12.c
diff --git a/Makefile.am b/Makefile.am index 22a245e9..5e2ea3ea 100644 --- a/Makefile.am +++ b/Makefile.am @@ -46,6 +46,9 @@ vkd3d_cross_tests = \ tests/d3d12 \ tests/d3d12_invalid_usage
+vkd3d_shader_runners = \ + tests/shader_runner_d3d12 + vkd3d_test_headers = \ tests/d3d12_crosstest.h \ tests/d3d12_test_utils.h @@ -151,13 +154,18 @@ vkd3d_compiler_LDADD = libvkd3d-shader.la @NCURSES_LIBS@
LDADD = libvkd3d.la libvkd3d-utils.la AM_DEFAULT_SOURCE_EXT = .c + +TEST_EXTENSIONS = .shader_test + if BUILD_TESTS -check_PROGRAMS = $(vkd3d_tests) $(vkd3d_cross_tests) +check_PROGRAMS = $(vkd3d_tests) $(vkd3d_cross_tests) $(vkd3d_shader_runners) TESTS = $(vkd3d_tests) $(vkd3d_cross_tests) tests_d3d12_LDADD = $(LDADD) @PTHREAD_LIBS@ @VULKAN_LIBS@ tests_d3d12_invalid_usage_LDADD = $(LDADD) @VULKAN_LIBS@ +tests_shader_runner_d3d12_LDADD = $(LDADD) @VULKAN_LIBS@ tests_vkd3d_api_LDADD = libvkd3d.la @VULKAN_LIBS@ tests_vkd3d_shader_api_LDADD = libvkd3d-shader.la +SHADER_TEST_LOG_COMPILER = tests/shader_runner_d3d12 endif
if BUILD_DEMOS @@ -239,7 +247,7 @@ if HAVE_CROSSTARGET32 CROSS32_CC = @CROSSCC32@ CROSS32_DLLTOOL = @CROSSTARGET32@-dlltool CROSS32_IMPLIBS = $(cross_implibs:=.cross32.a) -CROSS32_EXEFILES = $(vkd3d_cross_tests:=.cross32.exe) $(vkd3d_demos:=.cross32.exe) +CROSS32_EXEFILES = $(vkd3d_cross_tests:=.cross32.exe) $(vkd3d_demos:=.cross32.exe) $(vkd3d_shader_runners:=.cross32.exe) CROSS32_FILES = $(CROSS32_IMPLIBS) $(CROSS32_EXEFILES)
CLEANFILES += $(CROSS32_FILES) @@ -254,7 +262,7 @@ $(CROSS32_IMPLIBS): %.cross32.a: %.cross32.def
$(CROSS32_EXEFILES): %.cross32.exe: %.c $(CROSS32_IMPLIBS) $(widl_headers) $(AM_V_CCLD)depbase=`echo $@ | $(SED) 's![^/]*$$!$(DEPDIR)/&!;s!.exe$$!!'`; \ - $(CROSS32_CC) $(CROSS_CFLAGS) -MT $@ -MD -MP -MF $$depbase.Tpo -o $@ $< $(CROSS32_IMPLIBS) -ldxgi -lgdi32 && \ + $(CROSS32_CC) $(CROSS_CFLAGS) -MT $@ -MD -MP -MF $$depbase.Tpo -o $@ $< $(CROSS32_IMPLIBS) -ldxgi -lgdi32 -ld3dcompiler_47 && \ $(am__mv) $$depbase.Tpo $$depbase.Po else crosstest32: @@ -264,7 +272,7 @@ if HAVE_CROSSTARGET64 CROSS64_CC = @CROSSCC64@ CROSS64_DLLTOOL = @CROSSTARGET64@-dlltool CROSS64_IMPLIBS = $(cross_implibs:=.cross64.a) -CROSS64_EXEFILES = $(vkd3d_cross_tests:=.cross64.exe) $(vkd3d_demos:=.cross64.exe) +CROSS64_EXEFILES = $(vkd3d_cross_tests:=.cross64.exe) $(vkd3d_demos:=.cross64.exe) $(vkd3d_shader_runners:=.cross64.exe) CROSS64_FILES = $(CROSS64_IMPLIBS) $(CROSS64_EXEFILES)
CLEANFILES += $(CROSS64_FILES) @@ -279,7 +287,7 @@ $(CROSS64_IMPLIBS): %.cross64.a: %.cross64.def
$(CROSS64_EXEFILES): %.cross64.exe: %.c $(CROSS64_IMPLIBS) $(widl_headers) $(AM_V_CCLD)depbase=`echo $@ | sed 's![^/]*$$!$(DEPDIR)/&!;s!.exe$$!!'`; \ - $(CROSS64_CC) $(CROSS_CFLAGS) -MT $@ -MD -MP -MF $$depbase.Tpo -o $@ $< $(CROSS64_IMPLIBS) -ldxgi -lgdi32 && \ + $(CROSS64_CC) $(CROSS_CFLAGS) -MT $@ -MD -MP -MF $$depbase.Tpo -o $@ $< $(CROSS64_IMPLIBS) -ldxgi -lgdi32 -ld3dcompiler_47 && \ $(am__mv) $$depbase.Tpo $$depbase.Po else crosstest64: diff --git a/tests/.gitignore b/tests/.gitignore index 1854d55b..94d003dd 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -1,5 +1,6 @@ /d3d12 /d3d12_invalid_usage +/shader_runner_d3d12 /vkd3d_api /vkd3d_common /vkd3d_shader_api diff --git a/tests/d3d12.c b/tests/d3d12.c index f0b2d545..5554178e 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -31,11 +31,6 @@ struct vec2 float x, y; };
-struct vec4 -{ - float x, y, z, w; -}; - struct uvec4 { unsigned int x, y, z, w; @@ -46,39 +41,6 @@ struct ivec4 int x, y, z, w; };
-static bool compare_float(float f, float g, unsigned int ulps) -{ - int x, y; - union - { - float f; - int i; - } u; - - u.f = f; - x = u.i; - u.f = g; - y = u.i; - - if (x < 0) - x = INT_MIN - x; - if (y < 0) - y = INT_MIN - y; - - if (abs(x - y) > ulps) - return false; - - return true; -} - -static bool compare_vec4(const struct vec4 *v1, const struct vec4 *v2, unsigned int ulps) -{ - return compare_float(v1->x, v2->x, ulps) - && compare_float(v1->y, v2->y, ulps) - && compare_float(v1->z, v2->z, ulps) - && compare_float(v1->w, v2->w, ulps); -} - static bool compare_uvec4(const struct uvec4* v1, const struct uvec4 *v2) { return v1->x == v2->x && v1->y == v2->y && v1->z == v2->z && v1->w == v2->w; @@ -408,11 +370,6 @@ static float get_readback_float(struct resource_readback *rb, unsigned int x, un return *(float *)get_readback_data(rb, x, y, 0, sizeof(float)); }
-static const struct vec4 *get_readback_vec4(struct resource_readback *rb, unsigned int x, unsigned int y) -{ - return get_readback_data(rb, x, y, 0, sizeof(struct vec4)); -} - static const struct uvec4 *get_readback_uvec4(struct resource_readback *rb, unsigned int x, unsigned int y) { return get_readback_data(rb, x, y, 0, sizeof(struct uvec4)); @@ -582,37 +539,6 @@ static void check_sub_resource_uint64_(unsigned int line, ID3D12Resource *textur release_resource_readback(&rb); }
-#define check_sub_resource_vec4(a, b, c, d, e, f) check_sub_resource_vec4_(__LINE__, a, b, c, d, e, f) -static void check_sub_resource_vec4_(unsigned int line, ID3D12Resource *texture, - unsigned int sub_resource_idx, ID3D12CommandQueue *queue, ID3D12GraphicsCommandList *command_list, - const struct vec4 *expected, unsigned int max_diff) -{ - struct resource_readback rb; - unsigned int x = 0, y; - bool all_match = true; - struct vec4 got = {0}; - - get_texture_readback_with_command_list(texture, sub_resource_idx, &rb, queue, command_list); - for (y = 0; y < rb.height; ++y) - { - for (x = 0; x < rb.width; ++x) - { - got = *get_readback_vec4(&rb, x, y); - if (!compare_vec4(&got, expected, max_diff)) - { - all_match = false; - break; - } - } - if (!all_match) - break; - } - release_resource_readback(&rb); - - ok_(line)(all_match, "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u).\n", - got.x, got.y, got.z, got.w, expected->x, expected->y, expected->z, expected->w, x, y); -} - #define check_sub_resource_uvec4(a, b, c, d, e) check_sub_resource_uvec4_(__LINE__, a, b, c, d, e) static void check_sub_resource_uvec4_(unsigned int line, ID3D12Resource *texture, unsigned int sub_resource_idx, ID3D12CommandQueue *queue, ID3D12GraphicsCommandList *command_list, @@ -750,33 +676,6 @@ static ID3D12RootSignature *create_cb_root_signature_(unsigned int line, return root_signature; }
-#define create_32bit_constants_root_signature(a, b, c, e) \ - create_32bit_constants_root_signature_(__LINE__, a, b, c, e, 0) -static ID3D12RootSignature *create_32bit_constants_root_signature_(unsigned int line, - ID3D12Device *device, unsigned int reg_idx, unsigned int element_count, - D3D12_SHADER_VISIBILITY shader_visibility, D3D12_ROOT_SIGNATURE_FLAGS flags) -{ - D3D12_ROOT_SIGNATURE_DESC root_signature_desc; - ID3D12RootSignature *root_signature = NULL; - D3D12_ROOT_PARAMETER root_parameter; - HRESULT hr; - - root_parameter.ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS; - root_parameter.Constants.ShaderRegister = reg_idx; - root_parameter.Constants.RegisterSpace = 0; - root_parameter.Constants.Num32BitValues = element_count; - root_parameter.ShaderVisibility = shader_visibility; - - memset(&root_signature_desc, 0, sizeof(root_signature_desc)); - root_signature_desc.NumParameters = 1; - root_signature_desc.pParameters = &root_parameter; - root_signature_desc.Flags = flags; - hr = create_root_signature(device, &root_signature_desc, &root_signature); - ok_(line)(SUCCEEDED(hr), "Failed to create root signature, hr %#x.\n", hr); - - return root_signature; -} - #define create_texture_root_signature(a, b, c, d) create_texture_root_signature_(__LINE__, a, b, c, d, NULL) static ID3D12RootSignature *create_texture_root_signature_(unsigned int line, ID3D12Device *device, D3D12_SHADER_VISIBILITY shader_visibility, diff --git a/tests/d3d12_crosstest.h b/tests/d3d12_crosstest.h index 7ff835ad..f7a31804 100644 --- a/tests/d3d12_crosstest.h +++ b/tests/d3d12_crosstest.h @@ -46,6 +46,7 @@ typedef int HRESULT; #define WIDL_C_INLINE_WRAPPERS #include "vkd3d_d3d12.h" #include "vkd3d_d3d12sdklayers.h" +#include "vkd3d_d3dcompiler.h"
#include <inttypes.h> #include <limits.h> diff --git a/tests/d3d12_test_utils.h b/tests/d3d12_test_utils.h index e4c8e586..ece48966 100644 --- a/tests/d3d12_test_utils.h +++ b/tests/d3d12_test_utils.h @@ -19,6 +19,11 @@ #ifndef __VKD3D_D3D12_TEST_UTILS_H #define __VKD3D_D3D12_TEST_UTILS_H
+struct vec4 +{ + float x, y, z, w; +}; + #define wait_queue_idle(a, b) wait_queue_idle_(__LINE__, a, b) static void wait_queue_idle_(unsigned int line, ID3D12Device *device, ID3D12CommandQueue *queue); static ID3D12Device *create_device(void); @@ -53,6 +58,31 @@ static void set_viewport(D3D12_VIEWPORT *vp, float x, float y, vp->MaxDepth = max_depth; }
+static bool compare_float(float f, float g, unsigned int ulps) +{ + int x, y; + union + { + float f; + int i; + } u; + + u.f = f; + x = u.i; + u.f = g; + y = u.i; + + if (x < 0) + x = INT_MIN - x; + if (y < 0) + y = INT_MIN - y; + + if (abs(x - y) > ulps) + return false; + + return true; +} + static bool compare_uint(unsigned int x, unsigned int y, unsigned int max_diff) { unsigned int diff = x > y ? x - y : y - x; @@ -68,6 +98,14 @@ static bool compare_color(DWORD c1, DWORD c2, BYTE max_diff) && compare_uint((c1 >> 24) & 0xff, (c2 >> 24) & 0xff, max_diff); }
+static bool compare_vec4(const struct vec4 *v1, const struct vec4 *v2, unsigned int ulps) +{ + return compare_float(v1->x, v2->x, ulps) + && compare_float(v1->y, v2->y, ulps) + && compare_float(v1->z, v2->z, ulps) + && compare_float(v1->w, v2->w, ulps); +} + static D3D12_SHADER_BYTECODE shader_bytecode(const DWORD *code, size_t size) { D3D12_SHADER_BYTECODE shader_bytecode = { code, size }; @@ -501,6 +539,11 @@ static unsigned int get_readback_uint(struct resource_readback *rb, return *(unsigned int *)get_readback_data(rb, x, y, z, sizeof(unsigned int)); }
+static const struct vec4 *get_readback_vec4(struct resource_readback *rb, unsigned int x, unsigned int y) +{ + return get_readback_data(rb, x, y, 0, sizeof(struct vec4)); +} + static void release_resource_readback(struct resource_readback *rb) { D3D12_RANGE range = {0, 0}; @@ -554,6 +597,37 @@ static inline void check_sub_resource_uint_(unsigned int line, ID3D12Resource *t release_resource_readback(&rb); }
+#define check_sub_resource_vec4(a, b, c, d, e, f) check_sub_resource_vec4_(__LINE__, a, b, c, d, e, f) +static inline void check_sub_resource_vec4_(unsigned int line, ID3D12Resource *texture, + unsigned int sub_resource_idx, ID3D12CommandQueue *queue, ID3D12GraphicsCommandList *command_list, + const struct vec4 *expected, unsigned int max_diff) +{ + struct resource_readback rb; + unsigned int x = 0, y; + bool all_match = true; + struct vec4 got = {0}; + + get_texture_readback_with_command_list(texture, sub_resource_idx, &rb, queue, command_list); + for (y = 0; y < rb.height; ++y) + { + for (x = 0; x < rb.width; ++x) + { + got = *get_readback_vec4(&rb, x, y); + if (!compare_vec4(&got, expected, max_diff)) + { + all_match = false; + break; + } + } + if (!all_match) + break; + } + release_resource_readback(&rb); + + ok_(line)(all_match, "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u).\n", + got.x, got.y, got.z, got.w, expected->x, expected->y, expected->z, expected->w, x, y); +} + #define create_default_buffer(a, b, c, d) create_default_buffer_(__LINE__, a, b, c, d) static inline ID3D12Resource *create_default_buffer_(unsigned int line, ID3D12Device *device, size_t size, D3D12_RESOURCE_FLAGS resource_flags, D3D12_RESOURCE_STATES initial_resource_state) @@ -595,7 +669,7 @@ static ID3D12Resource *create_default_texture_(unsigned int line, ID3D12Device *
#define create_default_texture(a, b, c, d, e, f) create_default_texture2d_(__LINE__, a, b, c, 1, 1, d, e, f) #define create_default_texture2d(a, b, c, d, e, f, g, h) create_default_texture2d_(__LINE__, a, b, c, d, e, f, g, h) -static ID3D12Resource *create_default_texture2d_(unsigned int line, ID3D12Device *device, +static inline ID3D12Resource *create_default_texture2d_(unsigned int line, ID3D12Device *device, unsigned int width, unsigned int height, unsigned int array_size, unsigned int miplevel_count, DXGI_FORMAT format, D3D12_RESOURCE_FLAGS flags, D3D12_RESOURCE_STATES initial_state) { @@ -646,6 +720,33 @@ static ID3D12RootSignature *create_empty_root_signature_(unsigned int line, return root_signature; }
+#define create_32bit_constants_root_signature(a, b, c, e) \ + create_32bit_constants_root_signature_(__LINE__, a, b, c, e, 0) +static inline ID3D12RootSignature *create_32bit_constants_root_signature_(unsigned int line, + ID3D12Device *device, unsigned int reg_idx, unsigned int element_count, + D3D12_SHADER_VISIBILITY shader_visibility, D3D12_ROOT_SIGNATURE_FLAGS flags) +{ + D3D12_ROOT_SIGNATURE_DESC root_signature_desc; + ID3D12RootSignature *root_signature = NULL; + D3D12_ROOT_PARAMETER root_parameter; + HRESULT hr; + + root_parameter.ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS; + root_parameter.Constants.ShaderRegister = reg_idx; + root_parameter.Constants.RegisterSpace = 0; + root_parameter.Constants.Num32BitValues = element_count; + root_parameter.ShaderVisibility = shader_visibility; + + memset(&root_signature_desc, 0, sizeof(root_signature_desc)); + root_signature_desc.NumParameters = 1; + root_signature_desc.pParameters = &root_parameter; + root_signature_desc.Flags = flags; + hr = create_root_signature(device, &root_signature_desc, &root_signature); + ok_(line)(SUCCEEDED(hr), "Failed to create root signature, hr %#x.\n", hr); + + return root_signature; +} + static void init_pipeline_state_desc(D3D12_GRAPHICS_PIPELINE_STATE_DESC *desc, ID3D12RootSignature *root_signature, DXGI_FORMAT rt_format, const D3D12_SHADER_BYTECODE *vs, const D3D12_SHADER_BYTECODE *ps, diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c new file mode 100644 index 00000000..e9a7387b --- /dev/null +++ b/tests/shader_runner_d3d12.c @@ -0,0 +1,254 @@ +/* + * Copyright © 2010 Intel Corporation + * Copyright © 2020 Zebediah Figura for CodeWeavers + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "d3d12_crosstest.h" +#include <errno.h> + +struct shader_context +{ + struct test_context c; + + ID3D10Blob *ps_code; + + uint32_t *uniforms; + size_t uniform_count; +}; + +static ID3D10Blob *compile_shader(const char *source, const char *target) +{ + ID3D10Blob *blob = NULL, *errors = NULL; + HRESULT hr; + + hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main", target, 0, 0, &blob, &errors); + ok(hr == S_OK, "Failed to compile shader, hr %#x.\n", hr); + if (errors) + { + if (vkd3d_test_state.debug_level) + trace("%s\n", (char *)ID3D10Blob_GetBufferPointer(errors)); + ID3D10Blob_Release(errors); + } + return blob; +} + +enum parse_state +{ + STATE_NONE, + STATE_SHADER_PIXEL, + STATE_TEST, +}; + +static bool match_string(const char *line, const char *token, const char **const rest) +{ + size_t len = strlen(token); + + if (strncmp(line, token, len) || !isspace(line[len])) + return false; + if (rest) + { + *rest = line + len; + while (isspace(**rest)) + ++*rest; + } + return true; +} + +static void parse_test_directive(struct shader_context *context, const char *line) +{ + const char *const orig_line = line; + + if (match_string(line, "draw quad", &line)) + { + D3D12_SHADER_BYTECODE ps + = {ID3D10Blob_GetBufferPointer(context->ps_code), ID3D10Blob_GetBufferSize(context->ps_code)}; + ID3D12GraphicsCommandList *command_list = context->c.list; + static const float clear_color[4]; + ID3D12PipelineState *pso; + + context->c.root_signature = create_32bit_constants_root_signature(context->c.device, + 0, context->uniform_count, D3D12_SHADER_VISIBILITY_ALL); + + pso = create_pipeline_state(context->c.device, context->c.root_signature, + context->c.render_target_desc.Format, NULL, &ps, NULL); + + ID3D12GraphicsCommandList_SetGraphicsRootSignature(command_list, context->c.root_signature); + ID3D12GraphicsCommandList_SetGraphicsRoot32BitConstants(command_list, 0, + context->uniform_count, context->uniforms, 0); + ID3D12GraphicsCommandList_OMSetRenderTargets(command_list, 1, &context->c.rtv, false, NULL); + ID3D12GraphicsCommandList_RSSetScissorRects(command_list, 1, &context->c.scissor_rect); + ID3D12GraphicsCommandList_RSSetViewports(command_list, 1, &context->c.viewport); + ID3D12GraphicsCommandList_IASetPrimitiveTopology(command_list, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, context->c.rtv, clear_color, 0, NULL); + ID3D12GraphicsCommandList_SetPipelineState(command_list, pso); + ID3D12GraphicsCommandList_DrawInstanced(command_list, 3, 1, 0, 0); + ID3D12PipelineState_Release(pso); + transition_resource_state(command_list, context->c.render_target, + D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE); + } + else if (match_string(line, "probe all rgba", &line)) + { + unsigned int ulps; + struct vec4 v; + int ret; + + ret = sscanf(line, "( %f , %f , %f , %f ) %u", &v.x, &v.y, &v.z, &v.w, &ulps); + if (ret < 4) + goto err; + if (ret < 5) + ulps = 0; + check_sub_resource_vec4(context->c.render_target, 0, context->c.queue, context->c.list, &v, ulps); + reset_command_list(context->c.list, context->c.allocator); + } + else if (match_string(line, "uniform", &line)) + { + unsigned int offset; + + if (!sscanf(line, "%u", &offset)) + goto err; + line = strchr(line, ' ') + 1; + + if (match_string(line, "float4", &line)) + { + struct vec4 v; + + if (sscanf(line, "%f %f %f %f", &v.x, &v.y, &v.z, &v.w) < 4) + goto err; + if (offset + 4 > context->uniform_count) + { + context->uniform_count = offset + 4; + context->uniforms = realloc(context->uniforms, context->uniform_count * sizeof(*context->uniforms)); + } + memcpy(context->uniforms + offset, &v, sizeof(v)); + } + } + else + { + goto err; + } + + return; + +err: + fprintf(stderr, "Ignoring malformed line '%s'.\n", orig_line); +} + +START_TEST(shader_runner_d3d12) +{ + static const struct test_context_desc desc = + { + .no_root_signature = true, + .rt_format = DXGI_FORMAT_R32G32B32A32_FLOAT, + }; + enum parse_state state = STATE_NONE; + struct shader_context context; + const char *filename = NULL; + char *shader_source = NULL; + unsigned int i; + char line[256]; + FILE *f; + + parse_args(argc, argv); + enable_d3d12_debug_layer(argc, argv); + init_adapter_info(); + + for (i = 1; i < argc; ++i) + { + if (argv[i][0] != '-') + { + filename = argv[i]; + break; + } + } + + if (!filename) + { + fprintf(stderr, "Usage: %s [file]\n", argv[0]); + return; + } + + if (!(f = fopen(filename, "r"))) + { + fprintf(stderr, "Unable to open '%s' for reading: %s\n", argv[1], strerror(errno)); + return; + } + + memset(&context, 0, sizeof(context)); + init_test_context(&context.c, &desc); + + while (fgets(line, sizeof(line), f)) + { + if (line[0] == '[') + { + switch (state) + { + case STATE_NONE: + case STATE_TEST: + break; + + case STATE_SHADER_PIXEL: + if (!(context.ps_code = compile_shader(shader_source, "ps_4_0"))) + return; + free(shader_source); + shader_source = NULL; + break; + } + + if (!strcmp(line, "[pixel shader]\n")) + state = STATE_SHADER_PIXEL; + else if (!strcmp(line, "[test]\n")) + state = STATE_TEST; + } + else + { + switch (state) + { + case STATE_NONE: + if (line[0] != '#') + fprintf(stderr, "Ignoring line '%s' in %s.\n", line, argv[1]); + break; + + case STATE_SHADER_PIXEL: + if (!shader_source) + { + shader_source = strdup(line); + } + else + { + shader_source = realloc(shader_source, strlen(shader_source) + strlen(line) + 1); + strcat(shader_source, line); + } + break; + + case STATE_TEST: + if (line[0] != '#') + parse_test_directive(&context, line); + break; + } + } + } + + ID3D10Blob_Release(context.ps_code); + destroy_test_context(&context.c); + + fclose(f); +}
On Wed, 30 Sep 2020 at 00:45, Zebediah Figura zfigura@codeweavers.com wrote:
diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c new file mode 100644 index 00000000..e9a7387b --- /dev/null +++ b/tests/shader_runner_d3d12.c @@ -0,0 +1,254 @@ +/*
- Copyright © 2010 Intel Corporation
- Copyright © 2020 Zebediah Figura for CodeWeavers
- Permission is hereby granted, free of charge, to any person obtaining a
- copy of this software and associated documentation files (the "Software"),
- to deal in the Software without restriction, including without limitation
- the rights to use, copy, modify, merge, publish, distribute, sublicense,
- and/or sell copies of the Software, and to permit persons to whom the
- Software is furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice (including the next
- paragraph) shall be included in all copies or substantial portions of the
- Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- DEALINGS IN THE SOFTWARE.
- */
I think we'd want this to be under the regular vkd3d license. (See also the gears and triangle demos for other places where we incorporate code under a different but compatible license.)
case STATE_SHADER_PIXEL:
if (!shader_source)
{
shader_source = strdup(line);
}
else
{
shader_source = realloc(shader_source, strlen(shader_source) + strlen(line) + 1);
strcat(shader_source, line);
This isn't terribly efficient. (Both the strcat() after strlen(), and the realloc() strategy.) It probably doesn't really matter in practice, but we wouldn't want to set any bad examples.
On 9/30/20 9:16 AM, Henri Verbeet wrote:
On Wed, 30 Sep 2020 at 00:45, Zebediah Figura zfigura@codeweavers.com wrote:
diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c new file mode 100644 index 00000000..e9a7387b --- /dev/null +++ b/tests/shader_runner_d3d12.c @@ -0,0 +1,254 @@ +/*
- Copyright © 2010 Intel Corporation
- Copyright © 2020 Zebediah Figura for CodeWeavers
- Permission is hereby granted, free of charge, to any person obtaining a
- copy of this software and associated documentation files (the "Software"),
- to deal in the Software without restriction, including without limitation
- the rights to use, copy, modify, merge, publish, distribute, sublicense,
- and/or sell copies of the Software, and to permit persons to whom the
- Software is furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice (including the next
- paragraph) shall be included in all copies or substantial portions of the
- Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- DEALINGS IN THE SOFTWARE.
- */
I think we'd want this to be under the regular vkd3d license. (See also the gears and triangle demos for other places where we incorporate code under a different but compatible license.)
Sure; I wasn't sure and decided to play it safe...
case STATE_SHADER_PIXEL:
if (!shader_source)
{
shader_source = strdup(line);
}
else
{
shader_source = realloc(shader_source, strlen(shader_source) + strlen(line) + 1);
strcat(shader_source, line);
This isn't terribly efficient. (Both the strcat() after strlen(), and the realloc() strategy.) It probably doesn't really matter in practice, but we wouldn't want to set any bad examples.
I guess you're proposing to instead use something like array_reserve(), and e.g.
len = strlen(line); ... memcpy(shader_source + source_len, line, len);
Both of which struck me as extra complexity for not much reason, but I don't care too much...
On Wed, 30 Sep 2020 at 18:44, Zebediah Figura zfigura@codeweavers.com wrote:
On 9/30/20 9:16 AM, Henri Verbeet wrote:
case STATE_SHADER_PIXEL:
if (!shader_source)
{
shader_source = strdup(line);
}
else
{
shader_source = realloc(shader_source, strlen(shader_source) + strlen(line) + 1);
strcat(shader_source, line);
This isn't terribly efficient. (Both the strcat() after strlen(), and the realloc() strategy.) It probably doesn't really matter in practice, but we wouldn't want to set any bad examples.
I guess you're proposing to instead use something like array_reserve(), and e.g.
len = strlen(line); ... memcpy(shader_source + source_len, line, len);
Both of which struck me as extra complexity for not much reason, but I don't care too much...
array_reserve() is probably overkill, although chances are we'll need it at some point in the future anyway. Simply doubling the allocation would have been fine too. The alternative I was thinking of though, was to simply read/map the entire input file into memory at once, and then simply pass a pointer into the input file to D3DCompile().
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- Makefile.am | 21 ++++++++++++++++++++- tests/swizzle-0.shader_test | 15 +++++++++++++++ tests/swizzle-1.shader_test | 11 +++++++++++ tests/swizzle-2.shader_test | 11 +++++++++++ tests/swizzle-3.shader_test | 14 ++++++++++++++ tests/swizzle-4.shader_test | 13 +++++++++++++ tests/swizzle-5.shader_test | 10 ++++++++++ tests/swizzle-6.shader_test | 12 ++++++++++++ tests/swizzle-7.shader_test | 11 +++++++++++ 9 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 tests/swizzle-0.shader_test create mode 100644 tests/swizzle-1.shader_test create mode 100644 tests/swizzle-2.shader_test create mode 100644 tests/swizzle-3.shader_test create mode 100644 tests/swizzle-4.shader_test create mode 100644 tests/swizzle-5.shader_test create mode 100644 tests/swizzle-6.shader_test create mode 100644 tests/swizzle-7.shader_test
diff --git a/Makefile.am b/Makefile.am index 5e2ea3ea..958be146 100644 --- a/Makefile.am +++ b/Makefile.am @@ -49,6 +49,16 @@ vkd3d_cross_tests = \ vkd3d_shader_runners = \ tests/shader_runner_d3d12
+vkd3d_shader_tests = \ + tests/swizzle-0.shader_test \ + tests/swizzle-1.shader_test \ + tests/swizzle-2.shader_test \ + tests/swizzle-3.shader_test \ + tests/swizzle-4.shader_test \ + tests/swizzle-5.shader_test \ + tests/swizzle-6.shader_test \ + tests/swizzle-7.shader_test + vkd3d_test_headers = \ tests/d3d12_crosstest.h \ tests/d3d12_test_utils.h @@ -159,13 +169,22 @@ TEST_EXTENSIONS = .shader_test
if BUILD_TESTS check_PROGRAMS = $(vkd3d_tests) $(vkd3d_cross_tests) $(vkd3d_shader_runners) -TESTS = $(vkd3d_tests) $(vkd3d_cross_tests) +TESTS = $(vkd3d_tests) $(vkd3d_cross_tests) $(vkd3d_shader_tests) tests_d3d12_LDADD = $(LDADD) @PTHREAD_LIBS@ @VULKAN_LIBS@ tests_d3d12_invalid_usage_LDADD = $(LDADD) @VULKAN_LIBS@ tests_shader_runner_d3d12_LDADD = $(LDADD) @VULKAN_LIBS@ tests_vkd3d_api_LDADD = libvkd3d.la @VULKAN_LIBS@ tests_vkd3d_shader_api_LDADD = libvkd3d-shader.la SHADER_TEST_LOG_COMPILER = tests/shader_runner_d3d12 +XFAIL_TESTS = \ + tests/swizzle-0.shader_test \ + tests/swizzle-1.shader_test \ + tests/swizzle-2.shader_test \ + tests/swizzle-3.shader_test \ + tests/swizzle-4.shader_test \ + tests/swizzle-5.shader_test \ + tests/swizzle-6.shader_test \ + tests/swizzle-7.shader_test endif
if BUILD_DEMOS diff --git a/tests/swizzle-0.shader_test b/tests/swizzle-0.shader_test new file mode 100644 index 00000000..9be141cf --- /dev/null +++ b/tests/swizzle-0.shader_test @@ -0,0 +1,15 @@ +[pixel shader] +uniform float4 color; + +float4 main() : sv_target +{ + float4 ret = color; + ret.gb = ret.ra; + ret.ra = float2(0.0101, 0.0404); + return ret; +} + +[test] +uniform 0 float4 0.0303 0.08 0.07 0.0202 +draw quad +probe all rgba (0.0101, 0.0303, 0.0202, 0.0404) diff --git a/tests/swizzle-1.shader_test b/tests/swizzle-1.shader_test new file mode 100644 index 00000000..40cdc010 --- /dev/null +++ b/tests/swizzle-1.shader_test @@ -0,0 +1,11 @@ +[pixel shader] +float4 main() : SV_target +{ + float4 ret = float4(0.1, 0.2, 0.3, 0.4); + ret.wyz.yx = float2(0.5, 0.6).yx; + return ret; +} + +[test] +draw quad +probe all rgba (0.1, 0.6, 0.3, 0.5) diff --git a/tests/swizzle-2.shader_test b/tests/swizzle-2.shader_test new file mode 100644 index 00000000..b07134c6 --- /dev/null +++ b/tests/swizzle-2.shader_test @@ -0,0 +1,11 @@ +[pixel shader] +float4 main() : SV_target +{ + float4 ret; + ret.zwyx = float4(0.1, 0.2, 0.3, 0.4); + return ret; +} + +[test] +draw quad +probe all rgba (0.4, 0.3, 0.1, 0.2) diff --git a/tests/swizzle-3.shader_test b/tests/swizzle-3.shader_test new file mode 100644 index 00000000..1ecf5a5c --- /dev/null +++ b/tests/swizzle-3.shader_test @@ -0,0 +1,14 @@ +[pixel shader] +float4 main() : SV_target +{ + float4 ret; + ret.yw.y = 0.1; + ret.xzy.yz.y.x = 0.2; + ret.yzwx.yzwx.wz.y = 0.3; + ret.zxy.xyz.zxy.xy.y = 0.4; + return ret; +} + +[test] +draw quad +probe all rgba (0.3, 0.2, 0.4, 0.1) diff --git a/tests/swizzle-4.shader_test b/tests/swizzle-4.shader_test new file mode 100644 index 00000000..c09fa515 --- /dev/null +++ b/tests/swizzle-4.shader_test @@ -0,0 +1,13 @@ +[pixel shader] +float4 main() : SV_target +{ + float4 ret; + ret.yxz.yx = float2(0.1, 0.2); + ret.w.x = 0.3; + ret.wzyx.zyx.yx.x = 0.4; + return ret; +} + +[test] +draw quad +probe all rgba (0.1, 0.2, 0.4, 0.3) diff --git a/tests/swizzle-5.shader_test b/tests/swizzle-5.shader_test new file mode 100644 index 00000000..5a3ee1db --- /dev/null +++ b/tests/swizzle-5.shader_test @@ -0,0 +1,10 @@ +[pixel shader] +float4 main() : SV_target +{ + float4 ret = float4(0.1, 0.2, 0.3, 0.4).ywxz.zyyz; + return ret; +} + +[test] +draw quad +probe all rgba (0.1, 0.4, 0.4, 0.1) diff --git a/tests/swizzle-6.shader_test b/tests/swizzle-6.shader_test new file mode 100644 index 00000000..04251c65 --- /dev/null +++ b/tests/swizzle-6.shader_test @@ -0,0 +1,12 @@ +[pixel shader] +float4 main() : SV_target +{ + float4 ret = float4(0.1, 0.2, 0.3, 0.4); + ret.yxwz = ret; + ret = ret.wyzx; + return ret; +} + +[test] +draw quad +probe all rgba (0.3, 0.1, 0.4, 0.2) diff --git a/tests/swizzle-7.shader_test b/tests/swizzle-7.shader_test new file mode 100644 index 00000000..15a4cd07 --- /dev/null +++ b/tests/swizzle-7.shader_test @@ -0,0 +1,11 @@ +[pixel shader] +float4 main() : SV_target +{ + float4 ret; + ret.xyzw.xyzw = float4(0.1, 0.2, 0.3, 0.4); + return ret; +} + +[test] +draw quad +probe all rgba (0.1, 0.2, 0.3, 0.4)
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=79751
Your paranoid android.
=== debiant (build log) ===
Task: Patch failed to apply
=== debiant (build log) ===
Task: Patch failed to apply
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- Makefile.am | 2 ++ tests/math.shader_test | 15 +++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 tests/math.shader_test
diff --git a/Makefile.am b/Makefile.am index 958be146..bb69078c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -50,6 +50,7 @@ vkd3d_shader_runners = \ tests/shader_runner_d3d12
vkd3d_shader_tests = \ + tests/math.shader_test \ tests/swizzle-0.shader_test \ tests/swizzle-1.shader_test \ tests/swizzle-2.shader_test \ @@ -177,6 +178,7 @@ tests_vkd3d_api_LDADD = libvkd3d.la @VULKAN_LIBS@ tests_vkd3d_shader_api_LDADD = libvkd3d-shader.la SHADER_TEST_LOG_COMPILER = tests/shader_runner_d3d12 XFAIL_TESTS = \ + tests/math.shader_test \ tests/swizzle-0.shader_test \ tests/swizzle-1.shader_test \ tests/swizzle-2.shader_test \ diff --git a/tests/math.shader_test b/tests/math.shader_test new file mode 100644 index 00000000..2fe59a08 --- /dev/null +++ b/tests/math.shader_test @@ -0,0 +1,15 @@ +[pixel shader] +float4 main(uniform float u, uniform float v, uniform float w, uniform float x, + uniform float y, uniform float z) : SV_TARGET +{ + return float4(x * y - z / w + --u / -v, + z * x / y + w / -v, + u + v - w, + x / y / w); +} + +[test] +uniform 0 float4 2.5 0.3 0.2 0.7 +uniform 4 float4 0.1 1.5 0.0 0.0 +draw quad +probe all rgba (-12.43, 9.833333, 1.6, 35.0) 1