From 66d81ea34ec0670230a53a3f1a04962e7ee7abdf Mon Sep 17 00:00:00 2001 From: Jan Sikorski Date: Fri, 29 Apr 2022 13:18:56 +0200 Subject: [PATCH] wined3d: Reduce the size of staging BO's for texture uploads. Signed-off-by: Jan Sikorski Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/wined3d/texture.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c index 35688fcd0d9..595baf07788 100644 --- a/dlls/wined3d/texture.c +++ b/dlls/wined3d/texture.c @@ -4876,6 +4876,7 @@ static void wined3d_texture_vk_upload_data(struct wined3d_context *context, struct wined3d_context_vk *context_vk = wined3d_context_vk(context); unsigned int dst_level, dst_row_pitch, dst_slice_pitch; struct wined3d_texture_sub_resource *sub_resource; + unsigned int src_width, src_height, src_depth; struct wined3d_bo_address staging_bo_addr; VkPipelineStageFlags bo_stage_flags = 0; const struct wined3d_vk_info *vk_info; @@ -4933,6 +4934,10 @@ static void wined3d_texture_vk_upload_data(struct wined3d_context *context, sub_resource = &dst_texture_vk->t.sub_resources[dst_sub_resource_idx]; vk_info = context_vk->vk_info; + src_width = src_box->right - src_box->left; + src_height = src_box->bottom - src_box->top; + src_depth = src_box->back - src_box->front; + src_offset = src_box->front * src_slice_pitch + (src_box->top / src_format->block_height) * src_row_pitch + (src_box->left / src_format->block_width) * src_format->block_byte_count; @@ -4945,10 +4950,15 @@ static void wined3d_texture_vk_upload_data(struct wined3d_context *context, /* We need to be outside of a render pass for vkCmdPipelineBarrier() and vkCmdCopyBufferToImage() calls below. */ wined3d_context_vk_end_current_render_pass(context_vk); - if (!src_bo_addr->buffer_object) { - if (!wined3d_context_vk_create_bo(context_vk, sub_resource->size, + unsigned int staging_row_pitch, staging_slice_pitch, staging_size; + + wined3d_format_calculate_pitch(src_format, context->device->surface_alignment, src_width, src_height, + &staging_row_pitch, &staging_slice_pitch); + staging_size = staging_slice_pitch * src_depth; + + if (!wined3d_context_vk_create_bo(context_vk, staging_size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &staging_bo)) { ERR("Failed to create staging bo.\n"); @@ -4958,26 +4968,25 @@ static void wined3d_texture_vk_upload_data(struct wined3d_context *context, staging_bo_addr.buffer_object = &staging_bo.b; staging_bo_addr.addr = NULL; if (!(map_ptr = wined3d_context_map_bo_address(context, &staging_bo_addr, - sub_resource->size, WINED3D_MAP_DISCARD | WINED3D_MAP_WRITE))) + staging_size, WINED3D_MAP_DISCARD | WINED3D_MAP_WRITE))) { ERR("Failed to map staging bo.\n"); wined3d_context_vk_destroy_bo(context_vk, &staging_bo); return; } - wined3d_format_copy_data(src_format, src_bo_addr->addr + src_offset, src_row_pitch, - src_slice_pitch, map_ptr, dst_row_pitch, dst_slice_pitch, src_box->right - src_box->left, - src_box->bottom - src_box->top, src_box->back - src_box->front); + wined3d_format_copy_data(src_format, src_bo_addr->addr, src_row_pitch, src_slice_pitch, + map_ptr, staging_row_pitch, staging_slice_pitch, src_width, src_height, src_depth); range.offset = 0; - range.size = sub_resource->size; + range.size = staging_size; wined3d_context_unmap_bo_address(context, &staging_bo_addr, 1, &range); src_bo = &staging_bo; src_offset = 0; - src_row_pitch = dst_row_pitch; - src_slice_pitch = dst_slice_pitch; + src_row_pitch = staging_row_pitch; + src_slice_pitch = staging_slice_pitch; } else { @@ -5027,9 +5036,9 @@ static void wined3d_texture_vk_upload_data(struct wined3d_context *context, region.imageOffset.x = dst_x; region.imageOffset.y = dst_y; region.imageOffset.z = dst_z; - region.imageExtent.width = src_box->right - src_box->left; - region.imageExtent.height = src_box->bottom - src_box->top; - region.imageExtent.depth = src_box->back - src_box->front; + region.imageExtent.width = src_width; + region.imageExtent.height = src_height; + region.imageExtent.depth = src_depth; VK_CALL(vkCmdCopyBufferToImage(vk_command_buffer, src_bo->vk_buffer, dst_texture_vk->image.vk_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion));