Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- tests/shader_runner.c | 60 ++++++++++++++++------------------ tests/shader_runner.h | 11 +++++-- tests/shader_runner_d3d12.c | 65 ++++++++++++++++++++++--------------- 3 files changed, 75 insertions(+), 61 deletions(-)
diff --git a/tests/shader_runner.c b/tests/shader_runner.c index 74b70890f..aabae5ae0 100644 --- a/tests/shader_runner.c +++ b/tests/shader_runner.c @@ -71,12 +71,6 @@ static void VKD3D_NORETURN VKD3D_PRINTF_FUNC(1, 2) fatal_error(const char *forma exit(1); }
-static void free_texture(struct texture *texture) -{ - free(texture->data); - memset(texture, 0, sizeof(*texture)); -} - enum parse_state { STATE_NONE, @@ -135,7 +129,7 @@ static void parse_require_directive(struct shader_context *context, const char * } }
-static void parse_texture_format(struct texture *texture, const char *line) +static void parse_texture_format(struct texture_params *texture, const char *line) { static const struct { @@ -228,7 +222,7 @@ static void parse_sampler_directive(struct sampler *sampler, const char *line) } }
-static void parse_texture_directive(struct texture *texture, const char *line) +static void parse_texture_directive(struct texture_params *texture, const char *line) { int ret;
@@ -425,26 +419,29 @@ static struct sampler *get_sampler(struct shader_context *context, unsigned int return NULL; }
-static struct texture *get_texture(struct shader_context *context, unsigned int slot) +static void set_texture(struct shader_context *context, struct texture *texture) { - struct texture *texture; size_t i;
for (i = 0; i < context->texture_count; ++i) { - texture = &context->textures[i]; - if (texture->slot == slot) - return texture; + if (context->textures[i]->slot == texture->slot) + { + context->ops->destroy_texture(context, context->textures[i]); + context->textures[i] = texture; + return; + } }
- return NULL; + context->textures = realloc(context->textures, (context->texture_count + 1) * sizeof(*context->textures)); + context->textures[context->texture_count++] = texture; }
void run_shader_tests(struct shader_context *context, 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; - struct texture *current_texture = NULL; + struct texture_params current_texture; enum parse_state state = STATE_NONE; unsigned int i, line_number = 0; const char *filename = NULL; @@ -490,7 +487,11 @@ void run_shader_tests(struct shader_context *context, int argc, char **argv, con case STATE_REQUIRE: case STATE_SAMPLER: case STATE_TEST: + break; + case STATE_TEXTURE: + set_texture(context, context->ops->create_texture(context, ¤t_texture)); + free(current_texture.data); break;
case STATE_SHADER_PIXEL: @@ -623,21 +624,12 @@ void run_shader_tests(struct shader_context *context, int argc, char **argv, con { state = STATE_TEXTURE;
- if ((current_texture = get_texture(context, index))) - { - free_texture(current_texture); - } - else - { - context->textures = realloc(context->textures, - ++context->texture_count * sizeof(*context->textures)); - current_texture = &context->textures[context->texture_count - 1]; - memset(current_texture, 0, sizeof(*current_texture)); - } - current_texture->slot = index; - current_texture->format = DXGI_FORMAT_R32G32B32A32_FLOAT; - current_texture->data_type = TEXTURE_DATA_FLOAT; - current_texture->texel_size = 16; + memset(¤t_texture, 0, sizeof(current_texture)); + + current_texture.slot = index; + current_texture.format = DXGI_FORMAT_R32G32B32A32_FLOAT; + current_texture.data_type = TEXTURE_DATA_FLOAT; + current_texture.texel_size = 16; } else if (!strcmp(line, "[test]\n")) { @@ -684,7 +676,7 @@ void run_shader_tests(struct shader_context *context, int argc, char **argv, con break;
case STATE_TEXTURE: - parse_texture_directive(current_texture, line); + parse_texture_directive(¤t_texture, line); break;
case STATE_TEST: @@ -697,7 +689,11 @@ void run_shader_tests(struct shader_context *context, int argc, char **argv, con if (context->ps_code) ID3D10Blob_Release(context->ps_code); for (i = 0; i < context->texture_count; ++i) - free_texture(&context->textures[i]); + { + if (context->textures[i]) + context->ops->destroy_texture(context, context->textures[i]); + } + free(context->textures);
fclose(f); } diff --git a/tests/shader_runner.h b/tests/shader_runner.h index e9001eeda..c541b56e8 100644 --- a/tests/shader_runner.h +++ b/tests/shader_runner.h @@ -45,7 +45,7 @@ struct sampler D3D12_TEXTURE_ADDRESS_MODE u_address, v_address, w_address; };
-struct texture +struct texture_params { unsigned int slot;
@@ -55,6 +55,11 @@ struct texture unsigned int width, height; uint8_t *data; size_t data_size, data_capacity; +}; + +struct texture +{ + unsigned int slot;
D3D12_DESCRIPTOR_RANGE descriptor_range; ID3D12DescriptorHeap *heap; @@ -72,7 +77,7 @@ struct shader_context uint32_t *uniforms; size_t uniform_count;
- struct texture *textures; + struct texture **textures; size_t texture_count;
struct sampler *samplers; @@ -82,6 +87,8 @@ struct shader_context struct shader_runner_ops { ID3D10Blob *(*compile_shader)(struct shader_context *context, const char *source, enum shader_model minimum_shader_model); + 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); }; diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c index bb0288e83..94399aea6 100644 --- a/tests/shader_runner_d3d12.c +++ b/tests/shader_runner_d3d12.c @@ -62,6 +62,40 @@ static ID3D10Blob *d3d12_runner_compile_shader(struct shader_context *c, return blob; }
+static struct texture *d3d12_runner_create_texture(struct shader_context *c, const struct texture_params *params) +{ + struct d3d12_shader_context *context = d3d12_shader_context(c); + struct test_context *test_context = &context->test_context; + ID3D12Device *device = test_context->device; + D3D12_SUBRESOURCE_DATA resource_data; + struct texture *texture; + + texture = calloc(1, sizeof(*texture)); + + texture->slot = params->slot; + + texture->heap = create_gpu_descriptor_heap(device, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 1); + texture->resource = create_default_texture(device, params->width, params->height, + params->format, 0, D3D12_RESOURCE_STATE_COPY_DEST); + resource_data.pData = params->data; + resource_data.SlicePitch = resource_data.RowPitch = params->width * params->texel_size; + upload_texture_data(texture->resource, &resource_data, 1, test_context->queue, test_context->list); + reset_command_list(test_context->list, test_context->allocator); + 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, texture->heap, 0)); + + return texture; +} + +static void d3d12_runner_destroy_texture(struct shader_context *c, struct texture *texture) +{ + ID3D12DescriptorHeap_Release(texture->heap); + ID3D12Resource_Release(texture->resource); + free(texture); +} + static void d3d12_runner_draw_quad(struct shader_context *c) { struct d3d12_shader_context *context = d3d12_shader_context(c); @@ -99,10 +133,8 @@ static void d3d12_runner_draw_quad(struct shader_context *c)
for (i = 0; i < context->c.texture_count; ++i) { - struct texture *texture = &context->c.textures[i]; - D3D12_SUBRESOURCE_DATA resource_data; + struct texture *texture = context->c.textures[i]; D3D12_DESCRIPTOR_RANGE *range; - ID3D12Resource *resource;
range = &texture->descriptor_range;
@@ -118,20 +150,6 @@ static void d3d12_runner_draw_quad(struct shader_context *c) range->BaseShaderRegister = texture->slot; range->RegisterSpace = 0; range->OffsetInDescriptorsFromTableStart = 0; - - texture->heap = create_gpu_descriptor_heap(device, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 1); - resource = create_default_texture(device, texture->width, texture->height, - texture->format, 0, D3D12_RESOURCE_STATE_COPY_DEST); - resource_data.pData = texture->data; - resource_data.SlicePitch = resource_data.RowPitch = texture->width * texture->texel_size; - upload_texture_data(resource, &resource_data, 1, queue, command_list); - reset_command_list(command_list, test_context->allocator); - transition_resource_state(command_list, resource, D3D12_RESOURCE_STATE_COPY_DEST, - D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE); - ID3D12Device_CreateShaderResourceView(device, resource, - NULL, get_cpu_descriptor_handle(test_context, texture->heap, 0)); - - texture->resource = resource; }
assert(root_signature_desc.NumParameters <= ARRAY_SIZE(root_params)); @@ -170,7 +188,7 @@ static void d3d12_runner_draw_quad(struct shader_context *c) context->c.uniform_count, context->c.uniforms, 0); for (i = 0; i < context->c.texture_count; ++i) { - struct texture *texture = &context->c.textures[i]; + struct texture *texture = context->c.textures[i];
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(command_list, texture->root_index, get_gpu_descriptor_handle(test_context, texture->heap, 0)); @@ -192,15 +210,6 @@ static void d3d12_runner_draw_quad(struct shader_context *c) exec_command_list(queue, command_list); wait_queue_idle(device, queue); reset_command_list(command_list, test_context->allocator); - - for (i = 0; i < context->c.texture_count; ++i) - { - struct texture *texture = &context->c.textures[i]; - - ID3D12DescriptorHeap_Release(texture->heap); - ID3D12Resource_Release(texture->resource); - free(texture); - } }
static void d3d12_runner_probe_vec4(struct shader_context *c, @@ -220,6 +229,8 @@ static void d3d12_runner_probe_vec4(struct shader_context *c, static const struct shader_runner_ops d3d12_runner_ops = { .compile_shader = d3d12_runner_compile_shader, + .create_texture = d3d12_runner_create_texture, + .destroy_texture = d3d12_runner_destroy_texture, .draw_quad = d3d12_runner_draw_quad, .probe_vec4 = d3d12_runner_probe_vec4, };