[Mesa-dev] [RFC 5/7] anv/android: add ahardwarebuffer external memory properties

Tapani Pälli tapani.palli at intel.com
Mon Aug 20 08:15:08 UTC 2018



On 08/17/2018 12:15 PM, Tapani Pälli wrote:
> Signed-off-by: Tapani Pälli <tapani.palli at intel.com>
> ---
>   src/intel/vulkan/anv_formats.c | 19 ++++++++++++++++++-
>   1 file changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/src/intel/vulkan/anv_formats.c b/src/intel/vulkan/anv_formats.c
> index dc398306a70..f1506b8acbe 100644
> --- a/src/intel/vulkan/anv_formats.c
> +++ b/src/intel/vulkan/anv_formats.c
> @@ -929,9 +929,11 @@ static const VkExternalMemoryProperties prime_fd_props = {
>      .exportFromImportedHandleTypes =
>         VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT |
>         VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT,
> +      VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID,
>      .compatibleHandleTypes =
>         VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT |
> -      VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT,
> +      VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT |
> +      VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID,
>   };
>   
>   VkResult anv_GetPhysicalDeviceImageFormatProperties2(
> @@ -943,6 +945,7 @@ VkResult anv_GetPhysicalDeviceImageFormatProperties2(
>      const VkPhysicalDeviceExternalImageFormatInfo *external_info = NULL;
>      VkExternalImageFormatPropertiesKHR *external_props = NULL;
>      VkSamplerYcbcrConversionImageFormatProperties *ycbcr_props = NULL;
> +   struct VkAndroidHardwareBufferUsageANDROID *android_usage = NULL;
>      VkResult result;
>   
>      /* Extract input structs */
> @@ -966,6 +969,9 @@ VkResult anv_GetPhysicalDeviceImageFormatProperties2(
>         case VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_IMAGE_FORMAT_PROPERTIES:
>            ycbcr_props = (void *) s;
>            break;
> +      case VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_USAGE_ANDROID:
> +         android_usage = (void *) s;
> +         break;
>         default:
>            anv_debug_ignored_stype(s->sType);
>            break;
> @@ -977,6 +983,14 @@ VkResult anv_GetPhysicalDeviceImageFormatProperties2(
>      if (result != VK_SUCCESS)
>         goto fail;
>   
> +#ifdef ANDROID
> +   if (android_usage) {
> +      android_usage->androidHardwareBufferUsage =
> +         AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE |
> +         AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT;
> +   }
> +#endif
> +
>      /* From the Vulkan 1.0.42 spec:
>       *
>       *    If handleType is 0, vkGetPhysicalDeviceImageFormatProperties2 will
> @@ -987,6 +1001,7 @@ VkResult anv_GetPhysicalDeviceImageFormatProperties2(
>         switch (external_info->handleType) {
>         case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT:
>         case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT:
> +      case VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID:
>            if (external_props)
>               external_props->externalMemoryProperties = prime_fd_props;
>            break;
> @@ -1070,6 +1085,8 @@ void anv_GetPhysicalDeviceExternalBufferProperties(
>      switch (pExternalBufferInfo->handleType) {
>      case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT:
>      case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT:
> +   case VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID:
> +      /* TODO - for android, should we set VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT for non-image buffers here? */

No we should not ... we should actually set it for images in 
GetPhysicalDeviceImageFormatProperties2 as specified in the spec.


>         pExternalBufferProperties->externalMemoryProperties = prime_fd_props;
>         return;
>      default:
> 

// Tapani


More information about the mesa-dev mailing list