diff --git a/samples/ComputeSharp.Benchmark/Blas/BlasBenchmark.cs b/samples/ComputeSharp.Benchmark/Blas/BlasBenchmark.cs index a27608c6..749cfb89 100644 --- a/samples/ComputeSharp.Benchmark/Blas/BlasBenchmark.cs +++ b/samples/ComputeSharp.Benchmark/Blas/BlasBenchmark.cs @@ -157,7 +157,7 @@ namespace ComputeSharp.Benchmark.Blas BlasHelpers.FullyConnectedForwardGpu(Gpu.Default, C, N, M, P, x, w, b, y); - y.GetData(Y); + y.CopyTo(Y); } } } diff --git a/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs b/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs index 864389ed..f53f3759 100644 --- a/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs +++ b/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs @@ -270,7 +270,7 @@ namespace ComputeSharp.BokehBlur.Processors { Vector4 parameters = KernelParameters[j]; - kernel.SetData(Kernels[j]); + kernel.CopyFrom(Kernels[j]); Gpu.Default.For( source.Width, @@ -287,7 +287,7 @@ namespace ComputeSharp.BokehBlur.Processors Gpu.Default.For(source.Height, new(temporary, texture)); // Write the final pixel data - texture.GetData(span); + texture.CopyTo(span); } /// diff --git a/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs b/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs index 9a8721a6..dcb932bd 100644 --- a/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs +++ b/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs @@ -101,7 +101,7 @@ namespace ComputeSharp.BokehBlur.Processors Gpu.Default.For(source.Width, source.Height, new(sourceTexture, firstPassTexture, kernelBuffer)); Gpu.Default.For(source.Width, source.Height, new(firstPassTexture, sourceTexture, kernelBuffer)); - sourceTexture.GetData(span); + sourceTexture.CopyTo(span); } /// diff --git a/samples/ComputeSharp.Sample.Shared/Program.cs b/samples/ComputeSharp.Sample.Shared/Program.cs index e20ef49d..30807dac 100644 --- a/samples/ComputeSharp.Sample.Shared/Program.cs +++ b/samples/ComputeSharp.Sample.Shared/Program.cs @@ -30,7 +30,7 @@ namespace ComputeSharp.Sample Gpu.Default.For(100, new MainKernel(gpuBuffer)); // Get the data back - gpuBuffer.GetData(array); + gpuBuffer.CopyTo(array); // Print the updated matrix Console.WriteLine("===================== AFTER ======================"); diff --git a/src/ComputeSharp.Graphics/Resources/Abstract/Buffer{T}.cs b/src/ComputeSharp.Graphics/Resources/Abstract/Buffer{T}.cs index 9e4a617d..4147ce48 100644 --- a/src/ComputeSharp.Graphics/Resources/Abstract/Buffer{T}.cs +++ b/src/ComputeSharp.Graphics/Resources/Abstract/Buffer{T}.cs @@ -112,7 +112,7 @@ namespace ComputeSharp.Resources /// The input memory area to write data to. /// The length of the memory area to write data to. /// The offset to start reading data from. - internal abstract void GetData(ref T destination, int length, int offset); + internal abstract void CopyTo(ref T destination, int length, int offset); /// /// Writes the contents of a given memory area to a specified area of the current instance. @@ -120,19 +120,19 @@ namespace ComputeSharp.Resources /// The input memory area to read data from. /// The length of the input memory area to read data from. /// The offset to start writing data to. - internal abstract void SetData(ref T source, int length, int offset); + internal abstract void CopyFrom(ref T source, int length, int offset); /// /// Writes the contents of a given to the current instance. /// /// The input to read data from. - public abstract void SetData(Buffer source); + public abstract void CopyFrom(Buffer source); /// /// Writes the contents of a given to the current instance, using a temporary CPU buffer. /// /// The input to read data from. - protected void SetDataWithCpuBuffer(Buffer source) + protected void CopyFromWithCpuBuffer(Buffer source) { T[] array = ArrayPool.Shared.Rent(source.Length); @@ -140,9 +140,9 @@ namespace ComputeSharp.Resources { ref T r0 = ref MemoryMarshal.GetArrayDataReference(array); - source.GetData(ref r0, source.Length, 0); + source.CopyTo(ref r0, source.Length, 0); - SetData(ref r0, source.Length, 0); + CopyFrom(ref r0, source.Length, 0); } finally { diff --git a/src/ComputeSharp.Graphics/Resources/Abstract/StructuredBuffer{T}.cs b/src/ComputeSharp.Graphics/Resources/Abstract/StructuredBuffer{T}.cs index 45658a3f..56e90cae 100644 --- a/src/ComputeSharp.Graphics/Resources/Abstract/StructuredBuffer{T}.cs +++ b/src/ComputeSharp.Graphics/Resources/Abstract/StructuredBuffer{T}.cs @@ -29,7 +29,7 @@ namespace ComputeSharp.Resources } /// - internal override unsafe void GetData(ref T destination, int length, int offset) + internal override unsafe void CopyTo(ref T destination, int length, int offset) { GraphicsDevice.ThrowIfDisposed(); @@ -87,7 +87,7 @@ namespace ComputeSharp.Resources /// The starting offset within to write data to. /// The number of items to read. /// The offset to start reading data from. - internal unsafe void GetData(ReadBackBuffer destination, int destinationOffset, int length, int offset) + internal unsafe void CopyTo(ReadBackBuffer destination, int destinationOffset, int length, int offset) { GraphicsDevice.ThrowIfDisposed(); @@ -113,7 +113,7 @@ namespace ComputeSharp.Resources } /// - internal override unsafe void SetData(ref T source, int length, int offset) + internal override unsafe void CopyFrom(ref T source, int length, int offset) { GraphicsDevice.ThrowIfDisposed(); @@ -169,7 +169,7 @@ namespace ComputeSharp.Resources /// The starting offset within to read data from. /// The number of items to read. /// The offset to start reading writing data to. - internal unsafe void SetData(UploadBuffer source, int sourceOffset, int length, int offset) + internal unsafe void CopyFrom(UploadBuffer source, int sourceOffset, int length, int offset) { GraphicsDevice.ThrowIfDisposed(); @@ -195,7 +195,7 @@ namespace ComputeSharp.Resources } /// - public override unsafe void SetData(Buffer source) + public override unsafe void CopyFrom(Buffer source) { GraphicsDevice.ThrowIfDisposed(); @@ -212,7 +212,7 @@ namespace ComputeSharp.Resources copyCommandList.CopyBufferRegion(D3D12Resource, 0, source.D3D12Resource, 0,(ulong)SizeInBytes); copyCommandList.ExecuteAndWaitForCompletion(); } - else SetDataWithCpuBuffer(source); + else CopyFromWithCpuBuffer(source); } } } diff --git a/src/ComputeSharp.Graphics/Resources/Abstract/Texture2D{T}.cs b/src/ComputeSharp.Graphics/Resources/Abstract/Texture2D{T}.cs index c4a349c3..18903173 100644 --- a/src/ComputeSharp.Graphics/Resources/Abstract/Texture2D{T}.cs +++ b/src/ComputeSharp.Graphics/Resources/Abstract/Texture2D{T}.cs @@ -131,7 +131,7 @@ namespace ComputeSharp.Resources /// The vertical offset in the source texture. /// The width of the memory area to copy. /// The height of the memory area to copy. - internal void GetData(ref T destination, int size, int x, int y, int width, int height) + internal void CopyTo(ref T destination, int size, int x, int y, int width, int height) { GraphicsDevice.ThrowIfDisposed(); @@ -203,7 +203,7 @@ namespace ComputeSharp.Resources /// 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. - internal void SetData(ref T source, int size, int x, int y, int width, int height) + internal void CopyFrom(ref T source, int size, int x, int y, int width, int height) { GraphicsDevice.ThrowIfDisposed(); diff --git a/src/ComputeSharp.Graphics/Resources/Abstract/Texture3D{T}.cs b/src/ComputeSharp.Graphics/Resources/Abstract/Texture3D{T}.cs index 2d0a59ac..2bccef01 100644 --- a/src/ComputeSharp.Graphics/Resources/Abstract/Texture3D{T}.cs +++ b/src/ComputeSharp.Graphics/Resources/Abstract/Texture3D{T}.cs @@ -142,7 +142,7 @@ namespace ComputeSharp.Resources /// The width of the memory area to copy. /// The height of the memory area to copy. /// The depth of the memory area to copy. - internal void GetData(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 x, int y, int z, int width, int height, int depth) { GraphicsDevice.ThrowIfDisposed(); @@ -221,7 +221,7 @@ namespace ComputeSharp.Resources /// The width of the memory area to write to. /// The height of the memory area to write to. /// The depth of the memory area to write to. - internal void SetData(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 x, int y, int z, int width, int height, int depth) { GraphicsDevice.ThrowIfDisposed(); diff --git a/src/ComputeSharp.Graphics/Resources/ConstantBuffer{T}.cs b/src/ComputeSharp.Graphics/Resources/ConstantBuffer{T}.cs index a4200c3e..dda2d033 100644 --- a/src/ComputeSharp.Graphics/Resources/ConstantBuffer{T}.cs +++ b/src/ComputeSharp.Graphics/Resources/ConstantBuffer{T}.cs @@ -59,7 +59,7 @@ namespace ComputeSharp } /// - internal override unsafe void GetData(ref T destination, int size, int offset) + internal override unsafe void CopyTo(ref T destination, int size, int offset) { GraphicsDevice.ThrowIfDisposed(); @@ -94,7 +94,7 @@ namespace ComputeSharp } /// - internal override unsafe void SetData(ref T source, int size, int offset) + internal override unsafe void CopyFrom(ref T source, int size, int offset) { GraphicsDevice.ThrowIfDisposed(); @@ -129,7 +129,7 @@ namespace ComputeSharp } /// - public override unsafe void SetData(Buffer source) + public override unsafe void CopyFrom(Buffer source) { GraphicsDevice.ThrowIfDisposed(); @@ -146,7 +146,7 @@ namespace ComputeSharp copyCommandList.CopyBufferRegion(D3D12Resource, 0, source.D3D12Resource, 0,(ulong)SizeInBytes); copyCommandList.ExecuteAndWaitForCompletion(); } - else SetDataWithCpuBuffer(source); + else CopyFromWithCpuBuffer(source); } /// diff --git a/src/ComputeSharp.Graphics/Resources/Views/BufferDebugView{T}.cs b/src/ComputeSharp.Graphics/Resources/Views/BufferDebugView{T}.cs index 2df6d818..d1f3f025 100644 --- a/src/ComputeSharp.Graphics/Resources/Views/BufferDebugView{T}.cs +++ b/src/ComputeSharp.Graphics/Resources/Views/BufferDebugView{T}.cs @@ -20,7 +20,7 @@ namespace ComputeSharp.Resources.Views { var items = GC.AllocateUninitializedArray(buffer.Length); - buffer.GetData(ref items[0], buffer.Length, 0); + buffer.CopyTo(ref items[0], buffer.Length, 0); Items = items; } diff --git a/src/ComputeSharp.Graphics/Resources/Views/Texture2DDebugView{T}.cs b/src/ComputeSharp.Graphics/Resources/Views/Texture2DDebugView{T}.cs index ad4f4951..e7130265 100644 --- a/src/ComputeSharp.Graphics/Resources/Views/Texture2DDebugView{T}.cs +++ b/src/ComputeSharp.Graphics/Resources/Views/Texture2DDebugView{T}.cs @@ -19,7 +19,7 @@ namespace ComputeSharp.Resources.Views { var items = new T[texture.Height, texture.Width]; - texture.GetData(ref items[0, 0], items.Length, 0, 0, texture.Width, texture.Height); + texture.CopyTo(ref items[0, 0], items.Length, 0, 0, texture.Width, texture.Height); Items = items; } diff --git a/src/ComputeSharp.Graphics/Resources/Views/Texture3DDebugView{T}.cs b/src/ComputeSharp.Graphics/Resources/Views/Texture3DDebugView{T}.cs index cdd8b3d2..6c331855 100644 --- a/src/ComputeSharp.Graphics/Resources/Views/Texture3DDebugView{T}.cs +++ b/src/ComputeSharp.Graphics/Resources/Views/Texture3DDebugView{T}.cs @@ -19,7 +19,7 @@ namespace ComputeSharp.Resources.Views { var items = new T[texture.Depth, texture.Height, texture.Width]; - texture.GetData(ref items[0, 0, 0], items.Length, 0, 0, 0, texture.Width, texture.Height, texture.Depth); + texture.CopyTo(ref items[0, 0, 0], items.Length, 0, 0, 0, texture.Width, texture.Height, texture.Depth); Items = items; } diff --git a/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs b/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs index ed47e719..252f2d78 100644 --- a/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs +++ b/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs @@ -55,7 +55,7 @@ namespace ComputeSharp { ConstantBuffer buffer = new(device, source.Length, AllocationMode.Default); - buffer.SetData(source); + buffer.CopyFrom(source); return buffer; } @@ -73,7 +73,7 @@ namespace ComputeSharp { ConstantBuffer constantBuffer = new(device, source.Length, AllocationMode.Default); - constantBuffer.SetData(source); + constantBuffer.CopyFrom(source); return constantBuffer; } @@ -120,7 +120,7 @@ namespace ComputeSharp { ReadOnlyBuffer buffer = new(device, source.Length, AllocationMode.Default); - buffer.SetData(source); + buffer.CopyFrom(source); return buffer; } @@ -138,7 +138,7 @@ namespace ComputeSharp { ReadOnlyBuffer readWriteBuffer = new(device, source.Length, AllocationMode.Default); - readWriteBuffer.SetData(source, 0, source.Length, 0); + readWriteBuffer.CopyFrom(source, 0, source.Length, 0); return readWriteBuffer; } @@ -156,7 +156,7 @@ namespace ComputeSharp { ReadOnlyBuffer readWriteBuffer = new(device, source.Length, AllocationMode.Default); - readWriteBuffer.SetData(source); + readWriteBuffer.CopyFrom(source); return readWriteBuffer; } @@ -223,7 +223,7 @@ namespace ComputeSharp { ReadOnlyTexture2D texture = new(device, source.GetLength(1), source.GetLength(0), AllocationMode.Default); - texture.SetData(source); + texture.CopyFrom(source); return texture; } @@ -243,7 +243,7 @@ namespace ComputeSharp { ReadOnlyTexture2D texture = new(device, width, height, AllocationMode.Default); - texture.SetData(source); + texture.CopyFrom(source); return texture; } @@ -318,7 +318,7 @@ namespace ComputeSharp { ReadOnlyTexture2D texture = new(device, source.GetLength(1), source.GetLength(0), AllocationMode.Default); - texture.SetData(source); + texture.CopyFrom(source); return texture; } @@ -340,7 +340,7 @@ namespace ComputeSharp { ReadOnlyTexture2D texture = new(device, width, height, AllocationMode.Default); - texture.SetData(source); + texture.CopyFrom(source); return texture; } @@ -414,7 +414,7 @@ namespace ComputeSharp { ReadOnlyTexture3D texture = new(device, source.GetLength(2), source.GetLength(1), source.GetLength(0), AllocationMode.Default); - texture.SetData(source); + texture.CopyFrom(source); return texture; } @@ -435,7 +435,7 @@ namespace ComputeSharp { ReadOnlyTexture3D texture = new(device, width, height, depth, AllocationMode.Default); - texture.SetData(source); + texture.CopyFrom(source); return texture; } @@ -517,7 +517,7 @@ namespace ComputeSharp { ReadOnlyTexture3D texture = new(device, source.GetLength(2), source.GetLength(1), source.GetLength(0), AllocationMode.Default); - texture.SetData(source); + texture.CopyFrom(source); return texture; } @@ -540,7 +540,7 @@ namespace ComputeSharp { ReadOnlyTexture3D texture = new(device, width, height, depth, AllocationMode.Default); - texture.SetData(source); + texture.CopyFrom(source); return texture; } @@ -587,7 +587,7 @@ namespace ComputeSharp { ReadWriteBuffer buffer = new(device, source.Length, AllocationMode.Default); - buffer.SetData(source); + buffer.CopyFrom(source); return buffer; } @@ -605,7 +605,7 @@ namespace ComputeSharp { ReadWriteBuffer readWriteBuffer = new(device, source.Length, AllocationMode.Default); - readWriteBuffer.SetData(source, 0, source.Length, 0); + readWriteBuffer.CopyFrom(source, 0, source.Length, 0); return readWriteBuffer; } @@ -623,7 +623,7 @@ namespace ComputeSharp { ReadWriteBuffer readWriteBuffer = new(device, source.Length, AllocationMode.Default); - readWriteBuffer.SetData(source); + readWriteBuffer.CopyFrom(source); return readWriteBuffer; } @@ -690,7 +690,7 @@ namespace ComputeSharp { ReadWriteTexture2D texture = new(device, source.GetLength(1), source.GetLength(0), AllocationMode.Default); - texture.SetData(source); + texture.CopyFrom(source); return texture; } @@ -710,7 +710,7 @@ namespace ComputeSharp { ReadWriteTexture2D texture = new(device, width, height, AllocationMode.Default); - texture.SetData(source); + texture.CopyFrom(source); return texture; } @@ -785,7 +785,7 @@ namespace ComputeSharp { ReadWriteTexture2D texture = new(device, source.GetLength(1), source.GetLength(0), AllocationMode.Default); - texture.SetData(source); + texture.CopyFrom(source); return texture; } @@ -807,7 +807,7 @@ namespace ComputeSharp { ReadWriteTexture2D texture = new(device, width, height, AllocationMode.Default); - texture.SetData(source); + texture.CopyFrom(source); return texture; } @@ -881,7 +881,7 @@ namespace ComputeSharp { ReadWriteTexture3D texture = new(device, source.GetLength(2), source.GetLength(1), source.GetLength(0), AllocationMode.Default); - texture.SetData(source); + texture.CopyFrom(source); return texture; } @@ -902,7 +902,7 @@ namespace ComputeSharp { ReadWriteTexture3D texture = new(device, width, height, depth, AllocationMode.Default); - texture.SetData(source); + texture.CopyFrom(source); return texture; } @@ -984,7 +984,7 @@ namespace ComputeSharp { ReadWriteTexture3D texture = new(device, source.GetLength(2), source.GetLength(1), source.GetLength(0), AllocationMode.Default); - texture.SetData(source); + texture.CopyFrom(source); return texture; } @@ -1007,7 +1007,7 @@ namespace ComputeSharp { ReadWriteTexture3D texture = new(device, width, height, depth, AllocationMode.Default); - texture.SetData(source); + texture.CopyFrom(source); return texture; } @@ -1105,7 +1105,7 @@ namespace ComputeSharp { ReadBackBuffer buffer = new(device, source.Length, AllocationMode.Default); - source.GetData(buffer, 0, buffer.Length, 0); + source.CopyTo(buffer, 0, buffer.Length, 0); return buffer; } diff --git a/src/ComputeSharp/Extensions/Resources/BufferExtensions.cs b/src/ComputeSharp/Extensions/Resources/BufferExtensions.cs index 6c1fd022..e231c449 100644 --- a/src/ComputeSharp/Extensions/Resources/BufferExtensions.cs +++ b/src/ComputeSharp/Extensions/Resources/BufferExtensions.cs @@ -18,10 +18,10 @@ namespace ComputeSharp /// The input instance to read data from. /// A array with the contents of the input buffer. [Pure] - public static T[] GetData(this Buffer buffer) + public static T[] ToArray(this Buffer buffer) where T : unmanaged { - return buffer.GetData(0, buffer.Length); + return buffer.ToArray(0, buffer.Length); } /// @@ -33,14 +33,14 @@ namespace ComputeSharp /// The number of items to read. /// A array with the contents of the specified range from the current buffer. [Pure] - public static T[] GetData(this Buffer buffer, int offset, int count) + public static T[] ToArray(this Buffer buffer, int offset, int count) where T : unmanaged { Guard.IsGreaterThanOrEqualTo(count, 0, nameof(count)); T[] data = GC.AllocateUninitializedArray(count); - buffer.GetData(data.AsSpan(), offset); + buffer.CopyTo(data.AsSpan(), offset); return data; } @@ -51,10 +51,10 @@ namespace ComputeSharp /// The type of items stored on the buffer. /// The input instance to read data from. /// The input array to write data to. - public static void GetData(this Buffer buffer, T[] destination) + public static void CopyTo(this Buffer buffer, T[] destination) where T : unmanaged { - buffer.GetData(destination.AsSpan(), 0); + buffer.CopyTo(destination.AsSpan(), 0); } /// @@ -66,12 +66,12 @@ namespace ComputeSharp /// The starting offset within to write data to. /// The offset to start reading data from. /// The number of items to read. - public static void GetData(this Buffer buffer, T[] destination, int destinationOffset, int bufferOffset, int count) + public static void CopyTo(this Buffer buffer, T[] destination, int destinationOffset, int bufferOffset, int count) where T : unmanaged { Span span = destination.AsSpan(destinationOffset, count); - buffer.GetData(span, bufferOffset); + buffer.CopyTo(span, bufferOffset); } /// @@ -80,10 +80,10 @@ namespace ComputeSharp /// The type of items stored on the buffer. /// The input instance to read data from. /// The input to write data to. - public static void GetData(this Buffer buffer, Span destination) + public static void CopyTo(this Buffer buffer, Span destination) where T : unmanaged { - buffer.GetData(destination, 0); + buffer.CopyTo(destination, 0); } /// @@ -93,10 +93,10 @@ namespace ComputeSharp /// The input instance to read data from. /// The input to write data to. /// The offset to start reading data from. - public static void GetData(this Buffer buffer, Span destination, int offset) + public static void CopyTo(this Buffer buffer, Span destination, int offset) where T : unmanaged { - buffer.GetData(ref MemoryMarshal.GetReference(destination), destination.Length, offset); + buffer.CopyTo(ref MemoryMarshal.GetReference(destination), destination.Length, offset); } /// @@ -105,10 +105,10 @@ namespace ComputeSharp /// The type of items stored on the buffer. /// The target instance to write data to. /// The input array to read data from. - public static void SetData(this Buffer buffer, T[] source) + public static void CopyFrom(this Buffer buffer, T[] source) where T : unmanaged { - buffer.SetData(source.AsSpan(), 0); + buffer.CopyFrom(source.AsSpan(), 0); } /// @@ -120,12 +120,12 @@ namespace ComputeSharp /// The starting offset within to read data from. /// The offset to start writing data to. /// The number of items to write. - public static void SetData(this Buffer buffer, T[] source, int sourceOffset, int bufferOffset, int count) + public static void CopyFrom(this Buffer buffer, T[] source, int sourceOffset, int bufferOffset, int count) where T : unmanaged { ReadOnlySpan span = source.AsSpan(sourceOffset, count); - buffer.SetData(span, bufferOffset); + buffer.CopyFrom(span, bufferOffset); } /// @@ -134,10 +134,10 @@ namespace ComputeSharp /// The type of items stored on the buffer. /// The target instance to write data to. /// The input to read data from. - public static void SetData(this Buffer buffer, ReadOnlySpan source) + public static void CopyFrom(this Buffer buffer, ReadOnlySpan source) where T : unmanaged { - buffer.SetData(source, 0); + buffer.CopyFrom(source, 0); } /// @@ -147,10 +147,10 @@ namespace ComputeSharp /// The target instance to write data to. /// The input to read data from. /// The offset to start writing data to. - public static void SetData(this Buffer buffer, ReadOnlySpan source, int offset) + public static void CopyFrom(this Buffer buffer, ReadOnlySpan source, int offset) where T : unmanaged { - buffer.SetData(ref MemoryMarshal.GetReference(source), source.Length, offset); + buffer.CopyFrom(ref MemoryMarshal.GetReference(source), source.Length, offset); } } } diff --git a/src/ComputeSharp/Extensions/Resources/StructuredBufferExtensions.cs b/src/ComputeSharp/Extensions/Resources/StructuredBufferExtensions.cs index 488ab3ba..3e6e8a79 100644 --- a/src/ComputeSharp/Extensions/Resources/StructuredBufferExtensions.cs +++ b/src/ComputeSharp/Extensions/Resources/StructuredBufferExtensions.cs @@ -18,7 +18,7 @@ namespace ComputeSharp public static void CopyTo(this StructuredBuffer buffer, ReadBackBuffer destination) where T : unmanaged { - buffer.GetData(destination, 0, buffer.Length, 0); + buffer.CopyTo(destination, 0, buffer.Length, 0); } /// @@ -33,7 +33,7 @@ namespace ComputeSharp public static void CopyTo(this StructuredBuffer buffer, ReadBackBuffer destination, int destinationOffset, int bufferOffset, int count) where T : unmanaged { - buffer.GetData(destination, destinationOffset, count, bufferOffset); + buffer.CopyTo(destination, destinationOffset, count, bufferOffset); } } } diff --git a/src/ComputeSharp/Extensions/Resources/Texture2DExtensions.cs b/src/ComputeSharp/Extensions/Resources/Texture2DExtensions.cs index c320577c..ef7c5a96 100644 --- a/src/ComputeSharp/Extensions/Resources/Texture2DExtensions.cs +++ b/src/ComputeSharp/Extensions/Resources/Texture2DExtensions.cs @@ -18,12 +18,12 @@ namespace ComputeSharp /// The input instance to read data from. /// A array with the contents of the current texture. [Pure] - public static T[,] GetData(this Texture2D texture) + public static T[,] ToArray(this Texture2D texture) where T : unmanaged { T[,] data = new T[texture.Height, texture.Width]; - texture.GetData(data); + texture.CopyTo(data); return data; } @@ -34,13 +34,13 @@ namespace ComputeSharp /// The type of items stored on the texture. /// The input instance to read data from. /// The input array to write data to. - public static void GetData(this Texture2D texture, T[,] destination) + public static void CopyTo(this Texture2D texture, T[,] destination) where T : unmanaged { Guard.IsEqualTo(destination.GetLength(0), texture.Height, nameof(destination)); Guard.IsEqualTo(destination.GetLength(1), texture.Width, nameof(destination)); - texture.GetData(ref destination[0, 0], destination.Length, 0, 0, texture.Width, texture.Height); + texture.CopyTo(ref destination[0, 0], destination.Length, 0, 0, texture.Width, texture.Height); } /// @@ -49,10 +49,10 @@ namespace ComputeSharp /// The type of items stored on the texture. /// The input instance to read data from. /// The input array to write data to. - public static void GetData(this Texture2D texture, T[] destination) + public static void CopyTo(this Texture2D texture, T[] destination) where T : unmanaged { - texture.GetData(destination.AsSpan(), 0, 0, texture.Width, texture.Height); + texture.CopyTo(destination.AsSpan(), 0, 0, texture.Width, texture.Height); } /// @@ -63,10 +63,10 @@ namespace ComputeSharp /// The input array to write data to. /// The horizontal range of items to copy. /// The vertical range of items to copy. - public static void GetData(this Texture2D texture, T[] destination, Range x, Range y) + public static void CopyTo(this Texture2D texture, T[] destination, Range x, Range y) where T : unmanaged { - texture.GetData(destination.AsSpan(), x, y); + texture.CopyTo(destination.AsSpan(), x, y); } /// @@ -79,10 +79,10 @@ namespace ComputeSharp /// 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 GetData(this Texture2D texture, T[] destination, int x, int y, int width, int height) + public static void CopyTo(this Texture2D texture, T[] destination, int x, int y, int width, int height) where T : unmanaged { - texture.GetData(destination.AsSpan(), x, y, width, height); + texture.CopyTo(destination.AsSpan(), x, y, width, height); } /// @@ -92,10 +92,10 @@ namespace ComputeSharp /// 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 GetData(this Texture2D texture, T[] destination, int offset) + public static void CopyTo(this Texture2D texture, T[] destination, int offset) where T : unmanaged { - texture.GetData(destination.AsSpan(offset), 0, 0, texture.Width, texture.Height); + texture.CopyTo(destination.AsSpan(offset), 0, 0, texture.Width, texture.Height); } /// @@ -107,10 +107,10 @@ namespace ComputeSharp /// 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 GetData(this Texture2D texture, T[] destination, int offset, Range x, Range y) + public static void CopyTo(this Texture2D texture, T[] destination, int offset, Range x, Range y) where T : unmanaged { - texture.GetData(destination.AsSpan(offset), x, y); + texture.CopyTo(destination.AsSpan(offset), x, y); } /// @@ -124,10 +124,10 @@ namespace ComputeSharp /// 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 GetData(this Texture2D texture, T[] destination, int offset, int x, int y, int width, int height) + public static void CopyTo(this Texture2D texture, T[] destination, int offset, int x, int y, int width, int height) where T : unmanaged { - texture.GetData(destination.AsSpan(offset), x, y, width, height); + texture.CopyTo(destination.AsSpan(offset), x, y, width, height); } /// @@ -137,10 +137,10 @@ namespace ComputeSharp /// The type of items stored on the texture. /// The input instance to read data from. /// The input to write data to. - public static void GetData(this Texture2D texture, Span destination) + public static void CopyTo(this Texture2D texture, Span destination) where T : unmanaged { - texture.GetData(destination, 0, 0, texture.Width, texture.Height); + texture.CopyTo(destination, 0, 0, texture.Width, texture.Height); } /// @@ -151,13 +151,13 @@ namespace ComputeSharp /// The input to write data to. /// The horizontal range of items to copy. /// The vertical range of items to copy. - public static void GetData(this Texture2D texture, Span destination, Range x, Range y) + public static void CopyTo(this Texture2D texture, Span destination, Range x, Range y) where T : unmanaged { var (offsetX, width) = x.GetOffsetAndLength(texture.Width); var (offsetY, height) = y.GetOffsetAndLength(texture.Height); - texture.GetData(destination, offsetX, offsetY, width, height); + texture.CopyTo(destination, offsetX, offsetY, width, height); } /// @@ -170,10 +170,10 @@ namespace ComputeSharp /// 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 GetData(this Texture2D texture, Span destination, int x, int y, int width, int height) + public static void CopyTo(this Texture2D texture, Span destination, int x, int y, int width, int height) where T : unmanaged { - texture.GetData(ref MemoryMarshal.GetReference(destination), destination.Length, x, y, width, height); + texture.CopyTo(ref MemoryMarshal.GetReference(destination), destination.Length, x, y, width, height); } /// @@ -182,13 +182,13 @@ namespace ComputeSharp /// The type of items stored on the texture. /// The target instance to write data to. /// The input array to read data from. - public static unsafe void SetData(this Texture2D texture, T[,] source) + public static unsafe void CopyFrom(this Texture2D texture, T[,] source) where T : unmanaged { Guard.IsEqualTo(source.GetLength(0), texture.Height, nameof(source)); Guard.IsEqualTo(source.GetLength(1), texture.Width, nameof(source)); - texture.SetData(ref source[0, 0], source.Length, 0, 0, texture.Width, texture.Height); + texture.CopyFrom(ref source[0, 0], source.Length, 0, 0, texture.Width, texture.Height); } /// @@ -197,10 +197,10 @@ namespace ComputeSharp /// The type of items stored on the texture. /// The target instance to write data to. /// The input array to read data from. - public static void SetData(this Texture2D texture, T[] source) + public static void CopyFrom(this Texture2D texture, T[] source) where T : unmanaged { - texture.SetData(source.AsSpan(), 0, 0, texture.Width, texture.Height); + texture.CopyFrom(source.AsSpan(), 0, 0, texture.Width, texture.Height); } /// @@ -211,10 +211,10 @@ namespace ComputeSharp /// The input array to read data from. /// The horizontal range of items to write. /// The vertical range of items to write. - public static void SetData(this Texture2D texture, T[] source, Range x, Range y) + public static void CopyFrom(this Texture2D texture, T[] source, Range x, Range y) where T : unmanaged { - texture.SetData(source.AsSpan(), x, y); + texture.CopyFrom(source.AsSpan(), x, y); } /// @@ -227,10 +227,10 @@ namespace ComputeSharp /// 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 SetData(this Texture2D texture, T[] source, int x, int y, int width, int height) + public static void CopyFrom(this Texture2D texture, T[] source, int x, int y, int width, int height) where T : unmanaged { - texture.SetData(source.AsSpan(), x, y, width, height); + texture.CopyFrom(source.AsSpan(), x, y, width, height); } /// @@ -242,10 +242,10 @@ namespace ComputeSharp /// 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 SetData(this Texture2D texture, T[] source, int offset, Range x, Range y) + public static void CopyFrom(this Texture2D texture, T[] source, int offset, Range x, Range y) where T : unmanaged { - texture.SetData(source.AsSpan(offset), x, y); + texture.CopyFrom(source.AsSpan(offset), x, y); } /// @@ -259,10 +259,10 @@ namespace ComputeSharp /// 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 SetData(this Texture2D texture, T[] source, int offset, int x, int y, int width, int height) + public static void CopyFrom(this Texture2D texture, T[] source, int offset, int x, int y, int width, int height) where T : unmanaged { - texture.SetData(source.AsSpan(offset), x, y, width, height); + texture.CopyFrom(source.AsSpan(offset), x, y, width, height); } /// @@ -272,10 +272,10 @@ namespace ComputeSharp /// The type of items stored on the texture. /// The target instance to write data to. /// The input to read data from. - public static void SetData(this Texture2D texture, ReadOnlySpan source) + public static void CopyFrom(this Texture2D texture, ReadOnlySpan source) where T : unmanaged { - texture.SetData(source, 0, 0, texture.Width, texture.Height); + texture.CopyFrom(source, 0, 0, texture.Width, texture.Height); } /// @@ -286,13 +286,13 @@ namespace ComputeSharp /// The input to read data from. /// The horizontal range of items to write. /// The vertical range of items to write. - public static void SetData(this Texture2D texture, ReadOnlySpan source, Range x, Range y) + public static void CopyFrom(this Texture2D texture, ReadOnlySpan source, Range x, Range y) where T : unmanaged { var (offsetX, width) = x.GetOffsetAndLength(texture.Width); var (offsetY, height) = y.GetOffsetAndLength(texture.Height); - texture.SetData(source, offsetX, offsetY, width, height); + texture.CopyFrom(source, offsetX, offsetY, width, height); } /// @@ -305,10 +305,10 @@ namespace ComputeSharp /// 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 SetData(this Texture2D texture, ReadOnlySpan source, int x, int y, int width, int height) + public static void CopyFrom(this Texture2D texture, ReadOnlySpan source, int x, int y, int width, int height) where T : unmanaged { - texture.SetData(ref MemoryMarshal.GetReference(source), source.Length, x, y, width, height); + texture.CopyFrom(ref MemoryMarshal.GetReference(source), source.Length, x, y, width, height); } } } diff --git a/src/ComputeSharp/Extensions/Resources/Texture3DExtensions.cs b/src/ComputeSharp/Extensions/Resources/Texture3DExtensions.cs index 796623d1..fc7ab4ad 100644 --- a/src/ComputeSharp/Extensions/Resources/Texture3DExtensions.cs +++ b/src/ComputeSharp/Extensions/Resources/Texture3DExtensions.cs @@ -23,12 +23,12 @@ namespace ComputeSharp /// the depth dimension. This means that the resulting 3D array will have a size of [D, H, W]. /// [Pure] - public static T[,,] GetData(this Texture3D texture) + public static T[,,] ToArray(this Texture3D texture) where T : unmanaged { T[,,] data = new T[texture.Depth, texture.Height, texture.Width]; - texture.GetData(data); + texture.CopyTo(data); return data; } @@ -43,14 +43,14 @@ namespace ComputeSharp /// 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 GetData(this Texture3D texture, T[,,] destination) + public static void CopyTo(this Texture3D texture, 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)); - texture.GetData(ref destination[0, 0, 0], destination.Length, 0, 0, 0, texture.Width, texture.Height, texture.Depth); + texture.CopyTo(ref destination[0, 0, 0], destination.Length, 0, 0, 0, texture.Width, texture.Height, texture.Depth); } /// @@ -60,10 +60,10 @@ namespace ComputeSharp /// 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 GetData(this Texture3D texture, T[] destination, int offset) + public static void CopyTo(this Texture3D texture, T[] destination, int offset) where T : unmanaged { - texture.GetData(destination.AsSpan(offset), 0, 0, 0, texture.Width, texture.Height, texture.Depth); + texture.CopyTo(destination.AsSpan(offset), 0, 0, 0, texture.Width, texture.Height, texture.Depth); } /// @@ -76,10 +76,10 @@ namespace ComputeSharp /// The horizontal range of items to copy. /// The vertical range of items to copy. /// The depthwise range of items to copy. - public static void GetData(this Texture3D texture, T[] destination, int offset, Range x, Range y, Range z) + public static void CopyTo(this Texture3D texture, T[] destination, int offset, Range x, Range y, Range z) where T : unmanaged { - texture.GetData(destination.AsSpan(offset), x, y, z); + texture.CopyTo(destination.AsSpan(offset), x, y, z); } /// @@ -95,10 +95,10 @@ namespace ComputeSharp /// 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 GetData(this Texture3D texture, T[] destination, int offset, int x, int y, int z, int width, int height, int depth) + public static void CopyTo(this Texture3D texture, T[] destination, int offset, int x, int y, int z, int width, int height, int depth) where T : unmanaged { - texture.GetData(destination.AsSpan(offset), x, y, z, width, height, depth); + texture.CopyTo(destination.AsSpan(offset), x, y, z, width, height, depth); } /// @@ -107,10 +107,10 @@ namespace ComputeSharp /// The type of items stored on the texture. /// The input instance to read data from. /// The input to write data to. - public static void GetData(this Texture3D texture, Span destination) + public static void CopyTo(this Texture3D texture, Span destination) where T : unmanaged { - texture.GetData(destination, 0, 0, 0, texture.Width, texture.Height, texture.Depth); + texture.CopyTo(destination, 0, 0, 0, texture.Width, texture.Height, texture.Depth); } /// @@ -122,14 +122,14 @@ namespace ComputeSharp /// The horizontal range in the source texture. /// The vertical range in the source texture. /// The depthwise range in the source texture. - public static void GetData(this Texture3D texture, Span destination, Range x, Range y, Range z) + public static void CopyTo(this Texture3D texture, Span 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); - texture.GetData(destination, offsetX, offsetY, offsetZ, width, height, depth); + texture.CopyTo(destination, offsetX, offsetY, offsetZ, width, height, depth); } /// @@ -144,10 +144,10 @@ namespace ComputeSharp /// 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 GetData(this Texture3D texture, Span destination, int x, int y, int z, int width, int height, int depth) + public static void CopyTo(this Texture3D texture, Span destination, int x, int y, int z, int width, int height, int depth) where T : unmanaged { - texture.GetData(ref MemoryMarshal.GetReference(destination), destination.Length, x, y, z, width, height, depth); + texture.CopyTo(ref MemoryMarshal.GetReference(destination), destination.Length, x, y, z, width, height, depth); } /// @@ -160,14 +160,14 @@ namespace ComputeSharp /// 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]. /// - public static void SetData(this Texture3D texture, T[,,] source) + public static void CopyFrom(this Texture3D texture, 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)); - texture.SetData(ref source[0, 0, 0], source.Length, 0, 0, 0, texture.Width, texture.Height, texture.Depth); + texture.CopyFrom(ref source[0, 0, 0], source.Length, 0, 0, 0, texture.Width, texture.Height, texture.Depth); } /// @@ -176,10 +176,10 @@ namespace ComputeSharp /// The type of items stored on the texture. /// The target instance to write data to. /// The input array to read data from. - public static void SetData(this Texture3D texture, T[] source) + public static void CopyFrom(this Texture3D texture, T[] source) where T : unmanaged { - texture.SetData(source.AsSpan(), 0, 0, 0, texture.Width, texture.Height, texture.Depth); + texture.CopyFrom(source.AsSpan(), 0, 0, 0, texture.Width, texture.Height, texture.Depth); } /// @@ -191,10 +191,10 @@ namespace ComputeSharp /// The horizontal range of items to write. /// The vertical range of items to write. /// The depthwise range of items to write. - public static void SetData(this Texture3D texture, T[] source, Range x, Range y, Range z) + public static void CopyFrom(this Texture3D texture, T[] source, Range x, Range y, Range z) where T : unmanaged { - texture.SetData(source.AsSpan(), x, y, z); + texture.CopyFrom(source.AsSpan(), x, y, z); } /// @@ -209,10 +209,10 @@ namespace ComputeSharp /// The width of the memory area to write to. /// The height of the memory area to write to. /// The depth of the memory area to write to. - public static void SetData(this Texture3D texture, T[] source, int x, int y, int z, int width, int height, int depth) + public static void CopyFrom(this Texture3D texture, T[] source, int x, int y, int z, int width, int height, int depth) where T : unmanaged { - texture.SetData(source.AsSpan(), x, y, z, width, height, depth); + texture.CopyFrom(source.AsSpan(), x, y, z, width, height, depth); } /// @@ -225,10 +225,10 @@ namespace ComputeSharp /// The horizontal range of items to write. /// The vertical range of items to write. /// The depthwise range of items to write. - public static void SetData(this Texture3D texture, T[] source, int offset, Range x, Range y, Range z) + public static void CopyFrom(this Texture3D texture, T[] source, int offset, Range x, Range y, Range z) where T : unmanaged { - texture.SetData(source.AsSpan(offset), x, y, z); + texture.CopyFrom(source.AsSpan(offset), x, y, z); } /// @@ -244,10 +244,10 @@ namespace ComputeSharp /// The width of the memory area to write to. /// The height of the memory area to write to. /// The depth of the memory area to write to. - public static void SetData(this Texture3D texture, T[] source, int offset, int x, int y, int z, int width, int height, int depth) + public static void CopyFrom(this Texture3D texture, T[] source, int offset, int x, int y, int z, int width, int height, int depth) where T : unmanaged { - texture.SetData(source.AsSpan(offset), x, y, z, width, height, depth); + texture.CopyFrom(source.AsSpan(offset), x, y, z, width, height, depth); } /// @@ -257,10 +257,10 @@ namespace ComputeSharp /// The type of items stored on the texture. /// The target instance to write data to. /// The input to read data from. - public static void SetData(this Texture3D texture, ReadOnlySpan source) + public static void CopyFrom(this Texture3D texture, ReadOnlySpan source) where T : unmanaged { - texture.SetData(source, 0, 0, 0, texture.Width, texture.Height, texture.Depth); + texture.CopyFrom(source, 0, 0, 0, texture.Width, texture.Height, texture.Depth); } /// @@ -272,14 +272,14 @@ namespace ComputeSharp /// The horizontal range of items to write. /// The vertical range of items to write. /// The depthwise range of items to write. - public static void SetData(this Texture3D texture, ReadOnlySpan source, Range x, Range y, Range z) + public static void CopyFrom(this Texture3D texture, ReadOnlySpan 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); - texture.SetData(source, offsetX, offsetY, offsetZ, width, height, depth); + texture.CopyFrom(source, offsetX, offsetY, offsetZ, width, height, depth); } /// @@ -294,10 +294,10 @@ namespace ComputeSharp /// The width of the memory area to write to. /// The height of the memory area to write to. /// The depth of the memory area to write to. - public static void SetData(this Texture3D texture, ReadOnlySpan source, int x, int y, int z, int width, int height, int depth) + public static void CopyFrom(this Texture3D texture, ReadOnlySpan source, int x, int y, int z, int width, int height, int depth) where T : unmanaged { - texture.SetData(ref MemoryMarshal.GetReference(source), source.Length, x, y, z, width, height, depth); + texture.CopyFrom(ref MemoryMarshal.GetReference(source), source.Length, x, y, z, width, height, depth); } } } diff --git a/src/ComputeSharp/Extensions/Resources/UploadBufferExtensions.cs b/src/ComputeSharp/Extensions/Resources/UploadBufferExtensions.cs index 00ebdef6..e05e1fe3 100644 --- a/src/ComputeSharp/Extensions/Resources/UploadBufferExtensions.cs +++ b/src/ComputeSharp/Extensions/Resources/UploadBufferExtensions.cs @@ -18,7 +18,7 @@ namespace ComputeSharp public static void CopyTo(this UploadBuffer buffer, StructuredBuffer destination) where T : unmanaged { - destination.SetData(buffer, 0, buffer.Length, 0); + destination.CopyFrom(buffer, 0, buffer.Length, 0); } /// @@ -33,7 +33,7 @@ namespace ComputeSharp public static void CopyTo(this UploadBuffer buffer, StructuredBuffer destination, int destinationOffset, int bufferOffset, int count) where T : unmanaged { - destination.SetData(buffer, bufferOffset, count, destinationOffset); + destination.CopyFrom(buffer, bufferOffset, count, destinationOffset); } } } diff --git a/tests/ComputeSharp.Tests/BufferTests.cs b/tests/ComputeSharp.Tests/BufferTests.cs index e8dcc321..5d91a25b 100644 --- a/tests/ComputeSharp.Tests/BufferTests.cs +++ b/tests/ComputeSharp.Tests/BufferTests.cs @@ -50,7 +50,7 @@ namespace ComputeSharp.Tests Assert.AreEqual(buffer.Length, 128); Assert.AreSame(buffer.GraphicsDevice, Gpu.Default); - float[] result = buffer.GetData(); + float[] result = buffer.ToArray(); Assert.IsNotNull(result); Assert.AreEqual(data.Length, result.Length); @@ -78,7 +78,7 @@ namespace ComputeSharp.Tests Assert.AreEqual(destination.Length, 128); Assert.AreSame(destination.GraphicsDevice, Gpu.Default); - float[] result = destination.GetData(); + float[] result = destination.ToArray(); Assert.IsNotNull(result); Assert.AreEqual(data.Length, result.Length); @@ -96,7 +96,7 @@ namespace ComputeSharp.Tests buffer.Dispose(); - _ = buffer.GetData(); + _ = buffer.ToArray(); } [TestMethod] @@ -109,13 +109,13 @@ namespace ComputeSharp.Tests [DataRow(typeof(ReadWriteBuffer<>), 0, 4096)] [DataRow(typeof(ReadWriteBuffer<>), 128, 512)] [DataRow(typeof(ReadWriteBuffer<>), 2048, 2048)] - public void GetData_RangeToArray_Ok(Type bufferType, int offset, int count) + public void CopyTo_RangeToArray_Ok(Type bufferType, int offset, int count) { float[] array = Enumerable.Range(0, 4096).Select(static i => (float)i).ToArray(); using Buffer buffer = Gpu.Default.AllocateBuffer(bufferType, array); - float[] result = buffer.GetData(offset, count); + float[] result = buffer.ToArray(offset, count); Assert.IsNotNull(result); Assert.AreEqual(result.Length, count); @@ -136,13 +136,13 @@ namespace ComputeSharp.Tests [DataRow(typeof(ReadWriteBuffer<>), 512, 4096)] [DataRow(typeof(ReadWriteBuffer<>), 512, -128)] [ExpectedException(typeof(ArgumentOutOfRangeException))] - public void GetData_RangeToArray_Fail(Type bufferType, int offset, int count) + public void CopyTo_RangeToArray_Fail(Type bufferType, int offset, int count) { float[] array = Enumerable.Range(0, 4096).Select(static i => (float)i).ToArray(); using Buffer buffer = Gpu.Default.AllocateBuffer(bufferType, array); - _ = buffer.GetData(offset, count); + _ = buffer.ToArray(offset, count); } [TestMethod] @@ -158,7 +158,7 @@ namespace ComputeSharp.Tests [DataRow(typeof(ReadWriteBuffer<>), 512, 0, 2048)] [DataRow(typeof(ReadWriteBuffer<>), 0, 512, 2048)] [DataRow(typeof(ReadWriteBuffer<>), 127, 1024, 587)] - public void GetData_RangeToVoid_Ok(Type bufferType, int destinationOffset, int bufferOffset, int count) + public void CopyTo_RangeToVoid_Ok(Type bufferType, int destinationOffset, int bufferOffset, int count) { float[] array = Enumerable.Range(0, 4096).Select(static i => (float)i).ToArray(); @@ -166,7 +166,7 @@ namespace ComputeSharp.Tests float[] result = new float[4096]; - buffer.GetData(result, destinationOffset, bufferOffset, count); + buffer.CopyTo(result, destinationOffset, bufferOffset, count); Assert.IsTrue(array.AsSpan(bufferOffset, count).SequenceEqual(result.AsSpan(destinationOffset, count))); } @@ -191,7 +191,7 @@ namespace ComputeSharp.Tests [DataRow(typeof(ReadWriteBuffer<>), 12, 1024, 3600)] [DataRow(typeof(ReadWriteBuffer<>), 12, 1024, -2096)] [ExpectedException(typeof(ArgumentOutOfRangeException))] - public void GetData_RangeToVoid_Fail(Type bufferType, int destinationOffset, int bufferOffset, int count) + public void CopyTo_RangeToVoid_Fail(Type bufferType, int destinationOffset, int bufferOffset, int count) { float[] array = Enumerable.Range(0, 4096).Select(static i => (float)i).ToArray(); @@ -199,7 +199,7 @@ namespace ComputeSharp.Tests float[] result = new float[4096]; - buffer.GetData(result, destinationOffset, bufferOffset, count); + buffer.CopyTo(result, destinationOffset, bufferOffset, count); } [TestMethod] @@ -212,7 +212,7 @@ namespace ComputeSharp.Tests Gpu.Default.For(source.Length, new ConstantBufferKernel(source, destination)); - int[] result = destination.GetData(); + int[] result = destination.ToArray(); CollectionAssert.AreEqual(data, result); } @@ -239,7 +239,7 @@ namespace ComputeSharp.Tests Gpu.Default.For(source.Length, new ReadOnlyBufferKernel(source, destination)); - int[] result = destination.GetData(); + int[] result = destination.ToArray(); CollectionAssert.AreEqual(data, result); } @@ -266,7 +266,7 @@ namespace ComputeSharp.Tests Gpu.Default.For(source.Length, new ReadWriteBufferKernel(source, destination)); - int[] result = destination.GetData(); + int[] result = destination.ToArray(); CollectionAssert.AreEqual(data, result); } diff --git a/tests/ComputeSharp.Tests/DispatchTests.cs b/tests/ComputeSharp.Tests/DispatchTests.cs index 39f74221..2729160f 100644 --- a/tests/ComputeSharp.Tests/DispatchTests.cs +++ b/tests/ComputeSharp.Tests/DispatchTests.cs @@ -13,7 +13,7 @@ namespace ComputeSharp.Tests Gpu.Default.For(buffer.Width, buffer.Height, buffer.Depth, new ThreadIdsShader(buffer)); - Int4[,,] data = buffer.GetData(); + Int4[,,] data = buffer.ToArray(); for (int z = 0; z < 50; z++) { @@ -49,7 +49,7 @@ namespace ComputeSharp.Tests Gpu.Default.For(buffer.Width, buffer.Height, buffer.Depth, 4, 4, 4, new GroupIdsShader(buffer)); - Int4[,,] data = buffer.GetData(); + Int4[,,] data = buffer.ToArray(); for (int z = 0; z < 50; z++) { @@ -87,7 +87,7 @@ namespace ComputeSharp.Tests Gpu.Default.For(1, 1, 1, 4, 15, 7, new GroupSizeShader(buffer)); - int[] data = buffer.GetData(); + int[] data = buffer.ToArray(); Assert.AreEqual(4, data[0]); Assert.AreEqual(15, data[1]); diff --git a/tests/ComputeSharp.Tests/InitializationTests.cs b/tests/ComputeSharp.Tests/InitializationTests.cs index 4e7e8589..2f9e563b 100644 --- a/tests/ComputeSharp.Tests/InitializationTests.cs +++ b/tests/ComputeSharp.Tests/InitializationTests.cs @@ -56,7 +56,7 @@ namespace ComputeSharp.Tests device.For(128, new SampleShader(buffer)); - int[] data = buffer.GetData(); + int[] data = buffer.ToArray(); Assert.IsTrue(data.SequenceEqual(Enumerable.Range(0, 128))); } @@ -75,7 +75,7 @@ namespace ComputeSharp.Tests device.For(128, new SampleShader(buffer)); - int[] data = buffer.GetData(); + int[] data = buffer.ToArray(); Assert.IsTrue(data.SequenceEqual(Enumerable.Range(0, 128))); } diff --git a/tests/ComputeSharp.Tests/Texture2DTests.cs b/tests/ComputeSharp.Tests/Texture2DTests.cs index 77991cfe..61e93068 100644 --- a/tests/ComputeSharp.Tests/Texture2DTests.cs +++ b/tests/ComputeSharp.Tests/Texture2DTests.cs @@ -53,7 +53,7 @@ namespace ComputeSharp.Tests Assert.AreEqual(texture.Height, 128); Assert.AreSame(texture.GraphicsDevice, Gpu.Default); - float[,] result = texture.GetData(); + float[,] result = texture.ToArray(); Assert.IsNotNull(result); Assert.AreEqual(data.Length, result.Length); @@ -70,7 +70,7 @@ namespace ComputeSharp.Tests texture.Dispose(); - _ = texture.GetData(); + _ = texture.ToArray(); } [TestMethod] @@ -100,7 +100,7 @@ namespace ComputeSharp.Tests float[] result = new float[width * height]; - texture.GetData(result, x, y, width, height); + texture.CopyTo(result, x, y, width, height); Span2D expected = new Span2D(array, 64, 64).Slice(y, x, height, width), @@ -135,7 +135,7 @@ namespace ComputeSharp.Tests float[] result = new float[4096]; - texture.GetData(result, x, y, width, height); + texture.CopyTo(result, x, y, width, height); } [TestMethod] @@ -148,7 +148,7 @@ namespace ComputeSharp.Tests Gpu.Default.For(source.Width, source.Height, new ReadOnlyTexture2DKernel(source, destination)); - int[] result = destination.GetData(); + int[] result = destination.ToArray(); CollectionAssert.AreEqual(data, result); } @@ -177,7 +177,7 @@ namespace ComputeSharp.Tests int[] result = new int[data.Length]; - destination.GetData(result); + destination.CopyTo(result); CollectionAssert.AreEqual(data, result); } diff --git a/tests/ComputeSharp.Tests/Texture3DTests.cs b/tests/ComputeSharp.Tests/Texture3DTests.cs index b2adb7e0..3c8e0ec1 100644 --- a/tests/ComputeSharp.Tests/Texture3DTests.cs +++ b/tests/ComputeSharp.Tests/Texture3DTests.cs @@ -66,7 +66,7 @@ namespace ComputeSharp.Tests Assert.AreEqual(texture.Depth, depth); Assert.AreSame(texture.GraphicsDevice, Gpu.Default); - float[,,] result = texture.GetData(); + float[,,] result = texture.ToArray(); Assert.IsNotNull(result); Assert.AreEqual(result.GetLength(0), depth); @@ -79,7 +79,7 @@ namespace ComputeSharp.Tests float[] flat = new float[result.Length]; - texture.GetData(flat); + texture.CopyTo(flat); CollectionAssert.AreEqual(flat, data); } @@ -94,7 +94,7 @@ namespace ComputeSharp.Tests texture.Dispose(); - _ = texture.GetData(); + _ = texture.ToArray(); } [TestMethod] @@ -129,7 +129,7 @@ namespace ComputeSharp.Tests int[,,] result = new int[depth, height, width]; - texture.GetData(result.AsSpan(), x, y, z, width, height, depth); + texture.CopyTo(result.AsSpan(), x, y, z, width, height, depth); for (int k = 0; k < depth; k++) { @@ -169,7 +169,7 @@ namespace ComputeSharp.Tests float[] result = new float[array.Length]; - texture.GetData(result, x, y, z, width, height, depth); + texture.CopyTo(result, x, y, z, width, height, depth); } [TestMethod] @@ -182,7 +182,7 @@ namespace ComputeSharp.Tests Gpu.Default.For(source.Width, source.Height, source.Depth, new ReadOnlyTexture3DKernel(source, destination)); - int[] result = destination.GetData(); + int[] result = destination.ToArray(); CollectionAssert.AreEqual(data, result); } @@ -211,7 +211,7 @@ namespace ComputeSharp.Tests int[] result = new int[data.Length]; - destination.GetData(result); + destination.CopyTo(result); CollectionAssert.AreEqual(data, result); }