<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sat, Sep 2, 2017 at 1:17 AM, Chad Versace <span dir="ltr"><<a href="mailto:chadversary@chromium.org" target="_blank">chadversary@chromium.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This patch adds a flag param to anv_bo_cache_import() and defines<br>
exactly one flag, ANV_BO_CACHE_IMPORT_NO_CLOSE_<wbr>FD. If set, the function<br>
will not close the fd.<br></blockquote><div><br></div><div>The other option (which I think I like better) would be to move the call to close(fd) to the two callers of anv_bo_cache_import.  That puts Vulkan extension API details with the extension implementation and not in the bo cache.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
This prepares for implementing VK_ANDROID_native_buffer, which must not<br>
close the imported fd.<br>
---<br>
 src/intel/vulkan/anv_<wbr>allocator.c | 26 +++++++++++++++-----------<br>
 src/intel/vulkan/anv_device.c    |  2 +-<br>
 src/intel/vulkan/anv_intel.c     |  2 +-<br>
 src/intel/vulkan/anv_private.h   | 10 +++++++++-<br>
 src/intel/vulkan/anv_queue.c     |  2 +-<br>
 5 files changed, 27 insertions(+), 15 deletions(-)<br>
<br>
diff --git a/src/intel/vulkan/anv_<wbr>allocator.c b/src/intel/vulkan/anv_<wbr>allocator.c<br>
index 708b32b3452..28d00f4d0b2 100644<br>
--- a/src/intel/vulkan/anv_<wbr>allocator.c<br>
+++ b/src/intel/vulkan/anv_<wbr>allocator.c<br>
@@ -1270,7 +1270,9 @@ anv_bo_cache_alloc(struct anv_device *device,<br>
 VkResult<br>
 anv_bo_cache_import(struct anv_device *device,<br>
                     struct anv_bo_cache *cache,<br>
-                    int fd, uint64_t size, struct anv_bo **bo_out)<br>
+                    int fd, uint64_t size,<br>
+                    anv_bo_cache_import_flags_t flags,<br>
+                    struct anv_bo **bo_out)<br>
 {<br>
    pthread_mutex_lock(&cache-><wbr>mutex);<br>
<br>
@@ -1323,16 +1325,18 @@ anv_bo_cache_import(struct anv_device *device,<br>
<br>
    pthread_mutex_unlock(&cache-><wbr>mutex);<br>
<br>
-   /* From the Vulkan spec:<br>
-    *<br>
-    *    "Importing memory from a file descriptor transfers ownership of<br>
-    *    the file descriptor from the application to the Vulkan<br>
-    *    implementation. The application must not perform any operations on<br>
-    *    the file descriptor after a successful import."<br>
-    *<br>
-    * If the import fails, we leave the file descriptor open.<br>
-    */<br>
-   close(fd);<br>
+   if (!(flags & ANV_BO_CACHE_IMPORT_NO_CLOSE_<wbr>FD)) {<br>
+      /* From the Vulkan spec:<br>
+       *<br>
+       *    "Importing memory from a file descriptor transfers ownership of<br>
+       *    the file descriptor from the application to the Vulkan<br>
+       *    implementation. The application must not perform any operations on<br>
+       *    the file descriptor after a successful import."<br>
+       *<br>
+       * If the import fails, we leave the file descriptor open.<br>
+       */<br>
+      close(fd);<br>
+   }<br>
<br>
    *bo_out = &bo->bo;<br>
<br>
diff --git a/src/intel/vulkan/anv_device.<wbr>c b/src/intel/vulkan/anv_device.<wbr>c<br>
index d026b541b01..095e18ebb95 100644<br>
--- a/src/intel/vulkan/anv_device.<wbr>c<br>
+++ b/src/intel/vulkan/anv_device.<wbr>c<br>
@@ -1482,7 +1482,7 @@ VkResult anv_AllocateMemory(<br>
<br>
       result = anv_bo_cache_import(device, &device->bo_cache,<br>
                                    fd_info->fd, pAllocateInfo->allocationSize,<br>
-                                   &mem->bo);<br>
+                                   0, &mem->bo);<br>
       if (result != VK_SUCCESS)<br>
          goto fail;<br>
    } else {<br>
diff --git a/src/intel/vulkan/anv_intel.c b/src/intel/vulkan/anv_intel.c<br>
index 172ae1dabf2..2653ff8e362 100644<br>
--- a/src/intel/vulkan/anv_intel.c<br>
+++ b/src/intel/vulkan/anv_intel.c<br>
@@ -52,7 +52,7 @@ VkResult anv_CreateDmaBufImageINTEL(<br>
    uint64_t size = (uint64_t)pCreateInfo-><wbr>strideInBytes * pCreateInfo->extent.height;<br>
<br>
    result = anv_bo_cache_import(device, &device->bo_cache,<br>
-                                pCreateInfo->fd, size, &mem->bo);<br>
+                                pCreateInfo->fd, size, 0, &mem->bo);<br>
    if (result != VK_SUCCESS)<br>
       goto fail;<br>
<br>
diff --git a/src/intel/vulkan/anv_<wbr>private.h b/src/intel/vulkan/anv_<wbr>private.h<br>
index d1c3d743061..014848fcef2 100644<br>
--- a/src/intel/vulkan/anv_<wbr>private.h<br>
+++ b/src/intel/vulkan/anv_<wbr>private.h<br>
@@ -586,6 +586,12 @@ struct anv_bo_cache {<br>
    pthread_mutex_t mutex;<br>
 };<br>
<br>
+enum anv_bo_cache_import_bits {<br>
+   /** Do not close the fd after import. */<br>
+   ANV_BO_CACHE_IMPORT_NO_CLOSE_<wbr>FD = (1 << 0),<br>
+};<br>
+typedef uint32_t anv_bo_cache_import_flags_t;<br>
+<br>
 VkResult anv_bo_cache_init(struct anv_bo_cache *cache);<br>
 void anv_bo_cache_finish(struct anv_bo_cache *cache);<br>
 VkResult anv_bo_cache_alloc(struct anv_device *device,<br>
@@ -593,7 +599,9 @@ VkResult anv_bo_cache_alloc(struct anv_device *device,<br>
                             uint64_t size, struct anv_bo **bo);<br>
 VkResult anv_bo_cache_import(struct anv_device *device,<br>
                              struct anv_bo_cache *cache,<br>
-                             int fd, uint64_t size, struct anv_bo **bo);<br>
+                             int fd, uint64_t size,<br>
+                             anv_bo_cache_import_flags_t flags,<br>
+                             struct anv_bo **bo);<br>
 VkResult anv_bo_cache_export(struct anv_device *device,<br>
                              struct anv_bo_cache *cache,<br>
                              struct anv_bo *bo_in, int *fd_out);<br>
diff --git a/src/intel/vulkan/anv_queue.c b/src/intel/vulkan/anv_queue.c<br>
index 21ca66757e6..c68657b6f5e 100644<br>
--- a/src/intel/vulkan/anv_queue.c<br>
+++ b/src/intel/vulkan/anv_queue.c<br>
@@ -1031,7 +1031,7 @@ VkResult anv_ImportSemaphoreFdKHR(<br>
          new_impl.type = ANV_SEMAPHORE_TYPE_BO;<br>
<br>
          VkResult result = anv_bo_cache_import(device, &device->bo_cache,<br>
-                                               fd, 4096, &<a href="http://new_impl.bo" rel="noreferrer" target="_blank">new_impl.bo</a>);<br>
+                                               fd, 4096, 0, &<a href="http://new_impl.bo" rel="noreferrer" target="_blank">new_impl.bo</a>);<br>
          if (result != VK_SUCCESS)<br>
             return result;<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
2.13.5<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>