Unify output node for D3D12 source generator
このコミットが含まれているのは:
1 親
aa708dc2d5
コミット
49d0ec2a5b
4ファイル変更
+16
-114
検索条件に一致するファイルはありません
@@ -41,16 +41,6 @@ internal static class DiagnosticsExtensions
|
||||
diagnostics.Add(DiagnosticInfo.Create(descriptor, node, args));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers an output node into an <see cref="IncrementalGeneratorInitializationContext"/> to output diagnostics.
|
||||
/// </summary>
|
||||
/// <param name="context">The input <see cref="IncrementalGeneratorInitializationContext"/> instance.</param>
|
||||
/// <param name="diagnostics">The input <see cref="IncrementalValuesProvider{TValues}"/> sequence of diagnostics.</param>
|
||||
public static void ReportDiagnostics(this IncrementalGeneratorInitializationContext context, IncrementalValuesProvider<DiagnosticInfo> diagnostics)
|
||||
{
|
||||
context.RegisterSourceOutput(diagnostics, static (context, diagnostic) => context.ReportDiagnostic(diagnostic.ToDiagnostic()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers an output node into an <see cref="IncrementalGeneratorInitializationContext"/> to output diagnostics.
|
||||
/// </summary>
|
||||
|
||||
@@ -13,7 +13,11 @@ namespace ComputeSharp.SourceGeneration.Models;
|
||||
/// <param name="SyntaxTree">The tree to use as location for the diagnostic, if available.</param>
|
||||
/// <param name="TextSpan">The span to use as location for the diagnostic.</param>
|
||||
/// <param name="Arguments">The diagnostic arguments.</param>
|
||||
internal sealed record DiagnosticInfo(DiagnosticDescriptor Descriptor, SyntaxTree? SyntaxTree, TextSpan TextSpan, EquatableArray<string> Arguments)
|
||||
internal sealed record DiagnosticInfo(
|
||||
DiagnosticDescriptor Descriptor,
|
||||
SyntaxTree? SyntaxTree,
|
||||
TextSpan TextSpan,
|
||||
EquatableArray<string> Arguments)
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Diagnostic"/> instance with the state from this model.
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using ComputeSharp.SourceGeneration.Models;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators;
|
||||
|
||||
@@ -43,44 +38,4 @@ partial class IShaderGenerator
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="CompilationUnitSyntax"/> instance wrapping the given method.
|
||||
/// </summary>
|
||||
/// <param name="hierarchyInfo">The <see cref="HierarchyInfo"/> instance for the current type.</param>
|
||||
/// <param name="methodDeclaration">The <see cref="MethodDeclarationSyntax"/> item to insert.</param>
|
||||
/// <param name="addSkipLocalsInitAttribute">Whether <c>[SkipLocalsInit]</c> should be used.</param>
|
||||
/// <returns>A <see cref="CompilationUnitSyntax"/> object wrapping <paramref name="methodDeclaration"/>.</returns>
|
||||
private static CompilationUnitSyntax GetCompilationUnitFromMethod(
|
||||
HierarchyInfo hierarchyInfo,
|
||||
MethodDeclarationSyntax methodDeclaration,
|
||||
bool addSkipLocalsInitAttribute)
|
||||
{
|
||||
// Method attributes
|
||||
List<AttributeListSyntax> attributes = new()
|
||||
{
|
||||
AttributeList(SingletonSeparatedList(
|
||||
Attribute(IdentifierName("global::System.CodeDom.Compiler.GeneratedCode")).AddArgumentListArguments(
|
||||
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(IShaderGenerator).FullName))),
|
||||
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(IShaderGenerator).Assembly.GetName().Version.ToString())))))),
|
||||
AttributeList(SingletonSeparatedList(Attribute(IdentifierName("global::System.Diagnostics.DebuggerNonUserCode")))),
|
||||
AttributeList(SingletonSeparatedList(Attribute(IdentifierName("global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage")))),
|
||||
AttributeList(SingletonSeparatedList(
|
||||
Attribute(IdentifierName("global::System.ComponentModel.EditorBrowsable")).AddArgumentListArguments(
|
||||
AttributeArgument(ParseExpression("global::System.ComponentModel.EditorBrowsableState.Never"))))),
|
||||
AttributeList(SingletonSeparatedList(
|
||||
Attribute(IdentifierName("global::System.Obsolete")).AddArgumentListArguments(
|
||||
AttributeArgument(LiteralExpression(
|
||||
SyntaxKind.StringLiteralExpression,
|
||||
Literal("This method is not intended to be used directly by user code"))))))
|
||||
};
|
||||
|
||||
// Add [SkipLocalsInit] if needed
|
||||
if (addSkipLocalsInitAttribute)
|
||||
{
|
||||
attributes.Add(AttributeList(SingletonSeparatedList(Attribute(IdentifierName("global::System.Runtime.CompilerServices.SkipLocalsInit")))));
|
||||
}
|
||||
|
||||
return hierarchyInfo.GetSyntax(methodDeclaration.AddAttributeLists(attributes.ToArray()));
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
|
||||
public void Initialize(IncrementalGeneratorInitializationContext context)
|
||||
{
|
||||
// Discover all shader types and extract all the necessary info from each of them
|
||||
IncrementalValuesProvider<ShaderInfo> shaderInfoWithErrors =
|
||||
IncrementalValuesProvider<ShaderInfo> shaderInfo =
|
||||
context.SyntaxProvider
|
||||
.CreateSyntaxProvider(
|
||||
static (node, _) => node.IsTypeDeclarationWithOrPotentiallyWithBaseTypes<StructDeclarationSyntax>(),
|
||||
@@ -117,68 +117,21 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
|
||||
})
|
||||
.Where(static item => item is not null)!;
|
||||
|
||||
// Output the diagnostics, if any
|
||||
context.ReportDiagnostics(shaderInfoWithErrors.Select(static (item, _) => item.Diagnostcs));
|
||||
// Split the diagnostics, and drop them from the output provider (see more notes in the D2D1 generator)
|
||||
IncrementalValuesProvider<EquatableArray<DiagnosticInfo>> diagnosticInfo = shaderInfo.Select(static (item, _) => item.Diagnostcs);
|
||||
IncrementalValuesProvider<ShaderInfo> outputInfo = shaderInfo.Select(static (item, _) => item with { Diagnostcs = default });
|
||||
|
||||
// Generate the LoadDispatchData() methods
|
||||
context.RegisterSourceOutput(shaderInfoWithErrors, static (context, item) =>
|
||||
// Output the diagnostics, if any
|
||||
context.ReportDiagnostics(diagnosticInfo);
|
||||
|
||||
// Generate the source files, if any
|
||||
context.RegisterSourceOutput(outputInfo, static (context, item) =>
|
||||
{
|
||||
using ImmutableArrayBuilder<IndentedTextWriter.Callback<ShaderInfo>> declaredMembers = new();
|
||||
|
||||
declaredMembers.Add(LoadDispatchData.WriteSyntax);
|
||||
|
||||
using IndentedTextWriter writer = new();
|
||||
|
||||
item.Hierarchy.WriteSyntax(
|
||||
state: item,
|
||||
writer: writer,
|
||||
baseTypes: ReadOnlySpan<string>.Empty,
|
||||
memberCallbacks: declaredMembers.WrittenSpan);
|
||||
|
||||
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{nameof(LoadDispatchData)}.g.cs", writer.ToString());
|
||||
});
|
||||
|
||||
// Generate the BuildHlslSource() methods
|
||||
context.RegisterSourceOutput(shaderInfoWithErrors, static (context, item) =>
|
||||
{
|
||||
using ImmutableArrayBuilder<IndentedTextWriter.Callback<ShaderInfo>> declaredMembers = new();
|
||||
|
||||
declaredMembers.Add(BuildHlslSource.WriteSyntax);
|
||||
|
||||
using IndentedTextWriter writer = new();
|
||||
|
||||
item.Hierarchy.WriteSyntax(
|
||||
state: item,
|
||||
writer: writer,
|
||||
baseTypes: ReadOnlySpan<string>.Empty,
|
||||
memberCallbacks: declaredMembers.WrittenSpan);
|
||||
|
||||
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{nameof(BuildHlslSource)}.g.cs", writer.ToString());
|
||||
});
|
||||
|
||||
// Generate the LoadDispatchMetadata() methods
|
||||
context.RegisterSourceOutput(shaderInfoWithErrors, static (context, item) =>
|
||||
{
|
||||
using ImmutableArrayBuilder<IndentedTextWriter.Callback<ShaderInfo>> declaredMembers = new();
|
||||
|
||||
declaredMembers.Add(LoadDispatchMetadata.WriteSyntax);
|
||||
|
||||
using IndentedTextWriter writer = new();
|
||||
|
||||
item.Hierarchy.WriteSyntax(
|
||||
state: item,
|
||||
writer: writer,
|
||||
baseTypes: ReadOnlySpan<string>.Empty,
|
||||
memberCallbacks: declaredMembers.WrittenSpan);
|
||||
|
||||
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{nameof(LoadDispatchMetadata)}.g.cs", writer.ToString());
|
||||
});
|
||||
|
||||
// Generate the TryGetBytecode() methods
|
||||
context.RegisterSourceOutput(shaderInfoWithErrors, static (context, item) =>
|
||||
{
|
||||
using ImmutableArrayBuilder<IndentedTextWriter.Callback<ShaderInfo>> declaredMembers = new();
|
||||
|
||||
declaredMembers.Add(BuildHlslSource.WriteSyntax);
|
||||
declaredMembers.Add(LoadBytecode.WriteSyntax);
|
||||
|
||||
using IndentedTextWriter writer = new();
|
||||
@@ -189,7 +142,7 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
|
||||
baseTypes: ReadOnlySpan<string>.Empty,
|
||||
memberCallbacks: declaredMembers.WrittenSpan);
|
||||
|
||||
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{nameof(LoadBytecode)}.g.cs", writer.ToString());
|
||||
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.g.cs", writer.ToString());
|
||||
});
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする