diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.cs index 4266885c..533f0a8e 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.cs @@ -2,6 +2,7 @@ using System.Collections.Immutable; using System.ComponentModel; using System.Linq; using ComputeSharp.D2D1.SourceGenerators.Models; +using ComputeSharp.SourceGeneration.Constants; using ComputeSharp.SourceGeneration.Extensions; using ComputeSharp.SourceGeneration.Helpers; using ComputeSharp.SourceGeneration.Models; @@ -197,13 +198,21 @@ public sealed partial class D2DPixelShaderDescriptorGenerator : IIncrementalGene HlslInfo: hlslInfo, Diagnostcs: diagnostics.ToImmutable()); }) + .WithTrackingName(WellKnownTrackingNames.Execute) .Where(static item => item is not null)!; - // We need to create two more incremental steps to ensure we correctly emit diagnostics and re-generate sources: - // - One with just the diagnostics, which will trigger every time any of them changes - // - One with just the shader info (and no diagnostics), so that changes there don't trigger generation unnecessarily - IncrementalValuesProvider> diagnosticInfo = shaderInfo.Select(static (item, _) => item.Diagnostcs); - IncrementalValuesProvider outputInfo = shaderInfo.Select(static (item, _) => item with { Diagnostcs = default }); + // We need to create two more incremental steps to ensure we correctly emit diagnostics and re-generate sources. + // First, select an incremental provider with just the diagnostics, which will trigger every time any of them changes. + IncrementalValuesProvider> diagnosticInfo = + shaderInfo + .Select(static (item, _) => item.Diagnostcs) + .WithTrackingName(WellKnownTrackingNames.Diagnostics); + + // Next, select one with just the shader info (and no diagnostics), so that changes there don't trigger generation unnecessarily + IncrementalValuesProvider outputInfo = + shaderInfo + .Select(static (item, _) => item with { Diagnostcs = default }) + .WithTrackingName(WellKnownTrackingNames.Output); // Output the diagnostics, if any context.ReportDiagnostics(diagnosticInfo); diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/ComputeSharp.SourceGeneration.Hlsl.projitems b/src/ComputeSharp.SourceGeneration.Hlsl/ComputeSharp.SourceGeneration.Hlsl.projitems index 5b6c9f91..0124d463 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/ComputeSharp.SourceGeneration.Hlsl.projitems +++ b/src/ComputeSharp.SourceGeneration.Hlsl/ComputeSharp.SourceGeneration.Hlsl.projitems @@ -9,6 +9,7 @@ ComputeSharp.SourceGeneration.Hlsl + diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/Constants/WellKnownTrackingNames.cs b/src/ComputeSharp.SourceGeneration.Hlsl/Constants/WellKnownTrackingNames.cs new file mode 100644 index 00000000..30f2b227 --- /dev/null +++ b/src/ComputeSharp.SourceGeneration.Hlsl/Constants/WellKnownTrackingNames.cs @@ -0,0 +1,22 @@ +namespace ComputeSharp.SourceGeneration.Constants; + +/// +/// The well known names for tracking steps, to test the incremental generators. +/// +internal static class WellKnownTrackingNames +{ + /// + /// The initial transform node. + /// + public const string Execute = nameof(Execute); + + /// + /// The filtered transform with just output diagnostics. + /// + public const string Diagnostics = nameof(Diagnostics); + + /// + /// The filtered transform with just output sources. + /// + public const string Output = nameof(Output); +} diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.cs index 4d3e6cbd..716ef91c 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.cs @@ -1,6 +1,7 @@ using System.Collections.Immutable; using System.ComponentModel; using System.Linq; +using ComputeSharp.SourceGeneration.Constants; using ComputeSharp.SourceGeneration.Extensions; using ComputeSharp.SourceGeneration.Helpers; using ComputeSharp.SourceGeneration.Models; @@ -146,11 +147,20 @@ public sealed partial class ComputeShaderDescriptorGenerator : IIncrementalGener HlslInfo: hlslInfo, Diagnostcs: diagnostics.ToImmutable()); }) + .WithTrackingName(WellKnownTrackingNames.Execute) .Where(static item => item is not null)!; // Split the diagnostics, and drop them from the output provider (see more notes in the D2D1 generator) - IncrementalValuesProvider> diagnosticInfo = shaderInfo.Select(static (item, _) => item.Diagnostcs); - IncrementalValuesProvider outputInfo = shaderInfo.Select(static (item, _) => item with { Diagnostcs = default }); + IncrementalValuesProvider> diagnosticInfo = + shaderInfo + .Select(static (item, _) => item.Diagnostcs) + .WithTrackingName(WellKnownTrackingNames.Diagnostics); + + // Gather the models to produce sources for + IncrementalValuesProvider outputInfo = + shaderInfo + .Select(static (item, _) => item with { Diagnostcs = default }) + .WithTrackingName(WellKnownTrackingNames.Output); // Output the diagnostics, if any context.ReportDiagnostics(diagnosticInfo);