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 8ac5aec
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/gpu/vulkan/SDL_gpu_vulkan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

0 comments on commit 8ac5aec

Please sign in to comment.