vulkan/util: meson build - add wayland client include
[mesa.git] / src / intel / vulkan / anv_android.c
index ca1eae7be99fb475009d4baeffd924c99e311f97..3272ddd85b1a1e99cfb705633f1feadfeb12edb2 100644 (file)
@@ -120,7 +120,7 @@ get_ahw_buffer_format_properties(
     * one of the AHARDWAREBUFFER_USAGE_GPU_* usage flags."
     */
    if (!(desc.usage & (gpu_usage)))
-      return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR;
+      return VK_ERROR_INVALID_EXTERNAL_HANDLE;
 
    /* Fill properties fields based on description. */
    VkAndroidHardwareBufferFormatPropertiesANDROID *p = pProperties;
@@ -204,7 +204,7 @@ anv_GetAndroidHardwareBufferPropertiesANDROID(
       AHardwareBuffer_getNativeHandle(buffer);
    int dma_buf = (handle && handle->numFds) ? handle->data[0] : -1;
    if (dma_buf < 0)
-      return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR;
+      return VK_ERROR_INVALID_EXTERNAL_HANDLE;
 
    /* All memory types. */
    uint32_t memory_types = (1ull << pdevice->memory.type_count) - 1;
@@ -261,7 +261,7 @@ anv_GetMemoryAndroidHardwareBufferANDROID(
     * Android hardware buffer object."
     *
     * "VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID must
-    * have been included in VkExportMemoryAllocateInfoKHR::handleTypes when
+    * have been included in VkExportMemoryAllocateInfo::handleTypes when
     * memory was created."
     */
    if (mem->ahw) {
@@ -295,7 +295,7 @@ anv_import_ahw_memory(VkDevice device_h,
     */
    int dma_buf = (handle && handle->numFds) ? handle->data[0] : -1;
    if (dma_buf < 0)
-      return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR;
+      return VK_ERROR_INVALID_EXTERNAL_HANDLE;
 
    uint64_t bo_flags = ANV_BO_EXTERNAL;
    if (device->instance->physicalDevice.supports_48bit_addresses)
@@ -373,6 +373,42 @@ anv_create_ahw_memory(VkDevice device_h,
    return VK_SUCCESS;
 }
 
+VkResult
+anv_image_from_external(
+   VkDevice device_h,
+   const VkImageCreateInfo *base_info,
+   const struct VkExternalMemoryImageCreateInfo *create_info,
+   const VkAllocationCallbacks *alloc,
+   VkImage *out_image_h)
+{
+   ANV_FROM_HANDLE(anv_device, device, device_h);
+
+   const struct VkExternalFormatANDROID *ext_info =
+      vk_find_struct_const(base_info->pNext, EXTERNAL_FORMAT_ANDROID);
+
+   if (ext_info && ext_info->externalFormat != 0) {
+      assert(base_info->format == VK_FORMAT_UNDEFINED);
+      assert(base_info->imageType == VK_IMAGE_TYPE_2D);
+      assert(base_info->usage == VK_IMAGE_USAGE_SAMPLED_BIT);
+      assert(base_info->tiling == VK_IMAGE_TILING_OPTIMAL);
+   }
+
+   struct anv_image_create_info anv_info = {
+      .vk_info = base_info,
+      .isl_extra_usage_flags = ISL_SURF_USAGE_DISABLE_AUX_BIT,
+      .external_format = true,
+   };
+
+   VkImage image_h;
+   VkResult result = anv_image_create(device_h, &anv_info, alloc, &image_h);
+   if (result != VK_SUCCESS)
+      return result;
+
+   *out_image_h = image_h;
+
+   return VK_SUCCESS;
+}
+
 VkResult
 anv_image_from_gralloc(VkDevice device_h,
                        const VkImageCreateInfo *base_info,
@@ -394,7 +430,7 @@ anv_image_from_gralloc(VkDevice device_h,
 
    if (gralloc_info->handle->numFds != 1) {
       return vk_errorf(device->instance, device,
-                       VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR,
+                       VK_ERROR_INVALID_EXTERNAL_HANDLE,
                        "VkNativeBufferANDROID::handle::numFds is %d, "
                        "expected 1", gralloc_info->handle->numFds);
    }
@@ -430,13 +466,13 @@ anv_image_from_gralloc(VkDevice device_h,
       break;
    case -1:
       result = vk_errorf(device->instance, device,
-                         VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR,
+                         VK_ERROR_INVALID_EXTERNAL_HANDLE,
                          "DRM_IOCTL_I915_GEM_GET_TILING failed for "
                          "VkNativeBufferANDROID");
       goto fail_tiling;
    default:
       result = vk_errorf(device->instance, device,
-                         VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR,
+                         VK_ERROR_INVALID_EXTERNAL_HANDLE,
                          "DRM_IOCTL_I915_GEM_GET_TILING returned unknown "
                          "tiling %d for VkNativeBufferANDROID", i915_tiling);
       goto fail_tiling;
@@ -458,7 +494,7 @@ anv_image_from_gralloc(VkDevice device_h,
 
    if (bo->size < image->size) {
       result = vk_errorf(device->instance, device,
-                         VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR,
+                         VK_ERROR_INVALID_EXTERNAL_HANDLE,
                          "dma-buf from VkNativeBufferANDROID is too small for "
                          "VkImage: %"PRIu64"B < %"PRIu64"B",
                          bo->size, image->size);
@@ -511,7 +547,7 @@ VkResult anv_GetSwapchainGrallocUsageANDROID(
    *grallocUsage = 0;
    intel_logd("%s: format=%d, usage=0x%x", __func__, format, imageUsage);
 
-   /* WARNING: Android Nougat's libvulkan.so hardcodes the VkImageUsageFlags
+   /* WARNING: Android's libvulkan.so hardcodes the VkImageUsageFlags
     * returned to applications via VkSurfaceCapabilitiesKHR::supportedUsageFlags.
     * The relevant code in libvulkan/swapchain.cpp contains this fun comment:
     *
@@ -524,16 +560,16 @@ VkResult anv_GetSwapchainGrallocUsageANDROID(
     * dEQP-VK.wsi.android.swapchain.*.image_usage to fail.
     */
 
-   const VkPhysicalDeviceImageFormatInfo2KHR image_format_info = {
-      .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2_KHR,
+   const VkPhysicalDeviceImageFormatInfo2 image_format_info = {
+      .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2,
       .format = format,
       .type = VK_IMAGE_TYPE_2D,
       .tiling = VK_IMAGE_TILING_OPTIMAL,
       .usage = imageUsage,
    };
 
-   VkImageFormatProperties2KHR image_format_props = {
-      .sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2_KHR,
+   VkImageFormatProperties2 image_format_props = {
+      .sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2,
    };
 
    /* Check that requested format and usage are supported. */
@@ -545,19 +581,13 @@ VkResult anv_GetSwapchainGrallocUsageANDROID(
                        "inside %s", __func__);
    }
 
-   /* Reject STORAGE here to avoid complexity elsewhere. */
-   if (imageUsage & VK_IMAGE_USAGE_STORAGE_BIT) {
-      return vk_errorf(device->instance, device, VK_ERROR_FORMAT_NOT_SUPPORTED,
-                       "VK_IMAGE_USAGE_STORAGE_BIT unsupported for gralloc "
-                       "swapchain");
-   }
-
    if (unmask32(&imageUsage, VK_IMAGE_USAGE_TRANSFER_DST_BIT |
                              VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT))
       *grallocUsage |= GRALLOC_USAGE_HW_RENDER;
 
    if (unmask32(&imageUsage, VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
                              VK_IMAGE_USAGE_SAMPLED_BIT |
+                             VK_IMAGE_USAGE_STORAGE_BIT |
                              VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT))
       *grallocUsage |= GRALLOC_USAGE_HW_TEXTURE;