From 3a29a14df62dbca8b4c2252bd86e57e78aad8d3b Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 10 May 2021 18:18:21 +0200 Subject: [PATCH] Added sampled texture indexers to 3D texture types --- .../Mappings/HlslKnownMembers.cs | 6 +++++- .../Interfaces/IReadOnlyTexture3D{TPixel}.cs | 16 ++++++++++++++++ .../Resources/ReadOnlyTexture3D{T,TPixel}.cs | 6 ++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMembers.cs b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMembers.cs index 8c6b0ebb..75a0095c 100644 --- a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMembers.cs +++ b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMembers.cs @@ -41,7 +41,11 @@ namespace ComputeSharp.SourceGenerators.Mappings [$"ComputeSharp.ReadOnlyTexture2D`2.this[{typeof(float).FullName}, {typeof(float).FullName}]"] = "float2", [$"ComputeSharp.ReadOnlyTexture2D`2.this[{typeof(Float2).FullName}]"] = null, [$"ComputeSharp.IReadOnlyTexture2D`1.this[{typeof(float).FullName}, {typeof(float).FullName}]"] = "float2", - [$"ComputeSharp.IReadOnlyTexture2D`1.this[{typeof(Float2).FullName}]"] = null + [$"ComputeSharp.IReadOnlyTexture2D`1.this[{typeof(Float2).FullName}]"] = null, + [$"ComputeSharp.ReadOnlyTexture3D`2.this[{typeof(float).FullName}, {typeof(float).FullName}, {typeof(float).FullName}]"] = "float3", + [$"ComputeSharp.ReadOnlyTexture3D`2.this[{typeof(Float3).FullName}]"] = null, + [$"ComputeSharp.IReadOnlyTexture2D`1.this[{typeof(float).FullName}, {typeof(float).FullName}, {typeof(float).FullName}]"] = "float3", + [$"ComputeSharp.IReadOnlyTexture2D`1.this[{typeof(Float3).FullName}]"] = null }; /// diff --git a/src/ComputeSharp/Graphics/Resources/Interfaces/IReadOnlyTexture3D{TPixel}.cs b/src/ComputeSharp/Graphics/Resources/Interfaces/IReadOnlyTexture3D{TPixel}.cs index 30f1db44..79536de0 100644 --- a/src/ComputeSharp/Graphics/Resources/Interfaces/IReadOnlyTexture3D{TPixel}.cs +++ b/src/ComputeSharp/Graphics/Resources/Interfaces/IReadOnlyTexture3D{TPixel}.cs @@ -38,5 +38,21 @@ /// 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. TPixel this[Int3 xyz] { get; } + + /// + /// Gets a single value from the current readonly texture with linear sampling. + /// + /// The horizontal normalized offset of the value to get. + /// The vertical normalized offset of the value to get. + /// The depthwise 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. + TPixel this[float u, float v, float w] { get; } + + /// + /// Gets a single value from the current readonly texture with linear sampling. + /// + /// The normalized coordinates of the value to get. + /// This API can only be used from a compute shader, and will always throw if used anywhere else. + TPixel this[Float3 uvw] { get; } } } diff --git a/src/ComputeSharp/Graphics/Resources/ReadOnlyTexture3D{T,TPixel}.cs b/src/ComputeSharp/Graphics/Resources/ReadOnlyTexture3D{T,TPixel}.cs index 29ea0ff1..2871cfd0 100644 --- a/src/ComputeSharp/Graphics/Resources/ReadOnlyTexture3D{T,TPixel}.cs +++ b/src/ComputeSharp/Graphics/Resources/ReadOnlyTexture3D{T,TPixel}.cs @@ -40,6 +40,12 @@ namespace ComputeSharp /// public TPixel this[Int3 xyz] => throw new InvalidExecutionContextException($"{typeof(ReadOnlyTexture3D)}[{typeof(Int3)}]"); + /// + public TPixel this[float u, float v, float w] => throw new InvalidExecutionContextException($"{typeof(ReadOnlyTexture3D)}[{typeof(float)}, {typeof(float)}, {typeof(float)}]"); + + /// + public TPixel this[Float3 uvw] => throw new InvalidExecutionContextException($"{typeof(ReadOnlyTexture3D)}[{typeof(Float3)}]"); + /// public override string ToString() {