tests/shader_runner: Use the global test_options structure.

Inspired by a patch by Giovanni Mascellani.
This commit is contained in:
Zebediah Figura 2023-02-21 17:46:36 -06:00 committed by Alexandre Julliard
parent c8a05a8b10
commit 9ea84ae8c9
Notes: Alexandre Julliard 2023-03-10 21:36:20 +01:00
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Zebediah Figura (@zfigura)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/117
11 changed files with 71 additions and 117 deletions

View File

@ -23,6 +23,8 @@
#include "d3d12_crosstest.h"
struct test_options test_options = {0};
static PFN_D3D12_CREATE_VERSIONED_ROOT_SIGNATURE_DESERIALIZER pfn_D3D12CreateVersionedRootSignatureDeserializer;
static PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE pfn_D3D12SerializeVersionedRootSignature;

View File

@ -258,14 +258,6 @@ static void wait_queue_idle_(unsigned int line, ID3D12Device *device, ID3D12Comm
ID3D12Fence_Release(fence);
}
static struct test_options
{
bool use_warp_device;
unsigned int adapter_idx;
bool enable_debug_layer;
bool enable_gpu_based_validation;
} test_options;
#ifdef VKD3D_CROSSTEST
static IUnknown *create_warp_adapter(IDXGIFactory4 *factory)
{
@ -675,23 +667,6 @@ static inline bool is_depth_clip_enable_supported(ID3D12Device *device)
}
#endif
static void parse_args(int argc, char **argv)
{
unsigned int i;
for (i = 1; i < argc; ++i)
{
if (!strcmp(argv[i], "--warp"))
test_options.use_warp_device = true;
else if (!strcmp(argv[i], "--adapter") && i + 1 < argc)
test_options.adapter_idx = atoi(argv[++i]);
else if (!strcmp(argv[i], "--validate"))
test_options.enable_debug_layer = true;
else if (!strcmp(argv[i], "--gbv"))
test_options.enable_gpu_based_validation = true;
}
}
static void enable_d3d12_debug_layer(void)
{
ID3D12Debug1 *debug1;

View File

@ -18,6 +18,8 @@
#include "d3d12_crosstest.h"
struct test_options test_options = {0};
#define recreate_command_list(a, b, c) recreate_command_list_(__LINE__, a, b, c)
static void recreate_command_list_(unsigned int line, ID3D12Device *device,
ID3D12CommandAllocator *allocator, ID3D12GraphicsCommandList **command_list)

View File

@ -20,6 +20,8 @@
#include "d3d12_crosstest.h"
#include "vkd3d_common.h"
struct test_options test_options = {0};
#define check_preprocess(a, b, c, d, e) check_preprocess_(__LINE__, a, b, c, d, e)
static void check_preprocess_(int line, const char *source, const D3D_SHADER_MACRO *macros,
ID3DInclude *include, const char *present, const char *absent)

View File

@ -61,6 +61,8 @@ typedef int HRESULT;
#include "vkd3d_test.h"
#include "shader_runner.h"
struct test_options test_options = {0};
void fatal_error(const char *format, ...)
{
va_list args;
@ -692,39 +694,23 @@ static void compile_shader(struct shader_runner *runner, const char *source, siz
}
}
void run_shader_tests(struct shader_runner *runner, int argc, char **argv, const struct shader_runner_ops *ops)
void run_shader_tests(struct shader_runner *runner, const struct shader_runner_ops *ops)
{
size_t shader_source_size = 0, shader_source_len = 0;
struct resource_params current_resource;
struct sampler *current_sampler = NULL;
enum parse_state state = STATE_NONE;
unsigned int i, line_number = 0;
const char *filename = NULL;
char *shader_source = NULL;
HRESULT expect_hr = S_OK;
char line[256];
FILE *f;
for (i = 1; i < argc; ++i)
{
if (argv[i][0] != '-')
{
filename = argv[i];
break;
}
}
if (!test_options.filename)
fatal_error("No filename specified.\n");
if (!filename)
{
fprintf(stderr, "Usage: %s [file]\n", argv[0]);
return;
}
if (!(f = fopen(filename, "r")))
{
fatal_error("Unable to open '%s' for reading: %s\n", argv[1], strerror(errno));
return;
}
if (!(f = fopen(test_options.filename, "r")))
fatal_error("Unable to open '%s' for reading: %s\n", test_options.filename, strerror(errno));
memset(runner, 0, sizeof(*runner));
runner->ops = ops;
@ -1114,17 +1100,19 @@ out:
START_TEST(shader_runner)
{
parse_args(argc, argv);
#if defined(VKD3D_CROSSTEST)
trace("Running tests from a Windows cross build\n");
trace("Compiling shaders with d3dcompiler_47.dll and executing with d3d9.dll\n");
run_shader_tests_d3d9(argc, argv);
run_shader_tests_d3d9();
trace("Compiling shaders with d3dcompiler_47.dll and executing with d3d11.dll\n");
run_shader_tests_d3d11(argc, argv);
run_shader_tests_d3d11();
trace("Compiling shaders with d3dcompiler_47.dll and executing with d3d12.dll\n");
run_shader_tests_d3d12(argc, argv);
run_shader_tests_d3d12();
print_dll_version("d3dcompiler_47.dll");
print_dll_version("dxgi.dll");
@ -1135,13 +1123,13 @@ START_TEST(shader_runner)
trace("Running tests from a Windows non-cross build\n");
trace("Compiling shaders with vkd3d-shader and executing with d3d9.dll\n");
run_shader_tests_d3d9(argc, argv);
run_shader_tests_d3d9();
trace("Compiling shaders with vkd3d-shader and executing with d3d11.dll\n");
run_shader_tests_d3d11(argc, argv);
run_shader_tests_d3d11();
trace("Compiling shaders with vkd3d-shader and executing with vkd3d\n");
run_shader_tests_d3d12(argc, argv);
run_shader_tests_d3d12();
print_dll_version("d3d9.dll");
print_dll_version("d3d11.dll");
@ -1149,9 +1137,9 @@ START_TEST(shader_runner)
trace("Running tests from a Unix build\n");
trace("Compiling shaders with vkd3d-shader and executing with Vulkan\n");
run_shader_tests_vulkan(argc, argv);
run_shader_tests_vulkan();
trace("Compiling shaders with vkd3d-shader and executing with vkd3d\n");
run_shader_tests_d3d12(argc, argv);
run_shader_tests_d3d12();
#endif
}

View File

@ -139,12 +139,12 @@ void fatal_error(const char *format, ...) VKD3D_NORETURN VKD3D_PRINTF_FUNC(1, 2)
unsigned int get_vb_stride(const struct shader_runner *runner, unsigned int slot);
void init_resource(struct resource *resource, const struct resource_params *params);
void run_shader_tests(struct shader_runner *runner, int argc, char **argv, const struct shader_runner_ops *ops);
void run_shader_tests(struct shader_runner *runner, const struct shader_runner_ops *ops);
#ifdef _WIN32
void run_shader_tests_d3d9(int argc, char **argv);
void run_shader_tests_d3d11(int argc, char **argv);
void run_shader_tests_d3d9(void);
void run_shader_tests_d3d11(void);
#else
void run_shader_tests_vulkan(int argc, char **argv);
void run_shader_tests_vulkan(void);
#endif
void run_shader_tests_d3d12(int argc, char **argv);
void run_shader_tests_d3d12(void);

View File

@ -70,10 +70,6 @@ static struct d3d11_shader_runner *d3d11_shader_runner(struct shader_runner *r)
return CONTAINING_RECORD(r, struct d3d11_shader_runner, r);
}
static bool enable_debug_layer;
static bool use_warp_adapter;
static unsigned int use_adapter_idx;
static ID3D10Blob *compile_shader(const char *source, const char *type, enum shader_model shader_model)
{
ID3D10Blob *blob = NULL, *errors = NULL;
@ -101,30 +97,6 @@ static ID3D10Blob *compile_shader(const char *source, const char *type, enum sha
return blob;
}
static void parse_args(int argc, char **argv)
{
unsigned int i;
for (i = 1; i < argc; ++i)
{
if (!strcmp(argv[i], "--warp"))
use_warp_adapter = true;
else if (!strcmp(argv[i], "--adapter") && i + 1 < argc)
use_adapter_idx = atoi(argv[++i]);
}
}
static void enable_d3d11_debug_layer(int argc, char **argv)
{
unsigned int i;
for (i = 1; i < argc; ++i)
{
if (!strcmp(argv[i], "--validate"))
enable_debug_layer = true;
}
}
static IDXGIAdapter *create_adapter(void)
{
IDXGIFactory4 *factory4;
@ -145,7 +117,7 @@ static IDXGIAdapter *create_adapter(void)
}
adapter = NULL;
if (use_warp_adapter)
if (test_options.use_warp_device)
{
if (SUCCEEDED(hr = IDXGIFactory_QueryInterface(factory, &IID_IDXGIFactory4, (void **)&factory4)))
{
@ -159,7 +131,7 @@ static IDXGIAdapter *create_adapter(void)
}
else
{
hr = IDXGIFactory_EnumAdapters(factory, use_adapter_idx, &adapter);
hr = IDXGIFactory_EnumAdapters(factory, test_options.adapter_idx, &adapter);
}
IDXGIFactory_Release(factory);
if (FAILED(hr))
@ -191,7 +163,7 @@ static void init_adapter_info(void)
if (desc.VendorId == 0x1414 && desc.DeviceId == 0x008c)
{
trace("Using WARP device.\n");
use_warp_adapter = true;
test_options.use_warp_device = true;
}
IDXGIAdapter_Release(adapter);
@ -210,7 +182,7 @@ static ID3D11Device *create_device(void)
UINT flags = 0;
HRESULT hr;
if (enable_debug_layer)
if (test_options.enable_debug_layer)
flags |= D3D11_CREATE_DEVICE_DEBUG;
if ((adapter = create_adapter()))
@ -688,7 +660,7 @@ static const struct shader_runner_ops d3d11_runner_ops =
.release_readback = d3d11_runner_release_readback,
};
void run_shader_tests_d3d11(int argc, char **argv)
void run_shader_tests_d3d11(void)
{
struct d3d11_shader_runner runner;
HMODULE dxgi_module, d3d11_module;
@ -700,12 +672,10 @@ void run_shader_tests_d3d11(int argc, char **argv)
pCreateDXGIFactory1 = (void *)GetProcAddress(dxgi_module, "CreateDXGIFactory1");
pD3D11CreateDevice = (void *)GetProcAddress(d3d11_module, "D3D11CreateDevice");
parse_args(argc, argv);
enable_d3d11_debug_layer(argc, argv);
init_adapter_info();
if (init_test_context(&runner))
{
run_shader_tests(&runner.r, argc, argv, &d3d11_runner_ops);
run_shader_tests(&runner.r, &d3d11_runner_ops);
destroy_test_context(&runner);
}
}

View File

@ -509,7 +509,7 @@ static const struct shader_runner_ops d3d12_runner_ops =
.release_readback = d3d12_runner_release_readback,
};
void run_shader_tests_d3d12(int argc, char **argv)
void run_shader_tests_d3d12(void)
{
static const struct test_context_desc desc =
{
@ -522,7 +522,6 @@ void run_shader_tests_d3d12(int argc, char **argv)
ID3D12Device *device;
HRESULT hr;
parse_args(argc, argv);
enable_d3d12_debug_layer();
init_adapter_info();
init_test_context(&runner.test_context, &desc);
@ -539,7 +538,7 @@ void run_shader_tests_d3d12(int argc, char **argv)
runner.compute_allocator, NULL, &IID_ID3D12GraphicsCommandList, (void **)&runner.compute_list);
ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
run_shader_tests(&runner.r, argc, argv, &d3d12_runner_ops);
run_shader_tests(&runner.r, &d3d12_runner_ops);
ID3D12GraphicsCommandList_Release(runner.compute_list);
ID3D12CommandAllocator_Release(runner.compute_allocator);

View File

@ -56,8 +56,6 @@ static struct d3d9_shader_runner *d3d9_shader_runner(struct shader_runner *r)
static IDirect3D9 *(WINAPI *pDirect3DCreate9)(UINT sdk_version);
static unsigned int use_adapter_idx;
static ID3D10Blob *compile_shader(const char *source, const char *profile)
{
ID3D10Blob *blob = NULL, *errors = NULL;
@ -74,17 +72,6 @@ static ID3D10Blob *compile_shader(const char *source, const char *profile)
return blob;
}
static void parse_args(int argc, char **argv)
{
unsigned int i;
for (i = 1; i < argc; ++i)
{
if (!strcmp(argv[i], "--adapter") && i + 1 < argc)
use_adapter_idx = atoi(argv[++i]);
}
}
static void init_adapter_info(void)
{
D3DADAPTER_IDENTIFIER9 identifier;
@ -94,7 +81,7 @@ static void init_adapter_info(void)
d3d = pDirect3DCreate9(D3D_SDK_VERSION);
ok(!!d3d, "Failed to create a D3D object.\n");
hr = IDirect3D9_GetAdapterIdentifier(d3d, use_adapter_idx, 0, &identifier);
hr = IDirect3D9_GetAdapterIdentifier(d3d, test_options.adapter_idx, 0, &identifier);
ok(hr == S_OK, "Failed to get adapter identifier, hr %#lx.\n", hr);
trace("Driver string: %s.\n", identifier.Driver);
@ -517,7 +504,7 @@ static const struct shader_runner_ops d3d9_runner_ops =
.release_readback = d3d9_runner_release_readback,
};
void run_shader_tests_d3d9(int argc, char **argv)
void run_shader_tests_d3d9(void)
{
struct d3d9_shader_runner runner;
HMODULE d3d9_module;
@ -527,10 +514,9 @@ void run_shader_tests_d3d9(int argc, char **argv)
{
pDirect3DCreate9 = (void *)GetProcAddress(d3d9_module, "Direct3DCreate9");
parse_args(argc, argv);
init_adapter_info();
init_test_context(&runner);
run_shader_tests(&runner.r, argc, argv, &d3d9_runner_ops);
run_shader_tests(&runner.r, &d3d9_runner_ops);
destroy_test_context(&runner);
}
FreeLibrary(d3d9_module);

View File

@ -1276,14 +1276,14 @@ static void cleanup_vulkan_runner(struct vulkan_shader_runner *runner)
VK_CALL(vkDestroyInstance(runner->instance, NULL));
}
void run_shader_tests_vulkan(int argc, char **argv)
void run_shader_tests_vulkan(void)
{
struct vulkan_shader_runner runner = {0};
if (!init_vulkan_runner(&runner))
return;
run_shader_tests(&runner.r, argc, argv, &vulkan_runner_ops);
run_shader_tests(&runner.r, &vulkan_runner_ops);
cleanup_vulkan_runner(&runner);
}

View File

@ -199,4 +199,34 @@ static inline void check_readback_data_vec4_(unsigned int line, const struct res
got.x, got.y, got.z, got.w, expected->x, expected->y, expected->z, expected->w, x, y);
}
struct test_options
{
bool use_warp_device;
unsigned int adapter_idx;
bool enable_debug_layer;
bool enable_gpu_based_validation;
const char *filename;
};
extern struct test_options test_options;
static inline void parse_args(int argc, char **argv)
{
unsigned int i;
for (i = 1; i < argc; ++i)
{
if (!strcmp(argv[i], "--warp"))
test_options.use_warp_device = true;
else if (!strcmp(argv[i], "--adapter") && i + 1 < argc)
test_options.adapter_idx = atoi(argv[++i]);
else if (!strcmp(argv[i], "--validate"))
test_options.enable_debug_layer = true;
else if (!strcmp(argv[i], "--gbv"))
test_options.enable_gpu_based_validation = true;
else if (argv[i][0] != '-')
test_options.filename = argv[i];
}
}
#endif