From 6904416d0bfae2a311296506b404bc378a1aecc3 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 4 Dec 2020 19:07:19 +0100 Subject: [PATCH] Added public texture 3D types --- .../Buffers/ReadOnlyTexture3D{T}.cs | 42 +++++++++++++++++++ .../Buffers/ReadWriteTexture3D{T}.cs | 42 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 src/ComputeSharp.Graphics/Buffers/ReadOnlyTexture3D{T}.cs create mode 100644 src/ComputeSharp.Graphics/Buffers/ReadWriteTexture3D{T}.cs diff --git a/src/ComputeSharp.Graphics/Buffers/ReadOnlyTexture3D{T}.cs b/src/ComputeSharp.Graphics/Buffers/ReadOnlyTexture3D{T}.cs new file mode 100644 index 00000000..560ad224 --- /dev/null +++ b/src/ComputeSharp.Graphics/Buffers/ReadOnlyTexture3D{T}.cs @@ -0,0 +1,42 @@ +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 3D texture stored on GPU memory. + /// + /// The type of items stored on the texture. + [DebuggerDisplay("{ToString(),raw}")] + public sealed class ReadOnlyTexture3D : Texture3D + 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. + /// The depth of the texture. + internal ReadOnlyTexture3D(GraphicsDevice device, int width, int height, int depth) + : base(device, width, height, depth, ResourceType.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[UInt3 xyz] => throw new InvalidExecutionContextException($"{nameof(ReadOnlyTexture3D)}[UInt3]"); + + /// + public override string ToString() + { + return $"ComputeSharp.ReadOnlyTexture3D<{typeof(T)}>[{Width}, {Height}, {Depth}]"; + } + } +} diff --git a/src/ComputeSharp.Graphics/Buffers/ReadWriteTexture3D{T}.cs b/src/ComputeSharp.Graphics/Buffers/ReadWriteTexture3D{T}.cs new file mode 100644 index 00000000..9e5e950d --- /dev/null +++ b/src/ComputeSharp.Graphics/Buffers/ReadWriteTexture3D{T}.cs @@ -0,0 +1,42 @@ +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 3D texture stored on GPU memory. + /// + /// The type of items stored on the texture. + [DebuggerDisplay("{ToString(),raw}")] + public sealed class ReadWriteTexture3D : Texture3D + 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. + /// The depth of the texture. + internal ReadWriteTexture3D(GraphicsDevice device, int width, int height, int depth) + : base(device, width, height, depth, ResourceType.ReadWrite) + { + } + + /// + /// 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[UInt3 xyz] => throw new InvalidExecutionContextException($"{nameof(ReadWriteTexture3D)}[UInt3]"); + + /// + public override string ToString() + { + return $"ComputeSharp.ReadOnlyTexture3D<{typeof(T)}>[{Width}, {Height}, {Depth}]"; + } + } +}