From 673633a48d88d6822615bc43aaffe754d2839439 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 15 Aug 2019 15:55:58 +0200 Subject: [PATCH] Added ReadOnlyBuffer type --- .../Buffers/ReadOnlyBuffer{T}.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/ComputeSharp.Graphics/Buffers/ReadOnlyBuffer{T}.cs diff --git a/src/ComputeSharp.Graphics/Buffers/ReadOnlyBuffer{T}.cs b/src/ComputeSharp.Graphics/Buffers/ReadOnlyBuffer{T}.cs new file mode 100644 index 00000000..f6aee2ec --- /dev/null +++ b/src/ComputeSharp.Graphics/Buffers/ReadOnlyBuffer{T}.cs @@ -0,0 +1,27 @@ +using System; +using ComputeSharp.Graphics.Buffers.Abstract; +using ComputeSharp.Graphics.Buffers.Enums; + +namespace ComputeSharp.Graphics.Buffers +{ + /// + /// A representing a typed readonly buffer stored on GPU memory + /// + /// The type of items stored on the buffer + public sealed class ReadOnlyBuffer : HlslStructuredBuffer where T : unmanaged + { + /// + /// Creates a new instance with the specified parameters + /// + /// The associated with the current instance + /// The number of items to store in the current buffer + internal ReadOnlyBuffer(GraphicsDevice device, int size) : base(device, size, BufferType.ReadOnly) { } + + /// + /// Gets or sets a single value from the current read write buffer + /// + /// The index of the value to get or set + /// This API can only be used from a compute shader, and will always throw if used anywhere else + public T this[uint i] => throw new InvalidOperationException("The indexer APIs can only be used from a compute shader"); + } +}