using System.Diagnostics;
using ComputeSharp.Exceptions;
using ComputeSharp.Graphics;
using ComputeSharp.Graphics.Buffers.Abstract;
using ComputeSharp.Graphics.Buffers.Enums;
using ComputeSharp.Graphics.Buffers.Views;
namespace ComputeSharp
{
///
/// A representing a typed read write buffer stored on GPU memory.
///
/// The type of items stored on the buffer.
[DebuggerTypeProxy(typeof(BufferDebugView<>))]
[DebuggerDisplay("{ToString(),raw}")]
public sealed class ReadWriteBuffer : StructuredBuffer
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 ReadWriteBuffer(GraphicsDevice device, int length)
: base(device, length, ResourceType.ReadWrite)
{
}
///
/// Gets or sets a single value from the current writeable 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 ref T this[int i] => throw new InvalidExecutionContextException($"{nameof(ReadWriteBuffer)}[int]");
///
public override string ToString()
{
return $"ComputeSharp.ReadWriteBuffer<{typeof(T)}>[{Length}]";
}
}
}