radv: destroy the base object if VkCreateImage() failed
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Fri, 10 Jul 2020 14:18:37 +0000 (16:18 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 15 Jul 2020 11:53:26 +0000 (13:53 +0200)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5868>

src/amd/vulkan/radv_device.c
src/amd/vulkan/radv_image.c
src/amd/vulkan/radv_private.h

index 9fc0668761ec5a27f9dd78590ca644d719a7246f..407cc6fc6ac63c78157c246287163a2a2a0c8f5f 100644 (file)
@@ -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;
index 1cbe60adbdcf6f52712fbe3a67dfa08e644c0979..3d29e1cfbceae1181c3047ef8b7f3770ada2d62d 100644 (file)
@@ -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(
index 53fc176baa3ded1df81dad03609bf738446ce72c..9a674fad14ba36453addcf6fca7c7577585b34bc 100644 (file)
@@ -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,