[Mesa-dev] [RFC PATCH 08/13] RFC: anv: Implement VK_MESAX_external_memory_dma_buf

Jason Ekstrand jason at jlekstrand.net
Tue Mar 7 22:54:12 UTC 2017


On Mon, Mar 6, 2017 at 12:40 PM, Chad Versace <chadversary at chromium.org>
wrote:

> For now, we support dma_bufs only for VkBuffers.  The
> VK_MESAX_external_memory_dma_buf spec allows us to support dma_buf
> VkImages, but we choose to defer that support until
> VK_MESAX_external_image_dma_buf.
> ---
>  src/intel/vulkan/anv_device.c           | 28 +++++++++++++++++++---------
>  src/intel/vulkan/anv_entrypoints_gen.py |  1 +
>  src/intel/vulkan/anv_formats.c          | 22 +++++++++++++++++++---
>  src/intel/vulkan/anv_private.h          |  4 ++++
>  4 files changed, 43 insertions(+), 12 deletions(-)
>
> diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
> index 1374118c83f..cc5f57b0f86 100644
> --- a/src/intel/vulkan/anv_device.c
> +++ b/src/intel/vulkan/anv_device.c
> @@ -322,6 +322,10 @@ static const VkExtensionProperties
> device_extensions[] = {
>        .extensionName = VK_KHX_EXTERNAL_MEMORY_FD_EXTENSION_NAME,
>        .specVersion = 1,
>     },
> +   {
> +      .extensionName = VK_MESAX_EXTERNAL_MEMORY_DMA_BUF_EXTENSION_NAME,
> +      .specVersion = 0,
> +   },
>  };
>
>  static void *
> @@ -1398,11 +1402,7 @@ VkResult anv_AllocateMemory(
>      * ignored.
>      */
>     if (fd_info && fd_info->handleType) {
> -      /* At the moment, we only support the OPAQUE_FD memory type which is
> -       * just a GEM buffer.
> -       */
> -      assert(fd_info->handleType ==
> -             VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHX);
> +      assert((fd_info->handleType & ~ANV_SUPPORTED_MEMORY_HANDLE_TYPES)
> == 0);
>
>        uint32_t gem_handle = anv_gem_fd_to_handle(device, fd_info->fd);
>        if (!gem_handle) {
> @@ -1450,8 +1450,7 @@ VkResult anv_GetMemoryFdKHX(
>     ANV_FROM_HANDLE(anv_device, dev, device_h);
>     ANV_FROM_HANDLE(anv_device_memory, mem, memory_h);
>
> -   /* We support only one handle type. */
> -   assert(handleType == VK_EXTERNAL_MEMORY_HANDLE_
> TYPE_OPAQUE_FD_BIT_KHX);
> +   assert((handleType & ~ANV_SUPPORTED_MEMORY_HANDLE_TYPES) == 0);
>
>     int fd = anv_gem_handle_to_fd(dev, mem->bo.gem_handle);
>     if (fd == -1)
> @@ -1468,13 +1467,24 @@ VkResult anv_GetMemoryFdPropertiesKHX(
>      int                                         fd,
>      VkMemoryFdPropertiesKHX*                    pMemoryFdProperties)
>  {
> +   ANV_FROM_HANDLE(anv_device, device, device_h);
> +
> +   if (fd == -1)
> +      return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHX;
> +
>     /* The valid usage section for this function says:
>      *
>      *    "handleType must not be one of the handle types defined as
> opaque."
>      *
> -    * Since we only handle opaque handles for now, there are no FD
> properties.
> +    * The only non-opaque fd type we support is dma_buf.
>      */
> -   return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHX;
> +   if (handleType != VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_MESAX)
> +      return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHX;
> +
> +   /* We support exactly one memory type on LLC, two on non-LLC.  */
> +   pMemoryFdProperties->memoryTypeBits = device->info.has_llc ? 1 : 3;
> +
> +   return VK_SUCCESS;
>  }
>
>  void anv_FreeMemory(
> diff --git a/src/intel/vulkan/anv_entrypoints_gen.py
> b/src/intel/vulkan/anv_entrypoints_gen.py
> index eb960b45986..7ba070be5e4 100644
> --- a/src/intel/vulkan/anv_entrypoints_gen.py
> +++ b/src/intel/vulkan/anv_entrypoints_gen.py
> @@ -43,6 +43,7 @@ supported_extensions = [
>     'VK_KHX_external_memory',
>     'VK_KHX_external_memory_capabilities',
>     'VK_KHX_external_memory_fd',
> +   'VK_MESAX_external_memory_dma_buf',
>  ]
>
>  # We generate a static hash table for entry point lookup
> diff --git a/src/intel/vulkan/anv_formats.c b/src/intel/vulkan/anv_
> formats.c
> index eade36eaf6f..cbbbd0bc0d8 100644
> --- a/src/intel/vulkan/anv_formats.c
> +++ b/src/intel/vulkan/anv_formats.c
> @@ -663,7 +663,7 @@ VkResult anv_GetPhysicalDeviceImageFormatProperties(
>                                            pImageFormatProperties);
>  }
>
> -static const VkExternalMemoryPropertiesKHX prime_fd_props = {
> +static const VkExternalMemoryPropertiesKHX opaque_fd_props = {
>     /* If we can handle external, then we can both import and export it. */
>     .externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT_KHX
> |
>                               VK_EXTERNAL_MEMORY_FEATURE_
> IMPORTABLE_BIT_KHX,
> @@ -674,6 +674,17 @@ static const VkExternalMemoryPropertiesKHX
> prime_fd_props = {
>        VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHX,
>  };
>
> +static const VkExternalMemoryPropertiesKHX dma_buf_mem_props = {
> +   /* If we can handle external, then we can both import and export it. */
> +   .externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT_KHX
> |
> +                             VK_EXTERNAL_MEMORY_FEATURE_
> IMPORTABLE_BIT_KHX,
> +   /* For the moment, let's not support mixing and matching */
> +   .exportFromImportedHandleTypes =
> +      VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_MESAX,
> +   .compatibleHandleTypes =
> +      VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_MESAX,
> +};
>

These two can import/export to/from each other just fine.  I don't see why
we need to separate them.


> +
>  VkResult anv_GetPhysicalDeviceImageFormatProperties2KHR(
>      VkPhysicalDevice                            physicalDevice,
>      const VkPhysicalDeviceImageFormatInfo2KHR*  base_info,
> @@ -722,8 +733,10 @@ VkResult anv_GetPhysicalDeviceImageFormatPr
> operties2KHR(
>     if (external_info && external_info->handleType != 0) {
>        switch (external_info->handleType) {
>        case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHX:
> -         external_props->externalMemoryProperties = prime_fd_props;
> +         external_props->externalMemoryProperties = opaque_fd_props;
>           break;
> +      case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_MESAX:
> +         /* Fallthrough. We support dma_buf for VkBuffer but not yet
> VkImage. */
>        default:
>           /* From the Vulkan 1.0.42 spec:
>            *
> @@ -802,7 +815,10 @@ void anv_GetPhysicalDeviceExternalBuffe
> rPropertiesKHX(
>
>     switch (pExternalBufferInfo->handleType) {
>     case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHX:
> -      pExternalBufferProperties->externalMemoryProperties =
> prime_fd_props;
> +      pExternalBufferProperties->externalMemoryProperties =
> opaque_fd_props;
> +      return;
> +   case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_MESAX:
> +      pExternalBufferProperties->externalMemoryProperties =
> dma_buf_mem_props;
>        return;
>     default:
>        goto unsupported;
> diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_
> private.h
> index 01aeb216597..ac922e7cfc6 100644
> --- a/src/intel/vulkan/anv_private.h
> +++ b/src/intel/vulkan/anv_private.h
> @@ -834,6 +834,10 @@ struct anv_device_memory {
>     void *                                       map;
>  };
>
> +#define ANV_SUPPORTED_MEMORY_HANDLE_TYPES \
> +   (VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHX | \
> +    VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_MESAX)
> +
>  /**
>   * Header for Vertex URB Entry (VUE)
>   */
> --
> 2.12.0
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170307/1eaf122a/attachment-0001.html>


More information about the mesa-dev mailing list