diff --git a/src/gpu/vulkan/SDL_gpu_vulkan.c b/src/gpu/vulkan/SDL_gpu_vulkan.c index 29951c609595c..394ed0d2636c6 100644 --- a/src/gpu/vulkan/SDL_gpu_vulkan.c +++ b/src/gpu/vulkan/SDL_gpu_vulkan.c @@ -10292,19 +10292,6 @@ static bool VULKAN_Submit( CHECK_VULKAN_ERROR_AND_RETURN(vulkanResult, vkQueueSubmit, false) } - // Mark command buffers as submitted - - if (renderer->submittedCommandBufferCount + 1 >= renderer->submittedCommandBufferCapacity) { - renderer->submittedCommandBufferCapacity = renderer->submittedCommandBufferCount + 1; - - renderer->submittedCommandBuffers = SDL_realloc( - renderer->submittedCommandBuffers, - sizeof(VulkanCommandBuffer *) * renderer->submittedCommandBufferCapacity); - } - - renderer->submittedCommandBuffers[renderer->submittedCommandBufferCount] = vulkanCommandBuffer; - renderer->submittedCommandBufferCount += 1; - // Present, if applicable bool result = true; @@ -10391,6 +10378,20 @@ static bool VULKAN_Submit( result = VULKAN_INTERNAL_DefragmentMemory(renderer); } + // Mark command buffer as submitted + // This must happen after defrag, because it will try to acquire new command buffers. + + if (renderer->submittedCommandBufferCount + 1 >= renderer->submittedCommandBufferCapacity) { + renderer->submittedCommandBufferCapacity = renderer->submittedCommandBufferCount + 1; + + renderer->submittedCommandBuffers = SDL_realloc( + renderer->submittedCommandBuffers, + sizeof(VulkanCommandBuffer *) * renderer->submittedCommandBufferCapacity); + } + + renderer->submittedCommandBuffers[renderer->submittedCommandBufferCount] = vulkanCommandBuffer; + renderer->submittedCommandBufferCount += 1; + SDL_UnlockMutex(renderer->submitLock); return result;