v3dv: make the command buffer own the command list BOs
authorIago Toral Quiroga <itoral@igalia.com>
Mon, 16 Dec 2019 08:05:07 +0000 (09:05 +0100)
committerMarge Bot <eric+marge@anholt.net>
Tue, 13 Oct 2020 21:21:25 +0000 (21:21 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

src/broadcom/vulkan/v3dv_cl.c
src/broadcom/vulkan/v3dv_cmd_buffer.c

index 62b04f0..4debcd3 100644 (file)
@@ -48,18 +48,16 @@ v3dv_cl_reset(struct v3dv_cl *cl)
    /* FIXME: consider keeping the BO when the command buffer is reset with
     * flag VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT.
     */
-   v3dv_cl_destroy(cl);
    v3dv_cl_init(cl->cmd_buffer, cl);
 }
 
 void
 v3dv_cl_destroy(struct v3dv_cl *cl)
 {
-   assert(cl);
-   if (cl->bo) {
-      assert(cl->cmd_buffer && cl->cmd_buffer->device);
-      v3dv_bo_free(cl->cmd_buffer->device, cl->bo);
-   }
+   /* The CL's BO is owned by the command buffer, so don't free it here */
+
+   /* Leave the CL in a reset state to catch use after destroy instances */
+   v3dv_cl_init(NULL, cl);
 }
 
 void
@@ -81,6 +79,7 @@ v3dv_cl_ensure_space_with_branch(struct v3dv_cl *cl, uint32_t space)
       }
    }
 
+   /* The command buffer takes ownership of the BO */
    v3dv_cmd_buffer_add_bo(cl->cmd_buffer, bo);
 
    bool ok = v3dv_bo_map(cl->cmd_buffer->device, bo, bo->size);
index 640f60f..a255c9b 100644 (file)
@@ -105,10 +105,6 @@ cmd_buffer_destroy(struct v3dv_cmd_buffer *cmd_buffer)
 {
    list_del(&cmd_buffer->pool_link);
 
-   /* FIXME: we are probably double-freeing these BOs in the loop below.
-    * either have a refcount system for BOs like in v3d or don't free the
-    * BO when we destroy a CL.
-    */
    v3dv_cl_destroy(&cmd_buffer->bcl);
    v3dv_cl_destroy(&cmd_buffer->rcl);
    v3dv_cl_destroy(&cmd_buffer->indirect);