···10821082 *
10831083 * @param vk Vulkan bundle
10841084 * @param image The VkImage to allocate for and bind.
10851085- * @param max_size The maximum value you'll allow for
10861086- * VkMemoryRequirements::size. Pass SIZE_MAX if you will accept any size
10871087- * that works.
10851085+ * @param requirements Memory requirements used for finding the memory type and the size.
10881086 * @param pNext_for_allocate (Optional) a pointer to use in the pNext chain of
10891087 * VkMemoryAllocateInfo.
10901088 * @param caller_name Used for error printing, this function is called from
···11041102XRT_CHECK_RESULT VkResult
11051103vk_alloc_and_bind_image_memory(struct vk_bundle *vk,
11061104 VkImage image,
11071107- size_t max_size,
11051105+ const VkMemoryRequirements *requirements,
11081106 const void *pNext_for_allocate,
11091107 const char *caller_name,
11101110- VkDeviceMemory *out_mem,
11111111- VkDeviceSize *out_size);
11081108+ VkDeviceMemory *out_mem);
1112110911131110/*!
11141111 *
···15641561 * CSCI = Compositor SwapChain Images.
15651562 */
15661563bool
15671567-vk_csci_is_format_supported(struct vk_bundle *vk,
15681568- VkFormat format,
15691569- enum xrt_swapchain_usage_bits xbits);
15641564+vk_csci_is_format_supported(struct vk_bundle *vk, VkFormat format, enum xrt_swapchain_usage_bits xbits);
1570156515711566/*
15721567 *
+31-7
src/xrt/auxiliary/vk/vk_image_allocator.c
···108108 VkDeviceMemory device_memory = VK_NULL_HANDLE;
109109 VkImage image = VK_NULL_HANDLE;
110110 VkResult ret = VK_SUCCESS;
111111- VkDeviceSize size;
112111113112#if defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_AHARDWAREBUFFER)
114113 /*
···187186 };
188187 CHAIN(format_android);
189188190190- // Android can't allocate native sRGB.
191191- // Use UNORM and correct gamma later.
192189 if (image_format == VK_FORMAT_R8G8B8A8_SRGB) {
190190+ // Some versions of Android can't allocate native sRGB, use UNORM and correct gamma later.
193191 image_format = VK_FORMAT_R8G8B8A8_UNORM;
194192195193 // https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageViewCreateInfo-image-01019
···203201 add_format_non_dup(&flh, VK_FORMAT_R8G8B8A8_UNORM);
204202 add_format_non_dup(&flh, VK_FORMAT_R8G8B8A8_SRGB);
205203 }
204204+205205+ if (vk_csci_is_format_supported(vk, image_format, info->bits)) {
206206+ // Format is supported, no need for VkExternalFormatANDROID
207207+ format_android.externalFormat = 0;
208208+ assert(a_buffer_format_props.format != VK_FORMAT_UNDEFINED); // Make sure there is a Vulkan format.
209209+ } else if (image_usage != VK_IMAGE_USAGE_SAMPLED_BIT && !vk->has_ANDROID_external_format_resolve) {
210210+ // VUID-VkImageCreateInfo-pNext-09457
211211+ VK_ERROR(
212212+ vk, "VK_ANDROID_external_format_resolve not supported, only VK_IMAGE_USAGE_SAMPLED_BIT is allowed");
213213+ return VK_ERROR_FORMAT_NOT_SUPPORTED;
214214+ } else {
215215+ VK_ERROR(vk, "Format not supported");
216216+ return VK_ERROR_FORMAT_NOT_SUPPORTED;
217217+ }
206218#endif
207219208220#ifdef VK_KHR_image_format_list
···270282 .pNext = &memory_dedicated_requirements,
271283 };
272284285285+ VkMemoryRequirements *requirements;
286286+#if defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_AHARDWAREBUFFER)
287287+ // VUID-VkImageMemoryRequirementsInfo2-image-01897
288288+ // VUID-VkMemoryAllocateInfo-pNext-01874
289289+ // Use the requirements from the VkAndroidHardwareBufferPropertiesANDROID instead of querying them
290290+ VkMemoryRequirements android_memory_requirements = {
291291+ .size = a_buffer_props.allocationSize,
292292+ .memoryTypeBits = a_buffer_props.memoryTypeBits,
293293+ };
294294+ requirements = &android_memory_requirements;
295295+#else
273296 vk->vkGetImageMemoryRequirements2(vk->device, &memory_requirements_info, &memory_requirements);
297297+ requirements = &memory_requirements.memoryRequirements;
298298+#endif
274299275300 /*
276301 * On tegra we must not use dedicated allocation when it is only preferred to avoid black textures and driver
···312337 ret = vk_alloc_and_bind_image_memory( //
313338 vk, // vk_bundle
314339 image, // image
315315- SIZE_MAX, // max_size
340340+ requirements, // requirements
316341 &export_alloc_info, // pNext_for_allocate
317342 "vk_image_allocator::create_image", // caller_name
318318- &device_memory, // out_mem
319319- &size); // out_size
343343+ &device_memory); // out_mem
320344 if (ret != VK_SUCCESS) {
321345 vk->vkDestroyImage(vk->device, image, NULL);
322346 return ret;
···324348325349 out_image->handle = image;
326350 out_image->memory = device_memory;
327327- out_image->size = size;
351351+ out_image->size = memory_requirements.memoryRequirements.size;
328352 out_image->use_dedicated_allocation = use_dedicated_allocation;
329353330354 return ret;