From 22313d4c9a9f62382b73fa6878017b31543ade23 Mon Sep 17 00:00:00 2001
From: Simon Zeni <simon.zeni@collabora.com>
Date: Wed, 2 Oct 2024 11:40:29 -0400
Subject: [PATCH] aux/vk: skip image size check for android in
 vk_create_image_from_native

Co-authored-by: Rylie Pavlik <rylie.pavlik@collabora.com>
Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2332>
---
 src/xrt/auxiliary/vk/vk_helpers.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/xrt/auxiliary/vk/vk_helpers.c b/src/xrt/auxiliary/vk/vk_helpers.c
index 91157c91e..3d1a609a9 100644
--- a/src/xrt/auxiliary/vk/vk_helpers.c
+++ b/src/xrt/auxiliary/vk/vk_helpers.c
@@ -1186,7 +1186,16 @@ vk_create_image_from_native(struct vk_bundle *vk,
 #else
 #error "need port"
 #endif
-	if (requirements.size > image_native->size) {
+
+
+	if (handle_type == VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID) {
+		/*
+		 * Skip check in this case
+		 * VUID-VkMemoryAllocateInfo-allocationSize-02383
+		 * For AHardwareBuffer handles, the alloc size must be the size returned by
+		 * vkGetAndroidHardwareBufferPropertiesANDROID for the Android hardware buffer
+		 */
+	} else if (requirements.size > image_native->size) {
 		VK_ERROR(vk, "size mismatch, exported %" PRIu64 " but requires %" PRIu64, image_native->size,
 		         requirements.size);
 		return VK_ERROR_OUT_OF_DEVICE_MEMORY;