From a68ad249292acd24b268147e6061a39e3f2ea767 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 13 Aug 2019 16:16:51 +0200 Subject: [PATCH] Added HlslBuffer class --- .../Buffers/Abstract/HlslBuffer{T}.cs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/ComputeSharp.Graphics/Buffers/Abstract/HlslBuffer{T}.cs diff --git a/src/ComputeSharp.Graphics/Buffers/Abstract/HlslBuffer{T}.cs b/src/ComputeSharp.Graphics/Buffers/Abstract/HlslBuffer{T}.cs new file mode 100644 index 00000000..1d8fa479 --- /dev/null +++ b/src/ComputeSharp.Graphics/Buffers/Abstract/HlslBuffer{T}.cs @@ -0,0 +1,47 @@ +using System; +using System.Diagnostics.Contracts; +using SharpDX.Direct3D12; + +namespace ComputeSharp.Graphics.Buffers.Abstract +{ + /// + /// A representing a typed buffer stored on GPU memory, that can be used from an HLSL shader + /// + /// The type of items stored on the buffer + public abstract class HlslBuffer : Buffer 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 + /// The size in bytes for the current buffer + /// The heap type for the current buffer + protected internal HlslBuffer(GraphicsDevice device, int size, int sizeInBytes, HeapType heapType) : base(device, size, sizeInBytes, heapType) { } + + /// + /// Reads the contents of the current instance and returns an array + /// + /// A array with the contents of the current buffer + [Pure] + public T[] GetData() + { + T[] data = new T[Size]; + GetData(data); + + return data; + } + + /// + /// Reads the contents of the current instance and writes them into a target + /// + /// The input to write data to + public abstract void GetData(Span span); + + /// + /// Writes the contents of a given to the current instance + /// + /// The input to read data from + public abstract void SetData(Span span); + } +}