Skip to content

Commit 4246356

Browse files
Kontrabantslouken
authored andcommitted
GPU: Vulkan backend flags command buffer for cleanup when swapchain is requested
When skipping presentation due to the window being hidden, presentDataCount is not incremented on the command buffer, and subsequently the submitted command buffers will not be cleaned up as long as the window is hidden. This results in a lag spike when showing the window due to all previously submitted command buffers suddenly being cleaned up at once, and lag at shutdown due to an equivalent number of fences needing to be destroyed. Instead of relying on presentDataCount to determine whether a command buffer should be cleaned up, use a flag, which is set under the appropriate circumstances.
1 parent ae5ce25 commit 4246356

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/gpu/vulkan/SDL_gpu_vulkan.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,7 @@ typedef struct VulkanCommandBuffer
10791079
VulkanFenceHandle *inFlightFence;
10801080
bool autoReleaseFence;
10811081

1082+
bool swapchainRequested;
10821083
bool isDefrag; // Whether this CB was created for defragging
10831084
} VulkanCommandBuffer;
10841085

@@ -9934,6 +9935,9 @@ static bool VULKAN_INTERNAL_AcquireSwapchainTexture(
99349935
SET_STRING_ERROR_AND_RETURN("Cannot acquire a swapchain texture from an unclaimed window!", false);
99359936
}
99369937

9938+
// The command buffer is flagged for cleanup when the swapchain is requested as a cleanup timing mechanism
9939+
vulkanCommandBuffer->swapchainRequested = true;
9940+
99379941
if (window->flags & SDL_WINDOW_HIDDEN) {
99389942
// Edge case, texture is filled in with NULL but not an error
99399943
return true;
@@ -10392,6 +10396,7 @@ static void VULKAN_INTERNAL_CleanCommandBuffer(
1039210396
commandBuffer->presentDataCount = 0;
1039310397
commandBuffer->waitSemaphoreCount = 0;
1039410398
commandBuffer->signalSemaphoreCount = 0;
10399+
commandBuffer->swapchainRequested = false;
1039510400

1039610401
// Reset defrag state
1039710402

@@ -10548,7 +10553,7 @@ static bool VULKAN_Submit(
1054810553
VulkanTextureSubresource *swapchainTextureSubresource;
1054910554
VulkanMemorySubAllocator *allocator;
1055010555
bool performCleanups =
10551-
(renderer->claimedWindowCount > 0 && vulkanCommandBuffer->presentDataCount > 0) ||
10556+
(renderer->claimedWindowCount > 0 && vulkanCommandBuffer->swapchainRequested) ||
1055210557
renderer->claimedWindowCount == 0;
1055310558

1055410559
SDL_LockMutex(renderer->submitLock);

0 commit comments

Comments
 (0)