diff --git a/src/ComputeSharp/Core/Helpers/AlignmentHelper.cs b/src/ComputeSharp/Core/Helpers/AlignmentHelper.cs
index 7ea5a097..846d2a6b 100644
--- a/src/ComputeSharp/Core/Helpers/AlignmentHelper.cs
+++ b/src/ComputeSharp/Core/Helpers/AlignmentHelper.cs
@@ -21,6 +21,19 @@ internal static class AlignmentHelper
return (size + alignment - 1) & ~(alignment - 1);
}
+ ///
+ /// Pads the input size so that its pitch is aligned to a multiple of a specified length.
+ ///
+ /// The input size to pad, if needed.
+ /// The target alignment.
+ /// The padded value relative to the given inputs.
+ [Pure]
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static nint Pad(nint size, nint alignment)
+ {
+ return (size + alignment - 1) & ~(alignment - 1);
+ }
+
///
/// Aligns a given offset to a specified boundary, if a given size increment would have crossed it.
///
diff --git a/src/ComputeSharp/Graphics/Extensions/BufferExtensions.cs b/src/ComputeSharp/Graphics/Extensions/BufferExtensions.cs
index edaaac86..90707aec 100644
--- a/src/ComputeSharp/Graphics/Extensions/BufferExtensions.cs
+++ b/src/ComputeSharp/Graphics/Extensions/BufferExtensions.cs
@@ -15,32 +15,32 @@ public static class BufferExtensions
/// Reads the contents of a instance and returns an array.
///
/// The type of items stored on the buffer.
- /// The input instance to read data from.
+ /// The input instance to read data from.
/// A array with the contents of the input buffer.
[Pure]
- public static T[] ToArray(this Buffer buffer)
+ public static T[] ToArray(this Buffer source)
where T : unmanaged
{
- return buffer.ToArray(0, buffer.Length);
+ return source.ToArray(0, source.Length);
}
///
/// Reads the contents of a instance in a given range and returns an array.
///
/// The type of items stored on the buffer.
- /// The input instance to read data from.
+ /// The input instance to read data from.
/// The offset to start reading data from.
/// The number of items to read.
/// A array with the contents of the specified range from the current buffer.
[Pure]
- public static T[] ToArray(this Buffer buffer, int offset, int count)
+ public static T[] ToArray(this Buffer source, int offset, int count)
where T : unmanaged
{
Guard.IsGreaterThanOrEqualTo(count, 0, nameof(count));
T[] data = GC.AllocateUninitializedArray(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 instance and writes them into a target array.
///
/// The type of items stored on the buffer.
- /// The input instance to read data from.
+ /// The input instance to read data from.
/// The input array to write data to.
- public static void CopyTo(this Buffer buffer, T[] destination)
+ public static void CopyTo(this Buffer source, T[] destination)
where T : unmanaged
{
- buffer.CopyTo(destination.AsSpan(), 0);
+ source.CopyTo(destination.AsSpan(), 0);
}
///
/// Reads the contents of the specified range from a instance and writes them into a target array.
///
/// The type of items stored on the buffer.
- /// The input instance to read data from.
+ /// The input instance to read data from.
/// The input array to write data to.
+ /// The offset to start reading data from.
/// The starting offset within to write data to.
- /// The offset to start reading data from.
/// The number of items to read.
- public static void CopyTo(this Buffer buffer, T[] destination, int destinationOffset, int bufferOffset, int count)
+ public static void CopyTo(this Buffer source, T[] destination, int sourceOffset, int destinationOffset, int count)
where T : unmanaged
{
Span span = destination.AsSpan(destinationOffset, count);
- buffer.CopyTo(span, bufferOffset);
+ source.CopyTo(span, sourceOffset);
}
///
/// Reads the contents of a instance and writes them into a target .
///
/// The type of items stored on the buffer.
- /// The input instance to read data from.
+ /// The input instance to read data from.
/// The input to write data to.
- public static void CopyTo(this Buffer buffer, Span destination)
+ public static void CopyTo(this Buffer source, Span destination)
where T : unmanaged
{
- buffer.CopyTo(destination, 0);
+ source.CopyTo(destination, 0);
}
///
/// Reads the contents of the specified range from a instance and writes them into a target .
///
/// The type of items stored on the buffer.
- /// The input instance to read data from.
+ /// The input instance to read data from.
/// The input to write data to.
- /// The offset to start reading data from.
- public static void CopyTo(this Buffer buffer, Span destination, int offset)
+ /// The offset to start reading data from.
+ public static void CopyTo(this Buffer source, Span destination, int sourceOffset)
where T : unmanaged
{
- buffer.CopyTo(ref MemoryMarshal.GetReference(destination), destination.Length, offset);
+ source.CopyTo(ref MemoryMarshal.GetReference(destination), sourceOffset, destination.Length);
+ }
+
+ ///
+ /// Reads the contents of the specified instance and copies them to the target instance.
+ ///
+ /// The type of items stored on the buffers.
+ /// The input instance to read data from.
+ /// The target instance to write data to.
+ public static void CopyTo(this Buffer source, Buffer destination)
+ where T : unmanaged
+ {
+ source.CopyTo(destination, 0, 0, source.Length);
+ }
+
+ ///
+ /// Reads the contents of the specified range from a instance and copies them to the target instance.
+ ///
+ /// The type of items stored on the buffers.
+ /// The input instance to read data from.
+ /// The target instance to write data to.
+ /// The offset to start reading data from.
+ /// The starting offset within to write data to.
+ /// The number of items to read.
+ public static void CopyTo(this Buffer source, Buffer destination, int sourceOffset, int destinationOffset, int count)
+ where T : unmanaged
+ {
+ source.CopyTo(destination, sourceOffset, destinationOffset, count);
}
///
/// Writes the contents of a given array to a instance.
///
/// The type of items stored on the buffer.
- /// The target instance to write data to.
+ /// The target instance to write data to.
/// The input array to read data from.
- public static void CopyFrom(this Buffer buffer, T[] source)
+ public static void CopyFrom(this Buffer destination, T[] source)
where T : unmanaged
{
- buffer.CopyFrom(source.AsSpan(), 0);
+ destination.CopyFrom(source.AsSpan(), 0);
}
///
/// Writes the contents of a given array to a specified area of a instance.
///
/// The type of items stored on the buffer.
- /// The target instance to write data to.
+ /// The target instance to write data to.
/// The input array to read data from.
/// The starting offset within to read data from.
- /// The offset to start writing data to.
+ /// The offset to start writing data to.
/// The number of items to write.
- public static void CopyFrom(this Buffer buffer, T[] source, int sourceOffset, int bufferOffset, int count)
+ public static void CopyFrom(this Buffer destination, T[] source, int sourceOffset, int destinationOffset, int count)
where T : unmanaged
{
ReadOnlySpan span = source.AsSpan(sourceOffset, count);
- buffer.CopyFrom(span, bufferOffset);
+ destination.CopyFrom(span, destinationOffset);
}
///
/// Writes the contents of a given to a instance.
///
/// The type of items stored on the buffer.
- /// The target instance to write data to.
+ /// The target instance to write data to.
/// The input to read data from.
- public static void CopyFrom(this Buffer buffer, ReadOnlySpan source)
+ public static void CopyFrom(this Buffer destination, ReadOnlySpan source)
where T : unmanaged
{
- buffer.CopyFrom(source, 0);
+ destination.CopyFrom(source, 0);
}
///
/// Writes the contents of a given to a specified area of a instance.
///
/// The type of items stored on the buffer.
- /// The target instance to write data to.
+ /// The target instance to write data to.
/// The input to read data from.
- /// The offset to start writing data to.
- public static void CopyFrom(this Buffer buffer, ReadOnlySpan source, int offset)
+ /// The offset to start writing data to.
+ public static void CopyFrom(this Buffer destination, ReadOnlySpan source, int destinationOffset)
where T : unmanaged
{
- buffer.CopyFrom(ref MemoryMarshal.GetReference(source), source.Length, offset);
+ destination.CopyFrom(ref MemoryMarshal.GetReference(source), destinationOffset, source.Length);
+ }
+
+ ///
+ /// Writes the contents of the specified instance to the curreent instance.
+ ///
+ /// The type of items stored on the buffers.
+ /// The input instance to write data data to.
+ /// The source instance to read data from.
+ public static void CopyFrom(this Buffer destination, Buffer source)
+ where T : unmanaged
+ {
+ source.CopyTo(destination, 0, 0, source.Length);
+ }
+
+ ///
+ /// Writes the contents of the specified range from a instance and copies them to the current instance.
+ ///
+ /// The type of items stored on the buffers.
+ /// The input instance to write data to.
+ /// The source instance to read data from.
+ /// The offset to start reading data from.
+ /// The starting offset within to write data to.
+ /// The number of items to read.
+ public static void CopyFrom(this Buffer destination, Buffer source, int sourceOffset, int destinationOffset, int count)
+ where T : unmanaged
+ {
+ source.CopyTo(destination, sourceOffset, destinationOffset, count);
}
}
diff --git a/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12GraphicsCommandListExtensions.cs b/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12GraphicsCommandListExtensions.cs
index 0027ade5..25f7a512 100644
--- a/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12GraphicsCommandListExtensions.cs
+++ b/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12GraphicsCommandListExtensions.cs
@@ -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);
}
+ ///
+ /// Copies a texture memory region from one texture to another.
+ ///
+ /// The instance in use.
+ /// The destination (a buffer) to write to.
+ /// The horizontal offset in the destination buffer.
+ /// The vertical offset in the destination buffer.
+ /// The depthwise offset in the destination buffer.
+ /// The source (a texture) to read from.
+ /// The horizontal offset in the source texture.
+ /// The vertical offset in the source texture.
+ /// The depthwise offset in the source texture.
+ /// The width of the memory area to read from.
+ /// The height of the memory area to read from.
+ /// The depth of the memory area to read from.
+ 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);
+ }
+
///
/// Creates a resource barrier to transition a resource to a specific state.
///
diff --git a/src/ComputeSharp/Graphics/Extensions/ReadBackBufferExtensions.cs b/src/ComputeSharp/Graphics/Extensions/ReadBackBufferExtensions.cs
new file mode 100644
index 00000000..ba0f8009
--- /dev/null
+++ b/src/ComputeSharp/Graphics/Extensions/ReadBackBufferExtensions.cs
@@ -0,0 +1,36 @@
+using ComputeSharp.Resources;
+
+namespace ComputeSharp;
+
+///
+/// A that contains extension methods for the type.
+///
+public static class ReadBackBufferExtensions
+{
+ ///
+ /// Reads the contents of a instance and writes them into a target instance.
+ ///
+ /// The type of items stored on the buffer.
+ /// The target instance to write data to.
+ /// The input instance to read data from.
+ public static void CopyFrom(this ReadBackBuffer destination, StructuredBuffer source)
+ where T : unmanaged
+ {
+ source.CopyTo(destination, 0, 0, source.Length);
+ }
+
+ ///
+ /// Reads the contents of a instance and writes them into a target instance.
+ ///
+ /// The type of items stored on the buffer.
+ /// The target instance to write data to.
+ /// The input instance to read data from.
+ /// The offset to start reading data from.
+ /// The starting offset within to write data to.
+ /// The number of items to read.
+ public static void CopyFrom(this ReadBackBuffer destination, StructuredBuffer source, int sourceOffset, int destinationOffset, int count)
+ where T : unmanaged
+ {
+ source.CopyTo(destination, sourceOffset, destinationOffset, count);
+ }
+}
diff --git a/src/ComputeSharp/Graphics/Extensions/ReadBackTexture2DExtensions.cs b/src/ComputeSharp/Graphics/Extensions/ReadBackTexture2DExtensions.cs
index 8f08ebb9..8d855bfb 100644
--- a/src/ComputeSharp/Graphics/Extensions/ReadBackTexture2DExtensions.cs
+++ b/src/ComputeSharp/Graphics/Extensions/ReadBackTexture2DExtensions.cs
@@ -1,5 +1,6 @@
using System;
using ComputeSharp.Graphics.Helpers;
+using ComputeSharp.Resources;
namespace ComputeSharp;
@@ -8,6 +9,52 @@ namespace ComputeSharp;
///
public static class ReadBackTexture2DExtensions
{
+ ///
+ /// Reads the contents of a instance and writes them into a target instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input instance to read data from.
+ public static void CopyFrom(this ReadBackTexture2D destination, Texture2D source)
+ where T : unmanaged
+ {
+ source.CopyTo(destination, 0, 0, 0, 0, source.Width, source.Height);
+ }
+
+ ///
+ /// Reads the contents of a instance and writes them into a target instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input instance to read data from.
+ /// The horizontal offset in the source texture.
+ /// The vertical offset in the source texture.
+ /// The width of the memory area to copy.
+ /// The height of the memory area to copy.
+ public static void CopyFrom(this ReadBackTexture2D destination, Texture2D source, int sourceOffsetX, int sourceOffsetY, int width, int height)
+ where T : unmanaged
+ {
+ source.CopyTo(destination, sourceOffsetX, sourceOffsetY, 0, 0, width, height);
+ }
+
+ ///
+ /// Reads the contents of a instance and writes them into a target instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input instance to read data from.
+ /// The horizontal offset in the source texture.
+ /// The vertical offset in the source texture.
+ /// The horizontal offset in the destination texture.
+ /// The vertical offset in the destination texture.
+ /// The width of the memory area to copy.
+ /// The height of the memory area to copy.
+ public static void CopyFrom(this ReadBackTexture2D destination, Texture2D 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);
+ }
+
///
/// Saves a texture to a specified file.
///
diff --git a/src/ComputeSharp/Graphics/Extensions/ReadBackTexture3DExtensions.cs b/src/ComputeSharp/Graphics/Extensions/ReadBackTexture3DExtensions.cs
new file mode 100644
index 00000000..80024868
--- /dev/null
+++ b/src/ComputeSharp/Graphics/Extensions/ReadBackTexture3DExtensions.cs
@@ -0,0 +1,60 @@
+using ComputeSharp.Resources;
+
+namespace ComputeSharp;
+
+///
+/// A that contains extension methods for the type.
+///
+public static class ReadBackTexture3DExtensions
+{
+ ///
+ /// Reads the contents of a instance and writes them into a target instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input instance to read data from.
+ public static void CopyFrom(this ReadBackTexture3D destination, Texture3D source)
+ where T : unmanaged
+ {
+ source.CopyTo(destination, 0, 0, 0, 0, 0, 0, source.Width, source.Height, source.Depth);
+ }
+
+ ///
+ /// Reads the contents of a instance and writes them into a target instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input instance to read data from.
+ /// The horizontal offset in the source texture.
+ /// The vertical offset in the source texture.
+ /// The depthwise offset in the source texture.
+ /// The width of the memory area to copy.
+ /// The height of the memory area to copy.
+ /// The depth of the memory area to copy.
+ public static void CopyFrom(this ReadBackTexture3D destination, Texture3D 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);
+ }
+
+ ///
+ /// Reads the contents of a instance and writes them into a target instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input instance to read data from.
+ /// The horizontal offset in the source texture.
+ /// The vertical offset in the source texture.
+ /// The depthwise offset in the source texture.
+ /// The horizontal offset in the destination texture.
+ /// The vertical offset in the destination texture.
+ /// The depthwise offset in the destination texture.
+ /// The width of the memory area to copy.
+ /// The height of the memory area to copy.
+ /// The depth of the memory area to copy.
+ public static void CopyFrom(this ReadBackTexture3D destination, Texture3D 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);
+ }
+}
diff --git a/src/ComputeSharp/Graphics/Extensions/StructuredBufferExtensions.cs b/src/ComputeSharp/Graphics/Extensions/StructuredBufferExtensions.cs
index bde72b1f..8d97bd5f 100644
--- a/src/ComputeSharp/Graphics/Extensions/StructuredBufferExtensions.cs
+++ b/src/ComputeSharp/Graphics/Extensions/StructuredBufferExtensions.cs
@@ -11,26 +11,53 @@ public static class StructuredBufferExtensions
/// Reads the contents of a instance and writes them into a target instance.
///
/// The type of items stored on the buffer.
- /// The input instance to read data from.
+ /// The input instance to read data from.
/// The target instance to write data to.
- public static void CopyTo(this StructuredBuffer buffer, ReadBackBuffer destination)
+ public static void CopyTo(this StructuredBuffer source, ReadBackBuffer destination)
where T : unmanaged
{
- buffer.CopyTo(destination, 0, buffer.Length, 0);
+ source.CopyTo(destination, 0, 0, source.Length);
}
///
/// Reads the contents of a instance and writes them into a target instance.
///
/// The type of items stored on the buffer.
- /// The input instance to read data from.
+ /// The input instance to read data from.
/// The target instance to write data to.
+ /// The offset to start reading data from.
/// The starting offset within to write data to.
- /// The offset to start reading data from.
/// The number of items to read.
- public static void CopyTo(this StructuredBuffer buffer, ReadBackBuffer destination, int destinationOffset, int bufferOffset, int count)
+ public static void CopyTo(this StructuredBuffer source, ReadBackBuffer destination, int sourceOffset, int destinationOffset, int count)
where T : unmanaged
{
- buffer.CopyTo(destination, destinationOffset, count, bufferOffset);
+ source.CopyTo(destination, sourceOffset, destinationOffset, count);
+ }
+
+ ///
+ /// Reads the contents of an instance and writes them into a target instance.
+ ///
+ /// The type of items stored on the buffer.
+ /// The target instance to write data to.
+ /// The input instance to read data from.
+ public static void CopyFrom(this StructuredBuffer destination, UploadBuffer source)
+ where T : unmanaged
+ {
+ source.CopyTo(destination, 0, 0, source.Length);
+ }
+
+ ///
+ /// Reads the contents of an instance and writes them into a target instance.
+ ///
+ /// The type of items stored on the buffer.
+ /// The target instance to write data to.
+ /// The input instance to read data from.
+ /// The offset to start reading data from.
+ /// The starting offset within to write data to.
+ /// The number of items to read.
+ public static void CopyFrom(this StructuredBuffer destination, UploadBuffer source, int sourceOffset, int destinationOffset, int count)
+ where T : unmanaged
+ {
+ source.CopyTo(destination, sourceOffset, destinationOffset, count);
}
}
diff --git a/src/ComputeSharp/Graphics/Extensions/Texture2DExtensions.cs b/src/ComputeSharp/Graphics/Extensions/Texture2DExtensions.cs
index 330a81d2..fe671afa 100644
--- a/src/ComputeSharp/Graphics/Extensions/Texture2DExtensions.cs
+++ b/src/ComputeSharp/Graphics/Extensions/Texture2DExtensions.cs
@@ -16,15 +16,42 @@ public static class Texture2DExtensions
/// Reads the contents of the current instance and returns an array.
///
/// The type of items stored on the texture.
- /// The input instance to read data from.
+ /// The input instance to read data from.
/// A array with the contents of the current texture.
[Pure]
- public static T[,] ToArray(this Texture2D texture)
+ public static T[,] ToArray(this Texture2D 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;
+ }
+
+ ///
+ /// Reads the contents of the current instance and returns an array.
+ ///
+ /// The type of items stored on the texture.
+ /// The input instance to read data from.
+ /// The horizontal offset in the source texture.
+ /// The vertical offset in the source texture.
+ /// The width of the memory area to copy.
+ /// The height of the memory area to copy.
+ /// A array with the contents of the current texture.
+ [Pure]
+ public static unsafe T[,] ToArray(this Texture2D 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(p, width * height), x, y, width, height);
+ }
return data;
}
@@ -33,102 +60,102 @@ public static class Texture2DExtensions
/// Reads the contents of the current instance and writes them into a target array.
///
/// The type of items stored on the texture.
- /// The input instance to read data from.
+ /// The input instance to read data from.
/// The input array to write data to.
- public static void CopyTo(this Texture2D texture, T[,] destination)
+ public static void CopyTo(this Texture2D 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);
}
///
/// Reads the contents of the specified range from the current instance and writes them into a target array.
///
/// The type of items stored on the texture.
- /// The input instance to read data from.
+ /// The input instance to read data from.
/// The input array to write data to.
- public static void CopyTo(this Texture2D texture, T[] destination)
+ public static void CopyTo(this Texture2D 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);
}
///
/// Reads the contents of the specified range from the current instance and writes them into a target array.
///
/// The type of items stored on the texture.
- /// The input instance to read data from.
+ /// The input instance to read data from.
/// The input array to write data to.
/// The horizontal range of items to copy.
/// The vertical range of items to copy.
- public static void CopyTo(this Texture2D texture, T[] destination, Range x, Range y)
+ public static void CopyTo(this Texture2D source, T[] destination, Range x, Range y)
where T : unmanaged
{
- texture.CopyTo(destination.AsSpan(), x, y);
+ source.CopyTo(destination.AsSpan(), x, y);
}
///
/// Reads the contents of the specified range from the current instance and writes them into a target array.
///
/// The type of items stored on the texture.
- /// The input instance to read data from.
+ /// The input instance to read data from.
/// The input array to write data to.
- /// The horizontal offset in the source texture.
- /// The vertical offset in the source texture.
+ /// The horizontal offset in the source texture.
+ /// The vertical offset in the source texture.
/// The width of the memory area to copy.
/// The height of the memory area to copy.
- public static void CopyTo(this Texture2D texture, T[] destination, int x, int y, int width, int height)
+ public static void CopyTo(this Texture2D 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);
}
///
/// Reads the contents of the specified range from the current instance and writes them into a target array.
///
/// The type of items stored on the texture.
- /// The input instance to read data from.
+ /// The input instance to read data from.
/// The input array to write data to.
- /// The starting offset within to write data to.
- public static void CopyTo(this Texture2D texture, T[] destination, int offset)
+ /// The starting offset within to write data to.
+ public static void CopyTo(this Texture2D 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);
}
///
/// Reads the contents of the specified range from the current instance and writes them into a target array.
///
/// The type of items stored on the texture.
- /// The input instance to read data from.
+ /// The input instance to read data from.
/// The input array to write data to.
- /// The starting offset within to write data to.
+ /// The starting offset within to write data to.
/// The horizontal range of items to copy.
/// The vertical range of items to copy.
- public static void CopyTo(this Texture2D texture, T[] destination, int offset, Range x, Range y)
+ public static void CopyTo(this Texture2D 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);
}
///
/// Reads the contents of the specified range from the current instance and writes them into a target array.
///
/// The type of items stored on the texture.
- /// The input instance to read data from.
+ /// The input instance to read data from.
/// The input array to write data to.
- /// The starting offset within to write data to.
- /// The horizontal offset in the source texture.
- /// The vertical offset in the source texture.
+ /// The starting offset within to write data to.
+ /// The horizontal offset in the source texture.
+ /// The vertical offset in the source texture.
/// The width of the memory area to copy.
/// The height of the memory area to copy.
- public static void CopyTo(this Texture2D texture, T[] destination, int offset, int x, int y, int width, int height)
+ public static void CopyTo(this Texture2D 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);
}
///
@@ -136,162 +163,226 @@ public static class Texture2DExtensions
/// The input data will be read from the start of the texture.
///
/// The type of items stored on the texture.
- /// The input instance to read data from.
+ /// The input instance to read data from.
/// The input to write data to.
- public static void CopyTo(this Texture2D texture, Span destination)
+ public static void CopyTo(this Texture2D source, Span destination)
where T : unmanaged
{
- texture.CopyTo(destination, 0, 0, texture.Width, texture.Height);
+ source.CopyTo(destination, 0, 0, source.Width, source.Height);
}
///
/// Reads the contents of the specified range from the current instance and writes them into a target .
///
/// The type of items stored on the texture.
- /// The input instance to read data from.
+ /// The input instance to read data from.
/// The input to write data to.
/// The horizontal range of items to copy.
/// The vertical range of items to copy.
- public static void CopyTo(this Texture2D texture, Span destination, Range x, Range y)
+ public static void CopyTo(this Texture2D source, Span 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);
}
///
/// Reads the contents of the specified range from the current instance and writes them into a target .
///
/// The type of items stored on the texture.
- /// The input instance to read data from.
+ /// The input instance to read data from.
/// The input to write data to.
- /// The horizontal offset in the source texture.
- /// The vertical offset in the source texture.
+ /// The horizontal offset in the source texture.
+ /// The vertical offset in the source texture.
/// The width of the memory area to copy.
/// The height of the memory area to copy.
- public static void CopyTo(this Texture2D texture, Span destination, int x, int y, int width, int height)
+ public static void CopyTo(this Texture2D source, Span 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);
+ }
+
+ ///
+ /// Reads the contents of a instance and writes them into a target instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The input instance to read data from.
+ /// The target instance to write data to.
+ public static void CopyTo(this Texture2D source, Texture2D destination)
+ where T : unmanaged
+ {
+ source.CopyTo(destination, 0, 0, 0, 0, source.Width, source.Height);
+ }
+
+ ///
+ /// Reads the contents of a instance and writes them into a target instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The input instance to read data from.
+ /// The target instance to write data to.
+ /// The horizontal offset in the source texture.
+ /// The vertical offset in the source texture.
+ /// The width of the memory area to copy.
+ /// The height of the memory area to copy.
+ public static void CopyTo(this Texture2D source, Texture2D destination, int sourceOffsetX, int sourceOffsetY, int width, int height)
+ where T : unmanaged
+ {
+ source.CopyTo(destination, sourceOffsetX, sourceOffsetY, 0, 0, width, height);
+ }
+
+ ///
+ /// Reads the contents of a instance and writes them into a target instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The input instance to read data from.
+ /// The target instance to write data to.
+ /// The horizontal offset in the source texture.
+ /// The vertical offset in the source texture.
+ /// The horizontal offset in the destination texture.
+ /// The vertical offset in the destination texture.
+ /// The width of the memory area to copy.
+ /// The height of the memory area to copy.
+ public static void CopyTo(this Texture2D source, Texture2D 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);
}
///
/// Reads the contents of a instance and writes them into a target instance.
///
/// The type of items stored on the texture.
- /// The input instance to read data from.
+ /// The input instance to read data from.
/// The target instance to write data to.
- public static void CopyTo(this Texture2D texture, ReadBackTexture2D destination)
+ public static void CopyTo(this Texture2D source, ReadBackTexture2D 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);
}
///
/// Reads the contents of a instance and writes them into a target instance.
///
/// The type of items stored on the texture.
- /// The input instance to read data from.
+ /// The input instance to read data from.
/// The target instance to write data to.
- /// The horizontal offset in the source texture.
- /// The vertical offset in the source texture.
+ /// The horizontal offset in the source texture.
+ /// The vertical offset in the source texture.
/// The width of the memory area to copy.
/// The height of the memory area to copy.
- public static void CopyTo(this Texture2D texture, ReadBackTexture2D destination, int x, int y, int width, int height)
+ public static void CopyTo(this Texture2D source, ReadBackTexture2D 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);
+ }
+
+ ///
+ /// Reads the contents of a instance and writes them into a target instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The input instance to read data from.
+ /// The target instance to write data to.
+ /// The horizontal offset in the source texture.
+ /// The vertical offset in the source texture.
+ /// The horizontal offset in the destination texture.
+ /// The vertical offset in the destination texture.
+ /// The width of the memory area to copy.
+ /// The height of the memory area to copy.
+ public static void CopyTo(this Texture2D source, ReadBackTexture2D 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);
}
///
/// Writes the contents of a given array to the current instance.
///
/// The type of items stored on the texture.
- /// The target instance to write data to.
+ /// The target instance to write data to.
/// The input array to read data from.
- public static unsafe void CopyFrom(this Texture2D texture, T[,] source)
+ public static unsafe void CopyFrom(this Texture2D 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);
}
///
/// Writes the contents of a given array to the current instance.
///
/// The type of items stored on the texture.
- /// The target instance to write data to.
+ /// The target instance to write data to.
/// The input array to read data from.
- public static void CopyFrom(this Texture2D texture, T[] source)
+ public static void CopyFrom(this Texture2D 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);
}
///
/// Writes the contents of a given array to a specified area of the current instance.
///
/// The type of items stored on the texture.
- /// The target instance to write data to.
+ /// The target instance to write data to.
/// The input array to read data from.
/// The horizontal range of items to write.
/// The vertical range of items to write.
- public static void CopyFrom(this Texture2D texture, T[] source, Range x, Range y)
+ public static void CopyFrom(this Texture2D destination, T[] source, Range x, Range y)
where T : unmanaged
{
- texture.CopyFrom(source.AsSpan(), x, y);
+ destination.CopyFrom(source.AsSpan(), x, y);
}
///
/// Writes the contents of a given array to a specified area of the current instance.
///
/// The type of items stored on the texture.
- /// The target instance to write data to.
+ /// The target instance to write data to.
/// The input array to read data from.
- /// The horizontal offset in the destination texture.
- /// The vertical offset in the destination texture.
+ /// The horizontal offset in the destination texture.
+ /// The vertical offset in the destination texture.
/// The width of the memory area to write to.
/// The height of the memory area to write to.
- public static void CopyFrom(this Texture2D texture, T[] source, int x, int y, int width, int height)
+ public static void CopyFrom(this Texture2D 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);
}
///
/// Writes the contents of a given array to a specified area of the current instance.
///
/// The type of items stored on the texture.
- /// The target instance to write data to.
+ /// The target instance to write data to.
/// The input array to read data from.
- /// The starting offset within to read data from.
+ /// The starting offset within to read data from.
/// The horizontal range of items to write.
/// The vertical range of items to write.
- public static void CopyFrom(this Texture2D texture, T[] source, int offset, Range x, Range y)
+ public static void CopyFrom(this Texture2D 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);
}
///
/// Writes the contents of a given array to a specified area of the current instance.
///
/// The type of items stored on the texture.
- /// The target instance to write data to.
+ /// The target instance to write data to.
/// The input array to read data from.
- /// The starting offset within to read data from.
- /// The horizontal offset in the destination texture.
- /// The vertical offset in the destination texture.
+ /// The starting offset within to read data from.
+ /// The horizontal offset in the destination texture.
+ /// The vertical offset in the destination texture.
/// The width of the memory area to write to.
/// The height of the memory area to write to.
- public static void CopyFrom(this Texture2D texture, T[] source, int offset, int x, int y, int width, int height)
+ public static void CopyFrom(this Texture2D 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);
}
///
@@ -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.
///
/// The type of items stored on the texture.
- /// The target instance to write data to.
+ /// The target instance to write data to.
/// The input to read data from.
- public static void CopyFrom(this Texture2D texture, ReadOnlySpan source)
+ public static void CopyFrom(this Texture2D destination, ReadOnlySpan source)
where T : unmanaged
{
- texture.CopyFrom(source, 0, 0, texture.Width, texture.Height);
+ destination.CopyFrom(source, 0, 0, destination.Width, destination.Height);
}
///
/// Writes the contents of a given to a specified area of the current instance.
///
/// The type of items stored on the texture.
- /// The target instance to write data to.
+ /// The target instance to write data to.
/// The input to read data from.
/// The horizontal range of items to write.
/// The vertical range of items to write.
- public static void CopyFrom(this Texture2D texture, ReadOnlySpan source, Range x, Range y)
+ public static void CopyFrom(this Texture2D destination, ReadOnlySpan 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);
}
///
/// Writes the contents of a given to a specified area of the current instance.
///
/// The type of items stored on the texture.
- /// The target instance to write data to.
+ /// The target instance to write data to.
/// The input to read data from.
- /// The horizontal offset in the destination texture.
- /// The vertical offset in the destination texture.
+ /// The horizontal offset in the destination texture.
+ /// The vertical offset in the destination texture.
/// The width of the memory area to write to.
/// The height of the memory area to write to.
- public static void CopyFrom(this Texture2D texture, ReadOnlySpan source, int x, int y, int width, int height)
+ public static void CopyFrom(this Texture2D destination, ReadOnlySpan 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);
+ }
+
+ ///
+ /// Reads the contents of an instance and writes them into a target instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input instance to read data from.
+ public static void CopyFrom(this Texture2D destination, Texture2D source)
+ where T : unmanaged
+ {
+ destination.CopyFrom(source, 0, 0, 0, 0, source.Width, source.Height);
+ }
+
+ ///
+ /// Reads the contents of an instance and writes them into a target instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input instance to read data from.
+ /// The horizontal offset in the source texture.
+ /// The vertical offset in the source texture.
+ /// The width of the memory area to copy.
+ /// The height of the memory area to copy.
+ public static void CopyFrom(this Texture2D destination, Texture2D source, int sourceOffsetX, int sourceOffsetY, int width, int height)
+ where T : unmanaged
+ {
+ source.CopyTo(destination, sourceOffsetX, sourceOffsetY, 0, 0, width, height);
+ }
+
+ ///
+ /// Reads the contents of an instance and writes them into a target instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input instance to read data from.
+ /// The horizontal offset in the source texture.
+ /// The vertical offset in the source texture.
+ /// The horizontal offset in the destination texture.
+ /// The vertical offset in the destination texture.
+ /// The width of the memory area to copy.
+ /// The height of the memory area to copy.
+ public static void CopyFrom(this Texture2D destination, Texture2D 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);
+ }
+
+ ///
+ /// Reads the contents of an instance and writes them into a target instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input instance to read data from.
+ public static void CopyFrom(this Texture2D destination, UploadTexture2D source)
+ where T : unmanaged
+ {
+ source.CopyTo(destination, 0, 0, 0, 0, source.Width, source.Height);
+ }
+
+ ///
+ /// Reads the contents of an instance and writes them into a target instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input instance to read data from.
+ /// The horizontal offset in the source texture.
+ /// The vertical offset in the source texture.
+ /// The width of the memory area to copy.
+ /// The height of the memory area to copy.
+ public static void CopyFrom(this Texture2D destination, UploadTexture2D source, int sourceOffsetX, int sourceOffsetY, int width, int height)
+ where T : unmanaged
+ {
+ destination.CopyFrom(source, sourceOffsetX, sourceOffsetY, 0, 0, width, height);
+ }
+
+ ///
+ /// Reads the contents of an instance and writes them into a target instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input instance to read data from.
+ /// The horizontal offset in the source texture.
+ /// The vertical offset in the source texture.
+ /// The horizontal offset in the destination texture.
+ /// The vertical offset in the destination texture.
+ /// The width of the memory area to copy.
+ /// The height of the memory area to copy.
+ public static void CopyFrom(this Texture2D destination, UploadTexture2D 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);
}
///
diff --git a/src/ComputeSharp/Graphics/Extensions/Texture3DExtensions.cs b/src/ComputeSharp/Graphics/Extensions/Texture3DExtensions.cs
index 436b1be1..e38b317d 100644
--- a/src/ComputeSharp/Graphics/Extensions/Texture3DExtensions.cs
+++ b/src/ComputeSharp/Graphics/Extensions/Texture3DExtensions.cs
@@ -15,7 +15,7 @@ public static class Texture3DExtensions
/// Reads the contents of the current instance and returns an array.
///
/// The type of items stored on the texture.
- /// The input instance to read data from.
+ /// The input instance to read data from.
/// A array with the contents of the current buffer.
///
/// 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].
///
[Pure]
- public static T[,,] ToArray(this Texture3D texture)
+ public static T[,,] ToArray(this Texture3D 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;
+ }
+
+ ///
+ /// Reads the contents of the current instance and returns an array.
+ ///
+ /// The type of items stored on the texture.
+ /// The input instance to read data from.
+ /// The horizontal offset in the source texture.
+ /// The vertical offset in the source texture.
+ /// The depthwise offset in the source texture.
+ /// The width of the memory area to copy.
+ /// The height of the memory area to copy.
+ /// The depth of the memory area to copy.
+ /// A array with the contents of the current texture.
+ public static unsafe T[,,] ToArray(this Texture3D 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(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 instance and writes them into a target array.
///
/// The type of items stored on the texture.
- /// The input instance to read data from.
+ /// The input instance to read data from.
/// The input array to write data to.
///
/// 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].
///
- public static void CopyTo(this Texture3D texture, T[,,] destination)
+ public static void CopyTo(this Texture3D 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);
}
///
/// Reads the contents of the specified range from the current