diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.Execute.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.Execute.cs
index b26dbb1c..daf3fcea 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.Execute.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.Execute.cs
@@ -1,3 +1,4 @@
+using System.Collections.Immutable;
using ComputeSharp.D2D1.SourceGenerators.Models;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
@@ -98,38 +99,34 @@ partial class D2DPixelShaderSourceGenerator
///
/// The input instance to process.
/// The source instance.
- /// The collection of produced instances.
- public static void GetInfoDiagnostics(
- IMethodSymbol methodSymbol,
- HlslBytecodeInfo info,
- ImmutableArrayBuilder diagnostics)
+ /// The collection of produced instances.
+ public static ImmutableArray GetInfoDiagnostics(IMethodSymbol methodSymbol, HlslBytecodeInfo info)
{
- DiagnosticInfo? diagnostic = null;
-
if (info is HlslBytecodeInfo.Win32Error win32Error)
{
- diagnostic = DiagnosticInfo.Create(
+ DiagnosticInfo diagnostic = DiagnosticInfo.Create(
D2DPixelShaderSourceCompilationFailedWithWin32Exception,
methodSymbol,
methodSymbol,
methodSymbol.ContainingType,
win32Error.HResult,
win32Error.Message);
+
+ return ImmutableArray.Create(diagnostic);
}
else if (info is HlslBytecodeInfo.CompilerError fxcError)
{
- diagnostic = DiagnosticInfo.Create(
+ DiagnosticInfo diagnostic = DiagnosticInfo.Create(
D2DPixelShaderSourceCompilationFailedWithFxcCompilationException,
methodSymbol,
methodSymbol,
methodSymbol.ContainingType,
fxcError.Message);
+
+ return ImmutableArray.Create(diagnostic);
}
- if (diagnostic is not null)
- {
- diagnostics.Add(diagnostic);
- }
+ return ImmutableArray.Empty;
}
///
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.cs
index 5906a970..0573a8fd 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.cs
@@ -35,8 +35,6 @@ public sealed partial class D2DPixelShaderSourceGenerator : IIncrementalGenerato
MethodDeclarationSyntax methodDeclaration = (MethodDeclarationSyntax)context.TargetNode;
IMethodSymbol methodSymbol = (IMethodSymbol)context.TargetSymbol;
- using ImmutableArrayBuilder diagnostics = new();
-
// Get the remaining info for the current shader
ImmutableArray modifiers = methodDeclaration.Modifiers.Select(token => (ushort)token.Kind()).ToImmutableArray();
string methodName = methodSymbol.Name;
@@ -65,8 +63,8 @@ public sealed partial class D2DPixelShaderSourceGenerator : IIncrementalGenerato
token.ThrowIfCancellationRequested();
- // Append any diagnostic for the shader compilation
- Execute.GetInfoDiagnostics(methodSymbol, hlslInfo, diagnostics);
+ // Get any diagnostics for the shader compilation
+ ImmutableArray diagnostics = Execute.GetInfoDiagnostics(methodSymbol, hlslInfo);
token.ThrowIfCancellationRequested();
@@ -82,7 +80,7 @@ public sealed partial class D2DPixelShaderSourceGenerator : IIncrementalGenerato
InvalidReturnType: invalidReturnType,
HlslInfoKey: hlslInfoKey,
HlslInfo: hlslInfo,
- Diagnostcs: diagnostics.ToImmutable());
+ Diagnostcs: diagnostics);
})
.WithTrackingName(WellKnownTrackingNames.Execute);