From c262cd5519375e5b980b18c8c92dab24ae96555d Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 7 Dec 2020 17:08:14 +0100 Subject: [PATCH] Added single-element indexers for texture types --- .../Buffers/ReadOnlyTexture2D{T}.cs | 8 ++++++++ .../Buffers/ReadOnlyTexture3D{T}.cs | 9 +++++++++ .../Buffers/ReadWriteBuffer{T}.cs | 2 +- .../Buffers/ReadWriteTexture2D{T}.cs | 12 ++++++++++-- .../Buffers/ReadWriteTexture3D{T}.cs | 11 ++++++++++- 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/ComputeSharp.Graphics/Buffers/ReadOnlyTexture2D{T}.cs b/src/ComputeSharp.Graphics/Buffers/ReadOnlyTexture2D{T}.cs index c2d93771..36b930ef 100644 --- a/src/ComputeSharp.Graphics/Buffers/ReadOnlyTexture2D{T}.cs +++ b/src/ComputeSharp.Graphics/Buffers/ReadOnlyTexture2D{T}.cs @@ -27,6 +27,14 @@ 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 T this[int x, int y] => throw new InvalidExecutionContextException($"{nameof(ReadOnlyTexture2D)}[int,int]"); + /// /// Gets a single value from the current readonly texture. /// diff --git a/src/ComputeSharp.Graphics/Buffers/ReadOnlyTexture3D{T}.cs b/src/ComputeSharp.Graphics/Buffers/ReadOnlyTexture3D{T}.cs index 26bf0c7d..306b0d19 100644 --- a/src/ComputeSharp.Graphics/Buffers/ReadOnlyTexture3D{T}.cs +++ b/src/ComputeSharp.Graphics/Buffers/ReadOnlyTexture3D{T}.cs @@ -28,6 +28,15 @@ 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 T this[int x, int y, int z] => throw new InvalidExecutionContextException($"{nameof(ReadOnlyTexture3D)}[int,int,int]"); + /// /// Gets a single value from the current readonly texture. /// diff --git a/src/ComputeSharp.Graphics/Buffers/ReadWriteBuffer{T}.cs b/src/ComputeSharp.Graphics/Buffers/ReadWriteBuffer{T}.cs index a2f2c0c2..28c65443 100644 --- a/src/ComputeSharp.Graphics/Buffers/ReadWriteBuffer{T}.cs +++ b/src/ComputeSharp.Graphics/Buffers/ReadWriteBuffer{T}.cs @@ -27,7 +27,7 @@ namespace ComputeSharp } /// - /// Gets or sets a single value from the current read write buffer. + /// 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. diff --git a/src/ComputeSharp.Graphics/Buffers/ReadWriteTexture2D{T}.cs b/src/ComputeSharp.Graphics/Buffers/ReadWriteTexture2D{T}.cs index 925be95d..1b75ce5b 100644 --- a/src/ComputeSharp.Graphics/Buffers/ReadWriteTexture2D{T}.cs +++ b/src/ComputeSharp.Graphics/Buffers/ReadWriteTexture2D{T}.cs @@ -28,11 +28,19 @@ namespace ComputeSharp } /// - /// Gets or sets a single value from the current readonly texture. + /// 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 T 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 T this[Int2 xy] => throw new InvalidExecutionContextException($"{nameof(ReadOnlyTexture2D)}[Int2]"); + public ref T this[Int2 xy] => throw new InvalidExecutionContextException($"{nameof(ReadWriteTexture2D)}[Int2]"); /// public override string ToString() diff --git a/src/ComputeSharp.Graphics/Buffers/ReadWriteTexture3D{T}.cs b/src/ComputeSharp.Graphics/Buffers/ReadWriteTexture3D{T}.cs index ee042fa4..8ee45602 100644 --- a/src/ComputeSharp.Graphics/Buffers/ReadWriteTexture3D{T}.cs +++ b/src/ComputeSharp.Graphics/Buffers/ReadWriteTexture3D{T}.cs @@ -29,7 +29,16 @@ namespace ComputeSharp } /// - /// Gets a single value from the current readonly texture. + /// 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 T 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.