On Sat, Sep 2, 2017 at 1:17 AM, Chad Versace <chadvers...@chromium.org> wrote:
> This patch adds a flag param to anv_bo_cache_import() and defines > exactly one flag, ANV_BO_CACHE_IMPORT_NO_CLOSE_FD. If set, the function > will not close the fd. > 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. > This prepares for implementing VK_ANDROID_native_buffer, which must not > close the imported fd. > --- > src/intel/vulkan/anv_allocator.c | 26 +++++++++++++++----------- > src/intel/vulkan/anv_device.c | 2 +- > src/intel/vulkan/anv_intel.c | 2 +- > src/intel/vulkan/anv_private.h | 10 +++++++++- > src/intel/vulkan/anv_queue.c | 2 +- > 5 files changed, 27 insertions(+), 15 deletions(-) > > diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_ > allocator.c > index 708b32b3452..28d00f4d0b2 100644 > --- a/src/intel/vulkan/anv_allocator.c > +++ b/src/intel/vulkan/anv_allocator.c > @@ -1270,7 +1270,9 @@ anv_bo_cache_alloc(struct anv_device *device, > VkResult > anv_bo_cache_import(struct anv_device *device, > struct anv_bo_cache *cache, > - int fd, uint64_t size, struct anv_bo **bo_out) > + int fd, uint64_t size, > + anv_bo_cache_import_flags_t flags, > + struct anv_bo **bo_out) > { > pthread_mutex_lock(&cache->mutex); > > @@ -1323,16 +1325,18 @@ 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); > + if (!(flags & ANV_BO_CACHE_IMPORT_NO_CLOSE_FD)) { > + /* 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; > > diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c > index d026b541b01..095e18ebb95 100644 > --- a/src/intel/vulkan/anv_device.c > +++ b/src/intel/vulkan/anv_device.c > @@ -1482,7 +1482,7 @@ VkResult anv_AllocateMemory( > > result = anv_bo_cache_import(device, &device->bo_cache, > fd_info->fd, > pAllocateInfo->allocationSize, > - &mem->bo); > + 0, &mem->bo); > if (result != VK_SUCCESS) > goto fail; > } else { > diff --git a/src/intel/vulkan/anv_intel.c b/src/intel/vulkan/anv_intel.c > index 172ae1dabf2..2653ff8e362 100644 > --- a/src/intel/vulkan/anv_intel.c > +++ b/src/intel/vulkan/anv_intel.c > @@ -52,7 +52,7 @@ VkResult anv_CreateDmaBufImageINTEL( > uint64_t size = (uint64_t)pCreateInfo->strideInBytes * > pCreateInfo->extent.height; > > result = anv_bo_cache_import(device, &device->bo_cache, > - pCreateInfo->fd, size, &mem->bo); > + pCreateInfo->fd, size, 0, &mem->bo); > if (result != VK_SUCCESS) > goto fail; > > diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_ > private.h > index d1c3d743061..014848fcef2 100644 > --- a/src/intel/vulkan/anv_private.h > +++ b/src/intel/vulkan/anv_private.h > @@ -586,6 +586,12 @@ struct anv_bo_cache { > pthread_mutex_t mutex; > }; > > +enum anv_bo_cache_import_bits { > + /** Do not close the fd after import. */ > + ANV_BO_CACHE_IMPORT_NO_CLOSE_FD = (1 << 0), > +}; > +typedef uint32_t anv_bo_cache_import_flags_t; > + > VkResult anv_bo_cache_init(struct anv_bo_cache *cache); > void anv_bo_cache_finish(struct anv_bo_cache *cache); > VkResult anv_bo_cache_alloc(struct anv_device *device, > @@ -593,7 +599,9 @@ VkResult anv_bo_cache_alloc(struct anv_device *device, > uint64_t size, struct anv_bo **bo); > VkResult anv_bo_cache_import(struct anv_device *device, > struct anv_bo_cache *cache, > - int fd, uint64_t size, struct anv_bo **bo); > + int fd, uint64_t size, > + anv_bo_cache_import_flags_t flags, > + struct anv_bo **bo); > VkResult anv_bo_cache_export(struct anv_device *device, > struct anv_bo_cache *cache, > struct anv_bo *bo_in, int *fd_out); > diff --git a/src/intel/vulkan/anv_queue.c b/src/intel/vulkan/anv_queue.c > index 21ca66757e6..c68657b6f5e 100644 > --- a/src/intel/vulkan/anv_queue.c > +++ b/src/intel/vulkan/anv_queue.c > @@ -1031,7 +1031,7 @@ VkResult anv_ImportSemaphoreFdKHR( > new_impl.type = ANV_SEMAPHORE_TYPE_BO; > > VkResult result = anv_bo_cache_import(device, &device->bo_cache, > - fd, 4096, &new_impl.bo); > + fd, 4096, 0, &new_impl.bo > ); > if (result != VK_SUCCESS) > return result; > > -- > 2.13.5 > > _______________________________________________ > mesa-dev mailing list > mesa-dev@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/mesa-dev >
_______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev