Add D2D1InteropServices.GetPixelShaderInputType API

このコミットが含まれているのは:
Sergio Pedri committed 2022-05-06 19:34:31 +02:00
1 親 6455678056
コミット e7c4288adf
6ファイル変更
+45 -12

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

@@ -24,12 +24,12 @@ partial class ID2D1ShaderGenerator
{
// This code produces a method declaration as follows:
//
// readonly uint global::ComputeSharp.D2D1.__Internals.ID2D1Shader.GetInputCount()
// readonly byte global::ComputeSharp.D2D1.__Internals.ID2D1Shader.GetInputCount()
// {
// return <INPUT_COUNT>;
// }
return
MethodDeclaration(PredefinedType(Token(SyntaxKind.UIntKeyword)), Identifier("GetInputCount"))
MethodDeclaration(PredefinedType(Token(SyntaxKind.ByteKeyword)), Identifier("GetInputCount"))
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.D2D1.__Internals.{nameof(ID2D1Shader)}")))
.AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
.WithBody(Block(ReturnStatement(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(inputCount)))));
@@ -23,15 +23,15 @@ partial class ID2D1ShaderGenerator
{
// This code produces a method declaration as follows:
//
// readonly uint global::ComputeSharp.D2D1.__Internals.ID2D1Shader.GetInputType(uint index)
// readonly byte global::ComputeSharp.D2D1.__Internals.ID2D1Shader.GetInputType(byte index)
// {
// return <INPUT_TYPE>;
// }
return
MethodDeclaration(PredefinedType(Token(SyntaxKind.UIntKeyword)), Identifier("GetInputType"))
MethodDeclaration(PredefinedType(Token(SyntaxKind.ByteKeyword)), Identifier("GetInputType"))
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.D2D1.__Internals.{nameof(ID2D1Shader)}")))
.AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
.AddParameterListParameters(Parameter(Identifier("index")).WithType(PredefinedType(Token(SyntaxKind.UIntKeyword))))
.AddParameterListParameters(Parameter(Identifier("index")).WithType(PredefinedType(Token(SyntaxKind.ByteKeyword))))
.WithBody(Block(ReturnStatement(GetInputTypesSwitchExpression(inputTypes))));
}
@@ -54,18 +54,18 @@ partial class ID2D1ShaderGenerator
{
// Add a switch branch to map a given input to its serialized type, as follows:
//
// 0u => 1u
// 0 => 1
switches.Add(
SwitchExpressionArm(
ConstantPattern(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal((uint)i))),
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(inputTypes[i]))));
ConstantPattern(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(i))),
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal((int)inputTypes[i]))));
}
// Add a default arm
switches.Add(
SwitchExpressionArm(
DiscardPattern(),
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0u))));
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0))));
// Build a switch expression as follows:
//
+12
ファイルの表示
@@ -45,6 +45,18 @@ internal static partial class ThrowHelper
throw new ArgumentOutOfRangeException(name);
}
/// <summary>
/// Throws a new <see cref="ArgumentOutOfRangeException"/>.
/// </summary>
/// <param name="name">The argument name.</param>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="ArgumentOutOfRangeException">Thrown with the specified parameter.</exception>
[DoesNotReturn]
public static void ThrowArgumentOutOfRangeException(string? name, string? message)
{
throw new ArgumentOutOfRangeException(name, message);
}
/// <summary>
/// Throws a new <see cref="InvalidOperationException"/>.
/// </summary>
+2 -2
ファイルの表示
@@ -25,7 +25,7 @@ public interface ID2D1Shader
/// <returns>The number of inputs for the current shader.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be used directly by user code")]
uint GetInputCount();
byte GetInputCount();
/// <summary>
/// Gets the input type for the input at the input index.
@@ -35,7 +35,7 @@ public interface ID2D1Shader
/// <remarks>The return value if the input is out of range is undefined.</remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be used directly by user code")]
uint GetInputType(uint index);
byte GetInputType(byte index);
/// <summary>
/// Loads the dispatch data for the shader.
+21
ファイルの表示
@@ -1,5 +1,6 @@
using System;
using System.Runtime.CompilerServices;
using ComputeSharp.D2D1.Helpers;
using ComputeSharp.D2D1.Shaders.Dispatching;
using ComputeSharp.D2D1.Shaders.Interop.Buffers;
using TerraFX.Interop.DirectX;
@@ -92,6 +93,26 @@ public static unsafe class D2D1InteropServices
return shader.GetInputCount();
}
/// <summary>
/// Gets the type of a given input for a D2D1 pixel shader.
/// </summary>
/// <typeparam name="T">The type of D2D1 pixel shader to get the input type for.</typeparam>
/// <param name="index">The index of the input to get the type for.</param>
/// <returns>The type of the input of the target D2D1 pixel shader at the specified index.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="index"/> is not in range for the available inputs for the shader type.</exception>
public static D2D1PixelShaderInputType GetPixelShaderInputType<T>(uint index)
where T : unmanaged, ID2D1PixelShader
{
Unsafe.SkipInit(out T shader);
if (index >= shader.GetInputCount())
{
ThrowHelper.ThrowArgumentOutOfRangeException(nameof(index), "The input index is outside of range for the target pixel shader type.");
}
return (D2D1PixelShaderInputType)shader.GetInputType((byte)index);
}
/// <summary>
/// Gets the constant buffer from an input D2D1 pixel shader.
/// </summary>
+1 -1
ファイルの表示
@@ -3,7 +3,7 @@
/// <summary>
/// Indicates the type of a given input for a D2D1 pixel shader.
/// </summary>
public enum D2D1PixelShaderInputType
public enum D2D1PixelShaderInputType : byte
{
/// <summary>
/// The input is of simple type.