diff --git a/src/ComputeSharp.Graphics/Buffers/ReadOnlyBuffer{T}.cs b/src/ComputeSharp.Graphics/Buffers/ReadOnlyBuffer{T}.cs index 92789c87..6488154a 100644 --- a/src/ComputeSharp.Graphics/Buffers/ReadOnlyBuffer{T}.cs +++ b/src/ComputeSharp.Graphics/Buffers/ReadOnlyBuffer{T}.cs @@ -27,7 +27,7 @@ namespace ComputeSharp } /// - /// Gets a single value from the current read write buffer. + /// Gets a single value from the current readonly buffer. /// /// The index of the value to get. /// This API can only be used from a compute shader, and will always throw if used anywhere else. diff --git a/src/ComputeSharp.Graphics/Buffers/ReadOnlyTexture2D{T}.cs b/src/ComputeSharp.Graphics/Buffers/ReadOnlyTexture2D{T}.cs new file mode 100644 index 00000000..9b78dac7 --- /dev/null +++ b/src/ComputeSharp.Graphics/Buffers/ReadOnlyTexture2D{T}.cs @@ -0,0 +1,41 @@ +using System.Diagnostics; +using ComputeSharp.Exceptions; +using ComputeSharp.Graphics; +using ComputeSharp.Graphics.Buffers.Abstract; +using ComputeSharp.Graphics.Buffers.Enums; + +namespace ComputeSharp +{ + /// + /// A representing a typed readonly 2D texture stored on GPU memory. + /// + /// The type of items stored on the texture. + [DebuggerDisplay("{ToString(),raw}")] + public sealed class ReadOnlyTexture2D : Texture2D + where T : unmanaged + { + /// + /// Creates a new instance with the specified parameters. + /// + /// The associated with the current instance. + /// The width of the texture. + /// The height of the texture. + internal ReadOnlyTexture2D(GraphicsDevice device, int width, int height) + : base(device, width, height, TextureType.ReadOnly) + { + } + + /// + /// Gets a single value from the current readonly texture. + /// + /// The coordinates of the value to get. + /// This API can only be used from a compute shader, and will always throw if used anywhere else. + public T this[UInt2 xy] => throw new InvalidExecutionContextException($"{nameof(ReadOnlyTexture2D)}[UInt2]"); + + /// + public override string ToString() + { + return $"ComputeSharp.ReadOnlyTexture2D<{typeof(T)}>[{Width}, {Height}]"; + } + } +} diff --git a/src/ComputeSharp.Graphics/Buffers/ReadWriteTexture2D{T}.cs b/src/ComputeSharp.Graphics/Buffers/ReadWriteTexture2D{T}.cs new file mode 100644 index 00000000..0557fdba --- /dev/null +++ b/src/ComputeSharp.Graphics/Buffers/ReadWriteTexture2D{T}.cs @@ -0,0 +1,41 @@ +using System.Diagnostics; +using ComputeSharp.Exceptions; +using ComputeSharp.Graphics; +using ComputeSharp.Graphics.Buffers.Abstract; +using ComputeSharp.Graphics.Buffers.Enums; + +namespace ComputeSharp +{ + /// + /// A representing a typed read write 2D texture stored on GPU memory. + /// + /// The type of items stored on the texture. + [DebuggerDisplay("{ToString(),raw}")] + public sealed class ReadWriteTexture2D : Texture2D + where T : unmanaged + { + /// + /// Creates a new instance with the specified parameters. + /// + /// The associated with the current instance. + /// The width of the texture. + /// The height of the texture. + internal ReadWriteTexture2D(GraphicsDevice device, int width, int height) + : base(device, width, height, TextureType.ReadWrite) + { + } + + /// + /// Gets or sets a single value from the current readonly texture. + /// + /// The coordinates of the value to get. + /// This API can only be used from a compute shader, and will always throw if used anywhere else. + public ref T this[UInt2 xy] => throw new InvalidExecutionContextException($"{nameof(ReadOnlyTexture2D)}[UInt2]"); + + /// + public override string ToString() + { + return $"ComputeSharp.ReadWriteTexture2D<{typeof(T)}>[{Width}, {Height}]"; + } + } +}