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. ///