From 013a518f3da47b6ea322c7cfd6745dbd8085a38f Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 17 Jul 2021 15:44:33 +0200 Subject: [PATCH] Fixed missing call to SetDescriptorHeaps for reused lists --- .../Graphics/Commands/CommandList.cs | 7 +++++++ .../Commands/Interop/ID3D12CommandListPool.cs | 18 +----------------- src/ComputeSharp/Graphics/GraphicsDevice.cs | 15 +++++++++++++-- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/ComputeSharp/Graphics/Commands/CommandList.cs b/src/ComputeSharp/Graphics/Commands/CommandList.cs index 42f0ffc8..993aad79 100644 --- a/src/ComputeSharp/Graphics/Commands/CommandList.cs +++ b/src/ComputeSharp/Graphics/Commands/CommandList.cs @@ -2,6 +2,7 @@ using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; using TerraFX.Interop; +using static TerraFX.Interop.D3D12_COMMAND_LIST_TYPE; namespace ComputeSharp.Graphics.Commands { @@ -47,6 +48,12 @@ namespace ComputeSharp.Graphics.Commands d3D12CommandListType, out *(ID3D12GraphicsCommandList**)Unsafe.AsPointer(ref this.d3D12GraphicsCommandList), out *(ID3D12CommandAllocator**)Unsafe.AsPointer(ref this.d3D12CommandAllocator)); + + // Set the heap descriptor if the command list is not for copy operations + if (d3D12CommandListType is not D3D12_COMMAND_LIST_TYPE_COPY) + { + device.SetDescriptorHeapForCommandList(this.d3D12GraphicsCommandList); + } } /// diff --git a/src/ComputeSharp/Graphics/Commands/Interop/ID3D12CommandListPool.cs b/src/ComputeSharp/Graphics/Commands/Interop/ID3D12CommandListPool.cs index b3b16ebd..5c74e0df 100644 --- a/src/ComputeSharp/Graphics/Commands/Interop/ID3D12CommandListPool.cs +++ b/src/ComputeSharp/Graphics/Commands/Interop/ID3D12CommandListPool.cs @@ -4,7 +4,6 @@ using System.Runtime.CompilerServices; using ComputeSharp.Core.Extensions; using ComputeSharp.Graphics.Extensions; using TerraFX.Interop; -using static TerraFX.Interop.D3D12_COMMAND_LIST_TYPE; namespace ComputeSharp.Graphics.Commands.Interop { @@ -18,11 +17,6 @@ namespace ComputeSharp.Graphics.Commands.Interop /// private readonly D3D12_COMMAND_LIST_TYPE d3D12CommandListType; - /// - /// The object in use for the current instance. - /// - private readonly ID3D12DescriptorHeap* d3D12DescriptorHeap; - /// /// The queue of items with the available command lists. /// @@ -32,11 +26,9 @@ namespace ComputeSharp.Graphics.Commands.Interop /// Creates a new instance with the specified parameters. /// /// The command list type to use. - /// The object in use for the current instance. - public ID3D12CommandListPool(D3D12_COMMAND_LIST_TYPE d3D12CommandListType, ID3D12DescriptorHeap* d3D12DescriptorHeap) + public ID3D12CommandListPool(D3D12_COMMAND_LIST_TYPE d3D12CommandListType) { this.d3D12CommandListType = d3D12CommandListType; - this.d3D12DescriptorHeap = d3D12DescriptorHeap; this.d3D12CommandListBundleQueue = new Queue(); } @@ -105,14 +97,6 @@ namespace ComputeSharp.Graphics.Commands.Interop using ComPtr d3D12CommandAllocatorComPtr = d3D12Device->CreateCommandAllocator(this.d3D12CommandListType); using ComPtr d3D12CommandListComPtr = d3D12Device->CreateCommandList(this.d3D12CommandListType, d3D12CommandAllocatorComPtr.Get()); - // Set the heap descriptor if the command list is not for copy operations - if (this.d3D12CommandListType is not D3D12_COMMAND_LIST_TYPE_COPY) - { - ID3D12DescriptorHeap* d3D12DescriptorHeap = this.d3D12DescriptorHeap; - - d3D12CommandListComPtr.Get()->SetDescriptorHeaps(1, &d3D12DescriptorHeap); - } - fixed (ID3D12GraphicsCommandList** d3D12CommandListPtr = &d3D12CommandList) fixed (ID3D12CommandAllocator** d3D12CommandAllocatorPtr = &d3D12CommandAllocator) { diff --git a/src/ComputeSharp/Graphics/GraphicsDevice.cs b/src/ComputeSharp/Graphics/GraphicsDevice.cs index 30932b32..4d6900ed 100644 --- a/src/ComputeSharp/Graphics/GraphicsDevice.cs +++ b/src/ComputeSharp/Graphics/GraphicsDevice.cs @@ -98,8 +98,8 @@ namespace ComputeSharp this.d3D12CopyFence = d3D12Device->CreateFence(); this.shaderResourceViewDescriptorAllocator = new ID3D12DescriptorHandleAllocator(d3D12Device); - this.computeCommandListPool = new ID3D12CommandListPool(D3D12_COMMAND_LIST_TYPE_COMPUTE, this.shaderResourceViewDescriptorAllocator.D3D12DescriptorHeap); - this.copyCommandListPool = new ID3D12CommandListPool(D3D12_COMMAND_LIST_TYPE_COPY, null); + this.computeCommandListPool = new ID3D12CommandListPool(D3D12_COMMAND_LIST_TYPE_COMPUTE); + this.copyCommandListPool = new ID3D12CommandListPool(D3D12_COMMAND_LIST_TYPE_COPY); Luid = Luid.FromLUID(dxgiDescription1->AdapterLuid); Name = new string((char*)dxgiDescription1->Description); @@ -292,6 +292,17 @@ namespace ComputeSharp } } + /// + /// Sets the descriptor heap for a given instance. + /// + /// The input instance to use. + internal void SetDescriptorHeapForCommandList(ID3D12GraphicsCommandList* d3D12GraphicsCommandList) + { + ID3D12DescriptorHeap* d3D12DescriptorHeap = this.shaderResourceViewDescriptorAllocator.D3D12DescriptorHeap; + + d3D12GraphicsCommandList->SetDescriptorHeaps(1, &d3D12DescriptorHeap); + } + /// /// Executes a given command list and waits for the operation to be completed. ///