Streamlined some transfer resource extensions

このコミットが含まれているのは:
Sergio Pedri committed 2021-02-04 21:42:23 +01:00
1 親 914dd052b7
コミット 0f6fb3f49e
1ファイル変更
+34 -72
+34 -72
ファイルの表示
@@ -125,24 +125,6 @@ namespace ComputeSharp
return buffer;
}
/// <summary>
/// Allocates a new readonly buffer with the specified parameters.
/// </summary>
/// <typeparam name="T">The type of items to store in the buffer.</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer.</param>
/// <param name="source">The input <see cref="UploadBuffer{T}"/> with the data to copy on the allocated buffer.</param>
/// <returns>A read write <see cref="ReadOnlyBuffer{T}"/> instance with the contents of the input <see cref="UploadBuffer{T}"/>.</returns>
[Pure]
public static ReadOnlyBuffer<T> AllocateReadOnlyBuffer<T>(this GraphicsDevice device, UploadBuffer<T> source)
where T : unmanaged
{
ReadOnlyBuffer<T> readWriteBuffer = new(device, source.Length, AllocationMode.Default);
readWriteBuffer.CopyFrom(source, 0, source.Length, 0);
return readWriteBuffer;
}
/// <summary>
/// Allocates a new readonly buffer with the specified parameters.
/// </summary>
@@ -592,24 +574,6 @@ namespace ComputeSharp
return buffer;
}
/// <summary>
/// Allocates a new read write buffer with the specified parameters.
/// </summary>
/// <typeparam name="T">The type of items to store in the buffer.</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer.</param>
/// <param name="source">The input <see cref="UploadBuffer{T}"/> with the data to copy on the allocated buffer.</param>
/// <returns>A read write <see cref="ReadWriteBuffer{T}"/> instance with the contents of the input <see cref="UploadBuffer{T}"/>.</returns>
[Pure]
public static ReadWriteBuffer<T> AllocateReadWriteBuffer<T>(this GraphicsDevice device, UploadBuffer<T> source)
where T : unmanaged
{
ReadWriteBuffer<T> readWriteBuffer = new(device, source.Length, AllocationMode.Default);
readWriteBuffer.CopyFrom(source, 0, source.Length, 0);
return readWriteBuffer;
}
/// <summary>
/// Allocates a new read write buffer with the specified parameters.
/// </summary>
@@ -917,7 +881,7 @@ namespace ComputeSharp
/// <param name="height">The height of the texture.</param>
/// <param name="depth">The depth of the texture.</param>
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
/// <returns>A zeroed <see cref="ReadWriteTexture3D{T,TPixel}"/> instance of size [<paramref name="width"/>, <paramref name="height"/>].</returns>
/// <returns>A <see cref="ReadWriteTexture3D{T,TPixel}"/> instance of size [<paramref name="width"/>, <paramref name="height"/>, <paramref name="depth"/>].</returns>
[Pure]
public static ReadWriteTexture3D<T, TPixel> AllocateReadWriteTexture3D<T, TPixel>(this GraphicsDevice device, int width, int height, int depth, AllocationMode allocationMode = AllocationMode.Default)
where T : unmanaged, IUnorm<TPixel>
@@ -1019,7 +983,7 @@ namespace ComputeSharp
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer.</param>
/// <param name="length">The length of the buffer to allocate.</param>
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
/// <returns>A zeroed <see cref="ReadOnlyBuffer{T}"/> instance of size <paramref name="length"/>.</returns>
/// <returns>A <see cref="ReadOnlyBuffer{T}"/> instance of size <paramref name="length"/>.</returns>
[Pure]
public static UploadBuffer<T> AllocateUploadBuffer<T>(this GraphicsDevice device, int length, AllocationMode allocationMode = AllocationMode.Default)
where T : unmanaged
@@ -1028,45 +992,46 @@ namespace ComputeSharp
}
/// <summary>
/// Allocates a new readonly buffer with the specified parameters.
/// Allocates a new upload 2D texture with the specified parameters.
/// </summary>
/// <typeparam name="T">The type of items to store in the buffer.</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer.</param>
/// <param name="source">The input <typeparamref name="T"/> array with the data to copy on the allocated buffer.</param>
/// <returns>A read write <see cref="ReadOnlyBuffer{T}"/> instance with the contents of the input array.</returns>
/// <param name="width">The width of the texture.</param>
/// <param name="height">The height of the texture.</param>
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
/// <returns>A <see cref="UploadTexture2D{T}"/> instance of size [<paramref name="width"/>, <paramref name="height"/>].</returns>
[Pure]
public static UploadBuffer<T> AllocateUploadBuffer<T>(this GraphicsDevice device, T[] source)
public static UploadTexture2D<T> AllocateUploadTexture2D<T>(this GraphicsDevice device, int width, int height, AllocationMode allocationMode = AllocationMode.Default)
where T : unmanaged
{
return device.AllocateUploadBuffer<T>(source.AsSpan());
return new(device, width, height, allocationMode);
}
/// <summary>
/// Allocates a new readonly buffer with the specified parameters.
/// Allocates a new upload 3D texture with the specified parameters.
/// </summary>
/// <typeparam name="T">The type of items to store in the buffer.</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer.</param>
/// <param name="source">The input <see cref="ReadOnlySpan{T}"/> with the data to copy on the allocated buffer.</param>
/// <returns>A read write <see cref="ReadOnlyBuffer{T}"/> instance with the contents of the input <see cref="ReadOnlySpan{T}"/>.</returns>
/// <param name="width">The width of the texture.</param>
/// <param name="height">The height of the texture.</param>
/// <param name="depth">The depth of the texture.</param>
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
/// <returns>A <see cref="UploadTexture3D{T}"/> instance of size [<paramref name="width"/>, <paramref name="height"/>, <paramref name="depth"/>].</returns>
[Pure]
public static UploadBuffer<T> AllocateUploadBuffer<T>(this GraphicsDevice device, ReadOnlySpan<T> source)
public static UploadTexture3D<T> AllocateUploadTexture3D<T>(this GraphicsDevice device, int width, int height, int depth, AllocationMode allocationMode = AllocationMode.Default)
where T : unmanaged
{
UploadBuffer<T> buffer = new(device, source.Length, AllocationMode.Default);
source.CopyTo(buffer.Span);
return buffer;
return new(device, width, height, depth, allocationMode);
}
/// <summary>
/// Allocates a new upload buffer with the specified parameters.
/// Allocates a new readback buffer with the specified parameters.
/// </summary>
/// <typeparam name="T">The type of items to store in the buffer.</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer.</param>
/// <param name="length">The length of the buffer to allocate.</param>
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
/// <returns>A zeroed <see cref="ReadOnlyBuffer{T}"/> instance of size <paramref name="length"/>.</returns>
/// <returns>A <see cref="ReadBackBuffer{T}"/> instance of size <paramref name="length"/>.</returns>
[Pure]
public static ReadBackBuffer<T> AllocateReadBackBuffer<T>(this GraphicsDevice device, int length, AllocationMode allocationMode = AllocationMode.Default)
where T : unmanaged
@@ -1075,39 +1040,36 @@ namespace ComputeSharp
}
/// <summary>
/// Allocates a new readonly buffer with the specified parameters.
/// Allocates a new readback 2D texture with the specified parameters.
/// </summary>
/// <typeparam name="T">The type of items to store in the buffer.</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer.</param>
/// <param name="source">The input <see cref="ReadOnlySpan{T}"/> with the data to copy on the allocated buffer.</param>
/// <returns>A read write <see cref="ReadOnlyBuffer{T}"/> instance with the contents of the input <see cref="ReadOnlySpan{T}"/>.</returns>
/// <param name="width">The width of the texture.</param>
/// <param name="height">The height of the texture.</param>
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
/// <returns>A <see cref="ReadBackTexture2D{T}"/> instance of size [<paramref name="width"/>, <paramref name="height"/>].</returns>
[Pure]
public static ReadBackBuffer<T> AllocateReadBackBuffer<T>(this GraphicsDevice device, ReadOnlySpan<T> source)
public static ReadBackTexture2D<T> AllocateReadBackTexture2D<T>(this GraphicsDevice device, int width, int height, AllocationMode allocationMode = AllocationMode.Default)
where T : unmanaged
{
ReadBackBuffer<T> buffer = new(device, source.Length, AllocationMode.Default);
source.CopyTo(buffer.Span);
return buffer;
return new(device, width, height, allocationMode);
}
/// <summary>
/// Allocates a new readonly buffer with the specified parameters.
/// Allocates a new readback 3D texture with the specified parameters.
/// </summary>
/// <typeparam name="T">The type of items to store in the buffer.</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer.</param>
/// <param name="source">The input <see cref="Buffer{T}"/> with the data to copy on the allocated buffer.</param>
/// <returns>A read write <see cref="ReadOnlyBuffer{T}"/> instance with the contents of the input array.</returns>
/// <param name="width">The width of the texture.</param>
/// <param name="height">The height of the texture.</param>
/// <param name="depth">The depth of the texture.</param>
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
/// <returns>A <see cref="ReadBackTexture3D{T}"/> instance of size [<paramref name="width"/>, <paramref name="height"/>, <paramref name="depth"/>].</returns>
[Pure]
public static ReadBackBuffer<T> AllocateReadBackBuffer<T>(this GraphicsDevice device, StructuredBuffer<T> source)
public static ReadBackTexture3D<T> AllocateReadBackTexture3D<T>(this GraphicsDevice device, int width, int height, int depth, AllocationMode allocationMode = AllocationMode.Default)
where T : unmanaged
{
ReadBackBuffer<T> buffer = new(device, source.Length, AllocationMode.Default);
source.CopyTo(buffer, 0, buffer.Length, 0);
return buffer;
return new(device, width, height, depth, allocationMode);
}
/// <summary>