anv: fix nested command buffer relocations

When executing 3 command buffers :

vkCmdExecuteCommands(CB_B, CB_C);
vkCmdExecuteCommands(CB_A, CB_B);

vkQueueSubmit(CB_A);

We're not transfering correctly the relocations of CB_C from CB_B to
CB_A.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: mesa-stable
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
(cherry picked from commit e64889635c)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40092>
This commit is contained in:
Lionel Landwerlin 2025-05-26 08:02:04 +00:00 committed by Eric Engestrom
parent f8ce75c40c
commit 12da136c07
2 changed files with 22 additions and 16 deletions

View file

@ -5634,7 +5634,7 @@
"description": "anv: fix nested command buffer relocations",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": null,
"notes": null

View file

@ -1123,19 +1123,15 @@ anv_cmd_buffer_end_batch_buffer(struct anv_cmd_buffer *cmd_buffer)
cmd_buffer->total_batch_size += batch_bo->length;
}
static VkResult
anv_cmd_buffer_add_seen_bbos(struct anv_cmd_buffer *cmd_buffer,
struct list_head *list)
static void
anv_cmd_buffer_add_seen_bbos(struct anv_cmd_buffer *primary,
struct anv_cmd_buffer *secondary)
{
list_for_each_entry(struct anv_batch_bo, bbo, list, link) {
struct anv_batch_bo **bbo_ptr = u_vector_add(&cmd_buffer->seen_bbos);
if (bbo_ptr == NULL)
return vk_error(cmd_buffer, VK_ERROR_OUT_OF_HOST_MEMORY);
*bbo_ptr = bbo;
struct anv_batch_bo **bbo;
u_vector_foreach(bbo, &secondary->seen_bbos) {
struct anv_batch_bo **bbo_ptr = u_vector_add(&primary->seen_bbos);
*bbo_ptr = *bbo;
}
return VK_SUCCESS;
}
void
@ -1164,7 +1160,7 @@ anv_cmd_buffer_add_secondary(struct anv_cmd_buffer *primary,
*/
anv_batch_bo_link(primary, last_bbo, this_bbo, offset);
anv_cmd_buffer_add_seen_bbos(primary, &secondary->batch_bos);
anv_cmd_buffer_add_seen_bbos(primary, secondary);
break;
}
case ANV_CMD_BUFFER_EXEC_MODE_COPY_AND_CHAIN: {
@ -1172,10 +1168,20 @@ anv_cmd_buffer_add_secondary(struct anv_cmd_buffer *primary,
VkResult result = anv_batch_bo_list_clone(&secondary->batch_bos,
secondary,
&copy_list);
if (result != VK_SUCCESS)
if (result != VK_SUCCESS) {
anv_batch_set_error(&primary->batch, result);
return; /* FIXME */
}
anv_cmd_buffer_add_seen_bbos(primary, &copy_list);
list_for_each_entry(struct anv_batch_bo, bbo, &copy_list, link) {
struct anv_batch_bo **bbo_ptr = u_vector_add(&primary->seen_bbos);
if (bbo_ptr == NULL) {
anv_batch_set_error(&primary->batch,
VK_ERROR_OUT_OF_HOST_MEMORY);
return;
}
*bbo_ptr = bbo;
}
struct anv_batch_bo *first_bbo =
list_first_entry(&copy_list, struct anv_batch_bo, link);
@ -1200,7 +1206,7 @@ anv_cmd_buffer_add_secondary(struct anv_cmd_buffer *primary,
(struct anv_address) { .bo = first_bbo->bo },
secondary->return_addr);
anv_cmd_buffer_add_seen_bbos(primary, &secondary->batch_bos);
anv_cmd_buffer_add_seen_bbos(primary, secondary);
break;
}
default: