diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index 7b1ca50179d..db706ac54f4 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -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; diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 8205d8cb121..3d558252306 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -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; };