Switch ID2D1Shader.InputCount to a property
このコミットが含まれているのは:
1 親
0780345ef9
コミット
32ceaf3def
4ファイル変更
+17
-20
検索条件に一致するファイルはありません
+10
-12
@@ -11,28 +11,26 @@ namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
partial class ID2D1ShaderGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper with all logic to generate the <c>GetInputCount</c> method.
|
||||
/// A helper with all logic to generate the <c>InputCount</c> property.
|
||||
/// </summary>
|
||||
private static partial class GetInputCount
|
||||
private static partial class InputCount
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a <see cref="MethodDeclarationSyntax"/> instance for the <c>GetInputCount</c> method.
|
||||
/// Creates a <see cref="MethodDeclarationSyntax"/> instance for the <c>InputCount</c> property.
|
||||
/// </summary>
|
||||
/// <param name="inputCount">The number of inputs for the shader.</param>
|
||||
/// <returns>The resulting <see cref="MethodDeclarationSyntax"/> instance for the <c>GetInputCount</c> method.</returns>
|
||||
public static MethodDeclarationSyntax GetSyntax(int inputCount)
|
||||
/// <returns>The resulting <see cref="MethodDeclarationSyntax"/> instance for the <c>InputCount</c> property.</returns>
|
||||
public static PropertyDeclarationSyntax GetSyntax(int inputCount)
|
||||
{
|
||||
// This code produces a method declaration as follows:
|
||||
// This code produces a property declaration as follows:
|
||||
//
|
||||
// readonly uint global::ComputeSharp.D2D1.__Internals.ID2D1Shader.GetInputCount()
|
||||
// {
|
||||
// return <INPUT_COUNT>;
|
||||
// }
|
||||
// readonly int global::ComputeSharp.D2D1.__Internals.ID2D1Shader.InputCount => <INPUT_COUNT>;
|
||||
return
|
||||
MethodDeclaration(PredefinedType(Token(SyntaxKind.UIntKeyword)), Identifier(nameof(GetInputCount)))
|
||||
PropertyDeclaration(PredefinedType(Token(SyntaxKind.IntKeyword)), Identifier(nameof(InputCount)))
|
||||
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.D2D1.__Internals.{nameof(ID2D1Shader)}")))
|
||||
.AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
|
||||
.WithBody(Block(ReturnStatement(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(inputCount)))));
|
||||
.WithExpressionBody(ArrowExpressionClause(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(inputCount))))
|
||||
.WithSemicolonToken(Token(SyntaxKind.SemicolonToken));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -243,18 +243,18 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
|
||||
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.EffectAuthor.g.cs", compilationUnit.GetText(Encoding.UTF8));
|
||||
});
|
||||
|
||||
// Get the GetInputCount() info (hierarchy and input count)
|
||||
// Get the InputCount info (hierarchy and input count)
|
||||
IncrementalValuesProvider<(HierarchyInfo Hierarchy, int InputCount)> inputCountInfo =
|
||||
shaderInfoWithErrors
|
||||
.Select(static (item, _) => (item.Hierarchy, item.InputTypes.InputTypes.Length));
|
||||
|
||||
// Generate the GetInputCount() methods
|
||||
// Generate the InputCount properties
|
||||
context.RegisterSourceOutput(inputCountInfo, static (context, item) =>
|
||||
{
|
||||
MethodDeclarationSyntax getInputCountMethod = GetInputCount.GetSyntax(item.InputCount);
|
||||
CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMember(item.Hierarchy, getInputCountMethod, canUseSkipLocalsInit: false);
|
||||
PropertyDeclarationSyntax inputCountProperty = InputCount.GetSyntax(item.InputCount);
|
||||
CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMember(item.Hierarchy, inputCountProperty, canUseSkipLocalsInit: false);
|
||||
|
||||
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{nameof(GetInputCount)}.g.cs", compilationUnit.GetText(Encoding.UTF8));
|
||||
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{nameof(InputCount)}.g.cs", compilationUnit.GetText(Encoding.UTF8));
|
||||
});
|
||||
|
||||
// Get the InputTypes info (hierarchy and input types)
|
||||
|
||||
@@ -71,10 +71,9 @@ public interface ID2D1Shader
|
||||
/// <summary>
|
||||
/// Gets the number of inputs for the current shader.
|
||||
/// </summary>
|
||||
/// <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();
|
||||
int InputCount { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the input types for the current shader.
|
||||
|
||||
@@ -255,7 +255,7 @@ public static class D2D1PixelShader
|
||||
{
|
||||
Unsafe.SkipInit(out T shader);
|
||||
|
||||
return (int)shader.GetInputCount();
|
||||
return shader.InputCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする