anv: fix wsi image aliasing

The private BO can get removed due to WSI aliasing and that breaks the
submission code (expecting one).

Delay the registration on the device to when the image actually gets
bound and there is a private BO.

Fixes: b21e62b71a ("anv: avoid leaking private binding for aliased wsi image")
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36474>
This commit is contained in:
Lionel Landwerlin 2025-07-30 22:00:16 +03:00 committed by Marge Bot
parent 19d2f5e086
commit 9efb3ee511
2 changed files with 15 additions and 8 deletions

View file

@ -1486,11 +1486,6 @@ alloc_private_binding(struct anv_device *device,
binding->memory_range.size, 0, 0,
&binding->address.bo);
ANV_DMR_BO_ALLOC(&image->vk.base, binding->address.bo, result);
if (result == VK_SUCCESS) {
pthread_mutex_lock(&device->mutex);
list_addtail(&image->link, &device->image_private_objects);
pthread_mutex_unlock(&device->mutex);
}
return result;
}
@ -2027,9 +2022,11 @@ anv_image_finish(struct anv_image *image)
struct anv_bo *private_bo = image->bindings[ANV_IMAGE_MEMORY_BINDING_PRIVATE].address.bo;
if (private_bo) {
pthread_mutex_lock(&device->mutex);
list_del(&image->link);
pthread_mutex_unlock(&device->mutex);
if (image->device_registered) {
pthread_mutex_lock(&device->mutex);
list_del(&image->link);
pthread_mutex_unlock(&device->mutex);
}
ANV_DMR_BO_FREE(&image->vk.base, private_bo);
anv_device_release_bo(device, private_bo);
}
@ -2931,6 +2928,14 @@ anv_bind_image_memory(struct anv_device *device,
}
}
if (image->bindings[ANV_IMAGE_MEMORY_BINDING_PRIVATE].address.bo != NULL &&
!image->device_registered) {
pthread_mutex_lock(&device->mutex);
list_addtail(&image->link, &device->image_private_objects);
image->device_registered = true;
pthread_mutex_unlock(&device->mutex);
}
if (bind_status)
*bind_status->pResult = result;

View file

@ -5657,6 +5657,8 @@ struct anv_image {
/* Link in the anv_device.image_private_objects list */
struct list_head link;
/* Whether the image was added to anv_device.image_private_objects list */
bool device_registered;
struct anv_image_memory_range av1_cdf_table;
};