Added specific writeable and readonly buffer types

このコミットが含まれているのは:
Sergio Pedri committed 2019-08-12 13:48:35 +02:00
1 親 acf2aa9fce
コミット 13ee3e9422
7ファイル変更
+74 -31

検索条件に一致するファイルはありません

+2 -13
ファイルの表示
@@ -11,7 +11,7 @@ namespace ComputeSharp.Graphics.Buffers
/// A <see langword="class"/> representing a typed buffer stored on GPU memory
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer</typeparam>
public sealed class Buffer<T> : GraphicsResource where T : unmanaged
public class Buffer<T> : GraphicsResource where T : unmanaged
{
/// <summary>
/// Creates a new <see cref="Buffer{T}"/> instance with the specified parameters
@@ -19,7 +19,7 @@ namespace ComputeSharp.Graphics.Buffers
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance</param>
/// <param name="size">The number of items to store in the current buffer</param>
/// <param name="heapType">The heap type for the current buffer</param>
internal Buffer(GraphicsDevice device, int size, HeapType heapType) : base(device)
protected internal Buffer(GraphicsDevice device, int size, HeapType heapType) : base(device)
{
Size = size;
ElementSizeInBytes = Unsafe.SizeOf<T>();
@@ -108,17 +108,6 @@ namespace ComputeSharp.Graphics.Buffers
/// </summary>
public HeapType HeapType { get; }
/// <summary>
/// Gets or sets a single value from the current buffer
/// </summary>
/// <param name="i">The index of the value to get or set</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else</remarks>
public T this[uint i]
{
get => throw new InvalidOperationException("The indexer APIs can only be used from a compute shader");
set => throw new InvalidOperationException("The indexer APIs can only be used from a compute shader");
}
/// <summary>
/// Reads the contents of the current <see cref="Buffer{T}"/> instance and returns an array
/// </summary>
+9 -9
ファイルの表示
@@ -16,12 +16,12 @@ namespace ComputeSharp.Graphics.Buffers
/// <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="size">The size of the buffer to allocate</param>
/// <returns>A zeroed read write <see cref="Buffer{T}"/> instance of size <paramref name="size"/></returns>
/// <returns>A zeroed <see cref="ReadWriteBuffer{T}"/> instance of size <paramref name="size"/></returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Buffer<T> AllocateReadWriteBuffer<T>(this GraphicsDevice device, int size) where T : unmanaged
public static ReadWriteBuffer<T> AllocateReadWriteBuffer<T>(this GraphicsDevice device, int size) where T : unmanaged
{
return new Buffer<T>(device, size, HeapType.Default);
return new ReadWriteBuffer<T>(device, size);
}
/// <summary>
@@ -30,12 +30,12 @@ namespace ComputeSharp.Graphics.Buffers
/// <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="span">The input <see cref="Span{T}"/> with the data to copy on the allocated buffer</param>
/// <returns>A read write <see cref="Buffer{T}"/> instance with the contents of the input <see cref="Span{T}"/></returns>
/// <returns>A read write <see cref="ReadWriteBuffer{T}"/> instance with the contents of the input <see cref="Span{T}"/></returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Buffer<T> AllocateReadWriteBuffer<T>(this GraphicsDevice device, Span<T> span) where T : unmanaged
public static ReadWriteBuffer<T> AllocateReadWriteBuffer<T>(this GraphicsDevice device, Span<T> span) where T : unmanaged
{
Buffer<T> buffer = new Buffer<T>(device, span.Length, HeapType.Default);
ReadWriteBuffer<T> buffer = new ReadWriteBuffer<T>(device, span.Length);
buffer.SetData(span);
return buffer;
@@ -47,12 +47,12 @@ namespace ComputeSharp.Graphics.Buffers
/// <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="span">The input <see cref="Span{T}"/> with the data to copy on the allocated buffer</param>
/// <returns>A constant <see cref="Buffer{T}"/> instance with the contents of the input <see cref="Span{T}"/></returns>
/// <returns>A constant <see cref="ReadOnlyBuffer{T}"/> instance with the contents of the input <see cref="Span{T}"/></returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Buffer<T> AllocateConstantBuffer<T>(this GraphicsDevice device, Span<T> span) where T : unmanaged
public static ReadOnlyBuffer<T> AllocateConstantBuffer<T>(this GraphicsDevice device, Span<T> span) where T : unmanaged
{
Buffer<T> buffer = new Buffer<T>(device, span.Length, HeapType.Upload);
ReadOnlyBuffer<T> buffer = new ReadOnlyBuffer<T>(device, span.Length);
buffer.SetData(span);
return buffer;
+26
ファイルの表示
@@ -0,0 +1,26 @@
using System;
using SharpDX.Direct3D12;
namespace ComputeSharp.Graphics.Buffers
{
/// <summary>
/// A <see langword="class"/> representing a typed read write buffer stored on GPU memory
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer</typeparam>
public sealed class ReadOnlyBuffer<T> : Buffer<T> where T : unmanaged
{
/// <summary>
/// Creates a new <see cref="ReadOnlyBuffer{T}"/> instance with the specified parameters
/// </summary>
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance</param>
/// <param name="size">The number of items to store in the current buffer</param>
internal ReadOnlyBuffer(GraphicsDevice device, int size) : base(device, size, HeapType.Upload) { }
/// <summary>
/// Gets a single <typeparamref name="T"/> value from the current read write buffer
/// </summary>
/// <param name="i">The index of the value to get</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else</remarks>
public T this[uint i] => throw new InvalidOperationException("The indexer APIs can only be used from a compute shader");
}
}
+30
ファイルの表示
@@ -0,0 +1,30 @@
using System;
using SharpDX.Direct3D12;
namespace ComputeSharp.Graphics.Buffers
{
/// <summary>
/// A <see langword="class"/> representing a typed read write buffer stored on GPU memory
/// </summary>
/// <typeparam name="T">The type of items stored on the buffer</typeparam>
public sealed class ReadWriteBuffer<T> : Buffer<T> where T : unmanaged
{
/// <summary>
/// Creates a new <see cref="ReadWriteBuffer{T}"/> instance with the specified parameters
/// </summary>
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance</param>
/// <param name="size">The number of items to store in the current buffer</param>
internal ReadWriteBuffer(GraphicsDevice device, int size) : base(device, size, HeapType.Default) { }
/// <summary>
/// Gets or sets a single <typeparamref name="T"/> value from the current read write buffer
/// </summary>
/// <param name="i">The index of the value to get or set</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else</remarks>
public T this[uint i]
{
get => throw new InvalidOperationException("The indexer APIs can only be used from a compute shader");
set => throw new InvalidOperationException("The indexer APIs can only be used from a compute shader");
}
}
}