tests: Move HLSL shader compilation to a new d3d12 shader runner backend.

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2022-01-26 19:40:27 -06:00 committed by Alexandre Julliard
parent 63622a92e8
commit 85d61f0c64
5 changed files with 154 additions and 54 deletions

View File

@ -50,9 +50,6 @@ vkd3d_cross_tests = \
tests/d3d12_invalid_usage \ tests/d3d12_invalid_usage \
tests/hlsl_d3d12 tests/hlsl_d3d12
vkd3d_shader_runners = \
tests/shader_runner
vkd3d_shader_tests = \ vkd3d_shader_tests = \
tests/abs.shader_test \ tests/abs.shader_test \
tests/cast-to-float.shader_test \ tests/cast-to-float.shader_test \
@ -117,7 +114,8 @@ vkd3d_shader_tests = \
vkd3d_test_headers = \ vkd3d_test_headers = \
tests/d3d12_crosstest.h \ tests/d3d12_crosstest.h \
tests/d3d12_test_utils.h tests/d3d12_test_utils.h \
tests/shader_runner.h
vkd3d_demos = \ vkd3d_demos = \
demos/vkd3d-gears \ demos/vkd3d-gears \
@ -277,12 +275,15 @@ AM_DEFAULT_SOURCE_EXT = .c
TEST_EXTENSIONS = .shader_test TEST_EXTENSIONS = .shader_test
if BUILD_TESTS 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 = $(vkd3d_tests) $(vkd3d_cross_tests) $(vkd3d_shader_tests)
tests_d3d12_LDADD = $(LDADD) @PTHREAD_LIBS@ @VULKAN_LIBS@ tests_d3d12_LDADD = $(LDADD) @PTHREAD_LIBS@ @VULKAN_LIBS@
tests_d3d12_invalid_usage_LDADD = $(LDADD) @VULKAN_LIBS@ tests_d3d12_invalid_usage_LDADD = $(LDADD) @VULKAN_LIBS@
tests_hlsl_d3d12_LDADD = $(LDADD) @VULKAN_LIBS@ tests_hlsl_d3d12_LDADD = $(LDADD) @VULKAN_LIBS@
tests_shader_runner_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_api_LDADD = libvkd3d.la @VULKAN_LIBS@
tests_vkd3d_shader_api_LDADD = libvkd3d-shader.la tests_vkd3d_shader_api_LDADD = libvkd3d-shader.la
SHADER_TEST_LOG_COMPILER = tests/shader_runner 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 CROSS_CFLAGS = -g -O2 -Wall -municode ${CROSS_CPPFLAGS} -D__USE_MINGW_ANSI_STDIO=0
EXTRA_DIST += $(cross_implibs:=.cross32.def) $(cross_implibs:=.cross64.def) 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 if HAVE_CROSSTARGET32
CROSS32_CC = @CROSSCC32@ CROSS32_CC = @CROSSCC32@
CROSS32_DLLTOOL = @CROSSTARGET32@-dlltool CROSS32_DLLTOOL = @CROSSTARGET32@-dlltool
CROSS32_IMPLIBS = $(cross_implibs:=.cross32.a) CROSS32_IMPLIBS = $(cross_implibs:=.cross32.a)
CROSS32_EXEFILES = $(vkd3d_cross_tests:=.cross32.exe) \ CROSS32_EXEFILES = $(vkd3d_cross_tests:=.cross32.exe) \
$(vkd3d_demos:demos/vkd3d-%=demos/%.cross32.exe) \ $(vkd3d_demos:demos/vkd3d-%=demos/%.cross32.exe)
$(vkd3d_shader_runners:=.cross32.exe) CROSS32_FILES = $(CROSS32_IMPLIBS) $(CROSS32_EXEFILES) tests/shader_runner.cross32.exe
CROSS32_FILES = $(CROSS32_IMPLIBS) $(CROSS32_EXEFILES)
CLEANFILES += $(CROSS32_FILES) CLEANFILES += $(CROSS32_FILES)
crosstest32: $(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$$!!'`; \ $(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 && \ $(CROSS32_CC) $(CROSS_CFLAGS) -MT $@ -MD -MP -MF $$depbase.Tpo -o $@ $< $(CROSS32_IMPLIBS) -ldxgi -lgdi32 -ld3dcompiler_47 && \
$(am__mv) $$depbase.Tpo $$depbase.Po $(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 else
crosstest32: crosstest32:
endif endif
@ -423,9 +433,8 @@ CROSS64_CC = @CROSSCC64@
CROSS64_DLLTOOL = @CROSSTARGET64@-dlltool CROSS64_DLLTOOL = @CROSSTARGET64@-dlltool
CROSS64_IMPLIBS = $(cross_implibs:=.cross64.a) CROSS64_IMPLIBS = $(cross_implibs:=.cross64.a)
CROSS64_EXEFILES = $(vkd3d_cross_tests:=.cross64.exe) \ CROSS64_EXEFILES = $(vkd3d_cross_tests:=.cross64.exe) \
$(vkd3d_demos:demos/vkd3d-%=demos/%.cross64.exe) \ $(vkd3d_demos:demos/vkd3d-%=demos/%.cross64.exe)
$(vkd3d_shader_runners:=.cross64.exe) CROSS64_FILES = $(CROSS64_IMPLIBS) $(CROSS64_EXEFILES) tests/shader_runner.cross64.exe
CROSS64_FILES = $(CROSS64_IMPLIBS) $(CROSS64_EXEFILES)
CLEANFILES += $(CROSS64_FILES) CLEANFILES += $(CROSS64_FILES)
crosstest64: $(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$$!!'`; \ $(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 && \ $(CROSS64_CC) $(CROSS_CFLAGS) -MT $@ -MD -MP -MF $$depbase.Tpo -o $@ $< $(CROSS64_IMPLIBS) -ldxgi -lgdi32 -ld3dcompiler_47 && \
$(am__mv) $$depbase.Tpo $$depbase.Po $(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 else
crosstest64: crosstest64:
endif endif

View File

@ -28,16 +28,15 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
static void vkd3d_test_main(int argc, char **argv); extern const char *vkd3d_test_name;
static const char *vkd3d_test_name; extern const char *vkd3d_test_platform;
static const char *vkd3d_test_platform = "other";
static void vkd3d_test_start_todo(bool is_todo); static void vkd3d_test_start_todo(bool is_todo);
static int vkd3d_test_loop_todo(void); static int vkd3d_test_loop_todo(void);
static void vkd3d_test_end_todo(void); static void vkd3d_test_end_todo(void);
#define START_TEST(name) \ #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) 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) #define todo todo_if(true)
static struct struct vkd3d_test_state
{ {
LONG success_count; LONG success_count;
LONG failure_count; LONG failure_count;
@ -120,7 +119,8 @@ static struct
const char *test_name_filter; const char *test_name_filter;
char context[1024]; char context[1024];
} vkd3d_test_state; };
extern struct vkd3d_test_state vkd3d_test_state;
static bool static bool
vkd3d_test_platform_is_windows(void) vkd3d_test_platform_is_windows(void)
@ -253,6 +253,12 @@ vkd3d_test_debug(const char *fmt, ...)
printf("%s\n", buffer); 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) int main(int argc, char **argv)
{ {
const char *test_filter = getenv("VKD3D_TEST_FILTER"); const char *test_filter = getenv("VKD3D_TEST_FILTER");
@ -339,6 +345,7 @@ int wmain(int argc, WCHAR **wargv)
return ret; return ret;
} }
#endif /* _WIN32 */ #endif /* _WIN32 */
#endif /* VKD3D_TEST_NO_DEFS */
typedef void (*vkd3d_test_pfn)(void); typedef void (*vkd3d_test_pfn)(void);

View File

@ -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 * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -43,6 +43,7 @@
*/ */
#include "d3d12_crosstest.h" #include "d3d12_crosstest.h"
#include "shader_runner.h"
#include <errno.h> #include <errno.h>
static void VKD3D_NORETURN VKD3D_PRINTF_FUNC(1, 2) fatal_error(const char *format, ...) static void VKD3D_NORETURN VKD3D_PRINTF_FUNC(1, 2) fatal_error(const char *format, ...)
@ -115,16 +116,10 @@ struct texture
unsigned int root_index; 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 struct shader_context
{ {
const struct shader_runner_ops *ops;
struct test_context c; struct test_context c;
enum shader_model minimum_shader_model; enum shader_model minimum_shader_model;
@ -140,22 +135,6 @@ struct shader_context
size_t sampler_count; 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) static void free_texture(struct texture *texture)
{ {
ID3D12DescriptorHeap_Release(texture->heap); ID3D12DescriptorHeap_Release(texture->heap);
@ -643,7 +622,7 @@ static struct texture *get_texture(struct shader_context *context, unsigned int
return NULL; 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 = static const struct test_context_desc desc =
{ {
@ -689,6 +668,7 @@ START_TEST(shader_runner)
} }
memset(&context, 0, sizeof(context)); memset(&context, 0, sizeof(context));
context.ops = ops;
init_test_context(&context.c, &desc); init_test_context(&context.c, &desc);
for (;;) for (;;)
@ -709,20 +689,10 @@ START_TEST(shader_runner)
break; break;
case STATE_SHADER_PIXEL: case STATE_SHADER_PIXEL:
{ if (!(context.ps_code = context.ops->compile_shader(shader_source, context.minimum_shader_model)))
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])))
return; return;
shader_source_len = 0; shader_source_len = 0;
break; break;
}
case STATE_SHADER_INVALID_PIXEL: case STATE_SHADER_INVALID_PIXEL:
{ {
@ -926,3 +896,8 @@ START_TEST(shader_runner)
fclose(f); fclose(f);
} }
START_TEST(shader_runner)
{
run_shader_tests_d3d12(argc, argv);
}

37
tests/shader_runner.h Normal file
View File

@ -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);

View File

@ -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);
}