From 3bf77618e46bad9eb39e45b83c0f6d347d057f57 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 27 Apr 2022 22:38:50 +0200 Subject: [PATCH 1/5] Exclude explicit interface implementations in shaders --- ...2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs | 12 ++++++++++++ .../IShaderGenerator.CreateBuildHlslSourceMethod.cs | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs index f68e444d..36842aac 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs @@ -240,6 +240,12 @@ partial class ID2D1ShaderGenerator methodDeclarationSymbol.TypeParameters.Length == 0 && methodDeclarationSymbol.Parameters.Length == 0; + // Except for the entry point, ignore explicit interface implementations + if (!isShaderEntryPoint && !methodDeclarationSymbol.ExplicitInterfaceImplementations.IsDefaultOrEmpty) + { + continue; + } + // Create the source rewriter for the current method ShaderSourceRewriter shaderSourceRewriter = new( structDeclarationSymbol, @@ -374,6 +380,12 @@ partial class ID2D1ShaderGenerator { foreach (var propertySymbol in structDeclarationSymbol.GetMembers().OfType()) { + // Ignore explicit interface implementations + if (!propertySymbol.ExplicitInterfaceImplementations.IsDefaultOrEmpty) + { + return; + } + diagnostics.Add(DiagnosticDescriptors.PropertyDeclaration, propertySymbol); } } diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.cs index 3e35ad4b..bfb74874 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.cs @@ -354,6 +354,12 @@ partial class IShaderGenerator methodDeclarationSymbol.TypeParameters.Length == 0 && methodDeclarationSymbol.Parameters.Length == 0); + // Except for the entry point, ignore explicit interface implementations + if (!isShaderEntryPoint && !methodDeclarationSymbol.ExplicitInterfaceImplementations.IsDefaultOrEmpty) + { + continue; + } + // Create the source rewriter for the current method ShaderSourceRewriter shaderSourceRewriter = new( structDeclarationSymbol, @@ -495,6 +501,12 @@ partial class IShaderGenerator { foreach (var propertySymbol in structDeclarationSymbol.GetMembers().OfType()) { + // Ignore explicit interface implementations + if (!propertySymbol.ExplicitInterfaceImplementations.IsDefaultOrEmpty) + { + return; + } + diagnostics.Add(DiagnosticDescriptors.PropertyDeclaration, propertySymbol); } } From 459517a181170bf2730f69c97aab67fdc822575b Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 28 Apr 2022 01:04:09 +0200 Subject: [PATCH 2/5] Enable shaders to inherit shader interfaces --- .../ID2D1ShaderGenerator.Helpers.cs | 2 +- .../IShaderGenerator.Helpers.cs | 2 +- .../ComputeSharp.Tests/ShaderCompilerTests.cs | 64 +++++++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.Helpers.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.Helpers.cs index 9232e403..79a971ae 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.Helpers.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.Helpers.cs @@ -18,7 +18,7 @@ partial class ID2D1ShaderGenerator /// Whether or not implements . private static bool IsD2D1PixelShaderType(INamedTypeSymbol typeSymbol, INamedTypeSymbol d2D1PixelShaderSymbol) { - foreach (INamedTypeSymbol interfaceSymbol in typeSymbol.Interfaces) + foreach (INamedTypeSymbol interfaceSymbol in typeSymbol.AllInterfaces) { if (interfaceSymbol.Name == nameof(ID2D1PixelShader) && SymbolEqualityComparer.Default.Equals(interfaceSymbol, d2D1PixelShaderSymbol)) diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.Helpers.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.Helpers.cs index 88d0550c..77462b98 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.Helpers.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.Helpers.cs @@ -23,7 +23,7 @@ partial class IShaderGenerator INamedTypeSymbol iComputeShaderSymbol, INamedTypeSymbol iPixelShaderSymbol) { - foreach (INamedTypeSymbol interfaceSymbol in typeSymbol.Interfaces) + foreach (INamedTypeSymbol interfaceSymbol in typeSymbol.AllInterfaces) { if (interfaceSymbol.Name == nameof(IComputeShader) && SymbolEqualityComparer.Default.Equals(interfaceSymbol, iComputeShaderSymbol)) diff --git a/tests/ComputeSharp.Tests/ShaderCompilerTests.cs b/tests/ComputeSharp.Tests/ShaderCompilerTests.cs index 0c497090..3fd445c3 100644 --- a/tests/ComputeSharp.Tests/ShaderCompilerTests.cs +++ b/tests/ComputeSharp.Tests/ShaderCompilerTests.cs @@ -272,6 +272,70 @@ namespace ComputeSharp.Tests this.buffer[ThreadIds.X] *= this.number; } } + + [TestMethod] + public void ComputeShaderWithInheritedShaderInterface() + { + _ = ReflectionServices.GetShaderInfo(); + } + + public interface IMyBaseShader : IComputeShader + { + public int A { get; } + + public void B(); + } + + [AutoConstructor] + internal readonly partial struct ComputeShaderWithInheritedShaderInterfaceShader : IMyBaseShader + { + int IMyBaseShader.A { get; } + + void IMyBaseShader.B() + { + } + + public readonly ReadWriteBuffer buffer; + public readonly float number; + + /// + public void Execute() + { + this.buffer[ThreadIds.X] *= this.number; + } + } + + [TestMethod] + public void PixelShaderWithInheritedShaderInterface() + { + _ = ReflectionServices.GetShaderInfo(); + } + + public interface IMyBaseShader : IPixelShader + where T : unmanaged + { + public int A { get; } + + public void B(); + } + + [AutoConstructor] + internal readonly partial struct PixelShaderWithInheritedShaderInterfaceShader : IMyBaseShader + { + int IMyBaseShader.A { get; } + + void IMyBaseShader.B() + { + } + + public readonly float number; + + /// + public float4 Execute() + { + return default; + } + } } } From 7d14403632e8a5e38912e295e1ec23b197e87a98 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 28 Apr 2022 01:43:37 +0200 Subject: [PATCH 3/5] Update [AutoConstructor] attribute to ignore generated fields --- .../AutoConstructorGenerator.cs | 2 +- .../AutoConstructorAttributeTests.cs | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/ComputeSharp.Core.SourceGenerators/AutoConstructorGenerator.cs b/src/ComputeSharp.Core.SourceGenerators/AutoConstructorGenerator.cs index 8a5771e5..c75b86ee 100644 --- a/src/ComputeSharp.Core.SourceGenerators/AutoConstructorGenerator.cs +++ b/src/ComputeSharp.Core.SourceGenerators/AutoConstructorGenerator.cs @@ -59,7 +59,7 @@ public sealed partial class AutoConstructorGenerator : IIncrementalGenerator { return ( from fieldSymbol in structDeclarationSymbol.GetMembers().OfType() - where fieldSymbol is { IsConst: false, IsStatic: false, IsFixedSizeBuffer: false } + where fieldSymbol is { IsConst: false, IsStatic: false, IsFixedSizeBuffer: false, IsImplicitlyDeclared: false } let typeName = fieldSymbol.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) select new ParameterInfo(typeName, fieldSymbol.Name)).ToImmutableArray(); } diff --git a/tests/ComputeSharp.Tests/AutoConstructorAttributeTests.cs b/tests/ComputeSharp.Tests/AutoConstructorAttributeTests.cs index 469c9e25..d63de33c 100644 --- a/tests/ComputeSharp.Tests/AutoConstructorAttributeTests.cs +++ b/tests/ComputeSharp.Tests/AutoConstructorAttributeTests.cs @@ -54,4 +54,35 @@ public unsafe partial class AutoConstructorAttributeTests Assert.AreEqual(instance.a, a); Assert.AreEqual(instance.b, b); } + + public partial interface IAnotherInterface + { + public int B { get; } + + public void Foo(); + } + + public partial struct AnotherStruct : IAnotherInterface + { + public int a; + public float b; + + int IAnotherInterface.B { get; } + + void IAnotherInterface.Foo() + { + } + } + + [TestMethod] + public void GenerateConstructorWithExplicitInterfaceMembers() + { + int a = 42; + float b = 3.14f; + + AnotherStruct instance = new(a, b); + + Assert.AreEqual(instance.a, a); + Assert.AreEqual(instance.b, b); + } } From 1ef6040e58c4ce253ffcb5c61d4b4601eb411e00 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 29 Apr 2022 02:42:47 +0200 Subject: [PATCH 4/5] Tweak properties detection to block all field backed ones --- .../Diagnostics/DiagnosticDescriptors.cs | 17 ++++++---- ...erGenerator.CreateBuildHlslSourceMethod.cs | 20 ++++++----- .../Diagnostics/DiagnosticDescriptors.cs | 11 ++++--- ...erGenerator.CreateBuildHlslSourceMethod.cs | 22 ++++++++----- .../DiagnosticsTests.cs | 33 +++++++++++++++++++ .../AutoConstructorAttributeTests.cs | 3 +- .../ComputeSharp.Tests/ShaderCompilerTests.cs | 4 +-- 7 files changed, 79 insertions(+), 31 deletions(-) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs index 9d65598d..1ad3ab02 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs @@ -413,31 +413,34 @@ internal static 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)". + /// /// - public static readonly DiagnosticDescriptor PropertyDeclaration = new DiagnosticDescriptor( + public static readonly DiagnosticDescriptor InvalidPropertyDeclaration = new DiagnosticDescriptor( id: "CMPSD2D0031", - title: "Property declaration", - messageFormat: "Property declarations cannot be used in a compute shader", + 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)", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, - description: "Property declarations cannot be used in a compute shader.", + description: "Property declarations (except for stateless properties explicitly implementing an interface property) cannot be used in a D2D1 shader.", helpLinkUri: "https://github.com/Sergio0694/ComputeSharp"); /// /// Gets a for a shader with a root signature that is too large. /// - /// Format: "The compute shader of type {0} has exceeded the maximum allowed size for captured values and resources". + /// Format: "The D2D1 shader of type {0} has exceeded the maximum allowed size for captured values and resources". /// /// public static readonly DiagnosticDescriptor ShaderDispatchDataSizeExceeded = new DiagnosticDescriptor( id: "CMPSD2D0032", title: "Shader dispatch data size exceeded", - messageFormat: "The compute shader of type {0} has exceeded the maximum allowed size for captured values and resources", + messageFormat: "The D2D1 shader of type {0} has exceeded the maximum allowed size for captured values and resources", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, - description: "The compute shader of type {0} has exceeded the maximum allowed size for captured values and resources.", + description: "The D2D1 shader of type {0} has exceeded the maximum allowed size for captured values and resources.", helpLinkUri: "https://github.com/Sergio0694/ComputeSharp"); /// diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs index 36842aac..07a8829f 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs @@ -45,7 +45,7 @@ partial class ID2D1ShaderGenerator ImmutableArray.Builder builder = ImmutableArray.CreateBuilder(); // Properties are not supported - DetectAndReportPropertyDeclarations(builder, structDeclarationSymbol); + DetectAndReportInvalidPropertyDeclarations(builder, structDeclarationSymbol); // We need to sets to track all discovered custom types and static methods HashSet discoveredTypes = new(SymbolEqualityComparer.Default); @@ -372,21 +372,25 @@ partial class ID2D1ShaderGenerator } /// - /// Finds and reports all declared properties in a shader. + /// Finds and reports all invalid declared properties in a shader. /// /// The collection of produced instances. /// The input instance to process. - private static void DetectAndReportPropertyDeclarations(ImmutableArray.Builder diagnostics, INamedTypeSymbol structDeclarationSymbol) + private static void DetectAndReportInvalidPropertyDeclarations(ImmutableArray.Builder diagnostics, INamedTypeSymbol structDeclarationSymbol) { - foreach (var propertySymbol in structDeclarationSymbol.GetMembers().OfType()) + foreach (var memberSymbol in structDeclarationSymbol.GetMembers()) { - // Ignore explicit interface implementations - if (!propertySymbol.ExplicitInterfaceImplementations.IsDefaultOrEmpty) + // Detect properties that are not explicit interface implementations + if (memberSymbol is IPropertySymbol { ExplicitInterfaceImplementations.IsEmpty: true }) { - return; + diagnostics.Add(InvalidPropertyDeclaration, memberSymbol, structDeclarationSymbol, memberSymbol); } - diagnostics.Add(DiagnosticDescriptors.PropertyDeclaration, propertySymbol); + // Detect properties causing a field to be generated + if (memberSymbol is IFieldSymbol { AssociatedSymbol: IPropertySymbol associatedProperty }) + { + diagnostics.Add(InvalidPropertyDeclaration, associatedProperty, structDeclarationSymbol, associatedProperty); + } } } diff --git a/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs b/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs index d57ee454..1e9e4d7f 100644 --- a/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs +++ b/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs @@ -542,15 +542,18 @@ internal static 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)". + /// /// - public static readonly DiagnosticDescriptor PropertyDeclaration = new DiagnosticDescriptor( + public static readonly DiagnosticDescriptor InvalidPropertyDeclaration = new DiagnosticDescriptor( id: "CMPS0040", - title: "Property declaration", - messageFormat: "Property declarations cannot be used in a compute shader", + 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)", category: "ComputeSharp.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, - description: "Property declarations cannot be used in a compute shader.", + description: "Property declarations (except for stateless properties explicitly implementing an interface property) cannot be used in a compute shader.", helpLinkUri: "https://github.com/Sergio0694/ComputeSharp"); /// diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.cs index bfb74874..83ff9589 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.cs @@ -43,8 +43,8 @@ partial class IShaderGenerator { ImmutableArray.Builder builder = ImmutableArray.CreateBuilder(); - // Properties are not supported - DetectAndReportPropertyDeclarations(builder, structDeclarationSymbol); + // Detect invalid properties + DetectAndReportInvalidPropertyDeclarations(builder, structDeclarationSymbol); // We need to sets to track all discovered custom types and static methods HashSet discoveredTypes = new(SymbolEqualityComparer.Default); @@ -493,21 +493,25 @@ partial class IShaderGenerator } /// - /// Finds and reports all declared properties in a shader. + /// Finds and reports all invalid declared properties in a shader. /// /// The collection of produced instances. /// The input instance to process. - private static void DetectAndReportPropertyDeclarations(ImmutableArray.Builder diagnostics, INamedTypeSymbol structDeclarationSymbol) + private static void DetectAndReportInvalidPropertyDeclarations(ImmutableArray.Builder diagnostics, INamedTypeSymbol structDeclarationSymbol) { - foreach (var propertySymbol in structDeclarationSymbol.GetMembers().OfType()) + foreach (var memberSymbol in structDeclarationSymbol.GetMembers()) { - // Ignore explicit interface implementations - if (!propertySymbol.ExplicitInterfaceImplementations.IsDefaultOrEmpty) + // Detect properties that are not explicit interface implementations + if (memberSymbol is IPropertySymbol { ExplicitInterfaceImplementations.IsEmpty: true }) { - return; + diagnostics.Add(InvalidPropertyDeclaration, memberSymbol, structDeclarationSymbol, memberSymbol); } - diagnostics.Add(DiagnosticDescriptors.PropertyDeclaration, propertySymbol); + // Detect properties causing a field to be generated + if (memberSymbol is IFieldSymbol { AssociatedSymbol: IPropertySymbol associatedProperty }) + { + diagnostics.Add(InvalidPropertyDeclaration, associatedProperty, structDeclarationSymbol, associatedProperty); + } } } diff --git a/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs b/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs index 53623b77..42fc327f 100644 --- a/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs +++ b/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs @@ -1253,6 +1253,39 @@ public class DiagnosticsTests VerifyGeneratedDiagnostics(source, "CMPS0040", "CMPS0047"); } + [TestMethod] + public void PropertyDeclaration_AutoProp_WithExplicitInterfaceImplementation() + { + string source = @" + using ComputeSharp; + + namespace ComputeSharp + { + public class ReadWriteBuffer { } + } + + namespace MyFancyApp.Sample + { + public interface IFoo + { + float Pi { get; } + } + + public struct MyShader : IComputeShader, IFoo + { + public ReadWriteBuffer buffer; + + float IFoo.Pi { get; } = 3.14f; + + public void Execute() + { + } + } + }"; + + VerifyGeneratedDiagnostics(source, "CMPS0040", "CMPS0047"); + } + [TestMethod] public void PropertyDeclaration_GetterBlock() { diff --git a/tests/ComputeSharp.Tests/AutoConstructorAttributeTests.cs b/tests/ComputeSharp.Tests/AutoConstructorAttributeTests.cs index d63de33c..dd147250 100644 --- a/tests/ComputeSharp.Tests/AutoConstructorAttributeTests.cs +++ b/tests/ComputeSharp.Tests/AutoConstructorAttributeTests.cs @@ -62,12 +62,13 @@ public unsafe partial class AutoConstructorAttributeTests public void Foo(); } + [AutoConstructor] public partial struct AnotherStruct : IAnotherInterface { public int a; public float b; - int IAnotherInterface.B { get; } + int IAnotherInterface.B => 100; void IAnotherInterface.Foo() { diff --git a/tests/ComputeSharp.Tests/ShaderCompilerTests.cs b/tests/ComputeSharp.Tests/ShaderCompilerTests.cs index 3fd445c3..7b5d0d08 100644 --- a/tests/ComputeSharp.Tests/ShaderCompilerTests.cs +++ b/tests/ComputeSharp.Tests/ShaderCompilerTests.cs @@ -289,7 +289,7 @@ namespace ComputeSharp.Tests [AutoConstructor] internal readonly partial struct ComputeShaderWithInheritedShaderInterfaceShader : IMyBaseShader { - int IMyBaseShader.A { get; } + int IMyBaseShader.A => 42; void IMyBaseShader.B() { @@ -322,7 +322,7 @@ namespace ComputeSharp.Tests [AutoConstructor] internal readonly partial struct PixelShaderWithInheritedShaderInterfaceShader : IMyBaseShader { - int IMyBaseShader.A { get; } + int IMyBaseShader.A => 42; void IMyBaseShader.B() { From 4bbe394f5525645d6f9c0fd95cbe158ee825e4e3 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 29 Apr 2022 02:46:16 +0200 Subject: [PATCH 5/5] Skip implicitly declared fields from all generated methods --- .../ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.cs | 4 +--- .../IShaderGenerator.CreateGetDispatchIdMethod.cs | 2 +- .../IShaderGenerator.CreateLoadDispatchDataMethod.cs | 4 +--- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.cs index 14f23044..a6e21e6f 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.cs @@ -43,9 +43,7 @@ partial class ID2D1ShaderGenerator foreach ( IFieldSymbol fieldSymbol in from fieldSymbol in currentTypeSymbol.GetMembers().OfType() - where fieldSymbol.Type is INamedTypeSymbol { IsStatic: false } && - !fieldSymbol.IsConst && !fieldSymbol.IsStatic && - !fieldSymbol.IsFixedSizeBuffer + where fieldSymbol is { Type: INamedTypeSymbol { IsStatic: false }, IsConst: false, IsStatic: false, IsFixedSizeBuffer: false, IsImplicitlyDeclared: false } select fieldSymbol) { string fieldName = fieldSymbol.Name; diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetDispatchIdMethod.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetDispatchIdMethod.cs index ebeb772e..589a926d 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetDispatchIdMethod.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetDispatchIdMethod.cs @@ -23,7 +23,7 @@ partial class IShaderGenerator structDeclarationSymbol .GetMembers() .OfType() - .Where(static member => member.Type is INamedTypeSymbol { TypeKind: TypeKind.Delegate, IsStatic: false }) + .Where(static member => member is { Type: INamedTypeSymbol { TypeKind: TypeKind.Delegate, IsStatic: false }, IsImplicitlyDeclared: false }) .Select(static member => member.Name) .ToImmutableArray(); } diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.cs index f7a20523..40af5a53 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.cs @@ -48,9 +48,7 @@ partial class IShaderGenerator foreach ( IFieldSymbol fieldSymbol in from fieldSymbol in currentTypeSymbol.GetMembers().OfType() - where fieldSymbol.Type is INamedTypeSymbol { IsStatic: false } && - !fieldSymbol.IsConst && !fieldSymbol.IsStatic && - !fieldSymbol.IsFixedSizeBuffer + where fieldSymbol is { Type: INamedTypeSymbol { IsStatic: false }, IsConst: false, IsStatic: false, IsFixedSizeBuffer: false, IsImplicitlyDeclared: false } select fieldSymbol) { string fieldName = fieldSymbol.Name;