From 0d924830d9ef5c4027b52340a1e9c2a9eaacfa4f Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 29 Aug 2022 01:16:28 +0200 Subject: [PATCH] Add interfaces for 1D texture types --- .../IReadOnlyNormalizedTexture1D{TPixel}.cs | 29 +++++++++++++++++++ .../Interfaces/IReadOnlyTexture1D{T}.cs | 29 +++++++++++++++++++ .../IReadWriteNormalizedTexture1D{TPixel}.cs | 22 ++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 src/ComputeSharp/Graphics/Resources/Interfaces/IReadOnlyNormalizedTexture1D{TPixel}.cs create mode 100644 src/ComputeSharp/Graphics/Resources/Interfaces/IReadOnlyTexture1D{T}.cs create mode 100644 src/ComputeSharp/Graphics/Resources/Interfaces/IReadWriteNormalizedTexture1D{TPixel}.cs diff --git a/src/ComputeSharp/Graphics/Resources/Interfaces/IReadOnlyNormalizedTexture1D{TPixel}.cs b/src/ComputeSharp/Graphics/Resources/Interfaces/IReadOnlyNormalizedTexture1D{TPixel}.cs new file mode 100644 index 00000000..eda6c900 --- /dev/null +++ b/src/ComputeSharp/Graphics/Resources/Interfaces/IReadOnlyNormalizedTexture1D{TPixel}.cs @@ -0,0 +1,29 @@ +namespace ComputeSharp; + +/// +/// An interface representing a typed readonly 1D 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 IReadOnlyNormalizedTexture1D : IGraphicsResource + where TPixel : unmanaged +{ + /// + /// Gets the width of the current texture. + /// + int Width { get; } + + /// + /// Gets a single value from the current readonly texture. + /// + /// The horizontal offset of the value to get. + /// This API can only be used from a compute shader, and will always throw if used anywhere else. + ref readonly TPixel this[int x] { get; } + + /// + /// Retrieves a single value from the current readonly texture with linear sampling. + /// + /// The horizontal normalized offset of the value to get. + /// This API can only be used from a compute shader, and will always throw if used anywhere else. + ref readonly TPixel Sample(float u); +} diff --git a/src/ComputeSharp/Graphics/Resources/Interfaces/IReadOnlyTexture1D{T}.cs b/src/ComputeSharp/Graphics/Resources/Interfaces/IReadOnlyTexture1D{T}.cs new file mode 100644 index 00000000..14ae0c64 --- /dev/null +++ b/src/ComputeSharp/Graphics/Resources/Interfaces/IReadOnlyTexture1D{T}.cs @@ -0,0 +1,29 @@ +namespace ComputeSharp; + +/// +/// An interface representing a typed readonly 1D texture containing raw data stored on GPU memory. +/// This interface can only be used to wrap instances. +/// +/// The type of raw data used on the GPU side. +public interface IReadOnlyTexture1D : IGraphicsResource + where T : unmanaged +{ + /// + /// Gets the width of the current texture. + /// + int Width { get; } + + /// + /// Gets a single value from the current readonly texture. + /// + /// The horizontal offset of the value to get. + /// This API can only be used from a compute shader, and will always throw if used anywhere else. + ref readonly T this[int x] { get; } + + /// + /// Retrieves a single value from the current readonly texture with linear sampling. + /// + /// The horizontal normalized offset of the value to get. + /// This API can only be used from a compute shader, and will always throw if used anywhere else. + ref readonly T Sample(float u); +} diff --git a/src/ComputeSharp/Graphics/Resources/Interfaces/IReadWriteNormalizedTexture1D{TPixel}.cs b/src/ComputeSharp/Graphics/Resources/Interfaces/IReadWriteNormalizedTexture1D{TPixel}.cs new file mode 100644 index 00000000..0d65f74d --- /dev/null +++ b/src/ComputeSharp/Graphics/Resources/Interfaces/IReadWriteNormalizedTexture1D{TPixel}.cs @@ -0,0 +1,22 @@ +namespace ComputeSharp; + +/// +/// An interface representing a typed writeable 1D 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 IReadWriteNormalizedTexture1D : IGraphicsResource + where TPixel : unmanaged +{ + /// + /// Gets the width of the current texture. + /// + int Width { get; } + + /// + /// Gets a single value from the current writeable texture. + /// + /// The horizontal offset of the value to get. + /// This API can only be used from a compute shader, and will always throw if used anywhere else. + ref TPixel this[int x] { get; } +}