Mesa (master): anv: Move close(fd) from anv_bo_cache_import to its callers (v2)
Chad Versace
chadversary at kemper.freedesktop.org
Tue Oct 17 18:26:54 UTC 2017
Module: Mesa
Branch: master
Commit: eb69a61806a6bee22f2306420314ac712f4c6e1e
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=eb69a61806a6bee22f2306420314ac712f4c6e1e
Author: Chad Versace <chadversary at chromium.org>
Date: Mon Sep 11 16:41:21 2017 -0700
anv: Move close(fd) from anv_bo_cache_import to its callers (v2)
This will allow us to implement VK_ANDROID_native_buffer without dup'ing
the fd. We must close the fd in VK_KHR_external_memory_fd, but we should
not in VK_ANDROID_native_buffer.
v2:
- Add missing close(fd) for case
VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR, subcase
ANV_SEMAPHORE_TYPE_BO.
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
---
src/intel/vulkan/anv_allocator.c | 12 ------------
src/intel/vulkan/anv_device.c | 11 +++++++++++
src/intel/vulkan/anv_intel.c | 2 ++
src/intel/vulkan/anv_queue.c | 22 +++++++++++-----------
4 files changed, 24 insertions(+), 23 deletions(-)
diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_allocator.c
index 0f123563f7..401cea40e6 100644
--- a/src/intel/vulkan/anv_allocator.c
+++ b/src/intel/vulkan/anv_allocator.c
@@ -1324,18 +1324,6 @@ anv_bo_cache_import(struct anv_device *device,
}
pthread_mutex_unlock(&cache->mutex);
-
- /* From the Vulkan spec:
- *
- * "Importing memory from a file descriptor transfers ownership of
- * the file descriptor from the application to the Vulkan
- * implementation. The application must not perform any operations on
- * the file descriptor after a successful import."
- *
- * If the import fails, we leave the file descriptor open.
- */
- close(fd);
-
*bo_out = &bo->bo;
return VK_SUCCESS;
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index 2c10a2fe7f..1634b5158c 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -1547,6 +1547,17 @@ VkResult anv_AllocateMemory(
&mem->bo);
if (result != VK_SUCCESS)
goto fail;
+
+ /* From the Vulkan spec:
+ *
+ * "Importing memory from a file descriptor transfers ownership of
+ * the file descriptor from the application to the Vulkan
+ * implementation. The application must not perform any operations on
+ * the file descriptor after a successful import."
+ *
+ * If the import fails, we leave the file descriptor open.
+ */
+ close(fd_info->fd);
} else {
result = anv_bo_cache_alloc(device, &device->bo_cache,
pAllocateInfo->allocationSize,
diff --git a/src/intel/vulkan/anv_intel.c b/src/intel/vulkan/anv_intel.c
index 9f8cd92734..d6bad44091 100644
--- a/src/intel/vulkan/anv_intel.c
+++ b/src/intel/vulkan/anv_intel.c
@@ -71,6 +71,8 @@ VkResult anv_CreateDmaBufImageINTEL(
if (result != VK_SUCCESS)
goto fail;
+ close(pCreateInfo->fd);
+
image = anv_image_from_handle(image_h);
result = anv_bo_cache_import(device, &device->bo_cache,
diff --git a/src/intel/vulkan/anv_queue.c b/src/intel/vulkan/anv_queue.c
index aff7c53119..7e675e2274 100644
--- a/src/intel/vulkan/anv_queue.c
+++ b/src/intel/vulkan/anv_queue.c
@@ -1019,17 +1019,6 @@ VkResult anv_ImportSemaphoreFdKHR(
new_impl.syncobj = anv_gem_syncobj_fd_to_handle(device, fd);
if (!new_impl.syncobj)
return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR);
-
- /* From the Vulkan spec:
- *
- * "Importing semaphore state from a file descriptor transfers
- * ownership of the file descriptor from the application to the
- * Vulkan implementation. The application must not perform any
- * operations on the file descriptor after a successful import."
- *
- * If the import fails, we leave the file descriptor open.
- */
- close(pImportSemaphoreFdInfo->fd);
} else {
new_impl.type = ANV_SEMAPHORE_TYPE_BO;
@@ -1043,6 +1032,17 @@ VkResult anv_ImportSemaphoreFdKHR(
*/
assert(!(new_impl.bo->flags & EXEC_OBJECT_ASYNC));
}
+
+ /* From the Vulkan spec:
+ *
+ * "Importing semaphore state from a file descriptor transfers
+ * ownership of the file descriptor from the application to the
+ * Vulkan implementation. The application must not perform any
+ * operations on the file descriptor after a successful import."
+ *
+ * If the import fails, we leave the file descriptor open.
+ */
+ close(fd);
break;
case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR:
More information about the mesa-commit
mailing list