From 94c2d15895a0846f937536278eae25d955400984 Mon Sep 17 00:00:00 2001 From: Caleb Cornett Date: Thu, 26 Oct 2023 21:39:15 -0500 Subject: [PATCH] Fix command buffer memory leak --- src/Refresh_Driver_D3D11.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Refresh_Driver_D3D11.c b/src/Refresh_Driver_D3D11.c index 9b47552..2b8ef9c 100644 --- a/src/Refresh_Driver_D3D11.c +++ b/src/Refresh_Driver_D3D11.c @@ -2483,8 +2483,6 @@ static void D3D11_Submit( renderer->submittedCommandBuffers[renderer->submittedCommandBufferCount] = d3d11CommandBuffer; renderer->submittedCommandBufferCount += 1; - SDL_UnlockMutex(renderer->contextLock); - /* Present, if applicable */ if (d3d11CommandBuffer->swapchainData) { @@ -2495,6 +2493,27 @@ static void D3D11_Submit( ); } + /* Check if we can perform any cleanups */ + for (int32_t i = renderer->submittedCommandBufferCount - 1; i >= 0; i -= 1) + { + BOOL queryData; + + res = ID3D11DeviceContext_GetData( + renderer->immediateContext, + (ID3D11Asynchronous*) renderer->submittedCommandBuffers[i]->completionQuery, + &queryData, + sizeof(queryData), + 0 + ); + if (res == S_OK) + { + D3D11_INTERNAL_CleanCommandBuffer( + renderer, + renderer->submittedCommandBuffers[i] + ); + } + } + SDL_UnlockMutex(renderer->contextLock); }