diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index 84b738bc144..06044bca7eb 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -1861,6 +1861,16 @@ anv_image_finish(struct anv_image *image) anv_device_release_bo(device, image->bindings[ANV_IMAGE_MEMORY_BINDING_MAIN].address.bo); } + for (uint32_t b = 0; b < ARRAY_SIZE(image->bindings); b++) { + if (image->bindings[b].host_map != NULL) { + anv_device_unmap_bo(device, + image->bindings[b].address.bo, + image->bindings[b].host_map, + image->bindings[b].memory_range.size, + false /* replace */); + } + } + struct anv_bo *private_bo = image->bindings[ANV_IMAGE_MEMORY_BINDING_PRIVATE].address.bo; if (private_bo) { pthread_mutex_lock(&device->mutex); @@ -2492,6 +2502,21 @@ anv_image_bind_address(struct anv_device *device, { image->bindings[binding].address = address; + /* Map bindings for images with host transfer usage, so that we don't have + * to map/unmap things at every host operation. + */ + if (image->vk.usage & VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT) { + VkResult result = anv_device_map_bo(device, + image->bindings[binding].address.bo, + image->bindings[binding].address.offset + + image->bindings[binding].memory_range.offset, + image->bindings[binding].memory_range.size, + NULL /* placed_addr */, + &image->bindings[binding].host_map); + if (result != VK_SUCCESS) + return result; + } + ANV_RMV(image_bind, device, image, binding); return VK_SUCCESS; diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 887c26a8ddf..a42d2d3bdb5 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -5330,11 +5330,14 @@ struct anv_image { * Usually, the app will provide the address via the parameters of * vkBindImageMemory. However, special-case bindings may be bound to * driver-private memory. + * + * If needed a host pointer to the image is mapped for host image copies. */ struct anv_image_binding { struct anv_image_memory_range memory_range; struct anv_address address; struct anv_sparse_binding_data sparse_data; + void *host_map; } bindings[ANV_IMAGE_MEMORY_BINDING_END]; /**