radv: destroy the base object if VkAllocateCommandBuffers() failed
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Sun, 12 Jul 2020 11:34:39 +0000 (13:34 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 15 Jul 2020 11:53:35 +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_cmd_buffer.c

index bfae582d30c18c2936dbfb023230c4b01ea8ff6b..92556e3b5e4043301ffa783c49cf55d04257882f 100644 (file)
@@ -336,6 +336,31 @@ enum ring_type radv_queue_family_to_ring(int f) {
        }
 }
 
+static void
+radv_destroy_cmd_buffer(struct radv_cmd_buffer *cmd_buffer)
+{
+       list_del(&cmd_buffer->pool_link);
+
+       list_for_each_entry_safe(struct radv_cmd_buffer_upload, up,
+                                &cmd_buffer->upload.list, list) {
+               cmd_buffer->device->ws->buffer_destroy(up->upload_bo);
+               list_del(&up->list);
+               free(up);
+       }
+
+       if (cmd_buffer->upload.upload_bo)
+               cmd_buffer->device->ws->buffer_destroy(cmd_buffer->upload.upload_bo);
+
+       if (cmd_buffer->cs)
+               cmd_buffer->device->ws->cs_destroy(cmd_buffer->cs);
+
+       for (unsigned i = 0; i < MAX_BIND_POINTS; i++)
+               free(cmd_buffer->descriptors[i].push_set.set.mapped_ptr);
+
+       vk_object_base_finish(&cmd_buffer->base);
+       vk_free(&cmd_buffer->pool->alloc, cmd_buffer);
+}
+
 static VkResult radv_create_cmd_buffer(
        struct radv_device *                         device,
        struct radv_cmd_pool *                       pool,
@@ -363,7 +388,7 @@ static VkResult radv_create_cmd_buffer(
 
        cmd_buffer->cs = device->ws->cs_create(device->ws, ring);
        if (!cmd_buffer->cs) {
-               vk_free(&cmd_buffer->pool->alloc, cmd_buffer);
+               radv_destroy_cmd_buffer(cmd_buffer);
                return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
        }
 
@@ -374,30 +399,6 @@ static VkResult radv_create_cmd_buffer(
        return VK_SUCCESS;
 }
 
-static void
-radv_cmd_buffer_destroy(struct radv_cmd_buffer *cmd_buffer)
-{
-       list_del(&cmd_buffer->pool_link);
-
-       list_for_each_entry_safe(struct radv_cmd_buffer_upload, up,
-                                &cmd_buffer->upload.list, list) {
-               cmd_buffer->device->ws->buffer_destroy(up->upload_bo);
-               list_del(&up->list);
-               free(up);
-       }
-
-       if (cmd_buffer->upload.upload_bo)
-               cmd_buffer->device->ws->buffer_destroy(cmd_buffer->upload.upload_bo);
-       cmd_buffer->device->ws->cs_destroy(cmd_buffer->cs);
-
-       for (unsigned i = 0; i < MAX_BIND_POINTS; i++)
-               free(cmd_buffer->descriptors[i].push_set.set.mapped_ptr);
-
-       vk_object_base_finish(&cmd_buffer->base);
-
-       vk_free(&cmd_buffer->pool->alloc, cmd_buffer);
-}
-
 static VkResult
 radv_reset_cmd_buffer(struct radv_cmd_buffer *cmd_buffer)
 {
@@ -3628,7 +3629,7 @@ void radv_FreeCommandBuffers(
                                list_del(&cmd_buffer->pool_link);
                                list_addtail(&cmd_buffer->pool_link, &cmd_buffer->pool->free_cmd_buffers);
                        } else
-                               radv_cmd_buffer_destroy(cmd_buffer);
+                               radv_destroy_cmd_buffer(cmd_buffer);
 
                }
        }
@@ -4767,12 +4768,12 @@ void radv_DestroyCommandPool(
 
        list_for_each_entry_safe(struct radv_cmd_buffer, cmd_buffer,
                                 &pool->cmd_buffers, pool_link) {
-               radv_cmd_buffer_destroy(cmd_buffer);
+               radv_destroy_cmd_buffer(cmd_buffer);
        }
 
        list_for_each_entry_safe(struct radv_cmd_buffer, cmd_buffer,
                                 &pool->free_cmd_buffers, pool_link) {
-               radv_cmd_buffer_destroy(cmd_buffer);
+               radv_destroy_cmd_buffer(cmd_buffer);
        }
 
        vk_object_base_finish(&pool->base);
@@ -4809,7 +4810,7 @@ void radv_TrimCommandPool(
 
        list_for_each_entry_safe(struct radv_cmd_buffer, cmd_buffer,
                                 &pool->free_cmd_buffers, pool_link) {
-               radv_cmd_buffer_destroy(cmd_buffer);
+               radv_destroy_cmd_buffer(cmd_buffer);
        }
 }