venus: refactor query record recycle

Add a new free helper while renaming the alloc one as well. During query
record resolving, use a dropped list to store those records being reset.
This is to prepare for later further query record resolving.

This change also simplifies a query pool compare.

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28112>
This commit is contained in:
Yiwei Zhang
2024-03-09 22:49:54 -08:00
committed by Marge Bot
parent 2a7085584e
commit aabb52979a
3 changed files with 45 additions and 48 deletions
+8 -11
View File
@@ -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;
+12 -5
View File
@@ -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 */
+25 -32
View File
@@ -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;