From: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- tests/shader_runner_vulkan.c | 42 +++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 17 deletions(-)
diff --git a/tests/shader_runner_vulkan.c b/tests/shader_runner_vulkan.c index 5d4b65cf..4ef371ac 100644 --- a/tests/shader_runner_vulkan.c +++ b/tests/shader_runner_vulkan.c @@ -825,12 +825,19 @@ out: return ret; }
-static const struct vec4 *get_readback_vec4(const uint8_t *data, unsigned int row_pitch, unsigned int x, unsigned int y) +struct vulkan_resource_readback { - return (struct vec4 *)(data + y * row_pitch + x * sizeof(struct vec4)); + struct resource_readback rb; + VkDeviceMemory memory; + VkBuffer buffer; +}; + +static const struct vec4 *get_readback_vec4(const struct resource_readback *rb, unsigned int x, unsigned int y) +{ + return (struct vec4 *)((uint8_t *)rb->data + y * rb->row_pitch + x * sizeof(struct vec4)); }
-static void check_readback_data_vec4(const uint8_t *data, unsigned int row_pitch, +static void check_readback_data_vec4(const struct resource_readback *rb, const RECT *rect, const struct vec4 *expected, unsigned int max_diff) { unsigned int x = 0, y = 0; @@ -841,7 +848,7 @@ static void check_readback_data_vec4(const uint8_t *data, unsigned int row_pitch { for (x = rect->left; x < rect->right; ++x) { - got = *get_readback_vec4(data, row_pitch, x, y); + got = *get_readback_vec4(rb, x, y); if (!compare_vec4(&got, expected, max_diff)) { all_match = false; @@ -858,17 +865,18 @@ static void check_readback_data_vec4(const uint8_t *data, unsigned int row_pitch static void vulkan_runner_probe_vec4(struct shader_runner *r, const RECT *rect, const struct vec4 *v, unsigned int ulps) { struct vulkan_shader_runner *runner = vulkan_shader_runner(r); + struct vulkan_resource_readback rb; VkDevice device = runner->device; VkBufferImageCopy region = {0}; - VkBuffer staging_buffer; - unsigned int row_pitch; - VkDeviceMemory memory; - void *data;
- row_pitch = RENDER_TARGET_WIDTH * sizeof(struct vec4); + rb.rb.width = RENDER_TARGET_WIDTH; + rb.rb.height = RENDER_TARGET_HEIGHT; + rb.rb.depth = 1; + + rb.rb.row_pitch = rb.rb.width * sizeof(struct vec4);
- staging_buffer = create_buffer(runner, row_pitch * RENDER_TARGET_HEIGHT, - VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &memory); + rb.buffer = create_buffer(runner, rb.rb.row_pitch * RENDER_TARGET_HEIGHT, + VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &rb.memory);
begin_command_buffer(runner);
@@ -882,19 +890,19 @@ static void vulkan_runner_probe_vec4(struct shader_runner *r, const RECT *rect, region.imageExtent.depth = 1;
VK_CALL(vkCmdCopyImageToBuffer(runner->cmd_buffer, runner->render_target, - VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, staging_buffer, 1, ®ion)); + VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, rb.buffer, 1, ®ion));
transition_image_layout(runner, runner->render_target, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
end_command_buffer(runner);
- VK_CALL(vkMapMemory(device, memory, 0, VK_WHOLE_SIZE, 0, &data)); - todo_if (runner->r.is_todo) check_readback_data_vec4(data, row_pitch, rect, v, ulps); - VK_CALL(vkUnmapMemory(device, memory)); + VK_CALL(vkMapMemory(device, rb.memory, 0, VK_WHOLE_SIZE, 0, &rb.rb.data)); + todo_if (runner->r.is_todo) check_readback_data_vec4(&rb.rb, rect, v, ulps); + VK_CALL(vkUnmapMemory(device, rb.memory));
- VK_CALL(vkFreeMemory(device, memory, NULL)); - VK_CALL(vkDestroyBuffer(device, staging_buffer, NULL)); + VK_CALL(vkFreeMemory(device, rb.memory, NULL)); + VK_CALL(vkDestroyBuffer(device, rb.buffer, NULL)); }
static const struct shader_runner_ops vulkan_runner_ops =