From 1ffa43ed34d89760c6651e68d42ac1e0c80c5a60 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 16 Dec 2023 00:04:59 +0100 Subject: [PATCH 1/7] Use semicolon token type declarations if possible --- .../CanvasEffect.EffectGraph.cs | 12 +++--------- .../D2DGeneratedPixelShaderDescriptorAttribute.cs | 4 +--- .../Attributes/D2DRequiresScenePositionAttribute.cs | 4 +--- .../Diagnostics/DiagnosticDescriptors.cs | 4 +--- .../GeneratedComputeShaderDescriptorAttribute.cs | 4 +--- .../Attributes/GloballyCoherentAttribute.cs | 4 +--- .../Attributes/AllDevicesAttribute.cs | 4 +--- tests/ComputeSharp.Tests/ShaderCompilerTests.cs | 4 +--- 8 files changed, 10 insertions(+), 30 deletions(-) diff --git a/src/ComputeSharp.D2D1.WinUI/CanvasEffect.EffectGraph.cs b/src/ComputeSharp.D2D1.WinUI/CanvasEffect.EffectGraph.cs index 0d3753c3..628e0894 100644 --- a/src/ComputeSharp.D2D1.WinUI/CanvasEffect.EffectGraph.cs +++ b/src/ComputeSharp.D2D1.WinUI/CanvasEffect.EffectGraph.cs @@ -228,9 +228,7 @@ partial class CanvasEffect /// This interface only implemented by and it's not meant to be implemented by external types. /// /// - protected interface IEffectNode - { - } + protected interface IEffectNode; /// /// A marker interface for a generic effect node that was registered from an value. @@ -246,16 +244,12 @@ partial class CanvasEffect /// /// protected interface IEffectNode : IEffectNode - where T : ICanvasImage - { - } + where T : ICanvasImage; /// /// A marker type for an effect node that can be registered and retrieved from an value. /// /// The type of associated with the current effect node. protected sealed class EffectNode : IEffectNode - where T : class, ICanvasImage - { - } + where T : class, ICanvasImage; } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/Attributes/D2DGeneratedPixelShaderDescriptorAttribute.cs b/src/ComputeSharp.D2D1/Attributes/D2DGeneratedPixelShaderDescriptorAttribute.cs index da27d2fe..92c531b3 100644 --- a/src/ComputeSharp.D2D1/Attributes/D2DGeneratedPixelShaderDescriptorAttribute.cs +++ b/src/ComputeSharp.D2D1/Attributes/D2DGeneratedPixelShaderDescriptorAttribute.cs @@ -19,6 +19,4 @@ namespace ComputeSharp.D2D1; /// /// [AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)] -public sealed class D2DGeneratedPixelShaderDescriptorAttribute : Attribute -{ -} \ No newline at end of file +public sealed class D2DGeneratedPixelShaderDescriptorAttribute : Attribute; \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/Attributes/D2DRequiresScenePositionAttribute.cs b/src/ComputeSharp.D2D1/Attributes/D2DRequiresScenePositionAttribute.cs index 8355261d..fb4ecb2e 100644 --- a/src/ComputeSharp.D2D1/Attributes/D2DRequiresScenePositionAttribute.cs +++ b/src/ComputeSharp.D2D1/Attributes/D2DRequiresScenePositionAttribute.cs @@ -12,6 +12,4 @@ namespace ComputeSharp.D2D1; /// For more info, see . /// [AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)] -public sealed class D2DRequiresScenePositionAttribute : Attribute -{ -} \ No newline at end of file +public sealed class D2DRequiresScenePositionAttribute : Attribute; \ No newline at end of file diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/Diagnostics/DiagnosticDescriptors.cs b/src/ComputeSharp.SourceGeneration.Hlsl/Diagnostics/DiagnosticDescriptors.cs index fc3653a2..c15a6ad1 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/Diagnostics/DiagnosticDescriptors.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/Diagnostics/DiagnosticDescriptors.cs @@ -5,6 +5,4 @@ namespace ComputeSharp.SourceGeneration.Diagnostics; /// /// A container for all instances for errors reported by analyzers in this project. /// -internal static partial class DiagnosticDescriptors -{ -} \ No newline at end of file +internal static partial class DiagnosticDescriptors; \ No newline at end of file diff --git a/src/ComputeSharp/Attributes/GeneratedComputeShaderDescriptorAttribute.cs b/src/ComputeSharp/Attributes/GeneratedComputeShaderDescriptorAttribute.cs index f92c1fe2..0424254d 100644 --- a/src/ComputeSharp/Attributes/GeneratedComputeShaderDescriptorAttribute.cs +++ b/src/ComputeSharp/Attributes/GeneratedComputeShaderDescriptorAttribute.cs @@ -22,6 +22,4 @@ namespace ComputeSharp; /// /// [AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)] -public sealed class GeneratedComputeShaderDescriptorAttribute : Attribute -{ -} \ No newline at end of file +public sealed class GeneratedComputeShaderDescriptorAttribute : Attribute; \ No newline at end of file diff --git a/src/ComputeSharp/Attributes/GloballyCoherentAttribute.cs b/src/ComputeSharp/Attributes/GloballyCoherentAttribute.cs index a04f23d8..a2b6e550 100644 --- a/src/ComputeSharp/Attributes/GloballyCoherentAttribute.cs +++ b/src/ComputeSharp/Attributes/GloballyCoherentAttribute.cs @@ -21,6 +21,4 @@ namespace ComputeSharp; /// /// [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)] -public sealed class GloballyCoherentAttribute : Attribute -{ -} \ No newline at end of file +public sealed class GloballyCoherentAttribute : Attribute; \ No newline at end of file diff --git a/tests/ComputeSharp.Tests/Attributes/AllDevicesAttribute.cs b/tests/ComputeSharp.Tests/Attributes/AllDevicesAttribute.cs index 7194b7b1..4da97a93 100644 --- a/tests/ComputeSharp.Tests/Attributes/AllDevicesAttribute.cs +++ b/tests/ComputeSharp.Tests/Attributes/AllDevicesAttribute.cs @@ -6,6 +6,4 @@ namespace ComputeSharp.Tests.Attributes; /// An attribute to use with targeting all supported devices. /// [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] -public sealed class AllDevicesAttribute : Attribute -{ -} \ No newline at end of file +public sealed class AllDevicesAttribute : Attribute; \ No newline at end of file diff --git a/tests/ComputeSharp.Tests/ShaderCompilerTests.cs b/tests/ComputeSharp.Tests/ShaderCompilerTests.cs index 5adf186b..8c507492 100644 --- a/tests/ComputeSharp.Tests/ShaderCompilerTests.cs +++ b/tests/ComputeSharp.Tests/ShaderCompilerTests.cs @@ -838,9 +838,7 @@ namespace ComputeSharp.Tests [AutoConstructor] [ThreadGroupSize(DefaultThreadGroupSizes.X)] [GeneratedComputeShaderDescriptor] - internal readonly partial struct ShaderWithPartialDeclarations : IComputeShader - { - } + internal readonly partial struct ShaderWithPartialDeclarations : IComputeShader; partial struct ShaderWithPartialDeclarations { From eb5a1d4acff19aee949a8a9c2dab5ee4b5fcf439 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 16 Dec 2023 02:14:58 +0100 Subject: [PATCH 2/7] Add D2DEnableRuntimeCompilationAttribute type --- .../Attributes/D2DEnableRuntimeCompilation.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/ComputeSharp.D2D1/Attributes/D2DEnableRuntimeCompilation.cs diff --git a/src/ComputeSharp.D2D1/Attributes/D2DEnableRuntimeCompilation.cs b/src/ComputeSharp.D2D1/Attributes/D2DEnableRuntimeCompilation.cs new file mode 100644 index 00000000..503bf6fe --- /dev/null +++ b/src/ComputeSharp.D2D1/Attributes/D2DEnableRuntimeCompilation.cs @@ -0,0 +1,27 @@ +using System; + +namespace ComputeSharp.D2D1; + +/// +/// An attribute that indicates that runtime compilation of D2D shaders is enabled. +/// This attribute is required for all shaders that are not compiled at build time. +/// +/// +/// +/// Precompiling shaders at build time is recommended, as it enables additional validation +/// and diagnostics, and provides better performance at runtime when dispatching the shaders. +/// +/// +/// This option can be used in advanced scenarios, for instance when trying to minimize +/// binary size (which should only be done after carefully measuring the actual difference). +/// +/// +/// Note that not using this attribute does not mean that trying to compile shaders at runtime will +/// fail. The purpose of this attribute is to allow declaring shader types that are not precompiled. +/// All other features, such as manually compiling a shader type with specific compile options or +/// with a different shader profile, or manually compiling a shader from source at runtime, are +/// always supported, regardless of whether nor not this attribute is used. +/// +/// +[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = false)] +public sealed class D2DEnableRuntimeCompilationAttribute : Attribute; \ No newline at end of file From 37af7113e6935e70c152fcfd5d74c5c5b47be27a Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 16 Dec 2023 02:26:02 +0100 Subject: [PATCH 3/7] Add D2DRuntimeCompilationDisabledAnalyzer --- .../AnalyzerReleases.Shipped.md | 1 + .../D2DRuntimeCompilationDisabledAnalyzer.cs | 68 +++++++++++++++++++ .../Diagnostics/DiagnosticDescriptors.cs | 16 +++++ 3 files changed, 85 insertions(+) create mode 100644 src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/D2DRuntimeCompilationDisabledAnalyzer.cs diff --git a/src/ComputeSharp.D2D1.SourceGenerators/AnalyzerReleases.Shipped.md b/src/ComputeSharp.D2D1.SourceGenerators/AnalyzerReleases.Shipped.md index 6fe7a3a5..33e24b45 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/AnalyzerReleases.Shipped.md +++ b/src/ComputeSharp.D2D1.SourceGenerators/AnalyzerReleases.Shipped.md @@ -82,3 +82,4 @@ CMPSD2D0072 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github CMPSD2D0073 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp) CMPSD2D0074 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp) CMPSD2D0075 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp) +CMPSD2D0076 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/D2DRuntimeCompilationDisabledAnalyzer.cs b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/D2DRuntimeCompilationDisabledAnalyzer.cs new file mode 100644 index 00000000..3041935b --- /dev/null +++ b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/D2DRuntimeCompilationDisabledAnalyzer.cs @@ -0,0 +1,68 @@ +using System.Collections.Immutable; +using System.Linq; +using ComputeSharp.SourceGeneration.Extensions; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Diagnostics; +using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors; + +namespace ComputeSharp.D2D1.SourceGenerators; + +/// +/// A diagnostic analyzer that generates an error whenever a shader is not precompiled but runtime compilation is not enabled. +/// +[DiagnosticAnalyzer(LanguageNames.CSharp)] +public sealed class D2DRuntimeCompilationDisabledAnalyzer : DiagnosticAnalyzer +{ + /// + public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create(D2DRuntimeCompilationDisabled); + + /// + public override void Initialize(AnalysisContext context) + { + context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics); + context.EnableConcurrentExecution(); + + context.RegisterCompilationStartAction(static context => + { + // Get the [D2DShaderProfile], [D2DEnableRuntimeCompilation] and [D2DGeneratedPixelShaderDescriptor] symbols + if (context.Compilation.GetTypeByMetadataName("ComputeSharp.D2D1.D2DShaderProfileAttribute") is not { } d2DShaderProfileAttributeSymbol || + context.Compilation.GetTypeByMetadataName("ComputeSharp.D2D1.D2DEnableRuntimeCompilationAttribute") is not { } d2DEnableRuntimeCompilationAttributeSymbol || + context.Compilation.GetTypeByMetadataName("ComputeSharp.D2D1.D2DGeneratedPixelShaderDescriptorAttribute") is not { } d2DGeneratedPixelShaderDescriptorAttributeSymbol) + { + return; + } + + context.RegisterSymbolAction(context => + { + // Only struct types are possible targets + if (context.Symbol is not INamedTypeSymbol { TypeKind: TypeKind.Struct } typeSymbol) + { + return; + } + + // Skip the type if it's not a generated shader descriptor target + if (!typeSymbol.HasAttributeWithType(d2DGeneratedPixelShaderDescriptorAttributeSymbol)) + { + return; + } + + // If the shader is being precompiled, we don't have anything else to do + if (typeSymbol.HasAttributeWithType(d2DShaderProfileAttributeSymbol) || + typeSymbol.ContainingAssembly.HasAttributeWithType(d2DShaderProfileAttributeSymbol)) + { + return; + } + + // Emit a diagnostic if there is no [D2DEnableRuntimeCompilation] set anywhere + if (!typeSymbol.HasAttributeWithType(d2DEnableRuntimeCompilationAttributeSymbol) && + !typeSymbol.ContainingAssembly.HasAttributeWithType(d2DEnableRuntimeCompilationAttributeSymbol)) + { + context.ReportDiagnostic(Diagnostic.Create( + D2DRuntimeCompilationDisabled, + typeSymbol.Locations.FirstOrDefault(), + typeSymbol)); + } + }, SymbolKind.NamedType); + }); + } +} \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs index ec8921e5..ec267d8d 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs @@ -1125,4 +1125,20 @@ partial class DiagnosticDescriptors isEnabledByDefault: true, description: "Methods from the Math and MathF types cannot be used in a shader, and equivalent APIs from the Hlsl type should be used instead.", helpLinkUri: "https://github.com/Sergio0694/ComputeSharp"); + + /// + /// Gets a for an invocation of a Math or MathF API. + /// + /// Format: "The shader {0} is not precompiled, but runtime compilation is not enabled (either precompile the shader by using [D2DShaderProfile], which is recommended, or enable runtime compilation using [D2DEnableRuntimeCompilation])". + /// + /// + public static readonly DiagnosticDescriptor D2DRuntimeCompilationDisabled = new( + id: "CMPSD2D0076", + title: "D2D runtime compilation disabled", + messageFormat: "The shader {0} is not precompiled, but runtime compilation is not enabled (either precompile the shader by using [D2DShaderProfile], which is recommended, or enable runtime compilation using [D2DEnableRuntimeCompilation])", + category: "ComputeSharp.D2D1.Shaders", + defaultSeverity: DiagnosticSeverity.Error, + isEnabledByDefault: true, + description: "Shaders must either be precompiled using [D2DShaderProfile], which is recommended, or runtime compilation for shaders must be enabled using [D2DEnableRuntimeCompilation].", + helpLinkUri: "https://github.com/Sergio0694/ComputeSharp"); } \ No newline at end of file From f603434310a7fab48d914f458b9905916e40d64a Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 16 Dec 2023 02:35:24 +0100 Subject: [PATCH 4/7] Add tests for D2DRuntimeCompilationDisabledAnalyzer --- .../Test_Analyzers.cs | 66 +++++++++++++++++++ .../Test_D2DPixelShaderSourceGenerator.cs | 11 ++++ 2 files changed, 77 insertions(+) diff --git a/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_Analyzers.cs b/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_Analyzers.cs index c5744a83..3ba72361 100644 --- a/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_Analyzers.cs +++ b/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_Analyzers.cs @@ -196,4 +196,70 @@ public class Test_Analyzers await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); } + + [TestMethod] + public async Task ShaderWithNoPrecompiledBytecode_WithNoD2DEnableRuntimeCompilation_Warns() + { + const string source = """ + using ComputeSharp; + using ComputeSharp.D2D1; + + [D2DInputCount(0)] + [D2DGeneratedPixelShaderDescriptor] + internal partial struct {|CMPSD2D0076:MyType|} : ID2D1PixelShader + { + public Float4 Execute() + { + return 0; + } + } + """; + + await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); + } + + [TestMethod] + public async Task ShaderWithNoPrecompiledBytecode_WithD2DEnableRuntimeCompilation_OnType_DoesNotWarn() + { + const string source = """ + using ComputeSharp; + using ComputeSharp.D2D1; + + [D2DInputCount(0)] + [D2DGeneratedPixelShaderDescriptor] + [D2DEnableRuntimeCompilation] + internal partial struct MyType : ID2D1PixelShader + { + public Float4 Execute() + { + return 0; + } + } + """; + + await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); + } + + [TestMethod] + public async Task ShaderWithNoPrecompiledBytecode_WithD2DEnableRuntimeCompilation_OnAssembly_DoesNotWarn() + { + const string source = """ + using ComputeSharp; + using ComputeSharp.D2D1; + + [assembly: D2DEnableRuntimeCompilation] + + [D2DInputCount(0)] + [D2DGeneratedPixelShaderDescriptor] + internal partial struct MyType : ID2D1PixelShader + { + public Float4 Execute() + { + return 0; + } + } + """; + + await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); + } } \ No newline at end of file diff --git a/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderSourceGenerator.cs b/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderSourceGenerator.cs index 6d4a81c8..7877840c 100644 --- a/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderSourceGenerator.cs +++ b/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderSourceGenerator.cs @@ -30,6 +30,8 @@ public class Test_D2DPixelShaderSourceGenerator using float3 = global::ComputeSharp.Float3; using float4 = global::ComputeSharp.Float4; + [assembly: D2DEnableRuntimeCompilation] + namespace MyNamespace; [D2DInputCount(0)] @@ -679,6 +681,8 @@ public class Test_D2DPixelShaderSourceGenerator using float3 = global::ComputeSharp.Float3; using float4 = global::ComputeSharp.Float4; + [assembly: D2DEnableRuntimeCompilation] + namespace MyNamespace; [D2DEffectId("B30E1384-DEE1-4200-9312-321521DF3B00")] @@ -985,6 +989,8 @@ public class Test_D2DPixelShaderSourceGenerator using float3 = global::ComputeSharp.Float3; using float4 = global::ComputeSharp.Float4; + [assembly: D2DEnableRuntimeCompilation] + namespace MyNamespace; [D2DInputCount(0)] @@ -1280,6 +1286,8 @@ public class Test_D2DPixelShaderSourceGenerator using ComputeSharp.D2D1; using float4 = global::ComputeSharp.Float4; + [assembly: D2DEnableRuntimeCompilation] + namespace MyNamespace; [D2DInputCount(2)] @@ -1566,6 +1574,8 @@ public class Test_D2DPixelShaderSourceGenerator using int2 = global::ComputeSharp.Int2; using float4 = global::ComputeSharp.Float4; + [assembly: D2DEnableRuntimeCompilation] + namespace MyNamespace; [D2DInputCount(0)] @@ -1802,6 +1812,7 @@ public class Test_D2DPixelShaderSourceGenerator private static async Task VerifyGeneratedDiagnosticsAsync(string source, (string Filename, string Source) result) { // Also validate all analyzers + await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); From 2d03612a1de511eac0ffa6cc32aaa5ae7baae9b9 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 16 Dec 2023 03:11:19 +0100 Subject: [PATCH 5/7] Add [D2DEnableRuntimeCompilation] to test projects --- tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderEffectTests.cs | 3 +++ .../Tests/PixelShaderEffectTests.cs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderEffectTests.cs b/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderEffectTests.cs index 1a426ebe..f28031b7 100644 --- a/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderEffectTests.cs +++ b/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderEffectTests.cs @@ -1,5 +1,6 @@ using System; using System.ComponentModel; +using ComputeSharp.D2D1; using ComputeSharp.D2D1.Interop; using ComputeSharp.D2D1.Tests.Effects; using ComputeSharp.D2D1.Tests.Helpers; @@ -7,6 +8,8 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; +[assembly: D2DEnableRuntimeCompilation] + #pragma warning disable IDE0022, IDE0044 namespace ComputeSharp.D2D1.Tests; diff --git a/tests/ComputeSharp.D2D1.WinUI.Tests/Tests/PixelShaderEffectTests.cs b/tests/ComputeSharp.D2D1.WinUI.Tests/Tests/PixelShaderEffectTests.cs index be42c656..830dfc69 100644 --- a/tests/ComputeSharp.D2D1.WinUI.Tests/Tests/PixelShaderEffectTests.cs +++ b/tests/ComputeSharp.D2D1.WinUI.Tests/Tests/PixelShaderEffectTests.cs @@ -1,6 +1,7 @@ using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using ComputeSharp.D2D1; using ComputeSharp.D2D1.Interop; using ComputeSharp.D2D1.WinUI.Tests.Helpers; using Microsoft.Graphics.Canvas; @@ -8,6 +9,8 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; +[assembly: D2DEnableRuntimeCompilation] + namespace ComputeSharp.D2D1.WinUI.Tests; [TestClass] From 3722eb3026191c555442e36c494bc591966230be Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 16 Dec 2023 13:19:55 +0100 Subject: [PATCH 6/7] Add more diagnostics for [D2DEnableRuntimeCompilation] --- .../AnalyzerReleases.Shipped.md | 2 + .../D2DRuntimeCompilationDisabledAnalyzer.cs | 45 +++++++++--- .../Diagnostics/DiagnosticDescriptors.cs | 34 ++++++++- .../Test_Analyzers.cs | 71 +++++++++++++++++++ 4 files changed, 143 insertions(+), 9 deletions(-) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/AnalyzerReleases.Shipped.md b/src/ComputeSharp.D2D1.SourceGenerators/AnalyzerReleases.Shipped.md index 33e24b45..32262bc6 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/AnalyzerReleases.Shipped.md +++ b/src/ComputeSharp.D2D1.SourceGenerators/AnalyzerReleases.Shipped.md @@ -83,3 +83,5 @@ CMPSD2D0073 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github CMPSD2D0074 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp) CMPSD2D0075 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp) CMPSD2D0076 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp) +CMPSD2D0077 | ComputeSharp.D2D1.Shaders | Info | [Documentation](https://github.com/Sergio0694/ComputeSharp) +CMPSD2D0078 | ComputeSharp.D2D1.Shaders | Warning | [Documentation](https://github.com/Sergio0694/ComputeSharp) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/D2DRuntimeCompilationDisabledAnalyzer.cs b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/D2DRuntimeCompilationDisabledAnalyzer.cs index 3041935b..f1d29829 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/D2DRuntimeCompilationDisabledAnalyzer.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/D2DRuntimeCompilationDisabledAnalyzer.cs @@ -14,7 +14,10 @@ namespace ComputeSharp.D2D1.SourceGenerators; public sealed class D2DRuntimeCompilationDisabledAnalyzer : DiagnosticAnalyzer { /// - public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create(D2DRuntimeCompilationDisabled); + public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create( + D2DRuntimeCompilationDisabled, + D2DRuntimeCompilationAlreadyEnabled, + D2DRuntimeCompilationNotNecessary); /// public override void Initialize(AnalysisContext context) @@ -46,17 +49,43 @@ public sealed class D2DRuntimeCompilationDisabledAnalyzer : DiagnosticAnalyzer return; } - // If the shader is being precompiled, we don't have anything else to do - if (typeSymbol.HasAttributeWithType(d2DShaderProfileAttributeSymbol) || - typeSymbol.ContainingAssembly.HasAttributeWithType(d2DShaderProfileAttributeSymbol)) + // This analyzer will detect the following cases: + // 1) Shader not precompiled, and missing [D2DEnableRuntimeCompilation] (D2DRuntimeCompilationDisabled) + // 2) Shader with [D2DEnableRuntimeCompilation] on the assembly and also on the shader type (D2DRuntimeCompilationAlreadyEnabled) + // 3) Shader being precompiled, but also with [D2DEnableRuntimeCompilation] (D2DRuntimeCompilationNotNecessary) + bool hasD2DShaderProfileAttributeOnAssembly = typeSymbol.ContainingAssembly.HasAttributeWithType(d2DShaderProfileAttributeSymbol); + bool hasD2DShaderProfileAttributeOnType = typeSymbol.HasAttributeWithType(d2DShaderProfileAttributeSymbol); + bool hasD2DEnableRuntimeCompilationAttributeOnAssembly = typeSymbol.ContainingAssembly.HasAttributeWithType(d2DEnableRuntimeCompilationAttributeSymbol); + bool hasD2DEnableRuntimeCompilationAttributeOnType = typeSymbol.TryGetAttributeWithType( + d2DEnableRuntimeCompilationAttributeSymbol, + out AttributeData? d2DEnableRuntimeCompilationAttributeData); + + // If [D2DEnableRuntimeCompilation] is present on the type and also on the assembly, emit a diagnostic (2) + if (hasD2DEnableRuntimeCompilationAttributeOnAssembly && hasD2DEnableRuntimeCompilationAttributeOnType) { - return; + context.ReportDiagnostic(Diagnostic.Create( + D2DRuntimeCompilationAlreadyEnabled, + d2DEnableRuntimeCompilationAttributeData!.GetLocation(), + typeSymbol)); } - // Emit a diagnostic if there is no [D2DEnableRuntimeCompilation] set anywhere - if (!typeSymbol.HasAttributeWithType(d2DEnableRuntimeCompilationAttributeSymbol) && - !typeSymbol.ContainingAssembly.HasAttributeWithType(d2DEnableRuntimeCompilationAttributeSymbol)) + // Check if the shader is precompiled: + // - If it is, we should check that it's not annotated with [D2DEnableRuntimeCompilation] + // - If it is not, we should check that it is annotated with [D2DEnableRuntimeCompilation] + if (hasD2DShaderProfileAttributeOnType || hasD2DShaderProfileAttributeOnAssembly) { + // Emit a diagnostic if [D2DEnableRuntimeCompilation] is present on the type (3) + if (hasD2DEnableRuntimeCompilationAttributeOnType) + { + context.ReportDiagnostic(Diagnostic.Create( + D2DRuntimeCompilationNotNecessary, + d2DEnableRuntimeCompilationAttributeData!.GetLocation(), + typeSymbol)); + } + } + else if (!hasD2DEnableRuntimeCompilationAttributeOnType && !hasD2DEnableRuntimeCompilationAttributeOnAssembly) + { + // Emit a diagnostic if there is no [D2DEnableRuntimeCompilation] set anywhere (1) context.ReportDiagnostic(Diagnostic.Create( D2DRuntimeCompilationDisabled, typeSymbol.Locations.FirstOrDefault(), diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs index ec267d8d..6002b367 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs @@ -1127,7 +1127,7 @@ partial class DiagnosticDescriptors helpLinkUri: "https://github.com/Sergio0694/ComputeSharp"); /// - /// Gets a for an invocation of a Math or MathF API. + /// Gets a for a shader not precompiled but with runtime compilation disabled. /// /// Format: "The shader {0} is not precompiled, but runtime compilation is not enabled (either precompile the shader by using [D2DShaderProfile], which is recommended, or enable runtime compilation using [D2DEnableRuntimeCompilation])". /// @@ -1141,4 +1141,36 @@ partial class DiagnosticDescriptors isEnabledByDefault: true, description: "Shaders must either be precompiled using [D2DShaderProfile], which is recommended, or runtime compilation for shaders must be enabled using [D2DEnableRuntimeCompilation].", helpLinkUri: "https://github.com/Sergio0694/ComputeSharp"); + + /// + /// Gets a for an unnecessary [D2DEnableRuntimeCompilation] use. + /// + /// Format: "The shader {0} is annotated with [D2DEnableRuntimeCompilation], but its containing assembly is already annotated with this attribute (so using it again on the shader type is unnecessary)". + /// + /// + public static readonly DiagnosticDescriptor D2DRuntimeCompilationAlreadyEnabled = new( + id: "CMPSD2D0077", + title: "D2D runtime compilation already enabled", + messageFormat: "The shader {0} is annotated with [D2DEnableRuntimeCompilation], but its containing assembly is already annotated with this attribute (so using it again on the shader type is unnecessary)", + category: "ComputeSharp.D2D1.Shaders", + defaultSeverity: DiagnosticSeverity.Info, + isEnabledByDefault: true, + description: "If an assembly is annotated with [D2DEnableRuntimeCompilation], that applies to all shader types within it. That means that using [D2DEnableRuntimeCompilation] on shader types too is unnecessary.", + helpLinkUri: "https://github.com/Sergio0694/ComputeSharp"); + + /// + /// Gets a for an unnecessary [D2DEnableRuntimeCompilation] use. + /// + /// Format: "The shader {0} is annotated with [D2DEnableRuntimeCompilation], but it is also being precompiled, as it has [D2DShaderProfile] on the type or containing assembly (so using [D2DEnableRuntimeCompilation] is unnecessary)". + /// + /// + public static readonly DiagnosticDescriptor D2DRuntimeCompilationNotNecessary = new( + id: "CMPSD2D0078", + title: "D2D runtime compilation is not necessary", + messageFormat: "The shader {0} is annotated with [D2DEnableRuntimeCompilation], but it is also being precompiled, as it has [D2DShaderProfile] on the type or containing assembly (so using [D2DEnableRuntimeCompilation] is unnecessary)", + category: "ComputeSharp.D2D1.Shaders", + defaultSeverity: DiagnosticSeverity.Warning, + isEnabledByDefault: true, + description: "If a shader is precompiled (ie. it has [D2DShaderProfile] on the type declaration or on its containing assembly), also using [D2DEnableRuntimeCompilation] is unnecessary.", + helpLinkUri: "https://github.com/Sergio0694/ComputeSharp"); } \ No newline at end of file diff --git a/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_Analyzers.cs b/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_Analyzers.cs index 3ba72361..d322b56c 100644 --- a/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_Analyzers.cs +++ b/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_Analyzers.cs @@ -262,4 +262,75 @@ public class Test_Analyzers await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); } + + [TestMethod] + public async Task ShaderWithNoPrecompiledBytecode_WithUnnecessaryD2DEnableRuntimeCompilation_Warns() + { + const string source = """ + using ComputeSharp; + using ComputeSharp.D2D1; + + [assembly: D2DEnableRuntimeCompilation] + + [D2DInputCount(0)] + [{|CMPSD2D0077:D2DEnableRuntimeCompilation|}] + [D2DGeneratedPixelShaderDescriptor] + internal partial struct MyType : ID2D1PixelShader + { + public Float4 Execute() + { + return 0; + } + } + """; + + await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); + } + + [TestMethod] + public async Task ShaderWithPrecompiledBytecode_FromAssembly_WithUnnecessaryD2DEnableRuntimeCompilation_Warns() + { + const string source = """ + using ComputeSharp; + using ComputeSharp.D2D1; + + [assembly: D2DShaderProfile(D2D1ShaderProfile.PixelShader50)] + + [D2DInputCount(0)] + [{|CMPSD2D0078:D2DEnableRuntimeCompilation|}] + [D2DGeneratedPixelShaderDescriptor] + internal partial struct MyType : ID2D1PixelShader + { + public Float4 Execute() + { + return 0; + } + } + """; + + await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); + } + + [TestMethod] + public async Task ShaderWithPrecompiledBytecode_FromType_WithUnnecessaryD2DEnableRuntimeCompilation_Warns() + { + const string source = """ + using ComputeSharp; + using ComputeSharp.D2D1; + + [D2DInputCount(0)] + [D2DShaderProfile(D2D1ShaderProfile.PixelShader50)] + [{|CMPSD2D0078:D2DEnableRuntimeCompilation|}] + [D2DGeneratedPixelShaderDescriptor] + internal partial struct MyType : ID2D1PixelShader + { + public Float4 Execute() + { + return 0; + } + } + """; + + await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); + } } \ No newline at end of file From 8474eec869c2cf210f4f321a8f73450f38a27163 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 16 Dec 2023 13:30:58 +0100 Subject: [PATCH 7/7] Add D2DEnableRuntimeCompilationOnAssemblyAnalyzer and tests --- .../AnalyzerReleases.Shipped.md | 1 + ...bleRuntimeCompilationOnAssemblyAnalyzer.cs | 39 +++++++++++++++++++ ...EnableRuntimeCompilationOnTypeAnalyzer.cs} | 8 ++-- .../Diagnostics/DiagnosticDescriptors.cs | 23 +++++++++-- .../Test_Analyzers.cs | 25 +++++++++--- .../Test_D2DPixelShaderSourceGenerator.cs | 3 +- 6 files changed, 85 insertions(+), 14 deletions(-) create mode 100644 src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/D2DEnableRuntimeCompilationOnAssemblyAnalyzer.cs rename src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/{D2DRuntimeCompilationDisabledAnalyzer.cs => D2DEnableRuntimeCompilationOnTypeAnalyzer.cs} (94%) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/AnalyzerReleases.Shipped.md b/src/ComputeSharp.D2D1.SourceGenerators/AnalyzerReleases.Shipped.md index 32262bc6..45dfa3bb 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/AnalyzerReleases.Shipped.md +++ b/src/ComputeSharp.D2D1.SourceGenerators/AnalyzerReleases.Shipped.md @@ -85,3 +85,4 @@ CMPSD2D0075 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github CMPSD2D0076 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp) CMPSD2D0077 | ComputeSharp.D2D1.Shaders | Info | [Documentation](https://github.com/Sergio0694/ComputeSharp) CMPSD2D0078 | ComputeSharp.D2D1.Shaders | Warning | [Documentation](https://github.com/Sergio0694/ComputeSharp) +CMPSD2D0079 | ComputeSharp.D2D1.Shaders | Warning | [Documentation](https://github.com/Sergio0694/ComputeSharp) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/D2DEnableRuntimeCompilationOnAssemblyAnalyzer.cs b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/D2DEnableRuntimeCompilationOnAssemblyAnalyzer.cs new file mode 100644 index 00000000..bed88bf1 --- /dev/null +++ b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/D2DEnableRuntimeCompilationOnAssemblyAnalyzer.cs @@ -0,0 +1,39 @@ +using System.Collections.Immutable; +using ComputeSharp.SourceGeneration.Extensions; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Diagnostics; +using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors; + +namespace ComputeSharp.D2D1.SourceGenerators; + +/// +/// A diagnostic analyzer that generates diagnostics for the [D2DEnableRuntimeCompilation] attribute, when used on an assembly. +/// +[DiagnosticAnalyzer(LanguageNames.CSharp)] +public sealed class D2DEnableRuntimeCompilationOnAssemblyAnalyzer : DiagnosticAnalyzer +{ + /// + public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create(D2DRuntimeCompilationOnAssemblyNotNecessary); + + /// + public override void Initialize(AnalysisContext context) + { + context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics); + context.EnableConcurrentExecution(); + + context.RegisterCompilationAction(static context => + { + IAssemblySymbol assemblySymbol = context.Compilation.Assembly; + + // Emit a diagnostic if an assembly has both [D2DShaderProfile] and [D2DEnableRuntimeCompilation] (the latter is useless) + if (assemblySymbol.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DShaderProfileAttribute", out _) && + assemblySymbol.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DEnableRuntimeCompilationAttribute", out AttributeData? attributeData)) + { + context.ReportDiagnostic(Diagnostic.Create( + D2DRuntimeCompilationOnAssemblyNotNecessary, + attributeData.GetLocation(), + assemblySymbol)); + } + }); + } +} \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/D2DRuntimeCompilationDisabledAnalyzer.cs b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/D2DEnableRuntimeCompilationOnTypeAnalyzer.cs similarity index 94% rename from src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/D2DRuntimeCompilationDisabledAnalyzer.cs rename to src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/D2DEnableRuntimeCompilationOnTypeAnalyzer.cs index f1d29829..2d64da80 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/D2DRuntimeCompilationDisabledAnalyzer.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/D2DEnableRuntimeCompilationOnTypeAnalyzer.cs @@ -8,16 +8,16 @@ using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors; namespace ComputeSharp.D2D1.SourceGenerators; /// -/// A diagnostic analyzer that generates an error whenever a shader is not precompiled but runtime compilation is not enabled. +/// A diagnostic analyzer that generates diagnostics for the [D2DEnableRuntimeCompilation] attribute, when used on a type. /// [DiagnosticAnalyzer(LanguageNames.CSharp)] -public sealed class D2DRuntimeCompilationDisabledAnalyzer : DiagnosticAnalyzer +public sealed class D2DEnableRuntimeCompilationOnTypeAnalyzer : DiagnosticAnalyzer { /// public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create( D2DRuntimeCompilationDisabled, D2DRuntimeCompilationAlreadyEnabled, - D2DRuntimeCompilationNotNecessary); + D2DRuntimeCompilationOnTypeNotNecessary); /// public override void Initialize(AnalysisContext context) @@ -78,7 +78,7 @@ public sealed class D2DRuntimeCompilationDisabledAnalyzer : DiagnosticAnalyzer if (hasD2DEnableRuntimeCompilationAttributeOnType) { context.ReportDiagnostic(Diagnostic.Create( - D2DRuntimeCompilationNotNecessary, + D2DRuntimeCompilationOnTypeNotNecessary, d2DEnableRuntimeCompilationAttributeData!.GetLocation(), typeSymbol)); } diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs index 6002b367..e76019d2 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs @@ -1159,18 +1159,35 @@ partial class DiagnosticDescriptors helpLinkUri: "https://github.com/Sergio0694/ComputeSharp"); /// - /// Gets a for an unnecessary [D2DEnableRuntimeCompilation] use. + /// Gets a for an unnecessary [D2DEnableRuntimeCompilation] use on . /// /// Format: "The shader {0} is annotated with [D2DEnableRuntimeCompilation], but it is also being precompiled, as it has [D2DShaderProfile] on the type or containing assembly (so using [D2DEnableRuntimeCompilation] is unnecessary)". /// /// - public static readonly DiagnosticDescriptor D2DRuntimeCompilationNotNecessary = new( + public static readonly DiagnosticDescriptor D2DRuntimeCompilationOnTypeNotNecessary = new( id: "CMPSD2D0078", - title: "D2D runtime compilation is not necessary", + title: "D2D runtime compilation on type is not necessary", messageFormat: "The shader {0} is annotated with [D2DEnableRuntimeCompilation], but it is also being precompiled, as it has [D2DShaderProfile] on the type or containing assembly (so using [D2DEnableRuntimeCompilation] is unnecessary)", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Warning, isEnabledByDefault: true, description: "If a shader is precompiled (ie. it has [D2DShaderProfile] on the type declaration or on its containing assembly), also using [D2DEnableRuntimeCompilation] is unnecessary.", helpLinkUri: "https://github.com/Sergio0694/ComputeSharp"); + + /// + /// Gets a for an unnecessary [D2DEnableRuntimeCompilation] use on an assembly. + /// + /// Format: "The assembly {0} is annotated with [D2DEnableRuntimeCompilation], but it is also has an assembly-level [D2DShaderProfile] attribute, which will cause all shaders to be precompiled (so using [D2DEnableRuntimeCompilation] is unnecessary)". + /// + /// + public static readonly DiagnosticDescriptor D2DRuntimeCompilationOnAssemblyNotNecessary = new( + id: "CMPSD2D0079", + title: "D2D runtime compilation on assembly is not necessary", + messageFormat: "The assembly {0} is annotated with [D2DEnableRuntimeCompilation], but it is also has an assembly-level [D2DShaderProfile] attribute, which will cause all shaders to be precompiled (so using [D2DEnableRuntimeCompilation] is unnecessary)", + category: "ComputeSharp.D2D1.Shaders", + defaultSeverity: DiagnosticSeverity.Warning, + isEnabledByDefault: true, + description: "If an assembly is using [D2DShaderProfile] (meaning that all shaders declared within it will be precompiled), also using [D2DEnableRuntimeCompilation] is unnecessary.", + helpLinkUri: "https://github.com/Sergio0694/ComputeSharp", + customTags: WellKnownDiagnosticTags.CompilationEnd); } \ No newline at end of file diff --git a/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_Analyzers.cs b/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_Analyzers.cs index d322b56c..cc4e3c5f 100644 --- a/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_Analyzers.cs +++ b/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_Analyzers.cs @@ -215,7 +215,7 @@ public class Test_Analyzers } """; - await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); + await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); } [TestMethod] @@ -237,7 +237,7 @@ public class Test_Analyzers } """; - await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); + await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); } [TestMethod] @@ -260,7 +260,7 @@ public class Test_Analyzers } """; - await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); + await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); } [TestMethod] @@ -284,7 +284,7 @@ public class Test_Analyzers } """; - await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); + await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); } [TestMethod] @@ -308,7 +308,7 @@ public class Test_Analyzers } """; - await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); + await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); } [TestMethod] @@ -331,6 +331,19 @@ public class Test_Analyzers } """; - await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); + await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); + } + + [TestMethod] + public async Task UnnecessaryD2DEnableRuntimeCompilation_OnAssembly_Warns() + { + const string source = """ + using ComputeSharp.D2D1; + + [assembly: D2DShaderProfile(D2D1ShaderProfile.PixelShader50)] + [assembly: {|CMPSD2D0079:D2DEnableRuntimeCompilation|}] + """; + + await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); } } \ No newline at end of file diff --git a/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderSourceGenerator.cs b/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderSourceGenerator.cs index 7877840c..d9d60411 100644 --- a/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderSourceGenerator.cs +++ b/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderSourceGenerator.cs @@ -1812,7 +1812,8 @@ public class Test_D2DPixelShaderSourceGenerator private static async Task VerifyGeneratedDiagnosticsAsync(string source, (string Filename, string Source) result) { // Also validate all analyzers - await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); + await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); + await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source);