Merge pull request #86 from Sergio0694/feature/unorm-texture-interfaces

Unorm texture interfaces
このコミットが含まれているのは:
Sergio Pedri authored and GitHub committed 2021-01-06 20:09:38 +01:00
コミット 741a9002ee
19ファイル変更
+395 -87

検索条件に一致するファイルはありません

+9 -9
ファイルの表示
@@ -288,13 +288,13 @@ namespace ComputeSharp.BokehBlur.Processors
/// <summary>
/// Performs a vertical 1D complex convolution with the specified parameters.
/// </summary>
/// <param name="source">The source <see cref="ReadOnlyTexture2D{T}"/> to read data from.</param>
/// <param name="source">The source <see cref="IReadOnlyTexture2D{TPixel}"/> to read data from.</param>
/// <param name="reals">The target <see cref="ReadWriteTexture2D{T}"/> to write the real results to.</param>
/// <param name="imaginaries">The target <see cref="ReadWriteTexture2D{T}"/> to write the imaginary results to.</param>
/// <param name="kernel">The <see cref="ReadOnlyBuffer{T}"/> with the values for the current complex kernel.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void ApplyVerticalConvolution(
ReadWriteTexture2D<Rgba32, Vector4> source,
IReadWriteTexture2D<Vector4> source,
ReadWriteTexture2D<Vector4> reals,
ReadWriteTexture2D<Vector4> imaginaries,
ReadOnlyBuffer<Complex64> kernel)
@@ -324,7 +324,7 @@ namespace ComputeSharp.BokehBlur.Processors
public int maxX;
public int kernelLength;
public ReadWriteTexture2D<Rgba32, Vector4> source;
public IReadWriteTexture2D<Vector4> source;
public ReadWriteTexture2D<Vector4> reals;
public ReadWriteTexture2D<Vector4> imaginaries;
public ReadOnlyBuffer<Complex64> kernel;
@@ -431,9 +431,9 @@ namespace ComputeSharp.BokehBlur.Processors
/// <summary>
/// Applies the gamma highlight pass to compute the final pixel values for a target image.
/// </summary>
/// <param name="source">The source <see cref="ReadWriteTexture2D{T}"/> instance to modify.</param>
/// <param name="source">The source <see cref="IReadWriteTexture2D{TPixel}"/> instance to modify.</param>
[Pure]
private void ApplyGammaHighlight(ReadWriteTexture2D<Rgba32, Vector4> source)
private void ApplyGammaHighlight(IReadWriteTexture2D<Vector4> source)
{
Gpu.Default.For(source.Height, new GammaHighlightProcessor(source.Width, source));
}
@@ -446,7 +446,7 @@ namespace ComputeSharp.BokehBlur.Processors
{
public readonly int width;
public readonly ReadWriteTexture2D<Rgba32, Vector4> source;
public readonly IReadWriteTexture2D<Vector4> source;
/// <inheritdoc/>
public void Execute(ThreadIds ids)
@@ -466,11 +466,11 @@ namespace ComputeSharp.BokehBlur.Processors
/// Applies the inverse gamma highlight pass to compute the final pixel values for a target image.
/// </summary>
/// <param name="source">The source <see cref="ReadWriteTexture2D{T}"/> instance to read from.</param>
/// <param name="target">The target <see cref="ReadWriteTexture2D{T, TPixel}"/> instance to write to.</param>
/// <param name="target">The target <see cref="IReadWriteTexture2D{TPixel}"/> instance to write to.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void ApplyInverseGammaExposure(
ReadWriteTexture2D<Vector4> source,
ReadWriteTexture2D<Rgba32, Vector4> target)
IReadWriteTexture2D<Vector4> target)
{
Gpu.Default.For(source.Height, new InverseGammaHighlightProcessor(source.Width, source, target));
}
@@ -484,7 +484,7 @@ namespace ComputeSharp.BokehBlur.Processors
public readonly int width;
public readonly ReadWriteTexture2D<Vector4> source;
public readonly ReadWriteTexture2D<Rgba32, Vector4> target;
public readonly IReadWriteTexture2D<Vector4> target;
/// <inheritdoc/>
public void Execute(ThreadIds ids)
+6 -6
ファイルの表示
@@ -107,12 +107,12 @@ namespace ComputeSharp.BokehBlur.Processors
/// <summary>
/// Performs a vertical 1D complex convolution with the specified parameters.
/// </summary>
/// <param name="source">The source <see cref="ReadWriteTexture2D{T, TPixel}"/> to read data from.</param>
/// <param name="source">The source <see cref="IReadWriteTexture2D{TPixel}"/> to read data from.</param>
/// <param name="target">The target <see cref="ReadWriteTexture2D{T}"/> to write the results to.</param>
/// <param name="kernel">The <see cref="ReadOnlyBuffer{T}"/> with the values for the current complex kernel.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void ApplyVerticalConvolution(
ReadWriteTexture2D<Rgba32, Vector4> source,
IReadWriteTexture2D<Vector4> source,
ReadWriteTexture2D<Vector4> target,
ReadOnlyBuffer<float> kernel)
{
@@ -140,7 +140,7 @@ namespace ComputeSharp.BokehBlur.Processors
public readonly int maxX;
public readonly int kernelLength;
public readonly ReadWriteTexture2D<Rgba32, Vector4> source;
public readonly IReadWriteTexture2D<Vector4> source;
public readonly ReadWriteTexture2D<Vector4> target;
public readonly ReadOnlyBuffer<float> kernel;
@@ -168,12 +168,12 @@ namespace ComputeSharp.BokehBlur.Processors
/// Performs an horizontal 1D complex convolution with the specified parameters.
/// </summary>
/// <param name="source">The source <see cref="ReadWriteTexture2D{T}"/> to read data from.</param>
/// <param name="target">The target <see cref="ReadWriteTexture2D{T, TPixel}"/> to write the results to.</param>
/// <param name="target">The target <see cref="IReadWriteTexture2D{TPixel}"/> to write the results to.</param>
/// <param name="kernel">The <see cref="ReadOnlyBuffer{T}"/> with the values for the current complex kernel.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void ApplyHorizontalConvolution(
ReadWriteTexture2D<Vector4> source,
ReadWriteTexture2D<Rgba32, Vector4> target,
IReadWriteTexture2D<Vector4> target,
ReadOnlyBuffer<float> kernel)
{
int height = Source.Height;
@@ -201,7 +201,7 @@ namespace ComputeSharp.BokehBlur.Processors
public readonly int kernelLength;
public readonly ReadWriteTexture2D<Vector4> source;
public readonly ReadWriteTexture2D<Rgba32, Vector4> target;
public readonly IReadWriteTexture2D<Vector4> target;
public readonly ReadOnlyBuffer<float> kernel;
/// <inheritdoc/>
+1 -1
ファイルの表示
@@ -9,7 +9,7 @@ using static TerraFX.Interop.D3D12_COMMAND_LIST_TYPE;
namespace ComputeSharp.Graphics.Commands
{
/// <summary>
/// A command list to set and execute operaations on the GPU.
/// A command list to set and execute operations on the GPU.
/// </summary>
internal unsafe ref struct CommandList
{
+162 -12
ファイルの表示
@@ -2,6 +2,7 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
using ComputeSharp.Resources;
using Microsoft.Toolkit.Diagnostics;
using TerraFX.Interop;
namespace ComputeSharp.__Internals
@@ -13,11 +14,26 @@ namespace ComputeSharp.__Internals
[Obsolete("This type is not intended to be used directly by user code")]
public static class GraphicsResourceHelper
{
/// <summary>
/// An interface for non-generic graphics resource types.
/// </summary>
internal interface IGraphicsResource
{
/// <summary>
/// Validates the given resource for usage with a specified device, and retrieves its GPU descriptor handle.
/// </summary>
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
/// <returns>The GPU descriptor handle for the resource.</returns>
D3D12_GPU_DESCRIPTOR_HANDLE ValidateAndGetGpuDescriptorHandle(GraphicsDevice device);
}
/// <summary>
/// Validates the given buffer for usage with a specified device, and retrieves its GPU descriptor handle.
/// </summary>
/// <typeparam name="T">The type of values stored in the input buffer.</typeparam>
/// <param name="buffer">The input <see cref="Buffer{T}"/> instance to check.</param>
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
/// <returns>The GPU descriptor handle for the buffer.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be called directly by user code")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -31,37 +47,171 @@ namespace ComputeSharp.__Internals
}
/// <summary>
/// Validates the given buffer for usage with a specified device, and retrieves its GPU descriptor handle.
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
/// </summary>
/// <param name="buffer">The input <see cref="Texture2D{T}"/> instance to check.</param>
/// <typeparam name="T">The type of values stored in the input texture.</typeparam>
/// <param name="texture">The input <see cref="ReadOnlyTexture2D{T}"/> instance to check.</param>
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
/// <returns>The GPU descriptor handle for the texture.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be called directly by user code")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ulong ValidateAndGetGpuDescriptorHandle<T>(Texture2D<T> buffer, GraphicsDevice device)
public static ulong ValidateAndGetGpuDescriptorHandle<T>(ReadOnlyTexture2D<T> texture, GraphicsDevice device)
where T : unmanaged
{
buffer.ThrowIfDisposed();
buffer.ThrowIfDeviceMismatch(device);
texture.ThrowIfDisposed();
texture.ThrowIfDeviceMismatch(device);
return Unsafe.As<D3D12_GPU_DESCRIPTOR_HANDLE, ulong>(ref Unsafe.AsRef(in buffer.D3D12GpuDescriptorHandle));
return Unsafe.As<D3D12_GPU_DESCRIPTOR_HANDLE, ulong>(ref Unsafe.AsRef(in texture.D3D12GpuDescriptorHandle));
}
/// <summary>
/// Validates the given buffer for usage with a specified device, and retrieves its GPU descriptor handle.
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
/// </summary>
/// <param name="buffer">The input <see cref="Texture3D{T}"/> instance to check.</param>
/// <typeparam name="T">The type of values stored in the input texture.</typeparam>
/// <param name="texture">The input <see cref="ReadWriteTexture2D{T}"/> instance to check.</param>
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
/// <returns>The GPU descriptor handle for the texture.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be called directly by user code")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ulong ValidateAndGetGpuDescriptorHandle<T>(Texture3D<T> buffer, GraphicsDevice device)
public static ulong ValidateAndGetGpuDescriptorHandle<T>(ReadWriteTexture2D<T> texture, GraphicsDevice device)
where T : unmanaged
{
buffer.ThrowIfDisposed();
buffer.ThrowIfDeviceMismatch(device);
texture.ThrowIfDisposed();
texture.ThrowIfDeviceMismatch(device);
return Unsafe.As<D3D12_GPU_DESCRIPTOR_HANDLE, ulong>(ref Unsafe.AsRef(in buffer.D3D12GpuDescriptorHandle));
return Unsafe.As<D3D12_GPU_DESCRIPTOR_HANDLE, ulong>(ref Unsafe.AsRef(in texture.D3D12GpuDescriptorHandle));
}
/// <summary>
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
/// </summary>
/// <typeparam name="TPixel">The type of normalized values stored in the input texture.</typeparam>
/// <param name="texture">The input <see cref="IReadOnlyTexture2D{TPixel}"/> instance to check.</param>
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
/// <returns>The GPU descriptor handle for the texture.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be called directly by user code")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe ulong ValidateAndGetGpuDescriptorHandle<TPixel>(IReadOnlyTexture2D<TPixel> texture, GraphicsDevice device)
where TPixel : unmanaged
{
if (texture is IGraphicsResource resource)
{
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = resource.ValidateAndGetGpuDescriptorHandle(device);
return *(ulong*)&d3D12GpuDescriptorHandle;
}
return ThrowHelper.ThrowArgumentException<ulong>("The input texture is not a valid instance");
}
/// <summary>
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
/// </summary>
/// <typeparam name="TPixel">The type of normalized values stored in the input texture.</typeparam>
/// <param name="texture">The input <see cref="IReadWriteTexture2D{TPixel}"/> instance to check.</param>
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
/// <returns>The GPU descriptor handle for the texture.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be called directly by user code")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe ulong ValidateAndGetGpuDescriptorHandle<TPixel>(IReadWriteTexture2D<TPixel> texture, GraphicsDevice device)
where TPixel : unmanaged
{
if (texture is IGraphicsResource resource)
{
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = resource.ValidateAndGetGpuDescriptorHandle(device);
return *(ulong*)&d3D12GpuDescriptorHandle;
}
return ThrowHelper.ThrowArgumentException<ulong>("The input texture is not a valid instance");
}
/// <summary>
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
/// </summary>
/// <typeparam name="T">The type of values stored in the input texture.</typeparam>
/// <param name="texture">The input <see cref="ReadOnlyTexture3D{T}"/> instance to check.</param>
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
/// <returns>The GPU descriptor handle for the texture.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be called directly by user code")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ulong ValidateAndGetGpuDescriptorHandle<T>(ReadOnlyTexture3D<T> texture, GraphicsDevice device)
where T : unmanaged
{
texture.ThrowIfDisposed();
texture.ThrowIfDeviceMismatch(device);
return Unsafe.As<D3D12_GPU_DESCRIPTOR_HANDLE, ulong>(ref Unsafe.AsRef(in texture.D3D12GpuDescriptorHandle));
}
/// <summary>
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
/// </summary>
/// <typeparam name="T">The type of values stored in the input texture.</typeparam>
/// <param name="texture">The input <see cref="ReadWriteTexture3D{T}"/> instance to check.</param>
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
/// <returns>The GPU descriptor handle for the texture.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be called directly by user code")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ulong ValidateAndGetGpuDescriptorHandle<T>(ReadWriteTexture3D<T> texture, GraphicsDevice device)
where T : unmanaged
{
texture.ThrowIfDisposed();
texture.ThrowIfDeviceMismatch(device);
return Unsafe.As<D3D12_GPU_DESCRIPTOR_HANDLE, ulong>(ref Unsafe.AsRef(in texture.D3D12GpuDescriptorHandle));
}
/// <summary>
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
/// </summary>
/// <typeparam name="TPixel">The type of normalized values stored in the input texture.</typeparam>
/// <param name="texture">The input <see cref="IReadOnlyTexture3D{TPixel}"/> instance to check.</param>
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
/// <returns>The GPU descriptor handle for the texture.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be called directly by user code")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe ulong ValidateAndGetGpuDescriptorHandle<TPixel>(IReadOnlyTexture3D<TPixel> texture, GraphicsDevice device)
where TPixel : unmanaged
{
if (texture is IGraphicsResource resource)
{
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = resource.ValidateAndGetGpuDescriptorHandle(device);
return *(ulong*)&d3D12GpuDescriptorHandle;
}
return ThrowHelper.ThrowArgumentException<ulong>("The input texture is not a valid instance");
}
/// <summary>
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
/// </summary>
/// <typeparam name="TPixel">The type of normalized values stored in the input texture.</typeparam>
/// <param name="texture">The input <see cref="IReadWriteTexture3D{TPixel}"/> instance to check.</param>
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
/// <returns>The GPU descriptor handle for the texture.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be called directly by user code")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe ulong ValidateAndGetGpuDescriptorHandle<TPixel>(IReadWriteTexture3D<TPixel> texture, GraphicsDevice device)
where TPixel : unmanaged
{
if (texture is IGraphicsResource resource)
{
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = resource.ValidateAndGetGpuDescriptorHandle(device);
return *(ulong*)&d3D12GpuDescriptorHandle;
}
return ThrowHelper.ThrowArgumentException<ulong>("The input texture is not a valid instance");
}
}
}
+1 -1
ファイルの表示
@@ -30,7 +30,7 @@ namespace ComputeSharp.Resources
/// <summary>
/// The <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
/// </summary>
internal readonly D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandle;
private readonly D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandle;
/// <summary>
/// The <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
+14 -2
ファイルの表示
@@ -1,4 +1,5 @@
using System.Runtime.CompilerServices;
using ComputeSharp.__Internals;
using ComputeSharp.Exceptions;
using ComputeSharp.Graphics.Commands;
using ComputeSharp.Graphics.Extensions;
@@ -15,13 +16,15 @@ using static TerraFX.Interop.D3D12_SRV_DIMENSION;
using static TerraFX.Interop.D3D12_UAV_DIMENSION;
using FX = TerraFX.Interop.Windows;
#pragma warning disable CS0618
namespace ComputeSharp.Resources
{
/// <summary>
/// A <see langword="class"/> representing a typed 2D texture stored on GPU memory.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
public unsafe abstract class Texture2D<T> : NativeObject
public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper.IGraphicsResource
where T : unmanaged
{
/// <summary>
@@ -32,7 +35,7 @@ namespace ComputeSharp.Resources
/// <summary>
/// The <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
/// </summary>
internal readonly D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandle;
private readonly D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandle;
/// <summary>
/// The <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
@@ -281,5 +284,14 @@ namespace ComputeSharp.Resources
GraphicsDeviceMismatchException.Throw(this, device);
}
}
/// <inheritdoc/>
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
{
ThrowIfDisposed();
ThrowIfDeviceMismatch(device);
return D3D12GpuDescriptorHandle;
}
}
}
+14 -2
ファイルの表示
@@ -1,4 +1,5 @@
using System.Runtime.CompilerServices;
using ComputeSharp.__Internals;
using ComputeSharp.Exceptions;
using ComputeSharp.Graphics.Commands;
using ComputeSharp.Graphics.Extensions;
@@ -15,13 +16,15 @@ using static TerraFX.Interop.D3D12_SRV_DIMENSION;
using static TerraFX.Interop.D3D12_UAV_DIMENSION;
using FX = TerraFX.Interop.Windows;
#pragma warning disable CS0618
namespace ComputeSharp.Resources
{
/// <summary>
/// A <see langword="class"/> representing a typed 3D texture stored on GPU memory.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
public unsafe abstract class Texture3D<T> : NativeObject
public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper.IGraphicsResource
where T : unmanaged
{
/// <summary>
@@ -32,7 +35,7 @@ namespace ComputeSharp.Resources
/// <summary>
/// The <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
/// </summary>
internal readonly D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandle;
private readonly D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandle;
/// <summary>
/// The <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
@@ -304,5 +307,14 @@ namespace ComputeSharp.Resources
GraphicsDeviceMismatchException.Throw(this, device);
}
}
/// <inheritdoc/>
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
{
ThrowIfDisposed();
ThrowIfDeviceMismatch(device);
return D3D12GpuDescriptorHandle;
}
}
}
+36
ファイルの表示
@@ -0,0 +1,36 @@
namespace ComputeSharp
{
/// <summary>
/// An interface representing a typed readonly 2D texture containing normalized pixel data stored on GPU memory.
/// This interface can only be used to wrap <see cref="ReadOnlyTexture2D{T, TPixel}"/> instances.
/// </summary>
/// <typeparam name="TPixel">The type of normalized pixels used on the GPU side.</typeparam>
public interface IReadOnlyTexture2D<TPixel>
where TPixel : unmanaged
{
/// <summary>
/// Gets the width of the current texture.
/// </summary>
public int Width { get; }
/// <summary>
/// Gets the height of the current texture.
/// </summary>
public int Height { get; }
/// <summary>
/// Gets a single <typeparamref name="TPixel"/> value from the current readonly texture.
/// </summary>
/// <param name="x">The horizontal offset of the value to get.</param>
/// <param name="y">The vertical offset of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
public TPixel this[int x, int y] { get; }
/// <summary>
/// Gets a single <typeparamref name="TPixel"/> value from the current readonly texture.
/// </summary>
/// <param name="xy">The coordinates of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
public TPixel this[Int2 xy] { get; }
}
}
+42
ファイルの表示
@@ -0,0 +1,42 @@
namespace ComputeSharp
{
/// <summary>
/// An interface representing a typed readonly 3D texture containing normalized pixel data stored on GPU memory.
/// This interface can only be used to wrap <see cref="ReadOnlyTexture3D{T, TPixel}"/> instances.
/// </summary>
/// <typeparam name="TPixel">The type of normalized pixels used on the GPU side.</typeparam>
public interface IReadOnlyTexture3D<TPixel>
where TPixel : unmanaged
{
/// <summary>
/// Gets the width of the current texture.
/// </summary>
public int Width { get; }
/// <summary>
/// Gets the height of the current texture.
/// </summary>
public int Height { get; }
/// <summary>
/// Gets the depth of the current texture.
/// </summary>
public int Depth { get; }
/// <summary>
/// Gets a single <typeparamref name="TPixel"/> value from the current readonly texture.
/// </summary>
/// <param name="x">The horizontal offset of the value to get.</param>
/// <param name="y">The vertical offset of the value to get.</param>
/// <param name="y">The depthwise offset of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
public TPixel this[int x, int y, int z] { get; }
/// <summary>
/// Gets a single <typeparamref name="TPixel"/> value from the current readonly texture.
/// </summary>
/// <param name="xyz">The coordinates of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
public TPixel this[Int3 xyz] { get; }
}
}
+36
ファイルの表示
@@ -0,0 +1,36 @@
namespace ComputeSharp
{
/// <summary>
/// An interface representing a typed writeable 2D texture containing normalized pixel data stored on GPU memory.
/// This interface can only be used to wrap <see cref="ReadWriteTexture2D{T, TPixel}"/> instances.
/// </summary>
/// <typeparam name="TPixel">The type of normalized pixels used on the GPU side.</typeparam>
public interface IReadWriteTexture2D<TPixel>
where TPixel : unmanaged
{
/// <summary>
/// Gets the width of the current texture.
/// </summary>
public int Width { get; }
/// <summary>
/// Gets the height of the current texture.
/// </summary>
public int Height { get; }
/// <summary>
/// Gets a single <typeparamref name="TPixel"/> value from the current writeable texture.
/// </summary>
/// <param name="x">The horizontal offset of the value to get.</param>
/// <param name="y">The vertical offset of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
public ref TPixel this[int x, int y] { get; }
/// <summary>
/// Gets or sets a single <typeparamref name="TPixel"/> value from the current writeable texture.
/// </summary>
/// <param name="xy">The coordinates of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
public ref TPixel this[Int2 xy] { get; }
}
}
+42
ファイルの表示
@@ -0,0 +1,42 @@
namespace ComputeSharp
{
/// <summary>
/// An interface representing a typed writeable 2D texture containing normalized pixel data stored on GPU memory.
/// This interface can only be used to wrap <see cref="ReadWriteTexture3D{T, TPixel}"/> instances.
/// </summary>
/// <typeparam name="TPixel">The type of normalized pixels used on the GPU side.</typeparam>
public interface IReadWriteTexture3D<TPixel>
where TPixel : unmanaged
{
/// <summary>
/// Gets the width of the current texture.
/// </summary>
public int Width { get; }
/// <summary>
/// Gets the height of the current texture.
/// </summary>
public int Height { get; }
/// <summary>
/// Gets the depth of the current texture.
/// </summary>
public int Depth { get; }
/// <summary>
/// Gets a single <typeparamref name="TPixel"/> value from the current writeable texture.
/// </summary>
/// <param name="x">The horizontal offset of the value to get.</param>
/// <param name="y">The vertical offset of the value to get.</param>
/// <param name="z">The depthwise offset of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
public ref TPixel this[int x, int y, int z] { get; }
/// <summary>
/// Gets a single <typeparamref name="TPixel"/> value from the current writeable texture.
/// </summary>
/// <param name="xyz">The coordinates of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
public ref TPixel this[Int3 xyz] { get; }
}
}
+3 -12
ファイルの表示
@@ -16,7 +16,7 @@ namespace ComputeSharp
/// <typeparam name="TPixel">The type of pixels used on the GPU side.</typeparam>
[DebuggerTypeProxy(typeof(Texture2DDebugView<>))]
[DebuggerDisplay("{ToString(),raw}")]
public sealed class ReadOnlyTexture2D<T, TPixel> : Texture2D<T>
public sealed class ReadOnlyTexture2D<T, TPixel> : Texture2D<T>, IReadOnlyTexture2D<TPixel>
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
@@ -31,19 +31,10 @@ namespace ComputeSharp
{
}
/// <summary>
/// Gets a single <typeparamref name="TPixel"/> value from the current readonly texture.
/// </summary>
/// <param name="x">The horizontal offset of the value to get.</param>
/// <param name="y">The vertical offset of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
/// <inheritdoc/>
public TPixel this[int x, int y] => throw new InvalidExecutionContextException($"{nameof(ReadOnlyTexture2D<T, TPixel>)}<T>[int,int]");
/// <summary>
/// Gets a single <typeparamref name="TPixel"/> value from the current readonly texture.
/// </summary>
/// <param name="xy">The coordinates of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
/// <inheritdoc/>
public TPixel this[Int2 xy] => throw new InvalidExecutionContextException($"{nameof(ReadOnlyTexture2D<T,TPixel>)}<T>[Int2]");
/// <inheritdoc/>
+3 -13
ファイルの表示
@@ -16,7 +16,7 @@ namespace ComputeSharp
/// <typeparam name="TPixel">The type of pixels used on the GPU side.</typeparam>
[DebuggerTypeProxy(typeof(Texture3DDebugView<>))]
[DebuggerDisplay("{ToString(),raw}")]
public sealed class ReadOnlyTexture3D<T, TPixel> : Texture3D<T>
public sealed class ReadOnlyTexture3D<T, TPixel> : Texture3D<T>, IReadOnlyTexture3D<TPixel>
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
@@ -32,20 +32,10 @@ namespace ComputeSharp
{
}
/// <summary>
/// Gets a single <typeparamref name="TPixel"/> value from the current readonly texture.
/// </summary>
/// <param name="x">The horizontal offset of the value to get.</param>
/// <param name="y">The vertical offset of the value to get.</param>
/// <param name="y">The depthwise offset of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
/// <inheritdoc/>
public TPixel this[int x, int y, int z] => throw new InvalidExecutionContextException($"{nameof(ReadOnlyTexture3D<T, TPixel>)}<T>[int,int,int]");
/// <summary>
/// Gets a single <typeparamref name="TPixel"/> value from the current readonly texture.
/// </summary>
/// <param name="xyz">The coordinates of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
/// <inheritdoc/>
public TPixel this[Int3 xyz] => throw new InvalidExecutionContextException($"{nameof(ReadOnlyTexture3D<T, TPixel>)}<T>[Int3]");
/// <inheritdoc/>
+3 -12
ファイルの表示
@@ -16,7 +16,7 @@ namespace ComputeSharp
/// <typeparam name="TPixel">The type of pixels used on the GPU side.</typeparam>
[DebuggerTypeProxy(typeof(Texture2DDebugView<>))]
[DebuggerDisplay("{ToString(),raw}")]
public sealed class ReadWriteTexture2D<T, TPixel> : Texture2D<T>
public sealed class ReadWriteTexture2D<T, TPixel> : Texture2D<T>, IReadWriteTexture2D<TPixel>
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
@@ -31,19 +31,10 @@ namespace ComputeSharp
{
}
/// <summary>
/// Gets a single <typeparamref name="TPixel"/> value from the current writeable texture.
/// </summary>
/// <param name="x">The horizontal offset of the value to get.</param>
/// <param name="y">The vertical offset of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
/// <inheritdoc/>
public ref TPixel this[int x, int y] => throw new InvalidExecutionContextException($"{nameof(ReadWriteTexture2D<T, TPixel>)}<T>[int,int]");
/// <summary>
/// Gets or sets a single <typeparamref name="TPixel"/> value from the current writeable texture.
/// </summary>
/// <param name="xy">The coordinates of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
/// <inheritdoc/>
public ref TPixel this[Int2 xy] => throw new InvalidExecutionContextException($"{nameof(ReadWriteTexture2D<T, TPixel>)}<T>[Int2]");
/// <inheritdoc/>
+3 -13
ファイルの表示
@@ -16,7 +16,7 @@ namespace ComputeSharp
/// <typeparam name="TPixel">The type of pixels used on the GPU side.</typeparam>
[DebuggerTypeProxy(typeof(Texture3DDebugView<>))]
[DebuggerDisplay("{ToString(),raw}")]
public sealed class ReadWriteTexture3D<T, TPixel> : Texture3D<T>
public sealed class ReadWriteTexture3D<T, TPixel> : Texture3D<T>, IReadWriteTexture3D<TPixel>
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
@@ -32,20 +32,10 @@ namespace ComputeSharp
{
}
/// <summary>
/// Gets a single <typeparamref name="TPixel"/> value from the current writeable texture.
/// </summary>
/// <param name="x">The horizontal offset of the value to get.</param>
/// <param name="y">The vertical offset of the value to get.</param>
/// <param name="z">The depthwise offset of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
/// <inheritdoc/>
public ref TPixel this[int x, int y, int z] => throw new InvalidExecutionContextException($"{nameof(ReadWriteTexture3D<T, TPixel>)}<T>[int,int,int]");
/// <summary>
/// Gets a single <typeparamref name="TPixel"/> value from the current writeable texture.
/// </summary>
/// <param name="xyz">The coordinates of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
/// <inheritdoc/>
public ref TPixel this[Int3 xyz] => throw new InvalidExecutionContextException($"{nameof(ReadWriteTexture3D<T, TPixel>)}<T>[Int3]");
/// <inheritdoc/>
+6 -2
ファイルの表示
@@ -79,7 +79,9 @@ namespace ComputeSharp.Shaders.Mappings
genericType == typeof(ReadOnlyTexture2D<>) ||
genericType == typeof(ReadOnlyTexture2D<,>) ||
genericType == typeof(ReadOnlyTexture3D<>) ||
genericType == typeof(ReadOnlyTexture3D<,>);
genericType == typeof(ReadOnlyTexture3D<,>) ||
genericType == typeof(IReadOnlyTexture2D<>) ||
genericType == typeof(IReadOnlyTexture3D<>);
}
/// <summary>
@@ -99,7 +101,9 @@ namespace ComputeSharp.Shaders.Mappings
genericType == typeof(ReadWriteTexture2D<>) ||
genericType == typeof(ReadWriteTexture2D<,>) ||
genericType == typeof(ReadWriteTexture3D<>) ||
genericType == typeof(ReadWriteTexture3D<,>);
genericType == typeof(ReadWriteTexture3D<,>) ||
genericType == typeof(IReadWriteTexture2D<>) ||
genericType == typeof(IReadWriteTexture3D<>); ;
}
}
}
+1 -1
ファイルの表示
@@ -28,7 +28,7 @@ namespace ComputeSharp.SourceGenerators.Mappings
/// Tries to get the mapped HLSL-compatible identifier name for the input identifier name.
/// </summary>
/// <param name="name">The input identifier name.</param>
/// <param name="mapped">The mapped identifier name, if aa replacement is needed.</param>
/// <param name="mapped">The mapped identifier name, if a replacement is needed.</param>
/// <returns>The HLSL-compatible identifier name that can be used in an HLSL shader.</returns>
[Pure]
public static bool TryGetMappedName(string name, out string? mapped)
+5 -1
ファイルの表示
@@ -21,10 +21,14 @@ namespace ComputeSharp.SourceGenerators.Mappings
[$"ComputeSharp.ReadOnlyTexture2D`2.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
[$"ComputeSharp.ReadWriteTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
[$"ComputeSharp.ReadWriteTexture2D`2.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
[$"ComputeSharp.IReadOnlyTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
[$"ComputeSharp.IReadWriteTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
[$"ComputeSharp.ReadOnlyTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
[$"ComputeSharp.ReadOnlyTexture3D`2.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
[$"ComputeSharp.ReadWriteTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
[$"ComputeSharp.ReadWriteTexture3D`2.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3"
[$"ComputeSharp.ReadWriteTexture3D`2.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
[$"ComputeSharp.IReadOnlyTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
[$"ComputeSharp.IReadWriteTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3"
};
/// <summary>
+8
ファイルの表示
@@ -78,6 +78,10 @@ namespace ComputeSharp.SourceGenerators.Mappings
case "ComputeSharp.ReadOnlyTexture3D`2":
case "ComputeSharp.ReadWriteTexture3D`1":
case "ComputeSharp.ReadWriteTexture3D`2":
case "ComputeSharp.IReadOnlyTexture2D`1":
case "ComputeSharp.IReadWriteTexture2D`1":
case "ComputeSharp.IReadOnlyTexture3D`1":
case "ComputeSharp.IReadWriteTexture3D`1":
return true;
default: return false;
};
@@ -134,6 +138,10 @@ namespace ComputeSharp.SourceGenerators.Mappings
"ComputeSharp.ReadOnlyTexture3D`2" => $"Texture3D<unorm {mapped}>",
"ComputeSharp.ReadWriteTexture3D`1" => $"RWTexture3D<{mapped}>",
"ComputeSharp.ReadWriteTexture3D`2" => $"RWTexture3D<unorm {mapped}>",
"ComputeSharp.IReadOnlyTexture2D`1" => $"Texture2D<unorm {mapped}>",
"ComputeSharp.IReadWriteTexture2D`1" => $"RWTexture2D<unorm {mapped}>",
"ComputeSharp.IReadOnlyTexture3D`1" => $"Texture3D<unorm {mapped}>",
"ComputeSharp.IReadWriteTexture3D`1" => $"RWTexture3D<unorm {mapped}>",
_ => throw new ArgumentException()
};
}