From 0bd70684b35ac6cae114e25a2fdca9f430e0b3b1 Mon Sep 17 00:00:00 2001 From: Evan Hemsley <2342303+thatcosmonaut@users.noreply.github.com> Date: Mon, 17 Mar 2025 13:19:41 -0700 Subject: [PATCH] GPU: Fix Vulkan backend never checking deallocations (#12567) --------- Co-authored-by: Sam Lantinga --- src/gpu/vulkan/SDL_gpu_vulkan.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/gpu/vulkan/SDL_gpu_vulkan.c b/src/gpu/vulkan/SDL_gpu_vulkan.c index 494cf95e72..a4f6cdeea8 100644 --- a/src/gpu/vulkan/SDL_gpu_vulkan.c +++ b/src/gpu/vulkan/SDL_gpu_vulkan.c @@ -1106,6 +1106,7 @@ struct VulkanRenderer VulkanMemoryAllocator *memoryAllocator; VkPhysicalDeviceMemoryProperties memoryProperties; + bool checkEmptyAllocations; WindowData **claimedWindows; Uint32 claimedWindowCount; @@ -1546,6 +1547,10 @@ static void VULKAN_INTERNAL_RemoveMemoryUsedRegion( usedRegion->offset, usedRegion->size); + if (usedRegion->allocation->usedRegionCount == 0) { + renderer->checkEmptyAllocations = true; + } + SDL_free(usedRegion); SDL_UnlockMutex(renderer->allocatorLock); @@ -10375,7 +10380,6 @@ static bool VULKAN_Submit( VkPipelineStageFlags waitStages[MAX_PRESENT_COUNT]; Uint32 swapchainImageIndex; VulkanTextureSubresource *swapchainTextureSubresource; - Uint8 commandBufferCleaned = 0; VulkanMemorySubAllocator *allocator; bool presenting = false; @@ -10491,12 +10495,10 @@ static bool VULKAN_Submit( renderer, renderer->submittedCommandBuffers[i], false); - - commandBufferCleaned = 1; } } - if (commandBufferCleaned) { + if (renderer->checkEmptyAllocations) { SDL_LockMutex(renderer->allocatorLock); for (Uint32 i = 0; i < VK_MAX_MEMORY_TYPES; i += 1) { @@ -10512,6 +10514,8 @@ static bool VULKAN_Submit( } } + renderer->checkEmptyAllocations = false; + SDL_UnlockMutex(renderer->allocatorLock); }