using System; using System.Runtime.CompilerServices; namespace ComputeSharp.Graphics.Helpers { /// /// A with some helper methods to copy data between memory areas /// internal static class MemoryHelper { /// /// Copies the content of a to the area pointed by an input value /// /// 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 /// 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 { 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)); } /// /// Copies a memory area pointed by an value to a target /// /// 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, int sourceOffset, Span destination, int destinationOffset, int count) where T : unmanaged { 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)); } } }