diff --git a/src/virtio/vulkan/vn_command_buffer.c b/src/virtio/vulkan/vn_command_buffer.c index 95f9deee94d..b814d7feff6 100644 --- a/src/virtio/vulkan/vn_command_buffer.c +++ b/src/virtio/vulkan/vn_command_buffer.c @@ -693,18 +693,6 @@ vn_CreateCommandPool(VkDevice device, return VK_SUCCESS; } -static inline void -vn_recycle_query_feedback_cmd(struct vn_command_buffer *cmd) -{ - simple_mtx_lock(&cmd->linked_query_feedback_cmd->pool->mutex); - vn_ResetCommandBuffer( - vn_command_buffer_to_handle(cmd->linked_query_feedback_cmd->cmd), 0); - list_add(&cmd->linked_query_feedback_cmd->head, - &cmd->linked_query_feedback_cmd->pool->free_query_feedback_cmds); - cmd->linked_query_feedback_cmd = NULL; - simple_mtx_unlock(&cmd->linked_query_feedback_cmd->pool->mutex); -} - void vn_DestroyCommandPool(VkDevice device, VkCommandPool commandPool, @@ -735,8 +723,10 @@ vn_DestroyCommandPool(VkDevice device, &cmd->builder.query_batches, head) vk_free(alloc, batch); - if (cmd->linked_query_feedback_cmd) - vn_recycle_query_feedback_cmd(cmd); + if (cmd->linked_query_feedback_cmd) { + vn_feedback_query_cmd_free(cmd->linked_query_feedback_cmd); + cmd->linked_query_feedback_cmd = NULL; + } vk_free(alloc, cmd); } @@ -767,8 +757,10 @@ vn_cmd_reset(struct vn_command_buffer *cmd) &cmd->builder.query_batches, head) list_move_to(&batch->head, &cmd->pool->free_query_batches); - if (cmd->linked_query_feedback_cmd) - vn_recycle_query_feedback_cmd(cmd); + if (cmd->linked_query_feedback_cmd) { + vn_feedback_query_cmd_free(cmd->linked_query_feedback_cmd); + cmd->linked_query_feedback_cmd = NULL; + } memset(&cmd->builder, 0, sizeof(cmd->builder)); @@ -893,8 +885,10 @@ vn_FreeCommandBuffers(VkDevice device, &cmd->builder.query_batches, head) list_move_to(&batch->head, &cmd->pool->free_query_batches); - if (cmd->linked_query_feedback_cmd) - vn_recycle_query_feedback_cmd(cmd); + if (cmd->linked_query_feedback_cmd) { + vn_feedback_query_cmd_free(cmd->linked_query_feedback_cmd); + cmd->linked_query_feedback_cmd = NULL; + } vn_object_base_fini(&cmd->base); vk_free(alloc, cmd); diff --git a/src/virtio/vulkan/vn_feedback.c b/src/virtio/vulkan/vn_feedback.c index 80944bb9038..d1538dffd4d 100644 --- a/src/virtio/vulkan/vn_feedback.c +++ b/src/virtio/vulkan/vn_feedback.c @@ -649,6 +649,16 @@ vn_feedback_query_cmd_alloc(VkDevice dev_handle, return VK_SUCCESS; } +void +vn_feedback_query_cmd_free(struct vn_query_feedback_cmd *feedback_cmd) +{ + simple_mtx_lock(&feedback_cmd->pool->mutex); + vn_ResetCommandBuffer(vn_command_buffer_to_handle(feedback_cmd->cmd), 0); + list_add(&feedback_cmd->head, + &feedback_cmd->pool->free_query_feedback_cmds); + simple_mtx_unlock(&feedback_cmd->pool->mutex); +} + VkResult vn_feedback_query_batch_record(VkDevice dev_handle, struct vn_query_feedback_cmd *feedback_cmd, diff --git a/src/virtio/vulkan/vn_feedback.h b/src/virtio/vulkan/vn_feedback.h index ea7bed85d83..965786c2477 100644 --- a/src/virtio/vulkan/vn_feedback.h +++ b/src/virtio/vulkan/vn_feedback.h @@ -159,6 +159,9 @@ vn_feedback_query_cmd_alloc(VkDevice dev_handle, struct vn_feedback_cmd_pool *feedback_pool, struct vn_query_feedback_cmd **out_feedback_cmd); +void +vn_feedback_query_cmd_free(struct vn_query_feedback_cmd *feedback_cmd); + VkResult vn_feedback_query_batch_record(VkDevice dev_handle, struct vn_query_feedback_cmd *feedback_cmd, diff --git a/src/virtio/vulkan/vn_queue.c b/src/virtio/vulkan/vn_queue.c index ef9c38a8a53..ad447689009 100644 --- a/src/virtio/vulkan/vn_queue.c +++ b/src/virtio/vulkan/vn_queue.c @@ -48,7 +48,6 @@ struct vn_queue_submission { const struct vn_device_memory *wsi_mem; uint32_t feedback_cmd_buffer_count; struct vn_sync_payload_external external_payload; - struct vn_query_feedback_cmd *recycle_query_feedback_cmd; /* Temporary storage allocation for submission * A single alloc for storage is performed and the offsets inside @@ -278,6 +277,19 @@ vn_queue_submission_count_batch_feedback(struct vn_queue_submission *submit, vn_get_cmd_handle(submit, batch_index, i)); if (!list_is_empty(&cmd->builder.query_batches)) batch_has_feedback_query = true; + + /* If a cmd that was submitted previously and already has a feedback + * cmd linked, as long as + * VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT was not set we can + * assume it has completed execution and is no longer in the pending + * state so its safe to recycle the old feedback command. + */ + if (cmd->linked_query_feedback_cmd) { + assert(!cmd->builder.is_simultaneous); + + vn_feedback_query_cmd_free(cmd->linked_query_feedback_cmd); + cmd->linked_query_feedback_cmd = NULL; + } } } @@ -580,7 +592,7 @@ vn_combine_query_feedback_batches_and_record( result = vn_feedback_query_batch_record(dev_handle, feedback_cmd, &combined_batches); if (result != VK_SUCCESS) - vk_free(&cmd_pool->allocator, feedback_cmd); + vn_feedback_query_cmd_free(feedback_cmd); } recycle_combined_batches: @@ -654,17 +666,6 @@ vn_queue_submission_add_query_feedback(struct vn_queue_submission *submit, return VK_SUCCESS; } - /* If a cmd that was submitted previously and already has a feedback cmd - * linked, as long as VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT is not - * set we can assume it has completed execution and is no longer in the - * pending state so its safe to recycle the old feedback command before - * linking a new one. Defer the actual recycle operation to - * vn_queue_submission_cleanup. - */ - if (linked_cmd->linked_query_feedback_cmd) - submit->recycle_query_feedback_cmd = - linked_cmd->linked_query_feedback_cmd; - linked_cmd->linked_query_feedback_cmd = feedback_cmd; return VK_SUCCESS; @@ -998,17 +999,6 @@ vn_queue_submission_cleanup(struct vn_queue_submission *submit) struct vn_queue *queue = vn_queue_from_handle(submit->queue_handle); const VkAllocationCallbacks *alloc = &queue->base.base.base.device->alloc; - if (submit->recycle_query_feedback_cmd) { - simple_mtx_lock(&submit->recycle_query_feedback_cmd->pool->mutex); - vn_ResetCommandBuffer( - vn_command_buffer_to_handle(submit->recycle_query_feedback_cmd->cmd), - 0); - list_add( - &submit->recycle_query_feedback_cmd->head, - &submit->recycle_query_feedback_cmd->pool->free_query_feedback_cmds); - simple_mtx_unlock(&submit->recycle_query_feedback_cmd->pool->mutex); - } - /* TODO clean up pending src feedbacks on failure? */ if (submit->has_feedback_semaphore) vn_queue_recycle_src_feedback(submit);