Added specific writeable and readonly buffer types
このコミットが含まれているのは:
1 親
acf2aa9fce
コミット
13ee3e9422
7ファイル変更
+74
-31
検索条件に一致するファイルはありません
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ namespace ComputeSharp.Shaders.Mappings
|
||||
[typeof(Vector4).FullName] = "float4",
|
||||
[typeof(Matrix4x4).FullName] = "float4x4",
|
||||
[typeof(ThreadIds).FullName] = "uint3",
|
||||
[typeof(Buffer<>).FullName] = "RWBuffer"
|
||||
[typeof(ReadWriteBuffer<>).FullName] = "RWBuffer"
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -54,13 +54,13 @@ namespace ComputeSharp.Shaders.Mappings
|
||||
type == typeof(Matrix4x4);
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not the input type is a <see cref="Buffer{T}"/> value
|
||||
/// Checks whether or not the input type is a <see cref="ReadWriteBuffer{T}"/> value
|
||||
/// </summary>
|
||||
/// <param name="type">The input <see cref="Type"/> instance to check</param>
|
||||
/// <returns>A <see langword="bool"/> indicating whether the input <see cref="Type"/> is in fact a <see cref="Buffer{T}"/> instance</returns>
|
||||
/// <returns>A <see langword="bool"/> indicating whether the input <see cref="Type"/> is in fact a <see cref="ReadWriteBuffer{T}"/> instance</returns>
|
||||
[Pure]
|
||||
public static bool IsBufferType(Type type) => type.IsGenericType &&
|
||||
type.GetGenericTypeDefinition() == typeof(Buffer<>);
|
||||
public static bool IsReadWriteBufferType(Type type) => type.IsGenericType &&
|
||||
type.GetGenericTypeDefinition() == typeof(ReadWriteBuffer<>);
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not a given <see cref="Type"/> is an HLSL known type
|
||||
|
||||
@@ -4,7 +4,6 @@ using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using ComputeSharp.Graphics.Buffers;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
using ComputeSharp.Shaders.Mappings;
|
||||
using ComputeSharp.Shaders.Renderer.Models.Fields;
|
||||
@@ -116,8 +115,7 @@ namespace ComputeSharp.Shaders
|
||||
FieldInfoBase processedFieldInfo;
|
||||
|
||||
// Read write buffer
|
||||
if (HlslKnownTypes.IsBufferType(fieldType) &&
|
||||
(HeapType)fieldType.GetProperty(nameof(Buffer<byte>.HeapType)).GetValue(fieldValue) == HeapType.Default)
|
||||
if (HlslKnownTypes.IsReadWriteBufferType(fieldType))
|
||||
{
|
||||
// Root parameter for a read write buffer
|
||||
DescriptorRange range = new DescriptorRange(DescriptorRangeType.UnorderedAccessView, 1, readWriteBuffersCount);
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace DirectX12ComputeShaderSample
|
||||
array[i] = i + 1;
|
||||
}
|
||||
|
||||
using Buffer<float> gpuBuffer = Gpu.Default.AllocateReadWriteBuffer(array.AsSpan());
|
||||
using ReadWriteBuffer<float> gpuBuffer = Gpu.Default.AllocateReadWriteBuffer(array.AsSpan());
|
||||
|
||||
// Shader body
|
||||
Action<ThreadIds> action = id =>
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする