Remove unnecessary ArrayPoolStringBuilder type
このコミットが含まれているのは:
1 親
8e0aa437bc
コミット
d797f14771
4ファイル変更
+13
-242
検索条件に一致するファイルはありません
+8
-69
@@ -1,4 +1,3 @@
|
||||
using System.Collections.Immutable;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.SourceGeneration.Helpers;
|
||||
using ComputeSharp.SourceGenerators.Models;
|
||||
@@ -25,14 +24,14 @@ partial class IShaderGenerator
|
||||
/// <returns>The resulting <see cref="MethodDeclarationSyntax"/> instance for the <c>BuildHlslSource</c> method.</returns>
|
||||
public static MethodDeclarationSyntax GetSyntax(HlslShaderSourceInfo hlslSourceInfo, int hierarchyDepth)
|
||||
{
|
||||
// Generate the necessary body statements depending on whether dynamic shaders are supported
|
||||
ImmutableArray<StatementSyntax> bodyStatements = GenerateRenderMethodBody(hlslSourceInfo, hierarchyDepth);
|
||||
// The indentation level is the current depth + 2 (the method, and the return expression)
|
||||
SyntaxToken hlslSourceLiteralExpression = SyntaxTokenHelper.CreateRawMultilineStringLiteral(hlslSourceInfo.HlslSource, hierarchyDepth + 2);
|
||||
|
||||
// This code produces a method declaration as follows:
|
||||
//
|
||||
// readonly void global::ComputeSharp.__Internals.IShader.BuildHlslSource(out global::ComputeSharp.__Internals.ArrayPoolStringBuilder builder, int threadsX, int threadsY, int threadsZ)
|
||||
// readonly void global::ComputeSharp.__Internals.IShader.BuildHlslSource(out string hlslSource)
|
||||
// {
|
||||
// <BODY>
|
||||
// hlslSource = <HLSL_SOURCE>;
|
||||
// }
|
||||
return
|
||||
MethodDeclaration(
|
||||
@@ -41,73 +40,13 @@ partial class IShaderGenerator
|
||||
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.__Internals.{nameof(IShader)}")))
|
||||
.AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
|
||||
.AddParameterListParameters(
|
||||
Parameter(Identifier("builder")).AddModifiers(Token(SyntaxKind.OutKeyword)).WithType(IdentifierName("global::ComputeSharp.__Internals.ArrayPoolStringBuilder")),
|
||||
Parameter(Identifier("threadsX")).WithType(PredefinedType(Token(SyntaxKind.IntKeyword))),
|
||||
Parameter(Identifier("threadsY")).WithType(PredefinedType(Token(SyntaxKind.IntKeyword))),
|
||||
Parameter(Identifier("threadsZ")).WithType(PredefinedType(Token(SyntaxKind.IntKeyword))))
|
||||
.WithBody(Block(bodyStatements));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Produces the series of statements for the empty fallback method.
|
||||
/// </summary>
|
||||
/// <returns>A series of statements for when dynamic shaders are not supported.</returns>
|
||||
private static ImmutableArray<StatementSyntax> GenerateEmptyMethodBody()
|
||||
{
|
||||
// builder = global::ComputeSharp.__Internals.ArrayPoolStringBuilder.Create(0);
|
||||
return
|
||||
ImmutableArray.Create<StatementSyntax>(
|
||||
Parameter(Identifier("hlslSource")).AddModifiers(Token(SyntaxKind.OutKeyword)).WithType(PredefinedType(Token(SyntaxKind.StringKeyword))))
|
||||
.WithBody(Block(
|
||||
ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
IdentifierName("builder"),
|
||||
InvocationExpression(
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName("global::ComputeSharp.__Internals.ArrayPoolStringBuilder"),
|
||||
IdentifierName("Create")))
|
||||
.AddArgumentListArguments(
|
||||
Argument(LiteralExpression(
|
||||
SyntaxKind.NumericLiteralExpression,
|
||||
Literal(0)))))));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Produces the series of statements to build the current HLSL source.
|
||||
/// </summary>
|
||||
/// <param name="hlslSourceInfo">The input <see cref="HlslShaderSourceInfo"/> instance to use.</param>
|
||||
/// <param name="hierarchyDepth">The depth of the hierarchy for this type (used to calculate the right indentation).</param>
|
||||
/// <returns>The series of statements to build the HLSL source to compile to execute the current shader.</returns>
|
||||
private static ImmutableArray<StatementSyntax> GenerateRenderMethodBody(HlslShaderSourceInfo hlslSourceInfo, int hierarchyDepth)
|
||||
{
|
||||
using ImmutableArrayBuilder<StatementSyntax> statements = new();
|
||||
|
||||
// builder = global::ComputeSharp.__Internals.ArrayPoolStringBuilder.Create(<SIZE_HINT>);
|
||||
statements.Add(
|
||||
ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
IdentifierName("builder"),
|
||||
InvocationExpression(
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName("global::ComputeSharp.__Internals.ArrayPoolStringBuilder"),
|
||||
IdentifierName("Create")))
|
||||
.AddArgumentListArguments(
|
||||
Argument(LiteralExpression(
|
||||
SyntaxKind.NumericLiteralExpression,
|
||||
Literal(hlslSourceInfo.HlslSource.Length)))))));
|
||||
|
||||
// The indentation level is the current depth + 2 (the method, and the return expression)
|
||||
SyntaxToken hlslSourceLiteralExpression = SyntaxTokenHelper.CreateRawMultilineStringLiteral(hlslSourceInfo.HlslSource, hierarchyDepth + 2);
|
||||
|
||||
statements.Add(
|
||||
ExpressionStatement(
|
||||
InvocationExpression(
|
||||
MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName("builder"), IdentifierName("Append")))
|
||||
.AddArgumentListArguments(Argument(LiteralExpression(SyntaxKind.StringLiteralExpression, hlslSourceLiteralExpression)))));
|
||||
|
||||
return statements.ToImmutable();
|
||||
IdentifierName("hlslSource"),
|
||||
LiteralExpression(SyntaxKind.StringLiteralExpression, hlslSourceLiteralExpression)))));
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする