From f4a5b2d59e19bac6977b3eb1364ad80a5ee4242e Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Mon, 20 Mar 2023 17:02:40 -0500 Subject: [PATCH] anv: Limit memory maps to the client-allocated size MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit No need to expose extra padding or CCS data to the client map. Now that we have the data, we can also make the BindBufferMemory asserts a bit more accurate. Reviewed-by: Iván Briano Part-of: --- src/intel/vulkan/anv_device.c | 10 ++++++---- src/intel/vulkan/anv_private.h | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 8bf94f5..da7a07c 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -3652,6 +3652,7 @@ VkResult anv_AllocateMemory( if (mem == NULL) return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY); + mem->size = pAllocateInfo->allocationSize; mem->type = mem_type; mem->map = NULL; mem->map_size = 0; @@ -4028,7 +4029,7 @@ VkResult anv_MapMemory( } if (size == VK_WHOLE_SIZE) - size = mem->bo->size - offset; + size = mem->size - offset; /* From the Vulkan spec version 1.0.32 docs for MapMemory: * @@ -4038,7 +4039,8 @@ VkResult anv_MapMemory( * equal to the size of the memory minus offset */ assert(size > 0); - assert(offset + size <= mem->bo->size); + assert(offset < mem->size); + assert(size <= mem->size - offset); if (size != (size_t)size) { return vk_errorf(device, VK_ERROR_MEMORY_MAP_FAILED, @@ -4177,8 +4179,8 @@ anv_bind_buffer_memory(const VkBindBufferMemoryInfo *pBindInfo) assert(pBindInfo->sType == VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO); if (mem) { - assert(pBindInfo->memoryOffset < mem->bo->size); - assert(mem->bo->size - pBindInfo->memoryOffset >= buffer->vk.size); + assert(pBindInfo->memoryOffset < mem->size); + assert(mem->size - pBindInfo->memoryOffset >= buffer->vk.size); buffer->address = (struct anv_address) { .bo = mem->bo, .offset = pBindInfo->memoryOffset, diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index ba0c80e..ff6b331 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -1577,6 +1577,9 @@ _anv_combine_address(struct anv_batch *batch, void *location, struct anv_device_memory { struct vk_object_base base; + /** Client-requested allocaiton size */ + uint64_t size; + struct list_head link; struct anv_bo * bo; -- 2.7.4