Merge pull request #573 from Sergio0694/dev/shader-interface-properties
Switch all D2D1 interface methods (except bytecode) to properties
このコミットが含まれているのは:
18ファイル変更
+253
-210
検索条件に一致するファイルはありません
-47
@@ -1,47 +0,0 @@
|
||||
using ComputeSharp.D2D1.__Internals;
|
||||
using ComputeSharp.SourceGeneration.Helpers;
|
||||
using Microsoft.CodeAnalysis;
|
||||
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 BuildHlslSource
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a <see cref="MethodDeclarationSyntax"/> instance for the <c>BuildHlslSource</c> method.
|
||||
/// </summary>
|
||||
/// <param name="hlslSource">The input HLSL source.</param>
|
||||
/// <param name="hierarchyDepth">The depth of the hierarchy for this type (used to calculate the right indentation).</param>
|
||||
/// <returns>The resulting <see cref="MethodDeclarationSyntax"/> instance for the <c>BuildHlslSource</c> method.</returns>
|
||||
public static MethodDeclarationSyntax GetSyntax(string hlslSource, int hierarchyDepth)
|
||||
{
|
||||
SyntaxToken hlslSourceLiteralExpression = SyntaxTokenHelper.CreateRawMultilineStringLiteral(hlslSource, hierarchyDepth);
|
||||
|
||||
// This code produces a method declaration as follows:
|
||||
//
|
||||
// readonly void global::ComputeSharp.D2D1.__Internals.ID2D1Shader.BuildHlslSource(out string hlslSource)
|
||||
// {
|
||||
// hlslSource = <HLSL_SOURCE>;
|
||||
// }
|
||||
return
|
||||
MethodDeclaration(PredefinedType(Token(SyntaxKind.VoidKeyword)), Identifier(nameof(BuildHlslSource)))
|
||||
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.D2D1.__Internals.{nameof(ID2D1Shader)}")))
|
||||
.AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
|
||||
.AddParameterListParameters(
|
||||
Parameter(Identifier("hlslSource")).AddModifiers(Token(SyntaxKind.OutKeyword)).WithType(PredefinedType(Token(SyntaxKind.StringKeyword))))
|
||||
.WithBody(Block(ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
IdentifierName("hlslSource"),
|
||||
LiteralExpression(SyntaxKind.StringLiteralExpression, hlslSourceLiteralExpression)))));
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -79,7 +79,7 @@ partial class ID2D1ShaderGenerator
|
||||
.AddArgumentListArguments(Argument(IdentifierName("bytes"))))
|
||||
.WithRefOrOutKeyword(Token(SyntaxKind.RefKeyword)))));
|
||||
|
||||
// This code produces a method declaration as follows:
|
||||
// This code produces a property declaration as follows:
|
||||
//
|
||||
// readonly ref readonly global::System.Guid global::ComputeSharp.D2D1.__Internals.ID2D1Shader.EffectId
|
||||
// {
|
||||
|
||||
-51
@@ -1,51 +0,0 @@
|
||||
using ComputeSharp.D2D1.__Internals;
|
||||
using ComputeSharp.D2D1.SourceGenerators.Models;
|
||||
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 GetOutputBuffer
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a <see cref="MethodDeclarationSyntax"/> instance for the <c>GetOutputBuffer</c> method.
|
||||
/// </summary>
|
||||
/// <param name="info">The input info for the shader output buffer.</param>
|
||||
/// <returns>The resulting <see cref="MethodDeclarationSyntax"/> instance for the <c>GetOutputBuffer</c> method.</returns>
|
||||
public static MethodDeclarationSyntax GetSyntax(OutputBufferInfo info)
|
||||
{
|
||||
// This code produces a method declaration as follows:
|
||||
//
|
||||
// readonly void global::ComputeSharp.D2D1.__Internals.ID2D1Shader.GetOutputBuffer(out uint precision, out uint depth)
|
||||
// {
|
||||
// precision = <BUFFER_PRECISION>;
|
||||
// depth = <CHANNEL_DEPTH>;
|
||||
// }
|
||||
return
|
||||
MethodDeclaration(PredefinedType(Token(SyntaxKind.VoidKeyword)), Identifier(nameof(GetOutputBuffer)))
|
||||
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.D2D1.__Internals.{nameof(ID2D1Shader)}")))
|
||||
.AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
|
||||
.AddParameterListParameters(
|
||||
Parameter(Identifier("precision")).AddModifiers(Token(SyntaxKind.OutKeyword)).WithType(PredefinedType(Token(SyntaxKind.UIntKeyword))),
|
||||
Parameter(Identifier("depth")).AddModifiers(Token(SyntaxKind.OutKeyword)).WithType(PredefinedType(Token(SyntaxKind.UIntKeyword))))
|
||||
.WithBody(Block(
|
||||
ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
IdentifierName("precision"),
|
||||
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal((int)info.BufferPrecision)))),
|
||||
ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
IdentifierName("depth"),
|
||||
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal((int)info.ChannelDepth))))));
|
||||
}
|
||||
}
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
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(D2D1PixelOptions 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)))));
|
||||
}
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
using ComputeSharp.D2D1.__Internals;
|
||||
using ComputeSharp.SourceGeneration.Helpers;
|
||||
using Microsoft.CodeAnalysis;
|
||||
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 HlslSource
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a <see cref="PropertyDeclarationSyntax"/> instance for the <c>HlslSource</c> property.
|
||||
/// </summary>
|
||||
/// <param name="hlslSource">The input HLSL source.</param>
|
||||
/// <param name="hierarchyDepth">The depth of the hierarchy for this type (used to calculate the right indentation).</param>
|
||||
/// <returns>The resulting <see cref="PropertyDeclarationSyntax"/> instance for the <c>HlslSource</c> property.</returns>
|
||||
public static PropertyDeclarationSyntax GetSyntax(string hlslSource, int hierarchyDepth)
|
||||
{
|
||||
// The indentation level is the current depth + 1 (for the property)
|
||||
SyntaxToken hlslSourceLiteralExpression = SyntaxTokenHelper.CreateRawMultilineStringLiteral(hlslSource, hierarchyDepth + 1);
|
||||
|
||||
// This code produces a property declaration as follows:
|
||||
//
|
||||
// readonly string global::ComputeSharp.D2D1.__Internals.ID2D1Shader.HlslSource => <HLSL_SOURCE>;
|
||||
return
|
||||
PropertyDeclaration(PredefinedType(Token(SyntaxKind.StringKeyword)), Identifier("HlslSource"))
|
||||
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.D2D1.__Internals.{nameof(ID2D1Shader)}")))
|
||||
.AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
|
||||
.WithExpressionBody(ArrowExpressionClause(LiteralExpression(SyntaxKind.StringLiteralExpression, hlslSourceLiteralExpression)))
|
||||
.WithSemicolonToken(Token(SyntaxKind.SemicolonToken));
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-4
@@ -14,17 +14,15 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors;
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper with all logic to generate the <c>BuildHlslSource</c> method.
|
||||
/// A helper with all logic to generate the <c>HlslSource</c> property.
|
||||
/// </summary>
|
||||
private static partial class BuildHlslSource
|
||||
private static partial class HlslSource
|
||||
{
|
||||
/// <summary>
|
||||
/// Gathers all necessary information on a transpiled HLSL source for a given shader type.
|
||||
+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));
|
||||
}
|
||||
}
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using ComputeSharp.D2D1.__Internals;
|
||||
using ComputeSharp.D2D1.SourceGenerators.Models;
|
||||
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 OutputBuffer
|
||||
{
|
||||
/// <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="PropertyDeclarationSyntax"/> instance for the <c>ChannelDepth</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>ChannelDepth</c> property.</returns>
|
||||
public static PropertyDeclarationSyntax GetChannelDepthSyntax(OutputBufferInfo info)
|
||||
{
|
||||
ExpressionSyntax channelDepthExpression;
|
||||
|
||||
// Set the right expression if the buffer options are valid
|
||||
if (Enum.IsDefined(typeof(D2D1ChannelDepth), info.ChannelDepth))
|
||||
{
|
||||
channelDepthExpression =
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName("ComputeSharp.D2D1.D2D1ChannelDepth"),
|
||||
IdentifierName(info.ChannelDepth.ToString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise just return default (the analyzer will emit a diagnostic)
|
||||
channelDepthExpression = LiteralExpression(SyntaxKind.DefaultLiteralExpression, Token(SyntaxKind.DefaultKeyword));
|
||||
}
|
||||
|
||||
// This code produces a property declaration as follows:
|
||||
//
|
||||
// readonly ComputeSharp.D2D1.D2D1ChannelDepth global::ComputeSharp.D2D1.__Internals.ID2D1Shader.ChannelDepth => <CHANNEL_DEPTH>;
|
||||
return
|
||||
PropertyDeclaration(IdentifierName("ComputeSharp.D2D1.D2D1ChannelDepth"), Identifier("ChannelDepth"))
|
||||
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.D2D1.__Internals.{nameof(ID2D1Shader)}")))
|
||||
.AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
|
||||
.WithExpressionBody(ArrowExpressionClause(channelDepthExpression))
|
||||
.WithSemicolonToken(Token(SyntaxKind.SemicolonToken));
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -7,9 +7,9 @@ namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
partial class ID2D1ShaderGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper with all logic to generate the <c>GetOutputBuffer</c> method.
|
||||
/// A helper with all logic to generate the output buffer properties.
|
||||
/// </summary>
|
||||
private static partial class GetOutputBuffer
|
||||
private static partial class OutputBuffer
|
||||
{
|
||||
/// <summary>
|
||||
/// Extracts the output buffer info for the current shader.
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
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 PixelOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a <see cref="PropertyDeclarationSyntax"/> instance for the <c>PixelOptions</c> property.
|
||||
/// </summary>
|
||||
/// <param name="pixelOptions">The pixel options for the shader.</param>
|
||||
/// <returns>The resulting <see cref="MethodDeclarationSyntax"/> instance for the <c>PixelOptions</c> property.</returns>
|
||||
public static PropertyDeclarationSyntax GetSyntax(D2D1PixelOptions pixelOptions)
|
||||
{
|
||||
ExpressionSyntax pixelOptionsExpression;
|
||||
|
||||
// Set the right expression if the pixel options are valid
|
||||
if (pixelOptions is D2D1PixelOptions.None or D2D1PixelOptions.TrivialSampling)
|
||||
{
|
||||
pixelOptionsExpression =
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName("ComputeSharp.D2D1.D2D1PixelOptions"),
|
||||
IdentifierName(pixelOptions.ToString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise just return default (the analyzer will emit a diagnostic)
|
||||
pixelOptionsExpression = LiteralExpression(SyntaxKind.DefaultLiteralExpression, Token(SyntaxKind.DefaultKeyword));
|
||||
}
|
||||
|
||||
// This code produces a property declaration as follows:
|
||||
//
|
||||
// readonly ComputeSharp.D2D1.D2D1PixelOptions global::ComputeSharp.D2D1.__Internals.ID2D1Shader.PixelOptions => <PIXEL_OPTIONS>;
|
||||
return
|
||||
PropertyDeclaration(IdentifierName("ComputeSharp.D2D1.D2D1PixelOptions"), Identifier(nameof(PixelOptions)))
|
||||
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.D2D1.__Internals.{nameof(ID2D1Shader)}")))
|
||||
.AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
|
||||
.WithExpressionBody(ArrowExpressionClause(pixelOptionsExpression))
|
||||
.WithSemicolonToken(Token(SyntaxKind.SemicolonToken));
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -7,9 +7,9 @@ namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
partial class ID2D1ShaderGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper with all logic to generate the <c>GetPixelOptions</c> method.
|
||||
/// A helper with all logic to generate the <c>PixelOptions</c> property.
|
||||
/// </summary>
|
||||
private static partial class GetPixelOptions
|
||||
private static partial class PixelOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Extracts the pixel options for the current shader.
|
||||
@@ -107,8 +107,8 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
|
||||
inputCount,
|
||||
out ImmutableArray<ResourceTextureDescription> resourceTextureDescriptions);
|
||||
|
||||
// Get HLSL source for BuildHlslSource()
|
||||
string hlslSource = BuildHlslSource.GetHlslSource(
|
||||
// Get HLSL source for HlslSource
|
||||
string hlslSource = HlslSource.GetHlslSource(
|
||||
diagnostics,
|
||||
context.SemanticModel.Compilation,
|
||||
typeDeclaration,
|
||||
@@ -126,8 +126,8 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
// Get the info for GetOutputBuffer()
|
||||
GetOutputBuffer.GetInfo(typeSymbol, out D2D1BufferPrecision bufferPrecision, out D2D1ChannelDepth channelDepth);
|
||||
// Get the info for the output buffer properties
|
||||
OutputBuffer.GetInfo(typeSymbol, out D2D1BufferPrecision bufferPrecision, out D2D1ChannelDepth channelDepth);
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
@@ -139,8 +139,8 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
// Get the info for GetPixelOptions()
|
||||
GetPixelOptions.GetInfo(typeSymbol, out D2D1PixelOptions pixelOptions);
|
||||
// Get the info for PixelOptions
|
||||
PixelOptions.GetInfo(typeSymbol, out D2D1PixelOptions pixelOptions);
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
@@ -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)
|
||||
@@ -313,18 +313,18 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
|
||||
context.AddSource($"{item.Info.Hierarchy.FullyQualifiedMetadataName}.{nameof(LoadDispatchData)}.g.cs", compilationUnit.GetText(Encoding.UTF8));
|
||||
});
|
||||
|
||||
// Get the BuildHlslSource() info (hierarchy and HLSL source)
|
||||
// Get the HlslSource info (hierarchy, HLSL source and parsing options)
|
||||
IncrementalValuesProvider<(HierarchyInfo Hierarchy, string HlslSource)> hlslSourceInfo =
|
||||
shaderInfoWithErrors
|
||||
.Select(static (item, _) => (item.Hierarchy, item.HlslShaderSource.HlslSource));
|
||||
|
||||
// Generate the BuildHlslSource() methods
|
||||
// Generate the HlslSource properties
|
||||
context.RegisterSourceOutput(hlslSourceInfo, static (context, item) =>
|
||||
{
|
||||
MethodDeclarationSyntax buildHlslStringMethod = BuildHlslSource.GetSyntax(item.HlslSource, item.Hierarchy.Hierarchy.Length);
|
||||
CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMember(item.Hierarchy, buildHlslStringMethod, canUseSkipLocalsInit: false);
|
||||
PropertyDeclarationSyntax hlslStringProperty = HlslSource.GetSyntax(item.HlslSource, item.Hierarchy.Hierarchy.Length);
|
||||
CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMember(item.Hierarchy, hlslStringProperty, canUseSkipLocalsInit: false);
|
||||
|
||||
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{nameof(BuildHlslSource)}.g.cs", compilationUnit.GetText(Encoding.UTF8));
|
||||
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{nameof(HlslSource)}.g.cs", compilationUnit.GetText(Encoding.UTF8));
|
||||
});
|
||||
|
||||
// Get a filtered sequence to enable caching for the HLSL source info, before the shader compilation step
|
||||
@@ -386,18 +386,23 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
|
||||
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{nameof(LoadBytecode)}.g.cs", text);
|
||||
});
|
||||
|
||||
// Get the GetOutputBuffer() info (hierarchy and output buffers)
|
||||
// Get the output buffer info (hierarchy and output buffers)
|
||||
IncrementalValuesProvider<(HierarchyInfo Hierarchy, OutputBufferInfo OutputBuffer)> outputBufferInfo =
|
||||
shaderInfoWithErrors
|
||||
.Select(static (item, _) => (item.Hierarchy, item.OutputBuffer));
|
||||
|
||||
// Generate the GetOutputBuffer() methods
|
||||
// Generate the output buffer properties
|
||||
context.RegisterSourceOutput(outputBufferInfo, static (context, item) =>
|
||||
{
|
||||
MethodDeclarationSyntax getOutputBufferMethod = GetOutputBuffer.GetSyntax(item.OutputBuffer);
|
||||
CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMember(item.Hierarchy, getOutputBufferMethod, canUseSkipLocalsInit: false);
|
||||
PropertyDeclarationSyntax bufferPrecisionProperty = OutputBuffer.GetBufferPrecisionSyntax(item.OutputBuffer);
|
||||
CompilationUnitSyntax bufferPrecisionCompilationUnit = GetCompilationUnitFromMember(item.Hierarchy, bufferPrecisionProperty, canUseSkipLocalsInit: false);
|
||||
|
||||
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{nameof(GetOutputBuffer)}.g.cs", compilationUnit.GetText(Encoding.UTF8));
|
||||
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.BufferPrecision.g.cs", bufferPrecisionCompilationUnit.GetText(Encoding.UTF8));
|
||||
|
||||
PropertyDeclarationSyntax channelDepthProperty = OutputBuffer.GetChannelDepthSyntax(item.OutputBuffer);
|
||||
CompilationUnitSyntax channelDepthCompilationUnit = GetCompilationUnitFromMember(item.Hierarchy, channelDepthProperty, canUseSkipLocalsInit: false);
|
||||
|
||||
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.ChannelDepth.g.cs", channelDepthCompilationUnit.GetText(Encoding.UTF8));
|
||||
});
|
||||
|
||||
// Get the InputDescriptions info (hierarchy and input descriptions)
|
||||
@@ -415,18 +420,18 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
|
||||
context.AddSource($"{item.Info.Hierarchy.FullyQualifiedMetadataName}.{nameof(InputDescriptions)}.g.cs", compilationUnit.GetText(Encoding.UTF8));
|
||||
});
|
||||
|
||||
// Get the GetPixelOptions() info (hierarchy and pixel options)
|
||||
// Get the PixelOptions info (hierarchy and pixel options)
|
||||
IncrementalValuesProvider<(HierarchyInfo Hierarchy, D2D1PixelOptions PixelOptions)> pixelOptionsInfo =
|
||||
shaderInfoWithErrors
|
||||
.Select(static (item, _) => (item.Hierarchy, item.PixelOptions));
|
||||
|
||||
// Generate the GetPixelOptions() methods
|
||||
// Generate the PixelOptions properties
|
||||
context.RegisterSourceOutput(pixelOptionsInfo, static (context, item) =>
|
||||
{
|
||||
MethodDeclarationSyntax getPixelOptionsMethod = GetPixelOptions.GetSyntax(item.PixelOptions);
|
||||
CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMember(item.Hierarchy, getPixelOptionsMethod, canUseSkipLocalsInit: false);
|
||||
PropertyDeclarationSyntax pixelOptionsProperty = PixelOptions.GetSyntax(item.PixelOptions);
|
||||
CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMember(item.Hierarchy, pixelOptionsProperty, canUseSkipLocalsInit: false);
|
||||
|
||||
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{nameof(GetPixelOptions)}.g.cs", compilationUnit.GetText(Encoding.UTF8));
|
||||
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{nameof(PixelOptions)}.g.cs", compilationUnit.GetText(Encoding.UTF8));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -64,18 +64,16 @@ public interface ID2D1Shader
|
||||
/// <summary>
|
||||
/// Gets the pixel options for the current shader.
|
||||
/// </summary>
|
||||
/// <returns>The pixel options for the current shader.</returns>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This method is not intended to be used directly by user code")]
|
||||
uint GetPixelOptions();
|
||||
D2D1PixelOptions PixelOptions { get; }
|
||||
|
||||
/// <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.
|
||||
@@ -99,13 +97,18 @@ public interface ID2D1Shader
|
||||
ReadOnlyMemory<D2D1ResourceTextureDescription> ResourceTextureDescriptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the output buffer precision and depth for the shader.
|
||||
/// Gets the buffer precision for the shader.
|
||||
/// </summary>
|
||||
/// <param name="precision">The output buffer precision.</param>
|
||||
/// <param name="depth">The output buffer channel depth.</param>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This method is not intended to be used directly by user code")]
|
||||
void GetOutputBuffer(out uint precision, out uint depth);
|
||||
D2D1BufferPrecision BufferPrecision { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the channel depth for the shader.
|
||||
/// </summary>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This method is not intended to be used directly by user code")]
|
||||
D2D1ChannelDepth ChannelDepth { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Loads the dispatch data for the shader.
|
||||
@@ -118,12 +121,11 @@ public interface ID2D1Shader
|
||||
where TLoader : struct, ID2D1DispatchDataLoader;
|
||||
|
||||
/// <summary>
|
||||
/// Builds the HLSL source code for the current shader instance.
|
||||
/// Gets the HLSL source code for the current shader instance.
|
||||
/// </summary>
|
||||
/// <param name="hlslSource">The resulting HLSL source.</param>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This method is not intended to be called directly by user code")]
|
||||
void BuildHlslSource(out string hlslSource);
|
||||
string HlslSource { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Loads the bytecode for the current shader.
|
||||
|
||||
@@ -242,7 +242,7 @@ public static class D2D1PixelShader
|
||||
{
|
||||
Unsafe.SkipInit(out T shader);
|
||||
|
||||
return (D2D1PixelOptions)shader.GetPixelOptions();
|
||||
return shader.PixelOptions;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -255,7 +255,7 @@ public static class D2D1PixelShader
|
||||
{
|
||||
Unsafe.SkipInit(out T shader);
|
||||
|
||||
return (int)shader.GetInputCount();
|
||||
return shader.InputCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -307,9 +307,7 @@ public static class D2D1PixelShader
|
||||
{
|
||||
Unsafe.SkipInit(out T shader);
|
||||
|
||||
shader.GetOutputBuffer(out uint precision, out _);
|
||||
|
||||
return (D2D1BufferPrecision)precision;
|
||||
return shader.BufferPrecision;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -322,9 +320,7 @@ public static class D2D1PixelShader
|
||||
{
|
||||
Unsafe.SkipInit(out T shader);
|
||||
|
||||
shader.GetOutputBuffer(out _, out uint depth);
|
||||
|
||||
return (D2D1ChannelDepth)depth;
|
||||
return shader.ChannelDepth;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -33,7 +33,7 @@ public static class D2D1ReflectionServices
|
||||
{
|
||||
Unsafe.SkipInit(out T shader);
|
||||
|
||||
shader.BuildHlslSource(out string hlslSource);
|
||||
string hlslSource = shader.HlslSource;
|
||||
|
||||
D2D1ShaderBytecodeLoader bytecodeLoader = default;
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public static class D2D1ShaderCompiler
|
||||
where TLoader : struct, ID2D1BytecodeLoader
|
||||
where T : struct, ID2D1Shader
|
||||
{
|
||||
Unsafe.AsRef(in shader).BuildHlslSource(out string hlslSource);
|
||||
string hlslSource = Unsafe.AsRef(in shader).HlslSource;
|
||||
|
||||
using ComPtr<ID3DBlob> d3DBlobBytecode = Shaders.Translation.D3DCompiler.Compile(
|
||||
hlslSource.AsSpan(),
|
||||
|
||||
@@ -17,13 +17,11 @@ internal static class SyntaxTokenHelper
|
||||
/// <returns>A <see cref="SyntaxToken"/> representing a raw multiline string literal with the value of <paramref name="text"/>.</returns>
|
||||
public static SyntaxToken CreateRawMultilineStringLiteral(string text, int indentationLevel)
|
||||
{
|
||||
// Create a token to represent the raw multiline string literal expression. Here some spaces are
|
||||
// also added to properly align the resulting text with one indentation below the declaring string constant.
|
||||
// The spaces are: 4 for each containing type, 4 for the containing method, and 4 for the one additional indentation.
|
||||
// An extra newline and indentation has to be added to the raw text when there is no trailing newline, as not doing
|
||||
// so would otherwise case the terminating """ token to fall on the same line, which is invalid syntax. This is only
|
||||
// needed to make the code valid, as the actual literal context of the string is not affected and remains the same.
|
||||
string indentation = new(' ', (4 * indentationLevel) + 4 + 4);
|
||||
// Create a token to represent the raw multiline string literal expression. An extra newline and indentation
|
||||
// has to be added to the raw text when there is no trailing newline, as not doing so would otherwise case
|
||||
// the terminating """ token to fall on the same line, which is invalid syntax. This is only needed to make
|
||||
// the code valid, as the actual literal context of the string is not affected and remains the same.
|
||||
string indentation = new(' ', 4 * indentationLevel);
|
||||
|
||||
return Token(
|
||||
TriviaList(),
|
||||
|
||||
+2
-1
@@ -119,7 +119,8 @@ partial class IShaderGenerator
|
||||
|
||||
sizeHint += textBuilder.Length;
|
||||
|
||||
SyntaxToken hlslSourceLiteralExpression = SyntaxTokenHelper.CreateRawMultilineStringLiteral(hlslSource, hierarchyDepth);
|
||||
// The indentation level is the current depth + 2 (the method, and the return expression)
|
||||
SyntaxToken hlslSourceLiteralExpression = SyntaxTokenHelper.CreateRawMultilineStringLiteral(hlslSource, hierarchyDepth + 2);
|
||||
|
||||
statements.Add(
|
||||
ExpressionStatement(
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする