Add IComputeShaderDescriptor<T>, adjust namespaces

このコミットが含まれているのは:
Sergio Pedri committed 2023-10-15 21:28:02 +02:00
1 親 de498f338a
コミット cecafb8d88
15ファイル変更
+51 -70

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

+2 -1
ファイルの表示
@@ -1,4 +1,5 @@
using System;
using ComputeSharp.Descriptors;
using TerraFX.Interop.Windows;
namespace ComputeSharp.SwapChain.Backend;
@@ -11,7 +12,7 @@ namespace ComputeSharp.SwapChain.Backend;
/// The main point of this type is to hide the complexity of <see cref="Win32Application"/> from the non-NativeAOT sample.
/// </remarks>
internal static class Win32ApplicationFactory<T>
where T : struct, IComputeShader<float4>
where T : struct, IComputeShader<float4>, IComputeShaderDescriptor<T>
{
/// <summary>
/// The <see cref="Func{T1, TResult}"/> instance used to create shaders to run.
+6 -8
ファイルの表示
@@ -1,15 +1,13 @@
using System;
using System.Runtime.CompilerServices;
using ComputeSharp.__Internals;
using ComputeSharp.Core.Extensions;
using ComputeSharp.Descriptors;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
#if !NET6_0_OR_GREATER
using DirectX = TerraFX.Interop.DirectX.DirectX2;
#endif
#pragma warning disable CS0618
namespace ComputeSharp.Interop;
/// <summary>
@@ -32,7 +30,7 @@ public static class ReflectionServices
/// the APIs to dispatch a shader, the thread sizes would actually be set to a proper value insead.
/// </remarks>
public static ShaderInfo GetShaderInfo<T>()
where T : struct, IComputeShader
where T : struct, IComputeShader, IComputeShaderDescriptor<T>
{
return GetNonGenericShaderInfo(default(T));
}
@@ -49,7 +47,7 @@ public static class ReflectionServices
/// the APIs to dispatch a shader, the thread sizes would actually be set to a proper value insead.
/// </remarks>
public static unsafe ShaderInfo GetShaderInfo<T>(in T shader)
where T : struct, IComputeShader
where T : struct, IComputeShader, IComputeShaderDescriptor<T>
{
return GetNonGenericShaderInfo(in shader);
}
@@ -70,7 +68,7 @@ public static class ReflectionServices
/// the APIs to dispatch a shader, the thread sizes would actually be set to a proper value insead.
/// </remarks>
public static ShaderInfo GetShaderInfo<T, TPixel>()
where T : struct, IComputeShader<TPixel>
where T : struct, IComputeShader<TPixel>, IComputeShaderDescriptor<T>
where TPixel : unmanaged
{
return GetNonGenericShaderInfo(default(T));
@@ -89,7 +87,7 @@ public static class ReflectionServices
/// the APIs to dispatch a shader, the thread sizes would actually be set to a proper value insead.
/// </remarks>
public static unsafe ShaderInfo GetShaderInfo<T, TPixel>(in T shader)
where T : struct, IComputeShader<TPixel>
where T : struct, IComputeShader<TPixel>, IComputeShaderDescriptor<T>
where TPixel : unmanaged
{
return GetNonGenericShaderInfo(in shader);
@@ -102,7 +100,7 @@ public static class ReflectionServices
/// <param name="shader">The input shader to retrieve info for.</param>
/// <returns>The resulting <see cref="ShaderInfo"/> instance.</returns>
private static unsafe ShaderInfo GetNonGenericShaderInfo<T>(in T shader)
where T : struct, IShader
where T : struct, IComputeShaderDescriptor<T>
{
string hlslSource = Unsafe.AsRef(in shader).HlslSource;
@@ -1,13 +0,0 @@
using System;
using System.ComponentModel;
namespace ComputeSharp.__Internals;
/// <summary>
/// A base <see langword="interface"/> representing a given shader that can be dispatched.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This interface is not intended to be used directly by user code")]
public interface IShader
{
}
+2 -1
ファイルの表示
@@ -1,4 +1,5 @@
using System;
using ComputeSharp.Descriptors;
namespace ComputeSharp.WinUI;
@@ -8,7 +9,7 @@ namespace ComputeSharp.WinUI;
/// </summary>
/// <typeparam name="T">The type of shader to use to render frames.</typeparam>
public sealed class ShaderRunner<T> : IShaderRunner
where T : struct, IComputeShader<Float4>
where T : struct, IComputeShader<Float4>, IComputeShaderDescriptor<T>
{
/// <summary>
/// The <see cref="Func{T1,TResult}"/> instance used to create shaders to run.
@@ -1,15 +1,16 @@
using System;
using System.ComponentModel;
using ComputeSharp.Interop;
namespace ComputeSharp.__Internals;
namespace ComputeSharp.Descriptors;
/// <summary>
/// A base <see langword="interface"/> representing a given shader that can be dispatched.
/// An interface for a descriptor for a given compute shader.
/// Descriptors contain metadata associated to compute shaders,
/// with all information needed to execute them at runtime.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This interface is not intended to be used directly by user code")]
public interface IShader
/// <typeparam name="T">The type of compute shader being described.</typeparam>
public interface IComputeShaderDescriptor<T>
where T : struct
{
/// <summary>
/// The number of threads in each thread group for the X axis.
@@ -63,18 +64,20 @@ public interface IShader
/// Loads the constant buffer of a given input shader.
/// </summary>
/// <typeparam name="TLoader">The type of data loader being used.</typeparam>
/// <param name="shader">The input shader to load the constant buffer for.</param>
/// <param name="loader">The <typeparamref name="TLoader"/> instance to use to load the data.</param>
/// <param name="x">The number of iterations to run on the X axis.</param>
/// <param name="y">The number of iterations to run on the Y axis.</param>
/// <param name="z">The number of iterations to run on the Z axis.</param>
void LoadConstantBuffer<TLoader>(ref TLoader loader, int x, int y, int z)
void LoadConstantBuffer<TLoader>(in T shader, ref TLoader loader, int x, int y, int z)
where TLoader : struct, IConstantBufferLoader;
/// <summary>
/// Loads the graphics resources for the shader.
/// </summary>
/// <typeparam name="TLoader">The type of graphics resource loader being used.</typeparam>
/// <param name="shader">The input shader to load the graphics resources for.</param>
/// <param name="loader">The <typeparamref name="TLoader"/> instance to use to load the data.</param>
void LoadGraphicsResources<TLoader>(ref TLoader loader)
void LoadGraphicsResources<TLoader>(in T shader, ref TLoader loader)
where TLoader : struct, IGraphicsResourceLoader;
}
@@ -1,6 +1,6 @@
using System;
namespace ComputeSharp.__Internals;
namespace ComputeSharp.Descriptors;
/// <summary>
/// A type representing a data loader for the constant buffer of a compute shader.
@@ -1,6 +1,6 @@
using System;
namespace ComputeSharp.__Internals;
namespace ComputeSharp.Descriptors;
/// <summary>
/// A type representing a loader object for <see cref="IGraphicsResource"/> values used in compute shaders.
+1 -5
ファイルの表示
@@ -1,13 +1,9 @@
using ComputeSharp.__Internals;
#pragma warning disable CS0618
namespace ComputeSharp;
/// <summary>
/// An <see langword="interface"/> representing a compute shader.
/// </summary>
public interface IComputeShader : IShader
public interface IComputeShader
{
/// <summary>
/// Executes the current compute shader.
+1 -5
ファイルの表示
@@ -1,7 +1,3 @@
using ComputeSharp.__Internals;
#pragma warning disable CS0618
namespace ComputeSharp;
/// <summary>
@@ -11,7 +7,7 @@ namespace ComputeSharp;
/// <remarks>
/// This interface allows implementing logic analogous of pixel shaders, but via compute shaders.
/// </remarks>
public interface IComputeShader<TPixel> : IShader
public interface IComputeShader<TPixel>
where TPixel : unmanaged
{
/// <summary>
+6 -5
ファイルの表示
@@ -1,5 +1,6 @@
using System;
using System.Runtime.CompilerServices;
using ComputeSharp.Descriptors;
using ComputeSharp.Interop;
namespace ComputeSharp;
@@ -17,7 +18,7 @@ public static partial class GraphicsDeviceExtensions
/// <param name="x">The number of iterations to run on the X axis.</param>
/// <param name="shader">The input <typeparamref name="T"/> instance representing the compute shader to run.</param>
public static void For<T>(this GraphicsDevice device, int x, in T shader)
where T : struct, IComputeShader
where T : struct, IComputeShader, IComputeShaderDescriptor<T>
{
default(ArgumentNullException).ThrowIfNull(device);
@@ -35,7 +36,7 @@ public static partial class GraphicsDeviceExtensions
/// <param name="y">The number of iterations to run on the Y axis.</param>
/// <param name="shader">The input <typeparamref name="T"/> instance representing the compute shader to run.</param>
public static void For<T>(this GraphicsDevice device, int x, int y, in T shader)
where T : struct, IComputeShader
where T : struct, IComputeShader, IComputeShaderDescriptor<T>
{
default(ArgumentNullException).ThrowIfNull(device);
@@ -54,7 +55,7 @@ public static partial class GraphicsDeviceExtensions
/// <param name="z">The number of iterations to run on the Z axis.</param>
/// <param name="shader">The input <typeparamref name="T"/> instance representing the compute shader to run.</param>
public static void For<T>(this GraphicsDevice device, int x, int y, int z, in T shader)
where T : struct, IComputeShader
where T : struct, IComputeShader, IComputeShaderDescriptor<T>
{
default(ArgumentNullException).ThrowIfNull(device);
@@ -71,7 +72,7 @@ public static partial class GraphicsDeviceExtensions
/// <param name="device">The <see cref="GraphicsDevice"/> to use to run the shader.</param>
/// <param name="texture">The target texture to apply the pixel shader to.</param>
public static void ForEach<T, TPixel>(this GraphicsDevice device, IReadWriteNormalizedTexture2D<TPixel> texture)
where T : struct, IComputeShader<TPixel>
where T : struct, IComputeShader<TPixel>, IComputeShaderDescriptor<T>
where TPixel : unmanaged
{
default(ArgumentNullException).ThrowIfNull(device);
@@ -91,7 +92,7 @@ public static partial class GraphicsDeviceExtensions
/// <param name="texture">The target texture to apply the pixel shader to.</param>
/// <param name="shader">The input <typeparamref name="T"/> instance representing the pixel shader to run.</param>
public static void ForEach<T, TPixel>(this GraphicsDevice device, IReadWriteNormalizedTexture2D<TPixel> texture, in T shader)
where T : struct, IComputeShader<TPixel>
where T : struct, IComputeShader<TPixel>, IComputeShaderDescriptor<T>
where TPixel : unmanaged
{
default(ArgumentNullException).ThrowIfNull(device);
+9 -10
ファイルの表示
@@ -2,6 +2,7 @@ using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using ComputeSharp.Descriptors;
using ComputeSharp.Graphics.Commands;
using ComputeSharp.Graphics.Extensions;
using ComputeSharp.Resources.Interop;
@@ -9,8 +10,6 @@ using ComputeSharp.Shaders.Dispatching;
using ComputeSharp.Shaders.Loading;
using TerraFX.Interop.DirectX;
#pragma warning disable CS0618
namespace ComputeSharp;
/// <summary>
@@ -123,7 +122,7 @@ public struct ComputeContext : IDisposable, IAsyncDisposable
/// <param name="x">The number of iterations to run on the X axis.</param>
/// <param name="shader">The input <typeparamref name="T"/> instance representing the compute shader to run.</param>
internal readonly unsafe void Run<T>(int x, ref T shader)
where T : struct, IComputeShader
where T : struct, IComputeShader, IComputeShaderDescriptor<T>
{
Run(x, 1, 1, ref shader);
@@ -136,7 +135,7 @@ public struct ComputeContext : IDisposable, IAsyncDisposable
/// <param name="y">The number of iterations to run on the Y axis.</param>
/// <param name="shader">The input <typeparamref name="T"/> instance representing the compute shader to run.</param>
internal readonly unsafe void Run<T>(int x, int y, ref T shader)
where T : struct, IComputeShader
where T : struct, IComputeShader, IComputeShaderDescriptor<T>
{
Run(x, y, 1, ref shader);
@@ -151,7 +150,7 @@ public struct ComputeContext : IDisposable, IAsyncDisposable
/// <param name="z">The number of iterations to run on the Z axis.</param>
/// <param name="shader">The input <typeparamref name="T"/> instance representing the compute shader to run.</param>
internal readonly unsafe void Run<T>(int x, int y, int z, ref T shader)
where T : struct, IComputeShader
where T : struct, IComputeShader, IComputeShaderDescriptor<T>
{
default(InvalidOperationException).ThrowIf(this.device is null);
default(ArgumentOutOfRangeException).ThrowIfNegativeOrZero(x);
@@ -174,11 +173,11 @@ public struct ComputeContext : IDisposable, IAsyncDisposable
D3D12GraphicsCommandListConstantBufferLoader dataLoader = new(commandList.D3D12GraphicsCommandList);
shader.LoadConstantBuffer(ref dataLoader, x, y, z);
shader.LoadConstantBuffer(in shader, ref dataLoader, x, y, z);
D3D12GraphicsCommandListGraphicsResourceLoader graphicsResourceLoader = new(commandList.D3D12GraphicsCommandList, this.device, rootParameterOffset: 1);
shader.LoadGraphicsResources(ref graphicsResourceLoader);
shader.LoadGraphicsResources(in shader, ref graphicsResourceLoader);
commandList.D3D12GraphicsCommandList->Dispatch((uint)groupsX, (uint)groupsY, (uint)groupsZ);
}
@@ -191,7 +190,7 @@ public struct ComputeContext : IDisposable, IAsyncDisposable
/// <param name="texture">The target texture to invoke the pixel shader upon.</param>
/// <param name="shader">The input <typeparamref name="T"/> instance representing the pixel shader to run.</param>
internal readonly unsafe void Run<T, TPixel>(IReadWriteNormalizedTexture2D<TPixel> texture, ref T shader)
where T : struct, IComputeShader<TPixel>
where T : struct, IComputeShader<TPixel>, IComputeShaderDescriptor<T>
where TPixel : unmanaged
{
default(InvalidOperationException).ThrowIf(this.device is null);
@@ -212,11 +211,11 @@ public struct ComputeContext : IDisposable, IAsyncDisposable
D3D12GraphicsCommandListConstantBufferLoader constantBufferLoader = new(commandList.D3D12GraphicsCommandList);
shader.LoadConstantBuffer(ref constantBufferLoader, x, y, 1);
shader.LoadConstantBuffer(in shader, ref constantBufferLoader, x, y, 1);
D3D12GraphicsCommandListGraphicsResourceLoader graphicsResourceLoader = new(commandList.D3D12GraphicsCommandList, this.device, rootParameterOffset: 2);
shader.LoadGraphicsResources(ref graphicsResourceLoader);
shader.LoadGraphicsResources(in shader, ref graphicsResourceLoader);
// Load the implicit output texture
commandList.D3D12GraphicsCommandList->SetComputeRootDescriptorTable(
+1 -1
ファイルの表示
@@ -1,7 +1,7 @@
using System;
using System.Runtime.CompilerServices;
using ComputeSharp.Descriptors;
using ComputeSharp.Graphics.Extensions;
using ComputeSharp.__Internals;
using TerraFX.Interop.DirectX;
namespace ComputeSharp.Shaders.Dispatching;
+2 -2
ファイルの表示
@@ -1,8 +1,8 @@
using System;
using System.Runtime.CompilerServices;
using ComputeSharp.__Internals;
using TerraFX.Interop.DirectX;
using ComputeSharp.Resources.Interop;
using ComputeSharp.Descriptors;
using TerraFX.Interop.DirectX;
namespace ComputeSharp.Shaders.Dispatching;
+6 -5
ファイルの表示
@@ -1,5 +1,6 @@
using System;
using System.Runtime.CompilerServices;
using ComputeSharp.Descriptors;
using ComputeSharp.Graphics.Helpers;
using ComputeSharp.Interop;
using ComputeSharp.Resources.Interop;
@@ -484,7 +485,7 @@ public static class ComputeContextExtensions
/// <param name="x">The number of iterations to run on the X axis.</param>
/// <param name="shader">The input <typeparamref name="T"/> instance representing the compute shader to run.</param>
public static void For<T>(this in ComputeContext context, int x, in T shader)
where T : struct, IComputeShader
where T : struct, IComputeShader, IComputeShaderDescriptor<T>
{
context.Run(x, ref Unsafe.AsRef(in shader));
}
@@ -498,7 +499,7 @@ public static class ComputeContextExtensions
/// <param name="y">The number of iterations to run on the Y axis.</param>
/// <param name="shader">The input <typeparamref name="T"/> instance representing the compute shader to run.</param>
public static void For<T>(this in ComputeContext context, int x, int y, in T shader)
where T : struct, IComputeShader
where T : struct, IComputeShader, IComputeShaderDescriptor<T>
{
context.Run(x, y, ref Unsafe.AsRef(in shader));
}
@@ -513,7 +514,7 @@ public static class ComputeContextExtensions
/// <param name="z">The number of iterations to run on the Z axis.</param>
/// <param name="shader">The input <typeparamref name="T"/> instance representing the compute shader to run.</param>
public static void For<T>(this in ComputeContext context, int x, int y, int z, in T shader)
where T : struct, IComputeShader
where T : struct, IComputeShader, IComputeShaderDescriptor<T>
{
context.Run(x, y, z, ref Unsafe.AsRef(in shader));
}
@@ -526,7 +527,7 @@ public static class ComputeContextExtensions
/// <param name="context">The <see cref="ComputeContext"/> to use to run the shader.</param>
/// <param name="texture">The target texture to apply the pixel shader to.</param>
public static void ForEach<T, TPixel>(this in ComputeContext context, IReadWriteNormalizedTexture2D<TPixel> texture)
where T : struct, IComputeShader<TPixel>
where T : struct, IComputeShader<TPixel>, IComputeShaderDescriptor<T>
where TPixel : unmanaged
{
default(ArgumentNullException).ThrowIfNull(texture);
@@ -543,7 +544,7 @@ public static class ComputeContextExtensions
/// <param name="texture">The target texture to apply the pixel shader to.</param>
/// <param name="shader">The input <typeparamref name="T"/> instance representing the pixel shader to run.</param>
public static void ForEach<T, TPixel>(this in ComputeContext context, IReadWriteNormalizedTexture2D<TPixel> texture, in T shader)
where T : struct, IComputeShader<TPixel>
where T : struct, IComputeShader<TPixel>, IComputeShaderDescriptor<T>
where TPixel : unmanaged
{
default(ArgumentNullException).ThrowIfNull(texture);
+2 -4
ファイルの表示
@@ -2,14 +2,12 @@ using System;
using System.Buffers;
using System.Runtime.CompilerServices;
using ComputeSharp.Shaders.Extensions;
using ComputeSharp.Descriptors;
using ComputeSharp.Interop;
using ComputeSharp.__Internals;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
using static TerraFX.Interop.DirectX.D3D12_DESCRIPTOR_RANGE_FLAGS;
#pragma warning disable CS0618
namespace ComputeSharp.Shaders.Loading;
/// <summary>
@@ -17,7 +15,7 @@ namespace ComputeSharp.Shaders.Loading;
/// </summary>
/// <typeparam name="T">The type of compute shader to load.</typeparam>
internal static unsafe class PipelineDataLoader<T>
where T : struct, IShader
where T : struct, IComputeShaderDescriptor<T>
{
/// <summary>
/// The map of cached <see cref="PipelineData"/> instances for each GPU in use.