Code refactoring
このコミットが含まれているのは:
1 親
a292f8f017
コミット
e7bc76fd30
6ファイル変更
+142
-90
検索条件に一致するファイルはありません
@@ -67,7 +67,7 @@ namespace ComputeSharp.Graphics.Buffers
|
||||
|
||||
if (bufferType is BufferType.Constant or BufferType.ReadOnly or BufferType.ReadWrite)
|
||||
{
|
||||
GraphicsDevice.ShaderResourceViewDescriptorAllocator.Allocate(out D3D12CpuDescriptorHandle, out D3D12GpuDescriptorHandle);
|
||||
GraphicsDevice.AllocateShaderResourceViewDescriptorHandles(out D3D12CpuDescriptorHandle, out D3D12GpuDescriptorHandle);
|
||||
|
||||
switch (bufferType)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
@@ -36,7 +37,7 @@ namespace ComputeSharp.Graphics.Commands
|
||||
/// </summary>
|
||||
/// <param name="commandAllocator">The input <see cref="ID3D12CommandAllocator"/> to enqueue.</param>
|
||||
/// <param name="fenceValue">The fence value for the input <see cref="ID3D12CommandAllocator"/>.</param>
|
||||
public void Enqueue(ID3D12CommandAllocator* commandAllocator, ulong fenceValue)
|
||||
public void Enqueue(ComPtr<ID3D12CommandAllocator> commandAllocator, ulong fenceValue)
|
||||
{
|
||||
lock (this.d3d12CommandAllocatorQueue)
|
||||
{
|
||||
@@ -47,9 +48,11 @@ namespace ComputeSharp.Graphics.Commands
|
||||
/// <summary>
|
||||
/// Gets a new or reused <see cref="ID3D12CommandAllocator"/> item to use to issue GPU commands.
|
||||
/// </summary>
|
||||
[Pure]
|
||||
public ID3D12CommandAllocator* GetCommandAllocator(ID3D12Device* d3D12Device, ID3D12Fence* d3D12Fence)
|
||||
/// <returns>The rented <see cref="ID3D12CommandAllocator"/> object to use.</returns>
|
||||
public ComPtr<ID3D12CommandAllocator> GetCommandAllocator(ID3D12Device* d3D12Device, ID3D12Fence* d3D12Fence)
|
||||
{
|
||||
using ComPtr<ID3D12CommandAllocator> d3D12CommandAllocator = default;
|
||||
|
||||
lock (this.d3d12CommandAllocatorQueue)
|
||||
{
|
||||
// See if there is a reusable command allocator
|
||||
@@ -57,14 +60,18 @@ namespace ComputeSharp.Graphics.Commands
|
||||
{
|
||||
ID3D12CommandAllocatorEntry d3D12CommandAllocatorEntry = this.d3d12CommandAllocatorQueue.Peek();
|
||||
|
||||
d3D12CommandAllocatorEntry.D3D12CommandAllocator.Swap(ref *&d3D12CommandAllocator);
|
||||
|
||||
// We found one that is no longer in use, reset it and return it
|
||||
if (d3D12CommandAllocatorEntry.FenceValue <= d3D12Fence->GetCompletedValue())
|
||||
{
|
||||
this.d3d12CommandAllocatorQueue.Dequeue();
|
||||
_ = this.d3d12CommandAllocatorQueue.Dequeue();
|
||||
|
||||
d3D12CommandAllocatorEntry.D3D12CommandAllocator->Reset();
|
||||
int result = d3D12CommandAllocator.Get()->Reset();
|
||||
|
||||
return d3D12CommandAllocatorEntry.D3D12CommandAllocator;
|
||||
ThrowHelper.ThrowIfFailed(result);
|
||||
|
||||
return d3D12CommandAllocator.Move();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,18 +82,26 @@ namespace ComputeSharp.Graphics.Commands
|
||||
/// <inheritdoc cref="IDisposable.Dispose"/>
|
||||
public void Dispose()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
lock (this.d3d12CommandAllocatorQueue)
|
||||
{
|
||||
foreach (var entry in this.d3d12CommandAllocatorQueue)
|
||||
{
|
||||
entry.D3D12CommandAllocator.Dispose();
|
||||
}
|
||||
|
||||
this.d3d12CommandAllocatorQueue.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A type that stores info on pooled <see cref="ID3D12CommandAllocator"/> references.
|
||||
/// </summary>
|
||||
private readonly unsafe struct ID3D12CommandAllocatorEntry
|
||||
private unsafe struct ID3D12CommandAllocatorEntry
|
||||
{
|
||||
/// <summary>
|
||||
/// The current <see cref="ID3D12CommandAllocator"/> reference.
|
||||
/// </summary>
|
||||
public readonly ID3D12CommandAllocator* D3D12CommandAllocator;
|
||||
public ComPtr<ID3D12CommandAllocator> D3D12CommandAllocator;
|
||||
|
||||
/// <summary>
|
||||
/// The fence value for the current <see cref="ID3D12CommandAllocator"/> reference.
|
||||
@@ -98,7 +113,7 @@ namespace ComputeSharp.Graphics.Commands
|
||||
/// </summary>
|
||||
/// <param name="d3D12CommandAllocator">The input <see cref="ID3D12CommandAllocator"/> reference.</param>
|
||||
/// <param name="fenceValue">The fence value for the input <see cref="ID3D12CommandAllocator"/> reference.</param>
|
||||
public ID3D12CommandAllocatorEntry(ID3D12CommandAllocator* d3D12CommandAllocator, ulong fenceValue)
|
||||
public ID3D12CommandAllocatorEntry(ComPtr<ID3D12CommandAllocator> d3D12CommandAllocator, ulong fenceValue)
|
||||
{
|
||||
D3D12CommandAllocator = d3D12CommandAllocator;
|
||||
FenceValue = fenceValue;
|
||||
|
||||
@@ -24,12 +24,12 @@ namespace ComputeSharp.Graphics.Commands
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12CommandAllocator"/> object in use by the current instance.
|
||||
/// </summary>
|
||||
private readonly ID3D12CommandAllocator* d3D12CommandAllocator;
|
||||
private readonly ComPtr<ID3D12CommandAllocator> d3D12CommandAllocator;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12GraphicsCommandList"/> object in use by the current instance.
|
||||
/// </summary>
|
||||
public readonly ID3D12GraphicsCommandList* D3D12GraphicsCommandList;
|
||||
private readonly ComPtr<ID3D12GraphicsCommandList> d3D12GraphicsCommandList;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="CommandList2"/> instance with the specified parameters.
|
||||
@@ -40,21 +40,13 @@ namespace ComputeSharp.Graphics.Commands
|
||||
{
|
||||
this.device = device;
|
||||
this.d3d12CommandListType = d3d12CommandListType;
|
||||
this.d3D12CommandAllocator = d3d12CommandListType switch
|
||||
{
|
||||
D3D12_COMMAND_LIST_TYPE_COMPUTE => device.ComputeCommandAllocatorPool.GetCommandAllocator(device.D3D12Device, device.D3D12ComputeFence),
|
||||
D3D12_COMMAND_LIST_TYPE_COPY => device.ComputeCommandAllocatorPool.GetCommandAllocator(device.D3D12Device, device.D3D12CopyFence),
|
||||
_ => throw null!
|
||||
};
|
||||
|
||||
D3D12GraphicsCommandList = device.D3D12Device->CreateCommandList(d3d12CommandListType, d3D12CommandAllocator);
|
||||
this.d3D12CommandAllocator = device.GetCommandAllocator(d3d12CommandListType);
|
||||
this.d3D12GraphicsCommandList = device.D3D12Device->CreateCommandList(d3d12CommandListType, this.d3D12CommandAllocator);
|
||||
|
||||
// Set the heap descriptor if the command list is not for copy operations
|
||||
if (d3d12CommandListType is not D3D12_COMMAND_LIST_TYPE_COPY)
|
||||
{
|
||||
ID3D12DescriptorHeap* d3D12DescriptorHeap = device.ShaderResourceViewDescriptorAllocator.D3D12DescriptorHeap;
|
||||
|
||||
D3D12GraphicsCommandList->SetDescriptorHeaps(1, &d3D12DescriptorHeap);
|
||||
device.SetDescriptorHeapForCommandList(this.d3D12GraphicsCommandList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +60,7 @@ namespace ComputeSharp.Graphics.Commands
|
||||
/// <param name="numBytes">The total number of bytes to copy from one resource to another.</param>
|
||||
public void CopyBufferRegion(ID3D12Resource* d3D12ResourceSource, int sourceOffset, ID3D12Resource* d3d12ResourceDestination, int destinationOffset, int numBytes)
|
||||
{
|
||||
D3D12GraphicsCommandList->CopyBufferRegion(d3d12ResourceDestination, (uint)destinationOffset, d3D12ResourceSource, (uint)sourceOffset, (uint)numBytes);
|
||||
this.d3D12GraphicsCommandList.Get()->CopyBufferRegion(d3d12ResourceDestination, (uint)destinationOffset, d3D12ResourceSource, (uint)sourceOffset, (uint)numBytes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -78,7 +70,7 @@ namespace ComputeSharp.Graphics.Commands
|
||||
/// <param name="resource">The input <see cref="GraphicsResource"/> instance to bind.</param>
|
||||
public void SetComputeRootDescriptorTable(int rootParameterIndex, D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle)
|
||||
{
|
||||
D3D12GraphicsCommandList->SetComputeRootDescriptorTable((uint)rootParameterIndex, d3D12GpuDescriptorHandle);
|
||||
this.d3D12GraphicsCommandList.Get()->SetComputeRootDescriptorTable((uint)rootParameterIndex, d3D12GpuDescriptorHandle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -87,8 +79,8 @@ namespace ComputeSharp.Graphics.Commands
|
||||
/// <param name="pipelineState">The input <see cref="PipelineState"/> to setup.</param>
|
||||
public void SetPipelineData(PipelineData pipelineData)
|
||||
{
|
||||
D3D12GraphicsCommandList->SetComputeRootSignature(pipelineData.D3D12RootSignature);
|
||||
D3D12GraphicsCommandList->SetPipelineState(pipelineData.D3D12PipelineState);
|
||||
this.d3D12GraphicsCommandList.Get()->SetComputeRootSignature(pipelineData.D3D12RootSignature);
|
||||
this.d3D12GraphicsCommandList.Get()->SetPipelineState(pipelineData.D3D12PipelineState);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -99,7 +91,7 @@ namespace ComputeSharp.Graphics.Commands
|
||||
/// <param name="threadGroupCountZ">The number of thread groups to schedule for the Z axis.</param>
|
||||
public void Dispatch(int threadGroupCountX, int threadGroupCountY, int threadGroupCountZ)
|
||||
{
|
||||
D3D12GraphicsCommandList->Dispatch((uint)threadGroupCountX, (uint)threadGroupCountY, (uint)threadGroupCountZ);
|
||||
this.d3D12GraphicsCommandList.Get()->Dispatch((uint)threadGroupCountX, (uint)threadGroupCountY, (uint)threadGroupCountZ);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -107,7 +99,7 @@ namespace ComputeSharp.Graphics.Commands
|
||||
/// </summary>
|
||||
public void ExecuteAndWaitForCompletion()
|
||||
{
|
||||
D3D12GraphicsCommandList->Close();
|
||||
this.d3D12GraphicsCommandList.Get()->Close();
|
||||
|
||||
// TODO: GraphicsDevice.ExecuteCommandList(this);
|
||||
}
|
||||
@@ -115,17 +107,9 @@ namespace ComputeSharp.Graphics.Commands
|
||||
/// <inheritdoc cref="IDisposable.Dispose"/>
|
||||
public void Dispose()
|
||||
{
|
||||
switch (this.d3d12CommandListType)
|
||||
{
|
||||
case D3D12_COMMAND_LIST_TYPE_COMPUTE:
|
||||
device.ComputeCommandAllocatorPool.Enqueue(this.d3D12CommandAllocator, device.NextD3D12ComputeFenceValue);
|
||||
break;
|
||||
case D3D12_COMMAND_LIST_TYPE_COPY:
|
||||
device.CopyCommandAllocatorPool.Enqueue(this.d3D12CommandAllocator, device.NextD3D12CopyFenceValue);
|
||||
break;
|
||||
};
|
||||
this.device.EnqueueCommandAllocator(this.d3D12CommandAllocator.Move(), this.d3d12CommandListType);
|
||||
|
||||
D3D12GraphicsCommandList->Release();
|
||||
this.d3D12GraphicsCommandList.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,18 +33,12 @@ namespace ComputeSharp.Graphics.Commands
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ID3D12RootSignature"/> instance for the current <see cref="PipelineData"/> object.
|
||||
/// </summary>
|
||||
public ID3D12RootSignature* D3D12RootSignature
|
||||
{
|
||||
get => this.d3D12RootSignature;
|
||||
}
|
||||
public ID3D12RootSignature* D3D12RootSignature => this.d3D12RootSignature;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ID3D12PipelineState"/> instance for the current <see cref="PipelineData"/> object.
|
||||
/// </summary>
|
||||
public ID3D12PipelineState* D3D12PipelineState
|
||||
{
|
||||
get => this.d3D12PipelineState;
|
||||
}
|
||||
public ID3D12PipelineState* D3D12PipelineState => this.d3D12PipelineState;
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void Dispose(bool disposing)
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace ComputeSharp.Graphics
|
||||
/// <summary>
|
||||
/// A type that provides logic to create resource descriptors for a <see cref="GraphicsDevice"/> instance.
|
||||
/// </summary>
|
||||
internal unsafe struct DescriptorAllocator2
|
||||
internal unsafe struct DescriptorAllocator2 : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// The default number of available descriptors per heap.
|
||||
@@ -18,7 +18,7 @@ namespace ComputeSharp.Graphics
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12DescriptorHeap"/> in use for the current <see cref="DescriptorAllocator2"/> instance.
|
||||
/// </summary>
|
||||
public readonly ID3D12DescriptorHeap* D3D12DescriptorHeap;
|
||||
private ComPtr<ID3D12DescriptorHeap> d3D12DescriptorHeap;
|
||||
|
||||
/// <summary>
|
||||
/// The dummy object used to handle concurrent allocation requests.
|
||||
@@ -51,18 +51,24 @@ namespace ComputeSharp.Graphics
|
||||
/// <param name="device">The <see cref="ID3D12Device"/> instance to use</param>
|
||||
public DescriptorAllocator2(ID3D12Device* device)
|
||||
{
|
||||
D3D12DescriptorHeap = device->CreateDescriptorHeap(DescriptorsPerHeap);
|
||||
|
||||
this.d3D12DescriptorHeap = device->CreateDescriptorHeap(DescriptorsPerHeap);
|
||||
this.allocationLock = new object();
|
||||
this.descriptorSize = device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
|
||||
this.d3d12CpuDescriptorHandle = D3D12DescriptorHeap->GetCPUDescriptorHandleForHeapStart();
|
||||
this.d3d12GpuDescriptorHandle = D3D12DescriptorHeap->GetGPUDescriptorHandleForHeapStart();
|
||||
this.remainingHandles = D3D12DescriptorHeap->GetDesc().NumDescriptors;
|
||||
this.d3d12CpuDescriptorHandle = this.d3D12DescriptorHeap.Get()->GetCPUDescriptorHandleForHeapStart();
|
||||
this.d3d12GpuDescriptorHandle = this.d3D12DescriptorHeap.Get()->GetGPUDescriptorHandleForHeapStart();
|
||||
this.remainingHandles = this.d3D12DescriptorHeap.Get()->GetDesc().NumDescriptors;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ID3D12DescriptorHeap"/> in use for the current <see cref="DescriptorAllocator2"/> instance.
|
||||
/// </summary>
|
||||
public ID3D12DescriptorHeap* D3D12DescriptorHeap => this.d3D12DescriptorHeap;
|
||||
|
||||
/// <summary>
|
||||
/// Allocates a new CPU and GPU handle pair to use in a memory buffer
|
||||
/// </summary>
|
||||
/// <param name="d3d12CpuDescriptorHandle">The resulting <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> value.</param>
|
||||
/// <param name="d3d12CpuDescriptorHandle">The resulting <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> value.</param>
|
||||
public void Allocate(
|
||||
out D3D12_CPU_DESCRIPTOR_HANDLE d3d12CpuDescriptorHandle,
|
||||
out D3D12_GPU_DESCRIPTOR_HANDLE d3d12GpuDescriptorHandle)
|
||||
@@ -71,9 +77,9 @@ namespace ComputeSharp.Graphics
|
||||
{
|
||||
if (this.remainingHandles == 0)
|
||||
{
|
||||
this.d3d12CpuDescriptorHandle = D3D12DescriptorHeap->GetCPUDescriptorHandleForHeapStart();
|
||||
this.d3d12GpuDescriptorHandle = D3D12DescriptorHeap->GetGPUDescriptorHandleForHeapStart();
|
||||
this.remainingHandles = D3D12DescriptorHeap->GetDesc().NumDescriptors;
|
||||
this.d3d12CpuDescriptorHandle = this.d3D12DescriptorHeap.Get()->GetCPUDescriptorHandleForHeapStart();
|
||||
this.d3d12GpuDescriptorHandle = this.d3D12DescriptorHeap.Get()->GetGPUDescriptorHandleForHeapStart();
|
||||
this.remainingHandles = this.d3D12DescriptorHeap.Get()->GetDesc().NumDescriptors;
|
||||
}
|
||||
|
||||
d3d12CpuDescriptorHandle = this.d3d12CpuDescriptorHandle;
|
||||
@@ -85,10 +91,10 @@ namespace ComputeSharp.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IDisposable.Dispose"/>
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
D3D12DescriptorHeap->Release();
|
||||
this.d3D12DescriptorHeap.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,73 +15,74 @@ namespace ComputeSharp.Graphics
|
||||
/// <summary>
|
||||
/// The underlying <see cref="ID3D12Device"/> wrapped by the current instance.
|
||||
/// </summary>
|
||||
internal readonly ID3D12Device* D3D12Device;
|
||||
private ComPtr<ID3D12Device> d3D12Device;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12CommandQueue"/> instance to use for compute operations.
|
||||
/// </summary>
|
||||
internal readonly ID3D12CommandQueue* D3D12ComputeCommandQueue;
|
||||
private ComPtr<ID3D12CommandQueue> d3D12ComputeCommandQueue;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12CommandQueue"/> instance to use for copy operations.
|
||||
/// </summary>
|
||||
internal readonly ID3D12CommandQueue* D3D12CopyCommandQueue;
|
||||
private ComPtr<ID3D12CommandQueue> d3D12CopyCommandQueue;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12Fence"/> instance used for compute operations.
|
||||
/// </summary>
|
||||
internal readonly ID3D12Fence* D3D12ComputeFence;
|
||||
private ComPtr<ID3D12Fence> d3D12ComputeFence;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12Fence"/> instance used for copy operations.
|
||||
/// </summary>
|
||||
internal readonly ID3D12Fence* D3D12CopyFence;
|
||||
private ComPtr<ID3D12Fence> d3D12CopyFence;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="CommandAllocatorPool2"/> instance for compute operations.
|
||||
/// </summary>
|
||||
internal readonly CommandAllocatorPool2 ComputeCommandAllocatorPool;
|
||||
private readonly CommandAllocatorPool2 computeCommandAllocatorPool;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="CommandAllocatorPool2"/> instance for copy operations.
|
||||
/// </summary>
|
||||
internal readonly CommandAllocatorPool2 CopyCommandAllocatorPool;
|
||||
private readonly CommandAllocatorPool2 copyCommandAllocatorPool;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="DescriptorAllocator2"/> instance to use when allocating new buffers.
|
||||
/// </summary>
|
||||
internal DescriptorAllocator2 ShaderResourceViewDescriptorAllocator;
|
||||
private DescriptorAllocator2 shaderResourceViewDescriptorAllocator;
|
||||
|
||||
/// <summary>
|
||||
/// The next fence value for compute operations using <see cref="D3D12ComputeCommandQueue"/>.
|
||||
/// The next fence value for compute operations using <see cref="d3D12ComputeCommandQueue"/>.
|
||||
/// </summary>
|
||||
internal ulong NextD3D12ComputeFenceValue = 1;
|
||||
private ulong nextD3D12ComputeFenceValue = 1;
|
||||
|
||||
/// <summary>
|
||||
/// The next fence value for copy operations using <see cref="D3D12CopyCommandQueue"/>.
|
||||
/// The next fence value for copy operations using <see cref="d3D12CopyCommandQueue"/>.
|
||||
/// </summary>
|
||||
internal ulong NextD3D12CopyFenceValue = 1;
|
||||
private ulong nextD3D12CopyFenceValue = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="GraphicsDevice2"/> instance for the input <see cref="ID3D12Device"/>.
|
||||
/// </summary>
|
||||
/// <param name="device">The <see cref="ID3D12Device"/> to use for the new <see cref="GraphicsDevice2"/> instance.</param>
|
||||
/// <param name="description">The available info for the new <see cref="GraphicsDevice2"/> instance.</param>
|
||||
internal GraphicsDevice2(ID3D12Device* d3d12device, DXGI_ADAPTER_DESC1* dxgiDescription1)
|
||||
internal GraphicsDevice2(ComPtr<ID3D12Device> d3d12device, DXGI_ADAPTER_DESC1* dxgiDescription1)
|
||||
{
|
||||
D3D12Device = d3d12device;
|
||||
D3D12ComputeCommandQueue = d3d12device->CreateCommandQueue(D3D12_COMMAND_LIST_TYPE_COMPUTE);
|
||||
D3D12CopyCommandQueue = d3d12device->CreateCommandQueue(D3D12_COMMAND_LIST_TYPE_COPY);
|
||||
D3D12ComputeFence = d3d12device->CreateFence();
|
||||
D3D12CopyFence = d3d12device->CreateFence();
|
||||
ComputeCommandAllocatorPool = new CommandAllocatorPool2(D3D12_COMMAND_LIST_TYPE_COMPUTE);
|
||||
CopyCommandAllocatorPool = new CommandAllocatorPool2(D3D12_COMMAND_LIST_TYPE_COPY);
|
||||
ShaderResourceViewDescriptorAllocator = new DescriptorAllocator2(d3d12device);
|
||||
this.d3D12Device = d3d12device;
|
||||
this.d3D12ComputeCommandQueue = d3d12device.Get()->CreateCommandQueue(D3D12_COMMAND_LIST_TYPE_COMPUTE);
|
||||
this.d3D12CopyCommandQueue = d3d12device.Get()->CreateCommandQueue(D3D12_COMMAND_LIST_TYPE_COPY);
|
||||
this.d3D12ComputeFence = d3d12device.Get()->CreateFence();
|
||||
this.d3D12CopyFence = d3d12device.Get()->CreateFence();
|
||||
|
||||
this.computeCommandAllocatorPool = new CommandAllocatorPool2(D3D12_COMMAND_LIST_TYPE_COMPUTE);
|
||||
this.copyCommandAllocatorPool = new CommandAllocatorPool2(D3D12_COMMAND_LIST_TYPE_COPY);
|
||||
this.shaderResourceViewDescriptorAllocator = new DescriptorAllocator2(d3d12device);
|
||||
|
||||
Name = new string((char*)dxgiDescription1->Description);
|
||||
MemorySize = dxgiDescription1->DedicatedVideoMemory;
|
||||
|
||||
var d3D12Options1Data = d3d12device->CheckFeatureSupport<D3D12_FEATURE_DATA_D3D12_OPTIONS1>(D3D12_FEATURE_D3D12_OPTIONS1);
|
||||
var d3D12Options1Data = d3d12device.Get()->CheckFeatureSupport<D3D12_FEATURE_DATA_D3D12_OPTIONS1>(D3D12_FEATURE_D3D12_OPTIONS1);
|
||||
|
||||
ComputeUnits = d3D12Options1Data.TotalLaneCount;
|
||||
WavefrontSize = d3D12Options1Data.WaveLaneCountMin;
|
||||
@@ -107,17 +108,69 @@ namespace ComputeSharp.Graphics
|
||||
/// </summary>
|
||||
public uint WavefrontSize { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the underlying <see cref="ID3D12Device"/> wrapped by the current instance.
|
||||
/// </summary>
|
||||
internal ID3D12Device* D3D12Device => this.d3D12Device;
|
||||
|
||||
/// <inheritdoc cref="DescriptorAllocator2.Allocate"/>
|
||||
internal void AllocateShaderResourceViewDescriptorHandles(
|
||||
out D3D12_CPU_DESCRIPTOR_HANDLE d3d12CpuDescriptorHandle,
|
||||
out D3D12_GPU_DESCRIPTOR_HANDLE d3d12GpuDescriptorHandle)
|
||||
{
|
||||
this.shaderResourceViewDescriptorAllocator.Allocate(out d3d12CpuDescriptorHandle, out d3d12GpuDescriptorHandle);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="CommandAllocatorPool2.Enqueue"/>
|
||||
/// <param name="d3D12CommandAllocator">The <see cref="ID3D12CommandAllocator"/> instance to return to the pool.</param>
|
||||
/// <param name="d3d12CommandListType">The type of command allocator to return to the pool.</param>
|
||||
internal void EnqueueCommandAllocator(ComPtr<ID3D12CommandAllocator> d3D12CommandAllocator, D3D12_COMMAND_LIST_TYPE d3d12CommandListType)
|
||||
{
|
||||
switch (d3d12CommandListType)
|
||||
{
|
||||
case D3D12_COMMAND_LIST_TYPE_COMPUTE:
|
||||
this.computeCommandAllocatorPool.Enqueue(d3D12CommandAllocator, this.nextD3D12ComputeFenceValue);
|
||||
break;
|
||||
case D3D12_COMMAND_LIST_TYPE_COPY:
|
||||
this.copyCommandAllocatorPool.Enqueue(d3D12CommandAllocator, this.nextD3D12CopyFenceValue);
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="CommandAllocatorPool2.GetCommandAllocator"/>
|
||||
/// <param name="d3d12CommandListType">The type of command allocator to rent.</param>
|
||||
internal ComPtr<ID3D12CommandAllocator> GetCommandAllocator(D3D12_COMMAND_LIST_TYPE d3d12CommandListType)
|
||||
{
|
||||
return d3d12CommandListType switch
|
||||
{
|
||||
D3D12_COMMAND_LIST_TYPE_COMPUTE => this.computeCommandAllocatorPool.GetCommandAllocator(this.d3D12Device, this.d3D12ComputeFence),
|
||||
D3D12_COMMAND_LIST_TYPE_COPY => this.computeCommandAllocatorPool.GetCommandAllocator(this.d3D12Device, this.d3D12CopyFence),
|
||||
_ => throw null!
|
||||
};
|
||||
}
|
||||
|
||||
/// <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>
|
||||
internal void SetDescriptorHeapForCommandList(ID3D12GraphicsCommandList* d3D12GraphicsCommandList)
|
||||
{
|
||||
ID3D12DescriptorHeap* d3D12DescriptorHeap = this.shaderResourceViewDescriptorAllocator.D3D12DescriptorHeap;
|
||||
|
||||
d3D12GraphicsCommandList->SetDescriptorHeaps(1, &d3D12DescriptorHeap);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
D3D12Device->Release();
|
||||
D3D12ComputeCommandQueue->Release();
|
||||
D3D12CopyCommandQueue->Release();
|
||||
D3D12ComputeFence->Release();
|
||||
D3D12CopyFence->Release();
|
||||
ComputeCommandAllocatorPool.Dispose();
|
||||
CopyCommandAllocatorPool.Dispose();
|
||||
ShaderResourceViewDescriptorAllocator.Dispose();
|
||||
this.d3D12Device.Dispose();
|
||||
this.d3D12ComputeCommandQueue.Dispose();
|
||||
this.d3D12CopyCommandQueue.Dispose();
|
||||
this.d3D12ComputeFence.Dispose();
|
||||
this.d3D12CopyFence.Dispose();
|
||||
this.computeCommandAllocatorPool.Dispose();
|
||||
this.copyCommandAllocatorPool.Dispose();
|
||||
this.shaderResourceViewDescriptorAllocator.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする