diff --git a/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs b/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs index 9e889be2..d2a6e53d 100644 --- a/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs +++ b/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs @@ -139,70 +139,6 @@ namespace ComputeSharp return readWriteBuffer; } - /// - /// 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 length of the buffer to allocate. - /// A zeroed instance of size . - [Pure] - public static ReadWriteBuffer AllocateReadWriteBuffer(this GraphicsDevice device, int length) - where T : unmanaged - { - return new(device, length); - } - - /// - /// 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 array with the data to copy on the allocated buffer. - /// A read write instance with the contents of the input array. - [Pure] - public static ReadWriteBuffer AllocateReadWriteBuffer(this GraphicsDevice device, T[] array) - where T : unmanaged - { - return device.AllocateReadWriteBuffer(array.AsSpan()); - } - - /// - /// 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, ReadOnlySpan span) - where T : unmanaged - { - ReadWriteBuffer buffer = new(device, span.Length); - - buffer.SetData(span); - - 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, Buffer buffer) - where T : unmanaged - { - ReadWriteBuffer readWriteBuffer = new(device, buffer.Length); - - readWriteBuffer.SetData(buffer); - - return readWriteBuffer; - } - /// /// Allocates a new readonly 2D texture with the specified parameters. /// @@ -289,92 +225,6 @@ namespace ComputeSharp return texture; } - /// - /// Allocates a new writeable 2D texture with the specified parameters. - /// - /// The type of items to store in the texture. - /// The instance to use to allocate the texture. - /// The width of the texture. - /// The height of the texture. - /// A zeroed instance of size [, ]. - [Pure] - public static ReadWriteTexture2D AllocateReadWriteTexture2D(this GraphicsDevice device, int width, int height) - where T : unmanaged - { - return new(device, width, height); - } - - /// - /// Allocates a new writeable 2D texture with the specified parameters. - /// - /// The type of items to store in the texture. - /// The instance to use to allocate the texture. - /// The input array with the data to copy on the allocated texture. - /// The width of the texture. - /// The height of the texture. - /// A instance with the contents of the input array. - [Pure] - public static ReadWriteTexture2D AllocateReadWriteTexture2D(this GraphicsDevice device, T[] array, int width, int height) - where T : unmanaged - { - return device.AllocateReadWriteTexture2D(array.AsSpan(), width, height); - } - - /// - /// Allocates a new writeable 2D texture with the specified parameters. - /// - /// The type of items to store in the texture. - /// The instance to use to allocate the texture. - /// The input array with the data to copy on the allocated texture. - /// The starting offset within to read data from. - /// The width of the texture. - /// The height of the texture. - /// A instance with the contents of the input array. - [Pure] - public static ReadWriteTexture2D AllocateReadWriteTexture2D(this GraphicsDevice device, T[] array, int offset, int width, int height) - where T : unmanaged - { - return device.AllocateReadWriteTexture2D(array.AsSpan(offset), width, height); - } - - /// - /// Allocates a new writeable 2D texture with the specified parameters. - /// - /// The type of items to store in the texture. - /// The instance to use to allocate the texture. - /// The input array with the data to copy on the allocated texture. - /// A read write instance with the contents of the input array. - [Pure] - public static ReadWriteTexture2D AllocateReadWriteTexture2D(this GraphicsDevice device, T[,] array) - where T : unmanaged - { - ReadWriteTexture2D texture = new(device, array.GetLength(1), array.GetLength(0)); - - texture.SetData(array); - - return texture; - } - - /// - /// Allocates a new writeable 2D texture with the specified parameters. - /// - /// The type of items to store in the texture. - /// The instance to use to allocate the texture. - /// The input with the data to copy on the allocated texture. - /// The width of the texture. - /// The height of the texture. - /// A instance with the contents of the input . - [Pure] - public static ReadWriteTexture2D AllocateReadWriteTexture2D(this GraphicsDevice device, ReadOnlySpan span, int width, int height) - where T : unmanaged - { - ReadWriteTexture2D texture = new(device, width, height); - - texture.SetData(span); - - return texture; - } - /// /// Allocates a new readonly 3D texture with the specified parameters. /// @@ -469,6 +319,156 @@ namespace ComputeSharp return texture; } + /// + /// 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 length of the buffer to allocate. + /// A zeroed instance of size . + [Pure] + public static ReadWriteBuffer AllocateReadWriteBuffer(this GraphicsDevice device, int length) + where T : unmanaged + { + return new(device, length); + } + + /// + /// 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 array with the data to copy on the allocated buffer. + /// A read write instance with the contents of the input array. + [Pure] + public static ReadWriteBuffer AllocateReadWriteBuffer(this GraphicsDevice device, T[] array) + where T : unmanaged + { + return device.AllocateReadWriteBuffer(array.AsSpan()); + } + + /// + /// 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, ReadOnlySpan span) + where T : unmanaged + { + ReadWriteBuffer buffer = new(device, span.Length); + + buffer.SetData(span); + + 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, Buffer buffer) + where T : unmanaged + { + ReadWriteBuffer readWriteBuffer = new(device, buffer.Length); + + readWriteBuffer.SetData(buffer); + + return readWriteBuffer; + } + + /// + /// Allocates a new writeable 2D texture with the specified parameters. + /// + /// The type of items to store in the texture. + /// The instance to use to allocate the texture. + /// The width of the texture. + /// The height of the texture. + /// A zeroed instance of size [, ]. + [Pure] + public static ReadWriteTexture2D AllocateReadWriteTexture2D(this GraphicsDevice device, int width, int height) + where T : unmanaged + { + return new(device, width, height); + } + + /// + /// Allocates a new writeable 2D texture with the specified parameters. + /// + /// The type of items to store in the texture. + /// The instance to use to allocate the texture. + /// The input array with the data to copy on the allocated texture. + /// The width of the texture. + /// The height of the texture. + /// A instance with the contents of the input array. + [Pure] + public static ReadWriteTexture2D AllocateReadWriteTexture2D(this GraphicsDevice device, T[] array, int width, int height) + where T : unmanaged + { + return device.AllocateReadWriteTexture2D(array.AsSpan(), width, height); + } + + /// + /// Allocates a new writeable 2D texture with the specified parameters. + /// + /// The type of items to store in the texture. + /// The instance to use to allocate the texture. + /// The input array with the data to copy on the allocated texture. + /// The starting offset within to read data from. + /// The width of the texture. + /// The height of the texture. + /// A instance with the contents of the input array. + [Pure] + public static ReadWriteTexture2D AllocateReadWriteTexture2D(this GraphicsDevice device, T[] array, int offset, int width, int height) + where T : unmanaged + { + return device.AllocateReadWriteTexture2D(array.AsSpan(offset), width, height); + } + + /// + /// Allocates a new writeable 2D texture with the specified parameters. + /// + /// The type of items to store in the texture. + /// The instance to use to allocate the texture. + /// The input array with the data to copy on the allocated texture. + /// A read write instance with the contents of the input array. + [Pure] + public static ReadWriteTexture2D AllocateReadWriteTexture2D(this GraphicsDevice device, T[,] array) + where T : unmanaged + { + ReadWriteTexture2D texture = new(device, array.GetLength(1), array.GetLength(0)); + + texture.SetData(array); + + return texture; + } + + /// + /// Allocates a new writeable 2D texture with the specified parameters. + /// + /// The type of items to store in the texture. + /// The instance to use to allocate the texture. + /// The input with the data to copy on the allocated texture. + /// The width of the texture. + /// The height of the texture. + /// A instance with the contents of the input . + [Pure] + public static ReadWriteTexture2D AllocateReadWriteTexture2D(this GraphicsDevice device, ReadOnlySpan span, int width, int height) + where T : unmanaged + { + ReadWriteTexture2D texture = new(device, width, height); + + texture.SetData(span); + + return texture; + } + /// /// Allocates a new writeable 3D texture with the specified parameters. ///