Enable generation for ID2D1Shader.GetPixelOptions API
このコミットが含まれているのは:
1 親
6fbdef8ce4
コミット
b211932881
3ファイル変更
+91
検索条件に一致するファイルはありません
+36
@@ -0,0 +1,36 @@
|
||||
using ComputeSharp.D2D1.__Internals;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
partial class GetPixelOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a <see cref="MethodDeclarationSyntax"/> instance for the <c>GetPixelOptions</c> method.
|
||||
/// </summary>
|
||||
/// <param name="pixelOptions">The pixel options for the shader.</param>
|
||||
/// <returns>The resulting <see cref="MethodDeclarationSyntax"/> instance for the <c>GetPixelOptions</c> method.</returns>
|
||||
public static MethodDeclarationSyntax GetSyntax(D2D1PixelOption pixelOptions)
|
||||
{
|
||||
// This code produces a method declaration as follows:
|
||||
//
|
||||
// readonly uint global::ComputeSharp.D2D1.__Internals.ID2D1Shader.GetPixelOptions()
|
||||
// {
|
||||
// return <PIXEL_OPTIONS>;
|
||||
// }
|
||||
return
|
||||
MethodDeclaration(PredefinedType(Token(SyntaxKind.UIntKeyword)), Identifier(nameof(GetPixelOptions)))
|
||||
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.D2D1.__Internals.{nameof(ID2D1Shader)}")))
|
||||
.AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
|
||||
.WithBody(Block(ReturnStatement(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal((int)pixelOptions)))));
|
||||
}
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
using ComputeSharp.SourceGeneration.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper with all logic to generate the <c>GetPixelOptions</c> method.
|
||||
/// </summary>
|
||||
private static partial class GetPixelOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Extracts the pixel options for the current shader.
|
||||
/// </summary>
|
||||
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
|
||||
/// <param name="pixelOptions">The pixel options for the shader.</param>
|
||||
public static void GetInfo(INamedTypeSymbol structDeclarationSymbol, out D2D1PixelOption pixelOptions)
|
||||
{
|
||||
if (structDeclarationSymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DPixelOptionsAttribute", out AttributeData? attributeData))
|
||||
{
|
||||
pixelOptions = (D2D1PixelOption)attributeData!.ConstructorArguments[0].Value!;
|
||||
}
|
||||
else
|
||||
{
|
||||
pixelOptions = D2D1PixelOption.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -305,5 +305,29 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
|
||||
|
||||
context.AddSource($"{item.Left.Hierarchy.FilenameHint}.{nameof(LoadInputDescriptions)}", compilationUnit.ToFullString());
|
||||
});
|
||||
|
||||
// Get the pixel options, again independently from other generation steps.
|
||||
// This can also be immediately cached at a fine grained level.
|
||||
IncrementalValuesProvider<(HierarchyInfo Hierarchy, D2D1PixelOption Options)> pixelOptionsInfo =
|
||||
shaderDeclarations
|
||||
.Select(static (item, token) =>
|
||||
{
|
||||
// GetPixelOptions() info
|
||||
GetPixelOptions.GetInfo(item.Symbol, out D2D1PixelOption pixelOptions);
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
return (item.Hierarchy, pixelOptions);
|
||||
})
|
||||
.WithComparers(HierarchyInfo.Comparer.Default, EqualityComparer<D2D1PixelOption>.Default);
|
||||
|
||||
// Generate the GetPixelOptions() methods
|
||||
context.RegisterSourceOutput(pixelOptionsInfo, static (context, item) =>
|
||||
{
|
||||
MethodDeclarationSyntax getPixelOptionsMethod = GetPixelOptions.GetSyntax(item.Options);
|
||||
CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMethod(item.Hierarchy, getPixelOptionsMethod, false);
|
||||
|
||||
context.AddSource($"{item.Hierarchy.FilenameHint}.{nameof(GetPixelOptions)}", compilationUnit.ToFullString());
|
||||
});
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする