From 4075f8e2219c74ae01bb358817e381d5a3a23a1a Mon Sep 17 00:00:00 2001 From: Iago Toral Quiroga Date: Tue, 17 Dec 2019 08:41:35 +0100 Subject: [PATCH] v3dv: revert the decision that the command buffer takes ownership of BOs The CLs in the command buffer will reference BOs allocated by the application such as images and buffers, that will be destroyed by the application, so destroying them with the command buffer won't be correct. For now, let's just assume that the comman buffer only owns the BOs it explicitly allocates and that other abstractions own their own BOs and are responsible from freeing them. In the future, we might consider a ref/unref system similar to v3d's, but for now this should work. Part-of: --- src/broadcom/vulkan/v3dv_cl.c | 6 ++++-- src/broadcom/vulkan/v3dv_cmd_buffer.c | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/broadcom/vulkan/v3dv_cl.c b/src/broadcom/vulkan/v3dv_cl.c index 4debcd3a126..4436fc7456a 100644 --- a/src/broadcom/vulkan/v3dv_cl.c +++ b/src/broadcom/vulkan/v3dv_cl.c @@ -54,7 +54,10 @@ v3dv_cl_reset(struct v3dv_cl *cl) void v3dv_cl_destroy(struct v3dv_cl *cl) { - /* The CL's BO is owned by the command buffer, so don't free it here */ + if (cl->bo) { + assert(cl->cmd_buffer); + v3dv_bo_free(cl->cmd_buffer->device, cl->bo); + } /* Leave the CL in a reset state to catch use after destroy instances */ v3dv_cl_init(NULL, cl); @@ -79,7 +82,6 @@ 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); diff --git a/src/broadcom/vulkan/v3dv_cmd_buffer.c b/src/broadcom/vulkan/v3dv_cmd_buffer.c index 5a5001eb0f2..03421aaff7f 100644 --- a/src/broadcom/vulkan/v3dv_cmd_buffer.c +++ b/src/broadcom/vulkan/v3dv_cmd_buffer.c @@ -109,12 +109,20 @@ cmd_buffer_destroy(struct v3dv_cmd_buffer *cmd_buffer) v3dv_cl_destroy(&cmd_buffer->rcl); v3dv_cl_destroy(&cmd_buffer->indirect); + /* Since we don't ref BOs, when we add them to the command buffer, don't + * unref them here either. + */ +#if 0 set_foreach(cmd_buffer->bos, entry) { struct v3dv_bo *bo = (struct v3dv_bo *)entry->key; v3dv_bo_free(cmd_buffer->device, bo); } +#endif _mesa_set_destroy(cmd_buffer->bos, NULL); + v3dv_bo_free(cmd_buffer->device, cmd_buffer->tile_alloc); + v3dv_bo_free(cmd_buffer->device, cmd_buffer->tile_state); + vk_free(&cmd_buffer->pool->alloc, cmd_buffer); }