From 0f6fb3f49ee377e747e423993c10aca824ab0330 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 4 Feb 2021 21:42:23 +0100 Subject: [PATCH] Streamlined some transfer resource extensions --- .../Extensions/GraphicsDeviceExtensions.cs | 106 ++++++------------ 1 file changed, 34 insertions(+), 72 deletions(-) diff --git a/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs b/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs index 252f2d78..834b2bab 100644 --- a/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs +++ b/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs @@ -125,24 +125,6 @@ namespace ComputeSharp return buffer; } - /// - /// Allocates a new readonly buffer with the specified parameters. - /// - /// The type of items to store in the buffer. - /// The instance to use to allocate the buffer. - /// The input with the data to copy on the allocated buffer. - /// A read write instance with the contents of the input . - [Pure] - public static ReadOnlyBuffer AllocateReadOnlyBuffer(this GraphicsDevice device, UploadBuffer source) - where T : unmanaged - { - ReadOnlyBuffer readWriteBuffer = new(device, source.Length, AllocationMode.Default); - - readWriteBuffer.CopyFrom(source, 0, source.Length, 0); - - return readWriteBuffer; - } - /// /// Allocates a new readonly buffer with the specified parameters. /// @@ -592,24 +574,6 @@ namespace ComputeSharp return buffer; } - /// - /// Allocates a new read write buffer with the specified parameters. - /// - /// The type of items to store in the buffer. - /// The instance to use to allocate the buffer. - /// The input with the data to copy on the allocated buffer. - /// A read write instance with the contents of the input . - [Pure] - public static ReadWriteBuffer AllocateReadWriteBuffer(this GraphicsDevice device, UploadBuffer source) - where T : unmanaged - { - ReadWriteBuffer readWriteBuffer = new(device, source.Length, AllocationMode.Default); - - readWriteBuffer.CopyFrom(source, 0, source.Length, 0); - - return readWriteBuffer; - } - /// /// Allocates a new read write buffer with the specified parameters. /// @@ -917,7 +881,7 @@ namespace ComputeSharp /// The height of the texture. /// The depth of the texture. /// The allocation mode to use for the new resource. - /// A zeroed instance of size [, ]. + /// A instance of size [, , ]. [Pure] public static ReadWriteTexture3D AllocateReadWriteTexture3D(this GraphicsDevice device, int width, int height, int depth, AllocationMode allocationMode = AllocationMode.Default) where T : unmanaged, IUnorm @@ -1019,7 +983,7 @@ namespace ComputeSharp /// The instance to use to allocate the buffer. /// The length of the buffer to allocate. /// The allocation mode to use for the new resource. - /// A zeroed instance of size . + /// A instance of size . [Pure] public static UploadBuffer AllocateUploadBuffer(this GraphicsDevice device, int length, AllocationMode allocationMode = AllocationMode.Default) where T : unmanaged @@ -1028,45 +992,46 @@ namespace ComputeSharp } /// - /// Allocates a new readonly buffer with the specified parameters. + /// Allocates a new upload 2D texture with the specified parameters. /// /// The type of items to store in the buffer. /// The instance to use to allocate the buffer. - /// The input array with the data to copy on the allocated buffer. - /// A read write instance with the contents of the input array. + /// The width of the texture. + /// The height of the texture. + /// The allocation mode to use for the new resource. + /// A instance of size [, ]. [Pure] - public static UploadBuffer AllocateUploadBuffer(this GraphicsDevice device, T[] source) + public static UploadTexture2D AllocateUploadTexture2D(this GraphicsDevice device, int width, int height, AllocationMode allocationMode = AllocationMode.Default) where T : unmanaged { - return device.AllocateUploadBuffer(source.AsSpan()); + return new(device, width, height, allocationMode); } /// - /// Allocates a new readonly buffer with the specified parameters. + /// Allocates a new upload 3D texture with the specified parameters. /// /// The type of items to store in the buffer. /// The instance to use to allocate the buffer. - /// The input with the data to copy on the allocated buffer. - /// A read write instance with the contents of the input . + /// The width of the texture. + /// The height of the texture. + /// The depth of the texture. + /// The allocation mode to use for the new resource. + /// A instance of size [, , ]. [Pure] - public static UploadBuffer AllocateUploadBuffer(this GraphicsDevice device, ReadOnlySpan source) + public static UploadTexture3D AllocateUploadTexture3D(this GraphicsDevice device, int width, int height, int depth, AllocationMode allocationMode = AllocationMode.Default) where T : unmanaged { - UploadBuffer buffer = new(device, source.Length, AllocationMode.Default); - - source.CopyTo(buffer.Span); - - return buffer; + return new(device, width, height, depth, allocationMode); } /// - /// Allocates a new upload buffer with the specified parameters. + /// Allocates a new readback buffer with the specified parameters. /// /// The type of items to store in the buffer. /// The instance to use to allocate the buffer. /// The length of the buffer to allocate. /// The allocation mode to use for the new resource. - /// A zeroed instance of size . + /// A instance of size . [Pure] public static ReadBackBuffer AllocateReadBackBuffer(this GraphicsDevice device, int length, AllocationMode allocationMode = AllocationMode.Default) where T : unmanaged @@ -1075,39 +1040,36 @@ namespace ComputeSharp } /// - /// Allocates a new readonly buffer with the specified parameters. + /// Allocates a new readback 2D texture with the specified parameters. /// /// The type of items to store in the buffer. /// The instance to use to allocate the buffer. - /// The input with the data to copy on the allocated buffer. - /// A read write instance with the contents of the input . + /// The width of the texture. + /// The height of the texture. + /// The allocation mode to use for the new resource. + /// A instance of size [, ]. [Pure] - public static ReadBackBuffer AllocateReadBackBuffer(this GraphicsDevice device, ReadOnlySpan source) + public static ReadBackTexture2D AllocateReadBackTexture2D(this GraphicsDevice device, int width, int height, AllocationMode allocationMode = AllocationMode.Default) where T : unmanaged { - ReadBackBuffer buffer = new(device, source.Length, AllocationMode.Default); - - source.CopyTo(buffer.Span); - - return buffer; + return new(device, width, height, allocationMode); } /// - /// Allocates a new readonly buffer with the specified parameters. + /// Allocates a new readback 3D texture with the specified parameters. /// /// The type of items to store in the buffer. /// The instance to use to allocate the buffer. - /// The input with the data to copy on the allocated buffer. - /// A read write instance with the contents of the input array. + /// The width of the texture. + /// The height of the texture. + /// The depth of the texture. + /// The allocation mode to use for the new resource. + /// A instance of size [, , ]. [Pure] - public static ReadBackBuffer AllocateReadBackBuffer(this GraphicsDevice device, StructuredBuffer source) + public static ReadBackTexture3D AllocateReadBackTexture3D(this GraphicsDevice device, int width, int height, int depth, AllocationMode allocationMode = AllocationMode.Default) where T : unmanaged { - ReadBackBuffer buffer = new(device, source.Length, AllocationMode.Default); - - source.CopyTo(buffer, 0, buffer.Length, 0); - - return buffer; + return new(device, width, height, depth, allocationMode); } ///