summaryrefslogtreecommitdiffstats
path: root/src/intel
diff options
context:
space:
mode:
authorLionel Landwerlin <[email protected]>2019-10-26 18:59:59 +0300
committerLionel Landwerlin <[email protected]>2019-11-11 21:46:51 +0000
commit3e223635376d7a5cfbbd2eccfe1d8ad2620fdfd2 (patch)
tree5d2979e05bfde2e9aa0898b7af70dcad965d086b /src/intel
parent3da798c9f1b463f514cf058577fe38561810ba74 (diff)
anv: refcount semaphores
Delayed submissions required by timeline semaphores mean we need to be able to update the sync fd backed semaphores in a delayed fashion. This could mean a race between the application destroying the semaphore and the submission code trying to update it with the new sync fd. This change prepares semaphores to be refcounted, we'll most likely only take a reference for cases where we signal a sync fd semaphore. Signed-off-by: Lionel Landwerlin <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]>
Diffstat (limited to 'src/intel')
-rw-r--r--src/intel/vulkan/anv_private.h2
-rw-r--r--src/intel/vulkan/anv_queue.c30
2 files changed, 26 insertions, 6 deletions
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index ff28d897a21..3aae01e6b2f 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -2806,6 +2806,8 @@ struct anv_semaphore_impl {
};
struct anv_semaphore {
+ uint32_t refcount;
+
/* Permanent semaphore state. Every semaphore has some form of permanent
* state (type != ANV_SEMAPHORE_TYPE_NONE). This may be a BO to fence on
* (for cross-process semaphores0 or it could just be a dummy for use
diff --git a/src/intel/vulkan/anv_queue.c b/src/intel/vulkan/anv_queue.c
index 8bf58e3214a..74f3a3c4254 100644
--- a/src/intel/vulkan/anv_queue.c
+++ b/src/intel/vulkan/anv_queue.c
@@ -947,11 +947,13 @@ VkResult anv_CreateSemaphore(
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO);
- semaphore = vk_alloc2(&device->alloc, pAllocator, sizeof(*semaphore), 8,
- VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+ semaphore = vk_alloc(&device->alloc, sizeof(*semaphore), 8,
+ VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
if (semaphore == NULL)
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
+ p_atomic_set(&semaphore->refcount, 1);
+
const VkExportSemaphoreCreateInfo *export =
vk_find_struct_const(pCreateInfo->pNext, EXPORT_SEMAPHORE_CREATE_INFO);
VkExternalSemaphoreHandleTypeFlags handleTypes =
@@ -1049,6 +1051,25 @@ anv_semaphore_reset_temporary(struct anv_device *device,
anv_semaphore_impl_cleanup(device, &semaphore->temporary);
}
+static struct anv_semaphore *
+anv_semaphore_ref(struct anv_semaphore *semaphore)
+{
+ assert(semaphore->refcount);
+ p_atomic_inc(&semaphore->refcount);
+ return semaphore;
+}
+
+static void
+anv_semaphore_unref(struct anv_device *device, struct anv_semaphore *semaphore)
+{
+ if (!p_atomic_dec_zero(&semaphore->refcount))
+ return;
+
+ anv_semaphore_impl_cleanup(device, &semaphore->temporary);
+ anv_semaphore_impl_cleanup(device, &semaphore->permanent);
+ vk_free(&device->alloc, semaphore);
+}
+
void anv_DestroySemaphore(
VkDevice _device,
VkSemaphore _semaphore,
@@ -1060,10 +1081,7 @@ void anv_DestroySemaphore(
if (semaphore == NULL)
return;
- anv_semaphore_impl_cleanup(device, &semaphore->temporary);
- anv_semaphore_impl_cleanup(device, &semaphore->permanent);
-
- vk_free2(&device->alloc, pAllocator, semaphore);
+ anv_semaphore_unref(device, semaphore);
}
void anv_GetPhysicalDeviceExternalSemaphoreProperties(