magma: Fix android swapchain deferred image bind

In non-deferred mode the android swapchain creates a VkImage
providing VkNativeBufferANDROID so the format modifier is set
correctly.  In deferred mode the VkImage is created with no
indication that it will be bound using VkNativeBufferANDROID,
so it assumes CCS is enabled but that isn't current supported.

Bug:b/278904966

Change-Id: Iaa487d345c686058fb4ae45baab8f506d6063890
Reviewed-on: https://fuchsia-review.googlesource.com/c/third_party/mesa/+/855897
Reviewed-by: John Bauman <jbauman@google.com>
diff --git a/src/intel/vulkan/anv_android.c b/src/intel/vulkan/anv_android.c
index 419672e..2a59ef9 100644
--- a/src/intel/vulkan/anv_android.c
+++ b/src/intel/vulkan/anv_android.c
@@ -625,6 +625,21 @@
           ANV_IMAGE_MEMORY_BINDING_MAIN);
    assert(image->bindings[ANV_IMAGE_MEMORY_BINDING_MAIN].address.bo == NULL);
    assert(image->bindings[ANV_IMAGE_MEMORY_BINDING_MAIN].address.offset == 0);
+
+#if defined(USE_MAGMA)
+   enum isl_tiling tiling;
+   result = anv_device_get_bo_tiling(device, bo, &tiling);
+   if (result != VK_SUCCESS) {
+      anv_device_release_bo(device, bo);
+      return vk_errorf(device, result,
+                       "failed to get tiling from VkNativeBufferANDROID");
+   }
+
+   // Ensure image was created with appropriate tiling and no CCS
+   assert(image->planes[0].primary_surface.isl.tiling == tiling);
+   assert(image->planes[0].aux_usage == ISL_AUX_USAGE_NONE);
+#endif
+
    image->bindings[ANV_IMAGE_MEMORY_BINDING_MAIN].address.bo = bo;
    image->from_gralloc = true;
 
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index 72e2d6e..9986fa1 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -3993,7 +3993,7 @@
    mem->ahw = NULL;
    mem->host_ptr = NULL;
 
-#if defined(__linux__) && defined(USE_MAGMA)
+#if defined(__linux__) && !defined(ANDROID) && defined(USE_MAGMA)
    mem->dedicated.image = NULL;
    mem->dedicated.alloc_flags = 0;
 #endif
@@ -4282,7 +4282,7 @@
    if (mem_type->propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
       alloc_flags |= ANV_BO_ALLOC_LOCAL_MEM;
 
-#if defined(__linux__) && defined(USE_MAGMA)
+#if defined(__linux__) && !defined(ANDROID) && defined(USE_MAGMA)
    /* Dedicated allocation provides access to magma image */
    if (dedicated_info && dedicated_info->image != VK_NULL_HANDLE) {
       ANV_FROM_HANDLE(anv_image, image, dedicated_info->image);
@@ -4414,7 +4414,7 @@
    assert(pGetFdInfo->handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT ||
           pGetFdInfo->handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT);
 
-#if defined(__linux__) && defined(USE_MAGMA)
+#if defined(__linux__) && !defined(ANDROID) && defined(USE_MAGMA)
    /* If dedicated image is valid here, the device memory is a placeholder because
     * the memory hasn't been bound to the image yet.
     */
diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c
index c5b5416..6ff825f 100644
--- a/src/intel/vulkan/anv_image.c
+++ b/src/intel/vulkan/anv_image.c
@@ -1606,7 +1606,7 @@
       return anv_image_init_from_gralloc(device, image, pCreateInfo,
                                          gralloc_info);
 
-#if defined(__linux__) && defined(USE_MAGMA) && !defined(ANDROID)
+#if defined(__linux__) && !defined(ANDROID) && defined(USE_MAGMA)
    const VkExternalMemoryImageCreateInfo *external_create_info =
       vk_find_struct_const(pCreateInfo->pNext, EXTERNAL_MEMORY_IMAGE_CREATE_INFO);
 
@@ -1783,6 +1783,13 @@
        !isl_drm_modifier_has_aux(mod_explicit_info->drmFormatModifier))
       create_info.isl_extra_usage_flags |= ISL_SURF_USAGE_DISABLE_AUX_BIT;
 
+#if defined(ANDROID)
+   // When the android swapchain defers image allocation, it creates images without
+   // any indication they will be bound with VkNativeBufferANDROID.  Since CCS on
+   // gralloc images isn't supported, ensure the image is created appropriately.
+   create_info.isl_extra_usage_flags |= ISL_SURF_USAGE_DISABLE_AUX_BIT;
+#endif
+
    return anv_image_init(device, image, &create_info);
 }
 
@@ -2062,7 +2069,7 @@
       ANV_FROM_HANDLE(anv_image, image, bind_info->image);
       bool did_bind = false;
 
-#if defined(__linux__) && defined(USE_MAGMA)
+#if defined(__linux__) && defined(USE_MAGMA) && !defined(ANDROID)
       if (mem->dedicated.image) {
          /* If memory was created as dedicated for image, it must be bound
           * to that image, and the image can only be bound to one memory.
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index e14eb97..5e3761a 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -1806,7 +1806,7 @@
    /* If set, this memory comes from a host pointer. */
    void *                                       host_ptr;
 
-#if defined(__linux__) && defined(USE_MAGMA)
+#if defined(__linux__) && !defined(ANDROID) && defined(USE_MAGMA)
    /* Used to bind memory to a dedicated image. */
    struct {
       struct anv_image*                         image;