Refactor signatures and param names in buffer APIs

このコミットが含まれているのは:
Sergio Pedri committed 2021-11-12 01:53:01 +01:00
1 親 5261df4c0e
コミット ffa4881d0a
8ファイル変更
+119 -115

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

+46 -46
ファイルの表示
@@ -15,32 +15,32 @@ public static class BufferExtensions
/// Reads the contents of a <see cref="Buffer{T}"/> instance and returns an array.
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer.</typeparam>
/// <param name="buffer">The input <see cref="Buffer{T}"/> instance to read data from.</param>
/// <param name="source">The input <see cref="Buffer{T}"/> instance to read data from.</param>
/// <returns>A <typeparamref name="T"/> array with the contents of the input buffer.</returns>
[Pure]
public static T[] ToArray<T>(this Buffer<T> buffer)
public static T[] ToArray<T>(this Buffer<T> source)
where T : unmanaged
{
return buffer.ToArray(0, buffer.Length);
return source.ToArray(0, source.Length);
}
/// <summary>
/// Reads the contents of a <see cref="Buffer{T}"/> instance in a given range and returns an array.
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer.</typeparam>
/// <param name="buffer">The input <see cref="Buffer{T}"/> instance to read data from.</param>
/// <param name="source">The input <see cref="Buffer{T}"/> instance to read data from.</param>
/// <param name="offset">The offset to start reading data from.</param>
/// <param name="count">The number of items to read.</param>
/// <returns>A <typeparamref name="T"/> array with the contents of the specified range from the current buffer.</returns>
[Pure]
public static T[] ToArray<T>(this Buffer<T> buffer, int offset, int count)
public static T[] ToArray<T>(this Buffer<T> source, int offset, int count)
where T : unmanaged
{
Guard.IsGreaterThanOrEqualTo(count, 0, nameof(count));
T[] data = GC.AllocateUninitializedArray<T>(count);
buffer.CopyTo(data.AsSpan(), offset);
source.CopyTo(data.AsSpan(), offset);
return data;
}
@@ -49,161 +49,161 @@ public static class BufferExtensions
/// Reads the contents of a <see cref="Buffer{T}"/> instance and writes them into a target array.
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer.</typeparam>
/// <param name="buffer">The input <see cref="Buffer{T}"/> instance to read data from.</param>
/// <param name="source">The input <see cref="Buffer{T}"/> instance to read data from.</param>
/// <param name="destination">The input array to write data to.</param>
public static void CopyTo<T>(this Buffer<T> buffer, T[] destination)
public static void CopyTo<T>(this Buffer<T> source, T[] destination)
where T : unmanaged
{
buffer.CopyTo(destination.AsSpan(), 0);
source.CopyTo(destination.AsSpan(), 0);
}
/// <summary>
/// Reads the contents of the specified range from a <see cref="Buffer{T}"/> instance and writes them into a target array.
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer.</typeparam>
/// <param name="buffer">The input <see cref="Buffer{T}"/> instance to read data from.</param>
/// <param name="source">The input <see cref="Buffer{T}"/> instance to read data from.</param>
/// <param name="destination">The input array to write data to.</param>
/// <param name="sourceOffset">The offset to start reading data from.</param>
/// <param name="destinationOffset">The starting offset within <paramref name="destination"/> to write data to.</param>
/// <param name="count">The number of items to read.</param>
public static void CopyTo<T>(this Buffer<T> buffer, T[] destination, int sourceOffset, int destinationOffset, int count)
public static void CopyTo<T>(this Buffer<T> source, T[] destination, int sourceOffset, int destinationOffset, int count)
where T : unmanaged
{
Span<T> span = destination.AsSpan(destinationOffset, count);
buffer.CopyTo(span, sourceOffset);
source.CopyTo(span, sourceOffset);
}
/// <summary>
/// Reads the contents of a <see cref="Buffer{T}"/> instance and writes them into a target <see cref="Span{T}"/>.
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer.</typeparam>
/// <param name="buffer">The input <see cref="Buffer{T}"/> instance to read data from.</param>
/// <param name="source">The input <see cref="Buffer{T}"/> instance to read data from.</param>
/// <param name="destination">The input <see cref="Span{T}"/> to write data to.</param>
public static void CopyTo<T>(this Buffer<T> buffer, Span<T> destination)
public static void CopyTo<T>(this Buffer<T> source, Span<T> destination)
where T : unmanaged
{
buffer.CopyTo(destination, 0);
source.CopyTo(destination, 0);
}
/// <summary>
/// Reads the contents of the specified range from a <see cref="Buffer{T}"/> instance and writes them into a target <see cref="Span{T}"/>.
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer.</typeparam>
/// <param name="buffer">The input <see cref="Buffer{T}"/> instance to read data from.</param>
/// <param name="source">The input <see cref="Buffer{T}"/> instance to read data from.</param>
/// <param name="destination">The input <see cref="Span{T}"/> to write data to.</param>
/// <param name="offset">The offset to start reading data from.</param>
public static void CopyTo<T>(this Buffer<T> buffer, Span<T> destination, int offset)
/// <param name="sourceOffset">The offset to start reading data from.</param>
public static void CopyTo<T>(this Buffer<T> source, Span<T> destination, int sourceOffset)
where T : unmanaged
{
buffer.CopyTo(ref MemoryMarshal.GetReference(destination), destination.Length, offset);
source.CopyTo(ref MemoryMarshal.GetReference(destination), sourceOffset, destination.Length);
}
/// <summary>
/// Reads the contents of the specified <see cref="Buffer{T}"/> instance and copies them to the target <see cref="Buffer{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items stored on the buffers.</typeparam>
/// <param name="buffer">The input <see cref="Buffer{T}"/> instance to read data from.</param>
/// <param name="source">The input <see cref="Buffer{T}"/> instance to read data from.</param>
/// <param name="destination">The target <see cref="Buffer{T}"/> instance to write data to.</param>
public static void CopyTo<T>(this Buffer<T> buffer, Buffer<T> destination)
public static void CopyTo<T>(this Buffer<T> source, Buffer<T> destination)
where T : unmanaged
{
buffer.CopyTo(destination, 0, 0, buffer.Length);
source.CopyTo(destination, 0, 0, source.Length);
}
/// <summary>
/// Reads the contents of the specified range from a <see cref="Buffer{T}"/> instance and copies them to the target <see cref="Buffer{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items stored on the buffers.</typeparam>
/// <param name="buffer">The input <see cref="Buffer{T}"/> instance to read data from.</param>
/// <param name="source">The input <see cref="Buffer{T}"/> instance to read data from.</param>
/// <param name="destination">The target <see cref="Buffer{T}"/> instance to write data to.</param>
/// <param name="sourceOffset">The offset to start reading data from.</param>
/// <param name="destinationOffset">The starting offset within <paramref name="destination"/> to write data to.</param>
/// <param name="count">The number of items to read.</param>
public static void CopyTo<T>(this Buffer<T> buffer, Buffer<T> destination, int sourceOffset, int destinationOffset, int count)
public static void CopyTo<T>(this Buffer<T> source, Buffer<T> destination, int sourceOffset, int destinationOffset, int count)
where T : unmanaged
{
buffer.CopyTo(destination, sourceOffset, destinationOffset, count);
source.CopyTo(destination, sourceOffset, destinationOffset, count);
}
/// <summary>
/// Writes the contents of a given <typeparamref name="T"/> array to a <see cref="Buffer{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer.</typeparam>
/// <param name="buffer">The target <see cref="Buffer{T}"/> instance to write data to.</param>
/// <param name="destination">The target <see cref="Buffer{T}"/> instance to write data to.</param>
/// <param name="source">The input <typeparamref name="T"/> array to read data from.</param>
public static void CopyFrom<T>(this Buffer<T> buffer, T[] source)
public static void CopyFrom<T>(this Buffer<T> destination, T[] source)
where T : unmanaged
{
buffer.CopyFrom(source.AsSpan(), 0);
destination.CopyFrom(source.AsSpan(), 0);
}
/// <summary>
/// Writes the contents of a given <typeparamref name="T"/> array to a specified area of a <see cref="Buffer{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer.</typeparam>
/// <param name="buffer">The target <see cref="Buffer{T}"/> instance to write data to.</param>
/// <param name="destination">The target <see cref="Buffer{T}"/> instance to write data to.</param>
/// <param name="source">The input <typeparamref name="T"/> array to read data from.</param>
/// <param name="sourceOffset">The starting offset within <paramref name="source"/> to read data from.</param>
/// <param name="bufferOffset">The offset to start writing data to.</param>
/// <param name="destinationOffset">The offset to start writing data to.</param>
/// <param name="count">The number of items to write.</param>
public static void CopyFrom<T>(this Buffer<T> buffer, T[] source, int sourceOffset, int bufferOffset, int count)
public static void CopyFrom<T>(this Buffer<T> destination, T[] source, int sourceOffset, int destinationOffset, int count)
where T : unmanaged
{
ReadOnlySpan<T> span = source.AsSpan(sourceOffset, count);
buffer.CopyFrom(span, bufferOffset);
destination.CopyFrom(span, destinationOffset);
}
/// <summary>
/// Writes the contents of a given <see cref="ReadOnlySpan{T}"/> to a <see cref="Buffer{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer.</typeparam>
/// <param name="buffer">The target <see cref="Buffer{T}"/> instance to write data to.</param>
/// <param name="destination">The target <see cref="Buffer{T}"/> instance to write data to.</param>
/// <param name="source">The input <see cref="ReadOnlySpan{T}"/> to read data from.</param>
public static void CopyFrom<T>(this Buffer<T> buffer, ReadOnlySpan<T> source)
public static void CopyFrom<T>(this Buffer<T> destination, ReadOnlySpan<T> source)
where T : unmanaged
{
buffer.CopyFrom(source, 0);
destination.CopyFrom(source, 0);
}
/// <summary>
/// Writes the contents of a given <see cref="ReadOnlySpan{T}"/> to a specified area of a <see cref="Buffer{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer.</typeparam>
/// <param name="buffer">The target <see cref="Buffer{T}"/> instance to write data to.</param>
/// <param name="destination">The target <see cref="Buffer{T}"/> instance to write data to.</param>
/// <param name="source">The input <see cref="ReadOnlySpan{T}"/> to read data from.</param>
/// <param name="offset">The offset to start writing data to.</param>
public static void CopyFrom<T>(this Buffer<T> buffer, ReadOnlySpan<T> source, int offset)
/// <param name="destinationOffset">The offset to start writing data to.</param>
public static void CopyFrom<T>(this Buffer<T> destination, ReadOnlySpan<T> source, int destinationOffset)
where T : unmanaged
{
buffer.CopyFrom(ref MemoryMarshal.GetReference(source), source.Length, offset);
destination.CopyFrom(ref MemoryMarshal.GetReference(source), destinationOffset, source.Length);
}
/// <summary>
/// Writes the contents of the specified <see cref="Buffer{T}"/> instance to the curreent <see cref="Buffer{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items stored on the buffers.</typeparam>
/// <param name="buffer">The input <see cref="Buffer{T}"/> instance to write data data to.</param>
/// <param name="destination">The input <see cref="Buffer{T}"/> instance to write data data to.</param>
/// <param name="source">The source <see cref="Buffer{T}"/> instance to read data from.</param>
public static void CopyFrom<T>(this Buffer<T> buffer, Buffer<T> source)
public static void CopyFrom<T>(this Buffer<T> destination, Buffer<T> source)
where T : unmanaged
{
source.CopyTo(buffer, 0, 0, source.Length);
source.CopyTo(destination, 0, 0, source.Length);
}
/// <summary>
/// Writes the contents of the specified range from a <see cref="Buffer{T}"/> instance and copies them to the current <see cref="Buffer{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items stored on the buffers.</typeparam>
/// <param name="buffer">The input <see cref="Buffer{T}"/> instance to write data to.</param>
/// <param name="destination">The input <see cref="Buffer{T}"/> instance to write data to.</param>
/// <param name="source">The source <see cref="Buffer{T}"/> instance to read data from.</param>
/// <param name="sourceOffset">The offset to start reading data from.</param>
/// <param name="destinationOffset">The starting offset within <paramref name="buffer"/> to write data to.</param>
/// <param name="destinationOffset">The starting offset within <paramref name="destination"/> to write data to.</param>
/// <param name="count">The number of items to read.</param>
public static void CopyFrom<T>(this Buffer<T> buffer, Buffer<T> source, int sourceOffset, int destinationOffset, int count)
public static void CopyFrom<T>(this Buffer<T> destination, Buffer<T> source, int sourceOffset, int destinationOffset, int count)
where T : unmanaged
{
source.CopyTo(buffer, sourceOffset, destinationOffset, count);
source.CopyTo(destination, sourceOffset, destinationOffset, count);
}
}
+7 -7
ファイルの表示
@@ -11,26 +11,26 @@ public static class StructuredBufferExtensions
/// Reads the contents of a <see cref="StructuredBuffer{T}"/> instance and writes them into a target <see cref="ReadBackBuffer{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer.</typeparam>
/// <param name="buffer">The input <see cref="StructuredBuffer{T}"/> instance to read data from.</param>
/// <param name="source">The input <see cref="StructuredBuffer{T}"/> instance to read data from.</param>
/// <param name="destination">The target <see cref="ReadBackBuffer{T}"/> instance to write data to.</param>
public static void CopyTo<T>(this StructuredBuffer<T> buffer, ReadBackBuffer<T> destination)
public static void CopyTo<T>(this StructuredBuffer<T> source, ReadBackBuffer<T> destination)
where T : unmanaged
{
buffer.CopyTo(destination, 0, buffer.Length, 0);
source.CopyTo(destination, 0, 0, source.Length);
}
/// <summary>
/// Reads the contents of a <see cref="StructuredBuffer{T}"/> instance and writes them into a target <see cref="ReadBackBuffer{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer.</typeparam>
/// <param name="buffer">The input <see cref="StructuredBuffer{T}"/> instance to read data from.</param>
/// <param name="source">The input <see cref="StructuredBuffer{T}"/> instance to read data from.</param>
/// <param name="destination">The target <see cref="ReadBackBuffer{T}"/> instance to write data to.</param>
/// <param name="sourceOffset">The offset to start reading data from.</param>
/// <param name="destinationOffset">The starting offset within <paramref name="destination"/> to write data to.</param>
/// <param name="bufferOffset">The offset to start reading data from.</param>
/// <param name="count">The number of items to read.</param>
public static void CopyTo<T>(this StructuredBuffer<T> buffer, ReadBackBuffer<T> destination, int destinationOffset, int bufferOffset, int count)
public static void CopyTo<T>(this StructuredBuffer<T> source, ReadBackBuffer<T> destination, int sourceOffset, int destinationOffset, int count)
where T : unmanaged
{
buffer.CopyTo(destination, destinationOffset, count, bufferOffset);
source.CopyTo(destination, sourceOffset, destinationOffset, count);
}
}
+7 -7
ファイルの表示
@@ -11,26 +11,26 @@ public static class UploadBufferExtensions
/// Reads the contents of a <see cref="UploadBuffer{T}"/> instance and writes them into a target <see cref="StructuredBuffer{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer.</typeparam>
/// <param name="buffer">The input <see cref="UploadBuffer{T}"/> instance to read data from.</param>
/// <param name="source">The input <see cref="UploadBuffer{T}"/> instance to read data from.</param>
/// <param name="destination">The target <see cref="StructuredBuffer{T}"/> instance to write data to.</param>
public static void CopyTo<T>(this UploadBuffer<T> buffer, StructuredBuffer<T> destination)
public static void CopyTo<T>(this UploadBuffer<T> source, StructuredBuffer<T> destination)
where T : unmanaged
{
destination.CopyFrom(buffer, 0, buffer.Length, 0);
destination.CopyFrom(source, 0, 0, source.Length);
}
/// <summary>
/// Reads the contents of a <see cref="UploadBuffer{T}"/> instance and writes them into a target <see cref="StructuredBuffer{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer.</typeparam>
/// <param name="buffer">The input <see cref="UploadBuffer{T}"/> instance to read data from.</param>
/// <param name="source">The input <see cref="UploadBuffer{T}"/> instance to read data from.</param>
/// <param name="destination">The target <see cref="StructuredBuffer{T}"/> instance to write data to.</param>
/// <param name="sourceOffset">The offset to start reading data from.</param>
/// <param name="destinationOffset">The starting offset within <paramref name="destination"/> to write data to.</param>
/// <param name="bufferOffset">The offset to start reading data from.</param>
/// <param name="count">The number of items to read.</param>
public static void CopyTo<T>(this UploadBuffer<T> buffer, StructuredBuffer<T> destination, int destinationOffset, int bufferOffset, int count)
public static void CopyTo<T>(this UploadBuffer<T> source, StructuredBuffer<T> destination, int sourceOffset, int destinationOffset, int count)
where T : unmanaged
{
destination.CopyFrom(buffer, bufferOffset, count, destinationOffset);
destination.CopyFrom(source, sourceOffset, destinationOffset, count);
}
}
+13 -13
ファイルの表示
@@ -126,9 +126,9 @@ public unsafe abstract class Buffer<T> : NativeObject
/// 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="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 CopyTo(ref T destination, int length, int offset);
/// <param name="sourceOffset">The offset to start reading data from.</param>
/// <param name="count">The length of the memory area to write data to.</param>
internal abstract void CopyTo(ref T destination, int sourceOffset, int count);
/// <summary>
/// Writes the contents of a given range from the current <see cref="Buffer{T}"/> instance and writes them into a target <see cref="Buffer{T}"/> instance.
@@ -136,8 +136,8 @@ public unsafe abstract class Buffer<T> : NativeObject
/// <param name="destination">The target <see cref="Buffer{T}"/> instance to write data to.</param>
/// <param name="sourceOffset">The offset to start reading data from.</param>
/// <param name="destinationOffset">The starting offset within <paramref name="destination"/> to write data to.</param>
/// <param name="length">The number of items to read.</param>
internal abstract void CopyTo(Buffer<T> destination, int sourceOffset, int destinationOffset, int length);
/// <param name="count">The number of items to read.</param>
internal abstract void CopyTo(Buffer<T> destination, int sourceOffset, int destinationOffset, int count);
/// <summary>
/// Writes the contents of a given range from the current <see cref="Buffer{T}"/> instance and writes them into a target <see cref="Buffer{T}"/> instance, using a temporary CPU buffer.
@@ -145,18 +145,18 @@ public unsafe abstract class Buffer<T> : NativeObject
/// <param name="destination">The target <see cref="Buffer{T}"/> instance to write data to.</param>
/// <param name="sourceOffset">The offset to start reading data from.</param>
/// <param name="destinationOffset">The starting offset within <paramref name="destination"/> to write data to.</param>
/// <param name="length">The number of items to read.</param>
protected void CopyToWithCpuBuffer(Buffer<T> destination, int sourceOffset, int destinationOffset, int length)
/// <param name="count">The number of items to read.</param>
protected void CopyToWithCpuBuffer(Buffer<T> destination, int sourceOffset, int destinationOffset, int count)
{
T[] array = ArrayPool<T>.Shared.Rent(length);
T[] array = ArrayPool<T>.Shared.Rent(count);
try
{
ref T r0 = ref MemoryMarshal.GetArrayDataReference(array);
CopyTo(ref r0, length, sourceOffset);
CopyTo(ref r0, sourceOffset, count);
destination.CopyFrom(ref r0, length, destinationOffset);
destination.CopyFrom(ref r0, destinationOffset, count);
}
finally
{
@@ -168,9 +168,9 @@ public unsafe abstract class Buffer<T> : NativeObject
/// 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="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 CopyFrom(ref T source, int length, int offset);
/// <param name="destinationOffset">The offset to start writing data to.</param>
/// <param name="count">The length of the input memory area to read data from.</param>
internal abstract void CopyFrom(ref T source, int destinationOffset, int count);
/// <inheritdoc/>
protected override void OnDispose()
+41 -37
ファイルの表示
@@ -30,15 +30,15 @@ public abstract class StructuredBuffer<T> : Buffer<T>
}
/// <inheritdoc/>
internal override unsafe void CopyTo(ref T destination, int length, int offset)
internal override unsafe void CopyTo(ref T destination, int sourceOffset, int count)
{
GraphicsDevice.ThrowIfDisposed();
ThrowIfDisposed();
Guard.IsBetweenOrEqualTo(length, 0, Length, nameof(length));
Guard.IsInRange(offset, 0, Length, nameof(offset));
Guard.IsLessThanOrEqualTo(offset + length, Length, nameof(offset));
Guard.IsBetweenOrEqualTo(count, 0, Length, nameof(count));
Guard.IsInRange(sourceOffset, 0, Length, nameof(sourceOffset));
Guard.IsLessThanOrEqualTo(sourceOffset + count, Length, nameof(sourceOffset));
if (GraphicsDevice.IsCacheCoherentUMA)
{
@@ -49,17 +49,17 @@ public abstract class StructuredBuffer<T> : Buffer<T>
MemoryHelper.Copy<T>(
source: resource.Pointer,
destination: destinationPointer,
sourceElementOffset: (uint)offset,
sourceElementOffset: (uint)sourceOffset,
destinationElementOffset: 0,
sourceElementPitchInBytes: (uint)sizeof(T),
destinationElementPitchInBytes: (uint)sizeof(T),
count: (uint)length);
count: (uint)count);
}
}
else
{
nint byteOffset = (nint)offset * sizeof(T);
nint byteLength = length * sizeof(T);
nint byteOffset = (nint)sourceOffset * sizeof(T);
nint byteLength = count * sizeof(T);
using UniquePtr<D3D12MA_Allocation> allocation = GraphicsDevice.Allocator->CreateResource(null, ResourceType.ReadBack, AllocationMode.Default, (ulong)byteLength);
@@ -80,13 +80,13 @@ public abstract class StructuredBuffer<T> : Buffer<T>
destinationElementOffset: 0,
sourceElementPitchInBytes: (uint)sizeof(T),
destinationElementPitchInBytes: (uint)sizeof(T),
count: (uint)length);
count: (uint)count);
}
}
}
/// <inheritdoc/>
internal override unsafe void CopyTo(Buffer<T> destination, int sourceOffset, int destinationOffset, int length)
internal override unsafe void CopyTo(Buffer<T> destination, int sourceOffset, int destinationOffset, int count)
{
GraphicsDevice.ThrowIfDisposed();
@@ -95,18 +95,18 @@ public abstract class StructuredBuffer<T> : Buffer<T>
destination.ThrowIfDeviceMismatch(GraphicsDevice);
destination.ThrowIfDisposed();
Guard.IsBetweenOrEqualTo(length, 0, Length, nameof(length));
Guard.IsBetweenOrEqualTo(length, 0, destination.Length, nameof(length));
Guard.IsBetweenOrEqualTo(count, 0, Length, nameof(count));
Guard.IsBetweenOrEqualTo(count, 0, destination.Length, nameof(count));
Guard.IsInRange(sourceOffset, 0, Length, nameof(sourceOffset));
Guard.IsLessThanOrEqualTo(sourceOffset + length, Length, nameof(sourceOffset));
Guard.IsLessThanOrEqualTo(sourceOffset + count, Length, nameof(sourceOffset));
Guard.IsInRange(destinationOffset, 0, destination.Length, nameof(destinationOffset));
Guard.IsLessThanOrEqualTo(destinationOffset + length, destination.Length, nameof(destinationOffset));
Guard.IsLessThanOrEqualTo(destinationOffset + count, destination.Length, nameof(destinationOffset));
if (!destination.IsPaddingPresent)
{
nint sourceByteOffset = (nint)sourceOffset * sizeof(T);
nint destinationByteOffset = (nint)destinationOffset * sizeof(T);
nint byteLength = length * sizeof(T);
nint byteLength = count * sizeof(T);
// Directly copy the input buffer
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
@@ -120,17 +120,17 @@ public abstract class StructuredBuffer<T> : Buffer<T>
copyCommandList.ExecuteAndWaitForCompletion();
}
else CopyToWithCpuBuffer(destination, sourceOffset, destinationOffset, length);
else CopyToWithCpuBuffer(destination, sourceOffset, destinationOffset, count);
}
/// <summary>
/// Reads the contents of the specified range from the current <see cref="StructuredBuffer{T}"/> instance and writes them into a target <see cref="ReadBackBuffer{T}"/> instance.
/// </summary>
/// <param name="destination">The target <see cref="ReadBackBuffer{T}"/> instance to write data to.</param>
/// <param name="sourceOffset">The offset to start reading data from.</param>
/// <param name="destinationOffset">The starting offset within <paramref name="destination"/> to write data to.</param>
/// <param name="length">The number of items to read.</param>
/// <param name="offset">The offset to start reading data from.</param>
internal unsafe void CopyTo(ReadBackBuffer<T> destination, int destinationOffset, int length, int offset)
/// <param name="count">The number of items to read.</param>
internal unsafe void CopyTo(ReadBackBuffer<T> destination, int sourceOffset, int destinationOffset, int count)
{
GraphicsDevice.ThrowIfDisposed();
@@ -139,10 +139,12 @@ public abstract class StructuredBuffer<T> : Buffer<T>
destination.ThrowIfDeviceMismatch(GraphicsDevice);
destination.ThrowIfDisposed();
Guard.IsInRange(offset, 0, Length, nameof(offset));
Guard.IsLessThanOrEqualTo(offset + length, Length, nameof(length));
Guard.IsBetweenOrEqualTo(count, 0, Length, nameof(count));
Guard.IsBetweenOrEqualTo(count, 0, destination.Length, nameof(count));
Guard.IsInRange(sourceOffset, 0, Length, nameof(sourceOffset));
Guard.IsLessThanOrEqualTo(sourceOffset + count, Length, nameof(sourceOffset));
Guard.IsInRange(destinationOffset, 0, destination.Length, nameof(destinationOffset));
Guard.IsLessThanOrEqualTo(destinationOffset + length, destination.Length, nameof(length));
Guard.IsLessThanOrEqualTo(destinationOffset + count, destination.Length, nameof(destinationOffset));
if (GraphicsDevice.IsCacheCoherentUMA)
{
@@ -151,17 +153,17 @@ public abstract class StructuredBuffer<T> : Buffer<T>
MemoryHelper.Copy<T>(
source: resource.Pointer,
destination: destination.MappedData,
sourceElementOffset: (uint)offset,
sourceElementOffset: (uint)sourceOffset,
destinationElementOffset: (uint)destinationOffset,
sourceElementPitchInBytes: (uint)sizeof(T),
destinationElementPitchInBytes: (uint)sizeof(T),
count: (uint)length);
count: (uint)count);
}
else
{
ulong byteDestinationOffset = (uint)destinationOffset * (uint)sizeof(T);
ulong byteOffset = (uint)offset * (uint)sizeof(T);
ulong byteLength = (uint)length * (uint)sizeof(T);
ulong byteOffset = (uint)sourceOffset * (uint)sizeof(T);
ulong byteLength = (uint)count * (uint)sizeof(T);
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
@@ -171,7 +173,7 @@ public abstract class StructuredBuffer<T> : Buffer<T>
}
/// <inheritdoc/>
internal override unsafe void CopyFrom(ref T source, int length, int offset)
internal override unsafe void CopyFrom(ref T source, int offset, int length)
{
GraphicsDevice.ThrowIfDisposed();
@@ -229,9 +231,9 @@ public abstract class StructuredBuffer<T> : Buffer<T>
/// </summary>
/// <param name="source">The input <see cref="UploadBuffer{T}"/> instance to read data from.</param>
/// <param name="sourceOffset">The starting offset within <paramref name="source"/> to read data from.</param>
/// <param name="length">The number of items to read.</param>
/// <param name="offset">The offset to start reading writing data to.</param>
internal unsafe void CopyFrom(UploadBuffer<T> source, int sourceOffset, int length, int offset)
/// <param name="destinationOffset">The offset to start reading writing data to.</param>
/// <param name="count">The number of items to read.</param>
internal unsafe void CopyFrom(UploadBuffer<T> source, int sourceOffset, int destinationOffset, int count)
{
GraphicsDevice.ThrowIfDisposed();
@@ -240,10 +242,12 @@ public abstract class StructuredBuffer<T> : Buffer<T>
source.ThrowIfDeviceMismatch(GraphicsDevice);
source.ThrowIfDisposed();
Guard.IsInRange(offset, 0, Length, nameof(offset));
Guard.IsLessThanOrEqualTo(offset + length, Length, nameof(length));
Guard.IsBetweenOrEqualTo(count, 0, Length, nameof(count));
Guard.IsBetweenOrEqualTo(count, 0, source.Length, nameof(count));
Guard.IsInRange(sourceOffset, 0, source.Length, nameof(sourceOffset));
Guard.IsLessThanOrEqualTo(sourceOffset + length, source.Length, nameof(length));
Guard.IsLessThanOrEqualTo(sourceOffset + count, source.Length, nameof(sourceOffset));
Guard.IsInRange(destinationOffset, 0, Length, nameof(destinationOffset));
Guard.IsLessThanOrEqualTo(destinationOffset + count, Length, nameof(destinationOffset));
if (GraphicsDevice.IsCacheCoherentUMA)
{
@@ -253,16 +257,16 @@ public abstract class StructuredBuffer<T> : Buffer<T>
source: source.MappedData,
destination: resource.Pointer,
sourceElementOffset: (uint)sourceOffset,
destinationElementOffset: (uint)offset,
destinationElementOffset: (uint)destinationOffset,
sourceElementPitchInBytes: (uint)sizeof(T),
destinationElementPitchInBytes: (uint)sizeof(T),
count: (uint)length);
count: (uint)count);
}
else
{
ulong byteSourceOffset = (uint)sourceOffset * (uint)sizeof(T);
ulong byteOffset = (uint)offset * (uint)sizeof(T);
ulong byteLength = (uint)length * (uint)sizeof(T);
ulong byteOffset = (uint)destinationOffset * (uint)sizeof(T);
ulong byteLength = (uint)count * (uint)sizeof(T);
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
+2 -2
ファイルの表示
@@ -57,7 +57,7 @@ public sealed class ConstantBuffer<T> : Buffer<T>
}
/// <inheritdoc/>
internal override unsafe void CopyTo(ref T destination, int length, int offset)
internal override unsafe void CopyTo(ref T destination, int offset, int length)
{
GraphicsDevice.ThrowIfDisposed();
@@ -117,7 +117,7 @@ public sealed class ConstantBuffer<T> : Buffer<T>
}
/// <inheritdoc/>
internal override unsafe void CopyFrom(ref T source, int length, int offset)
internal override unsafe void CopyFrom(ref T source, int offset, int length)
{
GraphicsDevice.ThrowIfDisposed();
+1 -1
ファイルの表示
@@ -20,7 +20,7 @@ internal sealed class BufferDebugView<T>
{
var items = GC.AllocateUninitializedArray<T>(buffer.Length);
buffer.CopyTo(ref items[0], buffer.Length, 0);
buffer.CopyTo(ref items[0], 0, buffer.Length);
Items = items;
}
+2 -2
ファイルの表示
@@ -124,7 +124,7 @@ public partial class TransferBufferTests
using ReadOnlyBuffer<int> readOnlyBuffer = device.Get().AllocateReadOnlyBuffer<int>(uploadBuffer.Length);
uploadBuffer.CopyTo(readOnlyBuffer, destinationOffset, bufferOffset, count);
uploadBuffer.CopyTo(readOnlyBuffer, bufferOffset, destinationOffset, count);
int[] result = readOnlyBuffer.ToArray(destinationOffset, count);
@@ -164,7 +164,7 @@ public partial class TransferBufferTests
using ReadOnlyBuffer<int> readOnlyBuffer = device.Get().AllocateReadOnlyBuffer(source);
using ReadBackBuffer<int> readBackBuffer = device.Get().AllocateReadBackBuffer<int>(readOnlyBuffer.Length);
readOnlyBuffer.CopyTo(readBackBuffer, destinationOffset, bufferOffset, count);
readOnlyBuffer.CopyTo(readBackBuffer, bufferOffset, destinationOffset, count);
Assert.AreEqual(source.Length, readBackBuffer.Length);
Assert.IsTrue(source.AsSpan(bufferOffset, count).SequenceEqual(readBackBuffer.Span.Slice(destinationOffset, count)));