Added UploadBuffer<T> type

このコミットが含まれているのは:
Sergio Pedri committed 2021-01-31 19:41:39 +01:00
1 親 42f6401655
コミット 1857407c3d
5ファイル変更
+240 -18

検索条件に一致するファイルはありません

+4 -4
ファイルの表示
@@ -110,17 +110,17 @@ namespace ComputeSharp.Resources
/// Reads the contents of the specified range from the current <see cref="Buffer{T}"/> instance and writes them into a target memory area.
/// </summary>
/// <param name="destination">The input memory area to write data to.</param>
/// <param name="size">The size of the memory area to write data to.</param>
/// <param name="length">The length of the memory area to write data to.</param>
/// <param name="offset">The offset to start reading data from.</param>
internal abstract void GetData(ref T destination, int size, int offset);
internal abstract void GetData(ref T destination, int length, int offset);
/// <summary>
/// Writes the contents of a given memory area to a specified area of the current <see cref="Buffer{T}"/> instance.
/// </summary>
/// <param name="source">The input memory area to read data from.</param>
/// <param name="size">The size of the input memory area to read data from.</param>
/// <param name="length">The length of the input memory area to read data from.</param>
/// <param name="offset">The offset to start writing data to.</param>
internal abstract void SetData(ref T source, int size, int offset);
internal abstract void SetData(ref T source, int length, int offset);
/// <summary>
/// Writes the contents of a given <see cref="Buffer{T}"/> to the current <see cref="Buffer{T}"/> instance.
+40 -14
ファイルの表示
@@ -29,14 +29,14 @@ namespace ComputeSharp.Resources
}
/// <inheritdoc/>
internal override unsafe void GetData(ref T destination, int size, int offset)
internal override unsafe void GetData(ref T destination, int length, int offset)
{
GraphicsDevice.ThrowIfDisposed();
ThrowIfDisposed();
Guard.IsInRange(offset, 0, Length, nameof(offset));
Guard.IsLessThanOrEqualTo(offset + size, Length, nameof(size));
Guard.IsLessThanOrEqualTo(offset + length, Length, nameof(length));
if (GraphicsDevice.IsCacheCoherentUMA)
{
@@ -47,7 +47,7 @@ namespace ComputeSharp.Resources
MemoryHelper.Copy(
resource.Pointer,
(uint)offset,
(uint)size,
(uint)length,
(uint)sizeof(T),
destinationPointer);
}
@@ -56,13 +56,13 @@ namespace ComputeSharp.Resources
{
nint
byteOffset = (nint)offset * sizeof(T),
byteSize = size * sizeof(T);
byteLength = length * sizeof(T);
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, AllocationMode.Default, (ulong)byteSize, false);
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, AllocationMode.Default, (ulong)byteLength, false);
using (CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY))
{
copyCommandList.CopyBufferRegion(d3D12Resource.Get(), 0, D3D12Resource, (ulong)byteOffset, (ulong)byteSize);
copyCommandList.CopyBufferRegion(d3D12Resource.Get(), 0, D3D12Resource, (ulong)byteOffset, (ulong)byteLength);
copyCommandList.ExecuteAndWaitForCompletion();
}
@@ -73,7 +73,7 @@ namespace ComputeSharp.Resources
MemoryHelper.Copy(
resource.Pointer,
0u,
(uint)size,
(uint)length,
(uint)sizeof(T),
destinationPointer);
}
@@ -81,14 +81,14 @@ namespace ComputeSharp.Resources
}
/// <inheritdoc/>
internal override unsafe void SetData(ref T source, int size, int offset)
internal override unsafe void SetData(ref T source, int length, int offset)
{
GraphicsDevice.ThrowIfDisposed();
ThrowIfDisposed();
Guard.IsInRange(offset, 0, Length, nameof(offset));
Guard.IsLessThanOrEqualTo(offset + size, Length, nameof(size));
Guard.IsLessThanOrEqualTo(offset + length, Length, nameof(length));
if (GraphicsDevice.IsCacheCoherentUMA)
{
@@ -99,7 +99,7 @@ namespace ComputeSharp.Resources
MemoryHelper.Copy(
sourcePointer,
(uint)offset,
(uint)size,
(uint)length,
(uint)sizeof(T),
resource.Pointer);
}
@@ -108,9 +108,9 @@ namespace ComputeSharp.Resources
{
nint
byteOffset = (nint)offset * sizeof(T),
byteSize = size * sizeof(T);
byteLength = length * sizeof(T);
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, AllocationMode.Default, (ulong)byteSize, false);
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, AllocationMode.Default, (ulong)byteLength, false);
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
fixed (void* sourcePointer = &source)
@@ -118,18 +118,44 @@ namespace ComputeSharp.Resources
MemoryHelper.Copy(
sourcePointer,
0u,
(uint)size,
(uint)length,
(uint)sizeof(T),
resource.Pointer);
}
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
copyCommandList.CopyBufferRegion(D3D12Resource, (ulong)byteOffset, d3D12Resource.Get(), 0, (ulong)byteSize);
copyCommandList.CopyBufferRegion(D3D12Resource, (ulong)byteOffset, d3D12Resource.Get(), 0, (ulong)byteLength);
copyCommandList.ExecuteAndWaitForCompletion();
}
}
/// <inheritdoc/>
public unsafe void SetData(UploadBuffer<T> source, int sourceOffset, int length, int offset)
{
GraphicsDevice.ThrowIfDisposed();
ThrowIfDisposed();
source.ThrowIfDeviceMismatch(GraphicsDevice);
source.ThrowIfDisposed();
Guard.IsInRange(offset, 0, Length, nameof(offset));
Guard.IsLessThanOrEqualTo(offset + length, Length, nameof(length));
Guard.IsInRange(sourceOffset, 0, source.Length, nameof(sourceOffset));
Guard.IsLessThanOrEqualTo(sourceOffset + length, source.Length, nameof(length));
ulong
byteSourceOffset = (uint)sourceOffset * (uint)sizeof(T),
byteOffset = (uint)offset * (uint)sizeof(T),
byteLength = (uint)length * (uint)sizeof(T);
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
copyCommandList.CopyBufferRegion(D3D12Resource, byteOffset, source.D3D12Resource, byteSourceOffset, byteLength);
copyCommandList.ExecuteAndWaitForCompletion();
}
/// <inheritdoc/>
public override unsafe void SetData(Buffer<T> source)
{