diff --git a/src/virtio/vulkan/vn_command_buffer.c b/src/virtio/vulkan/vn_command_buffer.c index 7cb6d2e1105..0c975301beb 100644 --- a/src/virtio/vulkan/vn_command_buffer.c +++ b/src/virtio/vulkan/vn_command_buffer.c @@ -490,11 +490,11 @@ vn_cmd_transfer_present_src_images( } struct vn_cmd_query_record * -vn_cmd_query_record_alloc(struct vn_command_pool *cmd_pool, - struct vn_query_pool *query_pool, - uint32_t query, - uint32_t query_count, - bool copy) +vn_cmd_pool_alloc_query_record(struct vn_command_pool *cmd_pool, + struct vn_query_pool *query_pool, + uint32_t query, + uint32_t query_count, + bool copy) { struct vn_cmd_query_record *record; if (list_is_empty(&cmd_pool->free_query_records)) { @@ -522,12 +522,10 @@ vn_cmd_merge_query_records(struct vn_command_buffer *primary_cmd, { list_for_each_entry_safe(struct vn_cmd_query_record, secondary_record, &secondary_cmd->builder.query_records, head) { - - struct vn_cmd_query_record *record = vn_cmd_query_record_alloc( + struct vn_cmd_query_record *record = vn_cmd_pool_alloc_query_record( primary_cmd->pool, secondary_record->query_pool, secondary_record->query, secondary_record->query_count, secondary_record->copy); - if (!record) { primary_cmd->state = VN_COMMAND_BUFFER_STATE_INVALID; return; @@ -688,8 +686,7 @@ vn_cmd_reset(struct vn_command_buffer *cmd) /* reset cmd builder */ vk_free(&cmd->pool->allocator, cmd->builder.present_src_images); - list_splicetail(&cmd->builder.query_records, - &cmd->pool->free_query_records); + vn_cmd_pool_free_query_records(cmd->pool, &cmd->builder.query_records); memset(&cmd->builder, 0, sizeof(cmd->builder)); list_inithead(&cmd->builder.query_records); @@ -1756,7 +1753,7 @@ vn_cmd_record_query(VkCommandBuffer cmd_handle, return; struct vn_command_buffer *cmd = vn_command_buffer_from_handle(cmd_handle); - struct vn_cmd_query_record *record = vn_cmd_query_record_alloc( + struct vn_cmd_query_record *record = vn_cmd_pool_alloc_query_record( cmd->pool, query_pool, query, query_count, copy); if (!record) { cmd->state = VN_COMMAND_BUFFER_STATE_INVALID; diff --git a/src/virtio/vulkan/vn_command_buffer.h b/src/virtio/vulkan/vn_command_buffer.h index ee06488e540..4e91623ce41 100644 --- a/src/virtio/vulkan/vn_command_buffer.h +++ b/src/virtio/vulkan/vn_command_buffer.h @@ -118,10 +118,17 @@ struct vn_cmd_query_record { }; struct vn_cmd_query_record * -vn_cmd_query_record_alloc(struct vn_command_pool *cmd_pool, - struct vn_query_pool *query_pool, - uint32_t query, - uint32_t query_count, - bool copy); +vn_cmd_pool_alloc_query_record(struct vn_command_pool *cmd_pool, + struct vn_query_pool *query_pool, + uint32_t query, + uint32_t query_count, + bool copy); + +static inline void +vn_cmd_pool_free_query_records(struct vn_command_pool *cmd_pool, + struct list_head *query_records) +{ + list_splicetail(query_records, &cmd_pool->free_query_records); +} #endif /* VN_COMMAND_BUFFER_H */ diff --git a/src/virtio/vulkan/vn_queue.c b/src/virtio/vulkan/vn_queue.c index 77a3d53266a..90b56923805 100644 --- a/src/virtio/vulkan/vn_queue.c +++ b/src/virtio/vulkan/vn_queue.c @@ -575,10 +575,13 @@ vn_combine_query_records_and_record_feedback( { struct vn_command_pool *cmd_pool = vn_command_pool_from_handle(fb_cmd_pool->pool_handle); + struct vn_query_feedback_cmd *qfb_cmd = NULL; VkResult result = VK_SUCCESS; struct list_head resolved_records; + struct list_head dropped_records; list_inithead(&resolved_records); + list_inithead(&dropped_records); uintptr_t cmd_handle_ptr = (uintptr_t)cmd_handles; for (uint32_t i = 0; i < cmd_count; i++) { @@ -597,28 +600,23 @@ vn_combine_query_records_and_record_feedback( * to become available. */ if (resolved_record->copy && - (vn_query_pool_to_handle(resolved_record->query_pool) == - vn_query_pool_to_handle(record->query_pool)) && + resolved_record->query_pool == record->query_pool && resolved_record->query >= record->query && resolved_record->query < - record->query + record->query_count) { - simple_mtx_lock(&fb_cmd_pool->mutex); - list_move_to(&resolved_record->head, - &cmd_pool->free_query_records); - simple_mtx_unlock(&fb_cmd_pool->mutex); - } + record->query + record->query_count) + list_move_to(&resolved_record->head, &dropped_records); } } simple_mtx_lock(&fb_cmd_pool->mutex); struct vn_cmd_query_record *resolved_record = - vn_cmd_query_record_alloc(cmd_pool, record->query_pool, - record->query, record->query_count, - record->copy); + vn_cmd_pool_alloc_query_record(cmd_pool, record->query_pool, + record->query, record->query_count, + record->copy); simple_mtx_unlock(&fb_cmd_pool->mutex); if (!resolved_record) { result = VK_ERROR_OUT_OF_HOST_MEMORY; - goto recycle_resolved_records; + goto out_free_query_records; } list_addtail(&resolved_record->head, &resolved_records); @@ -627,29 +625,24 @@ vn_combine_query_records_and_record_feedback( cmd_handle_ptr += cmd_stride; } - if (list_is_empty(&resolved_records)) { - /* On the off chance the combined list resolves to empty due to - * resets, we can return with a null feedback cmd to indicate - * the query feedback cmd is noop and can be skipped. - */ - *out_qfb_cmd = NULL; - return VK_SUCCESS; + /* On the off chance the combined list resolves to empty due to resets, we + * can return with a null feedback cmd to indicate the query feedback cmd + * is noop and can be skipped. + */ + if (!list_is_empty(&resolved_records)) { + result = vn_query_feedback_cmd_alloc(dev_handle, fb_cmd_pool, &qfb_cmd); + if (result == VK_SUCCESS) { + result = vn_query_feedback_cmd_record(dev_handle, &resolved_records, + qfb_cmd); + if (result != VK_SUCCESS) + vn_query_feedback_cmd_free(qfb_cmd); + } } - struct vn_query_feedback_cmd *qfb_cmd; - result = vn_query_feedback_cmd_alloc(dev_handle, fb_cmd_pool, &qfb_cmd); - if (result == VK_SUCCESS) { - result = - vn_query_feedback_cmd_record(dev_handle, &resolved_records, qfb_cmd); - if (result != VK_SUCCESS) - vn_query_feedback_cmd_free(qfb_cmd); - } - -recycle_resolved_records: +out_free_query_records: simple_mtx_lock(&fb_cmd_pool->mutex); - list_for_each_entry_safe(struct vn_cmd_query_record, record, - &resolved_records, head) - list_move_to(&record->head, &cmd_pool->free_query_records); + vn_cmd_pool_free_query_records(cmd_pool, &resolved_records); + vn_cmd_pool_free_query_records(cmd_pool, &dropped_records); simple_mtx_unlock(&fb_cmd_pool->mutex); *out_qfb_cmd = qfb_cmd;