GPU Vulkan: release submitted command buffer after defrag (#11430)
Some checks are pending
Build (All) / Create test plan (push) Waiting to run
Build (All) / level1 (push) Blocked by required conditions
Build (All) / level2 (push) Blocked by required conditions

This commit is contained in:
Andrei Alexeyev 2024-11-08 19:40:26 +02:00 committed by GitHub
parent 1ed1bc1d5d
commit 332fd824f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10219,6 +10219,22 @@ static SDL_GPUFence *VULKAN_SubmitAndAcquireFence(
return (SDL_GPUFence *)vulkanCommandBuffer->inFlightFence;
}
static void VULKAN_INTERNAL_ReleaseCommandBuffer(VulkanCommandBuffer *vulkanCommandBuffer)
{
VulkanRenderer *renderer = vulkanCommandBuffer->renderer;
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;
}
static bool VULKAN_Submit(
SDL_GPUCommandBuffer *commandBuffer)
{
@ -10292,19 +10308,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;
@ -10336,6 +10339,11 @@ static bool VULKAN_Submit(
presentData->windowData->needsSwapchainRecreate = true;
}
} else {
if (presentResult != VK_SUCCESS) {
VULKAN_INTERNAL_ReleaseCommandBuffer(vulkanCommandBuffer);
SDL_UnlockMutex(renderer->submitLock);
}
CHECK_VULKAN_ERROR_AND_RETURN(presentResult, vkQueuePresentKHR, false)
}
@ -10391,6 +10399,10 @@ 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.
VULKAN_INTERNAL_ReleaseCommandBuffer(vulkanCommandBuffer);
SDL_UnlockMutex(renderer->submitLock);
return result;