Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- tests/d3d12_test_utils.h | 5 +- tests/shader_runner.c | 229 +++++------------------------------- tests/shader_runner.h | 54 ++++++++- tests/shader_runner_d3d12.c | 186 ++++++++++++++++++++++++++++- tests/utils.h | 58 +++++++++ 5 files changed, 322 insertions(+), 210 deletions(-) create mode 100644 tests/utils.h
diff --git a/tests/d3d12_test_utils.h b/tests/d3d12_test_utils.h index f2ce92219..21be6bae6 100644 --- a/tests/d3d12_test_utils.h +++ b/tests/d3d12_test_utils.h @@ -19,10 +19,7 @@ #ifndef __VKD3D_D3D12_TEST_UTILS_H #define __VKD3D_D3D12_TEST_UTILS_H
-struct vec4 -{ - float x, y, z, w; -}; +#include "utils.h"
#define wait_queue_idle(a, b) wait_queue_idle_(__LINE__, a, b) static void wait_queue_idle_(unsigned int line, ID3D12Device *device, ID3D12CommandQueue *queue); diff --git a/tests/shader_runner.c b/tests/shader_runner.c index df4344881..052415947 100644 --- a/tests/shader_runner.c +++ b/tests/shader_runner.c @@ -42,9 +42,19 @@ * DEALINGS IN THE SOFTWARE. */
-#include "d3d12_crosstest.h" -#include "shader_runner.h" +#define COBJMACROS +#define CONST_VTABLE +#include "config.h" +#include <ctype.h> #include <errno.h> +#include <stdbool.h> +#include <stdio.h> +#include "vkd3d_windows.h" +#include "vkd3d_d3dcommon.h" +#include "vkd3d_d3dcompiler.h" +#include "vkd3d_common.h" +#include "vkd3d_test.h" +#include "shader_runner.h"
static void VKD3D_NORETURN VKD3D_PRINTF_FUNC(1, 2) fatal_error(const char *format, ...) { @@ -56,71 +66,10 @@ static void VKD3D_NORETURN VKD3D_PRINTF_FUNC(1, 2) fatal_error(const char *forma exit(1); }
-static bool vkd3d_array_reserve(void **elements, size_t *capacity, size_t element_count, size_t element_size) -{ - size_t new_capacity, max_capacity; - void *new_elements; - - if (element_count <= *capacity) - return true; - - max_capacity = ~(size_t)0 / element_size; - if (max_capacity < element_count) - return false; - - new_capacity = max(*capacity, 4); - while (new_capacity < element_count && new_capacity <= max_capacity / 2) - new_capacity *= 2; - - if (new_capacity < element_count) - new_capacity = element_count; - - if (!(new_elements = realloc(*elements, new_capacity * element_size))) - return false; - - *elements = new_elements; - *capacity = new_capacity; - - return true; -} - -enum texture_data_type -{ - TEXTURE_DATA_FLOAT, - TEXTURE_DATA_SINT, - TEXTURE_DATA_UINT, -}; - -struct sampler -{ - unsigned int slot; - - D3D12_FILTER filter; - D3D12_TEXTURE_ADDRESS_MODE u_address, v_address, w_address; -}; - -struct texture -{ - unsigned int slot; - - DXGI_FORMAT format; - enum texture_data_type data_type; - unsigned int texel_size; - unsigned int width, height; - uint8_t *data; - size_t data_size, data_capacity; - - D3D12_DESCRIPTOR_RANGE descriptor_range; - ID3D12DescriptorHeap *heap; - ID3D12Resource *resource; - unsigned int root_index; -}; - struct shader_context { const struct shader_runner_ops *ops; - - struct test_context c; + void *private;
ID3D10Blob *ps_code;
@@ -136,8 +85,6 @@ struct shader_context
static void free_texture(struct texture *texture) { - ID3D12DescriptorHeap_Release(texture->heap); - ID3D12Resource_Release(texture->resource); free(texture->data); memset(texture, 0, sizeof(*texture)); } @@ -320,119 +267,25 @@ static void parse_test_directive(struct shader_context *context, const char *lin { if (match_string(line, "draw quad", &line)) { - D3D12_SHADER_BYTECODE ps - = {ID3D10Blob_GetBufferPointer(context->ps_code), ID3D10Blob_GetBufferSize(context->ps_code)}; - ID3D12GraphicsCommandList *command_list = context->c.list; - D3D12_ROOT_SIGNATURE_DESC root_signature_desc = {0}; - D3D12_ROOT_PARAMETER root_params[3], *root_param; - D3D12_STATIC_SAMPLER_DESC static_samplers[1]; - static const float clear_color[4]; - unsigned int uniform_index; - ID3D12PipelineState *pso; - HRESULT hr; - size_t i; - - root_signature_desc.NumParameters = 0; - root_signature_desc.pParameters = root_params; - root_signature_desc.NumStaticSamplers = 0; - root_signature_desc.pStaticSamplers = static_samplers; - - if (context->uniform_count) + const struct draw_params params = { - 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->uniform_count; - root_param->ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; - } - - for (i = 0; i < context->texture_count; ++i) - { - struct texture *texture = &context->textures[i]; - D3D12_DESCRIPTOR_RANGE *range = &texture->descriptor_range; - D3D12_SUBRESOURCE_DATA resource_data; - - texture->root_index = root_signature_desc.NumParameters++; - root_param = &root_params[texture->root_index]; - root_param->ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; - root_param->DescriptorTable.NumDescriptorRanges = 1; - root_param->DescriptorTable.pDescriptorRanges = range; - root_param->ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; - - range->RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV; - range->NumDescriptors = 1; - range->BaseShaderRegister = texture->slot; - range->RegisterSpace = 0; - range->OffsetInDescriptorsFromTableStart = 0; - - if (!texture->resource) - { - texture->heap = create_gpu_descriptor_heap(context->c.device, - D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 1); - texture->resource = create_default_texture(context->c.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(texture->resource, &resource_data, 1, context->c.queue, command_list); - reset_command_list(command_list, context->c.allocator); - transition_resource_state(command_list, texture->resource, D3D12_RESOURCE_STATE_COPY_DEST, - D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE); - ID3D12Device_CreateShaderResourceView(context->c.device, texture->resource, - NULL, get_cpu_descriptor_handle(&context->c, texture->heap, 0)); - } - } + .ps_code = context->ps_code,
- assert(root_signature_desc.NumParameters <= ARRAY_SIZE(root_params)); + .uniforms = context->uniforms, + .uniform_count = context->uniform_count,
- for (i = 0; i < context->sampler_count; ++i) - { - D3D12_STATIC_SAMPLER_DESC *sampler_desc = &static_samplers[root_signature_desc.NumStaticSamplers++]; - const struct sampler *sampler = &context->samplers[i]; - - memset(sampler_desc, 0, sizeof(*sampler_desc)); - sampler_desc->Filter = sampler->filter; - sampler_desc->AddressU = sampler->u_address; - sampler_desc->AddressV = sampler->v_address; - sampler_desc->AddressW = sampler->w_address; - sampler_desc->ShaderRegister = sampler->slot; - sampler_desc->RegisterSpace = 0; - sampler_desc->ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; - } + .textures = context->textures, + .texture_count = context->texture_count,
- if (context->c.root_signature) - ID3D12RootSignature_Release(context->c.root_signature); - hr = create_root_signature(context->c.device, &root_signature_desc, &context->c.root_signature); - ok(hr == S_OK, "Failed to create root signature, hr %#x.\n", hr); + .samplers = context->samplers, + .sampler_count = context->sampler_count, + };
- pso = create_pipeline_state(context->c.device, context->c.root_signature, context->c.render_target_desc.Format, - NULL, &ps, NULL); - if (!pso) - return; - vkd3d_array_reserve((void **)&context->c.pso, &context->c.pso_capacity, context->c.pso_count + 1, sizeof(*context->c.pso)); - context->c.pso[context->c.pso_count++] = pso; - - ID3D12GraphicsCommandList_SetGraphicsRootSignature(command_list, context->c.root_signature); - if (context->uniform_count) - ID3D12GraphicsCommandList_SetGraphicsRoot32BitConstants(command_list, uniform_index, - context->uniform_count, context->uniforms, 0); - for (i = 0; i < context->texture_count; ++i) - ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(command_list, context->textures[i].root_index, - get_gpu_descriptor_handle(&context->c, context->textures[i].heap, 0)); - - ID3D12GraphicsCommandList_OMSetRenderTargets(command_list, 1, &context->c.rtv, false, NULL); - ID3D12GraphicsCommandList_RSSetScissorRects(command_list, 1, &context->c.scissor_rect); - ID3D12GraphicsCommandList_RSSetViewports(command_list, 1, &context->c.viewport); - ID3D12GraphicsCommandList_IASetPrimitiveTopology(command_list, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); - ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, context->c.rtv, clear_color, 0, NULL); - ID3D12GraphicsCommandList_SetPipelineState(command_list, pso); - ID3D12GraphicsCommandList_DrawInstanced(command_list, 3, 1, 0, 0); - transition_resource_state(command_list, context->c.render_target, - D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE); + context->ops->draw_quad(context->private, ¶ms); } else if (match_string(line, "probe all rgba", &line)) { + static const RECT rect = {0, 0, 640, 480}; unsigned int ulps; struct vec4 v; int ret; @@ -442,13 +295,12 @@ static void parse_test_directive(struct shader_context *context, const char *lin fatal_error("Malformed probe arguments '%s'.\n", line); if (ret < 5) ulps = 0; - check_sub_resource_vec4(context->c.render_target, 0, context->c.queue, context->c.list, &v, ulps); - reset_command_list(context->c.list, context->c.allocator); + + context->ops->probe_vec4(context->private, &rect, &v, ulps); } else if (match_string(line, "probe rect rgba", &line)) { unsigned int x, y, w, h, ulps; - struct resource_readback rb; struct vec4 v; RECT rect; int ret; @@ -460,18 +312,14 @@ static void parse_test_directive(struct shader_context *context, const char *lin if (ret < 9) ulps = 0;
- get_texture_readback_with_command_list(context->c.render_target, 0, &rb, context->c.queue, context->c.list); rect.left = x; rect.right = x + w; rect.top = y; rect.bottom = y + h; - check_readback_data_vec4(&rb, &rect, &v, ulps); - release_resource_readback(&rb); - reset_command_list(context->c.list, context->c.allocator); + context->ops->probe_vec4(context->private, &rect, &v, ulps); } else if (match_string(line, "probe rgba", &line)) { - struct resource_readback rb; unsigned int x, y, ulps; struct vec4 v; RECT rect; @@ -483,14 +331,11 @@ static void parse_test_directive(struct shader_context *context, const char *lin if (ret < 7) ulps = 0;
- get_texture_readback_with_command_list(context->c.render_target, 0, &rb, context->c.queue, context->c.list); rect.left = x; rect.right = x + 1; rect.top = y; rect.bottom = y + 1; - check_readback_data_vec4(&rb, &rect, &v, ulps); - release_resource_readback(&rb); - reset_command_list(context->c.list, context->c.allocator); + context->ops->probe_vec4(context->private, &rect, &v, ulps); } else if (match_string(line, "uniform", &line)) { @@ -590,15 +435,8 @@ static struct texture *get_texture(struct shader_context *context, unsigned int return NULL; }
-void run_shader_tests(int argc, char **argv, const struct shader_runner_ops *ops) +void run_shader_tests(int argc, char **argv, const struct shader_runner_ops *ops, void *private) { - static const struct test_context_desc desc = - { - .rt_width = 640, - .rt_height = 480, - .no_root_signature = true, - .rt_format = DXGI_FORMAT_R32G32B32A32_FLOAT, - }; size_t shader_source_size = 0, shader_source_len = 0; struct sampler *current_sampler = NULL; struct texture *current_texture = NULL; @@ -610,10 +448,6 @@ void run_shader_tests(int argc, char **argv, const struct shader_runner_ops *ops char line[256]; FILE *f;
- parse_args(argc, argv); - enable_d3d12_debug_layer(argc, argv); - init_adapter_info(); - for (i = 1; i < argc; ++i) { if (argv[i][0] != '-') @@ -637,7 +471,7 @@ void run_shader_tests(int argc, char **argv, const struct shader_runner_ops *ops
memset(&context, 0, sizeof(context)); context.ops = ops; - init_test_context(&context.c, &desc); + context.private = private;
for (;;) { @@ -656,7 +490,7 @@ void run_shader_tests(int argc, char **argv, const struct shader_runner_ops *ops break;
case STATE_SHADER_PIXEL: - if (!(context.ps_code = context.ops->compile_shader(shader_source))) + if (!(context.ps_code = context.ops->compile_shader(context.private, shader_source))) return; shader_source_len = 0; break; @@ -851,7 +685,6 @@ void run_shader_tests(int argc, char **argv, const struct shader_runner_ops *ops ID3D10Blob_Release(context.ps_code); for (i = 0; i < context.texture_count; ++i) free_texture(&context.textures[i]); - destroy_test_context(&context.c);
fclose(f); } diff --git a/tests/shader_runner.h b/tests/shader_runner.h index 5178c6544..ec152978e 100644 --- a/tests/shader_runner.h +++ b/tests/shader_runner.h @@ -18,12 +18,62 @@
#include "vkd3d_windows.h" #include "vkd3d_d3dcommon.h" +#include "vkd3d_d3d12.h" +#include "vkd3d_dxgiformat.h" +#include "utils.h" + +struct draw_params; + +enum texture_data_type +{ + TEXTURE_DATA_FLOAT, + TEXTURE_DATA_SINT, + TEXTURE_DATA_UINT, +}; + +struct sampler +{ + unsigned int slot; + + D3D12_FILTER filter; + D3D12_TEXTURE_ADDRESS_MODE u_address, v_address, w_address; +}; + +struct texture +{ + unsigned int slot; + + DXGI_FORMAT format; + enum texture_data_type data_type; + unsigned int texel_size; + unsigned int width, height; + uint8_t *data; + size_t data_size, data_capacity; + + void *private; +}; + +struct draw_params +{ + ID3D10Blob *ps_code; + + const uint32_t *uniforms; + size_t uniform_count; + + struct texture *textures; + size_t texture_count; + + struct sampler *samplers; + size_t sampler_count; +};
struct shader_runner_ops { - ID3D10Blob *(*compile_shader)(const char *source); + ID3D10Blob *(*compile_shader)(void *private, const char *source); + void (*draw_quad)(void *private, const struct draw_params *params); + void (*probe_vec4)(void *private, const RECT *rect, const struct vec4 *v, unsigned int ulps); };
-void run_shader_tests(int argc, char **argv, const struct shader_runner_ops *ops); +void run_shader_tests(int argc, char **argv, const struct shader_runner_ops *ops, void *private);
void run_shader_tests_d3d12(int argc, char **argv); diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c index 6246c8701..5c9db69c0 100644 --- a/tests/shader_runner_d3d12.c +++ b/tests/shader_runner_d3d12.c @@ -16,16 +16,22 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
+#include <assert.h> #define COBJMACROS #define CONST_VTABLE #define VKD3D_TEST_NO_DEFS -#include "vkd3d_windows.h" -#include "vkd3d_d3dcommon.h" -#include "vkd3d_d3dcompiler.h" -#include "vkd3d_test.h" +#include "d3d12_crosstest.h" #include "shader_runner.h"
-static ID3D10Blob *d3d12_runner_compile_shader(const char *source) +struct d3d12_texture +{ + D3D12_DESCRIPTOR_RANGE descriptor_range; + ID3D12DescriptorHeap *heap; + ID3D12Resource *resource; + unsigned int root_index; +}; + +static ID3D10Blob *d3d12_runner_compile_shader(void *private, const char *source) { ID3D10Blob *blob = NULL, *errors = NULL; HRESULT hr; @@ -41,12 +47,180 @@ static ID3D10Blob *d3d12_runner_compile_shader(const char *source) return blob; }
+static void d3d12_runner_draw_quad(void *private, const struct draw_params *params) +{ + struct test_context *context = private; + + D3D12_SHADER_BYTECODE ps + = {ID3D10Blob_GetBufferPointer(params->ps_code), ID3D10Blob_GetBufferSize(params->ps_code)}; + ID3D12GraphicsCommandList *command_list = context->list; + D3D12_ROOT_SIGNATURE_DESC root_signature_desc = {0}; + D3D12_ROOT_PARAMETER root_params[3], *root_param; + D3D12_STATIC_SAMPLER_DESC static_samplers[1]; + ID3D12Device *device = context->device; + static const float clear_color[4]; + unsigned int uniform_index; + ID3D12PipelineState *pso; + HRESULT hr; + size_t i; + + root_signature_desc.NumParameters = 0; + root_signature_desc.pParameters = root_params; + root_signature_desc.NumStaticSamplers = 0; + root_signature_desc.pStaticSamplers = static_samplers; + + if (params->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 = params->uniform_count; + root_param->ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; + } + + for (i = 0; i < params->texture_count; ++i) + { + struct texture *texture = ¶ms->textures[i]; + D3D12_SUBRESOURCE_DATA resource_data; + struct d3d12_texture *d3d12_texture; + D3D12_DESCRIPTOR_RANGE *range; + ID3D12Resource *resource; + + texture->private = calloc(1, sizeof(*d3d12_texture)); + d3d12_texture = texture->private; + range = &d3d12_texture->descriptor_range; + + d3d12_texture->root_index = root_signature_desc.NumParameters++; + root_param = &root_params[d3d12_texture->root_index]; + root_param->ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; + root_param->DescriptorTable.NumDescriptorRanges = 1; + root_param->DescriptorTable.pDescriptorRanges = range; + root_param->ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; + + range->RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV; + range->NumDescriptors = 1; + range->BaseShaderRegister = texture->slot; + range->RegisterSpace = 0; + range->OffsetInDescriptorsFromTableStart = 0; + + d3d12_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, context->queue, command_list); + reset_command_list(command_list, 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(context, d3d12_texture->heap, 0)); + + d3d12_texture->resource = resource; + } + + assert(root_signature_desc.NumParameters <= ARRAY_SIZE(root_params)); + + for (i = 0; i < params->sampler_count; ++i) + { + D3D12_STATIC_SAMPLER_DESC *sampler_desc = &static_samplers[root_signature_desc.NumStaticSamplers++]; + const struct sampler *sampler = ¶ms->samplers[i]; + + memset(sampler_desc, 0, sizeof(*sampler_desc)); + sampler_desc->Filter = sampler->filter; + sampler_desc->AddressU = sampler->u_address; + sampler_desc->AddressV = sampler->v_address; + sampler_desc->AddressW = sampler->w_address; + sampler_desc->ShaderRegister = sampler->slot; + sampler_desc->RegisterSpace = 0; + sampler_desc->ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; + } + + if (context->root_signature) + ID3D12RootSignature_Release(context->root_signature); + hr = create_root_signature(device, &root_signature_desc, &context->root_signature); + ok(hr == S_OK, "Failed to create root signature, hr %#x.\n", hr); + + pso = create_pipeline_state(device, context->root_signature, + context->render_target_desc.Format, NULL, &ps, NULL); + if (!pso) + return; + vkd3d_array_reserve((void **)&context->pso, &context->pso_capacity, context->pso_count + 1, sizeof(*context->pso)); + context->pso[context->pso_count++] = pso; + + ID3D12GraphicsCommandList_SetGraphicsRootSignature(command_list, context->root_signature); + if (params->uniform_count) + ID3D12GraphicsCommandList_SetGraphicsRoot32BitConstants(command_list, uniform_index, + params->uniform_count, params->uniforms, 0); + for (i = 0; i < params->texture_count; ++i) + { + struct d3d12_texture *d3d12_texture = params->textures[i].private; + + ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(command_list, d3d12_texture->root_index, + get_gpu_descriptor_handle(context, d3d12_texture->heap, 0)); + } + + ID3D12GraphicsCommandList_OMSetRenderTargets(command_list, 1, &context->rtv, false, NULL); + ID3D12GraphicsCommandList_RSSetScissorRects(command_list, 1, &context->scissor_rect); + ID3D12GraphicsCommandList_RSSetViewports(command_list, 1, &context->viewport); + ID3D12GraphicsCommandList_IASetPrimitiveTopology(command_list, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, context->rtv, clear_color, 0, NULL); + ID3D12GraphicsCommandList_SetPipelineState(command_list, pso); + ID3D12GraphicsCommandList_DrawInstanced(command_list, 3, 1, 0, 0); + transition_resource_state(command_list, context->render_target, + D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE); + + /* Finish the command list so that we can destroy objects. */ + hr = ID3D12GraphicsCommandList_Close(command_list); + ok(hr == S_OK, "Failed to close command list, hr %#x.\n", hr); + exec_command_list(context->queue, command_list); + wait_queue_idle(context->device, context->queue); + reset_command_list(command_list, context->allocator); + + for (i = 0; i < params->texture_count; ++i) + { + struct d3d12_texture *d3d12_texture = params->textures[i].private; + + ID3D12DescriptorHeap_Release(d3d12_texture->heap); + ID3D12Resource_Release(d3d12_texture->resource); + free(d3d12_texture); + } +} + +static void d3d12_runner_probe_vec4(void *private, const RECT *rect, const struct vec4 *v, unsigned int ulps) +{ + struct test_context *context = private; + struct resource_readback rb; + + get_texture_readback_with_command_list(context->render_target, 0, &rb, context->queue, context->list); + check_readback_data_vec4(&rb, rect, v, ulps); + release_resource_readback(&rb); + reset_command_list(context->list, context->allocator); +} + static const struct shader_runner_ops d3d12_runner_ops = { .compile_shader = d3d12_runner_compile_shader, + .draw_quad = d3d12_runner_draw_quad, + .probe_vec4 = d3d12_runner_probe_vec4, };
void run_shader_tests_d3d12(int argc, char **argv) { - run_shader_tests(argc, argv, &d3d12_runner_ops); + static const struct test_context_desc desc = + { + .rt_width = 640, + .rt_height = 480, + .no_root_signature = true, + .rt_format = DXGI_FORMAT_R32G32B32A32_FLOAT, + }; + struct test_context test_context; + + parse_args(argc, argv); + enable_d3d12_debug_layer(argc, argv); + init_adapter_info(); + init_test_context(&test_context, &desc); + run_shader_tests(argc, argv, &d3d12_runner_ops, &test_context); + destroy_test_context(&test_context); } diff --git a/tests/utils.h b/tests/utils.h new file mode 100644 index 000000000..825520c27 --- /dev/null +++ b/tests/utils.h @@ -0,0 +1,58 @@ +/* + * Copyright 2016-2018 Józef Kucia for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef __VKD3D_TEST_UTILS_H +#define __VKD3D_TEST_UTILS_H + +#include <stdbool.h> +#include <stdlib.h> + +struct vec4 +{ + float x, y, z, w; +}; + +static inline bool vkd3d_array_reserve(void **elements, size_t *capacity, size_t element_count, size_t element_size) +{ + size_t new_capacity, max_capacity; + void *new_elements; + + if (element_count <= *capacity) + return true; + + max_capacity = ~(size_t)0 / element_size; + if (max_capacity < element_count) + return false; + + new_capacity = max(*capacity, 4); + while (new_capacity < element_count && new_capacity <= max_capacity / 2) + new_capacity *= 2; + + if (new_capacity < element_count) + new_capacity = element_count; + + if (!(new_elements = realloc(*elements, new_capacity * element_size))) + return false; + + *elements = new_elements; + *capacity = new_capacity; + + return true; +} + +#endif