From d211160b8980652327ca01ddac992a26d48af6ed Mon Sep 17 00:00:00 2001 From: Conor McCarthy Date: Thu, 21 Sep 2023 14:32:25 +1000 Subject: [PATCH] tests/shader-runner: Replace immediate shader type strings with an enum. --- tests/shader_runner.c | 23 ++++++++++++++++++----- tests/shader_runner.h | 9 +++++++++ tests/shader_runner_d3d12.c | 10 +++++----- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/tests/shader_runner.c b/tests/shader_runner.c index 87502f01..bec08d7e 100644 --- a/tests/shader_runner.c +++ b/tests/shader_runner.c @@ -790,7 +790,20 @@ static HRESULT map_unidentified_hrs(HRESULT hr) return hr; } -static void compile_shader(struct shader_runner *runner, const char *source, size_t len, const char *type, HRESULT expect) +const char *shader_type_string(enum shader_type type) +{ + static const char *const shader_types[] = + { + [SHADER_TYPE_CS] = "cs", + [SHADER_TYPE_PS] = "ps", + [SHADER_TYPE_VS] = "vs", + }; + assert(type < ARRAY_SIZE(shader_types)); + return shader_types[type]; +} + +static void compile_shader(struct shader_runner *runner, const char *source, size_t len, enum shader_type type, + HRESULT expect) { ID3D10Blob *blob = NULL, *errors = NULL; char profile[7]; @@ -806,7 +819,7 @@ static void compile_shader(struct shader_runner *runner, const char *source, siz [SHADER_MODEL_5_1] = "5_1", }; - sprintf(profile, "%s_%s", type, shader_models[runner->minimum_shader_model]); + sprintf(profile, "%s_%s", shader_type_string(type), shader_models[runner->minimum_shader_model]); 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); @@ -918,7 +931,7 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_o if (!skip_tests) { todo_if (state == STATE_SHADER_COMPUTE_TODO) - compile_shader(runner, shader_source, shader_source_len, "cs", expect_hr); + compile_shader(runner, shader_source, shader_source_len, SHADER_TYPE_CS, expect_hr); } free(runner->cs_source); runner->cs_source = shader_source; @@ -932,7 +945,7 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_o if (!skip_tests) { todo_if (state == STATE_SHADER_PIXEL_TODO) - compile_shader(runner, shader_source, shader_source_len, "ps", expect_hr); + compile_shader(runner, shader_source, shader_source_len, SHADER_TYPE_PS, expect_hr); } free(runner->ps_source); runner->ps_source = shader_source; @@ -946,7 +959,7 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_o if (!skip_tests) { todo_if (state == STATE_SHADER_VERTEX_TODO) - compile_shader(runner, shader_source, shader_source_len, "vs", expect_hr); + compile_shader(runner, shader_source, shader_source_len, SHADER_TYPE_VS, expect_hr); } free(runner->vs_source); runner->vs_source = shader_source; diff --git a/tests/shader_runner.h b/tests/shader_runner.h index 0844943d..6591143e 100644 --- a/tests/shader_runner.h +++ b/tests/shader_runner.h @@ -38,6 +38,15 @@ enum shader_model SHADER_MODEL_5_1, }; +enum shader_type +{ + SHADER_TYPE_CS, + SHADER_TYPE_PS, + SHADER_TYPE_VS, +}; + +const char *shader_type_string(enum shader_type type); + enum texture_data_type { TEXTURE_DATA_FLOAT, diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c index d620f1e2..925bdca9 100644 --- a/tests/shader_runner_d3d12.c +++ b/tests/shader_runner_d3d12.c @@ -56,7 +56,7 @@ static struct d3d12_shader_runner *d3d12_shader_runner(struct shader_runner *r) return CONTAINING_RECORD(r, struct d3d12_shader_runner, r); } -static ID3D10Blob *compile_shader(const struct d3d12_shader_runner *runner, const char *source, const char *type) +static ID3D10Blob *compile_shader(const struct d3d12_shader_runner *runner, const char *source, enum shader_type type) { ID3D10Blob *blob = NULL, *errors = NULL; char profile[7]; @@ -72,7 +72,7 @@ static ID3D10Blob *compile_shader(const struct d3d12_shader_runner *runner, cons [SHADER_MODEL_5_1] = "5_1", }; - sprintf(profile, "%s_%s", type, shader_models[runner->r.minimum_shader_model]); + sprintf(profile, "%s_%s", shader_type_string(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(FAILED(hr) == !blob, "Got unexpected hr %#x, blob %p.\n", hr, blob); if (errors) @@ -310,7 +310,7 @@ static bool d3d12_runner_dispatch(struct shader_runner *r, unsigned int x, unsig HRESULT hr; size_t i; - cs_code = compile_shader(runner, runner->r.cs_source, "cs"); + cs_code = compile_shader(runner, runner->r.cs_source, SHADER_TYPE_CS); todo_if (runner->r.is_todo) ok(cs_code, "Failed to compile shader.\n"); if (!cs_code) return false; @@ -385,8 +385,8 @@ static bool d3d12_runner_draw(struct shader_runner *r, HRESULT hr; size_t i; - ps_code = compile_shader(runner, runner->r.ps_source, "ps"); - vs_code = compile_shader(runner, runner->r.vs_source, "vs"); + ps_code = compile_shader(runner, runner->r.ps_source, SHADER_TYPE_PS); + vs_code = compile_shader(runner, runner->r.vs_source, SHADER_TYPE_VS); todo_if (runner->r.is_todo) ok(ps_code && vs_code, "Failed to compile shaders.\n"); if (!ps_code || !vs_code)