mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 11:48:06 +02:00
venus: rewrite qfb vn_feedback helpers
1. move record into alloc to simplify caller handling, which aligns with ffb and sfb as well 2. simplify locking to reduce lock overhead 3. remove unbalanced free from record helper 4. move reset to alloc Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28112>
This commit is contained in:
parent
aabb52979a
commit
a6bc116f84
3 changed files with 60 additions and 79 deletions
|
|
@ -648,106 +648,96 @@ vn_query_feedback_cmd_record_internal(VkCommandBuffer cmd_handle,
|
|||
offset, buf_size);
|
||||
}
|
||||
|
||||
static VkResult
|
||||
vn_query_feedback_cmd_record(VkDevice dev_handle,
|
||||
struct list_head *query_records,
|
||||
struct vn_query_feedback_cmd *qfb_cmd)
|
||||
{
|
||||
assert(!list_is_empty(query_records));
|
||||
|
||||
static const VkCommandBufferBeginInfo begin_info = {
|
||||
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
||||
};
|
||||
VkResult result = vn_BeginCommandBuffer(qfb_cmd->cmd_handle, &begin_info);
|
||||
if (result != VK_SUCCESS)
|
||||
return result;
|
||||
|
||||
list_for_each_entry_safe(struct vn_cmd_query_record, record, query_records,
|
||||
head) {
|
||||
vn_query_feedback_cmd_record_internal(
|
||||
qfb_cmd->cmd_handle, vn_query_pool_to_handle(record->query_pool),
|
||||
record->query, record->query_count, record->copy);
|
||||
}
|
||||
|
||||
return vn_EndCommandBuffer(qfb_cmd->cmd_handle);
|
||||
}
|
||||
|
||||
VkResult
|
||||
vn_query_feedback_cmd_alloc(VkDevice dev_handle,
|
||||
struct vn_feedback_cmd_pool *fb_cmd_pool,
|
||||
struct list_head *query_records,
|
||||
struct vn_query_feedback_cmd **out_qfb_cmd)
|
||||
{
|
||||
VkCommandPool cmd_pool_handle = fb_cmd_pool->pool_handle;
|
||||
const VkCommandBufferAllocateInfo info = {
|
||||
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
|
||||
.pNext = NULL,
|
||||
.commandPool = cmd_pool_handle,
|
||||
.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
|
||||
.commandBufferCount = 1,
|
||||
};
|
||||
struct vn_command_pool *cmd_pool =
|
||||
vn_command_pool_from_handle(cmd_pool_handle);
|
||||
struct vn_query_feedback_cmd *qfb_cmd = NULL;
|
||||
struct vn_query_feedback_cmd *qfb_cmd;
|
||||
VkResult result;
|
||||
|
||||
simple_mtx_lock(&fb_cmd_pool->mutex);
|
||||
if (!list_is_empty(&fb_cmd_pool->free_qfb_cmds)) {
|
||||
qfb_cmd = list_first_entry(&fb_cmd_pool->free_qfb_cmds,
|
||||
struct vn_query_feedback_cmd, head);
|
||||
list_del(&qfb_cmd->head);
|
||||
}
|
||||
simple_mtx_unlock(&fb_cmd_pool->mutex);
|
||||
|
||||
if (!qfb_cmd) {
|
||||
VkCommandBuffer qfb_cmd_handle;
|
||||
VkResult result;
|
||||
if (list_is_empty(&fb_cmd_pool->free_qfb_cmds)) {
|
||||
struct vn_command_pool *cmd_pool =
|
||||
vn_command_pool_from_handle(fb_cmd_pool->pool_handle);
|
||||
|
||||
qfb_cmd = vk_alloc(&cmd_pool->allocator, sizeof(*qfb_cmd),
|
||||
VN_DEFAULT_ALIGN, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
||||
if (!qfb_cmd)
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
if (!qfb_cmd) {
|
||||
result = VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
goto out_unlock;
|
||||
}
|
||||
|
||||
simple_mtx_lock(&fb_cmd_pool->mutex);
|
||||
const VkCommandBufferAllocateInfo info = {
|
||||
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
|
||||
.commandPool = fb_cmd_pool->pool_handle,
|
||||
.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
|
||||
.commandBufferCount = 1,
|
||||
};
|
||||
VkCommandBuffer qfb_cmd_handle;
|
||||
result = vn_AllocateCommandBuffers(dev_handle, &info, &qfb_cmd_handle);
|
||||
simple_mtx_unlock(&fb_cmd_pool->mutex);
|
||||
|
||||
if (result != VK_SUCCESS) {
|
||||
vk_free(&cmd_pool->allocator, qfb_cmd);
|
||||
return result;
|
||||
goto out_unlock;
|
||||
}
|
||||
|
||||
qfb_cmd->fb_cmd_pool = fb_cmd_pool;
|
||||
qfb_cmd->cmd_handle = qfb_cmd_handle;
|
||||
} else {
|
||||
qfb_cmd = list_first_entry(&fb_cmd_pool->free_qfb_cmds,
|
||||
struct vn_query_feedback_cmd, head);
|
||||
list_del(&qfb_cmd->head);
|
||||
vn_ResetCommandBuffer(qfb_cmd->cmd_handle, 0);
|
||||
}
|
||||
|
||||
result = vn_query_feedback_cmd_record(dev_handle, query_records, qfb_cmd);
|
||||
if (result != VK_SUCCESS) {
|
||||
list_add(&qfb_cmd->head, &fb_cmd_pool->free_qfb_cmds);
|
||||
goto out_unlock;
|
||||
}
|
||||
|
||||
*out_qfb_cmd = qfb_cmd;
|
||||
|
||||
return VK_SUCCESS;
|
||||
out_unlock:
|
||||
simple_mtx_unlock(&fb_cmd_pool->mutex);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
vn_query_feedback_cmd_free(struct vn_query_feedback_cmd *qfb_cmd)
|
||||
{
|
||||
simple_mtx_lock(&qfb_cmd->fb_cmd_pool->mutex);
|
||||
vn_ResetCommandBuffer(qfb_cmd->cmd_handle, 0);
|
||||
list_add(&qfb_cmd->head, &qfb_cmd->fb_cmd_pool->free_qfb_cmds);
|
||||
simple_mtx_unlock(&qfb_cmd->fb_cmd_pool->mutex);
|
||||
}
|
||||
|
||||
VkResult
|
||||
vn_query_feedback_cmd_record(VkDevice dev_handle,
|
||||
struct list_head *resolved_query_records,
|
||||
struct vn_query_feedback_cmd *qfb_cmd)
|
||||
{
|
||||
static const VkCommandBufferBeginInfo begin_info = {
|
||||
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
||||
};
|
||||
VkResult result;
|
||||
|
||||
simple_mtx_lock(&qfb_cmd->fb_cmd_pool->mutex);
|
||||
|
||||
result = vn_BeginCommandBuffer(qfb_cmd->cmd_handle, &begin_info);
|
||||
if (result != VK_SUCCESS) {
|
||||
vn_FreeCommandBuffers(dev_handle, qfb_cmd->fb_cmd_pool->pool_handle, 1,
|
||||
&qfb_cmd->cmd_handle);
|
||||
goto out_unlock;
|
||||
}
|
||||
|
||||
list_for_each_entry_safe(struct vn_cmd_query_record, record,
|
||||
resolved_query_records, head) {
|
||||
vn_query_feedback_cmd_record_internal(
|
||||
qfb_cmd->cmd_handle, vn_query_pool_to_handle(record->query_pool),
|
||||
record->query, record->query_count, record->copy);
|
||||
}
|
||||
|
||||
result = vn_EndCommandBuffer(qfb_cmd->cmd_handle);
|
||||
if (result != VK_SUCCESS) {
|
||||
vn_FreeCommandBuffers(dev_handle, qfb_cmd->fb_cmd_pool->pool_handle, 1,
|
||||
&qfb_cmd->cmd_handle);
|
||||
goto out_unlock;
|
||||
}
|
||||
|
||||
out_unlock:
|
||||
simple_mtx_unlock(&qfb_cmd->fb_cmd_pool->mutex);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
VkResult
|
||||
vn_feedback_cmd_alloc(VkDevice dev_handle,
|
||||
struct vn_feedback_cmd_pool *fb_cmd_pool,
|
||||
|
|
|
|||
|
|
@ -163,16 +163,12 @@ vn_semaphore_feedback_cmd_free(struct vn_device *dev,
|
|||
VkResult
|
||||
vn_query_feedback_cmd_alloc(VkDevice dev_handle,
|
||||
struct vn_feedback_cmd_pool *fb_cmd_pool,
|
||||
struct list_head *resolved_query_records,
|
||||
struct vn_query_feedback_cmd **out_qfb_cmd);
|
||||
|
||||
void
|
||||
vn_query_feedback_cmd_free(struct vn_query_feedback_cmd *qfb_cmd);
|
||||
|
||||
VkResult
|
||||
vn_query_feedback_cmd_record(VkDevice dev_handle,
|
||||
struct list_head *resolved_query_records,
|
||||
struct vn_query_feedback_cmd *qfb_cmd);
|
||||
|
||||
VkResult
|
||||
vn_feedback_cmd_alloc(VkDevice dev_handle,
|
||||
struct vn_feedback_cmd_pool *fb_cmd_pool,
|
||||
|
|
|
|||
|
|
@ -630,13 +630,8 @@ vn_combine_query_records_and_record_feedback(
|
|||
* 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);
|
||||
}
|
||||
result = vn_query_feedback_cmd_alloc(dev_handle, fb_cmd_pool,
|
||||
&resolved_records, &qfb_cmd);
|
||||
}
|
||||
|
||||
out_free_query_records:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue