From b2cf968fd819923be84a1afbbcbaffbcbfd07313 Mon Sep 17 00:00:00 2001 From: routersys Date: Fri, 17 Jul 2026 10:44:50 +0900 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E7=95=99=E3=82=B3=E3=83=9E=E3=83=B3?= =?UTF-8?q?=E3=83=89=E3=83=AA=E3=82=B9=E3=83=88=E4=B8=8A=E9=99=90=E3=82=92?= =?UTF-8?q?AppContext=E3=81=A7=E6=A7=8B=E6=88=90=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/Interop/ID3D12CommandListPool.cs | 11 +++++------ src/ComputeSharp/Graphics/GraphicsDevice.cs | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/ComputeSharp/Graphics/Commands/Interop/ID3D12CommandListPool.cs b/src/ComputeSharp/Graphics/Commands/Interop/ID3D12CommandListPool.cs index e022091b..5aa6108d 100644 --- a/src/ComputeSharp/Graphics/Commands/Interop/ID3D12CommandListPool.cs +++ b/src/ComputeSharp/Graphics/Commands/Interop/ID3D12CommandListPool.cs @@ -12,16 +12,15 @@ namespace ComputeSharp.Graphics.Commands.Interop; /// /// The command list type to use. /// The fence used to track deferred command list completion. -internal readonly unsafe struct ID3D12CommandListPool(D3D12_COMMAND_LIST_TYPE d3D12CommandListType, ID3D12Fence* d3D12Fence) : IDisposable +/// 保留可能なコマンドリスト数の上限。 +internal readonly unsafe struct ID3D12CommandListPool(D3D12_COMMAND_LIST_TYPE d3D12CommandListType, ID3D12Fence* d3D12Fence, int maximumPendingCommandListCount) : IDisposable { - private const int MaximumPendingCommandListCount = 16; - /// /// The queue of items with the available command lists. /// - private readonly Queue d3D12CommandListBundleQueue = new(MaximumPendingCommandListCount * 2); + private readonly Queue d3D12CommandListBundleQueue = new(maximumPendingCommandListCount * 2); - private readonly Queue pendingD3D12CommandListBundleQueue = new(MaximumPendingCommandListCount); + private readonly Queue pendingD3D12CommandListBundleQueue = new(maximumPendingCommandListCount); /// /// Rents a and pair. @@ -84,7 +83,7 @@ internal readonly unsafe struct ID3D12CommandListPool(D3D12_COMMAND_LIST_TYPE d3 { ReclaimCompletedCommandLists(); - if (this.pendingD3D12CommandListBundleQueue.Count == MaximumPendingCommandListCount) + if (this.pendingD3D12CommandListBundleQueue.Count >= maximumPendingCommandListCount) { pendingD3D12CommandListBundle = this.pendingD3D12CommandListBundleQueue.Dequeue(); hasPendingD3D12CommandListBundle = true; diff --git a/src/ComputeSharp/Graphics/GraphicsDevice.cs b/src/ComputeSharp/Graphics/GraphicsDevice.cs index da2b5605..9f3136f4 100644 --- a/src/ComputeSharp/Graphics/GraphicsDevice.cs +++ b/src/ComputeSharp/Graphics/GraphicsDevice.cs @@ -153,9 +153,11 @@ public sealed unsafe partial class GraphicsDevice : IReferenceTrackedObject this.d3D12CopyCommandQueue = d3D12Device->CreateCommandQueue(D3D12_COMMAND_LIST_TYPE_COPY); this.d3D12ComputeFence = d3D12Device->CreateFence(); this.d3D12CopyFence = d3D12Device->CreateFence(); + int maximumPendingCommandListCount = GetMaximumPendingCommandListCount(); + this.shaderResourceViewDescriptorAllocator = new ID3D12DescriptorHandleAllocator(d3D12Device); - this.computeCommandListPool = new ID3D12CommandListPool(D3D12_COMMAND_LIST_TYPE_COMPUTE, this.d3D12ComputeFence.Get()); - this.copyCommandListPool = new ID3D12CommandListPool(D3D12_COMMAND_LIST_TYPE_COPY, this.d3D12CopyFence.Get()); + this.computeCommandListPool = new ID3D12CommandListPool(D3D12_COMMAND_LIST_TYPE_COMPUTE, this.d3D12ComputeFence.Get(), maximumPendingCommandListCount); + this.copyCommandListPool = new ID3D12CommandListPool(D3D12_COMMAND_LIST_TYPE_COPY, this.d3D12CopyFence.Get(), maximumPendingCommandListCount); this.allocator = new ComPtr(allocator); Luid = Luid.FromLUID(dxgiDescription1->AdapterLuid); @@ -342,6 +344,16 @@ public sealed unsafe partial class GraphicsDevice : IReferenceTrackedObject D3D12_FORMAT_SUPPORT1_TEXTURE3D | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW); } + private static int GetMaximumPendingCommandListCount() + { + return AppContext.GetData("ComputeSharp.MaximumPendingCommandListCount") switch + { + int count when count > 0 => count, + string text when int.TryParse(text, out int count) && count > 0 => count, + _ => 16 + }; + } + /// /// Registers a object for the current device to enable early disposal. ///