mirror of
https://github.com/libsdl-org/SDL
synced 2024-11-20 16:06:10 -07:00
GPU Vulkan: release submitted command buffer after defrag (#11430)
This commit is contained in:
parent
1ed1bc1d5d
commit
332fd824f0
1 changed files with 25 additions and 13 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue