intel/tools: Disassemble WAIT's argument as a destination
[mesa.git] / src / intel / vulkan / anv_android.c
index dc5b972298536ba48c16d0cc7142ce7ad4446b55..a5f5904d06ba53d2b0f422279a41a953d725926a 100644 (file)
@@ -25,7 +25,6 @@
 
 #if ANDROID_API_LEVEL >= 26
 #include <hardware/gralloc1.h>
-#include <grallocusage/GrallocUsageConversion.h>
 #endif
 
 #include <hardware/hardware.h>
@@ -309,7 +308,7 @@ anv_import_ahw_memory(VkDevice device_h,
    VkResult result = anv_device_import_bo(device, dma_buf, 0,
                                           0 /* client_address */,
                                           &mem->bo);
-   assert(VK_SUCCESS);
+   assert(result == VK_SUCCESS);
 
    /* "If the vkAllocateMemory command succeeds, the implementation must
     * acquire a reference to the imported hardware buffer, which it must
@@ -445,8 +444,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,
+      return vk_errorf(device, device, VK_ERROR_INVALID_EXTERNAL_HANDLE,
                        "VkNativeBufferANDROID::handle::numFds is %d, "
                        "expected 1", gralloc_info->handle->numFds);
    }
@@ -472,7 +470,7 @@ anv_image_from_gralloc(VkDevice device_h,
                                  0 /* client_address */,
                                  &bo);
    if (result != VK_SUCCESS) {
-      return vk_errorf(device->instance, device, result,
+      return vk_errorf(device, device, result,
                        "failed to import dma-buf from VkNativeBufferANDROID");
    }
 
@@ -488,14 +486,12 @@ anv_image_from_gralloc(VkDevice device_h,
       anv_info.isl_tiling_flags = ISL_TILING_Y0_BIT;
       break;
    case -1:
-      result = vk_errorf(device->instance, device,
-                         VK_ERROR_INVALID_EXTERNAL_HANDLE,
+      result = vk_errorf(device, device, 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,
+      result = vk_errorf(device, device, VK_ERROR_INVALID_EXTERNAL_HANDLE,
                          "DRM_IOCTL_I915_GEM_GET_TILING returned unknown "
                          "tiling %d for VkNativeBufferANDROID", i915_tiling);
       goto fail_tiling;
@@ -516,8 +512,7 @@ anv_image_from_gralloc(VkDevice device_h,
       goto fail_create;
 
    if (bo->size < image->size) {
-      result = vk_errorf(device->instance, device,
-                         VK_ERROR_INVALID_EXTERNAL_HANDLE,
+      result = vk_errorf(device, device, VK_ERROR_INVALID_EXTERNAL_HANDLE,
                          "dma-buf from VkNativeBufferANDROID is too small for "
                          "VkImage: %"PRIu64"B < %"PRIu64"B",
                          bo->size, image->size);
@@ -544,7 +539,7 @@ anv_image_from_gralloc(VkDevice device_h,
    return result;
 }
 
-VkResult
+static VkResult
 format_supported_with_usage(VkDevice device_h, VkFormat format,
                             VkImageUsageFlags imageUsage)
 {
@@ -568,7 +563,7 @@ format_supported_with_usage(VkDevice device_h, VkFormat format,
    result = anv_GetPhysicalDeviceImageFormatProperties2(phys_dev_h,
                &image_format_info, &image_format_props);
    if (result != VK_SUCCESS) {
-      return vk_errorf(device->instance, device, result,
+      return vk_errorf(device, device, result,
                        "anv_GetPhysicalDeviceImageFormatProperties2 failed "
                        "inside %s", __func__);
    }
@@ -577,8 +572,8 @@ format_supported_with_usage(VkDevice device_h, VkFormat format,
 
 
 static VkResult
-setup_gralloc0_usage(VkFormat format, VkImageUsageFlags imageUsage,
-                     int *grallocUsage)
+setup_gralloc0_usage(struct anv_device *device, VkFormat format,
+                     VkImageUsageFlags imageUsage, int *grallocUsage)
 {
    /* WARNING: Android's libvulkan.so hardcodes the VkImageUsageFlags
     * returned to applications via VkSurfaceCapabilitiesKHR::supportedUsageFlags.
@@ -607,7 +602,7 @@ setup_gralloc0_usage(VkFormat format, VkImageUsageFlags imageUsage,
     * gralloc swapchains.
     */
    if (imageUsage != 0) {
-      return vk_errorf(device->instance, device, VK_ERROR_FORMAT_NOT_SUPPORTED,
+      return vk_errorf(device, device, VK_ERROR_FORMAT_NOT_SUPPORTED,
                        "unsupported VkImageUsageFlags(0x%x) for gralloc "
                        "swapchain", imageUsage);
    }
@@ -621,7 +616,7 @@ setup_gralloc0_usage(VkFormat format, VkImageUsageFlags imageUsage,
     */
    switch (format) {
       case VK_FORMAT_B8G8R8A8_UNORM:
-      case VK_FORMAT_B5G6R5_UNORM_PACK16:
+      case VK_FORMAT_R5G6B5_UNORM_PACK16:
       case VK_FORMAT_R8G8B8A8_UNORM:
       case VK_FORMAT_R8G8B8A8_SRGB:
          *grallocUsage |= GRALLOC_USAGE_HW_FB |
@@ -638,7 +633,6 @@ setup_gralloc0_usage(VkFormat format, VkImageUsageFlags imageUsage,
    return VK_SUCCESS;
 }
 
-
 #if ANDROID_API_LEVEL >= 26
 VkResult anv_GetSwapchainGrallocUsage2ANDROID(
     VkDevice            device_h,
@@ -660,12 +654,27 @@ VkResult anv_GetSwapchainGrallocUsage2ANDROID(
       return result;
 
    int32_t grallocUsage = 0;
-   result = setup_gralloc0_usage(format, imageUsage, &grallocUsage);
+   result = setup_gralloc0_usage(device, format, imageUsage, &grallocUsage);
    if (result != VK_SUCCESS)
       return result;
 
-   android_convertGralloc0To1Usage(grallocUsage, grallocProducerUsage,
-                                   grallocConsumerUsage);
+   /* Setup gralloc1 usage flags from gralloc0 flags. */
+
+   if (grallocUsage & GRALLOC_USAGE_HW_RENDER) {
+      *grallocProducerUsage |= GRALLOC1_PRODUCER_USAGE_GPU_RENDER_TARGET;
+      *grallocConsumerUsage |= GRALLOC1_CONSUMER_USAGE_CLIENT_TARGET;
+   }
+
+   if (grallocUsage & GRALLOC_USAGE_HW_TEXTURE) {
+      *grallocConsumerUsage |= GRALLOC1_CONSUMER_USAGE_GPU_TEXTURE;
+   }
+
+   if (grallocUsage & (GRALLOC_USAGE_HW_FB |
+                       GRALLOC_USAGE_HW_COMPOSER |
+                       GRALLOC_USAGE_EXTERNAL_DISP)) {
+      *grallocProducerUsage |= GRALLOC1_PRODUCER_USAGE_GPU_RENDER_TARGET;
+      *grallocConsumerUsage |= GRALLOC1_CONSUMER_USAGE_HWCOMPOSER;
+   }
 
    return VK_SUCCESS;
 }
@@ -677,6 +686,7 @@ VkResult anv_GetSwapchainGrallocUsageANDROID(
     VkImageUsageFlags   imageUsage,
     int*                grallocUsage)
 {
+   ANV_FROM_HANDLE(anv_device, device, device_h);
    VkResult result;
 
    *grallocUsage = 0;
@@ -686,7 +696,7 @@ VkResult anv_GetSwapchainGrallocUsageANDROID(
    if (result != VK_SUCCESS)
       return result;
 
-   return setup_gralloc0_usage(format, imageUsage, grallocUsage);
+   return setup_gralloc0_usage(device, format, imageUsage, grallocUsage);
 }
 
 VkResult
@@ -709,7 +719,7 @@ anv_AcquireImageANDROID(
        * VkFence.
        */
       if (sync_wait(nativeFenceFd, /*timeout*/ -1) < 0) {
-         result = vk_errorf(device->instance, device, VK_ERROR_DEVICE_LOST,
+         result = vk_errorf(device, device, VK_ERROR_DEVICE_LOST,
                             "%s: failed to wait on nativeFenceFd=%d",
                             __func__, nativeFenceFd);
       }
@@ -755,7 +765,7 @@ anv_AcquireImageANDROID(
       result = anv_QueueSubmit(anv_queue_to_handle(&device->queue), 1,
                                &submit, fence_h);
       if (result != VK_SUCCESS) {
-         return vk_errorf(device->instance, device, result,
+         return vk_errorf(device, device, result,
                           "anv_QueueSubmit failed inside %s", __func__);
       }
    }