This is a bit clearer, and avoids colliding with other things named "context", e.g. struct test_context, or d3d11 device contexts.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- tests/shader_runner.c | 90 ++++++++++++++++++------------------- tests/shader_runner.h | 12 ++--- tests/shader_runner_d3d11.c | 20 ++++----- tests/shader_runner_d3d12.c | 20 ++++----- 4 files changed, 71 insertions(+), 71 deletions(-)
diff --git a/tests/shader_runner.c b/tests/shader_runner.c index 8cfdf052c..d68d7f186 100644 --- a/tests/shader_runner.c +++ b/tests/shader_runner.c @@ -99,7 +99,7 @@ static bool match_string(const char *line, const char *token, const char **const return true; }
-static void parse_require_directive(struct shader_context *context, const char *line) +static void parse_require_directive(struct shader_runner *runner, const char *line) { if (match_string(line, "shader model >=", &line)) { @@ -117,7 +117,7 @@ static void parse_require_directive(struct shader_context *context, const char * { if (match_string(line, model_strings[i], &line)) { - context->minimum_shader_model = i; + runner->minimum_shader_model = i; return; } } @@ -277,19 +277,19 @@ static void parse_texture_directive(struct texture_params *texture, const char * } }
-static void set_uniforms(struct shader_context *context, size_t offset, size_t count, const void *uniforms) +static void set_uniforms(struct shader_runner *runner, size_t offset, size_t count, const void *uniforms) { - context->uniform_count = align(max(context->uniform_count, offset + count), 4); - vkd3d_array_reserve((void **)&context->uniforms, &context->uniform_capacity, - context->uniform_count, sizeof(*context->uniforms)); - memcpy(context->uniforms + offset, uniforms, count * sizeof(*context->uniforms)); + runner->uniform_count = align(max(runner->uniform_count, offset + count), 4); + vkd3d_array_reserve((void **)&runner->uniforms, &runner->uniform_capacity, + runner->uniform_count, sizeof(*runner->uniforms)); + memcpy(runner->uniforms + offset, uniforms, count * sizeof(*runner->uniforms)); }
-static void parse_test_directive(struct shader_context *context, const char *line) +static void parse_test_directive(struct shader_runner *runner, const char *line) { if (match_string(line, "draw quad", &line)) { - context->ops->draw_quad(context); + runner->ops->draw_quad(runner); } else if (match_string(line, "probe all rgba", &line)) { @@ -304,7 +304,7 @@ static void parse_test_directive(struct shader_context *context, const char *lin if (ret < 5) ulps = 0;
- context->ops->probe_vec4(context, &rect, &v, ulps); + runner->ops->probe_vec4(runner, &rect, &v, ulps); } else if (match_string(line, "probe rect rgba", &line)) { @@ -324,7 +324,7 @@ static void parse_test_directive(struct shader_context *context, const char *lin rect.right = x + w; rect.top = y; rect.bottom = y + h; - context->ops->probe_vec4(context, &rect, &v, ulps); + runner->ops->probe_vec4(runner, &rect, &v, ulps); } else if (match_string(line, "probe rgba", &line)) { @@ -343,7 +343,7 @@ static void parse_test_directive(struct shader_context *context, const char *lin rect.right = x + 1; rect.top = y; rect.bottom = y + 1; - context->ops->probe_vec4(context, &rect, &v, ulps); + runner->ops->probe_vec4(runner, &rect, &v, ulps); } else if (match_string(line, "uniform", &line)) { @@ -359,7 +359,7 @@ static void parse_test_directive(struct shader_context *context, const char *lin
if (sscanf(line, "%f %f %f %f", &v.x, &v.y, &v.z, &v.w) < 4) fatal_error("Malformed float4 constant '%s'.\n", line); - set_uniforms(context, offset, 4, &v); + set_uniforms(runner, offset, 4, &v); } else if (match_string(line, "float", &line)) { @@ -367,7 +367,7 @@ static void parse_test_directive(struct shader_context *context, const char *lin
if (sscanf(line, "%f", &f) < 1) fatal_error("Malformed float constant '%s'.\n", line); - set_uniforms(context, offset, 1, &f); + set_uniforms(runner, offset, 1, &f); } else if (match_string(line, "int4", &line)) { @@ -375,7 +375,7 @@ static void parse_test_directive(struct shader_context *context, const char *lin
if (sscanf(line, "%d %d %d %d", &v[0], &v[1], &v[2], &v[3]) < 4) fatal_error("Malformed int4 constant '%s'.\n", line); - set_uniforms(context, offset, 4, v); + set_uniforms(runner, offset, 4, v); } else if (match_string(line, "int", &line)) { @@ -383,7 +383,7 @@ static void parse_test_directive(struct shader_context *context, const char *lin
if (sscanf(line, "%i", &i) < 1) fatal_error("Malformed int constant '%s'.\n", line); - set_uniforms(context, offset, 1, &i); + set_uniforms(runner, offset, 1, &i); } else if (match_string(line, "uint", &line)) { @@ -391,7 +391,7 @@ static void parse_test_directive(struct shader_context *context, const char *lin
if (sscanf(line, "%u", &u) < 1) fatal_error("Malformed uint constant '%s'.\n", line); - set_uniforms(context, offset, 1, &u); + set_uniforms(runner, offset, 1, &u); } } else @@ -400,14 +400,14 @@ static void parse_test_directive(struct shader_context *context, const char *lin } }
-static struct sampler *get_sampler(struct shader_context *context, unsigned int slot) +static struct sampler *get_sampler(struct shader_runner *runner, unsigned int slot) { struct sampler *sampler; size_t i;
- for (i = 0; i < context->sampler_count; ++i) + for (i = 0; i < runner->sampler_count; ++i) { - sampler = &context->samplers[i]; + sampler = &runner->samplers[i];
if (sampler->slot == slot) return sampler; @@ -416,25 +416,25 @@ static struct sampler *get_sampler(struct shader_context *context, unsigned int return NULL; }
-static void set_texture(struct shader_context *context, struct texture *texture) +static void set_texture(struct shader_runner *runner, struct texture *texture) { size_t i;
- for (i = 0; i < context->texture_count; ++i) + for (i = 0; i < runner->texture_count; ++i) { - if (context->textures[i]->slot == texture->slot) + if (runner->textures[i]->slot == texture->slot) { - context->ops->destroy_texture(context, context->textures[i]); - context->textures[i] = texture; + runner->ops->destroy_texture(runner, runner->textures[i]); + runner->textures[i] = texture; return; } }
- context->textures = realloc(context->textures, (context->texture_count + 1) * sizeof(*context->textures)); - context->textures[context->texture_count++] = texture; + runner->textures = realloc(runner->textures, (runner->texture_count + 1) * sizeof(*runner->textures)); + runner->textures[runner->texture_count++] = texture; }
-void run_shader_tests(struct shader_context *context, int argc, char **argv, const struct shader_runner_ops *ops) +void run_shader_tests(struct shader_runner *runner, int argc, char **argv, const struct shader_runner_ops *ops) { size_t shader_source_size = 0, shader_source_len = 0; struct sampler *current_sampler = NULL; @@ -446,7 +446,7 @@ void run_shader_tests(struct shader_context *context, int argc, char **argv, con char line[256]; FILE *f;
- context->minimum_shader_model = SHADER_MODEL_2_0; + runner->minimum_shader_model = SHADER_MODEL_2_0;
for (i = 1; i < argc; ++i) { @@ -469,8 +469,8 @@ void run_shader_tests(struct shader_context *context, int argc, char **argv, con return; }
- memset(context, 0, sizeof(*context)); - context->ops = ops; + memset(runner, 0, sizeof(*runner)); + runner->ops = ops;
for (;;) { @@ -489,13 +489,13 @@ void run_shader_tests(struct shader_context *context, int argc, char **argv, con break;
case STATE_TEXTURE: - set_texture(context, context->ops->create_texture(context, ¤t_texture)); + set_texture(runner, runner->ops->create_texture(runner, ¤t_texture)); free(current_texture.data); break;
case STATE_SHADER_PIXEL: - free(context->ps_source); - context->ps_source = shader_source; + free(runner->ps_source); + runner->ps_source = shader_source; shader_source = NULL; shader_source_len = 0; shader_source_size = 0; @@ -599,15 +599,15 @@ void run_shader_tests(struct shader_context *context, int argc, char **argv, con { state = STATE_SAMPLER;
- if ((current_sampler = get_sampler(context, index))) + if ((current_sampler = get_sampler(runner, index))) { memset(current_sampler, 0, sizeof(*current_sampler)); } else { - context->samplers = realloc(context->samplers, - ++context->sampler_count * sizeof(*context->samplers)); - current_sampler = &context->samplers[context->sampler_count - 1]; + runner->samplers = realloc(runner->samplers, + ++runner->sampler_count * sizeof(*runner->samplers)); + current_sampler = &runner->samplers[runner->sampler_count - 1]; memset(current_sampler, 0, sizeof(*current_sampler)); } current_sampler->slot = index; @@ -664,7 +664,7 @@ void run_shader_tests(struct shader_context *context, int argc, char **argv, con }
case STATE_REQUIRE: - parse_require_directive(context, line); + parse_require_directive(runner, line); break;
case STATE_SAMPLER: @@ -676,19 +676,19 @@ void run_shader_tests(struct shader_context *context, int argc, char **argv, con break;
case STATE_TEST: - parse_test_directive(context, line); + parse_test_directive(runner, line); break; } } }
- free(context->ps_source); - for (i = 0; i < context->texture_count; ++i) + free(runner->ps_source); + for (i = 0; i < runner->texture_count; ++i) { - if (context->textures[i]) - context->ops->destroy_texture(context, context->textures[i]); + if (runner->textures[i]) + runner->ops->destroy_texture(runner, runner->textures[i]); } - free(context->textures); + free(runner->textures);
fclose(f);
diff --git a/tests/shader_runner.h b/tests/shader_runner.h index 6958191d9..84c170164 100644 --- a/tests/shader_runner.h +++ b/tests/shader_runner.h @@ -65,7 +65,7 @@ struct texture unsigned int slot; };
-struct shader_context +struct shader_runner { const struct shader_runner_ops *ops;
@@ -84,15 +84,15 @@ struct shader_context
struct shader_runner_ops { - struct texture *(*create_texture)(struct shader_context *context, const struct texture_params *params); - void (*destroy_texture)(struct shader_context *context, struct texture *texture); - void (*draw_quad)(struct shader_context *context); - void (*probe_vec4)(struct shader_context *context, const RECT *rect, const struct vec4 *v, unsigned int ulps); + struct texture *(*create_texture)(struct shader_runner *runner, const struct texture_params *params); + void (*destroy_texture)(struct shader_runner *runner, struct texture *texture); + void (*draw_quad)(struct shader_runner *runner); + void (*probe_vec4)(struct shader_runner *runner, const RECT *rect, const struct vec4 *v, unsigned int ulps); };
void fatal_error(const char *format, ...) VKD3D_NORETURN VKD3D_PRINTF_FUNC(1, 2);
-void run_shader_tests(struct shader_context *context, int argc, char **argv, const struct shader_runner_ops *ops); +void run_shader_tests(struct shader_runner *runner, int argc, char **argv, const struct shader_runner_ops *ops);
#ifdef _WIN32 void run_shader_tests_d3d11(int argc, char **argv); diff --git a/tests/shader_runner_d3d11.c b/tests/shader_runner_d3d11.c index 6290ac290..f84a3be83 100644 --- a/tests/shader_runner_d3d11.c +++ b/tests/shader_runner_d3d11.c @@ -53,7 +53,7 @@ static struct d3d11_texture *d3d11_texture(struct texture *t)
struct d3d11_shader_context { - struct shader_context c; + struct shader_runner c;
ID3D11Device *device; HWND window; @@ -65,9 +65,9 @@ struct d3d11_shader_context ID3D11VertexShader *vs; };
-static struct d3d11_shader_context *d3d11_shader_context(struct shader_context *c) +static struct d3d11_shader_context *d3d11_shader_context(struct shader_runner *r) { - return CONTAINING_RECORD(c, struct d3d11_shader_context, c); + return CONTAINING_RECORD(r, struct d3d11_shader_context, c); }
static bool enable_debug_layer; @@ -359,9 +359,9 @@ static ID3D11Buffer *create_buffer(ID3D11Device *device, unsigned int bind_flags return buffer; }
-static struct texture *d3d11_runner_create_texture(struct shader_context *c, const struct texture_params *params) +static struct texture *d3d11_runner_create_texture(struct shader_runner *r, const struct texture_params *params) { - struct d3d11_shader_context *context = d3d11_shader_context(c); + struct d3d11_shader_context *context = d3d11_shader_context(r); ID3D11Device *device = context->device; D3D11_SUBRESOURCE_DATA resource_data; D3D11_TEXTURE2D_DESC desc = {0}; @@ -394,7 +394,7 @@ static struct texture *d3d11_runner_create_texture(struct shader_context *c, con return &texture->t; }
-static void d3d11_runner_destroy_texture(struct shader_context *c, struct texture *t) +static void d3d11_runner_destroy_texture(struct shader_runner *r, struct texture *t) { struct d3d11_texture *texture = d3d11_texture(t);
@@ -403,7 +403,7 @@ static void d3d11_runner_destroy_texture(struct shader_context *c, struct textur free(texture); }
-static void d3d11_runner_draw_quad(struct shader_context *c) +static void d3d11_runner_draw_quad(struct shader_runner *r) { static const char vs_source[] = "void main(uint id : SV_VertexID, out float4 position : SV_Position)\n" @@ -412,7 +412,7 @@ static void d3d11_runner_draw_quad(struct shader_context *c) " position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);\n" "}";
- struct d3d11_shader_context *context = d3d11_shader_context(c); + struct d3d11_shader_context *context = d3d11_shader_context(r); ID3D11Device *device = context->device; ID3D11Buffer *cb = NULL; ID3D11PixelShader *ps; @@ -561,9 +561,9 @@ static void check_readback_data_vec4(struct resource_readback *rb, got.x, got.y, got.z, got.w, expected->x, expected->y, expected->z, expected->w, x, y); }
-static void d3d11_runner_probe_vec4(struct shader_context *c, const RECT *rect, const struct vec4 *v, unsigned int ulps) +static void d3d11_runner_probe_vec4(struct shader_runner *r, const RECT *rect, const struct vec4 *v, unsigned int ulps) { - struct d3d11_shader_context *context = d3d11_shader_context(c); + struct d3d11_shader_context *context = d3d11_shader_context(r); struct resource_readback rb;
init_readback(context, &rb); diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c index 571efeacd..eec9582c7 100644 --- a/tests/shader_runner_d3d12.c +++ b/tests/shader_runner_d3d12.c @@ -40,16 +40,16 @@ static struct d3d12_texture *d3d12_texture(struct texture *t)
struct d3d12_shader_context { - struct shader_context c; + struct shader_runner c;
struct test_context test_context;
ID3D12DescriptorHeap *heap; };
-static struct d3d12_shader_context *d3d12_shader_context(struct shader_context *c) +static struct d3d12_shader_context *d3d12_shader_context(struct shader_runner *r) { - return CONTAINING_RECORD(c, struct d3d12_shader_context, c); + return CONTAINING_RECORD(r, struct d3d12_shader_context, c); }
static ID3D10Blob *compile_shader(const char *source, enum shader_model shader_model) @@ -80,9 +80,9 @@ static ID3D10Blob *compile_shader(const char *source, enum shader_model shader_m
#define MAX_RESOURCE_DESCRIPTORS 256
-static struct texture *d3d12_runner_create_texture(struct shader_context *c, const struct texture_params *params) +static struct texture *d3d12_runner_create_texture(struct shader_runner *r, const struct texture_params *params) { - struct d3d12_shader_context *context = d3d12_shader_context(c); + struct d3d12_shader_context *context = d3d12_shader_context(r); struct test_context *test_context = &context->test_context; ID3D12Device *device = test_context->device; D3D12_SUBRESOURCE_DATA resource_data; @@ -113,7 +113,7 @@ static struct texture *d3d12_runner_create_texture(struct shader_context *c, con return &texture->t; }
-static void d3d12_runner_destroy_texture(struct shader_context *c, struct texture *t) +static void d3d12_runner_destroy_texture(struct shader_runner *r, struct texture *t) { struct d3d12_texture *texture = d3d12_texture(t);
@@ -121,9 +121,9 @@ static void d3d12_runner_destroy_texture(struct shader_context *c, struct textur free(texture); }
-static void d3d12_runner_draw_quad(struct shader_context *c) +static void d3d12_runner_draw_quad(struct shader_runner *r) { - struct d3d12_shader_context *context = d3d12_shader_context(c); + struct d3d12_shader_context *context = d3d12_shader_context(r); struct test_context *test_context = &context->test_context;
ID3D12GraphicsCommandList *command_list = test_context->list; @@ -243,10 +243,10 @@ static void d3d12_runner_draw_quad(struct shader_context *c) reset_command_list(command_list, test_context->allocator); }
-static void d3d12_runner_probe_vec4(struct shader_context *c, +static void d3d12_runner_probe_vec4(struct shader_runner *r, const RECT *rect, const struct vec4 *v, unsigned int ulps) { - struct d3d12_shader_context *context = d3d12_shader_context(c); + struct d3d12_shader_context *context = d3d12_shader_context(r); struct test_context *test_context = &context->test_context; struct resource_readback rb;
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- tests/shader_runner_d3d12.c | 62 ++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 31 deletions(-)
diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c index eec9582c7..a6db29ff6 100644 --- a/tests/shader_runner_d3d12.c +++ b/tests/shader_runner_d3d12.c @@ -38,18 +38,18 @@ static struct d3d12_texture *d3d12_texture(struct texture *t) return CONTAINING_RECORD(t, struct d3d12_texture, t); }
-struct d3d12_shader_context +struct d3d12_shader_runner { - struct shader_runner c; + struct shader_runner r;
struct test_context test_context;
ID3D12DescriptorHeap *heap; };
-static struct d3d12_shader_context *d3d12_shader_context(struct shader_runner *r) +static struct d3d12_shader_runner *d3d12_shader_runner(struct shader_runner *r) { - return CONTAINING_RECORD(r, struct d3d12_shader_context, c); + return CONTAINING_RECORD(r, struct d3d12_shader_runner, r); }
static ID3D10Blob *compile_shader(const char *source, enum shader_model shader_model) @@ -82,14 +82,14 @@ static ID3D10Blob *compile_shader(const char *source, enum shader_model shader_m
static struct texture *d3d12_runner_create_texture(struct shader_runner *r, const struct texture_params *params) { - struct d3d12_shader_context *context = d3d12_shader_context(r); - struct test_context *test_context = &context->test_context; + struct d3d12_shader_runner *runner = d3d12_shader_runner(r); + struct test_context *test_context = &runner->test_context; ID3D12Device *device = test_context->device; D3D12_SUBRESOURCE_DATA resource_data; struct d3d12_texture *texture;
- if (!context->heap) - context->heap = create_gpu_descriptor_heap(device, + if (!runner->heap) + runner->heap = create_gpu_descriptor_heap(device, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, MAX_RESOURCE_DESCRIPTORS);
if (params->slot >= MAX_RESOURCE_DESCRIPTORS) @@ -108,7 +108,7 @@ static struct texture *d3d12_runner_create_texture(struct shader_runner *r, cons transition_resource_state(test_context->list, texture->resource, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE); ID3D12Device_CreateShaderResourceView(device, texture->resource, - NULL, get_cpu_descriptor_handle(test_context, context->heap, params->slot)); + NULL, get_cpu_descriptor_handle(test_context, runner->heap, params->slot));
return &texture->t; } @@ -123,8 +123,8 @@ static void d3d12_runner_destroy_texture(struct shader_runner *r, struct texture
static void d3d12_runner_draw_quad(struct shader_runner *r) { - struct d3d12_shader_context *context = d3d12_shader_context(r); - struct test_context *test_context = &context->test_context; + struct d3d12_shader_runner *runner = d3d12_shader_runner(r); + struct test_context *test_context = &runner->test_context;
ID3D12GraphicsCommandList *command_list = test_context->list; D3D12_ROOT_SIGNATURE_DESC root_signature_desc = {0}; @@ -140,7 +140,7 @@ static void d3d12_runner_draw_quad(struct shader_runner *r) HRESULT hr; size_t i;
- if (!(ps_code = compile_shader(context->c.ps_source, context->c.minimum_shader_model))) + if (!(ps_code = compile_shader(runner->r.ps_source, runner->r.minimum_shader_model))) return;
root_signature_desc.NumParameters = 0; @@ -148,20 +148,20 @@ static void d3d12_runner_draw_quad(struct shader_runner *r) root_signature_desc.NumStaticSamplers = 0; root_signature_desc.pStaticSamplers = static_samplers;
- if (context->c.uniform_count) + if (runner->r.uniform_count) { uniform_index = root_signature_desc.NumParameters++; root_param = &root_params[uniform_index]; root_param->ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS; root_param->Constants.ShaderRegister = 0; root_param->Constants.RegisterSpace = 0; - root_param->Constants.Num32BitValues = context->c.uniform_count; + root_param->Constants.Num32BitValues = runner->r.uniform_count; root_param->ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; }
- for (i = 0; i < context->c.texture_count; ++i) + for (i = 0; i < runner->r.texture_count; ++i) { - struct d3d12_texture *texture = d3d12_texture(context->c.textures[i]); + struct d3d12_texture *texture = d3d12_texture(runner->r.textures[i]); D3D12_DESCRIPTOR_RANGE *range;
range = &texture->descriptor_range; @@ -182,10 +182,10 @@ static void d3d12_runner_draw_quad(struct shader_runner *r)
assert(root_signature_desc.NumParameters <= ARRAY_SIZE(root_params));
- for (i = 0; i < context->c.sampler_count; ++i) + for (i = 0; i < runner->r.sampler_count; ++i) { D3D12_STATIC_SAMPLER_DESC *sampler_desc = &static_samplers[root_signature_desc.NumStaticSamplers++]; - const struct sampler *sampler = &context->c.samplers[i]; + const struct sampler *sampler = &runner->r.samplers[i];
memset(sampler_desc, 0, sizeof(*sampler_desc)); sampler_desc->Filter = sampler->filter; @@ -214,15 +214,15 @@ static void d3d12_runner_draw_quad(struct shader_runner *r) test_context->pso[test_context->pso_count++] = pso;
ID3D12GraphicsCommandList_SetGraphicsRootSignature(command_list, test_context->root_signature); - if (context->c.uniform_count) + if (runner->r.uniform_count) ID3D12GraphicsCommandList_SetGraphicsRoot32BitConstants(command_list, uniform_index, - context->c.uniform_count, context->c.uniforms, 0); - for (i = 0; i < context->c.texture_count; ++i) + runner->r.uniform_count, runner->r.uniforms, 0); + for (i = 0; i < runner->r.texture_count; ++i) { - struct d3d12_texture *texture = d3d12_texture(context->c.textures[i]); + struct d3d12_texture *texture = d3d12_texture(runner->r.textures[i]);
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(command_list, texture->root_index, - get_gpu_descriptor_handle(test_context, context->heap, texture->t.slot)); + get_gpu_descriptor_handle(test_context, runner->heap, texture->t.slot)); }
ID3D12GraphicsCommandList_OMSetRenderTargets(command_list, 1, &test_context->rtv, false, NULL); @@ -246,8 +246,8 @@ static void d3d12_runner_draw_quad(struct shader_runner *r) static void d3d12_runner_probe_vec4(struct shader_runner *r, const RECT *rect, const struct vec4 *v, unsigned int ulps) { - struct d3d12_shader_context *context = d3d12_shader_context(r); - struct test_context *test_context = &context->test_context; + struct d3d12_shader_runner *runner = d3d12_shader_runner(r); + struct test_context *test_context = &runner->test_context; struct resource_readback rb;
get_texture_readback_with_command_list(test_context->render_target, 0, &rb, @@ -274,16 +274,16 @@ void run_shader_tests_d3d12(int argc, char **argv) .no_root_signature = true, .rt_format = DXGI_FORMAT_R32G32B32A32_FLOAT, }; - struct d3d12_shader_context context = {0}; + struct d3d12_shader_runner runner = {0};
parse_args(argc, argv); enable_d3d12_debug_layer(argc, argv); init_adapter_info(); - init_test_context(&context.test_context, &desc); + init_test_context(&runner.test_context, &desc);
- run_shader_tests(&context.c, argc, argv, &d3d12_runner_ops); + run_shader_tests(&runner.r, argc, argv, &d3d12_runner_ops);
- if (context.heap) - ID3D12DescriptorHeap_Release(context.heap); - destroy_test_context(&context.test_context); + if (runner.heap) + ID3D12DescriptorHeap_Release(runner.heap); + destroy_test_context(&runner.test_context); }
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- tests/shader_runner_d3d11.c | 114 ++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 57 deletions(-)
diff --git a/tests/shader_runner_d3d11.c b/tests/shader_runner_d3d11.c index f84a3be83..0a8e0efe7 100644 --- a/tests/shader_runner_d3d11.c +++ b/tests/shader_runner_d3d11.c @@ -51,9 +51,9 @@ static struct d3d11_texture *d3d11_texture(struct texture *t) return CONTAINING_RECORD(t, struct d3d11_texture, t); }
-struct d3d11_shader_context +struct d3d11_shader_runner { - struct shader_runner c; + struct shader_runner r;
ID3D11Device *device; HWND window; @@ -65,9 +65,9 @@ struct d3d11_shader_context ID3D11VertexShader *vs; };
-static struct d3d11_shader_context *d3d11_shader_context(struct shader_runner *r) +static struct d3d11_shader_runner *d3d11_shader_runner(struct shader_runner *r) { - return CONTAINING_RECORD(r, struct d3d11_shader_context, c); + return CONTAINING_RECORD(r, struct d3d11_shader_runner, r); }
static bool enable_debug_layer; @@ -264,7 +264,7 @@ static IDXGISwapChain *create_swapchain(ID3D11Device *device, HWND window) return swapchain; }
-static BOOL init_test_context(struct d3d11_shader_context *context) +static BOOL init_test_context(struct d3d11_shader_runner *runner) { const D3D11_TEXTURE2D_DESC texture_desc = { @@ -282,9 +282,9 @@ static BOOL init_test_context(struct d3d11_shader_context *context) HRESULT hr; RECT rect;
- memset(context, 0, sizeof(*context)); + memset(runner, 0, sizeof(*runner));
- if (!(context->device = create_device())) + if (!(runner->device = create_device())) { skip("Failed to create device.\n"); return FALSE; @@ -294,19 +294,19 @@ static BOOL init_test_context(struct d3d11_shader_context *context) rt_height = 480; SetRect(&rect, 0, 0, rt_width, rt_height); AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE); - context->window = CreateWindowA("static", "d3dcompiler_test", WS_OVERLAPPEDWINDOW, + runner->window = CreateWindowA("static", "d3dcompiler_test", WS_OVERLAPPEDWINDOW, 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL); - context->swapchain = create_swapchain(context->device, context->window); + runner->swapchain = create_swapchain(runner->device, runner->window);
- hr = ID3D11Device_CreateTexture2D(context->device, &texture_desc, NULL, &context->rt); + hr = ID3D11Device_CreateTexture2D(runner->device, &texture_desc, NULL, &runner->rt); ok(hr == S_OK, "Failed to create texture, hr %#lx.\n", hr);
- hr = ID3D11Device_CreateRenderTargetView(context->device, (ID3D11Resource *)context->rt, NULL, &context->rtv); + hr = ID3D11Device_CreateRenderTargetView(runner->device, (ID3D11Resource *)runner->rt, NULL, &runner->rtv); ok(hr == S_OK, "Failed to create rendertarget view, hr %#lx.\n", hr);
- ID3D11Device_GetImmediateContext(context->device, &context->immediate_context); + ID3D11Device_GetImmediateContext(runner->device, &runner->immediate_context);
- ID3D11DeviceContext_OMSetRenderTargets(context->immediate_context, 1, &context->rtv, NULL); + ID3D11DeviceContext_OMSetRenderTargets(runner->immediate_context, 1, &runner->rtv, NULL);
vp.TopLeftX = 0.0f; vp.TopLeftY = 0.0f; @@ -314,25 +314,25 @@ static BOOL init_test_context(struct d3d11_shader_context *context) vp.Height = rt_height; vp.MinDepth = 0.0f; vp.MaxDepth = 1.0f; - ID3D11DeviceContext_RSSetViewports(context->immediate_context, 1, &vp); + ID3D11DeviceContext_RSSetViewports(runner->immediate_context, 1, &vp);
return TRUE; }
-static void destroy_test_context(struct d3d11_shader_context *context) +static void destroy_test_context(struct d3d11_shader_runner *runner) { ULONG ref;
- if (context->vs) - ID3D11VertexShader_Release(context->vs); + if (runner->vs) + ID3D11VertexShader_Release(runner->vs);
- ID3D11DeviceContext_Release(context->immediate_context); - ID3D11RenderTargetView_Release(context->rtv); - ID3D11Texture2D_Release(context->rt); - IDXGISwapChain_Release(context->swapchain); - DestroyWindow(context->window); + ID3D11DeviceContext_Release(runner->immediate_context); + ID3D11RenderTargetView_Release(runner->rtv); + ID3D11Texture2D_Release(runner->rt); + IDXGISwapChain_Release(runner->swapchain); + DestroyWindow(runner->window);
- ref = ID3D11Device_Release(context->device); + ref = ID3D11Device_Release(runner->device); ok(!ref, "Device has %lu references left.\n", ref); }
@@ -361,8 +361,8 @@ static ID3D11Buffer *create_buffer(ID3D11Device *device, unsigned int bind_flags
static struct texture *d3d11_runner_create_texture(struct shader_runner *r, const struct texture_params *params) { - struct d3d11_shader_context *context = d3d11_shader_context(r); - ID3D11Device *device = context->device; + struct d3d11_shader_runner *runner = d3d11_shader_runner(r); + ID3D11Device *device = runner->device; D3D11_SUBRESOURCE_DATA resource_data; D3D11_TEXTURE2D_DESC desc = {0}; struct d3d11_texture *texture; @@ -412,8 +412,8 @@ static void d3d11_runner_draw_quad(struct shader_runner *r) " position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);\n" "}";
- struct d3d11_shader_context *context = d3d11_shader_context(r); - ID3D11Device *device = context->device; + struct d3d11_shader_runner *runner = d3d11_shader_runner(r); + ID3D11Device *device = runner->device; ID3D11Buffer *cb = NULL; ID3D11PixelShader *ps; ID3D10Blob *ps_code; @@ -429,15 +429,15 @@ static void d3d11_runner_draw_quad(struct shader_runner *r) [SHADER_MODEL_5_1] = "ps_5_1", };
- if (!(ps_code = compile_shader(context->c.ps_source, ps_profiles[context->c.minimum_shader_model]))) + if (!(ps_code = compile_shader(runner->r.ps_source, ps_profiles[runner->r.minimum_shader_model]))) return;
- if (!context->vs) + if (!runner->vs) { ID3D10Blob *vs_code = compile_shader(vs_source, "vs_4_0");
hr = ID3D11Device_CreateVertexShader(device, ID3D10Blob_GetBufferPointer(vs_code), - ID3D10Blob_GetBufferSize(vs_code), NULL, &context->vs); + ID3D10Blob_GetBufferSize(vs_code), NULL, &runner->vs); ok(hr == S_OK, "Failed to create vertex shader, hr %#lx.\n", hr); ID3D10Blob_Release(vs_code); } @@ -446,23 +446,23 @@ static void d3d11_runner_draw_quad(struct shader_runner *r) ID3D10Blob_GetBufferSize(ps_code), NULL, &ps); ok(hr == S_OK, "Failed to create pixel shader, hr %#lx.\n", hr);
- if (context->c.uniform_count) + if (runner->r.uniform_count) { cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, - context->c.uniform_count * sizeof(*context->c.uniforms), context->c.uniforms); - ID3D11DeviceContext_PSSetConstantBuffers(context->immediate_context, 0, 1, &cb); + runner->r.uniform_count * sizeof(*runner->r.uniforms), runner->r.uniforms); + ID3D11DeviceContext_PSSetConstantBuffers(runner->immediate_context, 0, 1, &cb); }
- for (i = 0; i < context->c.texture_count; ++i) + for (i = 0; i < runner->r.texture_count; ++i) { - struct d3d11_texture *texture = d3d11_texture(context->c.textures[i]); + struct d3d11_texture *texture = d3d11_texture(runner->r.textures[i]);
- ID3D11DeviceContext_PSSetShaderResources(context->immediate_context, texture->t.slot, 1, &texture->srv); + ID3D11DeviceContext_PSSetShaderResources(runner->immediate_context, texture->t.slot, 1, &texture->srv); }
- for (i = 0; i < context->c.sampler_count; ++i) + for (i = 0; i < runner->r.sampler_count; ++i) { - struct sampler *sampler = &context->c.samplers[i]; + struct sampler *sampler = &runner->r.samplers[i]; ID3D11SamplerState *d3d11_sampler; D3D11_SAMPLER_DESC desc = {0};
@@ -477,15 +477,15 @@ static void d3d11_runner_draw_quad(struct shader_runner *r)
hr = ID3D11Device_CreateSamplerState(device, &desc, &d3d11_sampler); ok(hr == S_OK, "Failed to create sampler state, hr %#lx.\n", hr); - ID3D11DeviceContext_PSSetSamplers(context->immediate_context, sampler->slot, 1, &d3d11_sampler); + ID3D11DeviceContext_PSSetSamplers(runner->immediate_context, sampler->slot, 1, &d3d11_sampler); ID3D11SamplerState_Release(d3d11_sampler); }
- ID3D11DeviceContext_IASetPrimitiveTopology(context->immediate_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); - ID3D11DeviceContext_VSSetShader(context->immediate_context, context->vs, NULL, 0); - ID3D11DeviceContext_PSSetShader(context->immediate_context, ps, NULL, 0); + ID3D11DeviceContext_IASetPrimitiveTopology(runner->immediate_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + ID3D11DeviceContext_VSSetShader(runner->immediate_context, runner->vs, NULL, 0); + ID3D11DeviceContext_PSSetShader(runner->immediate_context, ps, NULL, 0);
- ID3D11DeviceContext_Draw(context->immediate_context, 3, 0); + ID3D11DeviceContext_Draw(runner->immediate_context, 3, 0);
ID3D11PixelShader_Release(ps); if (cb) @@ -500,30 +500,30 @@ struct resource_readback D3D11_MAPPED_SUBRESOURCE map_desc; };
-static void init_readback(struct d3d11_shader_context *context, struct resource_readback *rb) +static void init_readback(struct d3d11_shader_runner *runner, struct resource_readback *rb) { D3D11_TEXTURE2D_DESC texture_desc; HRESULT hr;
- ID3D11Texture2D_GetDesc(context->rt, &texture_desc); + ID3D11Texture2D_GetDesc(runner->rt, &texture_desc); texture_desc.Usage = D3D11_USAGE_STAGING; texture_desc.BindFlags = 0; texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; texture_desc.MiscFlags = 0; - hr = ID3D11Device_CreateTexture2D(context->device, &texture_desc, NULL, (ID3D11Texture2D **)&rb->resource); + hr = ID3D11Device_CreateTexture2D(runner->device, &texture_desc, NULL, (ID3D11Texture2D **)&rb->resource); ok(hr == S_OK, "Failed to create texture, hr %#lx.\n", hr);
- ID3D11DeviceContext_CopyResource(context->immediate_context, rb->resource, (ID3D11Resource *)context->rt); - hr = ID3D11DeviceContext_Map(context->immediate_context, rb->resource, 0, D3D11_MAP_READ, 0, &rb->map_desc); + ID3D11DeviceContext_CopyResource(runner->immediate_context, rb->resource, (ID3D11Resource *)runner->rt); + hr = ID3D11DeviceContext_Map(runner->immediate_context, rb->resource, 0, D3D11_MAP_READ, 0, &rb->map_desc); ok(hr == S_OK, "Failed to map texture, hr %#lx.\n", hr);
rb->width = texture_desc.Width; rb->height = texture_desc.Height; }
-static void release_readback(struct d3d11_shader_context *context, struct resource_readback *rb) +static void release_readback(struct d3d11_shader_runner *runner, struct resource_readback *rb) { - ID3D11DeviceContext_Unmap(context->immediate_context, rb->resource, 0); + ID3D11DeviceContext_Unmap(runner->immediate_context, rb->resource, 0); ID3D11Resource_Release(rb->resource); }
@@ -563,12 +563,12 @@ static void check_readback_data_vec4(struct resource_readback *rb,
static void d3d11_runner_probe_vec4(struct shader_runner *r, const RECT *rect, const struct vec4 *v, unsigned int ulps) { - struct d3d11_shader_context *context = d3d11_shader_context(r); + struct d3d11_shader_runner *runner = d3d11_shader_runner(r); struct resource_readback rb;
- init_readback(context, &rb); + init_readback(runner, &rb); check_readback_data_vec4(&rb, rect, v, ulps); - release_readback(context, &rb); + release_readback(runner, &rb); }
static const struct shader_runner_ops d3d11_runner_ops = @@ -581,8 +581,8 @@ static const struct shader_runner_ops d3d11_runner_ops =
void run_shader_tests_d3d11(int argc, char **argv) { + struct d3d11_shader_runner runner; HMODULE dxgi_module, d3d11_module; - struct d3d11_shader_context context;
d3d11_module = LoadLibraryA("d3d11.dll"); dxgi_module = LoadLibraryA("dxgi.dll"); @@ -594,9 +594,9 @@ void run_shader_tests_d3d11(int argc, char **argv) parse_args(argc, argv); enable_d3d11_debug_layer(argc, argv); init_adapter_info(); - init_test_context(&context); - run_shader_tests(&context.c, argc, argv, &d3d11_runner_ops); - destroy_test_context(&context); + init_test_context(&runner); + run_shader_tests(&runner.r, argc, argv, &d3d11_runner_ops); + destroy_test_context(&runner); } FreeLibrary(d3d11_module); FreeLibrary(dxgi_module);
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- tests/shader_runner.c | 2 +- tests/shader_runner.h | 3 +++ tests/shader_runner_d3d11.c | 12 ++++++------ tests/shader_runner_d3d12.c | 4 ++-- 4 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/tests/shader_runner.c b/tests/shader_runner.c index d68d7f186..910e6ecdc 100644 --- a/tests/shader_runner.c +++ b/tests/shader_runner.c @@ -293,7 +293,7 @@ static void parse_test_directive(struct shader_runner *runner, const char *line) } else if (match_string(line, "probe all rgba", &line)) { - static const RECT rect = {0, 0, 640, 480}; + static const RECT rect = {0, 0, RENDER_TARGET_WIDTH, RENDER_TARGET_HEIGHT}; unsigned int ulps; struct vec4 v; int ret; diff --git a/tests/shader_runner.h b/tests/shader_runner.h index 84c170164..26fa2367b 100644 --- a/tests/shader_runner.h +++ b/tests/shader_runner.h @@ -24,6 +24,9 @@ #include "vkd3d_common.h" #include "utils.h"
+#define RENDER_TARGET_WIDTH 640 +#define RENDER_TARGET_HEIGHT 480 + enum shader_model { SHADER_MODEL_2_0, diff --git a/tests/shader_runner_d3d11.c b/tests/shader_runner_d3d11.c index 0a8e0efe7..884d86afe 100644 --- a/tests/shader_runner_d3d11.c +++ b/tests/shader_runner_d3d11.c @@ -241,8 +241,8 @@ static IDXGISwapChain *create_swapchain(ID3D11Device *device, HWND window) ok(hr == S_OK, "Failed to get factory, hr %#lx.\n", hr); IDXGIAdapter_Release(adapter);
- dxgi_desc.BufferDesc.Width = 640; - dxgi_desc.BufferDesc.Height = 480; + dxgi_desc.BufferDesc.Width = RENDER_TARGET_WIDTH; + dxgi_desc.BufferDesc.Height = RENDER_TARGET_HEIGHT; dxgi_desc.BufferDesc.RefreshRate.Numerator = 60; dxgi_desc.BufferDesc.RefreshRate.Denominator = 1; dxgi_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; @@ -268,8 +268,8 @@ static BOOL init_test_context(struct d3d11_shader_runner *runner) { const D3D11_TEXTURE2D_DESC texture_desc = { - .Width = 640, - .Height = 480, + .Width = RENDER_TARGET_WIDTH, + .Height = RENDER_TARGET_HEIGHT, .MipLevels = 1, .ArraySize = 1, .Format = DXGI_FORMAT_R32G32B32A32_FLOAT, @@ -290,8 +290,8 @@ static BOOL init_test_context(struct d3d11_shader_runner *runner) return FALSE; }
- rt_width = 640; - rt_height = 480; + rt_width = RENDER_TARGET_WIDTH; + rt_height = RENDER_TARGET_HEIGHT; SetRect(&rect, 0, 0, rt_width, rt_height); AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE); runner->window = CreateWindowA("static", "d3dcompiler_test", WS_OVERLAPPEDWINDOW, diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c index a6db29ff6..4f077b382 100644 --- a/tests/shader_runner_d3d12.c +++ b/tests/shader_runner_d3d12.c @@ -269,8 +269,8 @@ void run_shader_tests_d3d12(int argc, char **argv) { static const struct test_context_desc desc = { - .rt_width = 640, - .rt_height = 480, + .rt_width = RENDER_TARGET_WIDTH, + .rt_height = RENDER_TARGET_HEIGHT, .no_root_signature = true, .rt_format = DXGI_FORMAT_R32G32B32A32_FLOAT, };
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- tests/shader_runner_d3d11.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)
diff --git a/tests/shader_runner_d3d11.c b/tests/shader_runner_d3d11.c index 884d86afe..c077718c9 100644 --- a/tests/shader_runner_d3d11.c +++ b/tests/shader_runner_d3d11.c @@ -494,8 +494,6 @@ static void d3d11_runner_draw_quad(struct shader_runner *r)
struct resource_readback { - uint64_t width; - unsigned int height; ID3D11Resource *resource; D3D11_MAPPED_SUBRESOURCE map_desc; }; @@ -516,9 +514,6 @@ static void init_readback(struct d3d11_shader_runner *runner, struct resource_re ID3D11DeviceContext_CopyResource(runner->immediate_context, rb->resource, (ID3D11Resource *)runner->rt); hr = ID3D11DeviceContext_Map(runner->immediate_context, rb->resource, 0, D3D11_MAP_READ, 0, &rb->map_desc); ok(hr == S_OK, "Failed to map texture, hr %#lx.\n", hr); - - rb->width = texture_desc.Width; - rb->height = texture_desc.Height; }
static void release_readback(struct d3d11_shader_runner *runner, struct resource_readback *rb) @@ -535,17 +530,13 @@ static const struct vec4 *get_readback_vec4(struct resource_readback *rb, unsign static void check_readback_data_vec4(struct resource_readback *rb, const RECT *rect, const struct vec4 *expected, unsigned int max_diff) { - RECT r = {0, 0, rb->width, rb->height}; unsigned int x = 0, y = 0; struct vec4 got = {0}; bool all_match = true;
- if (rect) - r = *rect; - - for (y = r.top; y < r.bottom; ++y) + for (y = rect->top; y < rect->bottom; ++y) { - for (x = r.left; x < r.right; ++x) + for (x = rect->left; x < rect->right; ++x) { got = *get_readback_vec4(rb, x, y); if (!compare_vec4(&got, expected, max_diff))
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com