Add D2DEmbeddedBytecodeAttribute types

このコミットが含まれているのは:
Sergio Pedri committed 2022-04-24 21:03:45 +02:00
1 親 942d5bd3c5
コミット 5cca651dd5
6ファイル変更
+134 -4

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

+48
ファイルの表示
@@ -0,0 +1,48 @@
using System;
using ComputeSharp.D2D1Interop.Helpers;
namespace ComputeSharp.D2D1Interop;
/// <summary>
/// An attribute that indicates that a given D2D1 shader should be precompiled at build time and embedded
/// directly into the containing assembly as static bytecode, to avoid compiling it at runtime.
/// <para>
/// This attribute can be used to annotate shader types as follows:
/// <code>
/// // A compute shader that is dispatched on a target buffer
/// [D2DEmbeddedBytecode(D2D1ShaderProfile.PixelShader50)]
/// struct MyShader : ID2D1PixelShader
/// {
/// }
/// </code>
/// </para>
/// <para>
/// </para>
/// The runtime compilation will automatically be skipped if the shader bytecode is then retrieved using a matching profile,
/// otherwise the usual runtime compilation will be used as fallback (or an exception will be thrown, depending on the API).
/// </summary>
[AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)]
public sealed class D2DEmbeddedBytecodeAttribute : Attribute
{
/// <summary>
/// Creates a new <see cref="D2DEmbeddedBytecodeAttribute"/> instance with the specified parameters.
/// </summary>
/// <param name="shaderProfile">The target shader profile to use to compile the shader.</param>
public D2DEmbeddedBytecodeAttribute(D2D1ShaderProfile shaderProfile)
{
ShaderProfile = shaderProfile switch
{
D2D1ShaderProfile.PixelShader40 or
D2D1ShaderProfile.PixelShader40Level91 or
D2D1ShaderProfile.PixelShader40Level93 or
D2D1ShaderProfile.PixelShader41 or
D2D1ShaderProfile.PixelShader50 => shaderProfile,
_ => ThrowHelper.ThrowArgumentException<D2D1ShaderProfile>(nameof(shaderProfile), "Invalid shader profile value.")
};
}
/// <summary>
/// Gets the number of threads in each thread group for the X axis
/// </summary>
public D2D1ShaderProfile ShaderProfile { get; }
}
+69
ファイルの表示
@@ -0,0 +1,69 @@
namespace ComputeSharp.D2D1Interop;
/// <summary>
/// A <see langword="enum"/> to be used with <see cref="D2DEmbeddedBytecodeAttribute"/> to indicate the shader profile to use to precompile a shader.
/// </summary>
public enum D2D1ShaderProfile
{
/// <summary>
/// Indicates a D2D1 pixel shader compiled for Direct3D 9.1 feature level.
/// <para>
/// This has the following features:
/// <list type="bullet">
/// <item>64 arithmetic and 32 texture instructions.</item>
/// <item>12 temporary registers.</item>
/// <item>4 levels of dependent reads.</item>
/// </list>
/// </para>
/// </summary>
/// <remarks>
/// For more info, see <see href="https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/specifying-compiler-targets"/>.
/// </remarks>
PixelShader40Level91,
/// <summary>
/// Indicates a D2D1 pixel shader compiled for Direct3D 9.3 feature level.
/// <para>
/// This has the following features:
/// <list type="bullet">
/// <item>512 instructions.</item>
/// <item>32 temporary registers.</item>
/// <item>Static flow control (max depth of 4).</item>
/// <item>Dynamic flow control (max depth of 24).</item>
/// <item><c>D3DPS20CAPS_ARBITRARYSWIZZLE</c>.</item>
/// <item><c>D3DPS20CAPS_GRADIENTINSTRUCTIONS</c>.</item>
/// <item><c>D3DPS20CAPS_PREDICATION</c>.</item>
/// <item><c>D3DPS20CAPS_NODEPENDENTREADLIMIT</c>.</item>
/// <item><c>D3DPS20CAPS_NOTEXINSTRUCTIONLIMIT</c>.</item>
/// </list>
/// </para>
/// </summary>
/// <remarks>
/// For more info, see <see href="https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/specifying-compiler-targets"/>.
/// </remarks>
PixelShader40Level93,
/// <summary>
/// Indicates a D2D1 pixel shader compiled for Direct3D 10.0 feature level.
/// </summary>
/// <remarks>
/// For more info, see <see href="https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/specifying-compiler-targets"/>.
/// </remarks>
PixelShader40,
/// <summary>
/// Indicates a D2D1 pixel shader compiled for Direct3D 10.1 feature level.
/// </summary>
/// <remarks>
/// For more info, see <see href="https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/specifying-compiler-targets"/>.
/// </remarks>
PixelShader41,
/// <summary>
/// Indicates a D2D1 pixel shader compiled for Direct3D 11.0 and 11.1 feature levels.
/// </summary>
/// <remarks>
/// For more info, see <see href="https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/specifying-compiler-targets"/>.
/// </remarks>
PixelShader50
}
+14
ファイルの表示
@@ -8,6 +8,20 @@ namespace ComputeSharp.D2D1Interop.Helpers;
/// </summary>
internal static partial class ThrowHelper
{
/// <summary>
/// Throws a new <see cref="ArgumentException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="name">The argument name.</param>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="ArgumentException">Thrown with the specified parameters.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowArgumentException<T>(string? name, string? message)
{
throw new ArgumentException(message, name);
}
/// <summary>
/// Throws a new <see cref="ArgumentOutOfRangeException"/>.
/// </summary>
+1 -2
ファイルの表示
@@ -1,7 +1,6 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ComputeSharp.D2D1Interop;
using ComputeSharp.D2D1Interop.Extensions;
using ComputeSharp.Shaders.Dispatching;
using TerraFX.Interop.DirectX;
@@ -9,7 +8,7 @@ using TerraFX.Interop.Windows;
#pragma warning disable CS0618
namespace ComputeSharp.Interop;
namespace ComputeSharp.D2D1Interop.Interop;
/// <summary>
/// Provides methods to extract reflection info on D2D1 shaders generated using this library.
+1 -1
ファイルの表示
@@ -1,4 +1,4 @@
namespace ComputeSharp.Interop;
namespace ComputeSharp.D2D1Interop.Interop;
/// <summary>
/// A model representing reflection info for a given D2D1 shader.
+1 -1
ファイルの表示
@@ -1,7 +1,7 @@
namespace ComputeSharp;
/// <summary>
/// A <see langword="enum"/> to be used with <see cref="EmbeddedBytecodeAttribute"/> to indicate the dispatch
/// A <see langword="enum"/> to be used with <see cref="EmbeddedBytecodeAttribute"/> to indicate the dispatch axis to precompile a shader for.
/// </summary>
public enum DispatchAxis
{