From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- tests/shader_runner.c | 26 ++++++++++++++++++++++++-- tests/shader_runner.h | 2 ++ tests/shader_runner_d3d11.c | 12 ++++++------ tests/shader_runner_d3d12.c | 2 +- tests/shader_runner_d3d9.c | 10 +++++----- tests/shader_runner_vulkan.c | 28 +++++++++++++++++++++++++++- 6 files changed, 65 insertions(+), 15 deletions(-)
diff --git a/tests/shader_runner.c b/tests/shader_runner.c index 89137355..1c52f494 100644 --- a/tests/shader_runner.c +++ b/tests/shader_runner.c @@ -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); @@ -766,7 +788,7 @@ static void compile_shader(struct shader_runner *runner, const char *source, siz };
sprintf(profile, "%s_%s", type, shader_models[runner->minimum_shader_model]); - hr = D3DCompile(source, len, NULL, NULL, NULL, "main", profile, 0, 0, &blob, &errors); + hr = D3DCompile(source, len, NULL, NULL, NULL, "main", profile, runner->compile_options, 0, &blob, &errors); hr = map_unidentified_hrs(hr); ok(hr == expect, "Got unexpected hr %#x.\n", hr); if (hr == S_OK) diff --git a/tests/shader_runner.h b/tests/shader_runner.h index 7a2498f4..0844943d 100644 --- a/tests/shader_runner.h +++ b/tests/shader_runner.h @@ -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 diff --git a/tests/shader_runner_d3d11.c b/tests/shader_runner_d3d11.c index 3907e785..25b585b1 100644 --- a/tests/shader_runner_d3d11.c +++ b/tests/shader_runner_d3d11.c @@ -72,7 +72,7 @@ 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) { ID3D10Blob *blob = NULL, *errors = NULL; char profile[7]; @@ -88,8 +88,8 @@ static ID3D10Blob *compile_shader(const char *source, const char *type, enum sha [SHADER_MODEL_5_1] = "5_1", };
- sprintf(profile, "%s_%s", type, shader_models[shader_model]); - hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main", profile, 0, 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) { @@ -475,7 +475,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), @@ -548,10 +548,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; diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c index 6765c5ce..c5ee0cd2 100644 --- a/tests/shader_runner_d3d12.c +++ b/tests/shader_runner_d3d12.c @@ -73,7 +73,7 @@ static ID3D10Blob *compile_shader(const struct d3d12_shader_runner *runner, cons };
sprintf(profile, "%s_%s", type, shader_models[runner->r.minimum_shader_model]); - hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main", profile, 0, 0, &blob, &errors); + hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main", profile, runner->r.compile_options, 0, &blob, &errors); ok(FAILED(hr) == !blob, "Got unexpected hr %#x, blob %p.\n", hr, blob); if (errors) { diff --git a/tests/shader_runner_d3d9.c b/tests/shader_runner_d3d9.c index 15a5ab3e..0c6d3788 100644 --- a/tests/shader_runner_d3d9.c +++ b/tests/shader_runner_d3d9.c @@ -56,7 +56,7 @@ 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]; @@ -68,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, 0, 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) { @@ -334,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; diff --git a/tests/shader_runner_vulkan.c b/tests/shader_runner_vulkan.c index ce9ac7e8..716b922c 100644 --- a/tests/shader_runner_vulkan.c +++ b/tests/shader_runner_vulkan.c @@ -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;