tests: Add test file syntax to specify compiler options.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
This commit is contained in:
Nikolay Sivov 2023-07-13 07:41:14 +02:00 committed by Alexandre Julliard
parent bd3d4a6c06
commit 01faf6ad9e
Notes: Alexandre Julliard 2023-07-24 22:55:13 +02:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Zebediah Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/261
6 changed files with 65 additions and 19 deletions

View File

@ -111,6 +111,8 @@ static bool match_string(const char *line, const char *token, const char **const
static void parse_require_directive(struct shader_runner *runner, const char *line)
{
unsigned int i;
if (match_string(line, "shader model >=", &line))
{
static const char *const model_strings[] =
@ -122,7 +124,6 @@ static void parse_require_directive(struct shader_runner *runner, const char *li
[SHADER_MODEL_5_0] = "5.0",
[SHADER_MODEL_5_1] = "5.1",
};
unsigned int i;
for (i = 0; i < ARRAY_SIZE(model_strings); ++i)
{
@ -135,6 +136,27 @@ static void parse_require_directive(struct shader_runner *runner, const char *li
fatal_error("Unknown shader model '%s'.\n", line);
}
else if (match_string(line, "options:", &line))
{
static const struct option
{
unsigned int option;
const char *name;
}
options[] =
{
{ 0, "none" },
{ D3DCOMPILE_PACK_MATRIX_ROW_MAJOR, "row-major" },
{ D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR, "column-major" },
};
runner->compile_options = 0;
for (i = 0; i < ARRAY_SIZE(options); ++i)
{
if (match_string(line, options[i].name, &line))
runner->compile_options |= options[i].option;
}
}
else
{
fatal_error("Unknown require directive '%s'.\n", line);
@ -751,9 +773,9 @@ static HRESULT map_unidentified_hrs(HRESULT hr)
static void compile_shader(struct shader_runner *runner, const char *source, size_t len, const char *type, HRESULT expect)
{
UINT flags = runner->compile_options | D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY;
ID3D10Blob *blob = NULL, *errors = NULL;
char profile[7];
UINT flags = 0;
HRESULT hr;
static const char *const shader_models[] =
@ -766,7 +788,6 @@ static void compile_shader(struct shader_runner *runner, const char *source, siz
[SHADER_MODEL_5_1] = "5_1",
};
flags |= D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY;
sprintf(profile, "%s_%s", type, shader_models[runner->minimum_shader_model]);
hr = D3DCompile(source, len, NULL, NULL, NULL, "main", profile, flags, 0, &blob, &errors);
hr = map_unidentified_hrs(hr);

View File

@ -123,6 +123,8 @@ struct shader_runner
struct input_element *input_elements;
size_t input_element_count, input_element_capacity;
unsigned int compile_options;
};
struct shader_runner_ops

View File

@ -72,11 +72,11 @@ static struct d3d11_shader_runner *d3d11_shader_runner(struct shader_runner *r)
return CONTAINING_RECORD(r, struct d3d11_shader_runner, r);
}
static ID3D10Blob *compile_shader(const char *source, const char *type, enum shader_model shader_model)
static ID3D10Blob *compile_shader(const struct d3d11_shader_runner *runner, const char *source, const char *type)
{
UINT flags = runner->r.compile_options | D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY;
ID3D10Blob *blob = NULL, *errors = NULL;
char profile[7];
UINT flags = 0;
HRESULT hr;
static const char *const shader_models[] =
@ -89,8 +89,7 @@ static ID3D10Blob *compile_shader(const char *source, const char *type, enum sha
[SHADER_MODEL_5_1] = "5_1",
};
flags |= D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY;
sprintf(profile, "%s_%s", type, shader_models[shader_model]);
sprintf(profile, "%s_%s", type, shader_models[runner->r.minimum_shader_model]);
hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main", profile, flags, 0, &blob, &errors);
ok(hr == S_OK, "Failed to compile shader, hr %#lx.\n", hr);
if (errors)
@ -477,7 +476,7 @@ static bool d3d11_runner_dispatch(struct shader_runner *r, unsigned int x, unsig
HRESULT hr;
size_t i;
if (!(cs_code = compile_shader(runner->r.cs_source, "cs", runner->r.minimum_shader_model)))
if (!(cs_code = compile_shader(runner, runner->r.cs_source, "cs")))
return false;
hr = ID3D11Device_CreateComputeShader(device, ID3D10Blob_GetBufferPointer(cs_code),
@ -550,10 +549,10 @@ static bool d3d11_runner_draw(struct shader_runner *r,
unsigned int i;
HRESULT hr;
if (!(vs_code = compile_shader(runner->r.vs_source, "vs", runner->r.minimum_shader_model)))
if (!(vs_code = compile_shader(runner, runner->r.vs_source, "vs")))
return false;
if (!(ps_code = compile_shader(runner->r.ps_source, "ps", runner->r.minimum_shader_model)))
if (!(ps_code = compile_shader(runner, runner->r.ps_source, "ps")))
{
ID3D10Blob_Release(vs_code);
return false;

View File

@ -58,9 +58,9 @@ static struct d3d12_shader_runner *d3d12_shader_runner(struct shader_runner *r)
static ID3D10Blob *compile_shader(const struct d3d12_shader_runner *runner, const char *source, const char *type)
{
UINT flags = runner->r.compile_options | D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY;
ID3D10Blob *blob = NULL, *errors = NULL;
char profile[7];
UINT flags = 0;
HRESULT hr;
static const char *const shader_models[] =
@ -73,7 +73,6 @@ static ID3D10Blob *compile_shader(const struct d3d12_shader_runner *runner, cons
[SHADER_MODEL_5_1] = "5_1",
};
flags |= D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY;
sprintf(profile, "%s_%s", type, shader_models[runner->r.minimum_shader_model]);
hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main", profile, flags, 0, &blob, &errors);
ok(FAILED(hr) == !blob, "Got unexpected hr %#x, blob %p.\n", hr, blob);

View File

@ -56,11 +56,10 @@ static struct d3d9_shader_runner *d3d9_shader_runner(struct shader_runner *r)
static IDirect3D9 *(WINAPI *pDirect3DCreate9)(UINT sdk_version);
static ID3D10Blob *compile_shader(const char *source, const char *type, enum shader_model shader_model)
static ID3D10Blob *compile_shader(const struct d3d9_shader_runner *runner, const char *source, const char *type)
{
ID3D10Blob *blob = NULL, *errors = NULL;
char profile[7];
UINT flags = 0;
HRESULT hr;
static const char *const shader_models[] =
@ -69,8 +68,8 @@ static ID3D10Blob *compile_shader(const char *source, const char *type, enum sha
[SHADER_MODEL_3_0] = "3_0",
};
sprintf(profile, "%s_%s", type, shader_models[shader_model]);
hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main", profile, flags, 0, &blob, &errors);
sprintf(profile, "%s_%s", type, shader_models[runner->r.minimum_shader_model]);
hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main", profile, runner->r.compile_options, 0, &blob, &errors);
ok(hr == S_OK, "Failed to compile shader, hr %#lx.\n", hr);
if (errors)
{
@ -335,10 +334,10 @@ static bool d3d9_runner_draw(struct shader_runner *r,
unsigned int i, j;
HRESULT hr;
if (!(vs_code = compile_shader(runner->r.vs_source, "vs", runner->r.minimum_shader_model)))
if (!(vs_code = compile_shader(runner, runner->r.vs_source, "vs")))
return false;
if (!(ps_code = compile_shader(runner->r.ps_source, "ps", runner->r.minimum_shader_model)))
if (!(ps_code = compile_shader(runner, runner->r.ps_source, "ps")))
{
ID3D10Blob_Release(vs_code);
return false;

View File

@ -26,6 +26,7 @@
#include "vulkan/vulkan.h"
#include "vkd3d_shader.h"
#include "vkd3d.h"
#include "vkd3d_d3dcompiler.h"
#include "shader_runner.h"
#include "vkd3d_test.h"
@ -386,8 +387,9 @@ static bool compile_shader(const struct vulkan_shader_runner *runner, const char
struct vkd3d_shader_resource_binding bindings[MAX_RESOURCES + MAX_SAMPLERS];
struct vkd3d_shader_push_constant_buffer push_constants;
struct vkd3d_shader_resource_binding *binding;
struct vkd3d_shader_compile_option options[1];
unsigned int i, compile_options;
char profile[7];
unsigned int i;
char *messages;
int ret;
@ -408,6 +410,30 @@ static bool compile_shader(const struct vulkan_shader_runner *runner, const char
info.target_type = VKD3D_SHADER_TARGET_DXBC_TPF;
info.log_level = VKD3D_SHADER_LOG_WARNING;
info.options = options;
info.option_count = 0;
compile_options = runner->r.compile_options;
if (compile_options)
{
struct vkd3d_shader_compile_option *option;
if (compile_options & (D3DCOMPILE_PACK_MATRIX_ROW_MAJOR | D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR))
{
option = &options[info.option_count++];
option->name = VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_ORDER;
option->value = 0;
if (compile_options & D3DCOMPILE_PACK_MATRIX_ROW_MAJOR)
option->value |= VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_ROW_MAJOR;
if (compile_options & D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR)
option->value |= VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_COLUMN_MAJOR;
compile_options &= ~(D3DCOMPILE_PACK_MATRIX_ROW_MAJOR | D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR);
}
if (compile_options)
fatal_error("Unsupported compiler options %#x.\n", compile_options);
}
hlsl_info.entry_point = "main";
sprintf(profile, "%s_%s", type, shader_models[runner->r.minimum_shader_model]);
hlsl_info.profile = profile;