From: Samuel Pitoiset Date: Fri, 10 Jul 2020 14:18:37 +0000 (+0200) Subject: radv: destroy the base object if VkCreateImage() failed X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=852316494cf0678e24c63598682ab4250242a4fa;p=mesa.git radv: destroy the base object if VkCreateImage() failed Signed-off-by: Samuel Pitoiset Reviewed-by: Bas Nieuwenhuizen Part-of: --- diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index 9fc0668761e..407cc6fc6ac 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -4649,9 +4649,10 @@ bool radv_get_memory_fd(struct radv_device *device, } -static void radv_free_memory(struct radv_device *device, - const VkAllocationCallbacks* pAllocator, - struct radv_device_memory *mem) +void +radv_free_memory(struct radv_device *device, + const VkAllocationCallbacks* pAllocator, + struct radv_device_memory *mem) { if (mem == NULL) return; diff --git a/src/amd/vulkan/radv_image.c b/src/amd/vulkan/radv_image.c index 1cbe60adbdc..3d29e1cfbce 100644 --- a/src/amd/vulkan/radv_image.c +++ b/src/amd/vulkan/radv_image.c @@ -1348,6 +1348,23 @@ radv_image_create_layout(struct radv_device *device, return VK_SUCCESS; } +static void +radv_destroy_image(struct radv_device *device, + const VkAllocationCallbacks *pAllocator, + struct radv_image *image) +{ + if ((image->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) && image->bo) + device->ws->buffer_destroy(image->bo); + + if (image->owned_memory != VK_NULL_HANDLE) { + RADV_FROM_HANDLE(radv_device_memory, mem, image->owned_memory); + radv_free_memory(device, pAllocator, mem); + } + + vk_object_base_finish(&image->base); + vk_free2(&device->vk.alloc, pAllocator, image); +} + VkResult radv_image_create(VkDevice _device, const struct radv_image_create_info *create_info, @@ -1437,7 +1454,7 @@ radv_image_create(VkDevice _device, image->bo = device->ws->buffer_create(device->ws, image->size, image->alignment, 0, RADEON_FLAG_VIRTUAL, RADV_BO_PRIORITY_VIRTUAL); if (!image->bo) { - vk_free2(&device->vk.alloc, alloc, image); + radv_destroy_image(device, alloc, image); return vk_error(device->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY); } } @@ -1767,14 +1784,7 @@ radv_DestroyImage(VkDevice _device, VkImage _image, if (!image) return; - if (image->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) - device->ws->buffer_destroy(image->bo); - - if (image->owned_memory != VK_NULL_HANDLE) - radv_FreeMemory(_device, image->owned_memory, pAllocator); - - vk_object_base_finish(&image->base); - vk_free2(&device->vk.alloc, pAllocator, image); + radv_destroy_image(device, pAllocator, image); } void radv_GetImageSubresourceLayout( diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index 53fc176baa3..9a674fad14b 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -1505,6 +1505,9 @@ void radv_cmd_buffer_trace_emit(struct radv_cmd_buffer *cmd_buffer); bool radv_get_memory_fd(struct radv_device *device, struct radv_device_memory *memory, int *pFD); +void radv_free_memory(struct radv_device *device, + const VkAllocationCallbacks* pAllocator, + struct radv_device_memory *mem); static inline void radv_emit_shader_pointer_head(struct radeon_cmdbuf *cs,