diff --git a/src/ComputeSharp.Graphics/Helpers/MemoryHelper.cs b/src/ComputeSharp.Graphics/Helpers/MemoryHelper.cs
index ad79aa4b..560db122 100644
--- a/src/ComputeSharp.Graphics/Helpers/MemoryHelper.cs
+++ b/src/ComputeSharp.Graphics/Helpers/MemoryHelper.cs
@@ -13,11 +13,15 @@ namespace ComputeSharp.Graphics.Helpers
///
/// The type of values in the input
/// The source to read
+ /// The source offset to start reading data from
/// The for the destination memory area
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe void Copy(Span source, IntPtr destination) where T : unmanaged
+ /// The destination offset to start writing data to
+ /// The total number of items to copy
+ public static unsafe void Copy(Span source, int sourceOffset, IntPtr destination, int destinationOffset, int count) where T : unmanaged
{
- source.CopyTo(new Span(destination.ToPointer(), source.Length));
+ ref T rout = ref Unsafe.AsRef(destination.ToPointer());
+ void* target = Unsafe.AsPointer(ref Unsafe.Add(ref rout, destinationOffset));
+ source.Slice(sourceOffset, count).CopyTo(new Span(target, count));
}
///
@@ -25,11 +29,16 @@ namespace ComputeSharp.Graphics.Helpers
///
/// The type of values to read
/// The that indicates the memory area to read from
+ /// The source offset to start reading data from
/// The destination to write
+ /// The destination offset to start writing data to
+ /// The total number of items to copy
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe void Copy(IntPtr source, Span destination) where T : unmanaged
+ public static unsafe void Copy(IntPtr source, int sourceOffset, Span destination, int destinationOffset, int count) where T : unmanaged
{
- new Span(source.ToPointer(), destination.Length).CopyTo(destination);
+ ref T rin = ref Unsafe.AsRef(source.ToPointer());
+ void* target = Unsafe.AsPointer(ref Unsafe.Add(ref rin, sourceOffset));
+ new Span(target, count).CopyTo(destination.Slice(destinationOffset, count));
}
}
}