From d809d9f3f61fde3d904b08c988937933058caec6 Mon Sep 17 00:00:00 2001 From: Iago Toral Quiroga Date: Tue, 23 Jun 2020 13:36:15 +0200 Subject: [PATCH] v3dv: don't free BOs from imported memory objects Only free the underlying BO when the exported memory object is freed to avoid multiple frees of the same memory. The only exception is winsys BOs where we import a BO created in the display device into the render device. In this case, we only have one memory object referencing the BO and we want to destroy it with that memory object. Fixes: dEQP-VK.api.external.memory.dma_buf.* dEQP-VK.api.external.memory.opaque_fd.* Part-of: --- src/broadcom/vulkan/v3dv_device.c | 9 +++++++-- src/broadcom/vulkan/v3dv_private.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/broadcom/vulkan/v3dv_device.c b/src/broadcom/vulkan/v3dv_device.c index c9d32a9434d..c897e6e5160 100644 --- a/src/broadcom/vulkan/v3dv_device.c +++ b/src/broadcom/vulkan/v3dv_device.c @@ -1373,7 +1373,10 @@ device_alloc(struct v3dv_device *device, static void device_free(struct v3dv_device *device, struct v3dv_device_memory *mem) { - v3dv_bo_free(device, mem->bo); + if (mem->has_bo_ownership) + v3dv_bo_free(device, mem->bo); + else if (mem->bo) + vk_free(&device->alloc, mem->bo); } static void @@ -1457,6 +1460,7 @@ device_import_bo(struct v3dv_device *device, (*bo)->offset = get_offset.offset; (*bo)->map = NULL; (*bo)->map_size = 0; + (*bo)->private = false; return VK_SUCCESS; @@ -1506,7 +1510,6 @@ device_alloc_for_wsi(struct v3dv_device *device, if (result != VK_SUCCESS) goto fail_import; - return VK_SUCCESS; fail_import: @@ -1544,6 +1547,7 @@ v3dv_AllocateMemory(VkDevice _device, assert(pAllocateInfo->memoryTypeIndex < pdevice->memory.memoryTypeCount); mem->type = &pdevice->memory.memoryTypes[pAllocateInfo->memoryTypeIndex]; + mem->has_bo_ownership = true; const struct wsi_memory_allocate_info *wsi_info = NULL; const VkImportMemoryFdInfoKHR *fd_info = NULL; @@ -1571,6 +1575,7 @@ v3dv_AllocateMemory(VkDevice _device, result = device_import_bo(device, pAllocator, fd_info->fd, pAllocateInfo->allocationSize, &mem->bo); + mem->has_bo_ownership = false; if (result == VK_SUCCESS) close(fd_info->fd); } else { diff --git a/src/broadcom/vulkan/v3dv_private.h b/src/broadcom/vulkan/v3dv_private.h index b21c11ec62f..276fc1abf52 100644 --- a/src/broadcom/vulkan/v3dv_private.h +++ b/src/broadcom/vulkan/v3dv_private.h @@ -312,6 +312,7 @@ struct v3dv_device { struct v3dv_device_memory { struct v3dv_bo *bo; const VkMemoryType *type; + bool has_bo_ownership; }; #define V3D_OUTPUT_IMAGE_FORMAT_NO 255