From 84c73f82f72e8843e11a42733eda365b69b911df Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Mon, 21 Mar 2022 20:42:18 -0500 Subject: [PATCH] tests: Allow specifying a custom vertex buffer. Signed-off-by: Zebediah Figura Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- tests/shader_runner.c | 31 +++++++++++++++++++++++++++++++ tests/shader_runner.h | 5 +++++ tests/shader_runner_d3d11.c | 23 ++++++++++++++++++----- tests/shader_runner_d3d12.c | 17 +++++++++++++++++ 4 files changed, 71 insertions(+), 5 deletions(-) diff --git a/tests/shader_runner.c b/tests/shader_runner.c index f203e453..b564a8a5 100644 --- a/tests/shader_runner.c +++ b/tests/shader_runner.c @@ -85,6 +85,7 @@ enum parse_state STATE_SHADER_VERTEX, STATE_TEXTURE, STATE_TEST, + STATE_VERTEX_BUFFER, }; static bool match_string(const char *line, const char *token, const char **const rest) @@ -478,6 +479,24 @@ static void set_resource(struct shader_runner *runner, struct resource *resource runner->resources[runner->resource_count++] = resource; } +unsigned int get_vb_stride(const struct shader_runner *runner, unsigned int slot) +{ + unsigned int stride = 0; + size_t i; + + /* We currently don't deal with vertex formats less than 32 bits, so don't + * bother with alignment. */ + for (i = 0; i < runner->input_element_count; ++i) + { + const struct input_element *element = &runner->input_elements[i]; + + if (element->slot == slot) + stride += element->texel_size; + } + + return stride; +} + 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; @@ -534,6 +553,7 @@ void run_shader_tests(struct shader_runner *runner, int argc, char **argv, const break; case STATE_TEXTURE: + case STATE_VERTEX_BUFFER: set_resource(runner, runner->ops->create_resource(runner, ¤t_resource)); free(current_resource.data); break; @@ -681,6 +701,16 @@ void run_shader_tests(struct shader_runner *runner, int argc, char **argv, const current_resource.data_type = TEXTURE_DATA_FLOAT; current_resource.texel_size = 16; } + else if (sscanf(line, "[vertex buffer %u]\n", &index)) + { + state = STATE_VERTEX_BUFFER; + + memset(¤t_resource, 0, sizeof(current_resource)); + + current_resource.slot = index; + current_resource.type = RESOURCE_TYPE_VERTEX_BUFFER; + current_resource.data_type = TEXTURE_DATA_FLOAT; + } else if (!strcmp(line, "[test]\n")) { state = STATE_TEST; @@ -743,6 +773,7 @@ void run_shader_tests(struct shader_runner *runner, int argc, char **argv, const break; case STATE_TEXTURE: + case STATE_VERTEX_BUFFER: parse_resource_directive(¤t_resource, line); break; diff --git a/tests/shader_runner.h b/tests/shader_runner.h index 67944fda..dd692b5c 100644 --- a/tests/shader_runner.h +++ b/tests/shader_runner.h @@ -54,6 +54,7 @@ struct sampler enum resource_type { RESOURCE_TYPE_TEXTURE, + RESOURCE_TYPE_VERTEX_BUFFER, }; struct resource_params @@ -73,6 +74,8 @@ struct resource { unsigned int slot; enum resource_type type; + + unsigned int size; }; struct input_element @@ -115,6 +118,8 @@ struct shader_runner_ops void fatal_error(const char *format, ...) VKD3D_NORETURN VKD3D_PRINTF_FUNC(1, 2); +unsigned int get_vb_stride(const struct shader_runner *runner, unsigned int slot); + void run_shader_tests(struct shader_runner *runner, int argc, char **argv, const struct shader_runner_ops *ops); #ifdef _WIN32 diff --git a/tests/shader_runner_d3d11.c b/tests/shader_runner_d3d11.c index 838e04ff..5b20d22d 100644 --- a/tests/shader_runner_d3d11.c +++ b/tests/shader_runner_d3d11.c @@ -42,7 +42,7 @@ struct d3d11_resource { struct resource r; - ID3D11Texture2D *texture; + ID3D11Resource *resource; ID3D11ShaderResourceView *srv; }; @@ -397,12 +397,17 @@ static struct resource *d3d11_runner_create_resource(struct shader_runner *r, co resource_data.SysMemPitch = params->width * params->texel_size; resource_data.SysMemSlicePitch = params->height * resource_data.SysMemPitch; - hr = ID3D11Device_CreateTexture2D(device, &desc, &resource_data, &resource->texture); + hr = ID3D11Device_CreateTexture2D(device, &desc, &resource_data, (ID3D11Texture2D **)&resource->resource); ok(hr == S_OK, "Failed to create texture, hr %#lx.\n", hr); - hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)resource->texture, NULL, &resource->srv); + hr = ID3D11Device_CreateShaderResourceView(device, resource->resource, NULL, &resource->srv); ok(hr == S_OK, "Failed to create shader resource view, hr %#lx.\n", hr); break; } + + case RESOURCE_TYPE_VERTEX_BUFFER: + resource->resource = (ID3D11Resource *)create_buffer(device, + D3D11_BIND_VERTEX_BUFFER, params->data_size, params->data); + break; } return &resource->r; @@ -412,8 +417,9 @@ static void d3d11_runner_destroy_resource(struct shader_runner *r, struct resour { struct d3d11_resource *resource = d3d11_resource(res); - ID3D11Texture2D_Release(resource->texture); - ID3D11ShaderResourceView_Release(resource->srv); + ID3D11Resource_Release(resource->resource); + if (resource->srv) + ID3D11ShaderResourceView_Release(resource->srv); free(resource); } @@ -456,12 +462,19 @@ static void d3d11_runner_draw_quad(struct shader_runner *r) for (i = 0; i < runner->r.resource_count; ++i) { struct d3d11_resource *resource = d3d11_resource(runner->r.resources[i]); + unsigned int stride = get_vb_stride(&runner->r, resource->r.slot); + unsigned int offset = 0; switch (resource->r.type) { case RESOURCE_TYPE_TEXTURE: ID3D11DeviceContext_PSSetShaderResources(context, resource->r.slot, 1, &resource->srv); break; + + case RESOURCE_TYPE_VERTEX_BUFFER: + ID3D11DeviceContext_IASetVertexBuffers(context, resource->r.slot, 1, + (ID3D11Buffer **)&resource->resource, &stride, &offset); + break; } } diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c index 1d38ee90..588964b5 100644 --- a/tests/shader_runner_d3d12.c +++ b/tests/shader_runner_d3d12.c @@ -92,6 +92,7 @@ static struct resource *d3d12_runner_create_resource(struct shader_runner *r, co resource = calloc(1, sizeof(*resource)); resource->r.slot = params->slot; resource->r.type = params->type; + resource->r.size = params->data_size; switch (params->type) { @@ -114,6 +115,10 @@ static struct resource *d3d12_runner_create_resource(struct shader_runner *r, co ID3D12Device_CreateShaderResourceView(device, resource->resource, NULL, get_cpu_descriptor_handle(test_context, runner->heap, resource->r.slot)); break; + + case RESOURCE_TYPE_VERTEX_BUFFER: + resource->resource = create_upload_buffer(device, params->data_size, params->data); + break; } return &resource->r; @@ -197,6 +202,9 @@ static void d3d12_runner_draw_quad(struct shader_runner *r) range->RegisterSpace = 0; range->OffsetInDescriptorsFromTableStart = 0; break; + + case RESOURCE_TYPE_VERTEX_BUFFER: + break; } } @@ -261,6 +269,7 @@ static void d3d12_runner_draw_quad(struct shader_runner *r) for (i = 0; i < runner->r.resource_count; ++i) { struct d3d12_resource *resource = d3d12_resource(runner->r.resources[i]); + D3D12_VERTEX_BUFFER_VIEW vbv; switch (resource->r.type) { @@ -268,6 +277,14 @@ static void d3d12_runner_draw_quad(struct shader_runner *r) ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(command_list, resource->root_index, get_gpu_descriptor_handle(test_context, runner->heap, resource->r.slot)); break; + + case RESOURCE_TYPE_VERTEX_BUFFER: + vbv.BufferLocation = ID3D12Resource_GetGPUVirtualAddress(resource->resource); + vbv.StrideInBytes = get_vb_stride(&runner->r, resource->r.slot); + vbv.SizeInBytes = resource->r.size; + + ID3D12GraphicsCommandList_IASetVertexBuffers(command_list, resource->r.slot, 1, &vbv); + break; } }