diff --git a/src/ComputeSharp.Graphics/Buffers/Extensions/BufferExtensions.cs b/src/ComputeSharp.Graphics/Buffers/Extensions/BufferExtensions.cs
index 708bdb95..5d1112ea 100644
--- a/src/ComputeSharp.Graphics/Buffers/Extensions/BufferExtensions.cs
+++ b/src/ComputeSharp.Graphics/Buffers/Extensions/BufferExtensions.cs
@@ -12,6 +12,152 @@ namespace ComputeSharp
///
public static class BufferExtensions
{
+ ///
+ /// Allocates a new constant 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 constant instance with the contents of the input array
+ [Pure]
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static ConstantBuffer AllocateConstantBuffer(this GraphicsDevice device, T[] array) where T : unmanaged
+ {
+ return device.AllocateConstantBuffer(array.AsSpan());
+ }
+
+ ///
+ /// Allocates a new constant buffer with the specified parameters
+ ///
+ /// The type of items to store in the buffer
+ /// The instance to use to allocate the buffer
+ /// The input 2D array with the data to copy on the allocated buffer
+ /// 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
+ {
+ fixed (T* p = array)
+ {
+ Span span = new Span(p, array.Length);
+ return device.AllocateConstantBuffer(span);
+ }
+ }
+
+ ///
+ /// Allocates a new constant 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 constant instance with the contents of the input
+ [Pure]
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static ConstantBuffer AllocateConstantBuffer(this GraphicsDevice device, Span span) where T : unmanaged
+ {
+ ConstantBuffer buffer = new ConstantBuffer(device, span.Length);
+ buffer.SetData(span);
+
+ return buffer;
+ }
+
+ ///
+ /// Allocates a new constant 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 constant instance with the contents of the input
+ [Pure]
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static ConstantBuffer AllocateConstantBuffer(this GraphicsDevice device, HlslBuffer buffer) where T : unmanaged
+ {
+ ConstantBuffer constantBuffer = new ConstantBuffer(device, buffer.Size);
+ constantBuffer.SetData(buffer);
+
+ return constantBuffer;
+ }
+
+ ///
+ /// 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 size of the buffer to allocate
+ /// A zeroed instance of size
+ [Pure]
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static ReadOnlyBuffer AllocateReadOnlyBuffer(this GraphicsDevice device, int size) where T : unmanaged
+ {
+ return new ReadOnlyBuffer(device, size);
+ }
+
+ ///
+ /// 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 array with the data to copy on the allocated buffer
+ /// A read write instance with the contents of the input array
+ [Pure]
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static ReadOnlyBuffer AllocateReadOnlyBuffer(this GraphicsDevice device, T[] array) where T : unmanaged
+ {
+ return device.AllocateReadOnlyBuffer(array.AsSpan());
+ }
+
+ ///
+ /// 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 2D array with the data to copy on the allocated buffer
+ /// 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
+ {
+ fixed (T* p = array)
+ {
+ Span span = new Span(p, array.Length);
+ return device.AllocateReadOnlyBuffer(span);
+ }
+ }
+
+ ///
+ /// 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]
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static ReadOnlyBuffer AllocateReadOnlyBuffer(this GraphicsDevice device, Span span) where T : unmanaged
+ {
+ ReadOnlyBuffer buffer = new ReadOnlyBuffer(device, span.Length);
+ buffer.SetData(span);
+
+ 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]
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static ReadOnlyBuffer AllocateReadOnlyBuffer(this GraphicsDevice device, HlslBuffer buffer) where T : unmanaged
+ {
+ ReadOnlyBuffer readWriteBuffer = new ReadOnlyBuffer(device, buffer.Size);
+ readWriteBuffer.SetData(buffer);
+
+ return readWriteBuffer;
+ }
+
///
/// Allocates a new read write buffer with the specified parameters
///
@@ -91,71 +237,5 @@ namespace ComputeSharp
return readWriteBuffer;
}
-
- ///
- /// Allocates a new constant 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 constant instance with the contents of the input array
- [Pure]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ConstantBuffer AllocateConstantBuffer(this GraphicsDevice device, T[] array) where T : unmanaged
- {
- return device.AllocateConstantBuffer(array.AsSpan());
- }
-
- ///
- /// Allocates a new constant buffer with the specified parameters
- ///
- /// The type of items to store in the buffer
- /// The instance to use to allocate the buffer
- /// The input 2D array with the data to copy on the allocated buffer
- /// 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
- {
- fixed (T* p = array)
- {
- Span span = new Span(p, array.Length);
- return device.AllocateConstantBuffer(span);
- }
- }
-
- ///
- /// Allocates a new constant 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 constant instance with the contents of the input
- [Pure]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ConstantBuffer AllocateConstantBuffer(this GraphicsDevice device, Span span) where T : unmanaged
- {
- ConstantBuffer buffer = new ConstantBuffer(device, span.Length);
- buffer.SetData(span);
-
- return buffer;
- }
-
- ///
- /// Allocates a new constant 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 constant instance with the contents of the input
- [Pure]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ConstantBuffer AllocateConstantBuffer(this GraphicsDevice device, HlslBuffer buffer) where T : unmanaged
- {
- ConstantBuffer constantBuffer = new ConstantBuffer(device, buffer.Size);
- constantBuffer.SetData(buffer);
-
- return constantBuffer;
- }
}
}