GPU: Add SDL_CancelGPUCommandBuffer (#11316)

---------

Co-authored-by: Caleb Cornett <caleb.cornett@outlook.com>
This commit is contained in:
Evan Hemsley 2024-10-29 14:43:22 -07:00 committed by GitHub
parent 94d110edd5
commit b4dff42dcd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 389 additions and 147 deletions

View file

@ -7297,18 +7297,20 @@ static bool D3D12_INTERNAL_CopyTextureDownload(
static bool D3D12_INTERNAL_CleanCommandBuffer(
D3D12Renderer *renderer,
D3D12CommandBuffer *commandBuffer)
D3D12CommandBuffer *commandBuffer,
bool cancel)
{
Uint32 i;
HRESULT res;
bool result = true;
// Perform deferred texture data copies
for (i = 0; i < commandBuffer->textureDownloadCount; i += 1) {
result &= D3D12_INTERNAL_CopyTextureDownload(
commandBuffer,
commandBuffer->textureDownloads[i]);
if (!cancel) {
result &= D3D12_INTERNAL_CopyTextureDownload(
commandBuffer,
commandBuffer->textureDownloads[i]);
}
SDL_free(commandBuffer->textureDownloads[i]);
}
commandBuffer->textureDownloadCount = 0;
@ -7401,10 +7403,12 @@ static bool D3D12_INTERNAL_CleanCommandBuffer(
SDL_UnlockMutex(renderer->acquireCommandBufferLock);
// Remove this command buffer from the submitted list
for (i = 0; i < renderer->submittedCommandBufferCount; i += 1) {
if (renderer->submittedCommandBuffers[i] == commandBuffer) {
renderer->submittedCommandBuffers[i] = renderer->submittedCommandBuffers[renderer->submittedCommandBufferCount - 1];
renderer->submittedCommandBufferCount -= 1;
if (!cancel) {
for (i = 0; i < renderer->submittedCommandBufferCount; i += 1) {
if (renderer->submittedCommandBuffers[i] == commandBuffer) {
renderer->submittedCommandBuffers[i] = renderer->submittedCommandBuffers[renderer->submittedCommandBufferCount - 1];
renderer->submittedCommandBufferCount -= 1;
}
}
}
@ -7573,7 +7577,8 @@ static bool D3D12_Submit(
if (fenceValue == D3D12_FENCE_SIGNAL_VALUE) {
result &= D3D12_INTERNAL_CleanCommandBuffer(
renderer,
renderer->submittedCommandBuffers[i]);
renderer->submittedCommandBuffers[i],
false);
}
}
@ -7589,10 +7594,32 @@ static SDL_GPUFence *D3D12_SubmitAndAcquireFence(
{
D3D12CommandBuffer *d3d12CommandBuffer = (D3D12CommandBuffer *)commandBuffer;
d3d12CommandBuffer->autoReleaseFence = false;
D3D12_Submit(commandBuffer);
if (!D3D12_Submit(commandBuffer)) {
return NULL;
}
return (SDL_GPUFence *)d3d12CommandBuffer->inFlightFence;
}
static bool D3D12_Cancel(
SDL_GPUCommandBuffer *commandBuffer)
{
D3D12CommandBuffer *d3d12CommandBuffer = (D3D12CommandBuffer *)commandBuffer;
D3D12Renderer *renderer = d3d12CommandBuffer->renderer;
bool result;
HRESULT res;
// Notify the command buffer that we have completed recording
res = ID3D12GraphicsCommandList_Close(d3d12CommandBuffer->graphicsCommandList);
CHECK_D3D12_ERROR_AND_RETURN("Failed to close command list!", false);
d3d12CommandBuffer->autoReleaseFence = false;
SDL_LockMutex(renderer->submitLock);
result = D3D12_INTERNAL_CleanCommandBuffer(renderer, d3d12CommandBuffer, true);
SDL_UnlockMutex(renderer->submitLock);
return result;
}
static bool D3D12_Wait(
SDL_GPURenderer *driverData)
{
@ -7636,7 +7663,7 @@ static bool D3D12_Wait(
// Clean up
for (Sint32 i = renderer->submittedCommandBufferCount - 1; i >= 0; i -= 1) {
result &= D3D12_INTERNAL_CleanCommandBuffer(renderer, renderer->submittedCommandBuffers[i]);
result &= D3D12_INTERNAL_CleanCommandBuffer(renderer, renderer->submittedCommandBuffers[i], false);
}
D3D12_INTERNAL_PerformPendingDestroys(renderer);
@ -7692,7 +7719,8 @@ static bool D3D12_WaitForFences(
if (fenceValue == D3D12_FENCE_SIGNAL_VALUE) {
result &= D3D12_INTERNAL_CleanCommandBuffer(
renderer,
renderer->submittedCommandBuffers[i]);
renderer->submittedCommandBuffers[i],
false);
}
}