Merge pull request #161 from Sergio0694/feature/resource-copy-apis-revamp
Expand resource copying APIs
このコミットが含まれているのは:
34ファイル変更
+2915
-693
検索条件に一致するファイルはありません
@@ -21,6 +21,19 @@ internal static class AlignmentHelper
|
||||
return (size + alignment - 1) & ~(alignment - 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pads the input size so that its pitch is aligned to a multiple of a specified length.
|
||||
/// </summary>
|
||||
/// <param name="size">The input size to pad, if needed.</param>
|
||||
/// <param name="alignment">The target alignment.</param>
|
||||
/// <returns>The padded value relative to the given inputs.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static nint Pad(nint size, nint alignment)
|
||||
{
|
||||
return (size + alignment - 1) & ~(alignment - 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aligns a given offset to a specified boundary, if a given size increment would have crossed it.
|
||||
/// </summary>
|
||||
|
||||
@@ -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,107 +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="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 Buffer<T> buffer, T[] destination, int destinationOffset, int bufferOffset, 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, bufferOffset);
|
||||
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="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> source, Buffer<T> destination)
|
||||
where T : unmanaged
|
||||
{
|
||||
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="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> source, Buffer<T> destination, int sourceOffset, int destinationOffset, int count)
|
||||
where T : unmanaged
|
||||
{
|
||||
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="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> destination, Buffer<T> source)
|
||||
where T : unmanaged
|
||||
{
|
||||
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="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="destination"/> to write data to.</param>
|
||||
/// <param name="count">The number of items to read.</param>
|
||||
public static void CopyFrom<T>(this Buffer<T> destination, Buffer<T> source, int sourceOffset, int destinationOffset, int count)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, sourceOffset, destinationOffset, count);
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,9 @@ internal static unsafe class ID3D12GraphicsCommandListExtensions
|
||||
D3D12_BOX d3D12Box;
|
||||
D3D12_BOX* pD3D12Box;
|
||||
|
||||
if (sourceX == 0 && sourceY == 0 && sourceZ == 0 &&
|
||||
if (sourceX == 0 &&
|
||||
sourceY == 0 &&
|
||||
sourceZ == 0 &&
|
||||
width == d3D12ResourceDescriptionSource.Width &&
|
||||
height == d3D12ResourceDescriptionSource.Height &&
|
||||
depth == d3D12ResourceDescriptionSource.Depth)
|
||||
@@ -103,7 +105,9 @@ internal static unsafe class ID3D12GraphicsCommandListExtensions
|
||||
D3D12_BOX d3D12Box;
|
||||
D3D12_BOX* pD3D12Box;
|
||||
|
||||
if (sourceX == 0 && sourceY == 0 && sourceZ == 0 &&
|
||||
if (sourceX == 0 &&
|
||||
sourceY == 0 &&
|
||||
sourceZ == 0 &&
|
||||
width == d3D12PlacedSubresourceFootprintSource->Footprint.Width &&
|
||||
height == d3D12PlacedSubresourceFootprintSource->Footprint.Height &&
|
||||
depth == d3D12PlacedSubresourceFootprintSource->Footprint.Depth)
|
||||
@@ -125,6 +129,65 @@ internal static unsafe class ID3D12GraphicsCommandListExtensions
|
||||
pD3D12Box);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies a texture memory region from one texture to another.
|
||||
/// </summary>
|
||||
/// <param name="d3D12GraphicsCommandList">The <see cref="ID3D12GraphicsCommandList"/> instance in use.</param>
|
||||
/// <param name="d3D12ResourceDestination">The destination <see cref="ID3D12Resource"/> (a buffer) to write to.</param>
|
||||
/// <param name="destinationX">The horizontal offset in the destination buffer.</param>
|
||||
/// <param name="destinationY">The vertical offset in the destination buffer.</param>
|
||||
/// <param name="destinationZ">The depthwise offset in the destination buffer.</param>
|
||||
/// <param name="d3D12ResourceSource">The source <see cref="ID3D12Resource"/> (a texture) to read from.</param>
|
||||
/// <param name="sourceX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceY">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceZ">The depthwise offset in the source texture.</param>
|
||||
/// <param name="width">The width of the memory area to read from.</param>
|
||||
/// <param name="height">The height of the memory area to read from.</param>
|
||||
/// <param name="depth">The depth of the memory area to read from.</param>
|
||||
public static void CopyTextureRegion(
|
||||
this ref ID3D12GraphicsCommandList d3D12GraphicsCommandList,
|
||||
ID3D12Resource* d3D12ResourceDestination,
|
||||
uint destinationX,
|
||||
uint destinationY,
|
||||
ushort destinationZ,
|
||||
ID3D12Resource* d3D12ResourceSource,
|
||||
uint sourceX,
|
||||
uint sourceY,
|
||||
ushort sourceZ,
|
||||
uint width,
|
||||
uint height,
|
||||
ushort depth)
|
||||
{
|
||||
D3D12_RESOURCE_DESC d3D12ResourceDescriptionSource = d3D12ResourceSource->GetDesc();
|
||||
D3D12_TEXTURE_COPY_LOCATION d3D12TextureCopyLocationDestination = new(d3D12ResourceDestination, 0);
|
||||
D3D12_TEXTURE_COPY_LOCATION d3D12TextureCopyLocationSource = new(d3D12ResourceSource, 0);
|
||||
D3D12_BOX d3D12Box;
|
||||
D3D12_BOX* pD3D12Box;
|
||||
|
||||
if (sourceX == 0 &&
|
||||
sourceY == 0 &&
|
||||
sourceZ == 0 &&
|
||||
width == d3D12ResourceDescriptionSource.Width &&
|
||||
height == d3D12ResourceDescriptionSource.Height &&
|
||||
depth == d3D12ResourceDescriptionSource.Depth)
|
||||
{
|
||||
pD3D12Box = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
d3D12Box = new D3D12_BOX((int)sourceX, (int)sourceY, sourceZ, (int)(sourceX + width), (int)(sourceY + height), sourceZ + depth);
|
||||
pD3D12Box = &d3D12Box;
|
||||
}
|
||||
|
||||
d3D12GraphicsCommandList.CopyTextureRegion(
|
||||
&d3D12TextureCopyLocationDestination,
|
||||
destinationX,
|
||||
destinationY,
|
||||
destinationZ,
|
||||
&d3D12TextureCopyLocationSource,
|
||||
pD3D12Box);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a resource barrier to transition a resource to a specific state.
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
using ComputeSharp.Resources;
|
||||
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that contains extension methods for the <see cref="ReadBackBuffer{T}"/> type.
|
||||
/// </summary>
|
||||
public static class ReadBackBufferExtensions
|
||||
{
|
||||
/// <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="destination">The target <see cref="StructuredBuffer{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="UploadBuffer{T}"/> instance to read data from.</param>
|
||||
public static void CopyFrom<T>(this ReadBackBuffer<T> destination, StructuredBuffer<T> source)
|
||||
where T : unmanaged
|
||||
{
|
||||
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="destination">The target <see cref="StructuredBuffer{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="UploadBuffer{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="destination"/> to write data to.</param>
|
||||
/// <param name="count">The number of items to read.</param>
|
||||
public static void CopyFrom<T>(this ReadBackBuffer<T> destination, StructuredBuffer<T> source, int sourceOffset, int destinationOffset, int count)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, sourceOffset, destinationOffset, count);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using ComputeSharp.Resources;
|
||||
|
||||
namespace ComputeSharp;
|
||||
|
||||
@@ -8,6 +9,52 @@ namespace ComputeSharp;
|
||||
/// </summary>
|
||||
public static class ReadBackTexture2DExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="ReadBackTexture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="destination">The target <see cref="ReadBackTexture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
public static void CopyFrom<T>(this ReadBackTexture2D<T> destination, Texture2D<T> source)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, 0, 0, 0, 0, source.Width, source.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="ReadBackTexture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="destination">The target <see cref="ReadBackTexture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
public static void CopyFrom<T>(this ReadBackTexture2D<T> destination, Texture2D<T> source, int sourceOffsetX, int sourceOffsetY, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, 0, 0, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="ReadBackTexture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="destination">The target <see cref="ReadBackTexture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
public static void CopyFrom<T>(this ReadBackTexture2D<T> destination, Texture2D<T> source, int sourceOffsetX, int sourceOffsetY, int destinationOffsetX, int destinationOffsetY, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, destinationOffsetX, destinationOffsetY, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves a texture to a specified file.
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
using ComputeSharp.Resources;
|
||||
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that contains extension methods for the <see cref="ReadBackTexture3D{T}"/> type.
|
||||
/// </summary>
|
||||
public static class ReadBackTexture3DExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="ReadBackTexture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="destination">The target <see cref="ReadBackTexture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
public static void CopyFrom<T>(this ReadBackTexture3D<T> destination, Texture3D<T> source)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, 0, 0, 0, 0, 0, 0, source.Width, source.Height, source.Depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="ReadBackTexture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="destination">The target <see cref="ReadBackTexture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetZ">The depthwise offset in the source texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
/// <param name="depth">The depth of the memory area to copy.</param>
|
||||
public static void CopyFrom<T>(this ReadBackTexture3D<T> destination, Texture3D<T> source, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int width, int height, int depth)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, sourceOffsetZ, 0, 0, 0, width, height, depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="ReadBackTexture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="destination">The target <see cref="ReadBackTexture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetZ">The depthwise offset in the source texture.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetZ">The depthwise offset in the destination texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
/// <param name="depth">The depth of the memory area to copy.</param>
|
||||
public static void CopyFrom<T>(this ReadBackTexture3D<T> destination, Texture3D<T> source, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, sourceOffsetZ, destinationOffsetX, destinationOffsetY, destinationOffsetZ, width, height, depth);
|
||||
}
|
||||
}
|
||||
@@ -11,26 +11,53 @@ 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of an <see cref="UploadBuffer{T}"/> instance and writes them into a target <see cref="UploadBuffer{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the buffer.</typeparam>
|
||||
/// <param name="destination">The target <see cref="StructuredBuffer{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="UploadBuffer{T}"/> instance to read data from.</param>
|
||||
public static void CopyFrom<T>(this StructuredBuffer<T> destination, UploadBuffer<T> source)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, 0, 0, source.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of an <see cref="UploadBuffer{T}"/> instance and writes them into a target <see cref="UploadBuffer{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the buffer.</typeparam>
|
||||
/// <param name="destination">The target <see cref="StructuredBuffer{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="UploadBuffer{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="destination"/> to write data to.</param>
|
||||
/// <param name="count">The number of items to read.</param>
|
||||
public static void CopyFrom<T>(this StructuredBuffer<T> destination, UploadBuffer<T> source, int sourceOffset, int destinationOffset, int count)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, sourceOffset, destinationOffset, count);
|
||||
}
|
||||
}
|
||||
@@ -16,15 +16,42 @@ public static class Texture2DExtensions
|
||||
/// Reads the contents of the current <see cref="Texture2D{T}"/> instance and returns an array.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <returns>A <typeparamref name="T"/> array with the contents of the current texture.</returns>
|
||||
[Pure]
|
||||
public static T[,] ToArray<T>(this Texture2D<T> texture)
|
||||
public static T[,] ToArray<T>(this Texture2D<T> source)
|
||||
where T : unmanaged
|
||||
{
|
||||
T[,] data = new T[texture.Height, texture.Width];
|
||||
T[,] data = new T[source.Height, source.Width];
|
||||
|
||||
texture.CopyTo(data);
|
||||
source.CopyTo(data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of the current <see cref="Texture2D{T}"/> instance and returns an array.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="x">The horizontal offset in the source texture.</param>
|
||||
/// <param name="y">The vertical offset in the source texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
/// <returns>A <typeparamref name="T"/> array with the contents of the current texture.</returns>
|
||||
[Pure]
|
||||
public static unsafe T[,] ToArray<T>(this Texture2D<T> source, int x, int y, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
Guard.IsGreaterThanOrEqualTo(width, 0, nameof(width));
|
||||
Guard.IsGreaterThanOrEqualTo(height, 0, nameof(height));
|
||||
|
||||
T[,] data = new T[height, width];
|
||||
|
||||
fixed (T* p = data)
|
||||
{
|
||||
source.CopyTo(new Span<T>(p, width * height), x, y, width, height);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
@@ -33,102 +60,102 @@ public static class Texture2DExtensions
|
||||
/// Reads the contents of the current <see cref="Texture2D{T}"/> instance and writes them into a target array.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The input array to write data to.</param>
|
||||
public static void CopyTo<T>(this Texture2D<T> texture, T[,] destination)
|
||||
public static void CopyTo<T>(this Texture2D<T> source, T[,] destination)
|
||||
where T : unmanaged
|
||||
{
|
||||
Guard.IsEqualTo(destination.GetLength(0), texture.Height, nameof(destination));
|
||||
Guard.IsEqualTo(destination.GetLength(1), texture.Width, nameof(destination));
|
||||
Guard.IsEqualTo(destination.GetLength(0), source.Height, nameof(destination));
|
||||
Guard.IsEqualTo(destination.GetLength(1), source.Width, nameof(destination));
|
||||
|
||||
texture.CopyTo(ref destination[0, 0], destination.Length, 0, 0, texture.Width, texture.Height);
|
||||
source.CopyTo(ref destination[0, 0], destination.Length, 0, 0, source.Width, source.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of the specified range from the current <see cref="Texture2D{T}"/> instance and writes them into a target array.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The input array to write data to.</param>
|
||||
public static void CopyTo<T>(this Texture2D<T> texture, T[] destination)
|
||||
public static void CopyTo<T>(this Texture2D<T> source, T[] destination)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyTo(destination.AsSpan(), 0, 0, texture.Width, texture.Height);
|
||||
source.CopyTo(destination.AsSpan(), 0, 0, source.Width, source.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of the specified range from the current <see cref="Texture2D{T}"/> instance and writes them into a target array.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The input array to write data to.</param>
|
||||
/// <param name="x">The horizontal range of items to copy.</param>
|
||||
/// <param name="y">The vertical range of items to copy.</param>
|
||||
public static void CopyTo<T>(this Texture2D<T> texture, T[] destination, Range x, Range y)
|
||||
public static void CopyTo<T>(this Texture2D<T> source, T[] destination, Range x, Range y)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyTo(destination.AsSpan(), x, y);
|
||||
source.CopyTo(destination.AsSpan(), x, y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of the specified range from the current <see cref="Texture2D{T}"/> instance and writes them into a target array.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The input array to write data to.</param>
|
||||
/// <param name="x">The horizontal offset in the source texture.</param>
|
||||
/// <param name="y">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
public static void CopyTo<T>(this Texture2D<T> texture, T[] destination, int x, int y, int width, int height)
|
||||
public static void CopyTo<T>(this Texture2D<T> source, T[] destination, int sourceOffsetX, int sourceOffsetY, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyTo(destination.AsSpan(), x, y, width, height);
|
||||
source.CopyTo(destination.AsSpan(), sourceOffsetX, sourceOffsetY, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of the specified range from the current <see cref="Texture2D{T}"/> instance and writes them into a target array.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The input array to write data to.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="destination"/> to write data to.</param>
|
||||
public static void CopyTo<T>(this Texture2D<T> texture, T[] destination, int offset)
|
||||
/// <param name="destinationOffset">The starting offset within <paramref name="destination"/> to write data to.</param>
|
||||
public static void CopyTo<T>(this Texture2D<T> source, T[] destination, int destinationOffset)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyTo(destination.AsSpan(offset), 0, 0, texture.Width, texture.Height);
|
||||
source.CopyTo(destination.AsSpan(destinationOffset), 0, 0, source.Width, source.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of the specified range from the current <see cref="Texture2D{T}"/> instance and writes them into a target array.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The input array to write data to.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="destination"/> to write data to.</param>
|
||||
/// <param name="destinationOffset">The starting offset within <paramref name="destination"/> to write data to.</param>
|
||||
/// <param name="x">The horizontal range of items to copy.</param>
|
||||
/// <param name="y">The vertical range of items to copy.</param>
|
||||
public static void CopyTo<T>(this Texture2D<T> texture, T[] destination, int offset, Range x, Range y)
|
||||
public static void CopyTo<T>(this Texture2D<T> source, T[] destination, int destinationOffset, Range x, Range y)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyTo(destination.AsSpan(offset), x, y);
|
||||
source.CopyTo(destination.AsSpan(destinationOffset), x, y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of the specified range from the current <see cref="Texture2D{T}"/> instance and writes them into a target array.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The input array to write data to.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="destination"/> to write data to.</param>
|
||||
/// <param name="x">The horizontal offset in the source texture.</param>
|
||||
/// <param name="y">The vertical offset in the source texture.</param>
|
||||
/// <param name="destinationOffset">The starting offset within <paramref name="destination"/> to write data to.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
public static void CopyTo<T>(this Texture2D<T> texture, T[] destination, int offset, int x, int y, int width, int height)
|
||||
public static void CopyTo<T>(this Texture2D<T> source, T[] destination, int destinationOffset, int sourceOffsetX, int sourceOffsetY, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyTo(destination.AsSpan(offset), x, y, width, height);
|
||||
source.CopyTo(destination.AsSpan(destinationOffset), sourceOffsetX, sourceOffsetY, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -136,162 +163,226 @@ public static class Texture2DExtensions
|
||||
/// The input data will be read from the start of the texture.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="source">The input <see cref="Texture2D{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 Texture2D<T> texture, Span<T> destination)
|
||||
public static void CopyTo<T>(this Texture2D<T> source, Span<T> destination)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyTo(destination, 0, 0, texture.Width, texture.Height);
|
||||
source.CopyTo(destination, 0, 0, source.Width, source.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of the specified range from the current <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="Span{T}"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The input <see cref="Span{T}"/> to write data to.</param>
|
||||
/// <param name="x">The horizontal range of items to copy.</param>
|
||||
/// <param name="y">The vertical range of items to copy.</param>
|
||||
public static void CopyTo<T>(this Texture2D<T> texture, Span<T> destination, Range x, Range y)
|
||||
public static void CopyTo<T>(this Texture2D<T> source, Span<T> destination, Range x, Range y)
|
||||
where T : unmanaged
|
||||
{
|
||||
var (offsetX, width) = x.GetOffsetAndLength(texture.Width);
|
||||
var (offsetY, height) = y.GetOffsetAndLength(texture.Height);
|
||||
var (offsetX, width) = x.GetOffsetAndLength(source.Width);
|
||||
var (offsetY, height) = y.GetOffsetAndLength(source.Height);
|
||||
|
||||
texture.CopyTo(destination, offsetX, offsetY, width, height);
|
||||
source.CopyTo(destination, offsetX, offsetY, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of the specified range from the current <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="Span{T}"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The input <see cref="Span{T}"/> to write data to.</param>
|
||||
/// <param name="x">The horizontal offset in the source texture.</param>
|
||||
/// <param name="y">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
public static void CopyTo<T>(this Texture2D<T> texture, Span<T> destination, int x, int y, int width, int height)
|
||||
public static void CopyTo<T>(this Texture2D<T> source, Span<T> destination, int sourceOffsetX, int sourceOffsetY, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyTo(ref MemoryMarshal.GetReference(destination), destination.Length, x, y, width, height);
|
||||
source.CopyTo(ref MemoryMarshal.GetReference(destination), destination.Length, sourceOffsetX, sourceOffsetY, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
public static void CopyTo<T>(this Texture2D<T> source, Texture2D<T> destination)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, 0, 0, 0, 0, source.Width, source.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
public static void CopyTo<T>(this Texture2D<T> source, Texture2D<T> destination, int sourceOffsetX, int sourceOffsetY, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, 0, 0, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
public static void CopyTo<T>(this Texture2D<T> source, Texture2D<T> destination, int sourceOffsetX, int sourceOffsetY, int destinationOffsetX, int destinationOffsetY, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, destinationOffsetX, destinationOffsetY, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="ReadBackTexture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The target <see cref="ReadBackTexture2D{T}"/> instance to write data to.</param>
|
||||
public static void CopyTo<T>(this Texture2D<T> texture, ReadBackTexture2D<T> destination)
|
||||
public static void CopyTo<T>(this Texture2D<T> source, ReadBackTexture2D<T> destination)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyTo(destination, 0, 0, 0, 0, texture.Width, texture.Height);
|
||||
source.CopyTo(destination, 0, 0, 0, 0, source.Width, source.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="ReadBackTexture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The target <see cref="ReadBackTexture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="x">The horizontal offset in the source texture.</param>
|
||||
/// <param name="y">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
public static void CopyTo<T>(this Texture2D<T> texture, ReadBackTexture2D<T> destination, int x, int y, int width, int height)
|
||||
public static void CopyTo<T>(this Texture2D<T> source, ReadBackTexture2D<T> destination, int sourceOffsetX, int sourceOffsetY, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyTo(destination, 0, 0, x, y, width, height);
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, 0, 0, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="ReadBackTexture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The target <see cref="ReadBackTexture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
public static void CopyTo<T>(this Texture2D<T> source, ReadBackTexture2D<T> destination, int sourceOffsetX, int sourceOffsetY, int destinationOffsetX, int destinationOffsetY, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, destinationOffsetX, destinationOffsetY, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the contents of a given <typeparamref name="T"/> array to the current <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <typeparamref name="T"/> array to read data from.</param>
|
||||
public static unsafe void CopyFrom<T>(this Texture2D<T> texture, T[,] source)
|
||||
public static unsafe void CopyFrom<T>(this Texture2D<T> destination, T[,] source)
|
||||
where T : unmanaged
|
||||
{
|
||||
Guard.IsEqualTo(source.GetLength(0), texture.Height, nameof(source));
|
||||
Guard.IsEqualTo(source.GetLength(1), texture.Width, nameof(source));
|
||||
Guard.IsEqualTo(source.GetLength(0), destination.Height, nameof(source));
|
||||
Guard.IsEqualTo(source.GetLength(1), destination.Width, nameof(source));
|
||||
|
||||
texture.CopyFrom(ref source[0, 0], source.Length, 0, 0, texture.Width, texture.Height);
|
||||
destination.CopyFrom(ref source[0, 0], source.Length, 0, 0, destination.Width, destination.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the contents of a given <typeparamref name="T"/> array to the current <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="destination">The target <see cref="Texture2D{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 Texture2D<T> texture, T[] source)
|
||||
public static void CopyFrom<T>(this Texture2D<T> destination, T[] source)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyFrom(source.AsSpan(), 0, 0, texture.Width, texture.Height);
|
||||
destination.CopyFrom(source.AsSpan(), 0, 0, destination.Width, destination.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the contents of a given <typeparamref name="T"/> array to a specified area of the current <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <typeparamref name="T"/> array to read data from.</param>
|
||||
/// <param name="x">The horizontal range of items to write.</param>
|
||||
/// <param name="y">The vertical range of items to write.</param>
|
||||
public static void CopyFrom<T>(this Texture2D<T> texture, T[] source, Range x, Range y)
|
||||
public static void CopyFrom<T>(this Texture2D<T> destination, T[] source, Range x, Range y)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyFrom(source.AsSpan(), x, y);
|
||||
destination.CopyFrom(source.AsSpan(), x, y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the contents of a given <typeparamref name="T"/> array to a specified area of the current <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <typeparamref name="T"/> array to read data from.</param>
|
||||
/// <param name="x">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="y">The vertical offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
|
||||
/// <param name="width">The width of the memory area to write to.</param>
|
||||
/// <param name="height">The height of the memory area to write to.</param>
|
||||
public static void CopyFrom<T>(this Texture2D<T> texture, T[] source, int x, int y, int width, int height)
|
||||
public static void CopyFrom<T>(this Texture2D<T> destination, T[] source, int destinationOffsetX, int destinationOffsetY, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyFrom(source.AsSpan(), x, y, width, height);
|
||||
destination.CopyFrom(source.AsSpan(), destinationOffsetX, destinationOffsetY, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the contents of a given <typeparamref name="T"/> array to a specified area of the current <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <typeparamref name="T"/> array to read data from.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="source"/> to read data from.</param>
|
||||
/// <param name="sourceOffset">The starting offset within <paramref name="source"/> to read data from.</param>
|
||||
/// <param name="x">The horizontal range of items to write.</param>
|
||||
/// <param name="y">The vertical range of items to write.</param>
|
||||
public static void CopyFrom<T>(this Texture2D<T> texture, T[] source, int offset, Range x, Range y)
|
||||
public static void CopyFrom<T>(this Texture2D<T> destination, T[] source, int sourceOffset, Range x, Range y)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyFrom(source.AsSpan(offset), x, y);
|
||||
destination.CopyFrom(source.AsSpan(sourceOffset), x, y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the contents of a given <typeparamref name="T"/> array to a specified area of the current <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <typeparamref name="T"/> array to read data from.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="source"/> to read data from.</param>
|
||||
/// <param name="x">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="y">The vertical offset in the destination texture.</param>
|
||||
/// <param name="sourceOffset">The starting offset within <paramref name="source"/> to read data from.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
|
||||
/// <param name="width">The width of the memory area to write to.</param>
|
||||
/// <param name="height">The height of the memory area to write to.</param>
|
||||
public static void CopyFrom<T>(this Texture2D<T> texture, T[] source, int offset, int x, int y, int width, int height)
|
||||
public static void CopyFrom<T>(this Texture2D<T> destination, T[] source, int sourceOffset, int destinationOffsetX, int destinationOffsetY, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyFrom(source.AsSpan(offset), x, y, width, height);
|
||||
destination.CopyFrom(source.AsSpan(sourceOffset), destinationOffsetX, destinationOffsetY, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -299,45 +390,137 @@ public static class Texture2DExtensions
|
||||
/// The input data will be written to the start of the texture, and all input items will be copied.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="destination">The target <see cref="Texture2D{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 Texture2D<T> texture, ReadOnlySpan<T> source)
|
||||
public static void CopyFrom<T>(this Texture2D<T> destination, ReadOnlySpan<T> source)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyFrom(source, 0, 0, texture.Width, texture.Height);
|
||||
destination.CopyFrom(source, 0, 0, destination.Width, destination.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the contents of a given <see cref="ReadOnlySpan{T}"/> to a specified area of the current <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="ReadOnlySpan{T}"/> to read data from.</param>
|
||||
/// <param name="x">The horizontal range of items to write.</param>
|
||||
/// <param name="y">The vertical range of items to write.</param>
|
||||
public static void CopyFrom<T>(this Texture2D<T> texture, ReadOnlySpan<T> source, Range x, Range y)
|
||||
public static void CopyFrom<T>(this Texture2D<T> destination, ReadOnlySpan<T> source, Range x, Range y)
|
||||
where T : unmanaged
|
||||
{
|
||||
var (offsetX, width) = x.GetOffsetAndLength(texture.Width);
|
||||
var (offsetY, height) = y.GetOffsetAndLength(texture.Height);
|
||||
var (offsetX, width) = x.GetOffsetAndLength(destination.Width);
|
||||
var (offsetY, height) = y.GetOffsetAndLength(destination.Height);
|
||||
|
||||
texture.CopyFrom(source, offsetX, offsetY, width, height);
|
||||
destination.CopyFrom(source, offsetX, offsetY, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the contents of a given <see cref="ReadOnlySpan{T}"/> to a specified area of the current <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="ReadOnlySpan{T}"/> to read data from.</param>
|
||||
/// <param name="x">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="y">The vertical offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
|
||||
/// <param name="width">The width of the memory area to write to.</param>
|
||||
/// <param name="height">The height of the memory area to write to.</param>
|
||||
public static void CopyFrom<T>(this Texture2D<T> texture, ReadOnlySpan<T> source, int x, int y, int width, int height)
|
||||
public static void CopyFrom<T>(this Texture2D<T> destination, ReadOnlySpan<T> source, int destinationOffsetX, int destinationOffsetY, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyFrom(ref MemoryMarshal.GetReference(source), source.Length, x, y, width, height);
|
||||
destination.CopyFrom(ref MemoryMarshal.GetReference(source), source.Length, destinationOffsetX, destinationOffsetY, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of an <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
public static void CopyFrom<T>(this Texture2D<T> destination, Texture2D<T> source)
|
||||
where T : unmanaged
|
||||
{
|
||||
destination.CopyFrom(source, 0, 0, 0, 0, source.Width, source.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of an <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
public static void CopyFrom<T>(this Texture2D<T> destination, Texture2D<T> source, int sourceOffsetX, int sourceOffsetY, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, 0, 0, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of an <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
public static void CopyFrom<T>(this Texture2D<T> destination, Texture2D<T> source, int sourceOffsetX, int sourceOffsetY, int destinationOffsetX, int destinationOffsetY, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, destinationOffsetX, destinationOffsetY, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of an <see cref="UploadTexture2D{T}"/> instance and writes them into a target <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="UploadTexture2D{T}"/> instance to read data from.</param>
|
||||
public static void CopyFrom<T>(this Texture2D<T> destination, UploadTexture2D<T> source)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, 0, 0, 0, 0, source.Width, source.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of an <see cref="UploadTexture2D{T}"/> instance and writes them into a target <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="UploadTexture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
public static void CopyFrom<T>(this Texture2D<T> destination, UploadTexture2D<T> source, int sourceOffsetX, int sourceOffsetY, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
destination.CopyFrom(source, sourceOffsetX, sourceOffsetY, 0, 0, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of an <see cref="UploadTexture2D{T}"/> instance and writes them into a target <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="UploadTexture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
public static void CopyFrom<T>(this Texture2D<T> destination, UploadTexture2D<T> source, int sourceOffsetX, int sourceOffsetY, int destinationOffsetX, int destinationOffsetY, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
destination.CopyFrom(source, sourceOffsetX, sourceOffsetY, destinationOffsetX, destinationOffsetY, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -15,7 +15,7 @@ public static class Texture3DExtensions
|
||||
/// Reads the contents of the current <see cref="Texture3D{T}"/> instance and returns an array.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <returns>A <typeparamref name="T"/> array with the contents of the current buffer.</returns>
|
||||
/// <remarks>
|
||||
/// The returned array will be using the same memory layout as the texture, that is, each 2D plane
|
||||
@@ -23,12 +23,41 @@ public static class Texture3DExtensions
|
||||
/// the depth dimension. This means that the resulting 3D array will have a size of [D, H, W].
|
||||
/// </remarks>
|
||||
[Pure]
|
||||
public static T[,,] ToArray<T>(this Texture3D<T> texture)
|
||||
public static T[,,] ToArray<T>(this Texture3D<T> source)
|
||||
where T : unmanaged
|
||||
{
|
||||
T[,,] data = new T[texture.Depth, texture.Height, texture.Width];
|
||||
T[,,] data = new T[source.Depth, source.Height, source.Width];
|
||||
|
||||
texture.CopyTo(data);
|
||||
source.CopyTo(data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of the current <see cref="Texture3D{T}"/> instance and returns an array.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="x">The horizontal offset in the source texture.</param>
|
||||
/// <param name="y">The vertical offset in the source texture.</param>
|
||||
/// <param name="z">The depthwise offset in the source texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
/// <param name="depth">The depth of the memory area to copy.</param>
|
||||
/// <returns>A <typeparamref name="T"/> array with the contents of the current texture.</returns>
|
||||
public static unsafe T[,,] ToArray<T>(this Texture3D<T> source, int x, int y, int z, int width, int height, int depth)
|
||||
where T : unmanaged
|
||||
{
|
||||
Guard.IsGreaterThanOrEqualTo(width, 0, nameof(width));
|
||||
Guard.IsGreaterThanOrEqualTo(height, 0, nameof(height));
|
||||
Guard.IsGreaterThanOrEqualTo(depth, 0, nameof(depth));
|
||||
|
||||
T[,,] data = new T[depth, height, width];
|
||||
|
||||
fixed (T* p = data)
|
||||
{
|
||||
source.CopyTo(new Span<T>(p, width * height * depth), x, y, z, width, height, depth);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
@@ -37,247 +66,319 @@ public static class Texture3DExtensions
|
||||
/// Reads the contents of the current <see cref="Texture3D{T}"/> instance and writes them into a target array.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The input array to write data to.</param>
|
||||
/// <remarks>
|
||||
/// The input 3D array needs to have each 2D plane stacked on the depth axis. That is, the expected
|
||||
/// layout of the input array has to be of shape [depth, height, width].
|
||||
/// </remarks>
|
||||
public static void CopyTo<T>(this Texture3D<T> texture, T[,,] destination)
|
||||
public static void CopyTo<T>(this Texture3D<T> source, T[,,] destination)
|
||||
where T : unmanaged
|
||||
{
|
||||
Guard.IsEqualTo(destination.GetLength(0), texture.Depth, nameof(destination));
|
||||
Guard.IsEqualTo(destination.GetLength(1), texture.Height, nameof(destination));
|
||||
Guard.IsEqualTo(destination.GetLength(2), texture.Width, nameof(destination));
|
||||
Guard.IsEqualTo(destination.GetLength(0), source.Depth, nameof(destination));
|
||||
Guard.IsEqualTo(destination.GetLength(1), source.Height, nameof(destination));
|
||||
Guard.IsEqualTo(destination.GetLength(2), source.Width, nameof(destination));
|
||||
|
||||
texture.CopyTo(ref destination[0, 0, 0], destination.Length, 0, 0, 0, texture.Width, texture.Height, texture.Depth);
|
||||
source.CopyTo(ref destination[0, 0, 0], destination.Length, 0, 0, 0, source.Width, source.Height, source.Depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of the specified range from the current <see cref="Texture3D{T}"/> instance and writes them into a target array.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The input array to write data to.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="destination"/> to write data to.</param>
|
||||
public static void CopyTo<T>(this Texture3D<T> texture, T[] destination, int offset)
|
||||
/// <param name="destinationOffset">The starting offset within <paramref name="destination"/> to write data to.</param>
|
||||
public static void CopyTo<T>(this Texture3D<T> source, T[] destination, int destinationOffset)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyTo(destination.AsSpan(offset), 0, 0, 0, texture.Width, texture.Height, texture.Depth);
|
||||
source.CopyTo(destination.AsSpan(destinationOffset), 0, 0, 0, source.Width, source.Height, source.Depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of the specified range from the current <see cref="Texture3D{T}"/> instance and writes them into a target array.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The input array to write data to.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="destination"/> to write data to.</param>
|
||||
/// <param name="destinationOffset">The starting offset within <paramref name="destination"/> to write data to.</param>
|
||||
/// <param name="x">The horizontal range of items to copy.</param>
|
||||
/// <param name="y">The vertical range of items to copy.</param>
|
||||
/// <param name="z">The depthwise range of items to copy.</param>
|
||||
public static void CopyTo<T>(this Texture3D<T> texture, T[] destination, int offset, Range x, Range y, Range z)
|
||||
public static void CopyTo<T>(this Texture3D<T> source, T[] destination, int destinationOffset, Range x, Range y, Range z)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyTo(destination.AsSpan(offset), x, y, z);
|
||||
source.CopyTo(destination.AsSpan(destinationOffset), x, y, z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of the specified range from the current <see cref="Texture3D{T}"/> instance and writes them into a target array.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The input array to write data to.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="destination"/> to write data to.</param>
|
||||
/// <param name="x">The horizontal offset in the source texture.</param>
|
||||
/// <param name="y">The vertical offset in the source texture.</param>
|
||||
/// <param name="z">The depthwise offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetZ">The depthwise offset in the source texture.</param>
|
||||
/// <param name="destinationOffset">The starting offset within <paramref name="destination"/> to write data to.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
/// <param name="depth">The depth of the memory area to copy.</param>
|
||||
public static void CopyTo<T>(this Texture3D<T> texture, T[] destination, int offset, int x, int y, int z, int width, int height, int depth)
|
||||
public static void CopyTo<T>(this Texture3D<T> source, T[] destination, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int destinationOffset, int width, int height, int depth)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyTo(destination.AsSpan(offset), x, y, z, width, height, depth);
|
||||
source.CopyTo(destination.AsSpan(destinationOffset), sourceOffsetX, sourceOffsetY, sourceOffsetZ, width, height, depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of the specified range from the current <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="Span{T}"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="source">The input <see cref="Texture3D{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 Texture3D<T> texture, Span<T> destination)
|
||||
public static void CopyTo<T>(this Texture3D<T> source, Span<T> destination)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyTo(destination, 0, 0, 0, texture.Width, texture.Height, texture.Depth);
|
||||
source.CopyTo(destination, 0, 0, 0, source.Width, source.Height, source.Depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of the specified range from the current <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="Span{T}"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The input <see cref="Span{T}"/> to write data to.</param>
|
||||
/// <param name="x">The horizontal range in the source texture.</param>
|
||||
/// <param name="y">The vertical range in the source texture.</param>
|
||||
/// <param name="z">The depthwise range in the source texture.</param>
|
||||
public static void CopyTo<T>(this Texture3D<T> texture, Span<T> destination, Range x, Range y, Range z)
|
||||
public static void CopyTo<T>(this Texture3D<T> source, Span<T> destination, Range x, Range y, Range z)
|
||||
where T : unmanaged
|
||||
{
|
||||
var (offsetX, width) = x.GetOffsetAndLength(texture.Width);
|
||||
var (offsetY, height) = y.GetOffsetAndLength(texture.Height);
|
||||
var (offsetZ, depth) = z.GetOffsetAndLength(texture.Depth);
|
||||
var (offsetX, width) = x.GetOffsetAndLength(source.Width);
|
||||
var (offsetY, height) = y.GetOffsetAndLength(source.Height);
|
||||
var (offsetZ, depth) = z.GetOffsetAndLength(source.Depth);
|
||||
|
||||
texture.CopyTo(destination, offsetX, offsetY, offsetZ, width, height, depth);
|
||||
source.CopyTo(destination, offsetX, offsetY, offsetZ, width, height, depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of the specified range from the current <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="Span{T}"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The input <see cref="Span{T}"/> to write data to.</param>
|
||||
/// <param name="x">The horizontal offset in the source texture.</param>
|
||||
/// <param name="y">The vertical offset in the source texture.</param>
|
||||
/// <param name="z">The depthwise offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetZ">The depthwise offset in the source texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
/// <param name="depth">The depth of the memory area to copy.</param>
|
||||
public static void CopyTo<T>(this Texture3D<T> texture, Span<T> destination, int x, int y, int z, int width, int height, int depth)
|
||||
public static void CopyTo<T>(this Texture3D<T> source, Span<T> destination, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int width, int height, int depth)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyTo(ref MemoryMarshal.GetReference(destination), destination.Length, x, y, z, width, height, depth);
|
||||
source.CopyTo(ref MemoryMarshal.GetReference(destination), destination.Length, sourceOffsetX, sourceOffsetY, sourceOffsetZ, width, height, depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
public static void CopyTo<T>(this Texture3D<T> source, Texture3D<T> destination)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, 0, 0, 0, 0, 0, 0, source.Width, source.Height, source.Depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetZ">The depthwise offset in the source texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
/// <param name="depth">The depth of the memory area to copy.</param>
|
||||
public static void CopyTo<T>(this Texture3D<T> source, Texture3D<T> destination, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int width, int height, int depth)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, sourceOffsetZ, 0, 0, 0, width, height, depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetZ">The depthwise offset in the source texture.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetZ">The depthwise offset in the destination texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
/// <param name="depth">The depth of the memory area to copy.</param>
|
||||
public static void CopyTo<T>(this Texture3D<T> source, Texture3D<T> destination, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, sourceOffsetZ, destinationOffsetX, destinationOffsetY, destinationOffsetZ, width, height, depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="ReadBackTexture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The target <see cref="ReadBackTexture3D{T}"/> instance to write data to.</param>
|
||||
public static void CopyTo<T>(this Texture3D<T> texture, ReadBackTexture3D<T> destination)
|
||||
public static void CopyTo<T>(this Texture3D<T> source, ReadBackTexture3D<T> destination)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyTo(destination, 0, 0, 0, 0, 0, 0, texture.Width, texture.Height, texture.Depth);
|
||||
source.CopyTo(destination, 0, 0, 0, 0, 0, 0, source.Width, source.Height, source.Depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="ReadBackTexture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The target <see cref="ReadBackTexture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="x">The horizontal offset in the source texture.</param>
|
||||
/// <param name="y">The vertical offset in the source texture.</param>
|
||||
/// <param name="z">The depthwise offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetZ">The depthwise offset in the source texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
/// <param name="depth">The depth of the memory area to copy.</param>
|
||||
public static void CopyTo<T>(this Texture3D<T> texture, ReadBackTexture3D<T> destination, int x, int y, int z, int width, int height, int depth)
|
||||
public static void CopyTo<T>(this Texture3D<T> source, ReadBackTexture3D<T> destination, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int width, int height, int depth)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyTo(destination, 0, 0, 0, x, y, z, width, height, depth);
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, sourceOffsetZ, 0, 0, 0, width, height, depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="ReadBackTexture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The target <see cref="ReadBackTexture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetZ">The depthwise offset in the source texture.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetZ">The depthwise offset in the destination texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
/// <param name="depth">The depth of the memory area to copy.</param>
|
||||
public static void CopyTo<T>(this Texture3D<T> source, ReadBackTexture3D<T> destination, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, sourceOffsetZ, destinationOffsetX, destinationOffsetY, destinationOffsetZ, width, height, depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the contents of a given <typeparamref name="T"/> array to the current <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <typeparamref name="T"/> array to read data from.</param>
|
||||
/// <remarks>
|
||||
/// The source 3D array needs to have each 2D plane stacked on the depth axis. That is, the expected
|
||||
/// layout of the input array has to be of shape [depth, height, width].
|
||||
/// </remarks>
|
||||
public static void CopyFrom<T>(this Texture3D<T> texture, T[,,] source)
|
||||
public static void CopyFrom<T>(this Texture3D<T> destination, T[,,] source)
|
||||
where T : unmanaged
|
||||
{
|
||||
Guard.IsEqualTo(source.GetLength(0), texture.Depth, nameof(source));
|
||||
Guard.IsEqualTo(source.GetLength(1), texture.Height, nameof(source));
|
||||
Guard.IsEqualTo(source.GetLength(2), texture.Width, nameof(source));
|
||||
Guard.IsEqualTo(source.GetLength(0), destination.Depth, nameof(source));
|
||||
Guard.IsEqualTo(source.GetLength(1), destination.Height, nameof(source));
|
||||
Guard.IsEqualTo(source.GetLength(2), destination.Width, nameof(source));
|
||||
|
||||
texture.CopyFrom(ref source[0, 0, 0], source.Length, 0, 0, 0, texture.Width, texture.Height, texture.Depth);
|
||||
destination.CopyFrom(ref source[0, 0, 0], source.Length, 0, 0, 0, destination.Width, destination.Height, destination.Depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the contents of a given <typeparamref name="T"/> array to the current <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="destination">The target <see cref="Texture3D{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 Texture3D<T> texture, T[] source)
|
||||
public static void CopyFrom<T>(this Texture3D<T> destination, T[] source)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyFrom(source.AsSpan(), 0, 0, 0, texture.Width, texture.Height, texture.Depth);
|
||||
destination.CopyFrom(source.AsSpan(), 0, 0, 0, destination.Width, destination.Height, destination.Depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the contents of a given <typeparamref name="T"/> array to a specified area of the current <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <typeparamref name="T"/> array to read data from.</param>
|
||||
/// <param name="x">The horizontal range of items to write.</param>
|
||||
/// <param name="y">The vertical range of items to write.</param>
|
||||
/// <param name="z">The depthwise range of items to write.</param>
|
||||
public static void CopyFrom<T>(this Texture3D<T> texture, T[] source, Range x, Range y, Range z)
|
||||
public static void CopyFrom<T>(this Texture3D<T> destination, T[] source, Range x, Range y, Range z)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyFrom(source.AsSpan(), x, y, z);
|
||||
destination.CopyFrom(source.AsSpan(), x, y, z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the contents of a given <typeparamref name="T"/> array to a specified area of the current <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <typeparamref name="T"/> array to read data from.</param>
|
||||
/// <param name="x">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="y">The vertical offset in the destination texture.</param>
|
||||
/// <param name="z">The depthwise offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetZ">The depthwise offset in the destination texture.</param>
|
||||
/// <param name="width">The width of the memory area to write to.</param>
|
||||
/// <param name="height">The height of the memory area to write to.</param>
|
||||
/// <param name="depth">The depth of the memory area to write to.</param>
|
||||
public static void CopyFrom<T>(this Texture3D<T> texture, T[] source, int x, int y, int z, int width, int height, int depth)
|
||||
public static void CopyFrom<T>(this Texture3D<T> destination, T[] source, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyFrom(source.AsSpan(), x, y, z, width, height, depth);
|
||||
destination.CopyFrom(source.AsSpan(), destinationOffsetX, destinationOffsetY, destinationOffsetZ, width, height, depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the contents of a given <typeparamref name="T"/> array to a specified area of the current <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <typeparamref name="T"/> array to read data from.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="source"/> to read data from.</param>
|
||||
/// <param name="sourceOffset">The starting offset within <paramref name="source"/> to read data from.</param>
|
||||
/// <param name="x">The horizontal range of items to write.</param>
|
||||
/// <param name="y">The vertical range of items to write.</param>
|
||||
/// <param name="z">The depthwise range of items to write.</param>
|
||||
public static void CopyFrom<T>(this Texture3D<T> texture, T[] source, int offset, Range x, Range y, Range z)
|
||||
public static void CopyFrom<T>(this Texture3D<T> destination, T[] source, int sourceOffset, Range x, Range y, Range z)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyFrom(source.AsSpan(offset), x, y, z);
|
||||
destination.CopyFrom(source.AsSpan(sourceOffset), x, y, z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the contents of a given <typeparamref name="T"/> array to a specified area of the current <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <typeparamref name="T"/> array to read data from.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="source"/> to read data from.</param>
|
||||
/// <param name="x">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="y">The vertical offset in the destination texture.</param>
|
||||
/// <param name="z">The depthwise offset in the destination texture.</param>
|
||||
/// <param name="sourceOffset">The starting offset within <paramref name="source"/> to read data from.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetZ">The depthwise offset in the destination texture.</param>
|
||||
/// <param name="width">The width of the memory area to write to.</param>
|
||||
/// <param name="height">The height of the memory area to write to.</param>
|
||||
/// <param name="depth">The depth of the memory area to write to.</param>
|
||||
public static void CopyFrom<T>(this Texture3D<T> texture, T[] source, int offset, int x, int y, int z, int width, int height, int depth)
|
||||
public static void CopyFrom<T>(this Texture3D<T> destination, T[] source, int sourceOffset, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyFrom(source.AsSpan(offset), x, y, z, width, height, depth);
|
||||
destination.CopyFrom(source.AsSpan(sourceOffset), destinationOffsetX, destinationOffsetY, destinationOffsetZ, width, height, depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -285,48 +386,150 @@ public static class Texture3DExtensions
|
||||
/// The input data will be written to the start of the texture, and all input items will be copied.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="destination">The target <see cref="Texture3D{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 Texture3D<T> texture, ReadOnlySpan<T> source)
|
||||
public static void CopyFrom<T>(this Texture3D<T> destination, ReadOnlySpan<T> source)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyFrom(source, 0, 0, 0, texture.Width, texture.Height, texture.Depth);
|
||||
destination.CopyFrom(source, 0, 0, 0, destination.Width, destination.Height, destination.Depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the contents of a given <see cref="ReadOnlySpan{T}"/> to a specified area of the current <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="ReadOnlySpan{T}"/> to read data from.</param>
|
||||
/// <param name="x">The horizontal range of items to write.</param>
|
||||
/// <param name="y">The vertical range of items to write.</param>
|
||||
/// <param name="z">The depthwise range of items to write.</param>
|
||||
public static void CopyFrom<T>(this Texture3D<T> texture, ReadOnlySpan<T> source, Range x, Range y, Range z)
|
||||
public static void CopyFrom<T>(this Texture3D<T> destination, ReadOnlySpan<T> source, Range x, Range y, Range z)
|
||||
where T : unmanaged
|
||||
{
|
||||
var (offsetX, width) = x.GetOffsetAndLength(texture.Width);
|
||||
var (offsetY, height) = y.GetOffsetAndLength(texture.Height);
|
||||
var (offsetZ, depth) = z.GetOffsetAndLength(texture.Depth);
|
||||
var (offsetX, width) = x.GetOffsetAndLength(destination.Width);
|
||||
var (offsetY, height) = y.GetOffsetAndLength(destination.Height);
|
||||
var (offsetZ, depth) = z.GetOffsetAndLength(destination.Depth);
|
||||
|
||||
texture.CopyFrom(source, offsetX, offsetY, offsetZ, width, height, depth);
|
||||
destination.CopyFrom(source, offsetX, offsetY, offsetZ, width, height, depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the contents of a given <see cref="ReadOnlySpan{T}"/> to a specified area of the current <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="ReadOnlySpan{T}"/> to read data from.</param>
|
||||
/// <param name="x">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="y">The vertical offset in the destination texture.</param>
|
||||
/// <param name="z">The depthwise offseet in the destination texture.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetZ">The depthwise offseet in the destination texture.</param>
|
||||
/// <param name="width">The width of the memory area to write to.</param>
|
||||
/// <param name="height">The height of the memory area to write to.</param>
|
||||
/// <param name="depth">The depth of the memory area to write to.</param>
|
||||
public static void CopyFrom<T>(this Texture3D<T> texture, ReadOnlySpan<T> source, int x, int y, int z, int width, int height, int depth)
|
||||
public static void CopyFrom<T>(this Texture3D<T> destination, ReadOnlySpan<T> source, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.CopyFrom(ref MemoryMarshal.GetReference(source), source.Length, x, y, z, width, height, depth);
|
||||
destination.CopyFrom(ref MemoryMarshal.GetReference(source), source.Length, destinationOffsetX, destinationOffsetY, destinationOffsetZ, width, height, depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
public static void CopyFrom<T>(this Texture3D<T> destination, Texture3D<T> source)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, 0, 0, 0, 0, 0, 0, source.Width, source.Height, source.Depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetZ">The depthwise offset in the source texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
/// <param name="depth">The depth of the memory area to copy.</param>
|
||||
public static void CopyFrom<T>(this Texture3D<T> destination, Texture3D<T> source, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int width, int height, int depth)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, sourceOffsetZ, 0, 0, 0, width, height, depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetZ">The depthwise offset in the source texture.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetZ">The depthwise offset in the destination texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
/// <param name="depth">The depth of the memory area to copy.</param>
|
||||
public static void CopyFrom<T>(this Texture3D<T> destination, Texture3D<T> source, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
|
||||
where T : unmanaged
|
||||
{
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, sourceOffsetZ, destinationOffsetX, destinationOffsetY, destinationOffsetZ, width, height, depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of an <see cref="UploadTexture3D{T}"/> instance and writes them into a target <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="UploadTexture3D{T}"/> instance to read data from.</param>
|
||||
public static void CopyFrom<T>(this Texture3D<T> destination, UploadTexture3D<T> source)
|
||||
where T : unmanaged
|
||||
{
|
||||
destination.CopyFrom(source, 0, 0, 0, 0, 0, 0, source.Width, source.Height, source.Depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of an <see cref="UploadTexture3D{T}"/> instance and writes them into a target <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="UploadTexture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetZ">The depthwise offset in the source texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
/// <param name="depth">The depth of the memory area to copy.</param>
|
||||
public static void CopyFrom<T>(this Texture3D<T> destination, UploadTexture3D<T> source, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int width, int height, int depth)
|
||||
where T : unmanaged
|
||||
{
|
||||
destination.CopyFrom(source, sourceOffsetX, sourceOffsetY, sourceOffsetZ, 0, 0, 0, width, height, depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of an <see cref="UploadTexture3D{T}"/> instance and writes them into a target <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="source">The input <see cref="UploadTexture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetZ">The depthwise offset in the source texture.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetZ">The depthwise offset in the destination texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
/// <param name="depth">The depth of the memory area to copy.</param>
|
||||
public static void CopyFrom<T>(this Texture3D<T> destination, UploadTexture3D<T> source, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
|
||||
where T : unmanaged
|
||||
{
|
||||
destination.CopyFrom(source, sourceOffsetX, sourceOffsetY, sourceOffsetZ, destinationOffsetX, destinationOffsetY, destinationOffsetZ, width, height, depth);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -11,27 +11,45 @@ public static class UploadTexture2DExtensions
|
||||
/// Reads the contents of a <see cref="UploadTexture2D{T}"/> instance and writes them into a target <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="UploadTexture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="source">The input <see cref="UploadTexture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
public static void CopyTo<T>(this UploadTexture2D<T> texture, Texture2D<T> destination)
|
||||
public static void CopyTo<T>(this UploadTexture2D<T> source, Texture2D<T> destination)
|
||||
where T : unmanaged
|
||||
{
|
||||
destination.CopyFrom(texture, 0, 0, 0, 0, texture.Width, texture.Height);
|
||||
destination.CopyFrom(source, 0, 0, 0, 0, source.Width, source.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="UploadTexture2D{T}"/> instance and writes them into a target <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="UploadTexture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="source">The input <see cref="UploadTexture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="x">The horizontal offset in the source texture.</param>
|
||||
/// <param name="y">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
public static void CopyTo<T>(this UploadTexture2D<T> texture, Texture2D<T> destination, int x, int y, int width, int height)
|
||||
public static void CopyTo<T>(this UploadTexture2D<T> source, Texture2D<T> destination, int sourceOffsetX, int sourceOffsetY, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
destination.CopyFrom(texture, x, y, 0, 0, width, height);
|
||||
destination.CopyFrom(source, sourceOffsetX, sourceOffsetY, 0, 0, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="UploadTexture2D{T}"/> instance and writes them into a target <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="source">The input <see cref="UploadTexture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
public static void CopyTo<T>(this UploadTexture2D<T> source, Texture2D<T> destination, int sourceOffsetX, int sourceOffsetY, int destinationOffsetX, int destinationOffsetY, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
destination.CopyFrom(source, sourceOffsetX, sourceOffsetY, destinationOffsetX, destinationOffsetY, width, height);
|
||||
}
|
||||
}
|
||||
@@ -11,29 +11,50 @@ public static class UploadTexture3DExtensions
|
||||
/// Reads the contents of a <see cref="UploadTexture3D{T}"/> instance and writes them into a target <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="UploadTexture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="source">The input <see cref="UploadTexture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
public static void CopyTo<T>(this UploadTexture3D<T> texture, Texture3D<T> destination)
|
||||
public static void CopyTo<T>(this UploadTexture3D<T> source, Texture3D<T> destination)
|
||||
where T : unmanaged
|
||||
{
|
||||
destination.CopyFrom(texture, 0, 0, 0, 0, 0, 0, texture.Width, texture.Height, texture.Depth);
|
||||
destination.CopyFrom(source, 0, 0, 0, 0, 0, 0, source.Width, source.Height, source.Depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="UploadTexture3D{T}"/> instance and writes them into a target <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="UploadTexture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="source">The input <see cref="UploadTexture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="x">The horizontal offset in the source texture.</param>
|
||||
/// <param name="y">The vertical offset in the source texture.</param>
|
||||
/// <param name="z">The depthwise offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetZ">The depthwise offset in the source texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
/// <param name="depth">The depth of the memory area to copy.</param>
|
||||
public static void CopyTo<T>(this UploadTexture3D<T> texture, Texture3D<T> destination, int x, int y, int z, int width, int height, int depth)
|
||||
public static void CopyTo<T>(this UploadTexture3D<T> source, Texture3D<T> destination, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int width, int height, int depth)
|
||||
where T : unmanaged
|
||||
{
|
||||
destination.CopyFrom(texture, x, y, z, 0, 0, 0, width, height, depth);
|
||||
destination.CopyFrom(source, sourceOffsetX, sourceOffsetY, sourceOffsetZ, 0, 0, 0, width, height, depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of a <see cref="UploadTexture3D{T}"/> instance and writes them into a target <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="source">The input <see cref="UploadTexture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetZ">The depthwise offset in the source texture.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetZ">The depthwise offset in the destination texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
/// <param name="depth">The depth of the memory area to copy.</param>
|
||||
public static void CopyTo<T>(this UploadTexture3D<T> source, Texture3D<T> destination, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
|
||||
where T : unmanaged
|
||||
{
|
||||
destination.CopyFrom(source, sourceOffsetX, sourceOffsetY, sourceOffsetZ, destinationOffsetX, destinationOffsetY, destinationOffsetZ, width, height, depth);
|
||||
}
|
||||
}
|
||||
@@ -9,87 +9,109 @@ namespace ComputeSharp.Graphics.Helpers;
|
||||
internal static class MemoryHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Copies the content of a source memory area to a target one, accounting for padding.
|
||||
/// The destination memory area has padding for each element, while the source does not.
|
||||
/// Copies the content of a source memory area to a target one, accounting for padding if present.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of elements being copied.</typeparam>
|
||||
/// <param name="source">The source memory area to read from.</param>
|
||||
/// <param name="destination">The pointer for the destination memory area.</param>
|
||||
/// <param name="offset">The destination offset to start writing data to.</param>
|
||||
/// <param name="length">The number of items to copy.</param>
|
||||
/// <param name="elementPitchInBytes">The padded size of each element.</param>
|
||||
/// <param name="isPaddingInSourceToo">Indicates whether or not the source is padded too.</param>
|
||||
/// <param name="sourceElementOffset">The source offset to start reading data from.</param>
|
||||
/// <param name="destinationElementOffset">The destination offset to start writing data to.</param>
|
||||
/// <param name="sourceElementPitchInBytes">The padded size of each element in <paramref name="source"/>.</param>
|
||||
/// <param name="destinationElementPitchInBytes">The padded size of each element in <paramref name="destination"/>.</param>
|
||||
/// <param name="count">The number of items to copy from <paramref name="source"/> to <paramref name="destination"/>.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void Copy<T>(
|
||||
void* source,
|
||||
void* destination,
|
||||
uint offset,
|
||||
uint length,
|
||||
uint elementPitchInBytes,
|
||||
bool isPaddingInSourceToo)
|
||||
uint sourceElementOffset,
|
||||
uint destinationElementOffset,
|
||||
uint sourceElementPitchInBytes,
|
||||
uint destinationElementPitchInBytes,
|
||||
uint count)
|
||||
where T : unmanaged
|
||||
{
|
||||
destination = (byte*)destination + offset * elementPitchInBytes;
|
||||
// Offset adjustment
|
||||
source = (byte*)source + sourceElementOffset * sourceElementPitchInBytes;
|
||||
destination = (byte*)destination + destinationElementOffset * destinationElementPitchInBytes;
|
||||
|
||||
if (isPaddingInSourceToo)
|
||||
if (sourceElementPitchInBytes == (uint)sizeof(T))
|
||||
{
|
||||
for (int i = 0; i < length; i++)
|
||||
if (destinationElementPitchInBytes == (uint)sizeof(T))
|
||||
{
|
||||
*(T*)&((byte*)destination)[i * elementPitchInBytes] = *(T*)&((byte*)source)[i * elementPitchInBytes];
|
||||
// Neither source nor destination have padding
|
||||
Buffer.MemoryCopy(
|
||||
source: source,
|
||||
destination: destination,
|
||||
destinationSizeInBytes: ulong.MaxValue,
|
||||
sourceBytesToCopy: count * (uint)sizeof(T));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Source has no padding, destination does
|
||||
static void Copy(
|
||||
void* source,
|
||||
void* destination,
|
||||
uint destinationElementPitchInBytes,
|
||||
uint count)
|
||||
{
|
||||
void* sourceEnd = (byte*)source + count * sizeof(T);
|
||||
|
||||
while (source < sourceEnd)
|
||||
{
|
||||
*(T*)destination = *(T*)source;
|
||||
|
||||
source = (byte*)source + sizeof(T);
|
||||
destination = (byte*)destination + destinationElementPitchInBytes;
|
||||
}
|
||||
}
|
||||
|
||||
Copy(source, destination, destinationElementPitchInBytes, count);
|
||||
}
|
||||
}
|
||||
else if (destinationElementPitchInBytes == (uint)sizeof(T))
|
||||
{
|
||||
// Source has padding, destination does not
|
||||
static void Copy(
|
||||
void* source,
|
||||
void* destination,
|
||||
uint sourceElementPitchInBytes,
|
||||
uint count)
|
||||
{
|
||||
void* sourceEnd = (byte*)source + count * sourceElementPitchInBytes;
|
||||
|
||||
while (source < sourceEnd)
|
||||
{
|
||||
*(T*)destination = *(T*)source;
|
||||
|
||||
source = (byte*)source + sourceElementPitchInBytes;
|
||||
destination = (byte*)destination + sizeof(T);
|
||||
}
|
||||
}
|
||||
|
||||
Copy(source, destination, sourceElementPitchInBytes, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < length; i++)
|
||||
// Both source and destination have padding
|
||||
static void Copy(
|
||||
void* source,
|
||||
void* destination,
|
||||
uint sourceElementPitchInBytes,
|
||||
uint destinationElementPitchInBytes,
|
||||
uint count)
|
||||
{
|
||||
*(T*)&((byte*)destination)[i * elementPitchInBytes] = ((T*)source)[i];
|
||||
void* sourceEnd = (byte*)source + count * sourceElementPitchInBytes;
|
||||
|
||||
while (source < sourceEnd)
|
||||
{
|
||||
*(T*)destination = *(T*)source;
|
||||
|
||||
source = (byte*)source + sourceElementPitchInBytes;
|
||||
destination = (byte*)destination + destinationElementPitchInBytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies the content of a source memory area to a target one.
|
||||
/// </summary>
|
||||
/// <param name="source">The source memory area to read from.</param>
|
||||
/// <param name="offset">The source offset to start reading data from.</param>
|
||||
/// <param name="length">The number of items to copy.</param>
|
||||
/// <param name="elementSizeInBytes">The size in bytes of each item to copy.</param>
|
||||
/// <param name="destination">The pointer for the destination memory area.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void Copy(
|
||||
void* source,
|
||||
uint offset,
|
||||
uint length,
|
||||
uint elementSizeInBytes,
|
||||
void* destination)
|
||||
{
|
||||
Buffer.MemoryCopy(
|
||||
(byte*)source + offset * elementSizeInBytes,
|
||||
destination,
|
||||
ulong.MaxValue,
|
||||
elementSizeInBytes * length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies the content of a source memory area to a target one, accounting for padding.
|
||||
/// The source memory area has padding for each element, while the destination does not.
|
||||
/// </summary>
|
||||
/// <param name="source">The source memory area to read from.</param>
|
||||
/// <param name="offset">The source offset to start reading data from.</param>
|
||||
/// <param name="length">The number of items to copy.</param>
|
||||
/// <param name="elementPitchInBytes">The padded size of each element.</param>
|
||||
/// <param name="destination">The pointer for the destination memory area.</param>
|
||||
public static unsafe void Copy<T>(
|
||||
void* source,
|
||||
uint offset,
|
||||
uint length,
|
||||
uint elementPitchInBytes,
|
||||
void* destination)
|
||||
where T : unmanaged
|
||||
{
|
||||
source = (byte*)source + offset * elementPitchInBytes;
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
((T*)destination)[i] = *(T*)&((byte*)source)[i * elementPitchInBytes];
|
||||
Copy(source, destination, sourceElementPitchInBytes, destinationElementPitchInBytes, count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Buffers;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.Core.Helpers;
|
||||
using ComputeSharp.Exceptions;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
@@ -72,11 +73,14 @@ public unsafe abstract class Buffer<T> : NativeObject
|
||||
UnsupportedDoubleOperationsException.Throw<T>();
|
||||
}
|
||||
|
||||
SizeInBytes = checked((nint)(length * elementSizeInBytes));
|
||||
nint usableSizeInBytes = checked((nint)(length * elementSizeInBytes));
|
||||
nint effectiveSizeInBytes = resourceType == ResourceType.Constant ? AlignmentHelper.Pad(usableSizeInBytes, Windows.D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT) : usableSizeInBytes;
|
||||
|
||||
SizeInBytes = usableSizeInBytes;
|
||||
GraphicsDevice = device;
|
||||
Length = length;
|
||||
|
||||
this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, (ulong)SizeInBytes);
|
||||
this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, (ulong)effectiveSizeInBytes);
|
||||
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
|
||||
|
||||
device.RegisterAllocatedResource();
|
||||
@@ -85,7 +89,7 @@ public unsafe abstract class Buffer<T> : NativeObject
|
||||
switch (resourceType)
|
||||
{
|
||||
case ResourceType.Constant:
|
||||
device.D3D12Device->CreateConstantBufferView(this.d3D12Resource.Get(), SizeInBytes, D3D12CpuDescriptorHandle);
|
||||
device.D3D12Device->CreateConstantBufferView(this.d3D12Resource.Get(), effectiveSizeInBytes, D3D12CpuDescriptorHandle);
|
||||
break;
|
||||
case ResourceType.ReadOnly:
|
||||
device.D3D12Device->CreateShaderResourceView(this.d3D12Resource.Get(), (uint)length, elementSizeInBytes, D3D12CpuDescriptorHandle);
|
||||
@@ -126,39 +130,37 @@ 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 memory area to a specified area of the current <see cref="Buffer{T}"/> instance.
|
||||
/// 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.
|
||||
/// </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="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>
|
||||
internal abstract void CopyTo(Buffer<T> destination, int sourceOffset, int destinationOffset, int count);
|
||||
|
||||
/// <summary>
|
||||
/// Writes the contents of a given <see cref="Buffer{T}"/> to the current <see cref="Buffer{T}"/> instance.
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="source">The input <see cref="Buffer{T}"/> to read data from.</param>
|
||||
public abstract void CopyFrom(Buffer<T> source);
|
||||
|
||||
/// <summary>
|
||||
/// Writes the contents of a given <see cref="Buffer{T}"/> to the current <see cref="Buffer{T}"/> instance, using a temporary CPU buffer.
|
||||
/// </summary>
|
||||
/// <param name="source">The input <see cref="Buffer{T}"/> to read data from.</param>
|
||||
protected void CopyFromWithCpuBuffer(Buffer<T> source)
|
||||
/// <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>
|
||||
protected void CopyToWithCpuBuffer(Buffer<T> destination, int sourceOffset, int destinationOffset, int count)
|
||||
{
|
||||
T[] array = ArrayPool<T>.Shared.Rent(source.Length);
|
||||
T[] array = ArrayPool<T>.Shared.Rent(count);
|
||||
|
||||
try
|
||||
{
|
||||
ref T r0 = ref MemoryMarshal.GetArrayDataReference(array);
|
||||
|
||||
source.CopyTo(ref r0, source.Length, 0);
|
||||
CopyTo(ref r0, sourceOffset, count);
|
||||
|
||||
CopyFrom(ref r0, source.Length, 0);
|
||||
destination.CopyFrom(ref r0, destinationOffset, count);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -166,6 +168,14 @@ public unsafe abstract class Buffer<T> : NativeObject
|
||||
}
|
||||
}
|
||||
|
||||
/// <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="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()
|
||||
{
|
||||
|
||||
@@ -30,14 +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.IsInRange(offset, 0, Length, nameof(offset));
|
||||
Guard.IsLessThanOrEqualTo(offset + length, Length, nameof(length));
|
||||
Guard.IsBetweenOrEqualTo(count, 0, Length, nameof(count));
|
||||
Guard.IsInRange(sourceOffset, 0, Length, nameof(sourceOffset));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffset + count, Length, nameof(sourceOffset));
|
||||
|
||||
if (GraphicsDevice.IsCacheCoherentUMA)
|
||||
{
|
||||
@@ -45,18 +46,20 @@ public abstract class StructuredBuffer<T> : Buffer<T>
|
||||
|
||||
fixed (void* destinationPointer = &destination)
|
||||
{
|
||||
MemoryHelper.Copy(
|
||||
resource.Pointer,
|
||||
(uint)offset,
|
||||
(uint)length,
|
||||
(uint)sizeof(T),
|
||||
destinationPointer);
|
||||
MemoryHelper.Copy<T>(
|
||||
source: resource.Pointer,
|
||||
destination: destinationPointer,
|
||||
sourceElementOffset: (uint)sourceOffset,
|
||||
destinationElementOffset: 0,
|
||||
sourceElementPitchInBytes: (uint)sizeof(T),
|
||||
destinationElementPitchInBytes: (uint)sizeof(T),
|
||||
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);
|
||||
|
||||
@@ -70,24 +73,20 @@ public abstract class StructuredBuffer<T> : Buffer<T>
|
||||
|
||||
fixed (void* destinationPointer = &destination)
|
||||
{
|
||||
MemoryHelper.Copy(
|
||||
resource.Pointer,
|
||||
0u,
|
||||
(uint)length,
|
||||
(uint)sizeof(T),
|
||||
destinationPointer);
|
||||
MemoryHelper.Copy<T>(
|
||||
source: resource.Pointer,
|
||||
destination: destinationPointer,
|
||||
sourceElementOffset: 0,
|
||||
destinationElementOffset: 0,
|
||||
sourceElementPitchInBytes: (uint)sizeof(T),
|
||||
destinationElementPitchInBytes: (uint)sizeof(T),
|
||||
count: (uint)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="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)
|
||||
/// <inheritdoc/>
|
||||
internal override unsafe void CopyTo(Buffer<T> destination, int sourceOffset, int destinationOffset, int count)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
|
||||
@@ -96,27 +95,75 @@ 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 (!destination.IsPaddingPresent)
|
||||
{
|
||||
nint sourceByteOffset = (nint)sourceOffset * sizeof(T);
|
||||
nint destinationByteOffset = (nint)destinationOffset * sizeof(T);
|
||||
nint byteLength = count * sizeof(T);
|
||||
|
||||
// Directly copy the input buffer
|
||||
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
|
||||
|
||||
copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(
|
||||
destination.D3D12Resource,
|
||||
(ulong)destinationByteOffset,
|
||||
D3D12Resource,
|
||||
(ulong)sourceByteOffset,
|
||||
(ulong)byteLength);
|
||||
|
||||
copyCommandList.ExecuteAndWaitForCompletion();
|
||||
}
|
||||
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="count">The number of items to read.</param>
|
||||
internal unsafe void CopyTo(ReadBackBuffer<T> destination, int sourceOffset, int destinationOffset, int count)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
destination.ThrowIfDeviceMismatch(GraphicsDevice);
|
||||
destination.ThrowIfDisposed();
|
||||
|
||||
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 + count, destination.Length, nameof(destinationOffset));
|
||||
|
||||
if (GraphicsDevice.IsCacheCoherentUMA)
|
||||
{
|
||||
using ID3D12ResourceMap resource = D3D12Resource->Map();
|
||||
|
||||
MemoryHelper.Copy(
|
||||
resource.Pointer,
|
||||
(uint)offset,
|
||||
(uint)length,
|
||||
(uint)sizeof(T),
|
||||
destination.MappedData + destinationOffset);
|
||||
MemoryHelper.Copy<T>(
|
||||
source: resource.Pointer,
|
||||
destination: destination.MappedData,
|
||||
sourceElementOffset: (uint)sourceOffset,
|
||||
destinationElementOffset: (uint)destinationOffset,
|
||||
sourceElementPitchInBytes: (uint)sizeof(T),
|
||||
destinationElementPitchInBytes: (uint)sizeof(T),
|
||||
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);
|
||||
|
||||
@@ -126,14 +173,15 @@ 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();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
Guard.IsBetweenOrEqualTo(length, 0, Length, nameof(length));
|
||||
Guard.IsInRange(offset, 0, Length, nameof(offset));
|
||||
Guard.IsLessThanOrEqualTo(offset + length, Length, nameof(length));
|
||||
Guard.IsLessThanOrEqualTo(offset + length, Length, nameof(offset));
|
||||
|
||||
if (GraphicsDevice.IsCacheCoherentUMA)
|
||||
{
|
||||
@@ -141,12 +189,14 @@ public abstract class StructuredBuffer<T> : Buffer<T>
|
||||
|
||||
fixed (void* sourcePointer = &source)
|
||||
{
|
||||
MemoryHelper.Copy(
|
||||
sourcePointer,
|
||||
(uint)offset,
|
||||
(uint)length,
|
||||
(uint)sizeof(T),
|
||||
resource.Pointer);
|
||||
MemoryHelper.Copy<T>(
|
||||
source: sourcePointer,
|
||||
destination: resource.Pointer,
|
||||
sourceElementOffset: 0,
|
||||
destinationElementOffset: (uint)offset,
|
||||
sourceElementPitchInBytes: (uint)sizeof(T),
|
||||
destinationElementPitchInBytes: (uint)sizeof(T),
|
||||
count: (uint)length);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -159,12 +209,14 @@ public abstract class StructuredBuffer<T> : Buffer<T>
|
||||
using (ID3D12ResourceMap resource = allocation.Get()->GetResource()->Map())
|
||||
fixed (void* sourcePointer = &source)
|
||||
{
|
||||
MemoryHelper.Copy(
|
||||
sourcePointer,
|
||||
0u,
|
||||
(uint)length,
|
||||
(uint)sizeof(T),
|
||||
resource.Pointer);
|
||||
MemoryHelper.Copy<T>(
|
||||
source: sourcePointer,
|
||||
destination: resource.Pointer,
|
||||
sourceElementOffset: 0,
|
||||
destinationElementOffset: 0,
|
||||
sourceElementPitchInBytes: (uint)sizeof(T),
|
||||
destinationElementPitchInBytes: (uint)sizeof(T),
|
||||
count: (uint)length);
|
||||
}
|
||||
|
||||
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
|
||||
@@ -179,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();
|
||||
|
||||
@@ -190,27 +242,31 @@ 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)
|
||||
{
|
||||
using ID3D12ResourceMap resource = D3D12Resource->Map();
|
||||
|
||||
MemoryHelper.Copy(
|
||||
source.MappedData,
|
||||
(uint)sourceOffset,
|
||||
(uint)length,
|
||||
(uint)sizeof(T),
|
||||
(T*)resource.Pointer + offset);
|
||||
MemoryHelper.Copy<T>(
|
||||
source: source.MappedData,
|
||||
destination: resource.Pointer,
|
||||
sourceElementOffset: (uint)sourceOffset,
|
||||
destinationElementOffset: (uint)destinationOffset,
|
||||
sourceElementPitchInBytes: (uint)sizeof(T),
|
||||
destinationElementPitchInBytes: (uint)sizeof(T),
|
||||
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);
|
||||
|
||||
@@ -218,27 +274,4 @@ public abstract class StructuredBuffer<T> : Buffer<T>
|
||||
copyCommandList.ExecuteAndWaitForCompletion();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override unsafe void CopyFrom(Buffer<T> source)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
source.ThrowIfDeviceMismatch(GraphicsDevice);
|
||||
source.ThrowIfDisposed();
|
||||
|
||||
Guard.IsLessThanOrEqualTo(source.Length, Length, nameof(Length));
|
||||
|
||||
if (!source.IsPaddingPresent)
|
||||
{
|
||||
// Directly copy the input buffer
|
||||
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
|
||||
|
||||
copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(D3D12Resource, 0, source.D3D12Resource, 0,(ulong)SizeInBytes);
|
||||
copyCommandList.ExecuteAndWaitForCompletion();
|
||||
}
|
||||
else CopyFromWithCpuBuffer(source);
|
||||
}
|
||||
}
|
||||
@@ -147,22 +147,22 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
|
||||
/// </summary>
|
||||
/// <param name="destination">The target memory area to write data to.</param>
|
||||
/// <param name="size">The size of the target memory area to write data to.</param>
|
||||
/// <param name="x">The horizontal offset in the source texture.</param>
|
||||
/// <param name="y">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
internal void CopyTo(ref T destination, int size, int x, int y, int width, int height)
|
||||
internal void CopyTo(ref T destination, int size, int sourceOffsetX, int sourceOffsetY, int width, int height)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
Guard.IsInRange(x, 0, Width, nameof(x));
|
||||
Guard.IsInRange(y, 0, Height, nameof(y));
|
||||
Guard.IsInRange(sourceOffsetX, 0, Width, nameof(sourceOffsetX));
|
||||
Guard.IsInRange(sourceOffsetY, 0, Height, nameof(sourceOffsetY));
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width, nameof(width));
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height, nameof(height));
|
||||
Guard.IsLessThanOrEqualTo(x + width, Width, nameof(x));
|
||||
Guard.IsLessThanOrEqualTo(y + height, Height, nameof(y));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, Width, nameof(sourceOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, Height, nameof(sourceOffsetY));
|
||||
Guard.IsGreaterThanOrEqualTo(size, (nint)width * height, nameof(size));
|
||||
|
||||
GraphicsDevice.D3D12Device->GetCopyableFootprint(
|
||||
@@ -195,8 +195,8 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
|
||||
destinationY: 0,
|
||||
destinationZ: 0,
|
||||
d3D12ResourceSource: D3D12Resource,
|
||||
sourceX: (uint)x,
|
||||
sourceY: (uint)y,
|
||||
sourceX: (uint)sourceOffsetX,
|
||||
sourceY: (uint)sourceOffsetY,
|
||||
sourceZ: 0,
|
||||
(uint)width,
|
||||
(uint)height,
|
||||
@@ -224,16 +224,16 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of the specified range from the current <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="ReadBackTexture2D{T}"/> instance.
|
||||
/// Reads the contents of the specified range from the current <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="destination">The target <see cref="ReadBackTexture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="destinationX">The horizontal offset within <paramref name="destination"/>.</param>
|
||||
/// <param name="destinationY">The vertical offset within <paramref name="destination"/>.</param>
|
||||
/// <param name="sourceX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceY">The vertical offset in the source texture.</param>
|
||||
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset within <paramref name="destination"/>.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset within <paramref name="destination"/>.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
internal void CopyTo(ReadBackTexture2D<T> destination, int destinationX, int destinationY, int sourceX, int sourceY, int width, int height)
|
||||
internal void CopyTo(Texture2D<T> destination, int sourceOffsetX, int sourceOffsetY, int destinationOffsetX, int destinationOffsetY, int width, int height)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
|
||||
@@ -242,18 +242,86 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
|
||||
destination.ThrowIfDeviceMismatch(GraphicsDevice);
|
||||
destination.ThrowIfDisposed();
|
||||
|
||||
Guard.IsInRange(destinationX, 0, destination.Width, nameof(destinationX));
|
||||
Guard.IsInRange(destinationY, 0, destination.Height, nameof(destinationY));
|
||||
Guard.IsInRange(sourceX, 0, Width, nameof(sourceX));
|
||||
Guard.IsInRange(sourceY, 0, Height, nameof(sourceY));
|
||||
Guard.IsInRange(sourceOffsetX, 0, Width, nameof(sourceOffsetX));
|
||||
Guard.IsInRange(sourceOffsetY, 0, Height, nameof(sourceOffsetY));
|
||||
Guard.IsInRange(destinationOffsetX, 0, destination.Width, nameof(destinationOffsetX));
|
||||
Guard.IsInRange(destinationOffsetY, 0, destination.Height, nameof(destinationOffsetY));
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width, nameof(width));
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height, nameof(height));
|
||||
Guard.IsBetweenOrEqualTo(width, 1, destination.Width, nameof(width));
|
||||
Guard.IsBetweenOrEqualTo(height, 1, destination.Height, nameof(height));
|
||||
Guard.IsBetweenOrEqualTo(destinationX + width, 1, destination.Width, nameof(destinationX));
|
||||
Guard.IsBetweenOrEqualTo(destinationY + height, 1, destination.Height, nameof(destinationY));
|
||||
Guard.IsLessThanOrEqualTo(sourceX + width, Width, nameof(sourceX));
|
||||
Guard.IsLessThanOrEqualTo(sourceY + height, Height, nameof(sourceY));
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetX + width, 1, destination.Width, nameof(destinationOffsetX));
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetY + height, 1, destination.Height, nameof(destinationOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, Width, nameof(sourceOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, Height, nameof(sourceOffsetY));
|
||||
|
||||
D3D12_COMMAND_LIST_TYPE d3D12CommandListType =
|
||||
this.d3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE ||
|
||||
destination.d3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE
|
||||
? D3D12_COMMAND_LIST_TYPE_COMPUTE
|
||||
: D3D12_COMMAND_LIST_TYPE_COPY;
|
||||
|
||||
using CommandList copyCommandList = new(GraphicsDevice, d3D12CommandListType);
|
||||
|
||||
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
|
||||
{
|
||||
copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE);
|
||||
copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(destination.D3D12Resource, destination.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST);
|
||||
}
|
||||
|
||||
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
|
||||
d3D12ResourceDestination: destination.D3D12Resource,
|
||||
(uint)destinationOffsetX,
|
||||
(uint)destinationOffsetY,
|
||||
destinationZ: 0,
|
||||
d3D12ResourceSource: D3D12Resource,
|
||||
(uint)sourceOffsetX,
|
||||
(uint)sourceOffsetY,
|
||||
sourceZ: 0,
|
||||
(uint)width,
|
||||
(uint)height,
|
||||
1);
|
||||
|
||||
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
|
||||
{
|
||||
copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState);
|
||||
copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(destination.D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, destination.d3D12ResourceState);
|
||||
}
|
||||
|
||||
copyCommandList.ExecuteAndWaitForCompletion();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of the specified range from the current <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="ReadBackTexture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="destination">The target <see cref="ReadBackTexture2D{T}"/> instance to write data to.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset within <paramref name="destination"/>.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset within <paramref name="destination"/>.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
internal void CopyTo(ReadBackTexture2D<T> destination, int sourceOffsetX, int sourceOffsetY, int destinationOffsetX, int destinationOffsetY, int width, int height)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
destination.ThrowIfDeviceMismatch(GraphicsDevice);
|
||||
destination.ThrowIfDisposed();
|
||||
|
||||
Guard.IsInRange(sourceOffsetX, 0, Width, nameof(sourceOffsetX));
|
||||
Guard.IsInRange(sourceOffsetY, 0, Height, nameof(sourceOffsetY));
|
||||
Guard.IsInRange(destinationOffsetX, 0, destination.Width, nameof(destinationOffsetX));
|
||||
Guard.IsInRange(destinationOffsetY, 0, destination.Height, nameof(destinationOffsetY));
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width, nameof(width));
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height, nameof(height));
|
||||
Guard.IsBetweenOrEqualTo(width, 1, destination.Width, nameof(width));
|
||||
Guard.IsBetweenOrEqualTo(height, 1, destination.Height, nameof(height));
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetX + width, 1, destination.Width, nameof(destinationOffsetX));
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetY + height, 1, destination.Height, nameof(destinationOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, Width, nameof(sourceOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, Height, nameof(sourceOffsetY));
|
||||
|
||||
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
|
||||
|
||||
@@ -267,12 +335,12 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
|
||||
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
|
||||
d3D12ResourceDestination: destination.D3D12Resource,
|
||||
d3D12PlacedSubresourceFootprintDestination,
|
||||
(uint)destinationX,
|
||||
(uint)destinationY,
|
||||
(uint)destinationOffsetX,
|
||||
(uint)destinationOffsetY,
|
||||
destinationZ: 0,
|
||||
d3D12ResourceSource: D3D12Resource,
|
||||
(uint)sourceX,
|
||||
(uint)sourceY,
|
||||
(uint)sourceOffsetX,
|
||||
(uint)sourceOffsetY,
|
||||
sourceZ: 0,
|
||||
(uint)width,
|
||||
(uint)height,
|
||||
@@ -292,22 +360,22 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
|
||||
/// </summary>
|
||||
/// <param name="source">The input memory area to read data from.</param>
|
||||
/// <param name="size">The size of the memory area to read data from.</param>
|
||||
/// <param name="x">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="y">The vertical offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
|
||||
/// <param name="width">The width of the memory area to write to.</param>
|
||||
/// <param name="height">The height of the memory area to write to.</param>
|
||||
internal void CopyFrom(ref T source, int size, int x, int y, int width, int height)
|
||||
internal void CopyFrom(ref T source, int size, int destinationOffsetX, int destinationOffsetY, int width, int height)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
Guard.IsInRange(x, 0, Width, nameof(x));
|
||||
Guard.IsInRange(y, 0, Height, nameof(y));
|
||||
Guard.IsInRange(destinationOffsetX, 0, Width, nameof(destinationOffsetX));
|
||||
Guard.IsInRange(destinationOffsetY, 0, Height, nameof(destinationOffsetY));
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width, nameof(width));
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height, nameof(height));
|
||||
Guard.IsLessThanOrEqualTo(x + width, Width, nameof(x));
|
||||
Guard.IsLessThanOrEqualTo(y + height, Height, nameof(y));
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetX + width, Width, nameof(destinationOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetY + height, Height, nameof(destinationOffsetY));
|
||||
Guard.IsGreaterThanOrEqualTo(size, (nint)width * height, nameof(size));
|
||||
|
||||
GraphicsDevice.D3D12Device->GetCopyableFootprint(
|
||||
@@ -346,8 +414,8 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
|
||||
|
||||
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
|
||||
d3D12ResourceDestination: D3D12Resource,
|
||||
destinationX: (uint)x,
|
||||
destinationY: (uint)y,
|
||||
destinationX: (uint)destinationOffsetX,
|
||||
destinationY: (uint)destinationOffsetY,
|
||||
destinationZ: 0,
|
||||
d3D12ResourceSource: d3D12Resource.Get(),
|
||||
&d3D12PlacedSubresourceFootprintSource,
|
||||
@@ -370,13 +438,13 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
|
||||
/// Writes the contents of a given <see cref="UploadTexture2D{T}"/> instance to a specified area of the current <see cref="Texture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="source">The input <see cref="UploadTexture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="sourceX">The horizontal offset within <paramref name="source"/>.</param>
|
||||
/// <param name="sourceY">The vertical offset within <paramref name="source"/>.</param>
|
||||
/// <param name="destinationX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationY">The vertical offset in the destination texture.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset within <paramref name="source"/>.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset within <paramref name="source"/>.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
|
||||
/// <param name="width">The width of the memory area to write to.</param>
|
||||
/// <param name="height">The height of the memory area to write to.</param>
|
||||
internal void CopyFrom(UploadTexture2D<T> source, int sourceX, int sourceY, int destinationX, int destinationY, int width, int height)
|
||||
internal void CopyFrom(UploadTexture2D<T> source, int sourceOffsetX, int sourceOffsetY, int destinationOffsetX, int destinationOffsetY, int width, int height)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
|
||||
@@ -385,18 +453,18 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
|
||||
source.ThrowIfDeviceMismatch(GraphicsDevice);
|
||||
source.ThrowIfDisposed();
|
||||
|
||||
Guard.IsInRange(sourceX, 0, source.Width, nameof(sourceX));
|
||||
Guard.IsInRange(sourceY, 0, source.Height, nameof(sourceY));
|
||||
Guard.IsInRange(destinationX, 0, Width, nameof(destinationX));
|
||||
Guard.IsInRange(destinationY, 0, Height, nameof(destinationY));
|
||||
Guard.IsInRange(sourceOffsetX, 0, source.Width, nameof(sourceOffsetX));
|
||||
Guard.IsInRange(sourceOffsetY, 0, source.Height, nameof(sourceOffsetY));
|
||||
Guard.IsInRange(destinationOffsetX, 0, Width, nameof(destinationOffsetX));
|
||||
Guard.IsInRange(destinationOffsetY, 0, Height, nameof(destinationOffsetY));
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width, nameof(width));
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height, nameof(height));
|
||||
Guard.IsBetweenOrEqualTo(width, 1, source.Width, nameof(width));
|
||||
Guard.IsBetweenOrEqualTo(height, 1, source.Height, nameof(height));
|
||||
Guard.IsLessThanOrEqualTo(sourceX + width, source.Width, nameof(sourceX));
|
||||
Guard.IsLessThanOrEqualTo(sourceY + height, source.Height, nameof(sourceY));
|
||||
Guard.IsLessThanOrEqualTo(destinationX + width, Width, nameof(destinationX));
|
||||
Guard.IsLessThanOrEqualTo(destinationY + height, Height, nameof(destinationY));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, source.Width, nameof(sourceOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, source.Height, nameof(sourceOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetX + width, Width, nameof(destinationOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetY + height, Height, nameof(destinationOffsetY));
|
||||
|
||||
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
|
||||
|
||||
@@ -409,13 +477,13 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
|
||||
{
|
||||
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
|
||||
d3D12ResourceDestination: D3D12Resource,
|
||||
(uint)destinationX,
|
||||
(uint)destinationY,
|
||||
(uint)destinationOffsetX,
|
||||
(uint)destinationOffsetY,
|
||||
destinationZ: 0,
|
||||
d3D12ResourceSource: source.D3D12Resource,
|
||||
d3D12PlacedSubresourceFootprintSource,
|
||||
(uint)sourceX,
|
||||
(uint)sourceY,
|
||||
(uint)sourceOffsetX,
|
||||
(uint)sourceOffsetY,
|
||||
sourceZ: 0,
|
||||
(uint)width,
|
||||
(uint)height,
|
||||
|
||||
@@ -156,27 +156,27 @@ public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper
|
||||
/// </summary>
|
||||
/// <param name="destination">The target memory area to write data to.</param>
|
||||
/// <param name="size">The size of the memory area to write data to.</param>
|
||||
/// <param name="x">The horizontal offset in the source texture.</param>
|
||||
/// <param name="y">The vertical offset in the source texture.</param>
|
||||
/// <param name="z">The depthwise offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetZ">The depthwise offset in the source texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
/// <param name="depth">The depth of the memory area to copy.</param>
|
||||
internal void CopyTo(ref T destination, int size, int x, int y, int z, int width, int height, int depth)
|
||||
internal void CopyTo(ref T destination, int size, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int width, int height, int depth)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
Guard.IsInRange(x, 0, Width, nameof(x));
|
||||
Guard.IsInRange(y, 0, Height, nameof(y));
|
||||
Guard.IsInRange(z, 0, Depth, nameof(z));
|
||||
Guard.IsInRange(sourceOffsetX, 0, Width, nameof(sourceOffsetX));
|
||||
Guard.IsInRange(sourceOffsetY, 0, Height, nameof(sourceOffsetY));
|
||||
Guard.IsInRange(sourceOffsetZ, 0, Depth, nameof(sourceOffsetZ));
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width, nameof(width));
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height, nameof(height));
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, Depth, nameof(depth));
|
||||
Guard.IsLessThanOrEqualTo(x + width, Width, nameof(x));
|
||||
Guard.IsLessThanOrEqualTo(y + height, Height, nameof(y));
|
||||
Guard.IsLessThanOrEqualTo(z + depth, Depth, nameof(z));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, Width, nameof(sourceOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, Height, nameof(sourceOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetZ + depth, Depth, nameof(sourceOffsetZ));
|
||||
Guard.IsGreaterThanOrEqualTo(size, (nint)width * height * depth, nameof(size));
|
||||
|
||||
GraphicsDevice.D3D12Device->GetCopyableFootprint(
|
||||
@@ -210,9 +210,9 @@ public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper
|
||||
destinationY: 0,
|
||||
destinationZ: 0,
|
||||
d3D12ResourceSource: D3D12Resource,
|
||||
sourceX: (uint)x,
|
||||
sourceY: (uint)y,
|
||||
sourceZ: (ushort)z,
|
||||
sourceX: (uint)sourceOffsetX,
|
||||
sourceY: (uint)sourceOffsetY,
|
||||
sourceZ: (ushort)sourceOffsetZ,
|
||||
(uint)width,
|
||||
(uint)height,
|
||||
(ushort)depth);
|
||||
@@ -241,19 +241,19 @@ public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of the specified range from the current <see cref="Texture3D{T}"/> instance and writes them into a <see cref="ReadBackTexture3D{T}"/> instance.
|
||||
/// Reads the contents of the specified range from the current <see cref="Texture3D{T}"/> instance and writes them into a <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="destination">The target <see cref="ReadBackTexture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="destinationX">The horizontal offset within <paramref name="destination"/>.</param>
|
||||
/// <param name="destinationY">The vertical offset within <paramref name="destination"/>.</param>
|
||||
/// <param name="destinationZ">The depthwise offset within <paramref name="destination"/>.</param>
|
||||
/// <param name="sourceX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceY">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceZ">The depthwise offset in the source texture.</param>
|
||||
/// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetZ">The depthwise offset in the source texture.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset within <paramref name="destination"/>.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset within <paramref name="destination"/>.</param>
|
||||
/// <param name="destinationOffsetZ">The depthwise offset within <paramref name="destination"/>.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
/// <param name="depth">The depth of the memory area to copy.</param>
|
||||
internal void CopyTo(ReadBackTexture3D<T> destination, int destinationX, int destinationY, int destinationZ, int sourceX, int sourceY, int sourceZ, int width, int height, int depth)
|
||||
internal void CopyTo(Texture3D<T> destination, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
|
||||
@@ -262,24 +262,101 @@ public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper
|
||||
destination.ThrowIfDeviceMismatch(GraphicsDevice);
|
||||
destination.ThrowIfDisposed();
|
||||
|
||||
Guard.IsInRange(destinationX, 0, destination.Width, nameof(destinationX));
|
||||
Guard.IsInRange(destinationY, 0, destination.Height, nameof(destinationY));
|
||||
Guard.IsInRange(destinationZ, 0, destination.Depth, nameof(destinationZ));
|
||||
Guard.IsInRange(sourceX, 0, Width, nameof(sourceX));
|
||||
Guard.IsInRange(sourceY, 0, Height, nameof(sourceY));
|
||||
Guard.IsInRange(sourceZ, 0, Depth, nameof(sourceZ));
|
||||
Guard.IsInRange(sourceOffsetX, 0, Width, nameof(sourceOffsetX));
|
||||
Guard.IsInRange(sourceOffsetY, 0, Height, nameof(sourceOffsetY));
|
||||
Guard.IsInRange(sourceOffsetZ, 0, Depth, nameof(sourceOffsetZ));
|
||||
Guard.IsInRange(destinationOffsetX, 0, destination.Width, nameof(destinationOffsetX));
|
||||
Guard.IsInRange(destinationOffsetY, 0, destination.Height, nameof(destinationOffsetY));
|
||||
Guard.IsInRange(destinationOffsetZ, 0, destination.Depth, nameof(destinationOffsetZ));
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width, nameof(width));
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height, nameof(height));
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, Depth, nameof(depth));
|
||||
Guard.IsBetweenOrEqualTo(width, 1, destination.Width, nameof(width));
|
||||
Guard.IsBetweenOrEqualTo(height, 1, destination.Height, nameof(height));
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, destination.Depth, nameof(depth));
|
||||
Guard.IsBetweenOrEqualTo(destinationX + width, 1, destination.Width, nameof(destinationX));
|
||||
Guard.IsBetweenOrEqualTo(destinationY + height, 1, destination.Height, nameof(destinationY));
|
||||
Guard.IsBetweenOrEqualTo(destinationZ + depth, 1, destination.Depth, nameof(destinationZ));
|
||||
Guard.IsLessThanOrEqualTo(sourceX + width, Width, nameof(sourceX));
|
||||
Guard.IsLessThanOrEqualTo(sourceY + height, Height, nameof(sourceY));
|
||||
Guard.IsLessThanOrEqualTo(sourceZ + depth, Depth, nameof(sourceZ));
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetX + width, 1, destination.Width, nameof(destinationOffsetX));
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetY + height, 1, destination.Height, nameof(destinationOffsetY));
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetZ + depth, 1, destination.Depth, nameof(destinationOffsetZ));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, Width, nameof(sourceOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, Height, nameof(sourceOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetZ + depth, Depth, nameof(sourceOffsetZ));
|
||||
|
||||
D3D12_COMMAND_LIST_TYPE d3D12CommandListType =
|
||||
this.d3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE ||
|
||||
destination.d3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE
|
||||
? D3D12_COMMAND_LIST_TYPE_COMPUTE
|
||||
: D3D12_COMMAND_LIST_TYPE_COPY;
|
||||
|
||||
using CommandList copyCommandList = new(GraphicsDevice, d3D12CommandListType);
|
||||
|
||||
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
|
||||
{
|
||||
copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE);
|
||||
copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(destination.D3D12Resource, destination.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST);
|
||||
}
|
||||
|
||||
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
|
||||
d3D12ResourceDestination: destination.D3D12Resource,
|
||||
(uint)destinationOffsetX,
|
||||
(uint)destinationOffsetY,
|
||||
(ushort)destinationOffsetZ,
|
||||
d3D12ResourceSource: D3D12Resource,
|
||||
(uint)sourceOffsetX,
|
||||
(uint)sourceOffsetY,
|
||||
(ushort)sourceOffsetZ,
|
||||
(uint)width,
|
||||
(uint)height,
|
||||
(ushort)depth);
|
||||
|
||||
if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
|
||||
{
|
||||
copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState);
|
||||
copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(destination.D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, destination.d3D12ResourceState);
|
||||
}
|
||||
|
||||
copyCommandList.ExecuteAndWaitForCompletion();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of the specified range from the current <see cref="Texture3D{T}"/> instance and writes them into a <see cref="ReadBackTexture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="destination">The target <see cref="ReadBackTexture3D{T}"/> instance to write data to.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
|
||||
/// <param name="sourceOffsetZ">The depthwise offset in the source texture.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset within <paramref name="destination"/>.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset within <paramref name="destination"/>.</param>
|
||||
/// <param name="destinationOffsetZ">The depthwise offset within <paramref name="destination"/>.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
/// <param name="height">The height of the memory area to copy.</param>
|
||||
/// <param name="depth">The depth of the memory area to copy.</param>
|
||||
internal void CopyTo(ReadBackTexture3D<T> destination, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
destination.ThrowIfDeviceMismatch(GraphicsDevice);
|
||||
destination.ThrowIfDisposed();
|
||||
|
||||
Guard.IsInRange(sourceOffsetX, 0, Width, nameof(sourceOffsetX));
|
||||
Guard.IsInRange(sourceOffsetY, 0, Height, nameof(sourceOffsetY));
|
||||
Guard.IsInRange(sourceOffsetZ, 0, Depth, nameof(sourceOffsetZ));
|
||||
Guard.IsInRange(destinationOffsetX, 0, destination.Width, nameof(destinationOffsetX));
|
||||
Guard.IsInRange(destinationOffsetY, 0, destination.Height, nameof(destinationOffsetY));
|
||||
Guard.IsInRange(destinationOffsetZ, 0, destination.Depth, nameof(destinationOffsetZ));
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width, nameof(width));
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height, nameof(height));
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, Depth, nameof(depth));
|
||||
Guard.IsBetweenOrEqualTo(width, 1, destination.Width, nameof(width));
|
||||
Guard.IsBetweenOrEqualTo(height, 1, destination.Height, nameof(height));
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, destination.Depth, nameof(depth));
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetX + width, 1, destination.Width, nameof(destinationOffsetX));
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetY + height, 1, destination.Height, nameof(destinationOffsetY));
|
||||
Guard.IsBetweenOrEqualTo(destinationOffsetZ + depth, 1, destination.Depth, nameof(destinationOffsetZ));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, Width, nameof(sourceOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, Height, nameof(sourceOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetZ + depth, Depth, nameof(sourceOffsetZ));
|
||||
|
||||
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
|
||||
|
||||
@@ -293,13 +370,13 @@ public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper
|
||||
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
|
||||
d3D12ResourceDestination: destination.D3D12Resource,
|
||||
d3D12PlacedSubresourceFootprintDestination,
|
||||
(uint)destinationX,
|
||||
(uint)destinationY,
|
||||
(ushort)destinationZ,
|
||||
(uint)destinationOffsetX,
|
||||
(uint)destinationOffsetY,
|
||||
(ushort)destinationOffsetZ,
|
||||
d3D12ResourceSource: D3D12Resource,
|
||||
(uint)sourceX,
|
||||
(uint)sourceY,
|
||||
(ushort)sourceZ,
|
||||
(uint)sourceOffsetX,
|
||||
(uint)sourceOffsetY,
|
||||
(ushort)sourceOffsetZ,
|
||||
(uint)width,
|
||||
(uint)height,
|
||||
(ushort)depth);
|
||||
@@ -318,27 +395,27 @@ public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper
|
||||
/// </summary>
|
||||
/// <param name="source">The input memory area to read data from.</param>
|
||||
/// <param name="size">The size of the memory area to read data from.</param>
|
||||
/// <param name="x">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="y">The vertical offset in the destination texture.</param>
|
||||
/// <param name="z">The depthwise offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetZ">The depthwise offset in the destination texture.</param>
|
||||
/// <param name="width">The width of the memory area to write to.</param>
|
||||
/// <param name="height">The height of the memory area to write to.</param>
|
||||
/// <param name="depth">The depth of the memory area to write to.</param>
|
||||
internal void CopyFrom(ref T source, int size, int x, int y, int z, int width, int height, int depth)
|
||||
internal void CopyFrom(ref T source, int size, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
Guard.IsInRange(x, 0, Width, nameof(x));
|
||||
Guard.IsInRange(y, 0, Height, nameof(y));
|
||||
Guard.IsInRange(z, 0, Depth, nameof(z));
|
||||
Guard.IsInRange(destinationOffsetX, 0, Width, nameof(destinationOffsetX));
|
||||
Guard.IsInRange(destinationOffsetY, 0, Height, nameof(destinationOffsetY));
|
||||
Guard.IsInRange(destinationOffsetZ, 0, Depth, nameof(destinationOffsetZ));
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width, nameof(width));
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height, nameof(height));
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, Depth, nameof(depth));
|
||||
Guard.IsLessThanOrEqualTo(x + width, Width, nameof(x));
|
||||
Guard.IsLessThanOrEqualTo(y + height, Height, nameof(y));
|
||||
Guard.IsLessThanOrEqualTo(z + depth, Depth, nameof(z));
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetX + width, Width, nameof(destinationOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetY + height, Height, nameof(destinationOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetZ + depth, Depth, nameof(destinationOffsetZ));
|
||||
Guard.IsGreaterThanOrEqualTo(size, (nint)width * height * depth, nameof(size));
|
||||
|
||||
GraphicsDevice.D3D12Device->GetCopyableFootprint(
|
||||
@@ -380,9 +457,9 @@ public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper
|
||||
|
||||
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
|
||||
d3D12ResourceDestination: D3D12Resource,
|
||||
destinationX: (uint)x,
|
||||
destinationY: (uint)y,
|
||||
destinationZ: (ushort)z,
|
||||
destinationX: (uint)destinationOffsetX,
|
||||
destinationY: (uint)destinationOffsetY,
|
||||
destinationZ: (ushort)destinationOffsetZ,
|
||||
d3D12ResourceSource: d3D12Resource.Get(),
|
||||
&d3D12PlacedSubresourceFootprintSource,
|
||||
sourceX: 0,
|
||||
@@ -404,16 +481,16 @@ public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper
|
||||
/// Writes the contents of a given <see cref="UploadTexture3D{T}"/> instance to a specified area of the current <see cref="Texture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="source">The input <see cref="UploadTexture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="sourceX">The horizontal offset within <paramref name="source"/>.</param>
|
||||
/// <param name="sourceY">The vertical offset within <paramref name="source"/>.</param>
|
||||
/// <param name="sourceZ">The depthwise offset within <paramref name="source"/>.</param>
|
||||
/// <param name="destinationX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationY">The vertical offset in the destination texture.</param>
|
||||
/// <param name="destinationZ">The depthwise offset in the destination texture.</param>
|
||||
/// <param name="sourceOffsetX">The horizontal offset within <paramref name="source"/>.</param>
|
||||
/// <param name="sourceOffsetY">The vertical offset within <paramref name="source"/>.</param>
|
||||
/// <param name="sourceOffsetZ">The depthwise offset within <paramref name="source"/>.</param>
|
||||
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
|
||||
/// <param name="destinationOffsetZ">The depthwise offset in the destination texture.</param>
|
||||
/// <param name="width">The width of the memory area to write to.</param>
|
||||
/// <param name="height">The height of the memory area to write to.</param>
|
||||
/// <param name="depth">The depth of the memory area to write to.</param>
|
||||
internal void CopyFrom(UploadTexture3D<T> source, int sourceX, int sourceY, int sourceZ, int destinationX, int destinationY, int destinationZ, int width, int height, int depth)
|
||||
internal void CopyFrom(UploadTexture3D<T> source, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
|
||||
@@ -422,24 +499,24 @@ public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper
|
||||
source.ThrowIfDeviceMismatch(GraphicsDevice);
|
||||
source.ThrowIfDisposed();
|
||||
|
||||
Guard.IsInRange(sourceX, 0, source.Width, nameof(sourceX));
|
||||
Guard.IsInRange(sourceY, 0, source.Height, nameof(sourceY));
|
||||
Guard.IsInRange(sourceZ, 0, source.Depth, nameof(sourceZ));
|
||||
Guard.IsInRange(destinationX, 0, Width, nameof(destinationX));
|
||||
Guard.IsInRange(destinationY, 0, Height, nameof(destinationY));
|
||||
Guard.IsInRange(destinationZ, 0, Depth, nameof(destinationZ));
|
||||
Guard.IsInRange(sourceOffsetX, 0, source.Width, nameof(sourceOffsetX));
|
||||
Guard.IsInRange(sourceOffsetY, 0, source.Height, nameof(sourceOffsetY));
|
||||
Guard.IsInRange(sourceOffsetZ, 0, source.Depth, nameof(sourceOffsetZ));
|
||||
Guard.IsInRange(destinationOffsetX, 0, Width, nameof(destinationOffsetX));
|
||||
Guard.IsInRange(destinationOffsetY, 0, Height, nameof(destinationOffsetY));
|
||||
Guard.IsInRange(destinationOffsetZ, 0, Depth, nameof(destinationOffsetZ));
|
||||
Guard.IsBetweenOrEqualTo(width, 1, Width, nameof(width));
|
||||
Guard.IsBetweenOrEqualTo(height, 1, Height, nameof(height));
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, Depth, nameof(depth));
|
||||
Guard.IsBetweenOrEqualTo(width, 1, source.Width, nameof(width));
|
||||
Guard.IsBetweenOrEqualTo(height, 1, source.Height, nameof(height));
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, source.Depth, nameof(depth));
|
||||
Guard.IsLessThanOrEqualTo(sourceX + width, source.Width, nameof(sourceX));
|
||||
Guard.IsLessThanOrEqualTo(sourceY + height, source.Height, nameof(sourceY));
|
||||
Guard.IsLessThanOrEqualTo(sourceZ + depth, source.Depth, nameof(sourceZ));
|
||||
Guard.IsLessThanOrEqualTo(destinationX + width, Width, nameof(destinationX));
|
||||
Guard.IsLessThanOrEqualTo(destinationY + height, Height, nameof(destinationY));
|
||||
Guard.IsLessThanOrEqualTo(destinationZ + depth, Depth, nameof(destinationZ));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, source.Width, nameof(sourceOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, source.Height, nameof(sourceOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffsetZ + depth, source.Depth, nameof(sourceOffsetZ));
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetX + width, Width, nameof(destinationOffsetX));
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetY + height, Height, nameof(destinationOffsetY));
|
||||
Guard.IsLessThanOrEqualTo(destinationOffsetZ + depth, Depth, nameof(destinationOffsetZ));
|
||||
|
||||
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
|
||||
|
||||
@@ -452,14 +529,14 @@ public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper
|
||||
{
|
||||
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
|
||||
d3D12ResourceDestination: D3D12Resource,
|
||||
(uint)destinationX,
|
||||
(uint)destinationY,
|
||||
(ushort)destinationZ,
|
||||
(uint)destinationOffsetX,
|
||||
(uint)destinationOffsetY,
|
||||
(ushort)destinationOffsetZ,
|
||||
d3D12ResourceSource: source.D3D12Resource,
|
||||
d3D12PlacedSubresourceFootprintSource,
|
||||
(uint)sourceX,
|
||||
(uint)sourceY,
|
||||
(ushort)sourceZ,
|
||||
(uint)sourceOffsetX,
|
||||
(uint)sourceOffsetY,
|
||||
(ushort)sourceOffsetZ,
|
||||
(uint)width,
|
||||
(uint)height,
|
||||
(ushort)depth);
|
||||
|
||||
@@ -57,116 +57,91 @@ public sealed class ConstantBuffer<T> : Buffer<T>
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
internal override unsafe void CopyTo(ref T destination, int size, int offset)
|
||||
internal override unsafe void CopyTo(ref T destination, int offset, int length)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
Guard.IsBetweenOrEqualTo(length, 0, Length, nameof(length));
|
||||
Guard.IsInRange(offset, 0, Length, nameof(offset));
|
||||
Guard.IsLessThanOrEqualTo(offset + size, Length, nameof(size));
|
||||
Guard.IsLessThanOrEqualTo(offset + length, Length, nameof(offset));
|
||||
|
||||
using ID3D12ResourceMap resource = D3D12Resource->Map();
|
||||
|
||||
fixed (void* destinationPointer = &destination)
|
||||
{
|
||||
if (IsPaddingPresent)
|
||||
{
|
||||
MemoryHelper.Copy<T>(
|
||||
resource.Pointer,
|
||||
(uint)offset,
|
||||
(uint)size,
|
||||
(uint)GetPaddedSize(),
|
||||
destinationPointer);
|
||||
}
|
||||
else
|
||||
{
|
||||
MemoryHelper.Copy(
|
||||
resource.Pointer,
|
||||
(uint)offset,
|
||||
(uint)size,
|
||||
(uint)sizeof(T),
|
||||
destinationPointer);
|
||||
}
|
||||
MemoryHelper.Copy<T>(
|
||||
source: resource.Pointer,
|
||||
destination: destinationPointer,
|
||||
sourceElementOffset: (uint)offset,
|
||||
destinationElementOffset: 0,
|
||||
sourceElementPitchInBytes: (uint)GetPaddedSize(),
|
||||
destinationElementPitchInBytes: (uint)sizeof(T),
|
||||
count: (uint)length);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
internal override unsafe void CopyFrom(ref T source, int size, int offset)
|
||||
internal override unsafe void CopyTo(Buffer<T> destination, int sourceOffset, int destinationOffset, int length)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
destination.ThrowIfDeviceMismatch(GraphicsDevice);
|
||||
destination.ThrowIfDisposed();
|
||||
|
||||
Guard.IsBetweenOrEqualTo(length, 0, Length, nameof(length));
|
||||
Guard.IsBetweenOrEqualTo(length, 0, destination.Length, nameof(length));
|
||||
Guard.IsInRange(sourceOffset, 0, Length, nameof(sourceOffset));
|
||||
Guard.IsLessThanOrEqualTo(sourceOffset + length, Length, nameof(sourceOffset));
|
||||
Guard.IsInRange(destinationOffset, 0, destination.Length, nameof(destinationOffset));
|
||||
Guard.IsLessThanOrEqualTo(destinationOffset + length, destination.Length, nameof(destinationOffset));
|
||||
|
||||
if (destination is ConstantBuffer<T> buffer)
|
||||
{
|
||||
using ID3D12ResourceMap sourceMap = D3D12Resource->Map();
|
||||
using ID3D12ResourceMap destinationMap = buffer.D3D12Resource->Map();
|
||||
|
||||
MemoryHelper.Copy<T>(
|
||||
source: sourceMap.Pointer,
|
||||
destination: destinationMap.Pointer,
|
||||
sourceElementOffset: (uint)sourceOffset,
|
||||
destinationElementOffset: (uint)destinationOffset,
|
||||
sourceElementPitchInBytes: (uint)GetPaddedSize(),
|
||||
destinationElementPitchInBytes: (uint)GetPaddedSize(),
|
||||
count: (uint)length);
|
||||
}
|
||||
else CopyToWithCpuBuffer(destination, sourceOffset, destinationOffset, length);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
internal override unsafe void CopyFrom(ref T source, int offset, int length)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
Guard.IsBetweenOrEqualTo(length, 0, Length, nameof(length));
|
||||
Guard.IsInRange(offset, 0, Length, nameof(offset));
|
||||
Guard.IsLessThanOrEqualTo(offset + size, Length, nameof(size));
|
||||
Guard.IsLessThanOrEqualTo(offset + length, Length, nameof(offset));
|
||||
|
||||
using ID3D12ResourceMap resource = D3D12Resource->Map();
|
||||
|
||||
fixed (void* sourcePointer = &source)
|
||||
{
|
||||
if (IsPaddingPresent)
|
||||
{
|
||||
MemoryHelper.Copy<T>(
|
||||
sourcePointer,
|
||||
resource.Pointer,
|
||||
(uint)offset,
|
||||
(uint)size,
|
||||
(uint)GetPaddedSize(),
|
||||
isPaddingInSourceToo: false);
|
||||
}
|
||||
else
|
||||
{
|
||||
MemoryHelper.Copy(
|
||||
sourcePointer,
|
||||
(uint)offset,
|
||||
(uint)size,
|
||||
(uint)sizeof(T),
|
||||
resource.Pointer);
|
||||
}
|
||||
MemoryHelper.Copy<T>(
|
||||
source: sourcePointer,
|
||||
destination: resource.Pointer,
|
||||
sourceElementOffset: 0,
|
||||
destinationElementOffset: (uint)offset,
|
||||
sourceElementPitchInBytes: (uint)sizeof(T),
|
||||
destinationElementPitchInBytes: (uint)GetPaddedSize(),
|
||||
count: (uint)length);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override unsafe void CopyFrom(Buffer<T> source)
|
||||
{
|
||||
GraphicsDevice.ThrowIfDisposed();
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
source.ThrowIfDeviceMismatch(GraphicsDevice);
|
||||
source.ThrowIfDisposed();
|
||||
|
||||
Guard.IsLessThanOrEqualTo(source.Length, Length, nameof(Length));
|
||||
|
||||
if (source is ConstantBuffer<T> buffer)
|
||||
{
|
||||
using ID3D12ResourceMap sourceMap = buffer.D3D12Resource->Map();
|
||||
using ID3D12ResourceMap destinationMap = D3D12Resource->Map();
|
||||
|
||||
if (IsPaddingPresent)
|
||||
{
|
||||
MemoryHelper.Copy<T>(
|
||||
sourceMap.Pointer,
|
||||
destinationMap.Pointer,
|
||||
0,
|
||||
(uint)source.Length,
|
||||
(uint)GetPaddedSize(),
|
||||
isPaddingInSourceToo: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
MemoryHelper.Copy(
|
||||
sourceMap.Pointer,
|
||||
0,
|
||||
(uint)source.Length,
|
||||
(uint)sizeof(T),
|
||||
destinationMap.Pointer);
|
||||
}
|
||||
}
|
||||
else CopyFromWithCpuBuffer(source);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
|
||||
@@ -18,9 +18,9 @@ internal sealed class BufferDebugView<T>
|
||||
{
|
||||
if (buffer is not null)
|
||||
{
|
||||
var items = GC.AllocateUninitializedArray<T>(buffer.Length);
|
||||
T[] items = GC.AllocateUninitializedArray<T>(buffer.Length);
|
||||
|
||||
buffer.CopyTo(ref items[0], buffer.Length, 0);
|
||||
buffer.CopyTo(ref items[0], 0, buffer.Length);
|
||||
|
||||
Items = items;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ internal sealed class Texture2DDebugView<T>
|
||||
{
|
||||
if (texture is not null)
|
||||
{
|
||||
var items = new T[texture.Height, texture.Width];
|
||||
T[,] items = new T[texture.Height, texture.Width];
|
||||
|
||||
texture.CopyTo(ref items[0, 0], items.Length, 0, 0, texture.Width, texture.Height);
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ internal sealed class Texture3DDebugView<T>
|
||||
{
|
||||
if (texture is not null)
|
||||
{
|
||||
var items = new T[texture.Depth, texture.Height, texture.Width];
|
||||
T[,,] items = new T[texture.Depth, texture.Height, texture.Width];
|
||||
|
||||
texture.CopyTo(ref items[0, 0, 0], items.Length, 0, 0, 0, texture.Width, texture.Height, texture.Depth);
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ internal sealed class TransferBufferDebugView<T>
|
||||
{
|
||||
if (buffer is not null)
|
||||
{
|
||||
var items = GC.AllocateUninitializedArray<T>(buffer.Length);
|
||||
T[] items = GC.AllocateUninitializedArray<T>(buffer.Length);
|
||||
|
||||
buffer.Span.CopyTo(items);
|
||||
|
||||
|
||||
@@ -19,4 +19,16 @@
|
||||
PrivateAssets="contentfiles;build"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\ComputeSharp.Tests\Attributes\AdditionalDataAttribute.cs" Link="Attributes\AdditionalDataAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Tests\Attributes\AdditionalResourceAttribute.cs" Link="Attributes\AdditionalResourceAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Tests\Attributes\AllDevicesAttribute.cs" Link="Attributes\AllDevicesAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Tests\Attributes\CombinatorialTestMethodAttribute.cs" Link="Attributes\CombinatorialTestMethodAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Tests\Attributes\DataAttribute.cs" Link="Attributes\DataAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Tests\Attributes\DeviceAttribute.cs" Link="Attributes\DeviceAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Tests\Attributes\ResourceAttribute.cs" Link="Attributes\ResourceAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Tests\Extensions\DeviceExtensions.cs" Link="Extensions\DeviceExtensions.cs" />
|
||||
<Compile Include="..\ComputeSharp.Tests\Extensions\GraphicsDeviceExtensions.cs" Link="Extensions\GraphicsDeviceExtensions.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,321 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using ComputeSharp.Resources;
|
||||
using ComputeSharp.Resources.Debug;
|
||||
using ComputeSharp.Tests.Attributes;
|
||||
using ComputeSharp.Tests.Extensions;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ComputeSharp.Tests.Internals;
|
||||
|
||||
[TestClass]
|
||||
[TestCategory("Buffer")]
|
||||
public partial class DebugViewTests
|
||||
{
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ConstantBuffer<>))]
|
||||
[Resource(typeof(ReadOnlyBuffer<>))]
|
||||
[Resource(typeof(ReadWriteBuffer<>))]
|
||||
[Data(32)]
|
||||
[Data(256)]
|
||||
[Data(1024)]
|
||||
public void BufferDebugView_NotNull(Device device, Type bufferType, int size)
|
||||
{
|
||||
float[] data = Enumerable.Range(0, size).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Buffer<float> buffer = device.Get().AllocateBuffer(bufferType, data);
|
||||
|
||||
BufferDebugView<float> view = new(buffer);
|
||||
|
||||
Assert.IsNotNull(view.Items);
|
||||
|
||||
CollectionAssert.AreEqual(view.Items, data);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void BufferDebugView_Null()
|
||||
{
|
||||
using Buffer<float> buffer = null!;
|
||||
|
||||
BufferDebugView<float> view = new(buffer);
|
||||
|
||||
Assert.IsNull(view.Items);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<>))]
|
||||
[Data(32, 32)]
|
||||
[Data(1024, 1024)]
|
||||
[Data(667, 480)]
|
||||
public void Texture2DDebugView_NotNull(Device device, Type textureType, int width, int height)
|
||||
{
|
||||
float[] data = Enumerable.Range(0, width * height).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Texture2D<float> texture = device.Get().AllocateTexture2D(textureType, data, width, height);
|
||||
|
||||
Texture2DDebugView<float> view = new(texture);
|
||||
|
||||
Assert.IsNotNull(view.Items);
|
||||
Assert.AreEqual(view.Items.GetLength(0), height);
|
||||
Assert.AreEqual(view.Items.GetLength(1), width);
|
||||
|
||||
CollectionAssert.AreEqual(view.Items, data);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<,>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<,>))]
|
||||
[Data(32, 32)]
|
||||
[Data(512, 512)]
|
||||
[Data(667, 480)]
|
||||
public void Texture2DDebugView_WithTPixel_NotNull(Device device, Type textureType, int width, int height)
|
||||
{
|
||||
Random random = new(42);
|
||||
Rgba32[,] data = new Rgba32[height, width];
|
||||
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
for (int j = 0; j < width; j++)
|
||||
{
|
||||
data[i, j] = new Rgba32((byte)random.Next(256), (byte)random.Next(256), (byte)random.Next(256), (byte)random.Next(256));
|
||||
}
|
||||
}
|
||||
|
||||
using Texture2D<Rgba32> texture = device.Get().AllocateTexture2D<Rgba32, float4>(textureType, width, height);
|
||||
|
||||
texture.CopyFrom(data);
|
||||
|
||||
Texture2DDebugView<Rgba32> view = new(texture);
|
||||
|
||||
Assert.IsNotNull(view.Items);
|
||||
Assert.AreEqual(view.Items.GetLength(0), height);
|
||||
Assert.AreEqual(view.Items.GetLength(1), width);
|
||||
|
||||
CollectionAssert.AreEqual(view.Items, data);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Texture2DDebugView_Null()
|
||||
{
|
||||
using Texture2D<float> texture = null!;
|
||||
|
||||
Texture2DDebugView<float> view = new(texture);
|
||||
|
||||
Assert.IsNull(view.Items);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture3D<>))]
|
||||
[Resource(typeof(ReadWriteTexture3D<>))]
|
||||
[Data(32, 32, 4)]
|
||||
[Data(1024, 1024, 3)]
|
||||
[Data(667, 480, 7)]
|
||||
public void Texture3DDebugView_NotNull(Device device, Type textureType, int width, int height, int depth)
|
||||
{
|
||||
float[] data = Enumerable.Range(0, width * height * depth).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Texture3D<float> texture = device.Get().AllocateTexture3D(textureType, data, width, height, depth);
|
||||
|
||||
Texture3DDebugView<float> view = new(texture);
|
||||
|
||||
Assert.IsNotNull(view.Items);
|
||||
Assert.AreEqual(view.Items.GetLength(0), depth);
|
||||
Assert.AreEqual(view.Items.GetLength(1), height);
|
||||
Assert.AreEqual(view.Items.GetLength(2), width);
|
||||
|
||||
CollectionAssert.AreEqual(view.Items, data);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture3D<,>))]
|
||||
[Resource(typeof(ReadWriteTexture3D<,>))]
|
||||
[Data(32, 32, 4)]
|
||||
[Data(1024, 1024, 3)]
|
||||
[Data(667, 480, 7)]
|
||||
public void Texture3DDebugView_WithTPixel_NotNull(Device device, Type textureType, int width, int height, int depth)
|
||||
{
|
||||
Random random = new(42);
|
||||
Rgba32[,,] data = new Rgba32[depth, height, width];
|
||||
|
||||
for (int k = 0; k < depth; k++)
|
||||
{
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
for (int j = 0; j < width; j++)
|
||||
{
|
||||
data[k, i, j] = new Rgba32((byte)random.Next(256), (byte)random.Next(256), (byte)random.Next(256), (byte)random.Next(256));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
using Texture3D<Rgba32> texture = device.Get().AllocateTexture3D<Rgba32, float4>(textureType, width, height, depth);
|
||||
|
||||
texture.CopyFrom(data);
|
||||
|
||||
Texture3DDebugView<Rgba32> view = new(texture);
|
||||
|
||||
Assert.IsNotNull(view.Items);
|
||||
Assert.AreEqual(view.Items.GetLength(0), depth);
|
||||
Assert.AreEqual(view.Items.GetLength(1), height);
|
||||
Assert.AreEqual(view.Items.GetLength(2), width);
|
||||
|
||||
CollectionAssert.AreEqual(view.Items, data);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Texture3DDebugView_Null()
|
||||
{
|
||||
using Texture3D<float> texture = null!;
|
||||
|
||||
Texture3DDebugView<float> view = new(texture);
|
||||
|
||||
Assert.IsNull(view.Items);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(UploadBuffer<>))]
|
||||
[Resource(typeof(ReadBackBuffer<>))]
|
||||
[Data(32)]
|
||||
[Data(1024)]
|
||||
[Data(667)]
|
||||
public void TransferBufferDebugView_NotNull(Device device, Type bufferType, int size)
|
||||
{
|
||||
float[] data = Enumerable.Range(0, size).Select(static i => (float)i).ToArray();
|
||||
|
||||
using TransferBuffer<float> buffer = device.Get().AllocateTransferBuffer<float>(bufferType, size);
|
||||
|
||||
data.AsSpan().CopyTo(buffer.Span);
|
||||
|
||||
TransferBufferDebugView<float> view = new(buffer);
|
||||
|
||||
Assert.IsNotNull(view.Items);
|
||||
|
||||
CollectionAssert.AreEqual(view.Items, data);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TransferBufferDebugView_Null()
|
||||
{
|
||||
using TransferBuffer<float> buffer = null!;
|
||||
|
||||
TransferBufferDebugView<float> view = new(buffer);
|
||||
|
||||
Assert.IsNull(view.Items);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(UploadTexture2D<>))]
|
||||
[Resource(typeof(ReadBackTexture2D<>))]
|
||||
[Data(32, 32)]
|
||||
[Data(1024, 1024)]
|
||||
[Data(667, 480)]
|
||||
public void TransferTexture2DDebugView_NotNull(Device device, Type textureType, int width, int height)
|
||||
{
|
||||
Random random = new(42);
|
||||
float[,] data = new float[height, width];
|
||||
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
for (int j = 0; j < width; j++)
|
||||
{
|
||||
data[i, j] = random.NextSingle();
|
||||
}
|
||||
}
|
||||
|
||||
using TransferTexture2D<float> texture = device.Get().AllocateTransferTexture2D<float>(textureType, width, height);
|
||||
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
Span<float> row = texture.View.GetRowSpan(i);
|
||||
|
||||
for (int j = 0; j < width; j++)
|
||||
{
|
||||
row[j] = data[i, j];
|
||||
}
|
||||
}
|
||||
|
||||
TransferTexture2DDebugView<float> view = new(texture);
|
||||
|
||||
Assert.IsNotNull(view.Items);
|
||||
Assert.AreEqual(view.Items.GetLength(0), height);
|
||||
Assert.AreEqual(view.Items.GetLength(1), width);
|
||||
|
||||
CollectionAssert.AreEqual(view.Items, data);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TransferTexture2DDebugView_Null()
|
||||
{
|
||||
using Texture2D<float> texture = null!;
|
||||
|
||||
Texture2DDebugView<float> view = new(texture);
|
||||
|
||||
Assert.IsNull(view.Items);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(UploadTexture3D<>))]
|
||||
[Resource(typeof(ReadBackTexture3D<>))]
|
||||
[Data(32, 32, 4)]
|
||||
[Data(1024, 1024, 3)]
|
||||
[Data(667, 480, 7)]
|
||||
public void TransferTexture3DDebugView_NotNull(Device device, Type textureType, int width, int height, int depth)
|
||||
{
|
||||
Random random = new(42);
|
||||
float[,,] data = new float[depth, height, width];
|
||||
|
||||
for (int k = 0; k < depth; k++)
|
||||
{
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
for (int j = 0; j < width; j++)
|
||||
{
|
||||
data[k, i, j] = random.NextSingle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
using TransferTexture3D<float> texture = device.Get().AllocateTransferTexture3D<float>(textureType, width, height, depth);
|
||||
|
||||
for (int k = 0; k < depth; k++)
|
||||
{
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
Span<float> row = texture.View.GetRowSpan(i, k);
|
||||
|
||||
for (int j = 0; j < width; j++)
|
||||
{
|
||||
row[j] = data[k, i, j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TransferTexture3DDebugView<float> view = new(texture);
|
||||
|
||||
Assert.IsNotNull(view.Items);
|
||||
Assert.AreEqual(view.Items.GetLength(0), depth);
|
||||
Assert.AreEqual(view.Items.GetLength(1), height);
|
||||
Assert.AreEqual(view.Items.GetLength(2), width);
|
||||
|
||||
CollectionAssert.AreEqual(view.Items, data);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TransferTexture3DDebugView_Null()
|
||||
{
|
||||
using Texture3D<float> texture = null!;
|
||||
|
||||
Texture3DDebugView<float> view = new(texture);
|
||||
|
||||
Assert.IsNull(view.Items);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
|
||||
namespace ComputeSharp.Tests.Attributes;
|
||||
|
||||
/// <summary>
|
||||
/// An attribute to use with <see cref="CombinatorialAttribute"/> adding additional arbitrary input data.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
|
||||
public sealed class AdditionalDataAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="AdditionalDataAttribute"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="data">The additional input data.</param>
|
||||
public AdditionalDataAttribute(params object[] data)
|
||||
{
|
||||
Data = data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the additional input data for the current attribute.
|
||||
/// </summary>
|
||||
public object[] Data { get; }
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
|
||||
namespace ComputeSharp.Tests.Attributes;
|
||||
|
||||
/// <summary>
|
||||
/// An attribute to use with <see cref="CombinatorialAttribute"/> targeting an additional specific resource type.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
|
||||
public sealed class AdditionalResourceAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="AdditionalResourceAttribute"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="type">The additional resource type.</param>
|
||||
public AdditionalResourceAttribute(Type type)
|
||||
{
|
||||
Type = type;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the additional resource type for the current attribute.
|
||||
/// </summary>
|
||||
public Type Type { get; }
|
||||
}
|
||||
@@ -37,7 +37,9 @@ public sealed class CombinatorialTestMethodAttribute : TestMethodAttribute, ITes
|
||||
}
|
||||
|
||||
Type[] resources = methodInfo.GetCustomAttributes<ResourceAttribute>().Select(static value => value.Type).ToArray();
|
||||
Type[] additionalResources = methodInfo.GetCustomAttributes<AdditionalResourceAttribute>().Select(static value => value.Type).ToArray();
|
||||
object[][] data = methodInfo.GetCustomAttributes<DataAttribute>().Select(static value => value.Data).ToArray();
|
||||
object[][] additionalData = methodInfo.GetCustomAttributes<AdditionalDataAttribute>().Select(static value => value.Data).ToArray();
|
||||
|
||||
if (devices.Length > 0)
|
||||
{
|
||||
@@ -47,30 +49,109 @@ public sealed class CombinatorialTestMethodAttribute : TestMethodAttribute, ITes
|
||||
{
|
||||
foreach (Type type in resources)
|
||||
{
|
||||
if (data.Length == 0)
|
||||
if (additionalResources.Length > 0)
|
||||
{
|
||||
yield return new object[] { device, type };
|
||||
foreach (Type additionalType in additionalResources)
|
||||
{
|
||||
if (data.Length == 0)
|
||||
{
|
||||
if (additionalData.Length > 0)
|
||||
{
|
||||
Assert.Fail("Invalid usage of [AdditionalData]");
|
||||
}
|
||||
|
||||
yield return new object[] { device, type, additionalType };
|
||||
}
|
||||
else
|
||||
{
|
||||
if (additionalData.Length > 0)
|
||||
{
|
||||
foreach (object[] items in data)
|
||||
{
|
||||
foreach (object[] additionalItems in additionalData)
|
||||
{
|
||||
yield return new object[] { device, type, additionalType }.Concat(items).Concat(additionalItems).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (object[] items in data)
|
||||
{
|
||||
yield return new object[] { device, type, additionalType }.Concat(items).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (object[] items in data)
|
||||
if (data.Length == 0)
|
||||
{
|
||||
yield return new object[] { device, type }.Concat(items).ToArray();
|
||||
if (additionalData.Length > 0)
|
||||
{
|
||||
Assert.Fail("Invalid usage of [AdditionalData]");
|
||||
}
|
||||
|
||||
yield return new object[] { device, type };
|
||||
}
|
||||
else
|
||||
{
|
||||
if (additionalData.Length > 0)
|
||||
{
|
||||
foreach (object[] items in data)
|
||||
{
|
||||
foreach (object[] additionalItems in additionalData)
|
||||
{
|
||||
yield return new object[] { device, type }.Concat(items).Concat(additionalItems).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (object[] items in data)
|
||||
{
|
||||
yield return new object[] { device, type }.Concat(items).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (additionalResources.Length > 0)
|
||||
{
|
||||
Assert.Fail("Invalid usage of [AdditionalResource]");
|
||||
}
|
||||
|
||||
if (data.Length == 0)
|
||||
{
|
||||
if (additionalData.Length > 0)
|
||||
{
|
||||
Assert.Fail("Invalid usage of [AdditionalData]");
|
||||
}
|
||||
|
||||
yield return new object[] { device };
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (object[] items in data)
|
||||
if (additionalData.Length > 0)
|
||||
{
|
||||
yield return new object[] { device }.Concat(items).ToArray();
|
||||
foreach (object[] items in data)
|
||||
{
|
||||
foreach (object[] additionalItems in additionalData)
|
||||
{
|
||||
yield return new object[] { device }.Concat(items).Concat(additionalItems).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (object[] items in data)
|
||||
{
|
||||
yield return new object[] { device }.Concat(items).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,30 +161,109 @@ public sealed class CombinatorialTestMethodAttribute : TestMethodAttribute, ITes
|
||||
{
|
||||
foreach (Type type in resources)
|
||||
{
|
||||
if (data.Length == 0)
|
||||
if (additionalResources.Length > 0)
|
||||
{
|
||||
yield return new object[] { type };
|
||||
foreach (Type additionalType in additionalResources)
|
||||
{
|
||||
if (data.Length == 0)
|
||||
{
|
||||
if (additionalData.Length > 0)
|
||||
{
|
||||
Assert.Fail("Invalid usage of [AdditionalData]");
|
||||
}
|
||||
|
||||
yield return new object[] { type, additionalType };
|
||||
}
|
||||
else
|
||||
{
|
||||
if (additionalData.Length > 0)
|
||||
{
|
||||
foreach (object[] items in data)
|
||||
{
|
||||
foreach (object[] additionalItems in additionalData)
|
||||
{
|
||||
yield return new object[] { type, additionalType }.Concat(items).Concat(additionalItems).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (object[] items in data)
|
||||
{
|
||||
yield return new object[] { type, additionalType }.Concat(items).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (object[] items in data)
|
||||
if (data.Length == 0)
|
||||
{
|
||||
yield return new object[] { type }.Concat(items).ToArray();
|
||||
if (additionalData.Length > 0)
|
||||
{
|
||||
Assert.Fail("Invalid usage of [AdditionalData]");
|
||||
}
|
||||
|
||||
yield return new object[] { type };
|
||||
}
|
||||
else
|
||||
{
|
||||
if (additionalData.Length > 0)
|
||||
{
|
||||
foreach (object[] items in data)
|
||||
{
|
||||
foreach (object[] additionalItems in additionalData)
|
||||
{
|
||||
yield return new object[] { type }.Concat(items).Concat(additionalItems).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (object[] items in data)
|
||||
{
|
||||
yield return new object[] { type }.Concat(items).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (additionalResources.Length > 0)
|
||||
{
|
||||
Assert.Fail("Invalid usage of [AdditionalResource]");
|
||||
}
|
||||
|
||||
if (data.Length == 0)
|
||||
{
|
||||
if (additionalData.Length > 0)
|
||||
{
|
||||
Assert.Fail("Invalid usage of [AdditionalData]");
|
||||
}
|
||||
|
||||
yield return Array.Empty<object>();
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (object[] items in data)
|
||||
if (additionalData.Length > 0)
|
||||
{
|
||||
yield return items;
|
||||
foreach (object[] items in data)
|
||||
{
|
||||
foreach (object[] additionalItems in additionalData)
|
||||
{
|
||||
yield return items.Concat(additionalItems).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (object[] items in data)
|
||||
{
|
||||
yield return items;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,10 @@ namespace ComputeSharp.Tests.Attributes;
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
|
||||
public sealed class DataAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="DataAttribute"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="data">The input data.</param>
|
||||
public DataAttribute(params object[] data)
|
||||
{
|
||||
Data = data;
|
||||
|
||||
@@ -9,6 +9,10 @@ namespace ComputeSharp.Tests.Attributes;
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
|
||||
public sealed class DeviceAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="DeviceAttribute"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="device">The target device type to use..</param>
|
||||
public DeviceAttribute(Device device)
|
||||
{
|
||||
Device = device;
|
||||
|
||||
@@ -8,10 +8,17 @@ namespace ComputeSharp.Tests.Attributes;
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
|
||||
public sealed class ResourceAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ResourceAttribute"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="type">The resource type.</param>
|
||||
public ResourceAttribute(Type type)
|
||||
{
|
||||
Type = type;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the resource type for the current attribute.
|
||||
/// </summary>
|
||||
public Type Type { get; }
|
||||
}
|
||||
@@ -18,12 +18,16 @@ public partial class BufferTests
|
||||
[Resource(typeof(ReadWriteBuffer<>))]
|
||||
[Data(AllocationMode.Default)]
|
||||
[Data(AllocationMode.Clear)]
|
||||
public void Allocate_Uninitialized_Ok(Device device, Type bufferType, AllocationMode allocationMode)
|
||||
[AdditionalData(128)]
|
||||
[AdditionalData(768)]
|
||||
[AdditionalData(1024)]
|
||||
[AdditionalData(443)]
|
||||
public void Allocate_Uninitialized_Ok(Device device, Type bufferType, AllocationMode allocationMode, int size)
|
||||
{
|
||||
using Buffer<float> buffer = device.Get().AllocateBuffer<float>(bufferType, 128, allocationMode);
|
||||
using Buffer<float> buffer = device.Get().AllocateBuffer<float>(bufferType, size, allocationMode);
|
||||
|
||||
Assert.IsNotNull(buffer);
|
||||
Assert.AreEqual(buffer.Length, 128);
|
||||
Assert.AreEqual(buffer.Length, size);
|
||||
Assert.AreSame(buffer.GraphicsDevice, device.Get());
|
||||
|
||||
if (allocationMode == AllocationMode.Clear)
|
||||
@@ -53,14 +57,18 @@ public partial class BufferTests
|
||||
[Resource(typeof(ConstantBuffer<>))]
|
||||
[Resource(typeof(ReadOnlyBuffer<>))]
|
||||
[Resource(typeof(ReadWriteBuffer<>))]
|
||||
public void Allocate_FromArray(Device device, Type bufferType)
|
||||
[Data(128)]
|
||||
[Data(768)]
|
||||
[Data(1024)]
|
||||
[Data(443)]
|
||||
public void Allocate_FromArray(Device device, Type bufferType, int size)
|
||||
{
|
||||
float[] data = Enumerable.Range(0, 128).Select(static i => (float)i).ToArray();
|
||||
float[] data = Enumerable.Range(0, size).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Buffer<float> buffer = device.Get().AllocateBuffer(bufferType, data);
|
||||
|
||||
Assert.IsNotNull(buffer);
|
||||
Assert.AreEqual(buffer.Length, 128);
|
||||
Assert.AreEqual(buffer.Length, size);
|
||||
Assert.AreSame(buffer.GraphicsDevice, device.Get());
|
||||
|
||||
float[] result = buffer.ToArray();
|
||||
@@ -75,18 +83,22 @@ public partial class BufferTests
|
||||
[Resource(typeof(ConstantBuffer<>))]
|
||||
[Resource(typeof(ReadOnlyBuffer<>))]
|
||||
[Resource(typeof(ReadWriteBuffer<>))]
|
||||
[Data(typeof(ConstantBuffer<>))]
|
||||
[Data(typeof(ReadOnlyBuffer<>))]
|
||||
[Data(typeof(ReadWriteBuffer<>))]
|
||||
public void Allocate_FromBuffer(Device device, Type sourceType, Type destinationType)
|
||||
[AdditionalResource(typeof(ConstantBuffer<>))]
|
||||
[AdditionalResource(typeof(ReadOnlyBuffer<>))]
|
||||
[AdditionalResource(typeof(ReadWriteBuffer<>))]
|
||||
[Data(128)]
|
||||
[Data(768)]
|
||||
[Data(1024)]
|
||||
[Data(443)]
|
||||
public void Allocate_FromBuffer(Device device, Type sourceType, Type destinationType, int size)
|
||||
{
|
||||
float[] data = Enumerable.Range(0, 128).Select(static i => (float)i).ToArray();
|
||||
float[] data = Enumerable.Range(0, size).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Buffer<float> source = device.Get().AllocateBuffer(sourceType, data);
|
||||
using Buffer<float> destination = device.Get().AllocateBuffer(destinationType, source);
|
||||
|
||||
Assert.IsNotNull(destination);
|
||||
Assert.AreEqual(destination.Length, 128);
|
||||
Assert.AreEqual(destination.Length, size);
|
||||
Assert.AreSame(destination.GraphicsDevice, device.Get());
|
||||
|
||||
float[] result = destination.ToArray();
|
||||
@@ -184,10 +196,11 @@ public partial class BufferTests
|
||||
[Resource(typeof(ReadOnlyBuffer<>))]
|
||||
[Resource(typeof(ReadWriteBuffer<>))]
|
||||
[Data(0, 0, 4096)]
|
||||
[Data(512, 0, 2048)]
|
||||
[Data(0, 512, 2048)]
|
||||
[Data(127, 1024, 587)]
|
||||
public void CopyTo_RangeToVoid_Ok(Device device, Type bufferType, int destinationOffset, int bufferOffset, int count)
|
||||
[Data(512, 0, 2048)]
|
||||
[Data(1024, 127, 587)]
|
||||
[Data(65, 127, 587)]
|
||||
public void CopyTo_RangeToVoid_Ok(Device device, Type bufferType, int sourceOffset, int destinationOffset, int count)
|
||||
{
|
||||
float[] array = Enumerable.Range(0, 4096).Select(static i => (float)i).ToArray();
|
||||
|
||||
@@ -195,9 +208,9 @@ public partial class BufferTests
|
||||
|
||||
float[] result = new float[4096];
|
||||
|
||||
buffer.CopyTo(result, destinationOffset, bufferOffset, count);
|
||||
buffer.CopyTo(result, sourceOffset, destinationOffset, count);
|
||||
|
||||
Assert.IsTrue(array.AsSpan(bufferOffset, count).SequenceEqual(result.AsSpan(destinationOffset, count)));
|
||||
Assert.IsTrue(array.AsSpan(sourceOffset, count).SequenceEqual(result.AsSpan(destinationOffset, count)));
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
@@ -206,13 +219,13 @@ public partial class BufferTests
|
||||
[Resource(typeof(ReadOnlyBuffer<>))]
|
||||
[Resource(typeof(ReadWriteBuffer<>))]
|
||||
[Data(0, 0, 8196)]
|
||||
[Data(-12, 0, 1024)]
|
||||
[Data(0, -56, 1024)]
|
||||
[Data(512, 0, 4096)]
|
||||
[Data(12, 1024, 3600)]
|
||||
[Data(12, 1024, -2096)]
|
||||
[Data(0, -12, 1024)]
|
||||
[Data(-56, 0, 1024)]
|
||||
[Data(0, 512, 4096)]
|
||||
[Data(1024, 12, 3600)]
|
||||
[Data(1024, 12, - 2096)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void CopyTo_RangeToVoid_Fail(Device device, Type bufferType, int destinationOffset, int bufferOffset, int count)
|
||||
public void CopyTo_RangeToVoid_Fail(Device device, Type bufferType, int sourceOffset, int destinationOffset, int count)
|
||||
{
|
||||
float[] array = Enumerable.Range(0, 4096).Select(static i => (float)i).ToArray();
|
||||
|
||||
@@ -220,7 +233,59 @@ public partial class BufferTests
|
||||
|
||||
float[] result = new float[4096];
|
||||
|
||||
buffer.CopyTo(result, destinationOffset, bufferOffset, count);
|
||||
buffer.CopyTo(result, sourceOffset, destinationOffset, count);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ConstantBuffer<>))]
|
||||
[Resource(typeof(ReadOnlyBuffer<>))]
|
||||
[Resource(typeof(ReadWriteBuffer<>))]
|
||||
[AdditionalResource(typeof(ConstantBuffer<>))]
|
||||
[AdditionalResource(typeof(ReadOnlyBuffer<>))]
|
||||
[AdditionalResource(typeof(ReadWriteBuffer<>))]
|
||||
[Data(0, 0, 4096)]
|
||||
[Data(0, 512, 2048)]
|
||||
[Data(512, 0, 2048)]
|
||||
[Data(1024, 127, 587)]
|
||||
[Data(65, 127, 587)]
|
||||
public void CopyTo_BufferToVoid_Ok(Device device, Type sourceType, Type destinationType, int sourceOffset, int destinationOffset, int count)
|
||||
{
|
||||
float[] array = Enumerable.Range(0, 4096).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Buffer<float> source = device.Get().AllocateBuffer(sourceType, array);
|
||||
using Buffer<float> destination = device.Get().AllocateBuffer<float>(destinationType, 4096);
|
||||
|
||||
source.CopyTo(destination, sourceOffset, destinationOffset, count);
|
||||
|
||||
float[] result = destination.ToArray();
|
||||
|
||||
Assert.IsTrue(array.AsSpan(sourceOffset, count).SequenceEqual(result.AsSpan(destinationOffset, count)));
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ConstantBuffer<>))]
|
||||
[Resource(typeof(ReadOnlyBuffer<>))]
|
||||
[Resource(typeof(ReadWriteBuffer<>))]
|
||||
[AdditionalResource(typeof(ConstantBuffer<>))]
|
||||
[AdditionalResource(typeof(ReadOnlyBuffer<>))]
|
||||
[AdditionalResource(typeof(ReadWriteBuffer<>))]
|
||||
[Data(0, 0, 8196)]
|
||||
[Data(0, -12, 1024)]
|
||||
[Data(-56, 0, 1024)]
|
||||
[Data(0, 512, 4096)]
|
||||
[Data(1024, 12, 3600)]
|
||||
[Data(1024, 12, -2096)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void CopyTo_BufferToVoid_Fail(Device device, Type sourceType, Type destinationType, int sourceOffset, int destinationOffset, int count)
|
||||
{
|
||||
float[] array = Enumerable.Range(0, 4096).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Buffer<float> source = device.Get().AllocateBuffer(sourceType, array);
|
||||
using Buffer<float> destination = device.Get().AllocateBuffer<float>(destinationType, 4096);
|
||||
|
||||
source.CopyTo(destination, sourceOffset, destinationOffset, count);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
|
||||
@@ -112,6 +112,56 @@ public partial class Texture2DTests
|
||||
texture.Dispose();
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<>))]
|
||||
[Data(0, 0, 64, 64)]
|
||||
[Data(0, 14, 64, 50)]
|
||||
[Data(14, 0, 50, 64)]
|
||||
[Data(10, 10, 54, 54)]
|
||||
[Data(20, 20, 32, 27)]
|
||||
[Data(60, 0, 4, 64)]
|
||||
[Data(0, 60, 64, 4)]
|
||||
[Data(63, 2, 1, 60)]
|
||||
[Data(2, 63, 60, 1)]
|
||||
public void GetData_RangeToArray_Ok(Device device, Type textureType, int x, int y, int width, int height)
|
||||
{
|
||||
float[] array = Enumerable.Range(0, 4096).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Texture2D<float> texture = device.Get().AllocateTexture2D(textureType, array, 64, 64);
|
||||
|
||||
float[,] result = texture.ToArray(x, y, width, height);
|
||||
|
||||
Assert.AreEqual(height, result.GetLength(0));
|
||||
Assert.AreEqual(width, result.GetLength(1));
|
||||
|
||||
Span2D<float> expected = new Span2D<float>(array, 64, 64).Slice(y, x, height, width);
|
||||
Span2D<float> data = new(result);
|
||||
|
||||
CollectionAssert.AreEqual(expected.ToArray(), data.ToArray());
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<>))]
|
||||
[Data(-1, 0, 50, 50)]
|
||||
[Data(0, -1, 50, 50)]
|
||||
[Data(12, 0, -1, 50)]
|
||||
[Data(12, 0, 20, -1)]
|
||||
[Data(12, 20, 20, 50)]
|
||||
[Data(12, 20, 60, 20)]
|
||||
[Data(80, 20, 40, 20)]
|
||||
[Data(0, 80, 40, 20)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void GetData_RangeToArray_Fail(Device device, Type textureType, int x, int y, int width, int height)
|
||||
{
|
||||
using Texture2D<float> texture = device.Get().AllocateTexture2D<float>(textureType, 64, 64);
|
||||
|
||||
_ = texture.ToArray(x, y, width, height);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<>))]
|
||||
@@ -165,6 +215,228 @@ public partial class Texture2DTests
|
||||
texture.CopyTo(result, x, y, width, height);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<>))]
|
||||
[AdditionalResource(typeof(ReadOnlyTexture2D<>))]
|
||||
[AdditionalResource(typeof(ReadWriteTexture2D<>))]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 0, 0, 1024, 1024)]
|
||||
[Data(1024, 1024, 1024, 1024, 127, 256, 0, 0, 512, 480)]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 127, 256, 512, 480)]
|
||||
[Data(1024, 1024, 1024, 1024, 122, 329, 127, 256, 512, 480)]
|
||||
[Data(512, 480, 1024, 768, 122, 29, 127, 256, 256, 320)]
|
||||
[Data(512, 480, 256, 256, 122, 120, 0, 0, 256, 256)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 0, 0, 512, 512)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 512, 0, 512, 512)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 0, 512, 512, 512)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 512, 512, 512, 512)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 256, 256, 512, 512)]
|
||||
public void CopyTo_TextureToVoid_Ok(
|
||||
Device device,
|
||||
Type sourceType,
|
||||
Type destinationType,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
int destinationWidth,
|
||||
int destinationHeight,
|
||||
int sourceOffsetX,
|
||||
int sourceOffsetY,
|
||||
int destinationOffsetX,
|
||||
int destinationOffsetY,
|
||||
int copyWidth,
|
||||
int copyHeight)
|
||||
{
|
||||
float[] array = Enumerable.Range(0, sourceHeight * sourceWidth).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Texture2D<float> source = device.Get().AllocateTexture2D(sourceType, array, sourceWidth, sourceHeight);
|
||||
using Texture2D<float> destination = device.Get().AllocateTexture2D<float>(destinationType, destinationWidth, destinationHeight, AllocationMode.Clear);
|
||||
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, destinationOffsetX, destinationOffsetY, copyWidth, copyHeight);
|
||||
|
||||
ReadOnlySpan2D<float> expected = new(array, sourceHeight, sourceWidth);
|
||||
ReadOnlySpan2D<float> result = destination.ToArray();
|
||||
|
||||
for (int i = 0; i < destinationHeight; i++)
|
||||
{
|
||||
for (int j = 0; j < destinationWidth; j++)
|
||||
{
|
||||
if (i >= destinationOffsetY &&
|
||||
i < destinationOffsetY + copyHeight &&
|
||||
j >= destinationOffsetX &&
|
||||
j < destinationOffsetX + copyWidth)
|
||||
{
|
||||
int sourceY = i - destinationOffsetY + sourceOffsetY;
|
||||
int sourceX = j - destinationOffsetX + sourceOffsetX;
|
||||
|
||||
Assert.AreEqual(expected[sourceY, sourceX], result[i, j]);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.AreEqual(0, result[i, j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<>))]
|
||||
[AdditionalResource(typeof(ReadOnlyTexture2D<>))]
|
||||
[AdditionalResource(typeof(ReadWriteTexture2D<>))]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 0, 0, 2055, 1024)]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 0, 0, 1024, 3920)]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 0, 0, -1, 1024)]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 0, 0, 512, -2)]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 0, 0, 512, int.MaxValue)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 0, 0, 768, 768)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 0, 0, 256, 768)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 0, 0, 620, 256)]
|
||||
[Data(1024, 1024, 512, 512, 0, 0, 0, 0, 768, 768)]
|
||||
[Data(1024, 1024, 512, 512, 0, 0, 0, 0, 256, 768)]
|
||||
[Data(1024, 1024, 512, 512, 0, 0, 0, 0, 620, 256)]
|
||||
[Data(512, 512, 512, 512, 450, 0, 0, 0, 128, 128)]
|
||||
[Data(512, 512, 512, 512, 0, 450, 0, 0, 128, 128)]
|
||||
[Data(512, 512, 512, 512, 0, 0, 450, 0, 128, 128)]
|
||||
[Data(512, 512, 512, 512, 0, 0, 0, 450, 128, 128)]
|
||||
[Data(512, 512, 512, 512, -1, 0, 0, 0, 128, 128)]
|
||||
[Data(512, 512, 512, 512, 0, -1, 0, 0, 128, 128)]
|
||||
[Data(512, 512, 512, 512, 0, 0, -1, 0, 128, 128)]
|
||||
[Data(512, 512, 512, 512, 0, 0, 0, -1, 128, 128)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void CopyTo_TextureToVoid_Fail(
|
||||
Device device,
|
||||
Type sourceType,
|
||||
Type destinationType,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
int destinationWidth,
|
||||
int destinationHeight,
|
||||
int sourceOffsetX,
|
||||
int sourceOffsetY,
|
||||
int destinationOffsetX,
|
||||
int destinationOffsetY,
|
||||
int copyWidth,
|
||||
int copyHeight)
|
||||
{
|
||||
using Texture2D<float> source = device.Get().AllocateTexture2D<float>(sourceType, sourceWidth, sourceHeight);
|
||||
using Texture2D<float> destination = device.Get().AllocateTexture2D<float>(destinationType, destinationWidth, destinationHeight, AllocationMode.Clear);
|
||||
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, destinationOffsetX, destinationOffsetY, copyWidth, copyHeight);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<>))]
|
||||
[AdditionalResource(typeof(ReadOnlyTexture2D<>))]
|
||||
[AdditionalResource(typeof(ReadWriteTexture2D<>))]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 0, 0, 1024, 1024)]
|
||||
[Data(1024, 1024, 1024, 1024, 127, 256, 0, 0, 512, 480)]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 127, 256, 512, 480)]
|
||||
[Data(1024, 1024, 1024, 1024, 122, 329, 127, 256, 512, 480)]
|
||||
[Data(512, 480, 1024, 768, 122, 29, 127, 256, 256, 320)]
|
||||
[Data(512, 480, 256, 256, 122, 120, 0, 0, 256, 256)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 0, 0, 512, 512)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 512, 0, 512, 512)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 0, 512, 512, 512)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 512, 512, 512, 512)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 256, 256, 512, 512)]
|
||||
public void CopyFrom_TextureToVoid_Ok(
|
||||
Device device,
|
||||
Type sourceType,
|
||||
Type destinationType,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
int destinationWidth,
|
||||
int destinationHeight,
|
||||
int sourceOffsetX,
|
||||
int sourceOffsetY,
|
||||
int destinationOffsetX,
|
||||
int destinationOffsetY,
|
||||
int copyWidth,
|
||||
int copyHeight)
|
||||
{
|
||||
float[] array = Enumerable.Range(0, sourceHeight * sourceWidth).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Texture2D<float> source = device.Get().AllocateTexture2D(sourceType, array, sourceWidth, sourceHeight);
|
||||
using Texture2D<float> destination = device.Get().AllocateTexture2D<float>(destinationType, destinationWidth, destinationHeight, AllocationMode.Clear);
|
||||
|
||||
destination.CopyFrom(source, sourceOffsetX, sourceOffsetY, destinationOffsetX, destinationOffsetY, copyWidth, copyHeight);
|
||||
|
||||
ReadOnlySpan2D<float> expected = new(array, sourceHeight, sourceWidth);
|
||||
ReadOnlySpan2D<float> result = destination.ToArray();
|
||||
|
||||
for (int i = 0; i < destinationHeight; i++)
|
||||
{
|
||||
for (int j = 0; j < destinationWidth; j++)
|
||||
{
|
||||
if (i >= destinationOffsetY &&
|
||||
i < destinationOffsetY + copyHeight &&
|
||||
j >= destinationOffsetX &&
|
||||
j < destinationOffsetX + copyWidth)
|
||||
{
|
||||
int sourceY = i - destinationOffsetY + sourceOffsetY;
|
||||
int sourceX = j - destinationOffsetX + sourceOffsetX;
|
||||
|
||||
Assert.AreEqual(expected[sourceY, sourceX], result[i, j]);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.AreEqual(0, result[i, j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<>))]
|
||||
[AdditionalResource(typeof(ReadOnlyTexture2D<>))]
|
||||
[AdditionalResource(typeof(ReadWriteTexture2D<>))]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 0, 0, 2055, 1024)]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 0, 0, 1024, 3920)]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 0, 0, -1, 1024)]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 0, 0, 512, -2)]
|
||||
[Data(1024, 1024, 1024, 1024, 0, 0, 0, 0, 512, int.MaxValue)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 0, 0, 768, 768)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 0, 0, 256, 768)]
|
||||
[Data(512, 512, 1024, 1024, 0, 0, 0, 0, 620, 256)]
|
||||
[Data(1024, 1024, 512, 512, 0, 0, 0, 0, 768, 768)]
|
||||
[Data(1024, 1024, 512, 512, 0, 0, 0, 0, 256, 768)]
|
||||
[Data(1024, 1024, 512, 512, 0, 0, 0, 0, 620, 256)]
|
||||
[Data(512, 512, 512, 512, 450, 0, 0, 0, 128, 128)]
|
||||
[Data(512, 512, 512, 512, 0, 450, 0, 0, 128, 128)]
|
||||
[Data(512, 512, 512, 512, 0, 0, 450, 0, 128, 128)]
|
||||
[Data(512, 512, 512, 512, 0, 0, 0, 450, 128, 128)]
|
||||
[Data(512, 512, 512, 512, -1, 0, 0, 0, 128, 128)]
|
||||
[Data(512, 512, 512, 512, 0, -1, 0, 0, 128, 128)]
|
||||
[Data(512, 512, 512, 512, 0, 0, -1, 0, 128, 128)]
|
||||
[Data(512, 512, 512, 512, 0, 0, 0, -1, 128, 128)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void CopyFrom_TextureToVoid_Fail(
|
||||
Device device,
|
||||
Type sourceType,
|
||||
Type destinationType,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
int destinationWidth,
|
||||
int destinationHeight,
|
||||
int sourceOffsetX,
|
||||
int sourceOffsetY,
|
||||
int destinationOffsetX,
|
||||
int destinationOffsetY,
|
||||
int copyWidth,
|
||||
int copyHeight)
|
||||
{
|
||||
using Texture2D<float> source = device.Get().AllocateTexture2D<float>(sourceType, sourceWidth, sourceHeight);
|
||||
using Texture2D<float> destination = device.Get().AllocateTexture2D<float>(destinationType, destinationWidth, destinationHeight, AllocationMode.Clear);
|
||||
|
||||
destination.CopyFrom(source, sourceOffsetX, sourceOffsetY, destinationOffsetX, destinationOffsetY, copyWidth, copyHeight);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void Dispatch_ReadOnlyTexture2D(Device device)
|
||||
|
||||
@@ -131,6 +131,64 @@ public partial class Texture3DTests
|
||||
texture.Dispose();
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture3D<>))]
|
||||
[Resource(typeof(ReadWriteTexture3D<>))]
|
||||
[Data(0, 0, 0, 64, 64, 8)]
|
||||
[Data(0, 14, 0, 64, 50, 1)]
|
||||
[Data(14, 0, 0, 50, 64, 1)]
|
||||
[Data(0, 0, 3, 50, 64, 1)]
|
||||
[Data(10, 10, 1, 54, 54, 4)]
|
||||
[Data(20, 20, 3, 32, 27, 3)]
|
||||
[Data(40, 2, 4, 4, 62, 4)]
|
||||
[Data(0, 60, 1, 64, 4, 6)]
|
||||
[Data(63, 2, 2, 1, 60, 5)]
|
||||
[Data(2, 63, 7, 60, 1, 1)]
|
||||
public void GetData_RangeToArray_Ok(Device device, Type textureType, int x, int y, int z, int width, int height, int depth)
|
||||
{
|
||||
float[] array = Enumerable.Range(0, 64 * 64 * 8).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Texture3D<float> texture = device.Get().AllocateTexture3D(textureType, array, 64, 64, 8);
|
||||
|
||||
float[,,] result = texture.ToArray(x, y, z, width, height, depth);
|
||||
|
||||
Assert.AreEqual(depth, result.GetLength(0));
|
||||
Assert.AreEqual(height, result.GetLength(1));
|
||||
Assert.AreEqual(width, result.GetLength(2));
|
||||
|
||||
for (int k = 0; k < depth; k++)
|
||||
{
|
||||
Span2D<float> expected = new Span2D<float>(array, 64 * 64 * (k + z), 64, 64, 0).Slice(y, x, height, width);
|
||||
Span2D<float> data = new(result, k);
|
||||
|
||||
CollectionAssert.AreEqual(expected.ToArray(), data.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture3D<>))]
|
||||
[Resource(typeof(ReadWriteTexture3D<>))]
|
||||
[Data(-1, 0, 0, 50, 50, 1)]
|
||||
[Data(0, -1, 0, 50, 50, 1)]
|
||||
[Data(0, 0, -1, 50, 50, 1)]
|
||||
[Data(12, 0, 0, -1, 50, 1)]
|
||||
[Data(12, 0, 0, 20, -1, 0)]
|
||||
[Data(12, 0, 0, 20, 2, -1)]
|
||||
[Data(12, 20, 0, 20, 50, 2)]
|
||||
[Data(12, 20, 0, 60, 20, 3)]
|
||||
[Data(12, 10, 6, 20, 20, 10)]
|
||||
[Data(80, 20, 0, 40, 20, 1)]
|
||||
[Data(0, 80, 0, 40, 20, 1)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void GetData_RangeToArray_Fail(Device device, Type textureType, int x, int y, int z, int width, int height, int depth)
|
||||
{
|
||||
using Texture3D<float> texture = device.Get().AllocateTexture3D<float>(textureType, 64, 64, 8);
|
||||
|
||||
_ = texture.ToArray(x, y, z, width, height, depth);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture3D<>))]
|
||||
@@ -194,6 +252,289 @@ public partial class Texture3DTests
|
||||
texture.CopyTo(result, x, y, z, width, height, depth);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture3D<>))]
|
||||
[Resource(typeof(ReadWriteTexture3D<>))]
|
||||
[AdditionalResource(typeof(ReadOnlyTexture3D<>))]
|
||||
[AdditionalResource(typeof(ReadWriteTexture3D<>))]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 512, 512, 3)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 512, 512, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 1, 0, 0, 0, 512, 512, 2)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 1, 512, 512, 2)]
|
||||
// [Data(512, 512, 4, 512, 512, 4, 0, 0, 1, 0, 0, 2, 512, 512, 2)]
|
||||
// This test fails, only on WARP devices, and only if not run on its own. It seems
|
||||
// to be possibly caused by a bug in ID3D12GraphicsCommandList::CopyTextureRegion.
|
||||
[Data(512, 1024, 3, 512, 512, 3, 127, 256, 1, 128, 128, 1, 128, 256, 1)]
|
||||
[Data(512, 1024, 3, 512, 512, 3, 127, 256, 1, 128, 128, 1, 128, 256, 2)]
|
||||
[Data(512, 1024, 3, 512, 512, 3, 122, 329, 1, 127, 256, 2, 125, 200, 1)]
|
||||
[Data(1024, 1024, 3, 512, 512, 3, 127, 256, 1, 128, 128, 1, 128, 256, 1)]
|
||||
[Data(1024, 1024, 3, 512, 512, 3, 127, 256, 1, 128, 128, 1, 128, 256, 2)]
|
||||
[Data(1024, 1024, 3, 512, 512, 3, 122, 329, 1, 127, 256, 2, 125, 200, 1)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 0, 0, 0, 512, 512, 1)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 512, 0, 0, 512, 512, 1)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 0, 512, 0, 512, 512, 1)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 512, 512, 0, 512, 512, 1)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 0, 0, 0, 512, 512, 2)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 512, 0, 0, 512, 512, 2)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 0, 512, 0, 512, 512, 2)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 512, 512, 0, 512, 512, 2)]
|
||||
public void CopyTo_TextureToVoid_Ok(
|
||||
Device device,
|
||||
Type sourceType,
|
||||
Type destinationType,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
int sourceDepth,
|
||||
int destinationWidth,
|
||||
int destinationHeight,
|
||||
int destinationDepth,
|
||||
int sourceOffsetX,
|
||||
int sourceOffsetY,
|
||||
int sourceOffsetZ,
|
||||
int destinationOffsetX,
|
||||
int destinationOffsetY,
|
||||
int destinationOffsetZ,
|
||||
int copyWidth,
|
||||
int copyHeight,
|
||||
int copyDepth)
|
||||
{
|
||||
float[] array = Enumerable.Range(0, sourceHeight * sourceWidth * sourceDepth).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Texture3D<float> source = device.Get().AllocateTexture3D(sourceType, array, sourceWidth, sourceHeight, sourceDepth);
|
||||
using Texture3D<float> destination = device.Get().AllocateTexture3D<float>(destinationType, destinationWidth, destinationHeight, destinationDepth, AllocationMode.Clear);
|
||||
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, sourceOffsetZ, destinationOffsetX, destinationOffsetY, destinationOffsetZ, copyWidth, copyHeight, copyDepth);
|
||||
|
||||
float[,,] stack = destination.ToArray();
|
||||
|
||||
for (int k = 0; k < destinationDepth; k++)
|
||||
{
|
||||
ReadOnlySpan2D<float> result = new(stack, k);
|
||||
|
||||
for (int i = 0; i < destinationHeight; i++)
|
||||
{
|
||||
for (int j = 0; j < destinationWidth; j++)
|
||||
{
|
||||
if (k >= destinationOffsetZ &&
|
||||
k < destinationOffsetZ + copyDepth &&
|
||||
i >= destinationOffsetY &&
|
||||
i < destinationOffsetY + copyHeight &&
|
||||
j >= destinationOffsetX &&
|
||||
j < destinationOffsetX + copyWidth)
|
||||
{
|
||||
int sourceZ = k - destinationOffsetZ + sourceOffsetZ;
|
||||
int sourceY = i - destinationOffsetY + sourceOffsetY;
|
||||
int sourceX = j - destinationOffsetX + sourceOffsetX;
|
||||
|
||||
ReadOnlySpan2D<float> expected = new(array, sourceZ * sourceHeight * sourceWidth, sourceHeight, sourceWidth, 0);
|
||||
|
||||
Assert.AreEqual(expected[sourceY, sourceX], result[i, j]);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.AreEqual(0, result[i, j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture3D<>))]
|
||||
[Resource(typeof(ReadWriteTexture3D<>))]
|
||||
[AdditionalResource(typeof(ReadOnlyTexture3D<>))]
|
||||
[AdditionalResource(typeof(ReadWriteTexture3D<>))]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 2055, 1024, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, -1, 1024, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, int.MaxValue, 1024, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 256, 1025, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 256, -1, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 256, int.MaxValue, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 256, 128, 6)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 256, 128, -1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 256, 128, int.MaxValue)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 450, 0, 0, 0, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 450, 0, 0, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 5, 0, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 450, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 450, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 4, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, -1, 0, 0, 0, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, -1, 0, 0, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, -1, 0, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, -1, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, -1, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, -1, 128, 128, 1)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void CopyTo_TextureToVoid_Fail(
|
||||
Device device,
|
||||
Type sourceType,
|
||||
Type destinationType,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
int sourceDepth,
|
||||
int destinationWidth,
|
||||
int destinationHeight,
|
||||
int destinationDepth,
|
||||
int sourceOffsetX,
|
||||
int sourceOffsetY,
|
||||
int sourceOffsetZ,
|
||||
int destinationOffsetX,
|
||||
int destinationOffsetY,
|
||||
int destinationOffsetZ,
|
||||
int copyWidth,
|
||||
int copyHeight,
|
||||
int copyDepth)
|
||||
{
|
||||
using Texture3D<float> source = device.Get().AllocateTexture3D<float>(sourceType, sourceWidth, sourceHeight, sourceDepth);
|
||||
using Texture3D<float> destination = device.Get().AllocateTexture3D<float>(destinationType, destinationWidth, destinationHeight, destinationDepth, AllocationMode.Clear);
|
||||
|
||||
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, sourceOffsetZ, destinationOffsetX, destinationOffsetY, destinationOffsetZ, copyWidth, copyHeight, copyDepth);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture3D<>))]
|
||||
[Resource(typeof(ReadWriteTexture3D<>))]
|
||||
[AdditionalResource(typeof(ReadOnlyTexture3D<>))]
|
||||
[AdditionalResource(typeof(ReadWriteTexture3D<>))]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 512, 512, 3)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 512, 512, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 1, 0, 0, 0, 512, 512, 2)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 1, 512, 512, 2)]
|
||||
// [Data(512, 512, 4, 512, 512, 4, 0, 0, 1, 0, 0, 2, 512, 512, 2)]
|
||||
// TODO: see explanation above in CopyTo_TextureToVoid_Ok
|
||||
[Data(512, 1024, 3, 512, 512, 3, 127, 256, 1, 128, 128, 1, 128, 256, 1)]
|
||||
[Data(512, 1024, 3, 512, 512, 3, 127, 256, 1, 128, 128, 1, 128, 256, 2)]
|
||||
[Data(512, 1024, 3, 512, 512, 3, 122, 329, 1, 127, 256, 2, 125, 200, 1)]
|
||||
[Data(1024, 1024, 3, 512, 512, 3, 127, 256, 1, 128, 128, 1, 128, 256, 1)]
|
||||
[Data(1024, 1024, 3, 512, 512, 3, 127, 256, 1, 128, 128, 1, 128, 256, 2)]
|
||||
[Data(1024, 1024, 3, 512, 512, 3, 122, 329, 1, 127, 256, 2, 125, 200, 1)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 0, 0, 0, 512, 512, 1)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 512, 0, 0, 512, 512, 1)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 0, 512, 0, 512, 512, 1)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 512, 512, 0, 512, 512, 1)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 0, 0, 0, 512, 512, 2)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 512, 0, 0, 512, 512, 2)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 0, 512, 0, 512, 512, 2)]
|
||||
[Data(512, 512, 2, 1024, 1024, 3, 0, 0, 0, 512, 512, 0, 512, 512, 2)]
|
||||
public void CopyFrom_TextureToVoid_Ok(
|
||||
Device device,
|
||||
Type sourceType,
|
||||
Type destinationType,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
int sourceDepth,
|
||||
int destinationWidth,
|
||||
int destinationHeight,
|
||||
int destinationDepth,
|
||||
int sourceOffsetX,
|
||||
int sourceOffsetY,
|
||||
int sourceOffsetZ,
|
||||
int destinationOffsetX,
|
||||
int destinationOffsetY,
|
||||
int destinationOffsetZ,
|
||||
int copyWidth,
|
||||
int copyHeight,
|
||||
int copyDepth)
|
||||
{
|
||||
float[] array = Enumerable.Range(0, sourceHeight * sourceWidth * sourceDepth).Select(static i => (float)i).ToArray();
|
||||
|
||||
using Texture3D<float> source = device.Get().AllocateTexture3D(sourceType, array, sourceWidth, sourceHeight, sourceDepth);
|
||||
using Texture3D<float> destination = device.Get().AllocateTexture3D<float>(destinationType, destinationWidth, destinationHeight, destinationDepth, AllocationMode.Clear);
|
||||
|
||||
destination.CopyFrom(source, sourceOffsetX, sourceOffsetY, sourceOffsetZ, destinationOffsetX, destinationOffsetY, destinationOffsetZ, copyWidth, copyHeight, copyDepth);
|
||||
|
||||
float[,,] stack = destination.ToArray();
|
||||
|
||||
for (int k = 0; k < destinationDepth; k++)
|
||||
{
|
||||
ReadOnlySpan2D<float> result = new(stack, k);
|
||||
|
||||
for (int i = 0; i < destinationHeight; i++)
|
||||
{
|
||||
for (int j = 0; j < destinationWidth; j++)
|
||||
{
|
||||
if (k >= destinationOffsetZ &&
|
||||
k < destinationOffsetZ + copyDepth &&
|
||||
i >= destinationOffsetY &&
|
||||
i < destinationOffsetY + copyHeight &&
|
||||
j >= destinationOffsetX &&
|
||||
j < destinationOffsetX + copyWidth)
|
||||
{
|
||||
int sourceZ = k - destinationOffsetZ + sourceOffsetZ;
|
||||
int sourceY = i - destinationOffsetY + sourceOffsetY;
|
||||
int sourceX = j - destinationOffsetX + sourceOffsetX;
|
||||
|
||||
ReadOnlySpan2D<float> expected = new(array, sourceZ * sourceHeight * sourceWidth, sourceHeight, sourceWidth, 0);
|
||||
|
||||
Assert.AreEqual(expected[sourceY, sourceX], result[i, j]);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.AreEqual(0, result[i, j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture3D<>))]
|
||||
[Resource(typeof(ReadWriteTexture3D<>))]
|
||||
[AdditionalResource(typeof(ReadOnlyTexture3D<>))]
|
||||
[AdditionalResource(typeof(ReadWriteTexture3D<>))]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 2055, 1024, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, -1, 1024, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, int.MaxValue, 1024, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 256, 1025, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 256, -1, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 256, int.MaxValue, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 256, 128, 6)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 256, 128, -1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 0, 256, 128, int.MaxValue)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 450, 0, 0, 0, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 450, 0, 0, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 5, 0, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 450, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 450, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, 4, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, -1, 0, 0, 0, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, -1, 0, 0, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, -1, 0, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, -1, 0, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, -1, 0, 128, 128, 1)]
|
||||
[Data(512, 512, 3, 512, 512, 3, 0, 0, 0, 0, 0, -1, 128, 128, 1)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void CopyFrom_TextureToVoid_Fail(
|
||||
Device device,
|
||||
Type sourceType,
|
||||
Type destinationType,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
int sourceDepth,
|
||||
int destinationWidth,
|
||||
int destinationHeight,
|
||||
int destinationDepth,
|
||||
int sourceOffsetX,
|
||||
int sourceOffsetY,
|
||||
int sourceOffsetZ,
|
||||
int destinationOffsetX,
|
||||
int destinationOffsetY,
|
||||
int destinationOffsetZ,
|
||||
int copyWidth,
|
||||
int copyHeight,
|
||||
int copyDepth)
|
||||
{
|
||||
using Texture3D<float> source = device.Get().AllocateTexture3D<float>(sourceType, sourceWidth, sourceHeight, sourceDepth);
|
||||
using Texture3D<float> destination = device.Get().AllocateTexture3D<float>(destinationType, destinationWidth, destinationHeight, destinationDepth, AllocationMode.Clear);
|
||||
|
||||
destination.CopyFrom(source, sourceOffsetX, sourceOffsetY, sourceOffsetZ, destinationOffsetX, destinationOffsetY, destinationOffsetZ, copyWidth, copyHeight, copyDepth);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void Dispatch_ReadOnlyTexture3D(Device device)
|
||||
|
||||
@@ -94,7 +94,7 @@ public partial class TransferBufferTests
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void Allocate_UploadBuffer_Copy_Full(Device device)
|
||||
public void Allocate_UploadBuffer_CopyTo_Full(Device device)
|
||||
{
|
||||
using UploadBuffer<int> uploadBuffer = device.Get().AllocateUploadBuffer<int>(4096);
|
||||
|
||||
@@ -113,10 +113,10 @@ public partial class TransferBufferTests
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Data(0, 0, 4096)]
|
||||
[Data(128, 0, 2048)]
|
||||
[Data(0, 128, 2048)]
|
||||
[Data(97, 33, 512)]
|
||||
public void Allocate_UploadBuffer_Copy_Range(Device device, int destinationOffset, int bufferOffset, int count)
|
||||
[Data(128, 0, 2048)]
|
||||
[Data(33, 97, 512)]
|
||||
public void Allocate_UploadBuffer_CopyTo_Range(Device device, int sourceOffset, int destinationOffset, int count)
|
||||
{
|
||||
using UploadBuffer<int> uploadBuffer = device.Get().AllocateUploadBuffer<int>(4096);
|
||||
|
||||
@@ -124,17 +124,17 @@ public partial class TransferBufferTests
|
||||
|
||||
using ReadOnlyBuffer<int> readOnlyBuffer = device.Get().AllocateReadOnlyBuffer<int>(uploadBuffer.Length);
|
||||
|
||||
uploadBuffer.CopyTo(readOnlyBuffer, destinationOffset, bufferOffset, count);
|
||||
uploadBuffer.CopyTo(readOnlyBuffer, sourceOffset, destinationOffset, count);
|
||||
|
||||
int[] result = readOnlyBuffer.ToArray(destinationOffset, count);
|
||||
|
||||
Assert.AreEqual(result.Length, count);
|
||||
Assert.IsTrue(uploadBuffer.Span.Slice(bufferOffset, count).SequenceEqual(result));
|
||||
Assert.IsTrue(uploadBuffer.Span.Slice(sourceOffset, count).SequenceEqual(result));
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void Allocate_ReadBackBuffer_Copy_Full(Device device)
|
||||
public void Allocate_ReadBackBuffer_CopyTo_Full(Device device)
|
||||
{
|
||||
int[] source = new int[4096];
|
||||
|
||||
@@ -152,10 +152,10 @@ public partial class TransferBufferTests
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Data(0, 0, 4096)]
|
||||
[Data(128, 0, 2048)]
|
||||
[Data(0, 128, 2048)]
|
||||
[Data(97, 33, 512)]
|
||||
public void Allocate_ReadBackBuffer_Copy_Range(Device device, int destinationOffset, int bufferOffset, int count)
|
||||
[Data(128, 0, 2048)]
|
||||
[Data(33, 97, 512)]
|
||||
public void Allocate_ReadBackBuffer_CopyTo_Range(Device device, int sourceOffset, int destinationOffset, int count)
|
||||
{
|
||||
int[] source = new int[4096];
|
||||
|
||||
@@ -164,9 +164,87 @@ 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, sourceOffset, destinationOffset, count);
|
||||
|
||||
Assert.AreEqual(source.Length, readBackBuffer.Length);
|
||||
Assert.IsTrue(source.AsSpan(bufferOffset, count).SequenceEqual(readBackBuffer.Span.Slice(destinationOffset, count)));
|
||||
Assert.IsTrue(source.AsSpan(sourceOffset, count).SequenceEqual(readBackBuffer.Span.Slice(destinationOffset, count)));
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void Allocate_UploadBuffer_CopyFrom_Full(Device device)
|
||||
{
|
||||
using UploadBuffer<int> uploadBuffer = device.Get().AllocateUploadBuffer<int>(4096);
|
||||
|
||||
new Random(42).NextBytes(uploadBuffer.Span.AsBytes());
|
||||
|
||||
using ReadOnlyBuffer<int> readOnlyBuffer = device.Get().AllocateReadOnlyBuffer<int>(uploadBuffer.Length);
|
||||
|
||||
readOnlyBuffer.CopyFrom(uploadBuffer);
|
||||
|
||||
int[] result = readOnlyBuffer.ToArray();
|
||||
|
||||
Assert.AreEqual(uploadBuffer.Length, result.Length);
|
||||
Assert.IsTrue(uploadBuffer.Span.SequenceEqual(result));
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Data(0, 0, 4096)]
|
||||
[Data(0, 128, 2048)]
|
||||
[Data(128, 0, 2048)]
|
||||
[Data(33, 97, 512)]
|
||||
public void Allocate_UploadBuffer_CopyFrom_Range(Device device, int sourceOffset, int destinationOffset, int count)
|
||||
{
|
||||
using UploadBuffer<int> uploadBuffer = device.Get().AllocateUploadBuffer<int>(4096);
|
||||
|
||||
new Random(42).NextBytes(uploadBuffer.Span.AsBytes());
|
||||
|
||||
using ReadOnlyBuffer<int> readOnlyBuffer = device.Get().AllocateReadOnlyBuffer<int>(uploadBuffer.Length);
|
||||
|
||||
readOnlyBuffer.CopyFrom(uploadBuffer, sourceOffset, destinationOffset, count);
|
||||
|
||||
int[] result = readOnlyBuffer.ToArray(destinationOffset, count);
|
||||
|
||||
Assert.AreEqual(result.Length, count);
|
||||
Assert.IsTrue(uploadBuffer.Span.Slice(sourceOffset, count).SequenceEqual(result));
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void Allocate_ReadBackBuffer_CopyFrom_Full(Device device)
|
||||
{
|
||||
int[] source = new int[4096];
|
||||
|
||||
new Random(42).NextBytes(source.AsSpan().AsBytes());
|
||||
|
||||
using ReadOnlyBuffer<int> readOnlyBuffer = device.Get().AllocateReadOnlyBuffer(source);
|
||||
using ReadBackBuffer<int> readBackBuffer = device.Get().AllocateReadBackBuffer<int>(readOnlyBuffer.Length);
|
||||
|
||||
readBackBuffer.CopyFrom(readOnlyBuffer);
|
||||
|
||||
Assert.AreEqual(source.Length, readBackBuffer.Length);
|
||||
Assert.IsTrue(source.AsSpan().SequenceEqual(readBackBuffer.Span));
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Data(0, 0, 4096)]
|
||||
[Data(0, 128, 2048)]
|
||||
[Data(128, 0, 2048)]
|
||||
[Data(33, 97, 512)]
|
||||
public void Allocate_ReadBackBuffer_CopyFrom_Range(Device device, int sourceOffset, int destinationOffset, int count)
|
||||
{
|
||||
int[] source = new int[4096];
|
||||
|
||||
new Random(42).NextBytes(source.AsSpan().AsBytes());
|
||||
|
||||
using ReadOnlyBuffer<int> readOnlyBuffer = device.Get().AllocateReadOnlyBuffer(source);
|
||||
using ReadBackBuffer<int> readBackBuffer = device.Get().AllocateReadBackBuffer<int>(readOnlyBuffer.Length);
|
||||
|
||||
readBackBuffer.CopyFrom(readOnlyBuffer, sourceOffset, destinationOffset, count);
|
||||
|
||||
Assert.AreEqual(source.Length, readBackBuffer.Length);
|
||||
Assert.IsTrue(source.AsSpan(sourceOffset, count).SequenceEqual(readBackBuffer.Span.Slice(destinationOffset, count)));
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする