Skip to content

Commit

Permalink
GPU Vulkan: release submitted command buffer after defrag
Browse files Browse the repository at this point in the history
Fixes #11429
  • Loading branch information
Akaricchi committed Nov 8, 2024
1 parent 8a2cac7 commit 160d17e
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions src/gpu/vulkan/SDL_gpu_vulkan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 160d17e

Please sign in to comment.