From f465a52fb3b03f0a7f32cf7232893d2d52beae26 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 26 Aug 2019 03:46:01 +0200 Subject: [PATCH] Removed array pinning --- .../Buffers/Extensions/BufferExtensions.cs | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/ComputeSharp.Graphics/Buffers/Extensions/BufferExtensions.cs b/src/ComputeSharp.Graphics/Buffers/Extensions/BufferExtensions.cs index 5d1112ea..7eaa205e 100644 --- a/src/ComputeSharp.Graphics/Buffers/Extensions/BufferExtensions.cs +++ b/src/ComputeSharp.Graphics/Buffers/Extensions/BufferExtensions.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using ComputeSharp.Graphics; using ComputeSharp.Graphics.Buffers; using ComputeSharp.Graphics.Buffers.Abstract; @@ -35,13 +36,10 @@ namespace ComputeSharp /// A constant instance with the contents of the input 2D array [Pure] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static unsafe ConstantBuffer AllocateConstantBuffer(this GraphicsDevice device, T[,] array) where T : unmanaged + public static ConstantBuffer AllocateConstantBuffer(this GraphicsDevice device, T[,] array) where T : unmanaged { - fixed (T* p = array) - { - Span span = new Span(p, array.Length); - return device.AllocateConstantBuffer(span); - } + Span span = MemoryMarshal.CreateSpan(ref array[0, 0], array.Length); + return device.AllocateConstantBuffer(span); } /// @@ -115,13 +113,10 @@ namespace ComputeSharp /// A read write instance with the contents of the input 2D array [Pure] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static unsafe ReadOnlyBuffer AllocateReadOnlyBuffer(this GraphicsDevice device, T[,] array) where T : unmanaged + public static ReadOnlyBuffer AllocateReadOnlyBuffer(this GraphicsDevice device, T[,] array) where T : unmanaged { - fixed (T* p = array) - { - Span span = new Span(p, array.Length); - return device.AllocateReadOnlyBuffer(span); - } + Span span = MemoryMarshal.CreateSpan(ref array[0, 0], array.Length); + return device.AllocateReadOnlyBuffer(span); } /// @@ -195,13 +190,10 @@ namespace ComputeSharp /// A read write instance with the contents of the input 2D array [Pure] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static unsafe ReadWriteBuffer AllocateReadWriteBuffer(this GraphicsDevice device, T[,] array) where T : unmanaged + public static ReadWriteBuffer AllocateReadWriteBuffer(this GraphicsDevice device, T[,] array) where T : unmanaged { - fixed (T* p = array) - { - Span span = new Span(p, array.Length); - return device.AllocateReadWriteBuffer(span); - } + Span span = MemoryMarshal.CreateSpan(ref array[0, 0], array.Length); + return device.AllocateReadWriteBuffer(span); } ///