Add DispatchAxis type and new [EmbeddedBytecode] attribute
このコミットが含まれているのは:
1 親
658c9f527d
コミット
74793ab9f0
3ファイル変更
+109
-2
検索条件に一致するファイルはありません
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<PackSymbols>false</PackSymbols>
|
||||
<Description>ComputeSharp.SourceGenerators</Description>
|
||||
<NoWarn>$(NoWarn);CS1591;CS0649</NoWarn>
|
||||
<NoWarn>$(NoWarn);CS1591;CS0649;CS1574</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
@@ -20,6 +20,7 @@
|
||||
<Compile Include="..\ComputeSharp\Core\Attributes\GroupSharedAttribute.cs" Link="ComputeSharp\Core\Attributes\GroupSharedAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Dynamic\Attributes\ShaderMethodAttribute.cs" Link="ComputeSharp\Core\Attributes\ShaderMethodAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Dynamic\Attributes\__Internals\ShaderMethodSourceAttribute.cs" Link="ComputeSharp\Core\Attributes\__Internals\ShaderMethodSourceAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Dispatch\DispatchAxis.cs" Link="ComputeSharp\Core\Dispatch\DispatchAxis.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Dispatch\DispatchSize.cs" Link="ComputeSharp\Core\Dispatch\DispatchSize.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Dispatch\GridIds.cs" Link="ComputeSharp\Core\Dispatch\GridIds.cs" />
|
||||
<Compile Include="..\ComputeSharp\Core\Dispatch\GroupIds.cs" Link="ComputeSharp\Core\Dispatch\GroupIds.cs" />
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using System;
|
||||
#if !SOURCE_GENERATOR
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
#endif
|
||||
|
||||
namespace ComputeSharp;
|
||||
|
||||
@@ -8,11 +11,24 @@ namespace ComputeSharp;
|
||||
/// <para>
|
||||
/// This attribute can be used to annotate shader types as follows:
|
||||
/// <code>
|
||||
/// [EmbeddedBytecode(8, 8, 1)]
|
||||
/// // A compute shader that is dispatched on a target buffer
|
||||
/// [EmbeddedBytecode(DispatchAxis.X)]
|
||||
/// struct MyShader : IComputeShader
|
||||
/// {
|
||||
/// }
|
||||
/// </code>
|
||||
/// Or similarly, for a pixel shader:
|
||||
/// <code>
|
||||
/// // A pixel shader that is dispatched on a target texture
|
||||
/// [EmbeddedBytecode(DispatchAxis.XY)]
|
||||
/// struct MyShader : IPixelShader<float4>
|
||||
/// {
|
||||
/// }
|
||||
/// </code>
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Using <see cref="DispatchAxis"/> is an easier way to precompile shaders when dispatching them over known dimensions. For more
|
||||
/// fine grained control over the thread size values when dispatching, use <see cref="EmbeddedBytecodeAttribute(int, int, int)"/>.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// </para>
|
||||
@@ -32,6 +48,27 @@ namespace ComputeSharp;
|
||||
[AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)]
|
||||
public sealed class EmbeddedBytecodeAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="EmbeddedBytecodeAttribute"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="dispatchAxis">The target dispatch axes for the shader to run.</param>
|
||||
public EmbeddedBytecodeAttribute(DispatchAxis dispatchAxis)
|
||||
{
|
||||
#if !SOURCE_GENERATOR
|
||||
(ThreadsX, ThreadsY, ThreadsZ) = dispatchAxis switch
|
||||
{
|
||||
DispatchAxis.X => (64, 1, 1),
|
||||
DispatchAxis.Y => (1, 64, 1),
|
||||
DispatchAxis.Z => (1, 1, 64),
|
||||
DispatchAxis.XY => (8, 8, 1),
|
||||
DispatchAxis.XZ => (8, 1, 8),
|
||||
DispatchAxis.YZ => (1, 8, 8),
|
||||
DispatchAxis.XYZ => (4, 4, 4),
|
||||
_ => ThrowHelper.ThrowArgumentException<(int, int, int)>(nameof(dispatchAxis), "Invalid dispatch axis value.")
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="EmbeddedBytecodeAttribute"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="enum"/> to be used with <see cref="EmbeddedBytecodeAttribute"/> to indicate the dispatch
|
||||
/// </summary>
|
||||
public enum DispatchAxis
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates a shader dispatch only along the X axis.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This applies to using <see cref="GraphicsDeviceExtensions.For{T}(GraphicsDevice, int, in T)"/> or <see cref="ComputeContextExtensions.For{T}(in ComputeContext, int, in T)"/>.
|
||||
/// </remarks>
|
||||
X,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates a shader dispatch only along the Y axis.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This applies to using <see cref="GraphicsDeviceExtensions.For{T}(GraphicsDevice, int, int, int, in T)"/> or <see cref="ComputeContextExtensions.For{T}(in ComputeContext, int, int, int, in T)"/>,
|
||||
/// but only as long as the input dispatch size on both the X and Z axes is <c>1</c>. Using any other combination will not be able to leverage the precompiled shader bytecode.
|
||||
/// </remarks>
|
||||
Y,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates a shader dispatch only along the Z axis.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This applies to using <see cref="GraphicsDeviceExtensions.For{T}(GraphicsDevice, int, int, int, in T)"/> or <see cref="ComputeContextExtensions.For{T}(in ComputeContext, int, int, int, in T)"/>,
|
||||
/// but only as long as the input dispatch size on both the X and Y axes is <c>1</c>. Using any other combination will not be able to leverage the precompiled shader bytecode.
|
||||
/// </remarks>
|
||||
Z,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates a shader dispatch along the X and Y axes.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This applies to using <see cref="GraphicsDeviceExtensions.For{T}(GraphicsDevice, int, int, in T)"/>, <see cref="GraphicsDeviceExtensions.ForEach{T, TPixel}(GraphicsDevice, IReadWriteTexture2D{TPixel})"/>,
|
||||
/// <see cref="GraphicsDeviceExtensions.ForEach{T, TPixel}(GraphicsDevice, IReadWriteTexture2D{TPixel}, in T)"/>, <see cref="ComputeContextExtensions.For{T}(in ComputeContext, int, int, in T)"/>,
|
||||
/// <see cref="ComputeContextExtensions.ForEach{T, TPixel}(in ComputeContext, IReadWriteTexture2D{TPixel})"/> or <see cref="ComputeContextExtensions.ForEach{T, TPixel}(in ComputeContext, IReadWriteTexture2D{TPixel}, in T)"/>.
|
||||
/// </remarks>
|
||||
XY,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates a shader dispatch along the X and Z axes.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This applies to using <see cref="GraphicsDeviceExtensions.For{T}(GraphicsDevice, int, int, int, in T)"/> or <see cref="ComputeContextExtensions.For{T}(in ComputeContext, int, int, int, in T)"/>,
|
||||
/// but only as long as the input dispatch size on the Y axis <c>1</c>. Using any other combination will not be able to leverage the precompiled shader bytecode.
|
||||
/// </remarks>
|
||||
XZ,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates a shader dispatch along the Y and Z axes.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This applies to using <see cref="GraphicsDeviceExtensions.For{T}(GraphicsDevice, int, int, int, in T)"/> or <see cref="ComputeContextExtensions.For{T}(in ComputeContext, int, int, int, in T)"/>,
|
||||
/// but only as long as the input dispatch size on the X axis <c>1</c>. Using any other combination will not be able to leverage the precompiled shader bytecode.
|
||||
/// </remarks>
|
||||
YZ,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates a shader dispatch along the X, Y and Z axes.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This applies to using <see cref="GraphicsDeviceExtensions.For{T}(GraphicsDevice, int, int, int, in T)"/> or <see cref="ComputeContextExtensions.For{T}(in ComputeContext, int, int, int, in T)"/>.
|
||||
/// </remarks>
|
||||
XYZ
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする