From 228a4006a6b64e9ca3e2465ceef355884e0b65b6 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 15 Oct 2023 21:15:51 +0200 Subject: [PATCH 01/14] Add [GeneratedComputeShaderDescriptor] type --- ...neratedComputeShaderDescriptorAttribute.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/ComputeSharp/Core/Attributes/GeneratedComputeShaderDescriptorAttribute.cs diff --git a/src/ComputeSharp/Core/Attributes/GeneratedComputeShaderDescriptorAttribute.cs b/src/ComputeSharp/Core/Attributes/GeneratedComputeShaderDescriptorAttribute.cs new file mode 100644 index 00000000..f92c1fe2 --- /dev/null +++ b/src/ComputeSharp/Core/Attributes/GeneratedComputeShaderDescriptorAttribute.cs @@ -0,0 +1,27 @@ +using System; + +namespace ComputeSharp; + +/// +/// An attribute that indicates that a given compute shader should have its associated descriptor code being generated. +/// +/// This attribute can be used on shader types that are declared as : +/// +/// [GeneratedComputeShaderDescriptor] +/// partial struct MyShader : IComputeShader +/// { +/// } +/// +/// +/// +/// The shader type must implement either or . +/// +/// +/// When a shader is annotated with , the source generator will also add +/// to its implemented interfaces, and implement its APIs automatically. +/// +/// +[AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)] +public sealed class GeneratedComputeShaderDescriptorAttribute : Attribute +{ +} \ No newline at end of file From 6fe1ee57430a33472609498df1cba24a11e7baaf Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 15 Oct 2023 21:18:33 +0200 Subject: [PATCH 02/14] Switch D3D12 generator to use FAWMN on new attribute --- .../D2DPixelShaderDescriptorGenerator.cs | 4 +--- .../ComputeShaderDescriptorGenerator.cs | 10 ++++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.cs index 9ef3b213..5ddf70ba 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.cs @@ -43,8 +43,6 @@ public sealed partial class D2DPixelShaderDescriptorGenerator : IIncrementalGene return default; } - StructDeclarationSyntax typeDeclaration = (StructDeclarationSyntax)context.TargetNode; - // Check that the shader implements the ID2D1PixelShader interface if (!typeSymbol.HasInterfaceWithType(context.SemanticModel.Compilation.GetTypeByMetadataName("ComputeSharp.D2D1.ID2D1PixelShader")!)) { @@ -110,7 +108,7 @@ public sealed partial class D2DPixelShaderDescriptorGenerator : IIncrementalGene string hlslSource = HlslSource.GetHlslSource( diagnostics, context.SemanticModel.Compilation, - typeDeclaration, + (StructDeclarationSyntax)context.TargetNode, typeSymbol, inputCount, inputSimpleIndices, diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.cs index 50d63776..f81d68b9 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.cs @@ -5,7 +5,6 @@ using ComputeSharp.SourceGeneration.Helpers; using ComputeSharp.SourceGeneration.Models; using ComputeSharp.SourceGenerators.Models; using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; namespace ComputeSharp.SourceGenerators; @@ -27,7 +26,8 @@ public sealed partial class ComputeShaderDescriptorGenerator : IIncrementalGener // Discover all shader types and extract all the necessary info from each of them IncrementalValuesProvider shaderInfo = context.SyntaxProvider - .CreateSyntaxProvider( + .ForAttributeWithMetadataName( + "ComputeSharp.GeneratedComputeShaderDescriptorAttribute", static (node, _) => node.IsTypeDeclarationWithOrPotentiallyWithBaseTypes(), static (context, token) => { @@ -37,10 +37,8 @@ public sealed partial class ComputeShaderDescriptorGenerator : IIncrementalGener return default; } - StructDeclarationSyntax typeDeclaration = (StructDeclarationSyntax)context.Node; - // If the type symbol doesn't have at least one interface, it can't possibly be a shader type - if (context.SemanticModel.GetDeclaredSymbol(typeDeclaration, token) is not INamedTypeSymbol { AllInterfaces.Length: > 0 } typeSymbol) + if (context.TargetSymbol is not INamedTypeSymbol { AllInterfaces.Length: > 0 } typeSymbol) { return default; } @@ -78,7 +76,7 @@ public sealed partial class ComputeShaderDescriptorGenerator : IIncrementalGener HlslSource.GetInfo( diagnostics, context.SemanticModel.Compilation, - typeDeclaration, + (StructDeclarationSyntax)context.TargetNode, typeSymbol, threadsX, threadsY, From 6baf3339fe224f19f66a18f20028f3f0a64e08fd Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 15 Oct 2023 21:24:06 +0200 Subject: [PATCH 03/14] Add MissingComputeShaderDescriptorOnComputeShaderAnalyzer --- .../AnalyzerReleases.Shipped.md | 1 + ...ShaderDescriptorOnComputeShaderAnalyzer.cs | 63 +++++++++++++++++++ .../Diagnostics/DiagnosticDescriptors.cs | 22 +++++++ 3 files changed, 86 insertions(+) create mode 100644 src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/MissingComputeShaderDescriptorOnComputeShaderAnalyzer.cs diff --git a/src/ComputeSharp.SourceGenerators/AnalyzerReleases.Shipped.md b/src/ComputeSharp.SourceGenerators/AnalyzerReleases.Shipped.md index fadd3bb7..d910c18f 100644 --- a/src/ComputeSharp.SourceGenerators/AnalyzerReleases.Shipped.md +++ b/src/ComputeSharp.SourceGenerators/AnalyzerReleases.Shipped.md @@ -58,3 +58,4 @@ CMPS0049 | ComputeSharp.Shaders | Error | [Documentation](https://github.com/Ser CMPS0050 | ComputeSharp.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp) CMPS0051 | ComputeSharp | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp) CMPS0052 | ComputeSharp.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp) +CMPS0053 | ComputeSharp.Shaders | Warning | [Documentation](https://github.com/Sergio0694/ComputeSharp) diff --git a/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/MissingComputeShaderDescriptorOnComputeShaderAnalyzer.cs b/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/MissingComputeShaderDescriptorOnComputeShaderAnalyzer.cs new file mode 100644 index 00000000..85b64d60 --- /dev/null +++ b/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/MissingComputeShaderDescriptorOnComputeShaderAnalyzer.cs @@ -0,0 +1,63 @@ +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 a warning whenever a compute shader type does not have an associated descriptor. +/// +[DiagnosticAnalyzer(LanguageNames.CSharp)] +public sealed class MissingComputeShaderDescriptorOnComputeShaderAnalyzer : DiagnosticAnalyzer +{ + /// + public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create(MissingComputeShaderDescriptorOnComputeShaderType); + + /// + public override void Initialize(AnalysisContext context) + { + context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics); + context.EnableConcurrentExecution(); + + context.RegisterCompilationStartAction(static context => + { + // Get the IComputeShader, IComputeShader, IComputeShaderDescriptor and [GeneratedComputeShaderDescriptor] symbols + if (context.Compilation.GetTypeByMetadataName("ComputeSharp.IComputeShader") is not { } computeShaderSymbol || + context.Compilation.GetTypeByMetadataName("ComputeSharp.IComputeShader`1") is not { } pixelShaderSymbol || + context.Compilation.GetTypeByMetadataName("ComputeSharp.Descriptors.IComputeShaderDescriptor`1") is not { } computeShaderDescriptorSymbol || + context.Compilation.GetTypeByMetadataName("ComputeSharp.GeneratedComputeShaderDescriptorAttribute") is not { } generatedComputeShaderDescriptorAttributeSymbol) + { + return; + } + + context.RegisterSymbolAction(context => + { + // Only struct types are possible targets + if (context.Symbol is not INamedTypeSymbol { TypeKind: TypeKind.Struct } typeSymbol) + { + return; + } + + // If the type is not a compute shader type, immediately bail out + if (!typeSymbol.HasInterfaceWithType(computeShaderSymbol) && + !typeSymbol.HasInterfaceWithType(pixelShaderSymbol)) + { + return; + } + + // Emit a diagnostic if the descriptor is missing for the shader type + if (!typeSymbol.HasInterfaceWithType(computeShaderDescriptorSymbol) && + !typeSymbol.HasAttributeWithType(generatedComputeShaderDescriptorAttributeSymbol)) + { + context.ReportDiagnostic(Diagnostic.Create( + MissingComputeShaderDescriptorOnComputeShaderType, + typeSymbol.Locations.FirstOrDefault(), + typeSymbol)); + } + }, SymbolKind.NamedType); + }); + } +} \ No newline at end of file diff --git a/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs b/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs index 084ae35b..0fccd0c0 100644 --- a/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs +++ b/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs @@ -7,6 +7,11 @@ namespace ComputeSharp.SourceGeneration.Diagnostics; /// partial class DiagnosticDescriptors { + /// + /// The diagnostic id for . + /// + public const string MissingComputeShaderDescriptorOnComputeShaderTypeId = "CMPS0053"; + /// /// Gets a for an invalid shader field. /// @@ -730,4 +735,21 @@ partial class DiagnosticDescriptors description: "Unsafe blocks must be enabled for the source generators to emit valid code (the true option must be set in the .csproj/.props file).", helpLinkUri: "https://github.com/Sergio0694/ComputeSharp", customTags: WellKnownDiagnosticTags.CompilationEnd); + + /// + /// Gets a for when a compute shader type doesn't have an associated descriptor. + /// + /// Format: "The compute shader of type {0} does not have an associated descriptor (it can be autogenerated via the [GeneratedComputeShaderDescriptor] attribute)". + /// + /// + public static readonly DiagnosticDescriptor MissingComputeShaderDescriptorOnComputeShaderType = new DiagnosticDescriptor( + id: MissingComputeShaderDescriptorOnComputeShaderTypeId, + title: "Missing descriptor for compute pixel shader type", + messageFormat: "The compute shader of type {0} does not have an associated descriptor (it can be autogenerated via the [GeneratedComputeShaderDescriptor] attribute)", + category: "ComputeSharp.Shaders", + defaultSeverity: DiagnosticSeverity.Warning, + isEnabledByDefault: true, + description: "All compute shader types must have an associated descriptor (it can be autogenerated via the [GeneratedComputeShaderDescriptor] attribute).", + helpLinkUri: "https://github.com/Sergio0694/ComputeSharp", + customTags: WellKnownDiagnosticTags.CompilationEnd); } \ No newline at end of file From 876e261f6b958b88a1465bd03ac9a9155c35ab6f Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 15 Oct 2023 23:05:35 +0200 Subject: [PATCH 04/14] Add InvalidGeneratedComputeShaderDescriptorAttributeTargetAnalyzer --- .../AnalyzerReleases.Shipped.md | 1 + ...ShaderDescriptorAttributeTargetAnalyzer.cs | 55 +++++++++++++++++++ ...ShaderDescriptorOnComputeShaderAnalyzer.cs | 2 +- .../Diagnostics/DiagnosticDescriptors.cs | 16 ++++++ 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/InvalidGeneratedComputeShaderDescriptorAttributeTargetAnalyzer.cs diff --git a/src/ComputeSharp.SourceGenerators/AnalyzerReleases.Shipped.md b/src/ComputeSharp.SourceGenerators/AnalyzerReleases.Shipped.md index d910c18f..5afa651d 100644 --- a/src/ComputeSharp.SourceGenerators/AnalyzerReleases.Shipped.md +++ b/src/ComputeSharp.SourceGenerators/AnalyzerReleases.Shipped.md @@ -59,3 +59,4 @@ CMPS0050 | ComputeSharp.Shaders | Error | [Documentation](https://github.com/Ser CMPS0051 | ComputeSharp | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp) CMPS0052 | ComputeSharp.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp) CMPS0053 | ComputeSharp.Shaders | Warning | [Documentation](https://github.com/Sergio0694/ComputeSharp) +CMPS0054 | ComputeSharp.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp) diff --git a/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/InvalidGeneratedComputeShaderDescriptorAttributeTargetAnalyzer.cs b/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/InvalidGeneratedComputeShaderDescriptorAttributeTargetAnalyzer.cs new file mode 100644 index 00000000..c5868a6a --- /dev/null +++ b/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/InvalidGeneratedComputeShaderDescriptorAttributeTargetAnalyzer.cs @@ -0,0 +1,55 @@ +using System.Collections.Immutable; +using ComputeSharp.SourceGeneration.Extensions; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Diagnostics; +using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors; + +namespace ComputeSharp.SourceGenerators; + +/// +/// A diagnostic analyzer that generates an error whenever the [GeneratedComputeShaderDescriptor] attribute is used on an invalid target type. +/// +[DiagnosticAnalyzer(LanguageNames.CSharp)] +public sealed class InvalidGeneratedComputeShaderDescriptorAttributeTargetAnalyzer : DiagnosticAnalyzer +{ + /// + public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create(InvalidD2DGeneratedPixelShaderDescriptorAttributeTarget); + + /// + public override void Initialize(AnalysisContext context) + { + context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics); + context.EnableConcurrentExecution(); + + context.RegisterCompilationStartAction(static context => + { + // Get the IComputeShader, IComputeShader and [GeneratedComputeShaderDescriptor] symbols + if (context.Compilation.GetTypeByMetadataName("ComputeSharp.IComputeShader") is not { } computeShaderSymbol || + context.Compilation.GetTypeByMetadataName("ComputeSharp.IComputeShader`1") is not { } pixelShaderSymbol || + context.Compilation.GetTypeByMetadataName("ComputeSharp.GeneratedComputeShaderDescriptorAttribute") is not { } generatedComputeShaderDescriptorAttributeSymbol) + { + return; + } + + context.RegisterSymbolAction(context => + { + // Only struct types are possible targets + if (context.Symbol is not INamedTypeSymbol { TypeKind: TypeKind.Struct } typeSymbol) + { + return; + } + + // Emit a diagnostic if the target type is using [GeneratedComputeShaderDescriptor] but does not implement IComputeShader nor IComputeShader + if (typeSymbol.TryGetAttributeWithType(generatedComputeShaderDescriptorAttributeSymbol, out AttributeData? attribute) && + !typeSymbol.HasInterfaceWithType(computeShaderSymbol) && + !typeSymbol.HasInterfaceWithType(pixelShaderSymbol)) + { + context.ReportDiagnostic(Diagnostic.Create( + InvalidD2DGeneratedPixelShaderDescriptorAttributeTarget, + attribute.GetLocation(), + typeSymbol)); + } + }, SymbolKind.NamedType); + }); + } +} \ No newline at end of file diff --git a/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/MissingComputeShaderDescriptorOnComputeShaderAnalyzer.cs b/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/MissingComputeShaderDescriptorOnComputeShaderAnalyzer.cs index 85b64d60..b4030c41 100644 --- a/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/MissingComputeShaderDescriptorOnComputeShaderAnalyzer.cs +++ b/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/MissingComputeShaderDescriptorOnComputeShaderAnalyzer.cs @@ -5,7 +5,7 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors; -namespace ComputeSharp.D2D1.SourceGenerators; +namespace ComputeSharp.SourceGenerators; /// /// A diagnostic analyzer that generates a warning whenever a compute shader type does not have an associated descriptor. diff --git a/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs b/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs index 0fccd0c0..e6467719 100644 --- a/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs +++ b/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs @@ -752,4 +752,20 @@ partial class DiagnosticDescriptors description: "All compute shader types must have an associated descriptor (it can be autogenerated via the [GeneratedComputeShaderDescriptor] attribute).", helpLinkUri: "https://github.com/Sergio0694/ComputeSharp", customTags: WellKnownDiagnosticTags.CompilationEnd); + + /// + /// Gets a for when the [GeneratedComputeShaderDescriptor] attribute is being used on an invalid target type. + /// + /// Format: "The type {0} is not a valid target for the [GeneratedComputeShaderDescriptor] attribute (only types implementing the IComputeShader or IComputeShader<TPixel> interface are valid)". + /// + /// + public static readonly DiagnosticDescriptor InvalidD2DGeneratedPixelShaderDescriptorAttributeTarget = new DiagnosticDescriptor( + id: "CMPS0054", + title: "Invalid [GeneratedComputeShaderDescriptor] attribute target", + messageFormat: "The type {0} is not a valid target for the [GeneratedComputeShaderDescriptor] attribute (only types implementing the IComputeShader or IComputeShader interface are valid)", + category: "ComputeSharp.Shaders", + defaultSeverity: DiagnosticSeverity.Error, + isEnabledByDefault: true, + description: "The [GeneratedComputeShaderDescriptor] attribute must be used on types that implement the IComputeShader or IComputeShader interfaces.", + helpLinkUri: "https://github.com/Sergio0694/ComputeSharp"); } \ No newline at end of file From 827f1b9eca77d000c43b934babab4ce1f6ff9d66 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 16 Oct 2023 10:29:35 +0200 Subject: [PATCH 05/14] Add blank ComputeSharp.CodeFixing project --- ComputeSharp.sln | 3 +++ .../ComputeSharp.CodeFixing.projitems | 13 +++++++++++++ .../ComputeSharp.CodeFixing.shproj | 13 +++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 src/ComputeSharp.CodeFixing/ComputeSharp.CodeFixing.projitems create mode 100644 src/ComputeSharp.CodeFixing/ComputeSharp.CodeFixing.shproj diff --git a/ComputeSharp.sln b/ComputeSharp.sln index 6b1ac99f..778f57a2 100644 --- a/ComputeSharp.sln +++ b/ComputeSharp.sln @@ -146,6 +146,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.D2D1.Tests.Sou EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Win32", "Win32", "{D991153C-A34D-4042-B76F-822ADB111DD0}" EndProject +Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "ComputeSharp.CodeFixing", "src\ComputeSharp.CodeFixing\ComputeSharp.CodeFixing.shproj", "{29F6E256-BA0E-4F3B-854E-50839D67C6DD}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -463,6 +465,7 @@ Global samples\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems*{0071701e-b9c5-4098-be5f-ef556c4553c6}*SharedItemsImports = 5 samples\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems*{0800bd51-499d-44c2-9417-fd1f7fdfe9c4}*SharedItemsImports = 13 samples\ComputeSharp.SwapChain.Shaders.D2D1.Shared\ComputeSharp.SwapChain.Shaders.D2D1.Shared.projitems*{209c95a3-fa53-431b-b688-3299ca6c29d2}*SharedItemsImports = 5 + src\ComputeSharp.CodeFixing\ComputeSharp.CodeFixing.projitems*{29f6e256-ba0e-4f3b-854e-50839d67c6dd}*SharedItemsImports = 13 src\ComputeSharp.Win32.D2D1\ComputeSharp.Win32.D2D1.projitems*{4d7d9ba8-a821-4b1c-9ee2-cbcf5849906e}*SharedItemsImports = 5 src\ComputeSharp.Win32.D3D12\ComputeSharp.Win32.D3D12.projitems*{514ff00e-bbf0-4d55-a47c-eeeb6208adce}*SharedItemsImports = 13 src\ComputeSharp.SourceGeneration\ComputeSharp.SourceGeneration.projitems*{51d5a422-d3a5-4c4d-8a6d-a048940bf279}*SharedItemsImports = 13 diff --git a/src/ComputeSharp.CodeFixing/ComputeSharp.CodeFixing.projitems b/src/ComputeSharp.CodeFixing/ComputeSharp.CodeFixing.projitems new file mode 100644 index 00000000..98ea93eb --- /dev/null +++ b/src/ComputeSharp.CodeFixing/ComputeSharp.CodeFixing.projitems @@ -0,0 +1,13 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + 29f6e256-ba0e-4f3b-854e-50839d67c6dd + + + ComputeSharp.CodeFixing + + + + diff --git a/src/ComputeSharp.CodeFixing/ComputeSharp.CodeFixing.shproj b/src/ComputeSharp.CodeFixing/ComputeSharp.CodeFixing.shproj new file mode 100644 index 00000000..5edbba72 --- /dev/null +++ b/src/ComputeSharp.CodeFixing/ComputeSharp.CodeFixing.shproj @@ -0,0 +1,13 @@ + + + + 29f6e256-ba0e-4f3b-854e-50839d67c6dd + 14.0 + + + + + + + + From 01c15bcba164121d0243d81e947d88da0f2a7d8e Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 16 Oct 2023 10:39:49 +0200 Subject: [PATCH 06/14] Add MissingAttributeCodeFixer type --- ComputeSharp.sln | 1 + .../ComputeSharp.CodeFixing.projitems | 3 +- .../MissingAttributeCodeFixer.cs | 235 ++++++++++++++++++ .../ComputeSharp.D2D1.CodeFixers.csproj | 2 + 4 files changed, 240 insertions(+), 1 deletion(-) create mode 100644 src/ComputeSharp.CodeFixing/MissingAttributeCodeFixer.cs diff --git a/ComputeSharp.sln b/ComputeSharp.sln index 778f57a2..2c8e64eb 100644 --- a/ComputeSharp.sln +++ b/ComputeSharp.sln @@ -469,6 +469,7 @@ Global src\ComputeSharp.Win32.D2D1\ComputeSharp.Win32.D2D1.projitems*{4d7d9ba8-a821-4b1c-9ee2-cbcf5849906e}*SharedItemsImports = 5 src\ComputeSharp.Win32.D3D12\ComputeSharp.Win32.D3D12.projitems*{514ff00e-bbf0-4d55-a47c-eeeb6208adce}*SharedItemsImports = 13 src\ComputeSharp.SourceGeneration\ComputeSharp.SourceGeneration.projitems*{51d5a422-d3a5-4c4d-8a6d-a048940bf279}*SharedItemsImports = 13 + src\ComputeSharp.CodeFixing\ComputeSharp.CodeFixing.projitems*{54654960-54b5-4e19-b3ed-993591ca39e5}*SharedItemsImports = 5 samples\ComputeSharp.SwapChain.Shaders.D2D1.Shared\ComputeSharp.SwapChain.Shaders.D2D1.Shared.projitems*{73c32d0f-64db-4674-84e9-8fcc41228474}*SharedItemsImports = 5 src\ComputeSharp.SourceGeneration.Hlsl\ComputeSharp.SourceGeneration.Hlsl.projitems*{9ac496a3-bbf0-4c8f-a50d-a20bf01c5e05}*SharedItemsImports = 13 src\ComputeSharp.Win32.D2D1\ComputeSharp.Win32.D2D1.projitems*{9da1da9f-f8b2-4b25-be80-c21f773029e3}*SharedItemsImports = 13 diff --git a/src/ComputeSharp.CodeFixing/ComputeSharp.CodeFixing.projitems b/src/ComputeSharp.CodeFixing/ComputeSharp.CodeFixing.projitems index 98ea93eb..bf418a95 100644 --- a/src/ComputeSharp.CodeFixing/ComputeSharp.CodeFixing.projitems +++ b/src/ComputeSharp.CodeFixing/ComputeSharp.CodeFixing.projitems @@ -9,5 +9,6 @@ ComputeSharp.CodeFixing + - + \ No newline at end of file diff --git a/src/ComputeSharp.CodeFixing/MissingAttributeCodeFixer.cs b/src/ComputeSharp.CodeFixing/MissingAttributeCodeFixer.cs new file mode 100644 index 00000000..bc33a9b2 --- /dev/null +++ b/src/ComputeSharp.CodeFixing/MissingAttributeCodeFixer.cs @@ -0,0 +1,235 @@ +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Threading; +using System.Threading.Tasks; +using ComputeSharp.SourceGeneration.Extensions; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CodeActions; +using Microsoft.CodeAnalysis.CodeFixes; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.Editing; +using Microsoft.CodeAnalysis.Simplification; +using Microsoft.CodeAnalysis.Text; + +namespace ComputeSharp.CodeFixing; + +/// +/// A code fixer that adds an attribute that is missing on a type that requires it. +/// +public abstract class MissingAttributeCodeFixer : CodeFixProvider +{ + /// + /// The title to display for the code fixer. + /// + private readonly string codeActionTitle; + + /// + /// The fully qualified type name of the attribute to add. + /// + private readonly string attributeFullyQualifiedMetadataName; + + /// + /// The fully qualified type names of leading attributes to skip. + /// + private readonly IEnumerable leadingAttributeFullyQualifiedMetadataNames; + + /// + /// Creates a new instance with the specified parameters. + /// + /// The diagnostic id to trigger the code fixer. + /// The title to display for the code fixer. + /// The fully qualified type name of the attribute to add. + /// The fully qualified type names of leading attributes to skip. + protected MissingAttributeCodeFixer( + string diagnosticId, + string codeActionTitle, + string attributeFullyQualifiedMetadataName, + IEnumerable leadingAttributeFullyQualifiedMetadataNames) + { + this.codeActionTitle = codeActionTitle; + this.attributeFullyQualifiedMetadataName = attributeFullyQualifiedMetadataName; + this.leadingAttributeFullyQualifiedMetadataNames = leadingAttributeFullyQualifiedMetadataNames; + + FixableDiagnosticIds = ImmutableArray.Create(diagnosticId); + } + + /// + public override ImmutableArray FixableDiagnosticIds { get; } + + /// + public override Microsoft.CodeAnalysis.CodeFixes.FixAllProvider? GetFixAllProvider() + { + return new FixAllProvider(this); + } + + /// + public override async Task RegisterCodeFixesAsync(CodeFixContext context) + { + Diagnostic diagnostic = context.Diagnostics[0]; + TextSpan diagnosticSpan = context.Span; + + SyntaxNode? root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); + + // Get the struct declaration from the target diagnostic + if (root?.FindNode(diagnosticSpan) is StructDeclarationSyntax structDeclaration) + { + // Register the code fix to update the return type to be Task instead + context.RegisterCodeFix( + CodeAction.Create( + title: this.codeActionTitle, + createChangedDocument: token => AddMissingAttribute(context.Document, root, structDeclaration, token), + equivalenceKey: this.codeActionTitle), + diagnostic); + } + } + + /// + /// Applies the code fix to add the missing attribute to a target type. + /// + /// The original document being fixed. + /// The original tree root belonging to the current document. + /// The to update. + /// The cancellation token for the operation. + /// An updated document with the applied code fix, and the return type of the method being . + private async Task AddMissingAttribute( + Document document, + SyntaxNode root, + StructDeclarationSyntax structDeclaration, + CancellationToken cancellationToken) + { + // Get the new struct declaration + SyntaxNode updatedStructDeclaration = await AddMissingAttribute( + document, + structDeclaration, + cancellationToken); + + // Replace the node in the document tree + return document.WithSyntaxRoot(root.ReplaceNode(structDeclaration, updatedStructDeclaration)); + } + + /// + /// Applies the code fix to add the missing attribute to a target type. + /// + /// The original document being fixed. + /// The to update. + /// The cancellation token for the operation. + /// An updated document with the applied code fix, and the return type of the method being . + private async Task AddMissingAttribute( + Document document, + StructDeclarationSyntax structDeclaration, + CancellationToken cancellationToken) + { + // Get the semantic model (bail if it's not available) + if (await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false) is not SemanticModel semanticModel) + { + return structDeclaration; + } + + // Build the map of attributes to look for + if (!semanticModel.Compilation.TryBuildNamedTypeSymbolSet(this.leadingAttributeFullyQualifiedMetadataNames, out ImmutableHashSet? leadingAttributeTypeSymbols)) + { + return structDeclaration; + } + + // Also bail if we can't resolve the target attribute symbol (this should really never happen) + if (semanticModel.Compilation.GetTypeByMetadataName(this.attributeFullyQualifiedMetadataName) is not INamedTypeSymbol attributeSymbol) + { + return structDeclaration; + } + + int index = 0; + + // Find the index to use to insert the attribute. We want to make it so that if the struct declaration + // has a bunch of leading attributes, the new one will be inserted right after that. This way the final list + // will be nicely sorted, instead of having attributes interleaving other unrelated attributes, if any. + foreach (AttributeListSyntax attributeList in structDeclaration.AttributeLists) + { + // Make sure we have an attribute to check + if (attributeList.Attributes is not [AttributeSyntax attribute, ..]) + { + continue; + } + + // Resolve the symbol for the attribute (stop here if this failed for whatever reason) + if (!semanticModel.GetSymbolInfo(attribute, cancellationToken).TryGetAttributeTypeSymbol(out INamedTypeSymbol? attributeTypeSymbol)) + { + break; + } + + // If the attribute is a leading one, increment the index and continue + if (leadingAttributeTypeSymbols.Contains(attributeTypeSymbol)) + { + index++; + } + else + { + // Otherwise, stop here, we reached the end of the sequence + break; + } + } + + SyntaxGenerator syntaxGenerator = SyntaxGenerator.GetGenerator(document); + + // Create the attribute syntax for the new attribute. Also annotate it + // to automatically add using directives to the document, if needed. + // Then create the attribute syntax and insert it at the right position. + SyntaxNode attributeTypeSyntax = syntaxGenerator.TypeExpression(attributeSymbol).WithAdditionalAnnotations(Simplifier.AddImportsAnnotation); + SyntaxNode attributeSyntax = syntaxGenerator.Attribute(attributeTypeSyntax); + SyntaxNode updatedStructDeclarationSyntax = syntaxGenerator.InsertAttributes(structDeclaration, index, attributeSyntax); + + // Replace the node in the syntax tree + return updatedStructDeclarationSyntax; + } + + /// + /// A custom with the logic from . + /// + private sealed class FixAllProvider : DocumentBasedFixAllProvider + { + /// + /// The owning instance. + /// + private readonly MissingAttributeCodeFixer codeFixer; + + /// + /// Creates a new instance with the specified parameters. + /// + /// The owning instance. + public FixAllProvider(MissingAttributeCodeFixer codeFixer) + { + this.codeFixer = codeFixer; + } + + /// + protected override async Task FixAllAsync(FixAllContext fixAllContext, Document document, ImmutableArray diagnostics) + { + // Get the document root (this should always succeed) + if (await document.GetSyntaxRootAsync(fixAllContext.CancellationToken).ConfigureAwait(false) is not SyntaxNode root) + { + return document; + } + + SyntaxEditor syntaxEditor = new(root, fixAllContext.Solution.Services); + + foreach (Diagnostic diagnostic in diagnostics) + { + // Get the current struct declaration for the diagnostic + if (root.FindNode(diagnostic.Location.SourceSpan) is not StructDeclarationSyntax structDeclaration) + { + continue; + } + + // Get the syntax node with the updated declaration + SyntaxNode updatedStructDeclaration = await this.codeFixer.AddMissingAttribute( + document, + structDeclaration, + fixAllContext.CancellationToken); + + // Replace the node via the editor + syntaxEditor.ReplaceNode(structDeclaration, updatedStructDeclaration); + } + + return document.WithSyntaxRoot(syntaxEditor.GetChangedRoot()); + } + } +} diff --git a/src/ComputeSharp.D2D1.CodeFixers/ComputeSharp.D2D1.CodeFixers.csproj b/src/ComputeSharp.D2D1.CodeFixers/ComputeSharp.D2D1.CodeFixers.csproj index 41ca05c4..14fb87c2 100644 --- a/src/ComputeSharp.D2D1.CodeFixers/ComputeSharp.D2D1.CodeFixers.csproj +++ b/src/ComputeSharp.D2D1.CodeFixers/ComputeSharp.D2D1.CodeFixers.csproj @@ -10,4 +10,6 @@ + + From 936ea610b670ef7278ca907fe489104e9a2f12ef Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 16 Oct 2023 10:43:18 +0200 Subject: [PATCH 07/14] Adopt MissingAttributeCodeFixer as base code fixer type --- .../MissingAttributeCodeFixer.cs | 6 +- ...lShaderDescriptorOnPixelShaderCodeFixer.cs | 186 ++---------------- 2 files changed, 16 insertions(+), 176 deletions(-) diff --git a/src/ComputeSharp.CodeFixing/MissingAttributeCodeFixer.cs b/src/ComputeSharp.CodeFixing/MissingAttributeCodeFixer.cs index bc33a9b2..ade028d3 100644 --- a/src/ComputeSharp.CodeFixing/MissingAttributeCodeFixer.cs +++ b/src/ComputeSharp.CodeFixing/MissingAttributeCodeFixer.cs @@ -54,16 +54,16 @@ public abstract class MissingAttributeCodeFixer : CodeFixProvider } /// - public override ImmutableArray FixableDiagnosticIds { get; } + public sealed override ImmutableArray FixableDiagnosticIds { get; } /// - public override Microsoft.CodeAnalysis.CodeFixes.FixAllProvider? GetFixAllProvider() + public sealed override Microsoft.CodeAnalysis.CodeFixes.FixAllProvider? GetFixAllProvider() { return new FixAllProvider(this); } /// - public override async Task RegisterCodeFixesAsync(CodeFixContext context) + public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { Diagnostic diagnostic = context.Diagnostics[0]; TextSpan diagnosticSpan = context.Span; diff --git a/src/ComputeSharp.D2D1.CodeFixers/MissingPixelShaderDescriptorOnPixelShaderCodeFixer.cs b/src/ComputeSharp.D2D1.CodeFixers/MissingPixelShaderDescriptorOnPixelShaderCodeFixer.cs index bddd91ad..69b0a7dc 100644 --- a/src/ComputeSharp.D2D1.CodeFixers/MissingPixelShaderDescriptorOnPixelShaderCodeFixer.cs +++ b/src/ComputeSharp.D2D1.CodeFixers/MissingPixelShaderDescriptorOnPixelShaderCodeFixer.cs @@ -1,15 +1,7 @@ -using System.Collections.Immutable; using System.Composition; -using System.Threading; -using System.Threading.Tasks; -using ComputeSharp.SourceGeneration.Extensions; +using ComputeSharp.CodeFixing; using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.CodeAnalysis.Editing; -using Microsoft.CodeAnalysis.Simplification; -using Microsoft.CodeAnalysis.Text; using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors; namespace ComputeSharp.D2D1.CodeFixers; @@ -19,12 +11,13 @@ namespace ComputeSharp.D2D1.CodeFixers; /// [ExportCodeFixProvider(LanguageNames.CSharp)] [Shared] -public sealed class MissingPixelShaderDescriptorOnPixelShaderCodeFixer : CodeFixProvider +public sealed class MissingPixelShaderDescriptorOnPixelShaderCodeFixer : MissingAttributeCodeFixer { /// /// The set of type names for all D2D attributes that can be over shader types. /// - private static readonly ImmutableArray D2DAttributeTypeNames = ImmutableArray.Create( + private static readonly string[] D2DAttributeTypeNames = new[] + { "ComputeSharp.D2D1.D2DCompileOptionsAttribute", "ComputeSharp.D2D1.D2DEffectAuthorAttribute", "ComputeSharp.D2D1.D2DEffectCategoryAttribute", @@ -38,171 +31,18 @@ public sealed class MissingPixelShaderDescriptorOnPixelShaderCodeFixer : CodeFix "ComputeSharp.D2D1.D2DOutputBufferAttribute", "ComputeSharp.D2D1.D2DPixelOptionsAttribute", "ComputeSharp.D2D1.D2DRequiresScenePositionAttribute", - "ComputeSharp.D2D1.D2DShaderProfileAttribute"); - - /// - public override ImmutableArray FixableDiagnosticIds { get; } = ImmutableArray.Create(MissingPixelShaderDescriptorOnPixelShaderTypeId); - - /// - public override Microsoft.CodeAnalysis.CodeFixes.FixAllProvider? GetFixAllProvider() - { - return new FixAllProvider(); - } - - /// - public override async Task RegisterCodeFixesAsync(CodeFixContext context) - { - Diagnostic diagnostic = context.Diagnostics[0]; - TextSpan diagnosticSpan = context.Span; - - SyntaxNode? root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); - - // Get the struct declaration from the target diagnostic - if (root?.FindNode(diagnosticSpan) is StructDeclarationSyntax structDeclaration) - { - // Register the code fix to update the return type to be Task instead - context.RegisterCodeFix( - CodeAction.Create( - title: "Add [D2DGeneratedPixelShaderDescriptor] attribute", - createChangedDocument: token => AddMissingD2DGeneratedPixelShaderDescriptorAttribute(context.Document, root, structDeclaration, token), - equivalenceKey: "Add [D2DGeneratedPixelShaderDescriptor] attribute"), - diagnostic); - } - } + "ComputeSharp.D2D1.D2DShaderProfileAttribute" + }; /// - /// Applies the code fix to add the [D2DGeneratedPixelShaderDescriptor] attribute to a target type. + /// Creates a new instance with the specified parameters. /// - /// The original document being fixed. - /// The original tree root belonging to the current document. - /// The to update. - /// The cancellation token for the operation. - /// An updated document with the applied code fix, and the return type of the method being . - private static async Task AddMissingD2DGeneratedPixelShaderDescriptorAttribute( - Document document, - SyntaxNode root, - StructDeclarationSyntax structDeclaration, - CancellationToken cancellationToken) + public MissingPixelShaderDescriptorOnPixelShaderCodeFixer() + : base( + diagnosticId: MissingPixelShaderDescriptorOnPixelShaderTypeId, + codeActionTitle: "Add [D2DGeneratedPixelShaderDescriptor] attribute", + attributeFullyQualifiedMetadataName: "ComputeSharp.D2D1.D2DGeneratedPixelShaderDescriptorAttribute", + leadingAttributeFullyQualifiedMetadataNames: D2DAttributeTypeNames) { - // Get the new struct declaration - SyntaxNode updatedStructDeclaration = await AddMissingD2DGeneratedPixelShaderDescriptorAttribute( - document, - structDeclaration, - cancellationToken); - - // Replace the node in the document tree - return document.WithSyntaxRoot(root.ReplaceNode(structDeclaration, updatedStructDeclaration)); - } - - /// - /// Applies the code fix to add the [D2DGeneratedPixelShaderDescriptor] attribute to a target type. - /// - /// The original document being fixed. - /// The to update. - /// The cancellation token for the operation. - /// An updated document with the applied code fix, and the return type of the method being . - private static async Task AddMissingD2DGeneratedPixelShaderDescriptorAttribute( - Document document, - StructDeclarationSyntax structDeclaration, - CancellationToken cancellationToken) - { - // Get the semantic model (bail if it's not available) - if (await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false) is not SemanticModel semanticModel) - { - return structDeclaration; - } - - // Build the map of D2D attributes to look for - if (!semanticModel.Compilation.TryBuildNamedTypeSymbolSet(D2DAttributeTypeNames, out ImmutableHashSet? d2DAttributeTypeSymbols)) - { - return structDeclaration; - } - - // Also bail if we can't resolve the [D2DGeneratedPixelShaderDescriptor] attribute symbol (this should really never happen) - if (semanticModel.Compilation.GetTypeByMetadataName("ComputeSharp.D2D1.D2DGeneratedPixelShaderDescriptorAttribute") is not INamedTypeSymbol attributeSymbol) - { - return structDeclaration; - } - - int index = 0; - - // Find the index to use to insert the attribute. We want to make it so that if the struct declaration - // has a bunch of D2D attributes, the new one will be inserted right after that. This way the final list - // will be nicely sorted, instead of having D2D attributes interleaving other unrelated attributes, if any. - foreach (AttributeListSyntax attributeList in structDeclaration.AttributeLists) - { - // Make sure we have an attribute to check - if (attributeList.Attributes is not [AttributeSyntax attribute, ..]) - { - continue; - } - - // Resolve the symbol for the attribute (stop here if this failed for whatever reason) - if (!semanticModel.GetSymbolInfo(attribute, cancellationToken).TryGetAttributeTypeSymbol(out INamedTypeSymbol? attributeTypeSymbol)) - { - break; - } - - // If the attribute is D2D one, increment the index and continue - if (d2DAttributeTypeSymbols.Contains(attributeTypeSymbol)) - { - index++; - } - else - { - // Otherwise, stop here, we reached the end of the sequence - break; - } - } - - SyntaxGenerator syntaxGenerator = SyntaxGenerator.GetGenerator(document); - - // Create the attribute syntax for the new attribute. Also annotate it - // to automatically add using directives to the document, if needed. - // Then create the attribute syntax and insert it at the right position. - SyntaxNode attributeTypeSyntax = syntaxGenerator.TypeExpression(attributeSymbol).WithAdditionalAnnotations(Simplifier.AddImportsAnnotation); - SyntaxNode attributeSyntax = syntaxGenerator.Attribute(attributeTypeSyntax); - SyntaxNode updatedStructDeclarationSyntax = syntaxGenerator.InsertAttributes(structDeclaration, index, attributeSyntax); - - // Replace the node in the syntax tree - return updatedStructDeclarationSyntax; - } - - /// - /// A custom with the logic from . - /// - private sealed class FixAllProvider : DocumentBasedFixAllProvider - { - /// - protected override async Task FixAllAsync(FixAllContext fixAllContext, Document document, ImmutableArray diagnostics) - { - // Get the document root (this should always succeed) - if (await document.GetSyntaxRootAsync(fixAllContext.CancellationToken).ConfigureAwait(false) is not SyntaxNode root) - { - return document; - } - - SyntaxEditor syntaxEditor = new(root, fixAllContext.Solution.Services); - - foreach (Diagnostic diagnostic in diagnostics) - { - // Get the current struct declaration for the diagnostic - if (root.FindNode(diagnostic.Location.SourceSpan) is not StructDeclarationSyntax structDeclaration) - { - continue; - } - - // Get the syntax node with the updated declaration - SyntaxNode updatedStructDeclaration = await AddMissingD2DGeneratedPixelShaderDescriptorAttribute( - document, - structDeclaration, - fixAllContext.CancellationToken); - - // Replace the node via the editor - syntaxEditor.ReplaceNode(structDeclaration, updatedStructDeclaration); - } - - return document.WithSyntaxRoot(syntaxEditor.GetChangedRoot()); - } } } From 1075dc7e0b26ecd6e7ab4aea7beff0afe34b524c Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 16 Oct 2023 10:46:39 +0200 Subject: [PATCH 08/14] Add blank ComputeSharp.CodeFixers project --- ComputeSharp.sln | 11 +++++++++++ .../ComputeSharp.CodeFixers.csproj | 15 +++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/ComputeSharp.CodeFixers/ComputeSharp.CodeFixers.csproj diff --git a/ComputeSharp.sln b/ComputeSharp.sln index 2c8e64eb..d4ae56c6 100644 --- a/ComputeSharp.sln +++ b/ComputeSharp.sln @@ -148,6 +148,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Win32", "Win32", "{D991153C EndProject Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "ComputeSharp.CodeFixing", "src\ComputeSharp.CodeFixing\ComputeSharp.CodeFixing.shproj", "{29F6E256-BA0E-4F3B-854E-50839D67C6DD}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputeSharp.CodeFixers", "src\ComputeSharp.CodeFixers\ComputeSharp.CodeFixers.csproj", "{9B4448B1-200F-4966-8A13-A508691B3003}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -420,6 +422,14 @@ Global {59A17380-24A0-4BD7-9012-B105A9E7D46F}.Release|ARM64.Build.0 = Release|Any CPU {59A17380-24A0-4BD7-9012-B105A9E7D46F}.Release|x64.ActiveCfg = Release|Any CPU {59A17380-24A0-4BD7-9012-B105A9E7D46F}.Release|x64.Build.0 = Release|Any CPU + {9B4448B1-200F-4966-8A13-A508691B3003}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {9B4448B1-200F-4966-8A13-A508691B3003}.Debug|ARM64.Build.0 = Debug|Any CPU + {9B4448B1-200F-4966-8A13-A508691B3003}.Debug|x64.ActiveCfg = Debug|Any CPU + {9B4448B1-200F-4966-8A13-A508691B3003}.Debug|x64.Build.0 = Debug|Any CPU + {9B4448B1-200F-4966-8A13-A508691B3003}.Release|ARM64.ActiveCfg = Release|Any CPU + {9B4448B1-200F-4966-8A13-A508691B3003}.Release|ARM64.Build.0 = Release|Any CPU + {9B4448B1-200F-4966-8A13-A508691B3003}.Release|x64.ActiveCfg = Release|Any CPU + {9B4448B1-200F-4966-8A13-A508691B3003}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -472,6 +482,7 @@ Global src\ComputeSharp.CodeFixing\ComputeSharp.CodeFixing.projitems*{54654960-54b5-4e19-b3ed-993591ca39e5}*SharedItemsImports = 5 samples\ComputeSharp.SwapChain.Shaders.D2D1.Shared\ComputeSharp.SwapChain.Shaders.D2D1.Shared.projitems*{73c32d0f-64db-4674-84e9-8fcc41228474}*SharedItemsImports = 5 src\ComputeSharp.SourceGeneration.Hlsl\ComputeSharp.SourceGeneration.Hlsl.projitems*{9ac496a3-bbf0-4c8f-a50d-a20bf01c5e05}*SharedItemsImports = 13 + src\ComputeSharp.CodeFixing\ComputeSharp.CodeFixing.projitems*{9b4448b1-200f-4966-8a13-a508691b3003}*SharedItemsImports = 5 src\ComputeSharp.Win32.D2D1\ComputeSharp.Win32.D2D1.projitems*{9da1da9f-f8b2-4b25-be80-c21f773029e3}*SharedItemsImports = 13 samples\ComputeSharp.SwapChain.Shaders.D2D1.Shared\ComputeSharp.SwapChain.Shaders.D2D1.Shared.projitems*{9ea5ae9d-c39a-4f43-b03e-0a848ea2558a}*SharedItemsImports = 5 src\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems*{a5997814-d8d2-4541-87ac-c3e53caa67c0}*SharedItemsImports = 13 diff --git a/src/ComputeSharp.CodeFixers/ComputeSharp.CodeFixers.csproj b/src/ComputeSharp.CodeFixers/ComputeSharp.CodeFixers.csproj new file mode 100644 index 00000000..a729ff18 --- /dev/null +++ b/src/ComputeSharp.CodeFixers/ComputeSharp.CodeFixers.csproj @@ -0,0 +1,15 @@ + + + netstandard2.0 + + + + + + + + + + + + From d6096b525aebd25e5fd1b763195c23b15ab6ab9a Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 16 Oct 2023 10:50:40 +0200 Subject: [PATCH 09/14] Add MissingComputeShaderDescriptorOnComputeShaderCodeFixer --- ...haderDescriptorOnComputeShaderCodeFixer.cs | 36 +++++++++++++++++++ .../ComputeSharp.SourceGenerators.csproj | 5 +++ 2 files changed, 41 insertions(+) create mode 100644 src/ComputeSharp.CodeFixers/MissingComputeShaderDescriptorOnComputeShaderCodeFixer.cs diff --git a/src/ComputeSharp.CodeFixers/MissingComputeShaderDescriptorOnComputeShaderCodeFixer.cs b/src/ComputeSharp.CodeFixers/MissingComputeShaderDescriptorOnComputeShaderCodeFixer.cs new file mode 100644 index 00000000..a2a1de41 --- /dev/null +++ b/src/ComputeSharp.CodeFixers/MissingComputeShaderDescriptorOnComputeShaderCodeFixer.cs @@ -0,0 +1,36 @@ +using System.Composition; +using ComputeSharp.CodeFixing; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CodeFixes; +using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors; + +namespace ComputeSharp.D2D1.CodeFixers; + +/// +/// A code fixer that adds the [GeneratedComputeShaderDescriptor] to compute shader types with no descriptor. +/// +[ExportCodeFixProvider(LanguageNames.CSharp)] +[Shared] +public sealed class MissingComputeShaderDescriptorOnComputeShaderCodeFixer : MissingAttributeCodeFixer +{ + /// + /// The set of type names for all attributes that can be over shader types. + /// + private static readonly string[] D2DAttributeTypeNames = new[] + { + "ComputeSharp.EmbeddedBytecodeAttribute", + "ComputeSharp.GroupSharedAttribute" + }; + + /// + /// Creates a new instance with the specified parameters. + /// + public MissingComputeShaderDescriptorOnComputeShaderCodeFixer() + : base( + diagnosticId: MissingComputeShaderDescriptorOnComputeShaderTypeId, + codeActionTitle: "Add [GeneratedComputeShaderDescriptor] attribute", + attributeFullyQualifiedMetadataName: "ComputeSharp.GeneratedComputeShaderDescriptorAttribute", + leadingAttributeFullyQualifiedMetadataNames: D2DAttributeTypeNames) + { + } +} diff --git a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj index d47c90c9..35b85d5a 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj +++ b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj @@ -97,4 +97,9 @@ + + + + + From 0f0ecab6fc86071160d4108820eab327b0a46a40 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 16 Oct 2023 11:11:07 +0200 Subject: [PATCH 10/14] Fix InvalidGeneratedComputeShaderDescriptorAttributeTargetAnalyzer --- ...ShaderDescriptorAttributeTargetAnalyzer.cs | 29 +++++++++++++------ .../Diagnostics/DiagnosticDescriptors.cs | 2 +- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/InvalidGeneratedComputeShaderDescriptorAttributeTargetAnalyzer.cs b/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/InvalidGeneratedComputeShaderDescriptorAttributeTargetAnalyzer.cs index c5868a6a..d8b9051c 100644 --- a/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/InvalidGeneratedComputeShaderDescriptorAttributeTargetAnalyzer.cs +++ b/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/InvalidGeneratedComputeShaderDescriptorAttributeTargetAnalyzer.cs @@ -13,7 +13,7 @@ namespace ComputeSharp.SourceGenerators; public sealed class InvalidGeneratedComputeShaderDescriptorAttributeTargetAnalyzer : DiagnosticAnalyzer { /// - public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create(InvalidD2DGeneratedPixelShaderDescriptorAttributeTarget); + public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create(InvalidGeneratedPixelShaderDescriptorAttributeTarget); /// public override void Initialize(AnalysisContext context) @@ -39,16 +39,27 @@ public sealed class InvalidGeneratedComputeShaderDescriptorAttributeTargetAnalyz return; } - // Emit a diagnostic if the target type is using [GeneratedComputeShaderDescriptor] but does not implement IComputeShader nor IComputeShader - if (typeSymbol.TryGetAttributeWithType(generatedComputeShaderDescriptorAttributeSymbol, out AttributeData? attribute) && - !typeSymbol.HasInterfaceWithType(computeShaderSymbol) && - !typeSymbol.HasInterfaceWithType(pixelShaderSymbol)) + // If the current type does not have [GeneratedComputeShaderDescriptor], there is nothing to do + if (!typeSymbol.TryGetAttributeWithType(generatedComputeShaderDescriptorAttributeSymbol, out AttributeData? attribute)) { - context.ReportDiagnostic(Diagnostic.Create( - InvalidD2DGeneratedPixelShaderDescriptorAttributeTarget, - attribute.GetLocation(), - typeSymbol)); + return; } + + // If the type implements IComputeShader or IComputeShader, it is valid + foreach (INamedTypeSymbol interfaceSymbol in typeSymbol.AllInterfaces) + { + if (SymbolEqualityComparer.Default.Equals(interfaceSymbol, computeShaderSymbol) || + SymbolEqualityComparer.Default.Equals(interfaceSymbol.ConstructedFrom, pixelShaderSymbol)) + { + return; + } + } + + // If we got here, the type is not valid, so we can emit a diagnostic + context.ReportDiagnostic(Diagnostic.Create( + InvalidGeneratedPixelShaderDescriptorAttributeTarget, + attribute.GetLocation(), + typeSymbol)); }, SymbolKind.NamedType); }); } diff --git a/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs b/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs index e6467719..8fd642cb 100644 --- a/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs +++ b/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs @@ -759,7 +759,7 @@ partial class DiagnosticDescriptors /// Format: "The type {0} is not a valid target for the [GeneratedComputeShaderDescriptor] attribute (only types implementing the IComputeShader or IComputeShader<TPixel> interface are valid)". /// /// - public static readonly DiagnosticDescriptor InvalidD2DGeneratedPixelShaderDescriptorAttributeTarget = new DiagnosticDescriptor( + public static readonly DiagnosticDescriptor InvalidGeneratedPixelShaderDescriptorAttributeTarget = new DiagnosticDescriptor( id: "CMPS0054", title: "Invalid [GeneratedComputeShaderDescriptor] attribute target", messageFormat: "The type {0} is not a valid target for the [GeneratedComputeShaderDescriptor] attribute (only types implementing the IComputeShader or IComputeShader interface are valid)", From ba20d0db763e30a9cfd35201fc6eb59773f17af2 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 16 Oct 2023 11:15:48 +0200 Subject: [PATCH 11/14] Fix MissingComputeShaderDescriptorOnComputeShaderAnalyzer --- ...ShaderDescriptorAttributeTargetAnalyzer.cs | 15 +++-------- ...ShaderDescriptorOnComputeShaderAnalyzer.cs | 27 +++++++++++++++++-- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/InvalidGeneratedComputeShaderDescriptorAttributeTargetAnalyzer.cs b/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/InvalidGeneratedComputeShaderDescriptorAttributeTargetAnalyzer.cs index d8b9051c..988ccd78 100644 --- a/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/InvalidGeneratedComputeShaderDescriptorAttributeTargetAnalyzer.cs +++ b/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/InvalidGeneratedComputeShaderDescriptorAttributeTargetAnalyzer.cs @@ -45,21 +45,14 @@ public sealed class InvalidGeneratedComputeShaderDescriptorAttributeTargetAnalyz return; } - // If the type implements IComputeShader or IComputeShader, it is valid - foreach (INamedTypeSymbol interfaceSymbol in typeSymbol.AllInterfaces) + // If the type doesn't implement IComputeShader nor IComputeShader, we can emit a diagnostic + if (!MissingComputeShaderDescriptorOnComputeShaderAnalyzer.IsComputeShaderType(typeSymbol, computeShaderSymbol, pixelShaderSymbol)) { - if (SymbolEqualityComparer.Default.Equals(interfaceSymbol, computeShaderSymbol) || - SymbolEqualityComparer.Default.Equals(interfaceSymbol.ConstructedFrom, pixelShaderSymbol)) - { - return; - } - } - - // If we got here, the type is not valid, so we can emit a diagnostic - context.ReportDiagnostic(Diagnostic.Create( + context.ReportDiagnostic(Diagnostic.Create( InvalidGeneratedPixelShaderDescriptorAttributeTarget, attribute.GetLocation(), typeSymbol)); + } }, SymbolKind.NamedType); }); } diff --git a/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/MissingComputeShaderDescriptorOnComputeShaderAnalyzer.cs b/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/MissingComputeShaderDescriptorOnComputeShaderAnalyzer.cs index b4030c41..61db689f 100644 --- a/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/MissingComputeShaderDescriptorOnComputeShaderAnalyzer.cs +++ b/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/MissingComputeShaderDescriptorOnComputeShaderAnalyzer.cs @@ -42,8 +42,7 @@ public sealed class MissingComputeShaderDescriptorOnComputeShaderAnalyzer : Diag } // If the type is not a compute shader type, immediately bail out - if (!typeSymbol.HasInterfaceWithType(computeShaderSymbol) && - !typeSymbol.HasInterfaceWithType(pixelShaderSymbol)) + if (!IsComputeShaderType(typeSymbol, computeShaderSymbol, pixelShaderSymbol)) { return; } @@ -60,4 +59,28 @@ public sealed class MissingComputeShaderDescriptorOnComputeShaderAnalyzer : Diag }, SymbolKind.NamedType); }); } + + /// + /// Checks whether a given type is a compute shader type. + /// + /// The type to check. + /// The type symbol for IComputeShader. + /// The type symbol for IComputeShader<TPixel>. + /// + internal static bool IsComputeShaderType( + INamedTypeSymbol typeSymbol, + INamedTypeSymbol computeShaderSymbol, + INamedTypeSymbol pixelShaderSymbol) + { + foreach (INamedTypeSymbol interfaceSymbol in typeSymbol.AllInterfaces) + { + if (SymbolEqualityComparer.Default.Equals(interfaceSymbol, computeShaderSymbol) || + SymbolEqualityComparer.Default.Equals(interfaceSymbol.ConstructedFrom, pixelShaderSymbol)) + { + return true; + } + } + + return false; + } } \ No newline at end of file From c3ed6ead403eedcdccc299b7879e0741a498c00a Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 16 Oct 2023 11:20:24 +0200 Subject: [PATCH 12/14] Add [GeneratedComputeShaderDescriptor] to all shaders --- .../Blas/BlasHelpers.cs | 1 + .../Dispatching/DispatchingBenchmark.cs | 1 + .../HlslBokehBlurProcessor{TPixel}.cs | 4 ++++ .../HlslGaussianBlurProcessor{TPixel}.cs | 2 ++ .../MultiplyByTwo.cs | 1 + samples/ComputeSharp.Sample/Program.cs | 1 + .../ColorfulInfinity.cs | 1 + .../ContouredLayers.cs | 1 + .../ExtrudedTruchetPattern.cs | 1 + .../FourColorGradient.cs | 1 + .../FractalTiling.cs | 1 + .../HelloWorld.cs | 1 + .../MengerJourney.cs | 1 + .../Octagrams.cs | 1 + .../ProteanClouds.cs | 1 + .../PyramidPattern.cs | 1 + .../TerracedHills.cs | 1 + .../TriangleGridContouring.cs | 1 + .../TwoTiledTruchet.cs | 1 + ...omputeShaderDescriptorGenerator.Helpers.cs | 3 +-- tests/ComputeSharp.Dynamic.NuGet/Program.cs | 1 + tests/ComputeSharp.NuGet/Program.cs | 1 + tests/ComputeSharp.Pix.NuGet/Program.cs | 1 + .../DeviceDisposalTests.cs | 2 ++ .../DispatchTests.cs | 2 ++ .../Program.cs | 1 + .../ShaderDataLoaderTests.cs | 7 ++++++ tests/ComputeSharp.Tests/BufferTests.cs | 4 ++++ .../ComputeSharp.Tests/ComputeContextTests.cs | 12 ++++++++++ .../ComputeSharp.Tests.csproj | 1 + tests/ComputeSharp.Tests/DispatchTests.cs | 9 ++++++++ tests/ComputeSharp.Tests/IPixelShaderTests.cs | 1 + .../ComputeSharp.Tests/InitializationTests.cs | 1 + .../ResourceDimensionsTests.g.cs | 23 +++++++++++++++++++ .../ResourceDimensionsTests.tt | 1 + .../ComputeSharp.Tests/ShaderCompilerTests.cs | 18 +++++++++++++++ .../ComputeSharp.Tests/ShaderMembersTests.cs | 4 ++++ .../ComputeSharp.Tests/ShaderRewriterTests.cs | 13 +++++++++++ .../Shaders/Compute/ColorfulInfinity.cs | 1 + .../Shaders/Compute/ContouredLayers.cs | 1 + .../Shaders/Compute/ExtrudedTruchetPattern.cs | 1 + .../Shaders/Compute/FourColorGradient.cs | 1 + .../Shaders/Compute/FractalTiling.cs | 1 + .../Shaders/Compute/HelloWorld.cs | 1 + .../Shaders/Compute/MengerJourney.cs | 1 + .../Shaders/Compute/Octagrams.cs | 1 + .../Shaders/Compute/ProteanClouds.cs | 1 + .../Shaders/Compute/PyramidPattern.cs | 1 + .../Shaders/Compute/TerracedHills.cs | 1 + .../Shaders/Compute/TriangleGridContouring.cs | 1 + .../Shaders/Compute/TwoTiledTruchet.cs | 1 + .../Texture1DTests.Pixels.cs | 1 + .../Texture1DTests.Pixels.g.cs | 7 ++++++ .../Texture1DTests.Pixels.tt | 1 + tests/ComputeSharp.Tests/Texture1DTests.cs | 2 ++ .../Texture2DTests.Pixels.cs | 2 ++ .../Texture2DTests.Pixels.g.cs | 7 ++++++ .../Texture2DTests.Pixels.tt | 1 + tests/ComputeSharp.Tests/Texture2DTests.cs | 2 ++ .../Texture3DTests.Pixels.g.cs | 7 ++++++ .../Texture3DTests.Pixels.tt | 1 + tests/ComputeSharp.Tests/Texture3DTests.cs | 2 ++ .../ThreadGroupSizeTests.cs | 4 ++++ 63 files changed, 176 insertions(+), 2 deletions(-) diff --git a/samples/ComputeSharp.Benchmark/Blas/BlasHelpers.cs b/samples/ComputeSharp.Benchmark/Blas/BlasHelpers.cs index 7f092b09..c5ffab0d 100644 --- a/samples/ComputeSharp.Benchmark/Blas/BlasHelpers.cs +++ b/samples/ComputeSharp.Benchmark/Blas/BlasHelpers.cs @@ -82,6 +82,7 @@ internal static partial class BlasHelpers /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XYZ)] + [GeneratedComputeShaderDescriptor] public readonly partial struct FullyConnectedForwardKernel : IComputeShader { private readonly int n; diff --git a/samples/ComputeSharp.Benchmark/Dispatching/DispatchingBenchmark.cs b/samples/ComputeSharp.Benchmark/Dispatching/DispatchingBenchmark.cs index 5c477a7a..35d57b83 100644 --- a/samples/ComputeSharp.Benchmark/Dispatching/DispatchingBenchmark.cs +++ b/samples/ComputeSharp.Benchmark/Dispatching/DispatchingBenchmark.cs @@ -110,6 +110,7 @@ public partial class DispatchingBenchmark : IDisposable [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct TestShader : IComputeShader { private readonly ReadWriteBuffer buffer; diff --git a/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs b/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs index 6c8d9fc8..2db0049c 100644 --- a/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs +++ b/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs @@ -315,6 +315,7 @@ public sealed partial class HlslBokehBlurProcessor /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct VerticalConvolutionProcessor : IComputeShader { private readonly IReadWriteNormalizedTexture2D source; @@ -353,6 +354,7 @@ public sealed partial class HlslBokehBlurProcessor /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct HorizontalConvolutionAndAccumulatePartialsProcessor : IComputeShader { private readonly float z; @@ -393,6 +395,7 @@ public sealed partial class HlslBokehBlurProcessor /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct GammaHighlightProcessor : IComputeShader { private readonly IReadWriteNormalizedTexture2D source; @@ -418,6 +421,7 @@ public sealed partial class HlslBokehBlurProcessor /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct InverseGammaHighlightProcessor : IComputeShader { private readonly ReadWriteTexture2D source; diff --git a/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs b/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs index d35ac808..f358f6ac 100644 --- a/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs +++ b/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs @@ -119,6 +119,7 @@ public sealed partial class HlslGaussianBlurProcessor /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct VerticalConvolutionProcessor : IComputeShader { private readonly IReadWriteNormalizedTexture2D source; @@ -152,6 +153,7 @@ public sealed partial class HlslGaussianBlurProcessor /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct HorizontalConvolutionProcessor : IComputeShader { private readonly IReadWriteNormalizedTexture2D source; diff --git a/samples/ComputeSharp.Sample.FSharp.Shaders/MultiplyByTwo.cs b/samples/ComputeSharp.Sample.FSharp.Shaders/MultiplyByTwo.cs index ac8d99a2..d9c60473 100644 --- a/samples/ComputeSharp.Sample.FSharp.Shaders/MultiplyByTwo.cs +++ b/samples/ComputeSharp.Sample.FSharp.Shaders/MultiplyByTwo.cs @@ -5,6 +5,7 @@ namespace ComputeSharp.Sample.FSharp.Shaders; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] +[GeneratedComputeShaderDescriptor] public readonly partial struct MultiplyByTwo : IComputeShader { private readonly ReadWriteBuffer buffer; diff --git a/samples/ComputeSharp.Sample/Program.cs b/samples/ComputeSharp.Sample/Program.cs index 761aecc4..6c862923 100644 --- a/samples/ComputeSharp.Sample/Program.cs +++ b/samples/ComputeSharp.Sample/Program.cs @@ -25,6 +25,7 @@ Formatting.PrintMatrix(array, 10, 10, "AFTER"); /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct MultiplyByTwo : IComputeShader { private readonly ReadWriteBuffer buffer; diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/ColorfulInfinity.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/ColorfulInfinity.cs index 8d4b2b1d..433c0645 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/ColorfulInfinity.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/ColorfulInfinity.cs @@ -8,6 +8,7 @@ namespace ComputeSharp.SwapChain.Shaders; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct ColorfulInfinity : IComputeShader { /// diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/ContouredLayers.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/ContouredLayers.cs index 52cd77f2..e15a8d8f 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/ContouredLayers.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/ContouredLayers.cs @@ -7,6 +7,7 @@ namespace ComputeSharp.SwapChain.Shaders; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct ContouredLayers : IComputeShader { /// diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/ExtrudedTruchetPattern.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/ExtrudedTruchetPattern.cs index 44905851..e9babd5a 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/ExtrudedTruchetPattern.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/ExtrudedTruchetPattern.cs @@ -7,6 +7,7 @@ namespace ComputeSharp.SwapChain.Shaders; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct ExtrudedTruchetPattern : IComputeShader { /// diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/FourColorGradient.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/FourColorGradient.cs index 123f0575..7a7ee12d 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/FourColorGradient.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/FourColorGradient.cs @@ -8,6 +8,7 @@ namespace ComputeSharp.SwapChain.Shaders; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct FourColorGradient : IComputeShader { /// diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/FractalTiling.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/FractalTiling.cs index 156ece01..10b444c5 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/FractalTiling.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/FractalTiling.cs @@ -8,6 +8,7 @@ namespace ComputeSharp.SwapChain.Shaders; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct FractalTiling : IComputeShader { /// diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/HelloWorld.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/HelloWorld.cs index 75fc97c1..7e507eb8 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/HelloWorld.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/HelloWorld.cs @@ -6,6 +6,7 @@ namespace ComputeSharp.SwapChain.Shaders; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct HelloWorld : IComputeShader { /// diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/MengerJourney.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/MengerJourney.cs index 1b006248..1958ac85 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/MengerJourney.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/MengerJourney.cs @@ -7,6 +7,7 @@ namespace ComputeSharp.SwapChain.Shaders; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct MengerJourney : IComputeShader { /// diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/Octagrams.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/Octagrams.cs index 1fc1f0a6..9f87a082 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/Octagrams.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/Octagrams.cs @@ -7,6 +7,7 @@ namespace ComputeSharp.SwapChain.Shaders; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct Octagrams : IComputeShader { /// diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/ProteanClouds.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/ProteanClouds.cs index 6799eda1..d1dfdefa 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/ProteanClouds.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/ProteanClouds.cs @@ -8,6 +8,7 @@ namespace ComputeSharp.SwapChain.Shaders; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct ProteanClouds : IComputeShader { /// diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/PyramidPattern.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/PyramidPattern.cs index f4260f4c..af6b0c26 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/PyramidPattern.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/PyramidPattern.cs @@ -8,6 +8,7 @@ namespace ComputeSharp.SwapChain.Shaders; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct PyramidPattern : IComputeShader { /// diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/TerracedHills.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/TerracedHills.cs index 6eeff2ba..a32cd0c8 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/TerracedHills.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/TerracedHills.cs @@ -7,6 +7,7 @@ namespace ComputeSharp.SwapChain.Shaders; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct TerracedHills : IComputeShader { /// diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/TriangleGridContouring.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/TriangleGridContouring.cs index a3c03f54..4f24de96 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/TriangleGridContouring.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/TriangleGridContouring.cs @@ -7,6 +7,7 @@ namespace ComputeSharp.SwapChain.Shaders; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct TriangleGridContouring : IComputeShader { /// diff --git a/samples/ComputeSharp.SwapChain.Shaders.Shared/TwoTiledTruchet.cs b/samples/ComputeSharp.SwapChain.Shaders.Shared/TwoTiledTruchet.cs index 091813da..2b536ab8 100644 --- a/samples/ComputeSharp.SwapChain.Shaders.Shared/TwoTiledTruchet.cs +++ b/samples/ComputeSharp.SwapChain.Shaders.Shared/TwoTiledTruchet.cs @@ -7,6 +7,7 @@ namespace ComputeSharp.SwapChain.Shaders; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct TwoTiledTruchet : IComputeShader { /// diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.Helpers.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.Helpers.cs index aaa4bcc4..b2bc0a1f 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.Helpers.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.Helpers.cs @@ -25,8 +25,7 @@ partial class ComputeShaderDescriptorGenerator return true; } - else if (interfaceSymbol is { IsGenericType: true } && - SymbolEqualityComparer.Default.Equals(interfaceSymbol.ConstructedFrom, pixelShaderSymbol)) + else if (SymbolEqualityComparer.Default.Equals(interfaceSymbol.ConstructedFrom, pixelShaderSymbol)) { result = true; diff --git a/tests/ComputeSharp.Dynamic.NuGet/Program.cs b/tests/ComputeSharp.Dynamic.NuGet/Program.cs index 8a1cb76c..58d6e86e 100644 --- a/tests/ComputeSharp.Dynamic.NuGet/Program.cs +++ b/tests/ComputeSharp.Dynamic.NuGet/Program.cs @@ -35,6 +35,7 @@ Trace.Assert(shaderInfo.BoundResourceCount == 2); /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct MultiplyByTwo : IComputeShader { public readonly ReadWriteBuffer buffer; diff --git a/tests/ComputeSharp.NuGet/Program.cs b/tests/ComputeSharp.NuGet/Program.cs index bb7fb0d3..c4424f36 100644 --- a/tests/ComputeSharp.NuGet/Program.cs +++ b/tests/ComputeSharp.NuGet/Program.cs @@ -30,6 +30,7 @@ for (int i = 0; i < array.Length; i++) /// A sample kernel that is precompiled. /// [EmbeddedBytecode(DispatchAxis.X)] +[GeneratedComputeShaderDescriptor] [AutoConstructor] internal readonly partial struct MultiplyByTwo : IComputeShader { diff --git a/tests/ComputeSharp.Pix.NuGet/Program.cs b/tests/ComputeSharp.Pix.NuGet/Program.cs index 0d6e690b..306c6d71 100644 --- a/tests/ComputeSharp.Pix.NuGet/Program.cs +++ b/tests/ComputeSharp.Pix.NuGet/Program.cs @@ -36,6 +36,7 @@ for (int i = 0; i < array.Length; i++) /// A sample kernel that is precompiled. /// [EmbeddedBytecode(DispatchAxis.X)] +[GeneratedComputeShaderDescriptor] [AutoConstructor] internal readonly partial struct MultiplyByTwo : IComputeShader { diff --git a/tests/ComputeSharp.Tests.DeviceLost/DeviceDisposalTests.cs b/tests/ComputeSharp.Tests.DeviceLost/DeviceDisposalTests.cs index c1fcf6a7..312509ea 100644 --- a/tests/ComputeSharp.Tests.DeviceLost/DeviceDisposalTests.cs +++ b/tests/ComputeSharp.Tests.DeviceLost/DeviceDisposalTests.cs @@ -144,6 +144,7 @@ public partial class DeviceDisposalTests } [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] [AutoConstructor] private readonly partial struct InitializeShader : IComputeShader { @@ -177,6 +178,7 @@ public partial class DeviceDisposalTests } [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] private partial struct HelloWorldShader : IComputeShader { public float4 Execute() diff --git a/tests/ComputeSharp.Tests.DisableDynamicCompilation/DispatchTests.cs b/tests/ComputeSharp.Tests.DisableDynamicCompilation/DispatchTests.cs index b0d1ec55..b8cf0c02 100644 --- a/tests/ComputeSharp.Tests.DisableDynamicCompilation/DispatchTests.cs +++ b/tests/ComputeSharp.Tests.DisableDynamicCompilation/DispatchTests.cs @@ -32,6 +32,7 @@ public partial class DispatchTests [AutoConstructor] [EmbeddedBytecode(32, 1, 1)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ComputeShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -76,6 +77,7 @@ public partial class DispatchTests [AutoConstructor] [EmbeddedBytecode(8, 8, 1)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct PixelShader : IComputeShader { private readonly float b; diff --git a/tests/ComputeSharp.Tests.GlobalStatements/Program.cs b/tests/ComputeSharp.Tests.GlobalStatements/Program.cs index 33a9c0a1..6c0139b8 100644 --- a/tests/ComputeSharp.Tests.GlobalStatements/Program.cs +++ b/tests/ComputeSharp.Tests.GlobalStatements/Program.cs @@ -23,6 +23,7 @@ Console.WriteLine("Test passed successfully!"); [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] +[GeneratedComputeShaderDescriptor] public readonly partial struct ApplyFunctionShader : IComputeShader { private readonly ReadWriteBuffer sourceTexture; diff --git a/tests/ComputeSharp.Tests.Internals/ShaderDataLoaderTests.cs b/tests/ComputeSharp.Tests.Internals/ShaderDataLoaderTests.cs index 0562dc04..105203c4 100644 --- a/tests/ComputeSharp.Tests.Internals/ShaderDataLoaderTests.cs +++ b/tests/ComputeSharp.Tests.Internals/ShaderDataLoaderTests.cs @@ -11,6 +11,7 @@ public partial class ShaderDataLoaderTests { [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] public partial struct CapturedResourceShader : IComputeShader { public ReadWriteBuffer _; @@ -46,6 +47,7 @@ public partial class ShaderDataLoaderTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] public partial struct MultipleResourcesAndPrimitivesShader : IComputeShader { public ReadWriteBuffer _0; @@ -91,6 +93,7 @@ public partial class ShaderDataLoaderTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] public partial struct ScalarAndVectorTypesShader : IComputeShader { public ReadWriteBuffer _; @@ -141,6 +144,7 @@ public partial class ShaderDataLoaderTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] public partial struct ScalarVectorAndMatrixTypesShader : IComputeShader { public ReadWriteBuffer _; @@ -226,6 +230,7 @@ public partial class ShaderDataLoaderTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] public partial struct FlatCustomTypeShader : IComputeShader { public ReadWriteBuffer _0; @@ -317,6 +322,7 @@ public partial class ShaderDataLoaderTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] public partial struct NestedCustomTypesShader : IComputeShader { public ReadWriteBuffer _0; @@ -408,6 +414,7 @@ public partial class ShaderDataLoaderTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] public partial struct AmbiguousNamesShader : IComputeShader { public ReadWriteBuffer a; diff --git a/tests/ComputeSharp.Tests/BufferTests.cs b/tests/ComputeSharp.Tests/BufferTests.cs index 6d6c3dcd..94a5e26b 100644 --- a/tests/ComputeSharp.Tests/BufferTests.cs +++ b/tests/ComputeSharp.Tests/BufferTests.cs @@ -279,6 +279,7 @@ public partial class BufferTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ConstantBufferKernel : IComputeShader { public readonly ConstantBuffer source; @@ -308,6 +309,7 @@ public partial class BufferTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadOnlyBufferKernel : IComputeShader { public readonly ReadOnlyBuffer source; @@ -337,6 +339,7 @@ public partial class BufferTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadWriteBufferKernel : IComputeShader { public readonly ReadWriteBuffer source; @@ -373,6 +376,7 @@ public partial class BufferTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] public readonly partial struct DoublePrecisionSupportShader : IComputeShader { public readonly ReadWriteBuffer buffer; diff --git a/tests/ComputeSharp.Tests/ComputeContextTests.cs b/tests/ComputeSharp.Tests/ComputeContextTests.cs index adff51ed..4842b574 100644 --- a/tests/ComputeSharp.Tests/ComputeContextTests.cs +++ b/tests/ComputeSharp.Tests/ComputeContextTests.cs @@ -1295,6 +1295,7 @@ public partial class ComputeContextTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct OffsetComputeShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -1309,6 +1310,7 @@ public partial class ComputeContextTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ClearPixelShader : IComputeShader { /// @@ -1320,6 +1322,7 @@ public partial class ComputeContextTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ColorPixelShader : IComputeShader { public readonly float4 color; @@ -1333,6 +1336,7 @@ public partial class ComputeContextTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct LinearSampling2DPixelShader : IComputeShader { public readonly IReadOnlyTexture2D source; @@ -1346,6 +1350,7 @@ public partial class ComputeContextTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XYZ)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct LinearSampling3DComputeShader : IComputeShader { public readonly IReadOnlyTexture3D source; @@ -1365,6 +1370,7 @@ public partial class ComputeContextTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct LinearSamplingFromNormalized2DPixelShader : IComputeShader { public readonly IReadOnlyNormalizedTexture2D source; @@ -1378,6 +1384,7 @@ public partial class ComputeContextTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct CopyToOutputPixelShader : IComputeShader { public readonly IReadOnlyNormalizedTexture2D source; @@ -1391,6 +1398,7 @@ public partial class ComputeContextTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct InvertPixelShader : IComputeShader { public readonly IReadWriteNormalizedTexture2D source; @@ -1404,6 +1412,7 @@ public partial class ComputeContextTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XYZ)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct LinearSamplingFromNormalized3DComputeShader : IComputeShader { public readonly IReadOnlyNormalizedTexture3D source; @@ -1423,6 +1432,7 @@ public partial class ComputeContextTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct Dotted2DPixelShader : IComputeShader { public readonly IReadWriteNormalizedTexture2D source; @@ -1452,6 +1462,7 @@ public partial class ComputeContextTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XYZ)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct Dotted3DPixelShader : IComputeShader { public readonly IReadWriteNormalizedTexture3D source; @@ -1481,6 +1492,7 @@ public partial class ComputeContextTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ConvertToNonNormalized2DShader : IComputeShader { public readonly IReadOnlyNormalizedTexture2D source; diff --git a/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj b/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj index 88cf77f0..35c21b0b 100644 --- a/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj +++ b/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj @@ -20,6 +20,7 @@ + diff --git a/tests/ComputeSharp.Tests/DispatchTests.cs b/tests/ComputeSharp.Tests/DispatchTests.cs index 8c0f47f4..aab627ee 100644 --- a/tests/ComputeSharp.Tests/DispatchTests.cs +++ b/tests/ComputeSharp.Tests/DispatchTests.cs @@ -58,6 +58,7 @@ public partial class DispatchTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XYZ)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ThreadIdsShader : IComputeShader { public readonly ReadWriteTexture3D buffer; @@ -113,6 +114,7 @@ public partial class DispatchTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XYZ)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ThreadIdsNormalizedShader : IComputeShader { public readonly ReadWriteTexture3D buffer; @@ -155,6 +157,7 @@ public partial class DispatchTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XYZ)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct GroupIdsShader : IComputeShader { public readonly ReadWriteTexture3D buffer; @@ -186,6 +189,7 @@ public partial class DispatchTests [AutoConstructor] [EmbeddedBytecode(4, 15, 7)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct GroupSizeShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -219,6 +223,7 @@ public partial class DispatchTests [AutoConstructor] [EmbeddedBytecode(32, 1, 1)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct GridIdsShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -251,6 +256,7 @@ public partial class DispatchTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XYZ)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct DispatchSizeShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -291,6 +297,7 @@ public partial class DispatchTests } [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct DispatchPixelShader : IComputeShader { public float4 Execute() @@ -321,6 +328,7 @@ public partial class DispatchTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct FixedGroupSharedPixelShader : IComputeShader { private readonly ReadWriteBuffer buffer; @@ -365,6 +373,7 @@ public partial class DispatchTests [AutoConstructor] [EmbeddedBytecode(32, 1, 1)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct DynamicGroupSharedPixelShader : IComputeShader { private readonly ReadWriteBuffer buffer; diff --git a/tests/ComputeSharp.Tests/IPixelShaderTests.cs b/tests/ComputeSharp.Tests/IPixelShaderTests.cs index 7fad3712..999378d1 100644 --- a/tests/ComputeSharp.Tests/IPixelShaderTests.cs +++ b/tests/ComputeSharp.Tests/IPixelShaderTests.cs @@ -36,6 +36,7 @@ public partial class IPixelShaderTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct EarlyReturnShader : IComputeShader { public float4 Execute() diff --git a/tests/ComputeSharp.Tests/InitializationTests.cs b/tests/ComputeSharp.Tests/InitializationTests.cs index 005502f9..28a868d1 100644 --- a/tests/ComputeSharp.Tests/InitializationTests.cs +++ b/tests/ComputeSharp.Tests/InitializationTests.cs @@ -74,6 +74,7 @@ public partial class InitializationTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct SampleShader : IComputeShader { public readonly ReadWriteBuffer buffer; diff --git a/tests/ComputeSharp.Tests/ResourceDimensionsTests.g.cs b/tests/ComputeSharp.Tests/ResourceDimensionsTests.g.cs index 426325ff..d5e05040 100644 --- a/tests/ComputeSharp.Tests/ResourceDimensionsTests.g.cs +++ b/tests/ComputeSharp.Tests/ResourceDimensionsTests.g.cs @@ -30,6 +30,7 @@ public partial class ResourceDimensionsTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadOnlyBuffer_T1_AsReadOnlyBufferShader : IComputeShader { public readonly ReadOnlyBuffer source; @@ -63,6 +64,7 @@ public partial class ResourceDimensionsTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadWriteBuffer_T1_AsReadWriteBufferShader : IComputeShader { public readonly ReadWriteBuffer source; @@ -96,6 +98,7 @@ public partial class ResourceDimensionsTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadOnlyTexture1D_T1_AsReadOnlyTexture1DShader : IComputeShader { public readonly ReadOnlyTexture1D source; @@ -129,6 +132,7 @@ public partial class ResourceDimensionsTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadWriteTexture1D_T1_AsReadWriteTexture1DShader : IComputeShader { public readonly ReadWriteTexture1D source; @@ -166,6 +170,7 @@ public partial class ResourceDimensionsTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadWriteTexture1D_T1_AsIReadOnlyTexture1DShader : IComputeShader { public readonly IReadOnlyTexture1D source; @@ -199,6 +204,7 @@ public partial class ResourceDimensionsTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadOnlyTexture1D_T2_AsReadOnlyTexture1DShader : IComputeShader { public readonly ReadOnlyTexture1D source; @@ -232,6 +238,7 @@ public partial class ResourceDimensionsTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadOnlyTexture1D_T2_AsIReadOnlyNormalizedTexture1DShader : IComputeShader { public readonly IReadOnlyNormalizedTexture1D source; @@ -265,6 +272,7 @@ public partial class ResourceDimensionsTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadWriteTexture1D_T2_AsReadWriteTexture1DShader : IComputeShader { public readonly ReadWriteTexture1D source; @@ -298,6 +306,7 @@ public partial class ResourceDimensionsTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadWriteTexture1D_T2_AsIReadWriteNormalizedTexture1DShader : IComputeShader { public readonly IReadWriteNormalizedTexture1D source; @@ -331,6 +340,7 @@ public partial class ResourceDimensionsTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadOnlyTexture2D_T1_AsReadOnlyTexture2DShader : IComputeShader { public readonly ReadOnlyTexture2D source; @@ -365,6 +375,7 @@ public partial class ResourceDimensionsTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadWriteTexture2D_T1_AsReadWriteTexture2DShader : IComputeShader { public readonly ReadWriteTexture2D source; @@ -403,6 +414,7 @@ public partial class ResourceDimensionsTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadWriteTexture2D_T1_AsIReadOnlyTexture2DShader : IComputeShader { public readonly IReadOnlyTexture2D source; @@ -437,6 +449,7 @@ public partial class ResourceDimensionsTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadOnlyTexture2D_T2_AsReadOnlyTexture2DShader : IComputeShader { public readonly ReadOnlyTexture2D source; @@ -471,6 +484,7 @@ public partial class ResourceDimensionsTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadOnlyTexture2D_T2_AsIReadOnlyNormalizedTexture2DShader : IComputeShader { public readonly IReadOnlyNormalizedTexture2D source; @@ -505,6 +519,7 @@ public partial class ResourceDimensionsTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadWriteTexture2D_T2_AsReadWriteTexture2DShader : IComputeShader { public readonly ReadWriteTexture2D source; @@ -539,6 +554,7 @@ public partial class ResourceDimensionsTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadWriteTexture2D_T2_AsIReadWriteNormalizedTexture2DShader : IComputeShader { public readonly IReadWriteNormalizedTexture2D source; @@ -573,6 +589,7 @@ public partial class ResourceDimensionsTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadOnlyTexture3D_T1_AsReadOnlyTexture3DShader : IComputeShader { public readonly ReadOnlyTexture3D source; @@ -608,6 +625,7 @@ public partial class ResourceDimensionsTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadWriteTexture3D_T1_AsReadWriteTexture3DShader : IComputeShader { public readonly ReadWriteTexture3D source; @@ -647,6 +665,7 @@ public partial class ResourceDimensionsTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadWriteTexture3D_T1_AsIReadOnlyTexture3DShader : IComputeShader { public readonly IReadOnlyTexture3D source; @@ -682,6 +701,7 @@ public partial class ResourceDimensionsTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadOnlyTexture3D_T2_AsReadOnlyTexture3DShader : IComputeShader { public readonly ReadOnlyTexture3D source; @@ -717,6 +737,7 @@ public partial class ResourceDimensionsTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadOnlyTexture3D_T2_AsIReadOnlyNormalizedTexture3DShader : IComputeShader { public readonly IReadOnlyNormalizedTexture3D source; @@ -752,6 +773,7 @@ public partial class ResourceDimensionsTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadWriteTexture3D_T2_AsReadWriteTexture3DShader : IComputeShader { public readonly ReadWriteTexture3D source; @@ -787,6 +809,7 @@ public partial class ResourceDimensionsTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadWriteTexture3D_T2_AsIReadWriteNormalizedTexture3DShader : IComputeShader { public readonly IReadWriteNormalizedTexture3D source; diff --git a/tests/ComputeSharp.Tests/ResourceDimensionsTests.tt b/tests/ComputeSharp.Tests/ResourceDimensionsTests.tt index b39c5b09..ad2d44f6 100644 --- a/tests/ComputeSharp.Tests/ResourceDimensionsTests.tt +++ b/tests/ComputeSharp.Tests/ResourceDimensionsTests.tt @@ -133,6 +133,7 @@ foreach (var pair in typesMap) [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct <#=testMethodName#>Shader : IComputeShader { public readonly <#=shaderResourceType#> source; diff --git a/tests/ComputeSharp.Tests/ShaderCompilerTests.cs b/tests/ComputeSharp.Tests/ShaderCompilerTests.cs index b44ddc23..ca4f35b0 100644 --- a/tests/ComputeSharp.Tests/ShaderCompilerTests.cs +++ b/tests/ComputeSharp.Tests/ShaderCompilerTests.cs @@ -19,6 +19,7 @@ namespace ComputeSharp.Tests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] public readonly partial struct ReservedKeywordsShader : IComputeShader { public readonly ReadWriteBuffer row_major; @@ -55,6 +56,7 @@ namespace ComputeSharp.Tests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] public readonly partial struct ReservedKeywordsInCustomTypesShader : IComputeShader { public readonly ReadWriteBuffer row_major; @@ -83,6 +85,7 @@ namespace ComputeSharp.Tests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] public readonly partial struct ReservedKeywordsFromHlslTypesAndBuiltInValuesShader : IComputeShader { public readonly ReadWriteBuffer fragmentKeyword; @@ -125,6 +128,7 @@ namespace ComputeSharp.Tests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] public readonly partial struct ReservedKeywordsPrecompiledShader : IComputeShader { public readonly ReadWriteBuffer row_major; @@ -162,6 +166,7 @@ namespace ComputeSharp.Tests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] public readonly partial struct SpecialTypeAsReturnTypeShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -184,6 +189,7 @@ namespace ComputeSharp.Tests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] public readonly partial struct LocalFunctionInExternalMethodsShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -216,6 +222,7 @@ namespace ComputeSharp.Tests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] public readonly partial struct CapturedNestedStructTypeShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -236,6 +243,7 @@ namespace ComputeSharp.Tests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] public readonly partial struct ExternalStructTypeShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -258,6 +266,7 @@ namespace ComputeSharp.Tests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] public readonly partial struct OutOfOrderMethodsShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -294,6 +303,7 @@ namespace ComputeSharp.Tests } [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] public readonly partial struct StatelessPixelShader : IComputeShader { /// @@ -305,6 +315,7 @@ namespace ComputeSharp.Tests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] public readonly partial struct LoopWithVarCounterShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -335,6 +346,7 @@ namespace ComputeSharp.Tests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] public readonly partial struct DoublePrecisionSupportShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -355,6 +367,7 @@ namespace ComputeSharp.Tests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct FieldAccessWithThisExpressionShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -382,6 +395,7 @@ namespace ComputeSharp.Tests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ComputeShaderWithInheritedShaderInterfaceShader : IMyBaseShader { int IMyBaseShader.A => 42; @@ -416,6 +430,7 @@ namespace ComputeSharp.Tests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct PixelShaderWithInheritedShaderInterfaceShader : IMyBaseShader { int IMyBaseShader.A => 42; @@ -465,6 +480,7 @@ namespace ComputeSharp.Tests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct StructInstanceMethodsShader : IComputeShader { public readonly MyStructTypeA a; @@ -499,6 +515,7 @@ namespace ComputeSharp.Tests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct PixelShaderWithScopedParameterInMethodsShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -537,6 +554,7 @@ namespace ExternalNamespace { [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] public readonly partial struct UserDefinedTypeShader : IComputeShader { public readonly ReadWriteBuffer buffer; diff --git a/tests/ComputeSharp.Tests/ShaderMembersTests.cs b/tests/ComputeSharp.Tests/ShaderMembersTests.cs index b48a2840..f8be121f 100644 --- a/tests/ComputeSharp.Tests/ShaderMembersTests.cs +++ b/tests/ComputeSharp.Tests/ShaderMembersTests.cs @@ -32,6 +32,7 @@ public partial class ShaderMembersTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct StaticConstantsShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -72,6 +73,7 @@ public partial class ShaderMembersTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct GlobalVariableShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -107,6 +109,7 @@ public partial class ShaderMembersTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct BoolInstanceFieldsShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -171,6 +174,7 @@ public partial class ShaderMembersTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct BoolInstanceFieldInCustomStructShader : IComputeShader { public readonly ReadWriteBuffer buffer; diff --git a/tests/ComputeSharp.Tests/ShaderRewriterTests.cs b/tests/ComputeSharp.Tests/ShaderRewriterTests.cs index 034bfaf8..efb9bfe5 100644 --- a/tests/ComputeSharp.Tests/ShaderRewriterTests.cs +++ b/tests/ComputeSharp.Tests/ShaderRewriterTests.cs @@ -53,6 +53,7 @@ public partial class ShaderRewriterTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct NanAndInfiniteShader : IComputeShader { public readonly ReadWriteBuffer buffer1; @@ -114,6 +115,7 @@ public partial class ShaderRewriterTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ModAndComparisonOperatorsShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -176,6 +178,7 @@ public partial class ShaderRewriterTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct BitwiseOperatorsShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -229,6 +232,7 @@ public partial class ShaderRewriterTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct BooleanOperatorsShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -279,6 +283,7 @@ public partial class ShaderRewriterTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ToBooleanConversionIntrinsicsShader : IComputeShader { public readonly ReadOnlyBuffer buffer1; @@ -363,6 +368,7 @@ public partial class ShaderRewriterTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct FromBooleanConversionIntrinsicsShader : IComputeShader { public readonly ReadOnlyBuffer source; @@ -446,6 +452,7 @@ public partial class ShaderRewriterTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ConstantsInShaderConstantFieldsShader : IComputeShader { public const float rot_angle = (float)(137.2 / 180.0 * Math.PI); @@ -524,6 +531,7 @@ public partial class ShaderRewriterTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct DoubleConstantsInShaderConstantFieldsShader : IComputeShader { public const float DoubleToFloatConstant = (float)(1 / 255.0); @@ -586,6 +594,7 @@ public partial class ShaderRewriterTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct InterlockedOperationsShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -631,6 +640,7 @@ public partial class ShaderRewriterTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct GlslStyleMulOperatorsShader : IComputeShader { public readonly ReadOnlyBuffer source1; @@ -772,6 +782,7 @@ public partial class ShaderRewriterTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct CustomStructTypeShader : IComputeShader { public readonly ReadWriteBuffer source; @@ -810,6 +821,7 @@ public partial class ShaderRewriterTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct MiscHlslIntrinsicsShader : IComputeShader { public readonly ReadWriteBuffer buffer1; @@ -853,6 +865,7 @@ public partial class ShaderRewriterTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadonlyModifierInMethodsShader : IComputeShader { private readonly ReadWriteBuffer buffer; diff --git a/tests/ComputeSharp.Tests/Shaders/Compute/ColorfulInfinity.cs b/tests/ComputeSharp.Tests/Shaders/Compute/ColorfulInfinity.cs index 07a6b4f5..add82728 100644 --- a/tests/ComputeSharp.Tests/Shaders/Compute/ColorfulInfinity.cs +++ b/tests/ComputeSharp.Tests/Shaders/Compute/ColorfulInfinity.cs @@ -10,6 +10,7 @@ namespace ComputeSharp.SwapChain.Shaders.Compute; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct ColorfulInfinity : IComputeShader { /// diff --git a/tests/ComputeSharp.Tests/Shaders/Compute/ContouredLayers.cs b/tests/ComputeSharp.Tests/Shaders/Compute/ContouredLayers.cs index 267b42c7..2c5f03ad 100644 --- a/tests/ComputeSharp.Tests/Shaders/Compute/ContouredLayers.cs +++ b/tests/ComputeSharp.Tests/Shaders/Compute/ContouredLayers.cs @@ -9,6 +9,7 @@ namespace ComputeSharp.SwapChain.Shaders.Compute; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct ContouredLayers : IComputeShader { /// diff --git a/tests/ComputeSharp.Tests/Shaders/Compute/ExtrudedTruchetPattern.cs b/tests/ComputeSharp.Tests/Shaders/Compute/ExtrudedTruchetPattern.cs index d6fc5a22..0af21b02 100644 --- a/tests/ComputeSharp.Tests/Shaders/Compute/ExtrudedTruchetPattern.cs +++ b/tests/ComputeSharp.Tests/Shaders/Compute/ExtrudedTruchetPattern.cs @@ -9,6 +9,7 @@ namespace ComputeSharp.SwapChain.Shaders.Compute; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct ExtrudedTruchetPattern : IComputeShader { /// diff --git a/tests/ComputeSharp.Tests/Shaders/Compute/FourColorGradient.cs b/tests/ComputeSharp.Tests/Shaders/Compute/FourColorGradient.cs index 781c3977..bc869bf0 100644 --- a/tests/ComputeSharp.Tests/Shaders/Compute/FourColorGradient.cs +++ b/tests/ComputeSharp.Tests/Shaders/Compute/FourColorGradient.cs @@ -10,6 +10,7 @@ namespace ComputeSharp.SwapChain.Shaders.Compute; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct FourColorGradient : IComputeShader { /// diff --git a/tests/ComputeSharp.Tests/Shaders/Compute/FractalTiling.cs b/tests/ComputeSharp.Tests/Shaders/Compute/FractalTiling.cs index 63b95527..579e923f 100644 --- a/tests/ComputeSharp.Tests/Shaders/Compute/FractalTiling.cs +++ b/tests/ComputeSharp.Tests/Shaders/Compute/FractalTiling.cs @@ -10,6 +10,7 @@ namespace ComputeSharp.SwapChain.Shaders.Compute; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct FractalTiling : IComputeShader { /// diff --git a/tests/ComputeSharp.Tests/Shaders/Compute/HelloWorld.cs b/tests/ComputeSharp.Tests/Shaders/Compute/HelloWorld.cs index 43c0573f..78a069f3 100644 --- a/tests/ComputeSharp.Tests/Shaders/Compute/HelloWorld.cs +++ b/tests/ComputeSharp.Tests/Shaders/Compute/HelloWorld.cs @@ -8,6 +8,7 @@ namespace ComputeSharp.SwapChain.Shaders.Compute; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct HelloWorld : IComputeShader { /// diff --git a/tests/ComputeSharp.Tests/Shaders/Compute/MengerJourney.cs b/tests/ComputeSharp.Tests/Shaders/Compute/MengerJourney.cs index eddb7030..948696ec 100644 --- a/tests/ComputeSharp.Tests/Shaders/Compute/MengerJourney.cs +++ b/tests/ComputeSharp.Tests/Shaders/Compute/MengerJourney.cs @@ -9,6 +9,7 @@ namespace ComputeSharp.SwapChain.Shaders.Compute; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct MengerJourney : IComputeShader { /// diff --git a/tests/ComputeSharp.Tests/Shaders/Compute/Octagrams.cs b/tests/ComputeSharp.Tests/Shaders/Compute/Octagrams.cs index 6d82537d..b4c27361 100644 --- a/tests/ComputeSharp.Tests/Shaders/Compute/Octagrams.cs +++ b/tests/ComputeSharp.Tests/Shaders/Compute/Octagrams.cs @@ -9,6 +9,7 @@ namespace ComputeSharp.SwapChain.Shaders.Compute; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct Octagrams : IComputeShader { /// diff --git a/tests/ComputeSharp.Tests/Shaders/Compute/ProteanClouds.cs b/tests/ComputeSharp.Tests/Shaders/Compute/ProteanClouds.cs index 837d8c33..f9c22af0 100644 --- a/tests/ComputeSharp.Tests/Shaders/Compute/ProteanClouds.cs +++ b/tests/ComputeSharp.Tests/Shaders/Compute/ProteanClouds.cs @@ -10,6 +10,7 @@ namespace ComputeSharp.SwapChain.Shaders.Compute; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct ProteanClouds : IComputeShader { /// diff --git a/tests/ComputeSharp.Tests/Shaders/Compute/PyramidPattern.cs b/tests/ComputeSharp.Tests/Shaders/Compute/PyramidPattern.cs index dd78a284..fc6c30e9 100644 --- a/tests/ComputeSharp.Tests/Shaders/Compute/PyramidPattern.cs +++ b/tests/ComputeSharp.Tests/Shaders/Compute/PyramidPattern.cs @@ -10,6 +10,7 @@ namespace ComputeSharp.SwapChain.Shaders.Compute; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct PyramidPattern : IComputeShader { /// diff --git a/tests/ComputeSharp.Tests/Shaders/Compute/TerracedHills.cs b/tests/ComputeSharp.Tests/Shaders/Compute/TerracedHills.cs index 4b70114c..4e40ad21 100644 --- a/tests/ComputeSharp.Tests/Shaders/Compute/TerracedHills.cs +++ b/tests/ComputeSharp.Tests/Shaders/Compute/TerracedHills.cs @@ -7,6 +7,7 @@ namespace ComputeSharp.SwapChain.Shaders.Compute; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct TerracedHills : IComputeShader { /// diff --git a/tests/ComputeSharp.Tests/Shaders/Compute/TriangleGridContouring.cs b/tests/ComputeSharp.Tests/Shaders/Compute/TriangleGridContouring.cs index 64df5c0f..de1e0b2c 100644 --- a/tests/ComputeSharp.Tests/Shaders/Compute/TriangleGridContouring.cs +++ b/tests/ComputeSharp.Tests/Shaders/Compute/TriangleGridContouring.cs @@ -9,6 +9,7 @@ namespace ComputeSharp.SwapChain.Shaders.Compute; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct TriangleGridContouring : IComputeShader { /// diff --git a/tests/ComputeSharp.Tests/Shaders/Compute/TwoTiledTruchet.cs b/tests/ComputeSharp.Tests/Shaders/Compute/TwoTiledTruchet.cs index ae6ee711..7583d288 100644 --- a/tests/ComputeSharp.Tests/Shaders/Compute/TwoTiledTruchet.cs +++ b/tests/ComputeSharp.Tests/Shaders/Compute/TwoTiledTruchet.cs @@ -9,6 +9,7 @@ namespace ComputeSharp.SwapChain.Shaders.Compute; /// [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] +[GeneratedComputeShaderDescriptor] internal readonly partial struct TwoTiledTruchet : IComputeShader { /// diff --git a/tests/ComputeSharp.Tests/Texture1DTests.Pixels.cs b/tests/ComputeSharp.Tests/Texture1DTests.Pixels.cs index 014dec14..2b588302 100644 --- a/tests/ComputeSharp.Tests/Texture1DTests.Pixels.cs +++ b/tests/ComputeSharp.Tests/Texture1DTests.Pixels.cs @@ -90,6 +90,7 @@ partial class Texture1DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] public readonly partial struct SamplingComputeShader : IComputeShader { public readonly IReadOnlyNormalizedTexture1D source; diff --git a/tests/ComputeSharp.Tests/Texture1DTests.Pixels.g.cs b/tests/ComputeSharp.Tests/Texture1DTests.Pixels.g.cs index 4a791f90..0fe24a5f 100644 --- a/tests/ComputeSharp.Tests/Texture1DTests.Pixels.g.cs +++ b/tests/ComputeSharp.Tests/Texture1DTests.Pixels.g.cs @@ -70,6 +70,7 @@ partial class Texture1DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct Shader_Unorm_Bgra32_Float4 : IComputeShader { public readonly ReadOnlyTexture1D source; @@ -83,6 +84,7 @@ partial class Texture1DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct Shader_Unorm_R16_float : IComputeShader { public readonly ReadOnlyTexture1D source; @@ -96,6 +98,7 @@ partial class Texture1DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct Shader_Unorm_R8_float : IComputeShader { public readonly ReadOnlyTexture1D source; @@ -109,6 +112,7 @@ partial class Texture1DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct Shader_Unorm_Rg16_Float2 : IComputeShader { public readonly ReadOnlyTexture1D source; @@ -122,6 +126,7 @@ partial class Texture1DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct Shader_Unorm_Rg32_Float2 : IComputeShader { public readonly ReadOnlyTexture1D source; @@ -135,6 +140,7 @@ partial class Texture1DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct Shader_Unorm_Rgba32_Float4 : IComputeShader { public readonly ReadOnlyTexture1D source; @@ -148,6 +154,7 @@ partial class Texture1DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct Shader_Unorm_Rgba64_Float4 : IComputeShader { public readonly ReadOnlyTexture1D source; diff --git a/tests/ComputeSharp.Tests/Texture1DTests.Pixels.tt b/tests/ComputeSharp.Tests/Texture1DTests.Pixels.tt index 10c63aeb..a0aa73c8 100644 --- a/tests/ComputeSharp.Tests/Texture1DTests.Pixels.tt +++ b/tests/ComputeSharp.Tests/Texture1DTests.Pixels.tt @@ -66,6 +66,7 @@ foreach (var (t, tPixel) in EnumerateTypes()) [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct Shader_Unorm_<#=t#>_<#=tPixel#> : IComputeShader { public readonly ReadOnlyTexture1D<<#=t#>, <#=tPixel#>> source; diff --git a/tests/ComputeSharp.Tests/Texture1DTests.cs b/tests/ComputeSharp.Tests/Texture1DTests.cs index ef323c0b..62ad9e0b 100644 --- a/tests/ComputeSharp.Tests/Texture1DTests.cs +++ b/tests/ComputeSharp.Tests/Texture1DTests.cs @@ -364,6 +364,7 @@ public partial class Texture1DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadOnlyTexture1DKernel : IComputeShader { public readonly ReadOnlyTexture1D source; @@ -395,6 +396,7 @@ public partial class Texture1DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadWriteTexture1DKernel : IComputeShader { public readonly ReadWriteTexture1D source; diff --git a/tests/ComputeSharp.Tests/Texture2DTests.Pixels.cs b/tests/ComputeSharp.Tests/Texture2DTests.Pixels.cs index dbc26b43..d018f337 100644 --- a/tests/ComputeSharp.Tests/Texture2DTests.Pixels.cs +++ b/tests/ComputeSharp.Tests/Texture2DTests.Pixels.cs @@ -73,6 +73,7 @@ partial class Texture2DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] public readonly partial struct SamplingComputeShader : IComputeShader { public readonly IReadOnlyNormalizedTexture2D source; @@ -107,6 +108,7 @@ partial class Texture2DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] public readonly partial struct SamplingPixelShader : IComputeShader { public readonly IReadOnlyNormalizedTexture2D texture; diff --git a/tests/ComputeSharp.Tests/Texture2DTests.Pixels.g.cs b/tests/ComputeSharp.Tests/Texture2DTests.Pixels.g.cs index 51fd801e..21eba694 100644 --- a/tests/ComputeSharp.Tests/Texture2DTests.Pixels.g.cs +++ b/tests/ComputeSharp.Tests/Texture2DTests.Pixels.g.cs @@ -70,6 +70,7 @@ partial class Texture2DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct Shader_Unorm_Bgra32_Float4 : IComputeShader { public readonly ReadOnlyTexture2D source; @@ -83,6 +84,7 @@ partial class Texture2DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct Shader_Unorm_R16_float : IComputeShader { public readonly ReadOnlyTexture2D source; @@ -96,6 +98,7 @@ partial class Texture2DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct Shader_Unorm_R8_float : IComputeShader { public readonly ReadOnlyTexture2D source; @@ -109,6 +112,7 @@ partial class Texture2DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct Shader_Unorm_Rg16_Float2 : IComputeShader { public readonly ReadOnlyTexture2D source; @@ -122,6 +126,7 @@ partial class Texture2DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct Shader_Unorm_Rg32_Float2 : IComputeShader { public readonly ReadOnlyTexture2D source; @@ -135,6 +140,7 @@ partial class Texture2DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct Shader_Unorm_Rgba32_Float4 : IComputeShader { public readonly ReadOnlyTexture2D source; @@ -148,6 +154,7 @@ partial class Texture2DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct Shader_Unorm_Rgba64_Float4 : IComputeShader { public readonly ReadOnlyTexture2D source; diff --git a/tests/ComputeSharp.Tests/Texture2DTests.Pixels.tt b/tests/ComputeSharp.Tests/Texture2DTests.Pixels.tt index f5577e31..d7330a3a 100644 --- a/tests/ComputeSharp.Tests/Texture2DTests.Pixels.tt +++ b/tests/ComputeSharp.Tests/Texture2DTests.Pixels.tt @@ -66,6 +66,7 @@ foreach (var (t, tPixel) in EnumerateTypes()) [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct Shader_Unorm_<#=t#>_<#=tPixel#> : IComputeShader { public readonly ReadOnlyTexture2D<<#=t#>, <#=tPixel#>> source; diff --git a/tests/ComputeSharp.Tests/Texture2DTests.cs b/tests/ComputeSharp.Tests/Texture2DTests.cs index 5cf79486..a8e14b88 100644 --- a/tests/ComputeSharp.Tests/Texture2DTests.cs +++ b/tests/ComputeSharp.Tests/Texture2DTests.cs @@ -429,6 +429,7 @@ public partial class Texture2DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadOnlyTexture2DKernel : IComputeShader { public readonly ReadOnlyTexture2D source; @@ -460,6 +461,7 @@ public partial class Texture2DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadWriteTexture2DKernel : IComputeShader { public readonly ReadWriteTexture2D source; diff --git a/tests/ComputeSharp.Tests/Texture3DTests.Pixels.g.cs b/tests/ComputeSharp.Tests/Texture3DTests.Pixels.g.cs index f2601e67..b26c60e8 100644 --- a/tests/ComputeSharp.Tests/Texture3DTests.Pixels.g.cs +++ b/tests/ComputeSharp.Tests/Texture3DTests.Pixels.g.cs @@ -70,6 +70,7 @@ partial class Texture3DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XYZ)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct Shader_Unorm_Bgra32_Float4 : IComputeShader { public readonly ReadOnlyTexture3D source; @@ -83,6 +84,7 @@ partial class Texture3DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XYZ)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct Shader_Unorm_R16_float : IComputeShader { public readonly ReadOnlyTexture3D source; @@ -96,6 +98,7 @@ partial class Texture3DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XYZ)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct Shader_Unorm_R8_float : IComputeShader { public readonly ReadOnlyTexture3D source; @@ -109,6 +112,7 @@ partial class Texture3DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XYZ)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct Shader_Unorm_Rg16_Float2 : IComputeShader { public readonly ReadOnlyTexture3D source; @@ -122,6 +126,7 @@ partial class Texture3DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XYZ)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct Shader_Unorm_Rg32_Float2 : IComputeShader { public readonly ReadOnlyTexture3D source; @@ -135,6 +140,7 @@ partial class Texture3DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XYZ)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct Shader_Unorm_Rgba32_Float4 : IComputeShader { public readonly ReadOnlyTexture3D source; @@ -148,6 +154,7 @@ partial class Texture3DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XYZ)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct Shader_Unorm_Rgba64_Float4 : IComputeShader { public readonly ReadOnlyTexture3D source; diff --git a/tests/ComputeSharp.Tests/Texture3DTests.Pixels.tt b/tests/ComputeSharp.Tests/Texture3DTests.Pixels.tt index f18c826b..07a5109b 100644 --- a/tests/ComputeSharp.Tests/Texture3DTests.Pixels.tt +++ b/tests/ComputeSharp.Tests/Texture3DTests.Pixels.tt @@ -66,6 +66,7 @@ foreach (var (t, tPixel) in EnumerateTypes()) [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XYZ)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct Shader_Unorm_<#=t#>_<#=tPixel#> : IComputeShader { public readonly ReadOnlyTexture3D<<#=t#>, <#=tPixel#>> source; diff --git a/tests/ComputeSharp.Tests/Texture3DTests.cs b/tests/ComputeSharp.Tests/Texture3DTests.cs index faa111a4..79b5c025 100644 --- a/tests/ComputeSharp.Tests/Texture3DTests.cs +++ b/tests/ComputeSharp.Tests/Texture3DTests.cs @@ -534,6 +534,7 @@ public partial class Texture3DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XYZ)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadOnlyTexture3DKernel : IComputeShader { public readonly ReadOnlyTexture3D source; @@ -565,6 +566,7 @@ public partial class Texture3DTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XYZ)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct ReadWriteTexture3DKernel : IComputeShader { public readonly ReadWriteTexture3D source; diff --git a/tests/ComputeSharp.Tests/ThreadGroupSizeTests.cs b/tests/ComputeSharp.Tests/ThreadGroupSizeTests.cs index b36df45e..58aa2a45 100644 --- a/tests/ComputeSharp.Tests/ThreadGroupSizeTests.cs +++ b/tests/ComputeSharp.Tests/ThreadGroupSizeTests.cs @@ -29,6 +29,7 @@ public partial class ThreadGroupSizeTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.X)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct DispatchXShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -41,6 +42,7 @@ public partial class ThreadGroupSizeTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XY)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct DispatchXYShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -53,6 +55,7 @@ public partial class ThreadGroupSizeTests [AutoConstructor] [EmbeddedBytecode(DispatchAxis.XYZ)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct DispatchXYZShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -65,6 +68,7 @@ public partial class ThreadGroupSizeTests [AutoConstructor] [EmbeddedBytecode(11, 14, 6)] + [GeneratedComputeShaderDescriptor] internal readonly partial struct DispatchCustomShader : IComputeShader { public readonly ReadWriteBuffer buffer; From fb6b94c632b73236143d8014ad5903f7c9bd1d07 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 16 Oct 2023 14:03:02 +0200 Subject: [PATCH 13/14] Simplify code in diagnostic tests and diagnostic values --- .../Diagnostics/DiagnosticDescriptors.cs | 52 +- .../Diagnostics/DiagnosticDescriptors.cs | 20 +- .../DiagnosticsTests.cs | 1173 ++++++----------- 3 files changed, 430 insertions(+), 815 deletions(-) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs index 7b884420..e395e8a6 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs @@ -15,13 +15,13 @@ partial class DiagnosticDescriptors /// /// Gets a for an invalid shader field. /// - /// Format: "The compute shader of type {0} contains a field \"{1}\" of an invalid type {2}". + /// Format: "The compute shader of type {0} contains a field "{1}" of an invalid type {2}". /// /// public static readonly DiagnosticDescriptor InvalidShaderField = new DiagnosticDescriptor( id: "CMPSD2D0001", title: "Invalid shader field", - messageFormat: "The compute shader of type {0} contains a field \"{1}\" of an invalid type {2}", + messageFormat: """The compute shader of type {0} contains a field "{1}" of an invalid type {2}""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -401,13 +401,13 @@ partial class DiagnosticDescriptors /// /// Gets a for an invalid shader static readonly field type. /// - /// Format: "The compute shader of type {0} contains a static readonly field \"{1}\" of an invalid type {2} (only primitive, vector and matrix types are supported)". + /// Format: "The compute shader of type {0} contains a static readonly field "{1}" of an invalid type {2} (only primitive, vector and matrix types are supported)". /// /// public static readonly DiagnosticDescriptor InvalidShaderStaticFieldType = new DiagnosticDescriptor( id: "CMPSD2D0030", title: "Invalid shader static readonly field type", - messageFormat: "The compute shader of type {0} contains a static readonly field \"{1}\" of an invalid type {2} (only primitive, vector and matrix types are supported)", + messageFormat: """The compute shader of type {0} contains a static readonly field "{1}" of an invalid type {2} (only primitive, vector and matrix types are supported)""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -417,13 +417,13 @@ partial class DiagnosticDescriptors /// /// Gets a for a property declaration. /// - /// Format: "The D2D1 shader of type {0} contains an invalid property \"{1}\" declaration (only stateless properties explicitly implementing an interface property can be used)". + /// Format: "The D2D1 shader of type {0} contains an invalid property "{1}" declaration (only stateless properties explicitly implementing an interface property can be used)". /// /// public static readonly DiagnosticDescriptor InvalidPropertyDeclaration = new DiagnosticDescriptor( id: "CMPSD2D0031", title: "Invalid property declaration", - messageFormat: "The D2D1 shader of type {0} contains an invalid property \"{1}\" declaration (only stateless properties explicitly implementing an interface property can be used)", + messageFormat: """The D2D1 shader of type {0} contains an invalid property "{1}" declaration (only stateless properties explicitly implementing an interface property can be used)""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -455,7 +455,7 @@ partial class DiagnosticDescriptors public static readonly DiagnosticDescriptor EmbeddedBytecodeFailedWithWin32Exception = new DiagnosticDescriptor( id: "CMPSD2D0033", title: "Embedded bytecode compilation failed due to Win32 exception", - messageFormat: "The shader of type {0} failed to compile due to a Win32 exception (HRESULT: {1:X8}, Message: \"{2}\")", + messageFormat: """The shader of type {0} failed to compile due to a Win32 exception (HRESULT: {1:X8}, Message: "{2}")""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -471,7 +471,7 @@ partial class DiagnosticDescriptors public static readonly DiagnosticDescriptor EmbeddedBytecodeFailedWithFxcCompilationException = new DiagnosticDescriptor( id: "CMPSD2D0034", title: "Embedded bytecode compilation failed due to an HLSL compiler error", - messageFormat: "The shader of type {0} failed to compile due to an HLSL compiler error (Message: \"{1}\")", + messageFormat: """The shader of type {0} failed to compile due to an HLSL compiler error (Message: "{1}")""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -706,13 +706,13 @@ partial class DiagnosticDescriptors /// /// Gets a for an invalid use of [D2DResourceTextureIndex]. /// - /// Format: "The field \"{0}\" (in type {1}) is using [D2DResourceTextureIndex] incorrectly (the attribute can only be used on D2D1 resource texture types, but the field is of type {2})". + /// Format: "The field "{0}" (in type {1}) is using [D2DResourceTextureIndex] incorrectly (the attribute can only be used on D2D1 resource texture types, but the field is of type {2})". /// /// public static readonly DiagnosticDescriptor InvalidD2DResourceTextureIndexAttributeUse = new DiagnosticDescriptor( id: "CMPSD2D0049", title: "Invalid [D2DResourceTextureIndex] use", - messageFormat: "The field \"{0}\" (in type {1}) is using [D2DResourceTextureIndex] incorrectly (the attribute can only be used on D2D1 resource texture types, but the field is of type {2})", + messageFormat: """The field "{0}" (in type {1}) is using [D2DResourceTextureIndex] incorrectly (the attribute can only be used on D2D1 resource texture types, but the field is of type {2})""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -722,13 +722,13 @@ partial class DiagnosticDescriptors /// /// Gets a for a missing [D2DResourceTextureIndex]. /// - /// Format: "The field \"{0}\" (in type {1}) is of a D2D1 resource texture type but is missing the [D2DResourceTextureIndex] attribute". + /// Format: "The field "{0}" (in type {1}) is of a D2D1 resource texture type but is missing the [D2DResourceTextureIndex] attribute". /// /// public static readonly DiagnosticDescriptor MissingD2DResourceTextureIndexAttribute = new DiagnosticDescriptor( id: "CMPSD2D0050", title: "Missing [D2DResourceTextureIndex] attribute", - messageFormat: "The field \"{0}\" (in type {1}) is of a D2D1 resource texture type but is missing the [D2DResourceTextureIndex] attribute", + messageFormat: """The field "{0}" (in type {1}) is of a D2D1 resource texture type but is missing the [D2DResourceTextureIndex] attribute""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -738,13 +738,13 @@ partial class DiagnosticDescriptors /// /// Gets a for a resource texture using an invalid element type. /// - /// Format: "The field \"{0}\" (in type {1}) using a D2D1 resource texture of type {2} has an invalid element type (only float and float4 type arguments are supported)". + /// Format: "The field "{0}" (in type {1}) using a D2D1 resource texture of type {2} has an invalid element type (only float and float4 type arguments are supported)". /// /// public static readonly DiagnosticDescriptor InvalidResourceTextureElementType = new DiagnosticDescriptor( id: "CMPSD2D0051", title: "Invalid D2D1 resource texture element type", - messageFormat: "The field \"{0}\" (in type {1}) using a D2D1 resource texture of type {2} has an invalid element type (only float and float4 type arguments are supported)", + messageFormat: """The field "{0}" (in type {1}) using a D2D1 resource texture of type {2} has an invalid element type (only float and float4 type arguments are supported)""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -754,13 +754,13 @@ partial class DiagnosticDescriptors /// /// Gets a for an invalid HLSL source in [D2DPixelShaderSource]. /// - /// Format: "The method \"{0}\" (in type {1}) is using [D2DPixelShaderSource] with an invalid HLSL source argument". + /// Format: "The method "{0}" (in type {1}) is using [D2DPixelShaderSource] with an invalid HLSL source argument". /// /// public static readonly DiagnosticDescriptor InvalidD2DPixelShaderSource = new DiagnosticDescriptor( id: "CMPSD2D0052", title: "Invalid [D2DPixelShaderSource] HLSL source argument", - messageFormat: "The method \"{0}\" (in type {1}) is using [D2DPixelShaderSource] with an invalid HLSL source argument", + messageFormat: """The method "{0}" (in type {1}) is using [D2DPixelShaderSource] with an invalid HLSL source argument""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -770,13 +770,13 @@ partial class DiagnosticDescriptors /// /// Gets a for an embedded bytecode D2D shader failed due to a Win32 exception. /// - /// Format: "Compiling the HLSL source for method \"{1}\" (in type {0}) failed due to a Win32 exception (HRESULT: {2:X8}, Message: \"{3}\")". + /// Format: "Compiling the HLSL source for method "{1}" (in type {0}) failed due to a Win32 exception (HRESULT: {2:X8}, Message: "{3}")". /// /// public static readonly DiagnosticDescriptor D2DPixelShaderSourceCompilationFailedWithWin32Exception = new DiagnosticDescriptor( id: "CMPSD2D0053", title: "D2D shader compilation failed due to Win32 exception", - messageFormat: "Compiling the HLSL source for method \"{1}\" (in type {0}) failed due to a Win32 exception (HRESULT: {2:X8}, Message: \"{3}\")", + messageFormat: """Compiling the HLSL source for method "{1}" (in type {0}) failed due to a Win32 exception (HRESULT: {2:X8}, Message: "{3}")""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -786,13 +786,13 @@ partial class DiagnosticDescriptors /// /// Gets a for an embedded bytecode D2D shader failed due to an HLSL compilation exception. /// - /// Format: "Compiling the HLSL source for method \"{1}\" (in type {0}) failed due to an HLSL compiler error (Message: \"{2}\")". + /// Format: "Compiling the HLSL source for method "{1}" (in type {0}) failed due to an HLSL compiler error (Message: "{2}")". /// /// public static readonly DiagnosticDescriptor D2DPixelShaderSourceCompilationFailedWithFxcCompilationException = new DiagnosticDescriptor( id: "CMPSD2D0054", title: "D2D shader compilation failed due to an HLSL compiler error", - messageFormat: "Compiling the HLSL source for method \"{1}\" (in type {0}) failed due to an HLSL compiler error (Message: \"{2}\")", + messageFormat: """Compiling the HLSL source for method "{1}" (in type {0}) failed due to an HLSL compiler error (Message: "{2}")""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -802,13 +802,13 @@ partial class DiagnosticDescriptors /// /// Gets a for an embedded bytecode D2D shader with no shader profile set. /// - /// Format: "The method \"{0}\" (in type {1}) is using [D2DPixelShaderSource] but has not specified the shader profile to use". + /// Format: "The method "{0}" (in type {1}) is using [D2DPixelShaderSource] but has not specified the shader profile to use". /// /// public static readonly DiagnosticDescriptor MissingShaderProfileForD2DPixelShaderSource = new DiagnosticDescriptor( id: "CMPSD2D0055", title: "Missing shader profile for D2D pixel shader source", - messageFormat: "The method \"{0}\" (in type {1}) is using [D2DPixelShaderSource] but has not specified the shader profile to use", + messageFormat: """The method "{0}" (in type {1}) is using [D2DPixelShaderSource] but has not specified the shader profile to use""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -818,13 +818,13 @@ partial class DiagnosticDescriptors /// /// Gets a for an embedded bytecode D2D shader with no compile options set. /// - /// Format: "The method \"{0}\" (in type {1}) is using [D2DPixelShaderSource] but has not specified the compile options to use". + /// Format: "The method "{0}" (in type {1}) is using [D2DPixelShaderSource] but has not specified the compile options to use". /// /// public static readonly DiagnosticDescriptor MissingCompileOptionsForD2DPixelShaderSource = new DiagnosticDescriptor( id: "CMPSD2D0056", title: "Missing compile options for D2D pixel shader source", - messageFormat: "The method \"{0}\" (in type {1}) is using [D2DPixelShaderSource] but has not specified the compile options to use", + messageFormat: """The method "{0}" (in type {1}) is using [D2DPixelShaderSource] but has not specified the compile options to use""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -834,13 +834,13 @@ partial class DiagnosticDescriptors /// /// Gets a for when a method with [D2DPixelShaderSource] has an invalid return type. /// - /// Format: "The method \"{0}\" (in type {1}) is using [D2DPixelShaderSource] but has an invalid return type {2} (it must return a ReadOnlySpan<byte>)". + /// Format: "The method "{0}" (in type {1}) is using [D2DPixelShaderSource] but has an invalid return type {2} (it must return a ReadOnlySpan<byte>)". /// /// public static readonly DiagnosticDescriptor InvalidD2DPixelShaderSourceMethodReturnType = new DiagnosticDescriptor( id: "CMPSD2D0057", title: "Missing compile options for D2D pixel shader source", - messageFormat: "The method \"{0}\" (in type {1}) is using [D2DPixelShaderSource] but has an invalid return type {2} (it must return a ReadOnlySpan)", + messageFormat: """The method "{0}" (in type {1}) is using [D2DPixelShaderSource] but has an invalid return type {2} (it must return a ReadOnlySpan)""", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, diff --git a/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs b/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs index 8fd642cb..0d5f840a 100644 --- a/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs +++ b/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs @@ -21,7 +21,7 @@ partial class DiagnosticDescriptors public static readonly DiagnosticDescriptor InvalidShaderField = new DiagnosticDescriptor( id: "CMPS0001", title: "Invalid shader field", - messageFormat: "The compute shader of type {0} contains a field \"{1}\" of an invalid type {2}", + messageFormat: """The compute shader of type {0} contains a field "{1}" of an invalid type {2}""", category: "ComputeSharp.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -37,7 +37,7 @@ partial class DiagnosticDescriptors public static readonly DiagnosticDescriptor InvalidGroupSharedFieldType = new DiagnosticDescriptor( id: "CMPS0002", title: "Invalid group shared field type", - messageFormat: "The compute shader of type {0} contains a group shared field \"{1}\" of an invalid type {2} (it must be an array)", + messageFormat: """The compute shader of type {0} contains a group shared field "{1}" of an invalid type {2} (it must be an array)""", category: "ComputeSharp.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -53,7 +53,7 @@ partial class DiagnosticDescriptors public static readonly DiagnosticDescriptor InvalidGroupSharedFieldElementType = new DiagnosticDescriptor( id: "CMPS0003", title: "Invalid group shared field element type", - messageFormat: "The compute shader of type {0} contains a group shared field \"{1}\" of an invalid type {2} (it must be a primitive or unmanaged type)", + messageFormat: """The compute shader of type {0} contains a group shared field "{1}" of an invalid type {2} (it must be a primitive or unmanaged type)""", category: "ComputeSharp.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -69,7 +69,7 @@ partial class DiagnosticDescriptors public static readonly DiagnosticDescriptor InvalidGroupSharedFieldDeclaration = new DiagnosticDescriptor( id: "CMPS0004", title: "Invalid group shared field declaration", - messageFormat: "The compute shader of type {0} contains a group shared field \"{1}\" that is not static", + messageFormat: """The compute shader of type {0} contains a group shared field "{1}" that is not static""", category: "ComputeSharp.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -517,13 +517,13 @@ partial class DiagnosticDescriptors /// /// Gets a for an invalid shader static field type. /// - /// Format: "The compute shader of type {0} contains a static field \"{1}\" of an invalid type {2} (only primitive, vector and matrix types are supported)". + /// Format: "The compute shader of type {0} contains a static field "{1}" of an invalid type {2} (only primitive, vector and matrix types are supported)". /// /// public static readonly DiagnosticDescriptor InvalidShaderStaticFieldType = new DiagnosticDescriptor( id: "CMPS0038", title: "Invalid shader static field type", - messageFormat: "The compute shader of type {0} contains a static field \"{1}\" of an invalid type {2} (only primitive, vector and matrix types are supported)", + messageFormat: """The compute shader of type {0} contains a static field "{1}" of an invalid type {2} (only primitive, vector and matrix types are supported)""", category: "ComputeSharp.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -546,13 +546,13 @@ partial class DiagnosticDescriptors /// /// Gets a for a property declaration. /// - /// Format: "The compute shader of type {0} contains an invalid property \"{1}\" declaration (only stateless properties explicitly implementing an interface property can be used)". + /// Format: "The compute shader of type {0} contains an invalid property "{1}" declaration (only stateless properties explicitly implementing an interface property can be used)". /// /// public static readonly DiagnosticDescriptor InvalidPropertyDeclaration = new DiagnosticDescriptor( id: "CMPS0040", title: "Invalid property declaration", - messageFormat: "The compute shader of type {0} contains an invalid property \"{1}\" declaration (only stateless properties explicitly implementing an interface property can be used)", + messageFormat: """The compute shader of type {0} contains an invalid property "{1}" declaration (only stateless properties explicitly implementing an interface property can be used)""", category: "ComputeSharp.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -616,7 +616,7 @@ partial class DiagnosticDescriptors public static readonly DiagnosticDescriptor EmbeddedBytecodeFailedWithWin32Exception = new DiagnosticDescriptor( id: "CMPS0045", title: "Embedded bytecode compilation failed due to Win32 exception", - messageFormat: "The shader of type {0} failed to compile due to a Win32 exception (HRESULT: {1:X8}, Message: \"{2}\")", + messageFormat: """The shader of type {0} failed to compile due to a Win32 exception (HRESULT: {1:X8}, Message: "{2}")""", category: "ComputeSharp.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -632,7 +632,7 @@ partial class DiagnosticDescriptors public static readonly DiagnosticDescriptor EmbeddedBytecodeFailedWithDxcCompilationException = new DiagnosticDescriptor( id: "CMPS0046", title: "Embedded bytecode compilation failed due to an HLSL compiler error", - messageFormat: "The shader of type {0} failed to compile due to an HLSL compiler error (Message: \"{1}\")", + messageFormat: """The shader of type {0} failed to compile due to an HLSL compiler error (Message: "{1}")""", category: "ComputeSharp.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, diff --git a/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs b/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs index 4d701d54..a291d85e 100644 --- a/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs +++ b/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs @@ -19,20 +19,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + [GeneratedComputeShaderDescriptor] + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; - public string text; + public ReadWriteBuffer buffer; + public string text; - public void Execute() { } - } + public void Execute() { } } """; @@ -45,20 +40,14 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public unsafe struct MyShader : IComputeShader { - public unsafe struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; - public fixed int text[16]; + public ReadWriteBuffer buffer; + public fixed int text[16]; - public void Execute() { } - } + public void Execute() { } } """; @@ -71,23 +60,16 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp + namespace MyFancyApp.Sample; + + public struct MyShader : IComputeShader { - public class ReadWriteBuffer { } - public class GroupSharedAttribute : Attribute { } - } + public ReadWriteBuffer buffer; - namespace MyFancyApp.Sample - { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + [GroupShared] + public static string text; - [GroupShared] - public static string text; - - public void Execute() { } - } + public void Execute() { } } """; @@ -100,23 +82,16 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp + namespace MyFancyApp.Sample; + + public struct MyShader : IComputeShader { - public class ReadWriteBuffer { } - public class GroupSharedAttribute : Attribute { } - } + public ReadWriteBuffer buffer; - namespace MyFancyApp.Sample - { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + [GroupShared] + public static string[] text; - [GroupShared] - public static string[] text; - - public void Execute() { } - } + public void Execute() { } } """; @@ -129,21 +104,14 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - public class GroupSharedAttribute : Attribute { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - [GroupShared] - public ReadWriteBuffer buffer; + [GroupShared] + public ReadWriteBuffer buffer; - public void Execute() { } - } + public void Execute() { } } """; @@ -156,12 +124,11 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace MyFancyApp.Sample + namespace MyFancyApp.Sample; + + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public void Execute() { } - } + public void Execute() { } } """; @@ -179,24 +146,17 @@ public class DiagnosticsTests string source = $$""" using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - public static class {{typeName}} { public static int X => 0; } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; + static int Fail() => {{typeName}}.X; - public void Execute() - { - static int Fail() => {{typeName}}.X; - - Fail(); - } + Fail(); } } """; @@ -215,22 +175,15 @@ public class DiagnosticsTests string source = $$""" using ComputeSharp; - namespace ComputeSharp + namespace MyFancyApp.Sample; + + public struct MyShader : IComputeShader { - public class ReadWriteBuffer { } - public static class {{typeName}} { public static int X => 0; } - } + public ReadWriteBuffer buffer; - namespace MyFancyApp.Sample - { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public static int Fail() => {{typeName}}.X; - public static int Fail() => {{typeName}}.X; - - public void Execute() => Fail(); - } + public void Execute() => Fail(); } """; @@ -243,24 +196,17 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - public static class ThreadIds { public static class Normalized { public static int X => 0; } } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public static int Fail() => ThreadIds.Normalized.X; + + public void Execute() { - public ReadWriteBuffer buffer; - - public static int Fail() => ThreadIds.Normalized.X; - - public void Execute() - { - buffer[0] = Fail(); - } + buffer[0] = Fail(); } } """; @@ -274,21 +220,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() - { - object o = new object(); - } + object o = new object(); } } """; @@ -302,21 +242,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() - { - object o = new(); - } + object o = new(); } } """; @@ -330,21 +264,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() - { - var o = new { Age = 12 }; - } + var o = new { Age = 12 }; } } """; @@ -358,23 +286,17 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; + static async void Fail() { } - public void Execute() - { - static async void Fail() { } - - Fail(); - } + Fail(); } } """; @@ -388,21 +310,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp + namespace MyFancyApp.Sample; + + public struct MyShader : IComputeShader { - public class ReadWriteBuffer { } - } + public ReadWriteBuffer buffer; - namespace MyFancyApp.Sample - { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public static async void Fail() { } - public static async void Fail() { } - - public void Execute() => Fail(); - } + public void Execute() => Fail(); } """; @@ -415,21 +331,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public async void Execute() { - public ReadWriteBuffer buffer; - - public async void Execute() - { - await null; - } + await null; } } """; @@ -445,21 +355,15 @@ public class DiagnosticsTests string source = $$""" using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() - { - int a = {{text}}(1 + 1); - } + int a = {{text}}(1 + 1); } } """; @@ -475,23 +379,17 @@ public class DiagnosticsTests string source = $$""" using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() + {{text}} { - {{text}} - { - int a = 1 + 1; - } + int a = 1 + 1; } } } @@ -506,25 +404,16 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer - { - public int[] Data; - } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - fixed (void* p = buffer.Data) - { - } + public void Execute() + { + fixed (void* p = buffer.Data) + { } } } @@ -539,25 +428,16 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer - { - public int[] Data; - } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - foreach (int i in buffer.Data) - { - } + public void Execute() + { + foreach (int i in buffer.Data) + { } } } @@ -572,22 +452,16 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - lock (buffer) - { - } + public void Execute() + { + lock (buffer) + { } } } @@ -602,24 +476,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer - { - public int[] Data; - } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - _ = from x in buffer.Data select x; - } + public void Execute() + { + _ = from x in buffer.Data select x; } } """; @@ -633,24 +498,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer - { - public int[] Data; - } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - _ = buffer.Data[1..]; - } + public void Execute() + { + _ = buffer.Data[1..]; } } """; @@ -664,25 +520,16 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer - { - public object Data; - } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - if (buffer.Data is int[] { Length: 50 } foo) - { - } + public void Execute() + { + if (buffer.Data is int[] { Length: 50 } foo) + { } } } @@ -697,24 +544,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer - { - public ref T this[int x] => throw null; - } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - ref float x = ref buffer[0]; - } + public void Execute() + { + ref float x = ref buffer[0]; } } """; @@ -728,25 +566,16 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer - { - public int Data; - } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - if (buffer.Data is > 0 and < 10) - { - } + public void Execute() + { + if (buffer.Data is > 0 and < 10) + { } } } @@ -761,21 +590,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - _ = sizeof(float); - } + public void Execute() + { + _ = sizeof(float); } } """; @@ -789,21 +612,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - int* p = stackalloc int[10]; - } + public void Execute() + { + int* p = stackalloc int[10]; } } """; @@ -817,21 +634,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - throw null; - } + public void Execute() + { + throw null; } } """; @@ -845,25 +656,19 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() + try + { + } + catch { - try - { - } - catch - { - } } } } @@ -878,21 +683,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() - { - (int, float) foo; - } + (int, float) foo; } } """; @@ -906,21 +705,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() - { - using IDisposable foo = null - } + using IDisposable foo = null } } """; @@ -934,22 +727,16 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() + using (IDisposable foo = null) { - using (IDisposable foo = null) - { - } } } } @@ -965,26 +752,20 @@ public class DiagnosticsTests using System.Collections.Generic; using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public static IEnumerable Fail() { - public ReadWriteBuffer buffer; + yield return 3.14f; + } - public static IEnumerable Fail() - { - yield return 3.14f; - } - - public void Execute() - { - Fail(); - } + public void Execute() + { + Fail(); } } """; @@ -998,21 +779,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() - { - string bar; - } + string bar; } } """; @@ -1026,21 +801,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() - { - int* p; - } + int* p; } } """; @@ -1054,21 +823,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() - { - delegate* f; - } + delegate* f; } } """; @@ -1082,22 +845,16 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() + unsafe { - unsafe - { - } } } } @@ -1112,23 +869,17 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; + static unsafe void Fail() { } - public void Execute() - { - static unsafe void Fail() { } - - Fail(); - } + Fail(); } } """; @@ -1142,23 +893,17 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public static unsafe void Fail() { } + + public ReadWriteBuffer buffer; + + public void Execute() { - public static unsafe void Fail() { } - - public ReadWriteBuffer buffer; - - public void Execute() - { - Fail(); - } + Fail(); } } """; @@ -1172,21 +917,15 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + public void Execute() { - public ReadWriteBuffer buffer; - - public void Execute() - { - _ = "Hello world"; - } + _ = "Hello world"; } } """; @@ -1203,34 +942,17 @@ public class DiagnosticsTests using float4 = ComputeSharp.Float4; using float4x4 = ComputeSharp.Float4x4; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - public enum MatrixIndex - { - M11, - M12, - M13 - }, - public struct Float4 { } - public struct Float4x4 - { - public Float4 this[MatrixIndex m0, MatrixIndex m1, MatrixIndex m2, MatrixIndex m3] => default; - } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - float4x4 m = default; - MatrixIndex index = M12; - float4 = m[M11, index, M13, M11]; - } + public void Execute() + { + float4x4 m = default; + MatrixIndex index = M12; + float4 = m[M11, index, M13, M11]; } } """; @@ -1244,22 +966,16 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + private static string Pi = ""Hello""; + + public void Execute() { - public ReadWriteBuffer buffer; - - private static string Pi = ""Hello""; - - public void Execute() - { - } } } """; @@ -1273,22 +989,16 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + private static float Pi { get; } = 3.14f; + + public void Execute() { - public ReadWriteBuffer buffer; - - private static float Pi { get; } = 3.14f; - - public void Execute() - { - } } } """; @@ -1302,27 +1012,21 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp + namespace MyFancyApp.Sample; + + public interface IFoo { - public class ReadWriteBuffer { } + float Pi { get; } } - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader, IFoo { - public interface IFoo + public ReadWriteBuffer buffer; + + float IFoo.Pi { get; } = 3.14f; + + public void Execute() { - float Pi { get; } - } - - public struct MyShader : IComputeShader, IFoo - { - public ReadWriteBuffer buffer; - - float IFoo.Pi { get; } = 3.14f; - - public void Execute() - { - } } } """; @@ -1336,25 +1040,19 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + private static float Pi { - public ReadWriteBuffer buffer; + get => 3.14f; + } - private static float Pi - { - get => 3.14f; - } - - public void Execute() - { - } + public void Execute() + { } } """; @@ -1368,22 +1066,16 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + private static float Pi { get; set; } = 3.14f; + + public void Execute() { - public ReadWriteBuffer buffer; - - private static float Pi { get; set; } = 3.14f; - - public void Execute() - { - } } } """; @@ -1397,22 +1089,16 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public ReadWriteBuffer buffer; + + private float Pi => 3.14f; + + public void Execute() { - public ReadWriteBuffer buffer; - - private float Pi => 3.14f; - - public void Execute() - { - } } } """; @@ -1428,26 +1114,18 @@ public class DiagnosticsTests using double4x4 = ComputeSharp.Double4x4; using float4 = ComputeSharp.Float4; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - public struct Double4x4 { } - public struct Float4 { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public readonly ReadWriteBuffer buffer; + public readonly double4x4 a; + public readonly double4x4 b; + public readonly int c; + public readonly float4 d; + + public void Execute() { - public readonly ReadWriteBuffer buffer; - public readonly double4x4 a; - public readonly double4x4 b; - public readonly int c; - public readonly float4 d; - - public void Execute() - { - } } } """; @@ -1461,19 +1139,12 @@ public class DiagnosticsTests const string source = """ using ComputeSharp; - namespace ComputeSharp - { - public interface IComputeShader { } - public interface IComputeShader { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader, IComputeShader { - public struct MyShader : IComputeShader, IComputeShader + public void Execute() { - public void Execute() - { - } } } """; @@ -1494,26 +1165,15 @@ public class DiagnosticsTests using System; using ComputeSharp; - namespace ComputeSharp - { - public interface IComputeShader { } - public class ReadWriteBuffer { } - public class EmbeddedBytecodeAttribute : Attribute - { - public EmbeddedBytecodeAttribute(int threadsX, int threadsY, int threadsZ) { } - } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + [EmbeddedBytecode({{threadsX}}, {{threadsY}}, {{threadsZ}})] + public struct MyShader : IComputeShader { - [EmbeddedBytecode({{threadsX}}, {{threadsY}}, {{threadsZ}})] - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - } + public void Execute() + { } } """; @@ -1528,27 +1188,15 @@ public class DiagnosticsTests using System; using ComputeSharp; - namespace ComputeSharp - { - public interface IComputeShader { } - public class ReadWriteBuffer { } - public enum DispatchAxis { X, Y, Z, XY, XZ, YZ, XYZ } - public class EmbeddedBytecodeAttribute : Attribute - { - public EmbeddedBytecodeAttribute(DispatchAxis dispatchAxis) { } - } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + [EmbeddedBytecode(DispatchAxis.XYZ | DispatchAxis.Y)] + public struct MyShader : IComputeShader { - [EmbeddedBytecode(DispatchAxis.XYZ | DispatchAxis.Y)] - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - } + public void Execute() + { } } """; @@ -1563,27 +1211,15 @@ public class DiagnosticsTests using System; using ComputeSharp; - namespace ComputeSharp - { - public interface IComputeShader { } - public class ReadWriteBuffer { } - public enum DispatchAxis { X, Y, Z, XY, XZ, YZ, XYZ } - public class EmbeddedBytecodeAttribute : Attribute - { - public EmbeddedBytecodeAttribute(DispatchAxis dispatchAxis) { } - } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + [EmbeddedBytecode((DispatchAxis)243712)] + public struct MyShader : IComputeShader { - [EmbeddedBytecode((DispatchAxis)243712)] - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - } + public void Execute() + { } } """; @@ -1598,27 +1234,15 @@ public class DiagnosticsTests using System; using ComputeSharp; - namespace ComputeSharp - { - public interface IComputeShader { } - public class ReadWriteBuffer { } - public enum DispatchAxis { X, Y, Z, XY, XZ, YZ, XYZ } - public class EmbeddedBytecodeAttribute : Attribute - { - public EmbeddedBytecodeAttribute(DispatchAxis dispatchAxis) { } - } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + [EmbeddedBytecode((DispatchAxis)(-289))] + public struct MyShader : IComputeShader { - [EmbeddedBytecode((DispatchAxis)(-289))] - public struct MyShader : IComputeShader - { - public ReadWriteBuffer buffer; + public ReadWriteBuffer buffer; - public void Execute() - { - } + public void Execute() + { } } """; @@ -1633,21 +1257,15 @@ public class DiagnosticsTests using System; using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public readonly ReadWriteBuffer buffer; + + public void Execute() { - public readonly ReadWriteBuffer buffer; - - public void Execute() - { - buffer[0] = Convert.ToSingle(42); - } + buffer[0] = Convert.ToSingle(42); } } """; @@ -1662,21 +1280,15 @@ public class DiagnosticsTests using System; using ComputeSharp; - namespace ComputeSharp - { - public class ReadWriteBuffer { } - } + namespace MyFancyApp.Sample; - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct MyShader : IComputeShader + public readonly ReadWriteBuffer buffer; + + public void Execute() { - public readonly ReadWriteBuffer buffer; - - public void Execute() - { - buffer[0] = (byte)42; - } + buffer[0] = (byte)42; } } """; @@ -1691,27 +1303,21 @@ public class DiagnosticsTests using System; using ComputeSharp; - namespace ComputeSharp + namespace MyFancyApp.Sample; + + public struct Foo { - public class ReadWriteBuffer { } + public DateTime bar; } - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct Foo - { - public DateTime bar; - } + public readonly ReadWriteBuffer buffer; - public struct MyShader : IComputeShader + public void Execute() { - public readonly ReadWriteBuffer buffer; - - public void Execute() - { - Foo foo = default; - buffer[0] = 42; - } + Foo foo = default; + buffer[0] = 42; } } """; @@ -1726,25 +1332,19 @@ public class DiagnosticsTests using System; using ComputeSharp; - namespace ComputeSharp + namespace MyFancyApp.Sample; + + public struct Foo { - public class ReadWriteBuffer { } + public bool bar; } - namespace MyFancyApp.Sample + public struct MyShader : IComputeShader { - public struct Foo - { - public bool bar; - } + public readonly ReadWriteBuffer buffer; - public struct MyShader : IComputeShader + public void Execute() { - public readonly ReadWriteBuffer buffer; - - public void Execute() - { - } } } """; @@ -1761,8 +1361,11 @@ public class DiagnosticsTests private static void VerifyGeneratedDiagnostics(string source, params string[] diagnosticsIds) where TGenerator : class, IIncrementalGenerator, new() { - SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(source); + // Ensure ComputeSharp.Core and ComputeSharp are loaded + Type hlslType = typeof(Hlsl); + Type computeShaderType = typeof(IComputeShader); + // Get all assembly references for the loaded assemblies (easy way to pull in all necessary dependencies) IEnumerable references = from assembly in AppDomain.CurrentDomain.GetAssemblies() where !assembly.IsDynamic @@ -1771,7 +1374,7 @@ public class DiagnosticsTests CSharpCompilation compilation = CSharpCompilation.Create( "original", - new SyntaxTree[] { syntaxTree }, + new SyntaxTree[] { CSharpSyntaxTree.ParseText(source) }, references, new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true)); @@ -1784,5 +1387,17 @@ public class DiagnosticsTests HashSet resultingIds = diagnostics.Select(diagnostic => diagnostic.Id).ToHashSet(); Assert.IsTrue(resultingIds.SetEquals(diagnosticsIds)); + + // If the compilation was supposed to succeed, ensure that no further errors were generated + if (diagnosticsIds.Length == 0) + { + // Compute diagnostics for the final compiled output (just include errors) + List outputCompilationDiagnostics = outputCompilation.GetDiagnostics().Where(diagnostic => diagnostic.Severity == DiagnosticSeverity.Error).ToList(); + + Assert.IsTrue(outputCompilationDiagnostics.Count == 0, $"resultingIds: {string.Join(", ", outputCompilationDiagnostics)}"); + } + + GC.KeepAlive(hlslType); + GC.KeepAlive(computeShaderType); } } \ No newline at end of file From 2d60216b3149ec8eb92b01ae1cf579cd8ab4c75b Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 16 Oct 2023 23:19:43 +0200 Subject: [PATCH 14/14] Fix ComputeSharp.Tests.SourceGenerator tests --- ...ComputeSharp.Tests.SourceGenerators.csproj | 7 +- .../DiagnosticsTests.cs | 324 +++++++++++------- 2 files changed, 202 insertions(+), 129 deletions(-) diff --git a/tests/ComputeSharp.Tests.SourceGenerators/ComputeSharp.Tests.SourceGenerators.csproj b/tests/ComputeSharp.Tests.SourceGenerators/ComputeSharp.Tests.SourceGenerators.csproj index 49d3d836..a0a2c77c 100644 --- a/tests/ComputeSharp.Tests.SourceGenerators/ComputeSharp.Tests.SourceGenerators.csproj +++ b/tests/ComputeSharp.Tests.SourceGenerators/ComputeSharp.Tests.SourceGenerators.csproj @@ -4,14 +4,17 @@ - + + - + + + diff --git a/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs b/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs index a291d85e..9c12234f 100644 --- a/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs +++ b/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs @@ -1,7 +1,11 @@ +extern alias Core; +extern alias D3D12; + using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; +using Basic.Reference.Assemblies; using ComputeSharp.SourceGenerators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; @@ -22,7 +26,7 @@ public class DiagnosticsTests namespace MyFancyApp.Sample; [GeneratedComputeShaderDescriptor] - public struct MyShader : IComputeShader + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; public string text; @@ -41,8 +45,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public unsafe struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public unsafe partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; public fixed int text[16]; @@ -61,8 +66,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -83,8 +89,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -105,8 +112,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { [GroupShared] public ReadWriteBuffer buffer; @@ -125,8 +133,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public void Execute() { } } @@ -147,8 +156,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -176,8 +186,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -197,8 +208,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -221,8 +233,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -243,8 +256,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -265,8 +279,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -287,8 +302,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -311,8 +327,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -332,14 +349,15 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; public async void Execute() { - await null; + await System.Threading.Tasks.Task.CompletedTask; } } """; @@ -356,8 +374,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -380,8 +399,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -406,11 +426,12 @@ public class DiagnosticsTests namespace MyFancyApp.Sample; - public struct MyShader : IComputeShader + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; - public void Execute() + public unsafe void Execute() { fixed (void* p = buffer.Data) { @@ -419,7 +440,7 @@ public class DiagnosticsTests } """; - VerifyGeneratedDiagnostics(source, "CMPS0016", "CMPS0032", "CMPS0047"); + VerifyGeneratedDiagnostics(source, "CMPS0016", "CMPS0032", "CMPS0035", "CMPS0047"); } [TestMethod] @@ -429,8 +450,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -453,8 +475,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -477,8 +500,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -499,8 +523,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -521,8 +546,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -545,8 +571,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -567,8 +594,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -591,8 +619,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -613,8 +642,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -635,8 +665,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -657,8 +688,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -684,8 +716,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -706,8 +739,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -728,8 +762,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -753,8 +788,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -780,8 +816,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -802,8 +839,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -824,8 +862,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -846,8 +885,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -870,8 +910,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -894,8 +935,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public static unsafe void Fail() { } @@ -918,8 +960,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -943,8 +986,9 @@ public class DiagnosticsTests using float4x4 = ComputeSharp.Float4x4; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -967,8 +1011,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -990,8 +1035,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -1018,8 +1064,9 @@ public class DiagnosticsTests { float Pi { get; } } - - public struct MyShader : IComputeShader, IFoo + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader, IFoo { public ReadWriteBuffer buffer; @@ -1041,8 +1088,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -1067,8 +1115,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -1090,8 +1139,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -1115,8 +1165,9 @@ public class DiagnosticsTests using float4 = ComputeSharp.Float4; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public readonly ReadWriteBuffer buffer; public readonly double4x4 a; @@ -1140,8 +1191,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader, IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader, IComputeShader { public void Execute() { @@ -1168,7 +1220,8 @@ public class DiagnosticsTests namespace MyFancyApp.Sample; [EmbeddedBytecode({{threadsX}}, {{threadsY}}, {{threadsZ}})] - public struct MyShader : IComputeShader + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -1191,7 +1244,8 @@ public class DiagnosticsTests namespace MyFancyApp.Sample; [EmbeddedBytecode(DispatchAxis.XYZ | DispatchAxis.Y)] - public struct MyShader : IComputeShader + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -1214,7 +1268,8 @@ public class DiagnosticsTests namespace MyFancyApp.Sample; [EmbeddedBytecode((DispatchAxis)243712)] - public struct MyShader : IComputeShader + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -1237,7 +1292,8 @@ public class DiagnosticsTests namespace MyFancyApp.Sample; [EmbeddedBytecode((DispatchAxis)(-289))] - public struct MyShader : IComputeShader + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public ReadWriteBuffer buffer; @@ -1258,8 +1314,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -1281,8 +1338,9 @@ public class DiagnosticsTests using ComputeSharp; namespace MyFancyApp.Sample; - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -1309,8 +1367,9 @@ public class DiagnosticsTests { public DateTime bar; } - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -1338,8 +1397,9 @@ public class DiagnosticsTests { public bool bar; } - - public struct MyShader : IComputeShader + + [GeneratedComputeShaderDescriptor] + public partial struct MyShader : IComputeShader { public readonly ReadWriteBuffer buffer; @@ -1362,31 +1422,41 @@ public class DiagnosticsTests where TGenerator : class, IIncrementalGenerator, new() { // Ensure ComputeSharp.Core and ComputeSharp are loaded - Type hlslType = typeof(Hlsl); - Type computeShaderType = typeof(IComputeShader); + Type hlslType = typeof(Core::ComputeSharp.Hlsl); + Type computeShaderType = typeof(D3D12::ComputeSharp.IComputeShader); + + // Prepare the two additional metadata references + IEnumerable additionalReferences = new[] + { + MetadataReference.CreateFromFile(hlslType.Assembly.Location), + MetadataReference.CreateFromFile(computeShaderType.Assembly.Location) + }; // Get all assembly references for the loaded assemblies (easy way to pull in all necessary dependencies) - IEnumerable references = - from assembly in AppDomain.CurrentDomain.GetAssemblies() - where !assembly.IsDynamic - let reference = MetadataReference.CreateFromFile(assembly.Location) - select reference; + IEnumerable metadataReferences = Net70.References.All.Concat(additionalReferences); + // Parse the source text (C# 11) + SyntaxTree sourceTree = CSharpSyntaxTree.ParseText( + source, + CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp11)); + + // Create the original compilation CSharpCompilation compilation = CSharpCompilation.Create( "original", - new SyntaxTree[] { CSharpSyntaxTree.ParseText(source) }, - references, + new SyntaxTree[] { sourceTree }, + metadataReferences, new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true)); - IIncrementalGenerator generator = new TGenerator(); + // Run the generator on the source compilation, get the diagnostics + _ = CSharpGeneratorDriver.Create(new TGenerator()).RunGeneratorsAndUpdateCompilation( + compilation, + out Compilation outputCompilation, + out ImmutableArray diagnostics); - CSharpGeneratorDriver driver = CSharpGeneratorDriver.Create(generator); + Dictionary diagnosticMap = diagnostics.DistinctBy(diagnostic => diagnostic.Id).ToDictionary(diagnostic => diagnostic.Id); - _ = driver.RunGeneratorsAndUpdateCompilation(compilation, out Compilation outputCompilation, out ImmutableArray diagnostics); - - HashSet resultingIds = diagnostics.Select(diagnostic => diagnostic.Id).ToHashSet(); - - Assert.IsTrue(resultingIds.SetEquals(diagnosticsIds)); + // Check that the diagnostics match + Assert.IsTrue(diagnosticMap.Keys.ToHashSet().SetEquals(diagnosticsIds), $"Diagnostics didn't match. {string.Join(", ", diagnosticMap.Values)}"); // If the compilation was supposed to succeed, ensure that no further errors were generated if (diagnosticsIds.Length == 0)