Minor code refactoring
このコミットが含まれているのは:
1 親
26c6f86d9f
コミット
8c75a71580
7ファイル変更
+112
-204
検索条件に一致するファイルはありません
@@ -31,9 +31,9 @@ internal unsafe struct ID3D12DescriptorHandleAllocator : IDisposable
|
||||
private ComPtr<ID3D12DescriptorHeap> d3D12DescriptorHeapNonShaderVisible;
|
||||
|
||||
/// <summary>
|
||||
/// The array of <see cref="D3D12DescriptorHandleBundle"/> items with the available descriptor handles.
|
||||
/// The array of <see cref="ID3D12ResourceDescriptorHandles"/> items with the available descriptor handles.
|
||||
/// </summary>
|
||||
private readonly D3D12DescriptorHandleBundle[] d3D12DescriptorHandlePairs;
|
||||
private readonly ID3D12ResourceDescriptorHandles[] d3D12DescriptorHandlePairs;
|
||||
|
||||
/// <summary>
|
||||
/// The head index for the queue.
|
||||
@@ -58,24 +58,26 @@ internal unsafe struct ID3D12DescriptorHandleAllocator : IDisposable
|
||||
{
|
||||
this.d3D12DescriptorHeap = device->CreateDescriptorHeap(DescriptorsPerHeap, isShaderVisible: true);
|
||||
this.d3D12DescriptorHeapNonShaderVisible = device->CreateDescriptorHeap(DescriptorsPerHeap, isShaderVisible: false);
|
||||
this.d3D12DescriptorHandlePairs = GC.AllocateUninitializedArray<D3D12DescriptorHandleBundle>((int)DescriptorsPerHeap);
|
||||
this.d3D12DescriptorHandlePairs = GC.AllocateUninitializedArray<ID3D12ResourceDescriptorHandles>((int)DescriptorsPerHeap);
|
||||
this.head = 0;
|
||||
this.tail = 0;
|
||||
this.size = (int)DescriptorsPerHeap;
|
||||
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle = this.d3D12DescriptorHeap.Get()->GetCPUDescriptorHandleForHeapStart();
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandleNonShaderVisible = this.d3D12DescriptorHeapNonShaderVisible.Get()->GetCPUDescriptorHandleForHeapStart();
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandleStart = this.d3D12DescriptorHeap.Get()->GetCPUDescriptorHandleForHeapStart();
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandleStart = this.d3D12DescriptorHeap.Get()->GetGPUDescriptorHandleForHeapStart();
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandleNonShaderVisibleStart = this.d3D12DescriptorHeapNonShaderVisible.Get()->GetCPUDescriptorHandleForHeapStart();
|
||||
uint descriptorIncrementSize = device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
|
||||
|
||||
for (int i = 0; i < this.d3D12DescriptorHandlePairs.Length; i++)
|
||||
{
|
||||
this.d3D12DescriptorHandlePairs[i] = new D3D12DescriptorHandleBundle(
|
||||
in d3D12CpuDescriptorHandle,
|
||||
in d3D12CpuDescriptorHandleNonShaderVisible,
|
||||
in d3D12GpuDescriptorHandleStart,
|
||||
i,
|
||||
descriptorIncrementSize);
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE.InitOffsetted(out D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle, in d3D12CpuDescriptorHandleStart, i, descriptorIncrementSize);
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE.InitOffsetted(out D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle, in d3D12GpuDescriptorHandleStart, i, descriptorIncrementSize);
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE.InitOffsetted(out D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandleNonShaderVisible, in d3D12CpuDescriptorHandleNonShaderVisibleStart, i, descriptorIncrementSize);
|
||||
|
||||
this.d3D12DescriptorHandlePairs[i] = new ID3D12ResourceDescriptorHandles(
|
||||
d3D12CpuDescriptorHandle,
|
||||
d3D12GpuDescriptorHandle,
|
||||
d3D12CpuDescriptorHandleNonShaderVisible);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,25 +87,16 @@ internal unsafe struct ID3D12DescriptorHandleAllocator : IDisposable
|
||||
public ID3D12DescriptorHeap* D3D12DescriptorHeap => this.d3D12DescriptorHeap;
|
||||
|
||||
/// <summary>
|
||||
/// Rents a new CPU and GPU handle pair to use in a memory buffer.
|
||||
/// Rents a new bundle of CPU and GPU handles to use in a resource.
|
||||
/// </summary>
|
||||
/// <param name="d3D12CpuDescriptorHandle">The resulting <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> value.</param>
|
||||
/// <param name="d3D12CpuDescriptorHandleNonShaderVisible">The resulting non shader visible <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> value.</param>
|
||||
/// <param name="d3D12GpuDescriptorHandle">The resulting <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> value.</param>
|
||||
public void Rent(
|
||||
out D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle,
|
||||
out D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandleNonShaderVisible,
|
||||
out D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle)
|
||||
/// <param name="d3D12ResourceDescriptorHandles">The resulting <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> value.</param>
|
||||
public void Rent(out ID3D12ResourceDescriptorHandles d3D12ResourceDescriptorHandles)
|
||||
{
|
||||
lock (this.d3D12DescriptorHandlePairs)
|
||||
{
|
||||
Guard.IsGreaterThan(this.size, 0, nameof(size));
|
||||
|
||||
ref readonly D3D12DescriptorHandleBundle d3D12DescriptorHandlePair = ref this.d3D12DescriptorHandlePairs[this.head++];
|
||||
|
||||
d3D12CpuDescriptorHandle = d3D12DescriptorHandlePair.D3D12CpuDescriptorHandle;
|
||||
d3D12CpuDescriptorHandleNonShaderVisible = d3D12DescriptorHandlePair.D3D12CpuDescriptorHandleNonShaderVisible;
|
||||
d3D12GpuDescriptorHandle = d3D12DescriptorHandlePair.D3D12GpuDescriptorhandle;
|
||||
d3D12ResourceDescriptorHandles = this.d3D12DescriptorHandlePairs[this.head++];
|
||||
|
||||
if (this.head == DescriptorsPerHeap)
|
||||
{
|
||||
@@ -117,19 +110,14 @@ internal unsafe struct ID3D12DescriptorHandleAllocator : IDisposable
|
||||
/// <summary>
|
||||
/// Returns a CPU and GPU handle pair for later use.
|
||||
/// </summary>
|
||||
/// <param name="d3D12CpuDescriptorHandle">The returned <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> value.</param>
|
||||
/// <param name="d3D12CpuDescriptorHandleNonShaderVisible">The returned non shader visible <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> value.</param>
|
||||
/// <param name="d3D12GpuDescriptorHandle">The returned <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> value.</param>
|
||||
public void Return(
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle,
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandleNonShaderVisible,
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle)
|
||||
/// <param name="d3D12ResourceDescriptorHandles">The returned <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> value.</param>
|
||||
public void Return(in ID3D12ResourceDescriptorHandles d3D12ResourceDescriptorHandles)
|
||||
{
|
||||
lock (this.d3D12DescriptorHandlePairs)
|
||||
{
|
||||
Guard.IsLessThan(this.size, DescriptorsPerHeap, nameof(size));
|
||||
|
||||
this.d3D12DescriptorHandlePairs[this.tail++] = new D3D12DescriptorHandleBundle(d3D12CpuDescriptorHandle, d3D12CpuDescriptorHandleNonShaderVisible, d3D12GpuDescriptorHandle);
|
||||
this.d3D12DescriptorHandlePairs[this.tail++] = d3D12ResourceDescriptorHandles;
|
||||
|
||||
if (this.tail == DescriptorsPerHeap)
|
||||
{
|
||||
@@ -145,61 +133,4 @@ internal unsafe struct ID3D12DescriptorHandleAllocator : IDisposable
|
||||
{
|
||||
this.d3D12DescriptorHeap.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A type representing a bundle of reusable descriptor handles.
|
||||
/// </summary>
|
||||
private readonly struct D3D12DescriptorHandleBundle
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> value for the current entry.
|
||||
/// </summary>
|
||||
public readonly D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandle;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> value for the current entry, non shader visible.
|
||||
/// </summary>
|
||||
public readonly D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandleNonShaderVisible;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> value for the current entry.
|
||||
/// </summary>
|
||||
public readonly D3D12_GPU_DESCRIPTOR_HANDLE D3D12GpuDescriptorhandle;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="D3D12DescriptorHandleBundle"/> instance with the given parameters.
|
||||
/// </summary>
|
||||
/// <param name="d3D12CpuDescriptorHandle">The <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> value to wrap.</param>
|
||||
/// <param name="d3D12CpuDescriptorHandleNonShaderVisible">The non shader visible <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> value to wrap.</param>
|
||||
/// <param name="d3D12GpuDescriptorHandle">The <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> value to wrap.</param>
|
||||
public D3D12DescriptorHandleBundle(
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle,
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandleNonShaderVisible,
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle)
|
||||
{
|
||||
D3D12CpuDescriptorHandle = d3D12CpuDescriptorHandle;
|
||||
D3D12CpuDescriptorHandleNonShaderVisible = d3D12CpuDescriptorHandleNonShaderVisible;
|
||||
D3D12GpuDescriptorhandle = d3D12GpuDescriptorHandle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="D3D12DescriptorHandleBundle"/> instance with the given parameters.
|
||||
/// </summary>
|
||||
/// <param name="d3D12CpuDescriptorHandleStart">The base <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> value.</param>
|
||||
/// <param name="d3D12CpuDescriptorHandleNonShaderVisible">The base non shader visible <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> value.</param>
|
||||
/// <param name="d3D12GpuDescriptorHandleStart">The base <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> value.</param>
|
||||
/// <param name="offset">The offset for the new pair of handles to compute.</param>
|
||||
/// <param name="descriptorIncrementSize">The increment size for each consecutive handles pair.</param>
|
||||
public D3D12DescriptorHandleBundle(
|
||||
in D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandleStart,
|
||||
in D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandleNonShaderVisible,
|
||||
in D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandleStart,
|
||||
int offset,
|
||||
uint descriptorIncrementSize)
|
||||
{
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE.InitOffsetted(out D3D12CpuDescriptorHandle, in d3D12CpuDescriptorHandleStart, offset, descriptorIncrementSize);
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE.InitOffsetted(out D3D12CpuDescriptorHandleNonShaderVisible, in d3D12CpuDescriptorHandleNonShaderVisible, offset, descriptorIncrementSize);
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE.InitOffsetted(out D3D12GpuDescriptorhandle, in d3D12GpuDescriptorHandleStart, offset, descriptorIncrementSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using TerraFX.Interop.DirectX;
|
||||
|
||||
namespace ComputeSharp.Graphics.Commands.Interop;
|
||||
|
||||
/// <summary>
|
||||
/// A type representing a bundle of reusable resource descriptor handles.
|
||||
/// </summary>
|
||||
internal readonly struct ID3D12ResourceDescriptorHandles
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> value for the current entry.
|
||||
/// </summary>
|
||||
public readonly D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandle;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> value for the current entry.
|
||||
/// </summary>
|
||||
public readonly D3D12_GPU_DESCRIPTOR_HANDLE D3D12GpuDescriptorHandle;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> value for the current entry, non shader visible.
|
||||
/// </summary>
|
||||
public readonly D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandleNonShaderVisible;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ID3D12ResourceDescriptorHandles"/> instance with the given parameters.
|
||||
/// </summary>
|
||||
/// <param name="d3D12CpuDescriptorHandle">The <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> value to wrap.</param>
|
||||
/// <param name="d3D12GpuDescriptorHandle">The <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> value to wrap.</param>
|
||||
/// <param name="d3D12CpuDescriptorHandleNonShaderVisible">The non shader visible <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> value to wrap.</param>
|
||||
public ID3D12ResourceDescriptorHandles(
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle,
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle,
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandleNonShaderVisible)
|
||||
{
|
||||
D3D12CpuDescriptorHandle = d3D12CpuDescriptorHandle;
|
||||
D3D12GpuDescriptorHandle = d3D12GpuDescriptorHandle;
|
||||
D3D12CpuDescriptorHandleNonShaderVisible = d3D12CpuDescriptorHandleNonShaderVisible;
|
||||
}
|
||||
}
|
||||
@@ -284,22 +284,16 @@ public sealed unsafe partial class GraphicsDevice : NativeObject
|
||||
|
||||
/// <inheritdoc cref="ID3D12DescriptorHandleAllocator.Rent"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal void RentShaderResourceViewDescriptorHandles(
|
||||
out D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle,
|
||||
out D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandleNonGpuVisible,
|
||||
out D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle)
|
||||
internal void RentShaderResourceViewDescriptorHandles(out ID3D12ResourceDescriptorHandles d3D12ResourceDescriptorHandles)
|
||||
{
|
||||
this.shaderResourceViewDescriptorAllocator.Rent(out d3D12CpuDescriptorHandle, out d3D12CpuDescriptorHandleNonGpuVisible, out d3D12GpuDescriptorHandle);
|
||||
this.shaderResourceViewDescriptorAllocator.Rent(out d3D12ResourceDescriptorHandles);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID3D12DescriptorHandleAllocator.Return"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal void ReturnShaderResourceViewDescriptorHandles(
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle,
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandleNonGpuVisible,
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle)
|
||||
internal void ReturnShaderResourceViewDescriptorHandles(in ID3D12ResourceDescriptorHandles d3D12ResourceDescriptorHandles)
|
||||
{
|
||||
this.shaderResourceViewDescriptorAllocator.Return(d3D12CpuDescriptorHandle, d3D12CpuDescriptorHandleNonGpuVisible, d3D12GpuDescriptorHandle);
|
||||
this.shaderResourceViewDescriptorAllocator.Return(in d3D12ResourceDescriptorHandles);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID3D12CommandListPool.Rent"/>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.Core.Helpers;
|
||||
using ComputeSharp.Exceptions;
|
||||
using ComputeSharp.Graphics.Commands.Interop;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using ComputeSharp.Interop;
|
||||
@@ -38,19 +39,9 @@ public unsafe abstract class Buffer<T> : NativeObject
|
||||
private ComPtr<ID3D12Resource> d3D12Resource;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
|
||||
/// The <see cref="ID3D12ResourceDescriptorHandles"/> instance for the current resource.
|
||||
/// </summary>
|
||||
private readonly D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle;
|
||||
|
||||
/// <summary>
|
||||
/// The non shader visible <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
|
||||
/// </summary>
|
||||
private readonly D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandleNonShaderVisible;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
|
||||
/// </summary>
|
||||
private readonly D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle;
|
||||
private readonly ID3D12ResourceDescriptorHandles d3D12ResourceDescriptorHandles;
|
||||
|
||||
/// <summary>
|
||||
/// The size in bytes of the current buffer (this value is never negative).
|
||||
@@ -100,19 +91,19 @@ public unsafe abstract class Buffer<T> : NativeObject
|
||||
#endif
|
||||
|
||||
device.RegisterAllocatedResource();
|
||||
device.RentShaderResourceViewDescriptorHandles(out this.d3D12CpuDescriptorHandle, out this.d3D12CpuDescriptorHandleNonShaderVisible, out this.d3D12GpuDescriptorHandle);
|
||||
device.RentShaderResourceViewDescriptorHandles(out this.d3D12ResourceDescriptorHandles);
|
||||
|
||||
switch (resourceType)
|
||||
{
|
||||
case ResourceType.Constant:
|
||||
device.D3D12Device->CreateConstantBufferView(this.d3D12Resource.Get(), effectiveSizeInBytes, this.d3D12CpuDescriptorHandle);
|
||||
device.D3D12Device->CreateConstantBufferView(this.d3D12Resource.Get(), effectiveSizeInBytes, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandle);
|
||||
break;
|
||||
case ResourceType.ReadOnly:
|
||||
device.D3D12Device->CreateShaderResourceView(this.d3D12Resource.Get(), (uint)length, elementSizeInBytes, this.d3D12CpuDescriptorHandle);
|
||||
device.D3D12Device->CreateShaderResourceView(this.d3D12Resource.Get(), (uint)length, elementSizeInBytes, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandle);
|
||||
break;
|
||||
case ResourceType.ReadWrite:
|
||||
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), (uint)length, elementSizeInBytes, this.d3D12CpuDescriptorHandle);
|
||||
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), (uint)length, elementSizeInBytes, this.d3D12CpuDescriptorHandleNonShaderVisible);
|
||||
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), (uint)length, elementSizeInBytes, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandle);
|
||||
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), (uint)length, elementSizeInBytes, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandleNonShaderVisible);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -146,17 +137,7 @@ public unsafe abstract class Buffer<T> : NativeObject
|
||||
/// <summary>
|
||||
/// Gets the <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
|
||||
/// </summary>
|
||||
internal D3D12_GPU_DESCRIPTOR_HANDLE D3D12GpuDescriptorHandle => this.d3D12GpuDescriptorHandle;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
|
||||
/// </summary>
|
||||
internal D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandle => this.d3D12CpuDescriptorHandle;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the non shader visible <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
|
||||
/// </summary>
|
||||
internal D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandleNonShaderVisible => this.d3D12CpuDescriptorHandleNonShaderVisible;
|
||||
internal D3D12_GPU_DESCRIPTOR_HANDLE D3D12GpuDescriptorHandle => this.d3D12ResourceDescriptorHandles.D3D12GpuDescriptorHandle;
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of the specified range from the current <see cref="Buffer{T}"/> instance and writes them into a target memory area.
|
||||
@@ -219,7 +200,7 @@ public unsafe abstract class Buffer<T> : NativeObject
|
||||
if (GraphicsDevice is GraphicsDevice device)
|
||||
{
|
||||
device.UnregisterAllocatedResource();
|
||||
device.ReturnShaderResourceViewDescriptorHandles(D3D12CpuDescriptorHandle, this.d3D12CpuDescriptorHandleNonShaderVisible, D3D12GpuDescriptorHandle);
|
||||
device.ReturnShaderResourceViewDescriptorHandles(in this.d3D12ResourceDescriptorHandles);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,4 +215,22 @@ public unsafe abstract class Buffer<T> : NativeObject
|
||||
GraphicsDeviceMismatchException.Throw(this, device);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="__Internals.GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice, out bool)"/>
|
||||
internal (D3D12_GPU_DESCRIPTOR_HANDLE Gpu, D3D12_CPU_DESCRIPTOR_HANDLE Cpu) ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice device)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
ThrowIfDeviceMismatch(device);
|
||||
|
||||
return (this.d3D12ResourceDescriptorHandles.D3D12GpuDescriptorHandle, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandleNonShaderVisible);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="__Internals.GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice)"/>
|
||||
internal unsafe ID3D12Resource* ValidateAndGetID3D12Resource(GraphicsDevice device)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
ThrowIfDeviceMismatch(device);
|
||||
|
||||
return D3D12Resource;
|
||||
}
|
||||
}
|
||||
@@ -304,22 +304,4 @@ public abstract class StructuredBuffer<T> : Buffer<T>
|
||||
copyCommandList.ExecuteAndWaitForCompletion();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="__Internals.GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice, out bool)"/>
|
||||
internal (D3D12_GPU_DESCRIPTOR_HANDLE Gpu, D3D12_CPU_DESCRIPTOR_HANDLE Cpu) ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice device)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
ThrowIfDeviceMismatch(device);
|
||||
|
||||
return (D3D12GpuDescriptorHandle, D3D12CpuDescriptorHandleNonShaderVisible);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="__Internals.GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice)"/>
|
||||
internal unsafe ID3D12Resource* ValidateAndGetID3D12Resource(GraphicsDevice device)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
ThrowIfDeviceMismatch(device);
|
||||
|
||||
return D3D12Resource;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Exceptions;
|
||||
using ComputeSharp.Graphics.Commands;
|
||||
using ComputeSharp.Graphics.Commands.Interop;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using ComputeSharp.Graphics.Resources.Interop;
|
||||
@@ -39,19 +40,9 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
|
||||
private ComPtr<ID3D12Resource> d3D12Resource;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
|
||||
/// The <see cref="ID3D12ResourceDescriptorHandles"/> instance for the current resource.
|
||||
/// </summary>
|
||||
private readonly D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle;
|
||||
|
||||
/// <summary>
|
||||
/// The non shader visible <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
|
||||
/// </summary>
|
||||
private readonly D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandleNonShaderVisible;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
|
||||
/// </summary>
|
||||
private readonly D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle;
|
||||
private readonly ID3D12ResourceDescriptorHandles d3D12ResourceDescriptorHandles;
|
||||
|
||||
/// <summary>
|
||||
/// The default <see cref="D3D12_RESOURCE_STATES"/> value for the current resource.
|
||||
@@ -125,16 +116,16 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
|
||||
out _);
|
||||
|
||||
device.RegisterAllocatedResource();
|
||||
device.RentShaderResourceViewDescriptorHandles(out this.d3D12CpuDescriptorHandle, out this.d3D12CpuDescriptorHandleNonShaderVisible, out this.d3D12GpuDescriptorHandle);
|
||||
device.RentShaderResourceViewDescriptorHandles(out this.d3D12ResourceDescriptorHandles);
|
||||
|
||||
switch (resourceType)
|
||||
{
|
||||
case ResourceType.ReadOnly:
|
||||
device.D3D12Device->CreateShaderResourceView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType<T>(), D3D12_SRV_DIMENSION_TEXTURE2D, this.d3D12CpuDescriptorHandle);
|
||||
device.D3D12Device->CreateShaderResourceView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType<T>(), D3D12_SRV_DIMENSION_TEXTURE2D, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandle);
|
||||
break;
|
||||
case ResourceType.ReadWrite:
|
||||
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType<T>(), D3D12_UAV_DIMENSION_TEXTURE2D, this.d3D12CpuDescriptorHandle);
|
||||
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType<T>(), D3D12_UAV_DIMENSION_TEXTURE2D, this.d3D12CpuDescriptorHandleNonShaderVisible);
|
||||
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType<T>(), D3D12_UAV_DIMENSION_TEXTURE2D, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandle);
|
||||
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType<T>(), D3D12_UAV_DIMENSION_TEXTURE2D, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandleNonShaderVisible);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -164,17 +155,7 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
|
||||
/// <summary>
|
||||
/// Gets the <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
|
||||
/// </summary>
|
||||
internal D3D12_GPU_DESCRIPTOR_HANDLE D3D12GpuDescriptorHandle => this.d3D12GpuDescriptorHandle;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
|
||||
/// </summary>
|
||||
internal D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandle => this.d3D12CpuDescriptorHandle;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the non shader visible <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
|
||||
/// </summary>
|
||||
internal D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandleNonShaderVisible => this.d3D12CpuDescriptorHandleNonShaderVisible;
|
||||
internal D3D12_GPU_DESCRIPTOR_HANDLE D3D12GpuDescriptorHandle => this.d3D12ResourceDescriptorHandles.D3D12GpuDescriptorHandle;
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of the specified range from the current <see cref="Texture2D{T}"/> instance and writes them into a target memory area.
|
||||
@@ -557,7 +538,7 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
|
||||
if (GraphicsDevice is GraphicsDevice device)
|
||||
{
|
||||
device.UnregisterAllocatedResource();
|
||||
device.ReturnShaderResourceViewDescriptorHandles(D3D12CpuDescriptorHandle, this.d3D12CpuDescriptorHandleNonShaderVisible, D3D12GpuDescriptorHandle);
|
||||
device.ReturnShaderResourceViewDescriptorHandles(in this.d3D12ResourceDescriptorHandles);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -581,7 +562,7 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
|
||||
|
||||
isNormalized = DXGIFormatHelper.IsNormalizedType<T>();
|
||||
|
||||
return (D3D12GpuDescriptorHandle, D3D12CpuDescriptorHandleNonShaderVisible);
|
||||
return (this.d3D12ResourceDescriptorHandles.D3D12GpuDescriptorHandle, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandleNonShaderVisible);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice)"/>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Exceptions;
|
||||
using ComputeSharp.Graphics.Commands;
|
||||
using ComputeSharp.Graphics.Commands.Interop;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using ComputeSharp.Graphics.Resources.Interop;
|
||||
@@ -39,19 +40,9 @@ public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper
|
||||
private ComPtr<ID3D12Resource> d3D12Resource;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
|
||||
/// The <see cref="ID3D12ResourceDescriptorHandles"/> instance for the current resource.
|
||||
/// </summary>
|
||||
private readonly D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle;
|
||||
|
||||
/// <summary>
|
||||
/// The non shader visible <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
|
||||
/// </summary>
|
||||
private readonly D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandleNonShaderVisible;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
|
||||
/// </summary>
|
||||
private readonly D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle;
|
||||
private readonly ID3D12ResourceDescriptorHandles d3D12ResourceDescriptorHandles;
|
||||
|
||||
/// <summary>
|
||||
/// The default <see cref="D3D12_RESOURCE_STATES"/> value for the current resource.
|
||||
@@ -130,16 +121,16 @@ public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper
|
||||
out _);
|
||||
|
||||
device.RegisterAllocatedResource();
|
||||
device.RentShaderResourceViewDescriptorHandles(out this.d3D12CpuDescriptorHandle, out this.d3D12CpuDescriptorHandleNonShaderVisible, out this.d3D12GpuDescriptorHandle);
|
||||
device.RentShaderResourceViewDescriptorHandles(out this.d3D12ResourceDescriptorHandles);
|
||||
|
||||
switch (resourceType)
|
||||
{
|
||||
case ResourceType.ReadOnly:
|
||||
device.D3D12Device->CreateShaderResourceView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType<T>(), D3D12_SRV_DIMENSION_TEXTURE3D, this.d3D12CpuDescriptorHandle);
|
||||
device.D3D12Device->CreateShaderResourceView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType<T>(), D3D12_SRV_DIMENSION_TEXTURE3D, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandle);
|
||||
break;
|
||||
case ResourceType.ReadWrite:
|
||||
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType<T>(), D3D12_UAV_DIMENSION_TEXTURE3D, this.d3D12CpuDescriptorHandle);
|
||||
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType<T>(), D3D12_UAV_DIMENSION_TEXTURE3D, this.d3D12CpuDescriptorHandleNonShaderVisible);
|
||||
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType<T>(), D3D12_UAV_DIMENSION_TEXTURE3D, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandle);
|
||||
device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType<T>(), D3D12_UAV_DIMENSION_TEXTURE3D, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandleNonShaderVisible);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -174,17 +165,7 @@ public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper
|
||||
/// <summary>
|
||||
/// Gets the <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
|
||||
/// </summary>
|
||||
internal D3D12_GPU_DESCRIPTOR_HANDLE D3D12GpuDescriptorHandle => this.d3D12GpuDescriptorHandle;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
|
||||
/// </summary>
|
||||
internal D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandle => this.d3D12CpuDescriptorHandle;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the non shader visible <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
|
||||
/// </summary>
|
||||
internal D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandleNonShaderVisible => this.d3D12CpuDescriptorHandleNonShaderVisible;
|
||||
internal D3D12_GPU_DESCRIPTOR_HANDLE D3D12GpuDescriptorHandle => this.d3D12ResourceDescriptorHandles.D3D12GpuDescriptorHandle;
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of the specified range from the current <see cref="Texture3D{T}"/> instance and writes them into a target memory area.
|
||||
@@ -610,7 +591,7 @@ public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper
|
||||
if (GraphicsDevice is GraphicsDevice device)
|
||||
{
|
||||
device.UnregisterAllocatedResource();
|
||||
device.ReturnShaderResourceViewDescriptorHandles(D3D12CpuDescriptorHandle, this.d3D12CpuDescriptorHandleNonShaderVisible, D3D12GpuDescriptorHandle);
|
||||
device.ReturnShaderResourceViewDescriptorHandles(in this.d3D12ResourceDescriptorHandles);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -634,7 +615,7 @@ public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper
|
||||
|
||||
isNormalized = DXGIFormatHelper.IsNormalizedType<T>();
|
||||
|
||||
return (D3D12GpuDescriptorHandle, D3D12CpuDescriptorHandleNonShaderVisible);
|
||||
return (this.d3D12ResourceDescriptorHandles.D3D12GpuDescriptorHandle, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandleNonShaderVisible);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice)"/>
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする