+ image->planes[plane].address = (struct anv_address) {
+ .bo = memory->bo,
+ .offset = memory_offset,
+ };
+
+ if (anv_image_plane_uses_aux_map(device, image, plane)) {
+ image->planes[plane].aux_map_surface_address =
+ anv_address_physical(
+ anv_address_add(image->planes[plane].address,
+ image->planes[plane].surface.offset));
+
+ gen_aux_map_add_image(device->aux_map_ctx,
+ &image->planes[plane].surface.isl,
+ image->planes[plane].aux_map_surface_address,
+ anv_address_physical(
+ anv_address_add(image->planes[plane].address,
+ image->planes[plane].aux_surface.offset)));
+ }
+}
+
+/* We are binding AHardwareBuffer. Get a description, resolve the
+ * format and prepare anv_image properly.
+ */
+static void
+resolve_ahw_image(struct anv_device *device,
+ struct anv_image *image,
+ struct anv_device_memory *mem)
+{
+#if defined(ANDROID) && ANDROID_API_LEVEL >= 26
+ assert(mem->ahw);
+ AHardwareBuffer_Desc desc;
+ AHardwareBuffer_describe(mem->ahw, &desc);
+
+ /* Check tiling. */
+ int i915_tiling = anv_gem_get_tiling(device, mem->bo->gem_handle);
+ VkImageTiling vk_tiling;
+ isl_tiling_flags_t isl_tiling_flags = 0;
+
+ switch (i915_tiling) {
+ case I915_TILING_NONE:
+ vk_tiling = VK_IMAGE_TILING_LINEAR;
+ isl_tiling_flags = ISL_TILING_LINEAR_BIT;
+ break;
+ case I915_TILING_X:
+ vk_tiling = VK_IMAGE_TILING_OPTIMAL;
+ isl_tiling_flags = ISL_TILING_X_BIT;
+ break;
+ case I915_TILING_Y:
+ vk_tiling = VK_IMAGE_TILING_OPTIMAL;
+ isl_tiling_flags = ISL_TILING_Y0_BIT;
+ break;
+ case -1:
+ default:
+ unreachable("Invalid tiling flags.");
+ }
+
+ assert(vk_tiling == VK_IMAGE_TILING_LINEAR ||
+ vk_tiling == VK_IMAGE_TILING_OPTIMAL);
+
+ /* Check format. */
+ VkFormat vk_format = vk_format_from_android(desc.format, desc.usage);
+ enum isl_format isl_fmt = anv_get_isl_format(&device->info,
+ vk_format,
+ VK_IMAGE_ASPECT_COLOR_BIT,
+ vk_tiling);
+ assert(isl_fmt != ISL_FORMAT_UNSUPPORTED);
+
+ /* Handle RGB(X)->RGBA fallback. */
+ switch (desc.format) {
+ case AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM:
+ case AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM:
+ if (isl_format_is_rgb(isl_fmt))
+ isl_fmt = isl_format_rgb_to_rgba(isl_fmt);
+ break;
+ }
+
+ /* Now we are able to fill anv_image fields properly and create
+ * isl_surface for it.
+ */
+ image->vk_format = vk_format;
+ image->format = anv_get_format(vk_format);
+ image->aspects = vk_format_aspects(image->vk_format);
+ image->n_planes = image->format->n_planes;
+ image->ccs_e_compatible = false;
+
+ uint32_t stride = desc.stride *
+ (isl_format_get_layout(isl_fmt)->bpb / 8);
+
+ uint32_t b;
+ for_each_bit(b, image->aspects) {
+ VkResult r = make_surface(device, image, stride, isl_tiling_flags,
+ ISL_SURF_USAGE_DISABLE_AUX_BIT, (1 << b));
+ assert(r == VK_SUCCESS);
+ }
+#endif