Add ID2D1Shader.BufferPrecision property and generate it

このコミットが含まれているのは:
Sergio Pedri committed 2023-09-28 00:12:17 +02:00
1 親 d5c00e048a
コミット 81dd2e2b7e
3ファイル変更
+48

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

@@ -1,3 +1,4 @@
using System;
using ComputeSharp.D2D1.__Internals;
using ComputeSharp.D2D1.SourceGenerators.Models;
using Microsoft.CodeAnalysis.CSharp;
@@ -14,6 +15,41 @@ partial class ID2D1ShaderGenerator
/// <inheritdoc/>
partial class GetOutputBuffer
{
/// <summary>
/// Creates a <see cref="PropertyDeclarationSyntax"/> instance for the <c>BufferPrecision</c> property.
/// </summary>
/// <param name="info">The input info for the shader output buffer.</param>
/// <returns>The resulting <see cref="PropertyDeclarationSyntax"/> instance for the <c>BufferPrecision</c> property.</returns>
public static PropertyDeclarationSyntax GetBufferPrecisionSyntax(OutputBufferInfo info)
{
ExpressionSyntax bufferPrecisionExpression;
// Set the right expression if the buffer options are valid
if (Enum.IsDefined(typeof(D2D1BufferPrecision), info.BufferPrecision))
{
bufferPrecisionExpression =
MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
IdentifierName("ComputeSharp.D2D1.D2D1BufferPrecision"),
IdentifierName(info.BufferPrecision.ToString()));
}
else
{
// Otherwise just return default (the analyzer will emit a diagnostic)
bufferPrecisionExpression = LiteralExpression(SyntaxKind.DefaultLiteralExpression, Token(SyntaxKind.DefaultKeyword));
}
// This code produces a property declaration as follows:
//
// readonly ComputeSharp.D2D1.D2D1BufferPrecision global::ComputeSharp.D2D1.__Internals.ID2D1Shader.BufferPrecision => <BUFFER_PRECISION>;
return
PropertyDeclaration(IdentifierName("ComputeSharp.D2D1.D2D1BufferPrecision"), Identifier("BufferPrecision"))
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.D2D1.__Internals.{nameof(ID2D1Shader)}")))
.AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
.WithExpressionBody(ArrowExpressionClause(bufferPrecisionExpression))
.WithSemicolonToken(Token(SyntaxKind.SemicolonToken));
}
/// <summary>
/// Creates a <see cref="MethodDeclarationSyntax"/> instance for the <c>GetOutputBuffer</c> method.
/// </summary>
+5
ファイルの表示
@@ -398,6 +398,11 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMember(item.Hierarchy, getOutputBufferMethod, canUseSkipLocalsInit: false);
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{nameof(GetOutputBuffer)}.g.cs", compilationUnit.GetText(Encoding.UTF8));
PropertyDeclarationSyntax bufferPrecisionProperty = GetOutputBuffer.GetBufferPrecisionSyntax(item.OutputBuffer);
CompilationUnitSyntax bufferPrecisionCompilationUnit = GetCompilationUnitFromMember(item.Hierarchy, bufferPrecisionProperty, canUseSkipLocalsInit: false);
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.BufferPrecision.g.cs", bufferPrecisionCompilationUnit.GetText(Encoding.UTF8));
});
// Get the InputDescriptions info (hierarchy and input descriptions)
+7
ファイルの表示
@@ -97,6 +97,13 @@ public interface ID2D1Shader
[Obsolete("This method is not intended to be used directly by user code")]
ReadOnlyMemory<D2D1ResourceTextureDescription> ResourceTextureDescriptions { get; }
/// <summary>
/// Gets the buffer precision for the shader.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be used directly by user code")]
D2D1BufferPrecision BufferPrecision { get; }
/// <summary>
/// Gets the output buffer precision and depth for the shader.
/// </summary>