Added dispatch helpers for normalized texture interfaces

このコミットが含まれているのは:
Sergio Pedri committed 2021-01-06 17:28:55 +01:00
1 親 226481aff6
コミット 958fa15a11
5ファイル変更
+152 -16

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

+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
{
+124 -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,133 @@ 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="Texture2D{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>(Texture2D<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="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 ulong ValidateAndGetGpuDescriptorHandle<T>(Texture3D<T> buffer, GraphicsDevice device)
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="Texture3D{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> 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="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");
}
}
}
+13 -1
ファイルの表示
@@ -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>
@@ -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;
}
}
}
+13 -1
ファイルの表示
@@ -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>
@@ -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;
}
}
}
+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)