From c543c5615cf2ececbfc60c49e22f74b59851312d Mon Sep 17 00:00:00 2001 From: "Matias N. Goldberg" Date: Thu, 6 Mar 2025 19:56:52 -0300 Subject: [PATCH] Fix incorrect parameters passed to VMA If the allocation is small enough that it enters the if (p_size <= SMALL_ALLOCATION_MAX_SIZE) {} block, Godot would call vmaFindMemoryTypeIndexForBufferInfo with the wrong parameters. This can cause vmaFindMemoryTypeIndexForBufferInfo to potentially misbehave on some cards or drivers. Fixes regression introduced in #102830 Might potentially reopen #101850 (I doubt it, but it's possible) Must be backported to 4.4 --- drivers/vulkan/rendering_device_driver_vulkan.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/vulkan/rendering_device_driver_vulkan.cpp b/drivers/vulkan/rendering_device_driver_vulkan.cpp index ca75c8c9750..cb476c6db09 100644 --- a/drivers/vulkan/rendering_device_driver_vulkan.cpp +++ b/drivers/vulkan/rendering_device_driver_vulkan.cpp @@ -1547,6 +1547,10 @@ RDD::BufferID RenderingDeviceDriverVulkan::buffer_create(uint64_t p_size, BitFie } break; case MEMORY_ALLOCATION_TYPE_GPU: { vma_usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE; + if (!Engine::get_singleton()->is_extra_gpu_memory_tracking_enabled()) { + // We must set it right now or else vmaFindMemoryTypeIndexForBufferInfo will use wrong parameters. + alloc_create_info.usage = vma_usage; + } alloc_create_info.preferredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; if (p_size <= SMALL_ALLOCATION_MAX_SIZE) { uint32_t mem_type_index = 0;