Removed SetPipelineState call when dispatching shaders
このコミットが含まれているのは:
1 親
9d9ea4c70f
コミット
11a1414517
5ファイル変更
+54
-18
検索条件に一致するファイルはありません
@@ -56,6 +56,28 @@ namespace ComputeSharp.Graphics.Commands
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="CommandList"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance to use.</param>
|
||||
/// <param name="d3D12PipelineState">The <see cref="ID3D12PipelineState"/> instance to use for the new command list.</param>
|
||||
public CommandList(GraphicsDevice device, ID3D12PipelineState* d3D12PipelineState)
|
||||
{
|
||||
this.device = device;
|
||||
this.d3D12CommandListType = D3D12_COMMAND_LIST_TYPE_COMPUTE;
|
||||
|
||||
Unsafe.SkipInit(out this.d3D12GraphicsCommandList);
|
||||
Unsafe.SkipInit(out this.d3D12CommandAllocator);
|
||||
|
||||
device.GetCommandListAndAllocator(
|
||||
d3D12PipelineState,
|
||||
out *(ID3D12GraphicsCommandList**)Unsafe.AsPointer(ref this.d3D12GraphicsCommandList),
|
||||
out *(ID3D12CommandAllocator**)Unsafe.AsPointer(ref this.d3D12CommandAllocator));
|
||||
|
||||
// Set the heap descriptor for the command list
|
||||
device.SetDescriptorHeapForCommandList(this.d3D12GraphicsCommandList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the command list type being used by the current instance.
|
||||
/// </summary>
|
||||
|
||||
@@ -36,16 +36,17 @@ namespace ComputeSharp.Graphics.Commands.Interop
|
||||
/// Rents a <see cref="ID3D12GraphicsCommandList"/> and <see cref="ID3D12CommandAllocator"/> pair.
|
||||
/// </summary>
|
||||
/// <param name="d3D12Device">The <see cref="ID3D12Device"/> renting the command list.</param>
|
||||
/// <param name="d3D12PipelineState">The <see cref="ID3D12PipelineState"/> instance to use for the new command list.</param>
|
||||
/// <param name="d3D12CommandList">The resulting <see cref="ID3D12GraphicsCommandList"/> value.</param>
|
||||
/// <param name="d3D12CommandAllocator">The resulting <see cref="ID3D12CommandAllocator"/> value.</param>
|
||||
public void Rent(ID3D12Device* d3D12Device, out ID3D12GraphicsCommandList* d3D12CommandList, out ID3D12CommandAllocator* d3D12CommandAllocator)
|
||||
public void Rent(ID3D12Device* d3D12Device, ID3D12PipelineState* d3D12PipelineState, out ID3D12GraphicsCommandList* d3D12CommandList, out ID3D12CommandAllocator* d3D12CommandAllocator)
|
||||
{
|
||||
lock (this.d3D12CommandListBundleQueue)
|
||||
{
|
||||
if (this.d3D12CommandListBundleQueue.TryDequeue(out D3D12CommandListBundle d3D12CommandListBundle))
|
||||
{
|
||||
d3D12CommandListBundle.D3D12CommandAllocator->Reset().Assert();
|
||||
d3D12CommandListBundle.D3D12CommandList->Reset(d3D12CommandListBundle.D3D12CommandAllocator, null).Assert();
|
||||
d3D12CommandListBundle.D3D12CommandList->Reset(d3D12CommandListBundle.D3D12CommandAllocator, d3D12PipelineState).Assert();
|
||||
|
||||
d3D12CommandList = d3D12CommandListBundle.D3D12CommandList;
|
||||
d3D12CommandAllocator = d3D12CommandListBundle.D3D12CommandAllocator;
|
||||
@@ -53,7 +54,7 @@ namespace ComputeSharp.Graphics.Commands.Interop
|
||||
return;
|
||||
}
|
||||
|
||||
CreateCommandListAndAllocator(d3D12Device, out d3D12CommandList, out d3D12CommandAllocator);
|
||||
CreateCommandListAndAllocator(d3D12Device, d3D12PipelineState, out d3D12CommandList, out d3D12CommandAllocator);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,13 +90,14 @@ namespace ComputeSharp.Graphics.Commands.Interop
|
||||
/// Creates a new <see cref="ID3D12CommandList"/> and <see cref="ID3D12CommandAllocator"/> pair.
|
||||
/// </summary>
|
||||
/// <param name="d3D12Device">The <see cref="ID3D12Device"/> renting the command list.</param>
|
||||
/// <param name="d3D12PipelineState">The <see cref="ID3D12PipelineState"/> instance to use for the new command list.</param>
|
||||
/// <param name="d3D12CommandList">The resulting <see cref="ID3D12GraphicsCommandList"/> value.</param>
|
||||
/// <param name="d3D12CommandAllocator">The resulting <see cref="ID3D12CommandAllocator"/> value.</param>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private void CreateCommandListAndAllocator(ID3D12Device* d3D12Device, out ID3D12GraphicsCommandList* d3D12CommandList, out ID3D12CommandAllocator* d3D12CommandAllocator)
|
||||
private void CreateCommandListAndAllocator(ID3D12Device* d3D12Device, ID3D12PipelineState* d3D12PipelineState, out ID3D12GraphicsCommandList* d3D12CommandList, out ID3D12CommandAllocator* d3D12CommandAllocator)
|
||||
{
|
||||
using ComPtr<ID3D12CommandAllocator> d3D12CommandAllocatorComPtr = d3D12Device->CreateCommandAllocator(this.d3D12CommandListType);
|
||||
using ComPtr<ID3D12GraphicsCommandList> d3D12CommandListComPtr = d3D12Device->CreateCommandList(this.d3D12CommandListType, d3D12CommandAllocatorComPtr.Get());
|
||||
using ComPtr<ID3D12GraphicsCommandList> d3D12CommandListComPtr = d3D12Device->CreateCommandList(this.d3D12CommandListType, d3D12CommandAllocatorComPtr.Get(), d3D12PipelineState);
|
||||
|
||||
fixed (ID3D12GraphicsCommandList** d3D12CommandListPtr = &d3D12CommandList)
|
||||
fixed (ID3D12CommandAllocator** d3D12CommandAllocatorPtr = &d3D12CommandAllocator)
|
||||
|
||||
@@ -260,12 +260,14 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
/// <param name="d3D12Device">The target <see cref="ID3D12Device"/> to use to create the command list.</param>
|
||||
/// <param name="d3D12CommandListType">The type of command list to create.</param>
|
||||
/// <param name="d3D12CommandAllocator">The command allocator to use to create the command list.</param>
|
||||
/// <param name="d3D12PipelineState">The initial <see cref="ID3D12PipelineState"/> object, if present.</param>
|
||||
/// <returns>A pointer to the newly allocated <see cref="ID3D12GraphicsCommandList"/> instance.</returns>
|
||||
/// <exception cref="Exception">Thrown when the creation of the command list fails.</exception>
|
||||
public static ComPtr<ID3D12GraphicsCommandList> CreateCommandList(
|
||||
this ref ID3D12Device d3D12Device,
|
||||
D3D12_COMMAND_LIST_TYPE d3D12CommandListType,
|
||||
ID3D12CommandAllocator* d3D12CommandAllocator)
|
||||
ID3D12CommandAllocator* d3D12CommandAllocator,
|
||||
ID3D12PipelineState* d3D12PipelineState)
|
||||
{
|
||||
using ComPtr<ID3D12GraphicsCommandList> d3D12GraphicsCommandList = default;
|
||||
|
||||
@@ -273,7 +275,7 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
0,
|
||||
d3D12CommandListType,
|
||||
d3D12CommandAllocator,
|
||||
null,
|
||||
d3D12PipelineState,
|
||||
FX.__uuidof<ID3D12GraphicsCommandList>(),
|
||||
d3D12GraphicsCommandList.GetVoidAddressOf()).Assert();
|
||||
|
||||
|
||||
@@ -252,6 +252,7 @@ namespace ComputeSharp
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID3D12DescriptorHandleAllocator.Rent"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal void RentShaderResourceViewDescriptorHandles(
|
||||
out D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle,
|
||||
out D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle)
|
||||
@@ -260,6 +261,7 @@ namespace ComputeSharp
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID3D12DescriptorHandleAllocator.Return"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal void ReturnShaderResourceViewDescriptorHandles(
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle,
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle)
|
||||
@@ -271,6 +273,7 @@ namespace ComputeSharp
|
||||
/// <param name="d3D12CommandListType">The type of command allocator to rent.</param>
|
||||
/// <param name="d3D12CommandList">The resulting <see cref="ID3D12GraphicsCommandList"/> value.</param>
|
||||
/// <param name="d3D12CommandAllocator">The resulting <see cref="ID3D12CommandAllocator"/> value.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal void GetCommandListAndAllocator(
|
||||
D3D12_COMMAND_LIST_TYPE d3D12CommandListType,
|
||||
out ID3D12GraphicsCommandList* d3D12CommandList,
|
||||
@@ -279,10 +282,10 @@ namespace ComputeSharp
|
||||
switch (d3D12CommandListType)
|
||||
{
|
||||
case D3D12_COMMAND_LIST_TYPE_COMPUTE:
|
||||
this.computeCommandListPool.Rent(this.d3D12Device.Get(), out d3D12CommandList, out d3D12CommandAllocator);
|
||||
this.computeCommandListPool.Rent(this.d3D12Device.Get(), null, out d3D12CommandList, out d3D12CommandAllocator);
|
||||
break;
|
||||
case D3D12_COMMAND_LIST_TYPE_COPY:
|
||||
this.copyCommandListPool.Rent(this.d3D12Device.Get(), out d3D12CommandList, out d3D12CommandAllocator);
|
||||
this.copyCommandListPool.Rent(this.d3D12Device.Get(), null, out d3D12CommandList, out d3D12CommandAllocator);
|
||||
break;
|
||||
default:
|
||||
ThrowHelper.ThrowArgumentException<ComPtr<ID3D12CommandAllocator>>();
|
||||
@@ -292,10 +295,24 @@ namespace ComputeSharp
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID3D12CommandListPool.Rent"/>
|
||||
/// <param name="d3D12PipelineState">The <see cref="ID3D12PipelineState"/> instance to use for the new command list.</param>
|
||||
/// <param name="d3D12CommandList">The resulting <see cref="ID3D12GraphicsCommandList"/> value.</param>
|
||||
/// <param name="d3D12CommandAllocator">The resulting <see cref="ID3D12CommandAllocator"/> value.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal void GetCommandListAndAllocator(
|
||||
ID3D12PipelineState* d3D12PipelineState,
|
||||
out ID3D12GraphicsCommandList* d3D12CommandList,
|
||||
out ID3D12CommandAllocator* d3D12CommandAllocator)
|
||||
{
|
||||
this.computeCommandListPool.Rent(this.d3D12Device.Get(), d3D12PipelineState, out d3D12CommandList, out d3D12CommandAllocator);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the descriptor heap for a given <see cref="ID3D12GraphicsCommandList"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="d3D12GraphicsCommandList">The input <see cref="ID3D12GraphicsCommandList"/> instance to use.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal void SetDescriptorHeapForCommandList(ID3D12GraphicsCommandList* d3D12GraphicsCommandList)
|
||||
{
|
||||
ID3D12DescriptorHeap* d3D12DescriptorHeap = this.shaderResourceViewDescriptorAllocator.D3D12DescriptorHeap;
|
||||
|
||||
@@ -10,7 +10,6 @@ using ComputeSharp.__Internals;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
using TerraFX.Interop;
|
||||
using FX = TerraFX.Interop.Windows;
|
||||
using static TerraFX.Interop.D3D12_COMMAND_LIST_TYPE;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
@@ -148,10 +147,9 @@ namespace ComputeSharp.Shaders
|
||||
}
|
||||
}
|
||||
|
||||
using CommandList commandList = new(device, D3D12_COMMAND_LIST_TYPE_COMPUTE);
|
||||
using CommandList commandList = new(device, pipelineData.D3D12PipelineState);
|
||||
|
||||
commandList.D3D12GraphicsCommandList->SetComputeRootSignature(pipelineData.D3D12RootSignature);
|
||||
commandList.D3D12GraphicsCommandList->SetPipelineState(pipelineData.D3D12PipelineState);
|
||||
|
||||
ComputeShaderDispatchDataLoader dataLoader = new(commandList.D3D12GraphicsCommandList);
|
||||
|
||||
@@ -172,7 +170,6 @@ namespace ComputeSharp.Shaders
|
||||
{
|
||||
device.ThrowIfDisposed();
|
||||
|
||||
// Calculate the dispatch values
|
||||
int
|
||||
x = texture.Width,
|
||||
y = texture.Height,
|
||||
@@ -184,7 +181,6 @@ namespace ComputeSharp.Shaders
|
||||
Guard.IsBetweenOrEqualTo(groupsX, 1, FX.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX));
|
||||
Guard.IsBetweenOrEqualTo(groupsY, 1, FX.D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION, nameof(groupsX));
|
||||
|
||||
// Create the shader key
|
||||
ShaderKey key = new(shader.GetDispatchId(), threadsX, threadsY, 1);
|
||||
PipelineData? pipelineData;
|
||||
|
||||
@@ -206,11 +202,9 @@ namespace ComputeSharp.Shaders
|
||||
}
|
||||
}
|
||||
|
||||
// Create the commands list and set the pipeline state
|
||||
using CommandList commandList = new(device, D3D12_COMMAND_LIST_TYPE_COMPUTE);
|
||||
using CommandList commandList = new(device, pipelineData.D3D12PipelineState);
|
||||
|
||||
commandList.D3D12GraphicsCommandList->SetComputeRootSignature(pipelineData.D3D12RootSignature);
|
||||
commandList.D3D12GraphicsCommandList->SetPipelineState(pipelineData.D3D12PipelineState);
|
||||
|
||||
PixelShaderDispatchDataLoader dataLoader = new(commandList.D3D12GraphicsCommandList);
|
||||
|
||||
@@ -221,7 +215,6 @@ namespace ComputeSharp.Shaders
|
||||
1,
|
||||
((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetGpuDescriptorHandle(device));
|
||||
|
||||
// Dispatch and wait for completion
|
||||
commandList.D3D12GraphicsCommandList->Dispatch((uint)groupsX, (uint)groupsY, 1);
|
||||
commandList.ExecuteAndWaitForCompletion();
|
||||
}
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする