[PATCH vkd3d v3 2/8] tests: Move HLSL shader compilation to a new d3d12 shader runner backend.
Zebediah Figura
zfigura at codeweavers.com
Wed Jan 26 19:40:27 CST 2022
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
Makefile.am | 37 ++++++++++++++------
include/private/vkd3d_test.h | 19 +++++++----
tests/shader_runner.c | 49 +++++++-------------------
tests/shader_runner.h | 37 ++++++++++++++++++++
tests/shader_runner_d3d12.c | 66 ++++++++++++++++++++++++++++++++++++
5 files changed, 154 insertions(+), 54 deletions(-)
create mode 100644 tests/shader_runner.h
create mode 100644 tests/shader_runner_d3d12.c
diff --git a/Makefile.am b/Makefile.am
index 17fcae32f..51fa6719e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -50,9 +50,6 @@ vkd3d_cross_tests = \
tests/d3d12_invalid_usage \
tests/hlsl_d3d12
-vkd3d_shader_runners = \
- tests/shader_runner
-
vkd3d_shader_tests = \
tests/abs.shader_test \
tests/cast-to-float.shader_test \
@@ -117,7 +114,8 @@ vkd3d_shader_tests = \
vkd3d_test_headers = \
tests/d3d12_crosstest.h \
- tests/d3d12_test_utils.h
+ tests/d3d12_test_utils.h \
+ tests/shader_runner.h
vkd3d_demos = \
demos/vkd3d-gears \
@@ -277,12 +275,15 @@ AM_DEFAULT_SOURCE_EXT = .c
TEST_EXTENSIONS = .shader_test
if BUILD_TESTS
-check_PROGRAMS = $(vkd3d_tests) $(vkd3d_cross_tests) $(vkd3d_shader_runners)
+check_PROGRAMS = $(vkd3d_tests) $(vkd3d_cross_tests) tests/shader_runner
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_hlsl_d3d12_LDADD = $(LDADD) @VULKAN_LIBS@
tests_shader_runner_LDADD = $(LDADD) @VULKAN_LIBS@
+tests_shader_runner_SOURCES = \
+ tests/shader_runner.c \
+ tests/shader_runner_d3d12.c
tests_vkd3d_api_LDADD = libvkd3d.la @VULKAN_LIBS@
tests_vkd3d_shader_api_LDADD = libvkd3d-shader.la
SHADER_TEST_LOG_COMPILER = tests/shader_runner
@@ -391,14 +392,17 @@ CROSS_CPPFLAGS = -I$(srcdir)/include -I$(srcdir)/include/private -I$(builddir)/i
CROSS_CFLAGS = -g -O2 -Wall -municode ${CROSS_CPPFLAGS} -D__USE_MINGW_ANSI_STDIO=0
EXTRA_DIST += $(cross_implibs:=.cross32.def) $(cross_implibs:=.cross64.def)
+shader_runner_cross_sources = \
+ $(srcdir)/tests/shader_runner.c \
+ $(srcdir)/tests/shader_runner_d3d12.c
+
if HAVE_CROSSTARGET32
CROSS32_CC = @CROSSCC32@
CROSS32_DLLTOOL = @CROSSTARGET32 at -dlltool
CROSS32_IMPLIBS = $(cross_implibs:=.cross32.a)
CROSS32_EXEFILES = $(vkd3d_cross_tests:=.cross32.exe) \
- $(vkd3d_demos:demos/vkd3d-%=demos/%.cross32.exe) \
- $(vkd3d_shader_runners:=.cross32.exe)
-CROSS32_FILES = $(CROSS32_IMPLIBS) $(CROSS32_EXEFILES)
+ $(vkd3d_demos:demos/vkd3d-%=demos/%.cross32.exe)
+CROSS32_FILES = $(CROSS32_IMPLIBS) $(CROSS32_EXEFILES) tests/shader_runner.cross32.exe
CLEANFILES += $(CROSS32_FILES)
crosstest32: $(CROSS32_FILES)
@@ -414,6 +418,12 @@ $(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 -ld3dcompiler_47 && \
$(am__mv) $$depbase.Tpo $$depbase.Po
+
+tests/shader_runner.cross32.exe: $(shader_runner_cross_sources) $(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 $@ $(shader_runner_cross_sources) $(CROSS32_IMPLIBS) -ldxgi -lgdi32 -ld3dcompiler_47 && \
+ $(am__mv) $$depbase.Tpo $$depbase.Po
+
else
crosstest32:
endif
@@ -423,9 +433,8 @@ CROSS64_CC = @CROSSCC64@
CROSS64_DLLTOOL = @CROSSTARGET64 at -dlltool
CROSS64_IMPLIBS = $(cross_implibs:=.cross64.a)
CROSS64_EXEFILES = $(vkd3d_cross_tests:=.cross64.exe) \
- $(vkd3d_demos:demos/vkd3d-%=demos/%.cross64.exe) \
- $(vkd3d_shader_runners:=.cross64.exe)
-CROSS64_FILES = $(CROSS64_IMPLIBS) $(CROSS64_EXEFILES)
+ $(vkd3d_demos:demos/vkd3d-%=demos/%.cross64.exe)
+CROSS64_FILES = $(CROSS64_IMPLIBS) $(CROSS64_EXEFILES) tests/shader_runner.cross64.exe
CLEANFILES += $(CROSS64_FILES)
crosstest64: $(CROSS64_FILES)
@@ -441,6 +450,12 @@ $(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 -ld3dcompiler_47 && \
$(am__mv) $$depbase.Tpo $$depbase.Po
+
+tests/shader_runner.cross64.exe: $(shader_runner_cross_sources) $(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 $@ $(shader_runner_cross_sources) $(CROSS64_IMPLIBS) -ldxgi -lgdi32 -ld3dcompiler_47 && \
+ $(am__mv) $$depbase.Tpo $$depbase.Po
+
else
crosstest64:
endif
diff --git a/include/private/vkd3d_test.h b/include/private/vkd3d_test.h
index 6b8763dde..0cc7fe4f3 100644
--- a/include/private/vkd3d_test.h
+++ b/include/private/vkd3d_test.h
@@ -28,16 +28,15 @@
#include <stdlib.h>
#include <string.h>
-static void vkd3d_test_main(int argc, char **argv);
-static const char *vkd3d_test_name;
-static const char *vkd3d_test_platform = "other";
+extern const char *vkd3d_test_name;
+extern const char *vkd3d_test_platform;
static void vkd3d_test_start_todo(bool is_todo);
static int vkd3d_test_loop_todo(void);
static void vkd3d_test_end_todo(void);
#define START_TEST(name) \
- static const char *vkd3d_test_name = #name; \
+ const char *vkd3d_test_name = #name; \
static void vkd3d_test_main(int argc, char **argv)
/*
@@ -100,7 +99,7 @@ static void vkd3d_test_end_todo(void);
#define todo todo_if(true)
-static struct
+struct vkd3d_test_state
{
LONG success_count;
LONG failure_count;
@@ -120,7 +119,8 @@ static struct
const char *test_name_filter;
char context[1024];
-} vkd3d_test_state;
+};
+extern struct vkd3d_test_state vkd3d_test_state;
static bool
vkd3d_test_platform_is_windows(void)
@@ -253,6 +253,12 @@ vkd3d_test_debug(const char *fmt, ...)
printf("%s\n", buffer);
}
+#ifndef VKD3D_TEST_NO_DEFS
+const char *vkd3d_test_platform = "other";
+struct vkd3d_test_state vkd3d_test_state;
+
+static void vkd3d_test_main(int argc, char **argv);
+
int main(int argc, char **argv)
{
const char *test_filter = getenv("VKD3D_TEST_FILTER");
@@ -339,6 +345,7 @@ int wmain(int argc, WCHAR **wargv)
return ret;
}
#endif /* _WIN32 */
+#endif /* VKD3D_TEST_NO_DEFS */
typedef void (*vkd3d_test_pfn)(void);
diff --git a/tests/shader_runner.c b/tests/shader_runner.c
index 5db963f51..ef0b81d1b 100644
--- a/tests/shader_runner.c
+++ b/tests/shader_runner.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2020 Zebediah Figura for CodeWeavers
+ * Copyright 2020-2021 Zebediah Figura for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -43,6 +43,7 @@
*/
#include "d3d12_crosstest.h"
+#include "shader_runner.h"
#include <errno.h>
static void VKD3D_NORETURN VKD3D_PRINTF_FUNC(1, 2) fatal_error(const char *format, ...)
@@ -115,16 +116,10 @@ struct texture
unsigned int root_index;
};
-enum shader_model
-{
- SHADER_MODEL_4_0 = 0,
- SHADER_MODEL_4_1,
- SHADER_MODEL_5_0,
- SHADER_MODEL_5_1,
-};
-
struct shader_context
{
+ const struct shader_runner_ops *ops;
+
struct test_context c;
enum shader_model minimum_shader_model;
@@ -140,22 +135,6 @@ struct shader_context
size_t sampler_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;
-}
-
static void free_texture(struct texture *texture)
{
ID3D12DescriptorHeap_Release(texture->heap);
@@ -643,7 +622,7 @@ static struct texture *get_texture(struct shader_context *context, unsigned int
return NULL;
}
-START_TEST(shader_runner)
+void run_shader_tests(int argc, char **argv, const struct shader_runner_ops *ops)
{
static const struct test_context_desc desc =
{
@@ -689,6 +668,7 @@ START_TEST(shader_runner)
}
memset(&context, 0, sizeof(context));
+ context.ops = ops;
init_test_context(&context.c, &desc);
for (;;)
@@ -709,20 +689,10 @@ START_TEST(shader_runner)
break;
case STATE_SHADER_PIXEL:
- {
- static const char *const shader_models[] =
- {
- [SHADER_MODEL_4_0] = "ps_4_0",
- [SHADER_MODEL_4_1] = "ps_4_1",
- [SHADER_MODEL_5_0] = "ps_5_0",
- [SHADER_MODEL_5_1] = "ps_5_1",
- };
-
- if (!(context.ps_code = compile_shader(shader_source, shader_models[context.minimum_shader_model])))
+ if (!(context.ps_code = context.ops->compile_shader(shader_source, context.minimum_shader_model)))
return;
shader_source_len = 0;
break;
- }
case STATE_SHADER_INVALID_PIXEL:
{
@@ -926,3 +896,8 @@ START_TEST(shader_runner)
fclose(f);
}
+
+START_TEST(shader_runner)
+{
+ run_shader_tests_d3d12(argc, argv);
+}
diff --git a/tests/shader_runner.h b/tests/shader_runner.h
new file mode 100644
index 000000000..b00803cff
--- /dev/null
+++ b/tests/shader_runner.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2021 Zebediah Figura 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_windows.h"
+#include "vkd3d_d3dcommon.h"
+
+enum shader_model
+{
+ SHADER_MODEL_4_0 = 0,
+ SHADER_MODEL_4_1,
+ SHADER_MODEL_5_0,
+ SHADER_MODEL_5_1,
+};
+
+struct shader_runner_ops
+{
+ ID3D10Blob *(*compile_shader)(const char *source, enum shader_model minimum_shader_model);
+};
+
+void run_shader_tests(int argc, char **argv, const struct shader_runner_ops *ops);
+
+void run_shader_tests_d3d12(int argc, char **argv);
diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c
new file mode 100644
index 000000000..6343f78e9
--- /dev/null
+++ b/tests/shader_runner_d3d12.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2020-2021 Zebediah Figura 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
+ */
+
+#ifdef __MINGW32__
+# define _HRESULT_DEFINED
+typedef int HRESULT;
+#endif
+
+#define COBJMACROS
+#define CONST_VTABLE
+#define VKD3D_TEST_NO_DEFS
+#include "vkd3d_windows.h"
+#include "vkd3d_d3dcommon.h"
+#include "vkd3d_d3dcompiler.h"
+#include "vkd3d_test.h"
+#include "shader_runner.h"
+
+static ID3D10Blob *d3d12_runner_compile_shader(const char *source, enum shader_model shader_model)
+{
+ ID3D10Blob *blob = NULL, *errors = NULL;
+ HRESULT hr;
+
+ static const char *const shader_models[] =
+ {
+ [SHADER_MODEL_4_0] = "ps_4_0",
+ [SHADER_MODEL_4_1] = "ps_4_1",
+ [SHADER_MODEL_5_0] = "ps_5_0",
+ [SHADER_MODEL_5_1] = "ps_5_1",
+ };
+
+ hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main",
+ shader_models[shader_model], 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;
+}
+
+static const struct shader_runner_ops d3d12_runner_ops =
+{
+ .compile_shader = d3d12_runner_compile_shader,
+};
+
+void run_shader_tests_d3d12(int argc, char **argv)
+{
+ run_shader_tests(argc, argv, &d3d12_runner_ops);
+}
--
2.34.1
More information about the wine-devel
mailing list