[Mesa-dev] [PATCH 10/14] anv: Move close(fd) from anv_bo_cache_import to its callers

Chad Versace chad at kiwitree.net
Thu Sep 28 00:11:56 UTC 2017


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.
---
 src/intel/vulkan/anv_allocator.c | 12 ------------
 src/intel/vulkan/anv_device.c    | 11 +++++++++++
 src/intel/vulkan/anv_intel.c     |  2 ++
 3 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_allocator.c
index be750adeb52..2cf1130bf29 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 f04be4fce22..5c20f80024b 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -1539,6 +1539,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 991a93542d2..be6568468e1 100644
--- a/src/intel/vulkan/anv_intel.c
+++ b/src/intel/vulkan/anv_intel.c
@@ -79,6 +79,8 @@ VkResult anv_CreateDmaBufImageINTEL(
       }},
       pAllocator, &image_h);
 
+   close(pCreateInfo->fd);
+
    image = anv_image_from_handle(image_h);
    image->bo = mem->bo;
    image->offset = 0;
-- 
2.13.5



More information about the mesa-dev mailing list