From 1ac0e48fde75a80f52fd87d58d60791bd10f1222 Mon Sep 17 00:00:00 2001 From: routersys Date: Fri, 17 Jul 2026 10:44:48 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=97=E3=83=BC=E3=83=AB=E8=83=8C=E5=9C=A7?= =?UTF-8?q?=E5=BE=85=E6=A9=9F=E3=82=92=E3=83=AD=E3=83=83=E3=82=AF=E5=A4=96?= =?UTF-8?q?=E3=81=B8=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/Interop/ID3D12CommandListPool.cs | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/ComputeSharp/Graphics/Commands/Interop/ID3D12CommandListPool.cs b/src/ComputeSharp/Graphics/Commands/Interop/ID3D12CommandListPool.cs index f1e9aad7..e022091b 100644 --- a/src/ComputeSharp/Graphics/Commands/Interop/ID3D12CommandListPool.cs +++ b/src/ComputeSharp/Graphics/Commands/Interop/ID3D12CommandListPool.cs @@ -77,26 +77,36 @@ internal readonly unsafe struct ID3D12CommandListPool(D3D12_COMMAND_LIST_TYPE d3 public void ReturnWhenCompleted(ID3D12GraphicsCommandList* d3D12CommandList, ID3D12CommandAllocator* d3D12CommandAllocator, ulong fenceValue, GraphicsResourceLeaseSet? resourceLeases) { + PendingD3D12CommandListBundle pendingD3D12CommandListBundle = default; + bool hasPendingD3D12CommandListBundle = false; + lock (this.d3D12CommandListBundleQueue) { ReclaimCompletedCommandLists(); if (this.pendingD3D12CommandListBundleQueue.Count == MaximumPendingCommandListCount) { - PendingD3D12CommandListBundle pendingD3D12CommandListBundle = this.pendingD3D12CommandListBundleQueue.Dequeue(); - - if (pendingD3D12CommandListBundle.FenceValue > d3D12Fence->GetCompletedValue()) - { - d3D12Fence->SetEventOnCompletion(pendingD3D12CommandListBundle.FenceValue, default).Assert(); - } - - pendingD3D12CommandListBundle.ResourceLeases?.Release(); - - this.d3D12CommandListBundleQueue.Enqueue(pendingD3D12CommandListBundle.D3D12CommandListBundle); + pendingD3D12CommandListBundle = this.pendingD3D12CommandListBundleQueue.Dequeue(); + hasPendingD3D12CommandListBundle = true; } this.pendingD3D12CommandListBundleQueue.Enqueue(new PendingD3D12CommandListBundle(d3D12CommandList, d3D12CommandAllocator, fenceValue, resourceLeases)); } + + if (hasPendingD3D12CommandListBundle) + { + if (pendingD3D12CommandListBundle.FenceValue > d3D12Fence->GetCompletedValue()) + { + d3D12Fence->SetEventOnCompletion(pendingD3D12CommandListBundle.FenceValue, default).Assert(); + } + + pendingD3D12CommandListBundle.ResourceLeases?.Release(); + + lock (this.d3D12CommandListBundleQueue) + { + this.d3D12CommandListBundleQueue.Enqueue(pendingD3D12CommandListBundle.D3D12CommandListBundle); + } + } } ///