From c2f6e81e76d8dce07260caf3633a0c747fb24168 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 6 Jan 2021 16:09:36 +0100 Subject: [PATCH] Added unorm texture interface types --- .../Interfaces/IReadOnlyTexture2D{TPixel}.cs | 26 ++++++++++++++++++ .../Interfaces/IReadOnlyTexture3D{TPixel}.cs | 27 +++++++++++++++++++ .../Interfaces/IReadWriteTexture2D{TPixel}.cs | 26 ++++++++++++++++++ .../Interfaces/IReadWriteTexture3D{TPixel}.cs | 27 +++++++++++++++++++ .../Resources/ReadOnlyTexture2D{T,TPixel}.cs | 15 +++-------- .../Resources/ReadOnlyTexture3D{T,TPixel}.cs | 16 +++-------- .../Resources/ReadWriteTexture2D{T,TPixel}.cs | 15 +++-------- .../Resources/ReadWriteTexture3D{T,TPixel}.cs | 16 +++-------- 8 files changed, 118 insertions(+), 50 deletions(-) create mode 100644 src/ComputeSharp.Graphics/Resources/Interfaces/IReadOnlyTexture2D{TPixel}.cs create mode 100644 src/ComputeSharp.Graphics/Resources/Interfaces/IReadOnlyTexture3D{TPixel}.cs create mode 100644 src/ComputeSharp.Graphics/Resources/Interfaces/IReadWriteTexture2D{TPixel}.cs create mode 100644 src/ComputeSharp.Graphics/Resources/Interfaces/IReadWriteTexture3D{TPixel}.cs diff --git a/src/ComputeSharp.Graphics/Resources/Interfaces/IReadOnlyTexture2D{TPixel}.cs b/src/ComputeSharp.Graphics/Resources/Interfaces/IReadOnlyTexture2D{TPixel}.cs new file mode 100644 index 00000000..b03ba5c9 --- /dev/null +++ b/src/ComputeSharp.Graphics/Resources/Interfaces/IReadOnlyTexture2D{TPixel}.cs @@ -0,0 +1,26 @@ +namespace ComputeSharp +{ + /// + /// An interface representing a typed readonly 2D texture containing normalized pixel data stored on GPU memory. + /// This interface can only be used to wrap instances. + /// + /// The type of normalized pixels used on the GPU side. + public interface IReadOnlyTexture2D + where TPixel : unmanaged + { + /// + /// Gets a single value from the current readonly texture. + /// + /// The horizontal offset of the value to get. + /// The vertical offset of the value to get. + /// This API can only be used from a compute shader, and will always throw if used anywhere else. + public TPixel this[int x, int y] { get; } + + /// + /// 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 TPixel this[Int2 xy] { get; } + } +} diff --git a/src/ComputeSharp.Graphics/Resources/Interfaces/IReadOnlyTexture3D{TPixel}.cs b/src/ComputeSharp.Graphics/Resources/Interfaces/IReadOnlyTexture3D{TPixel}.cs new file mode 100644 index 00000000..a718f10f --- /dev/null +++ b/src/ComputeSharp.Graphics/Resources/Interfaces/IReadOnlyTexture3D{TPixel}.cs @@ -0,0 +1,27 @@ +namespace ComputeSharp +{ + /// + /// An interface representing a typed readonly 3D texture containing normalized pixel data stored on GPU memory. + /// This interface can only be used to wrap instances. + /// + /// The type of normalized pixels used on the GPU side. + public interface IReadOnlyTexture3D + where TPixel : unmanaged + { + /// + /// Gets a single value from the current readonly texture. + /// + /// The horizontal offset of the value to get. + /// The vertical offset of the value to get. + /// The depthwise offset of the value to get. + /// This API can only be used from a compute shader, and will always throw if used anywhere else. + public TPixel this[int x, int y, int z] { get; } + + /// + /// 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 TPixel this[Int3 xyz] { get; } + } +} diff --git a/src/ComputeSharp.Graphics/Resources/Interfaces/IReadWriteTexture2D{TPixel}.cs b/src/ComputeSharp.Graphics/Resources/Interfaces/IReadWriteTexture2D{TPixel}.cs new file mode 100644 index 00000000..62cd23f9 --- /dev/null +++ b/src/ComputeSharp.Graphics/Resources/Interfaces/IReadWriteTexture2D{TPixel}.cs @@ -0,0 +1,26 @@ +namespace ComputeSharp +{ + /// + /// An interface representing a typed writeable 2D texture containing normalized pixel data stored on GPU memory. + /// This interface can only be used to wrap instances. + /// + /// The type of normalized pixels used on the GPU side. + public interface IReadWriteTexture2D + where TPixel : unmanaged + { + /// + /// Gets a single value from the current writeable texture. + /// + /// The horizontal offset of the value to get. + /// The vertical offset 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 TPixel this[int x, int y] { get; } + + /// + /// Gets or sets a single value from the current writeable 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 TPixel this[Int2 xy] { get; } + } +} diff --git a/src/ComputeSharp.Graphics/Resources/Interfaces/IReadWriteTexture3D{TPixel}.cs b/src/ComputeSharp.Graphics/Resources/Interfaces/IReadWriteTexture3D{TPixel}.cs new file mode 100644 index 00000000..7e04187e --- /dev/null +++ b/src/ComputeSharp.Graphics/Resources/Interfaces/IReadWriteTexture3D{TPixel}.cs @@ -0,0 +1,27 @@ +namespace ComputeSharp +{ + /// + /// An interface representing a typed writeable 2D texture containing normalized pixel data stored on GPU memory. + /// This interface can only be used to wrap instances. + /// + /// The type of normalized pixels used on the GPU side. + public interface IReadWriteTexture3D + where TPixel : unmanaged + { + /// + /// Gets a single value from the current writeable texture. + /// + /// The horizontal offset of the value to get. + /// The vertical offset of the value to get. + /// The depthwise offset 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 TPixel this[int x, int y, int z] { get; } + + /// + /// Gets a single value from the current writeable 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 TPixel this[Int3 xyz] { get; } + } +} diff --git a/src/ComputeSharp.Graphics/Resources/ReadOnlyTexture2D{T,TPixel}.cs b/src/ComputeSharp.Graphics/Resources/ReadOnlyTexture2D{T,TPixel}.cs index b6a6f190..e2a1ab08 100644 --- a/src/ComputeSharp.Graphics/Resources/ReadOnlyTexture2D{T,TPixel}.cs +++ b/src/ComputeSharp.Graphics/Resources/ReadOnlyTexture2D{T,TPixel}.cs @@ -16,7 +16,7 @@ namespace ComputeSharp /// The type of pixels used on the GPU side. [DebuggerTypeProxy(typeof(Texture2DDebugView<>))] [DebuggerDisplay("{ToString(),raw}")] - public sealed class ReadOnlyTexture2D : Texture2D + public sealed class ReadOnlyTexture2D : Texture2D, IReadOnlyTexture2D where T : unmanaged, IUnorm where TPixel : unmanaged { @@ -31,19 +31,10 @@ namespace ComputeSharp { } - /// - /// Gets a single value from the current readonly texture. - /// - /// The horizontal offset of the value to get. - /// The vertical offset of the value to get. - /// This API can only be used from a compute shader, and will always throw if used anywhere else. + /// public TPixel this[int x, int y] => throw new InvalidExecutionContextException($"{nameof(ReadOnlyTexture2D)}[int,int]"); - /// - /// 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 TPixel this[Int2 xy] => throw new InvalidExecutionContextException($"{nameof(ReadOnlyTexture2D)}[Int2]"); /// diff --git a/src/ComputeSharp.Graphics/Resources/ReadOnlyTexture3D{T,TPixel}.cs b/src/ComputeSharp.Graphics/Resources/ReadOnlyTexture3D{T,TPixel}.cs index 2580c375..07d4d98a 100644 --- a/src/ComputeSharp.Graphics/Resources/ReadOnlyTexture3D{T,TPixel}.cs +++ b/src/ComputeSharp.Graphics/Resources/ReadOnlyTexture3D{T,TPixel}.cs @@ -16,7 +16,7 @@ namespace ComputeSharp /// The type of pixels used on the GPU side. [DebuggerTypeProxy(typeof(Texture3DDebugView<>))] [DebuggerDisplay("{ToString(),raw}")] - public sealed class ReadOnlyTexture3D : Texture3D + public sealed class ReadOnlyTexture3D : Texture3D, IReadOnlyTexture3D where T : unmanaged, IUnorm where TPixel : unmanaged { @@ -32,20 +32,10 @@ namespace ComputeSharp { } - /// - /// Gets a single value from the current readonly texture. - /// - /// The horizontal offset of the value to get. - /// The vertical offset of the value to get. - /// The depthwise offset of the value to get. - /// This API can only be used from a compute shader, and will always throw if used anywhere else. + /// public TPixel this[int x, int y, int z] => throw new InvalidExecutionContextException($"{nameof(ReadOnlyTexture3D)}[int,int,int]"); - /// - /// 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 TPixel this[Int3 xyz] => throw new InvalidExecutionContextException($"{nameof(ReadOnlyTexture3D)}[Int3]"); /// diff --git a/src/ComputeSharp.Graphics/Resources/ReadWriteTexture2D{T,TPixel}.cs b/src/ComputeSharp.Graphics/Resources/ReadWriteTexture2D{T,TPixel}.cs index c1e586d0..28366eb3 100644 --- a/src/ComputeSharp.Graphics/Resources/ReadWriteTexture2D{T,TPixel}.cs +++ b/src/ComputeSharp.Graphics/Resources/ReadWriteTexture2D{T,TPixel}.cs @@ -16,7 +16,7 @@ namespace ComputeSharp /// The type of pixels used on the GPU side. [DebuggerTypeProxy(typeof(Texture2DDebugView<>))] [DebuggerDisplay("{ToString(),raw}")] - public sealed class ReadWriteTexture2D : Texture2D + public sealed class ReadWriteTexture2D : Texture2D, IReadWriteTexture2D where T : unmanaged, IUnorm where TPixel : unmanaged { @@ -31,19 +31,10 @@ namespace ComputeSharp { } - /// - /// Gets a single value from the current writeable texture. - /// - /// The horizontal offset of the value to get. - /// The vertical offset 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 TPixel this[int x, int y] => throw new InvalidExecutionContextException($"{nameof(ReadWriteTexture2D)}[int,int]"); - /// - /// Gets or sets a single value from the current writeable 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 TPixel this[Int2 xy] => throw new InvalidExecutionContextException($"{nameof(ReadWriteTexture2D)}[Int2]"); /// diff --git a/src/ComputeSharp.Graphics/Resources/ReadWriteTexture3D{T,TPixel}.cs b/src/ComputeSharp.Graphics/Resources/ReadWriteTexture3D{T,TPixel}.cs index 03dc47c5..7a0caaa2 100644 --- a/src/ComputeSharp.Graphics/Resources/ReadWriteTexture3D{T,TPixel}.cs +++ b/src/ComputeSharp.Graphics/Resources/ReadWriteTexture3D{T,TPixel}.cs @@ -16,7 +16,7 @@ namespace ComputeSharp /// The type of pixels used on the GPU side. [DebuggerTypeProxy(typeof(Texture3DDebugView<>))] [DebuggerDisplay("{ToString(),raw}")] - public sealed class ReadWriteTexture3D : Texture3D + public sealed class ReadWriteTexture3D : Texture3D, IReadWriteTexture3D where T : unmanaged, IUnorm where TPixel : unmanaged { @@ -32,20 +32,10 @@ namespace ComputeSharp { } - /// - /// Gets a single value from the current writeable texture. - /// - /// The horizontal offset of the value to get. - /// The vertical offset of the value to get. - /// The depthwise offset 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 TPixel this[int x, int y, int z] => throw new InvalidExecutionContextException($"{nameof(ReadWriteTexture3D)}[int,int,int]"); - /// - /// Gets a single value from the current writeable 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 TPixel this[Int3 xyz] => throw new InvalidExecutionContextException($"{nameof(ReadWriteTexture3D)}[Int3]"); ///