diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.Execute.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.Execute.Syntax.cs index 44a47de8..e55cccc9 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.Execute.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.Execute.Syntax.cs @@ -87,7 +87,7 @@ partial class D2DPixelShaderSourceGenerator // return MethodDeclaration(returnType, Identifier(bytecodeInfo.MethodName)) - .AddModifiers(bytecodeInfo.Modifiers.Select(Token).ToArray()) + .AddModifiers(bytecodeInfo.Modifiers.Select(static m => Token((SyntaxKind)m)).ToArray()) .AddAttributeLists( AttributeList(SingletonSeparatedList( Attribute(IdentifierName("global::System.CodeDom.Compiler.GeneratedCode")) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.cs index 0e653800..ca539802 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.cs @@ -41,7 +41,7 @@ public sealed partial class D2DPixelShaderSourceGenerator : IIncrementalGenerato token.ThrowIfCancellationRequested(); // Get the remaining info for the current shader - ImmutableArray modifiers = methodDeclaration.Modifiers.Select(token => token.Kind()).ToImmutableArray(); + ImmutableArray modifiers = methodDeclaration.Modifiers.Select(token => (ushort)token.Kind()).ToImmutableArray(); string methodName = methodSymbol.Name; string? invalidReturnType = Execute.GetInvalidReturnType(diagnostics, methodSymbol); D2D1ShaderProfile shaderProfile = Execute.GetShaderProfile(diagnostics, methodSymbol); @@ -63,7 +63,7 @@ public sealed partial class D2DPixelShaderSourceGenerator : IIncrementalGenerato // Output the diagnostics context.ReportDiagnostics( shaderInfoWithErrors - .Select(static (item, _) => item.Diagnostcs) + .Select(static (item, _) => item.Diagnostcs.AsImmutableArray()) .WithComparer(EqualityComparer.Default.ForImmutableArray())); // Compile the requested shader bytecodes diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs index 01ee8226..85e264f0 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs @@ -135,7 +135,7 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator // Output the diagnostics, if any context.ReportDiagnostics( shaderInfoWithErrors - .Select(static (item, _) => item.Diagnostcs) + .Select(static (item, _) => item.Diagnostcs.AsImmutableArray()) .WithComparer(EqualityComparer.Default.ForImmutableArray())); // Get the GetInputCount() info (hierarchy and input count) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Models/D2D1PixelShaderSourceInfo.cs b/src/ComputeSharp.D2D1.SourceGenerators/Models/D2D1PixelShaderSourceInfo.cs index 20a81557..f355b6e6 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Models/D2D1PixelShaderSourceInfo.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Models/D2D1PixelShaderSourceInfo.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using ComputeSharp.SourceGeneration.Extensions; using ComputeSharp.SourceGeneration.Helpers; using ComputeSharp.SourceGeneration.Models; @@ -16,40 +12,4 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models; internal sealed record D2D1PixelShaderSourceInfo( HierarchyInfo Hierarchy, HlslShaderMethodSourceInfo HlslShaderMethodSource, - ImmutableArray Diagnostcs) -{ - /// - public bool Equals(D2D1PixelShaderSourceInfo? obj) - { - return Comparer.Default.Equals(this, obj); - } - - /// - public override int GetHashCode() - { - return Comparer.Default.GetHashCode(this); - } - - /// - /// An implementation for . - /// - private sealed class Comparer : Comparer - { - /// - protected override void AddToHashCode(ref HashCode hashCode, D2D1PixelShaderSourceInfo obj) - { - hashCode.Add(obj.Hierarchy); - hashCode.Add(obj.HlslShaderMethodSource); - hashCode.AddRange(obj.Diagnostcs); - } - - /// - protected override bool AreEqual(D2D1PixelShaderSourceInfo x, D2D1PixelShaderSourceInfo y) - { - return - x.Hierarchy == y.Hierarchy && - x.HlslShaderMethodSource == y.HlslShaderMethodSource && - x.Diagnostcs.SequenceEqual(y.Diagnostcs); - } - } -} \ No newline at end of file + EquatableArray Diagnostcs); \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Models/D2D1ShaderInfo.cs b/src/ComputeSharp.D2D1.SourceGenerators/Models/D2D1ShaderInfo.cs index f79ebb90..5674a782 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Models/D2D1ShaderInfo.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Models/D2D1ShaderInfo.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using ComputeSharp.SourceGeneration.Extensions; using ComputeSharp.SourceGeneration.Helpers; using ComputeSharp.SourceGeneration.Models; @@ -28,52 +24,4 @@ internal sealed record D2D1ShaderInfo( OutputBufferInfo OutputBuffer, InputDescriptionsInfo InputDescriptions, D2D1PixelOptions PixelOptions, - ImmutableArray Diagnostcs) -{ - /// - public bool Equals(D2D1ShaderInfo? obj) - { - return Comparer.Default.Equals(this, obj); - } - - /// - public override int GetHashCode() - { - return Comparer.Default.GetHashCode(this); - } - - /// - /// An implementation for . - /// - private sealed class Comparer : Comparer - { - /// - protected override void AddToHashCode(ref HashCode hashCode, D2D1ShaderInfo obj) - { - hashCode.Add(obj.Hierarchy); - hashCode.Add(obj.DispatchData); - hashCode.Add(obj.InputTypes); - hashCode.Add(obj.ResourceTextureDescriptions); - hashCode.Add(obj.HlslShaderSource); - hashCode.Add(obj.OutputBuffer); - hashCode.Add(obj.InputDescriptions); - hashCode.Add(obj.PixelOptions); - hashCode.AddRange(obj.Diagnostcs); - } - - /// - protected override bool AreEqual(D2D1ShaderInfo x, D2D1ShaderInfo y) - { - return - x.Hierarchy == y.Hierarchy && - x.DispatchData == y.DispatchData && - x.InputTypes == y.InputTypes && - x.ResourceTextureDescriptions == y.ResourceTextureDescriptions && - x.HlslShaderSource == y.HlslShaderSource && - x.OutputBuffer == y.OutputBuffer && - x.InputDescriptions == y.InputDescriptions && - x.PixelOptions == y.PixelOptions && - x.Diagnostcs.SequenceEqual(y.Diagnostcs); - } - } -} \ No newline at end of file + EquatableArray Diagnostcs); \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Models/DispatchDataInfo.cs b/src/ComputeSharp.D2D1.SourceGenerators/Models/DispatchDataInfo.cs index c8aa95ed..f2bb9a0a 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Models/DispatchDataInfo.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Models/DispatchDataInfo.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using ComputeSharp.SourceGeneration.Extensions; using ComputeSharp.SourceGeneration.Helpers; namespace ComputeSharp.D2D1.SourceGenerators.Models; @@ -11,38 +7,4 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models; /// /// The description on shader instance fields. /// The size of the shader constant buffer. -internal sealed record DispatchDataInfo(ImmutableArray FieldInfos, int ConstantBufferSizeInBytes) -{ - /// - public bool Equals(DispatchDataInfo? obj) - { - return Comparer.Default.Equals(this, obj); - } - - /// - public override int GetHashCode() - { - return Comparer.Default.GetHashCode(this); - } - - /// - /// An implementation for . - /// - private sealed class Comparer : Comparer - { - /// - protected override void AddToHashCode(ref HashCode hashCode, DispatchDataInfo obj) - { - hashCode.AddRange(obj.FieldInfos); - hashCode.Add(obj.ConstantBufferSizeInBytes); - } - - /// - protected override bool AreEqual(DispatchDataInfo x, DispatchDataInfo y) - { - return - x.FieldInfos.SequenceEqual(y.FieldInfos) && - x.ConstantBufferSizeInBytes == y.ConstantBufferSizeInBytes; - } - } -} \ No newline at end of file +internal sealed record DispatchDataInfo(EquatableArray FieldInfos, int ConstantBufferSizeInBytes); \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Models/EmbeddedBytecodeInfo.cs b/src/ComputeSharp.D2D1.SourceGenerators/Models/EmbeddedBytecodeInfo.cs index 1d65fbc8..72a49d1e 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Models/EmbeddedBytecodeInfo.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Models/EmbeddedBytecodeInfo.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using ComputeSharp.SourceGeneration.Extensions; using ComputeSharp.SourceGeneration.Helpers; namespace ComputeSharp.D2D1.SourceGenerators.Models; @@ -13,42 +9,4 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models; /// The shader profile to use to compile the shader, if requested. /// The compile options to use to compile the shader. /// The compiled shader bytecode, if available. -internal sealed record EmbeddedBytecodeInfo(string HlslSource, D2D1ShaderProfile? ShaderProfile, D2D1CompileOptions? CompileOptions, ImmutableArray Bytecode) -{ - /// - public bool Equals(EmbeddedBytecodeInfo? obj) - { - return Comparer.Default.Equals(this, obj); - } - - /// - public override int GetHashCode() - { - return Comparer.Default.GetHashCode(this); - } - - /// - /// An implementation for . - /// - private sealed class Comparer : Comparer - { - /// - protected override void AddToHashCode(ref HashCode hashCode, EmbeddedBytecodeInfo obj) - { - hashCode.Add(obj.HlslSource); - hashCode.Add(obj.ShaderProfile); - hashCode.Add(obj.CompileOptions); - hashCode.AddBytes(obj.Bytecode.AsSpan()); - } - - /// - protected override bool AreEqual(EmbeddedBytecodeInfo x, EmbeddedBytecodeInfo y) - { - return - x.HlslSource == y.HlslSource && - x.ShaderProfile == y.ShaderProfile && - x.CompileOptions == y.CompileOptions && - x.Bytecode.SequenceEqual(y.Bytecode); - } - } -} \ No newline at end of file +internal sealed record EmbeddedBytecodeInfo(string HlslSource, D2D1ShaderProfile? ShaderProfile, D2D1CompileOptions? CompileOptions, EquatableArray Bytecode); \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Models/EmbeddedBytecodeMethodInfo.cs b/src/ComputeSharp.D2D1.SourceGenerators/Models/EmbeddedBytecodeMethodInfo.cs index e2f43b8b..56ef702d 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Models/EmbeddedBytecodeMethodInfo.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Models/EmbeddedBytecodeMethodInfo.cs @@ -1,64 +1,18 @@ -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Runtime.InteropServices; -using ComputeSharp.SourceGeneration.Extensions; using ComputeSharp.SourceGeneration.Helpers; -using Microsoft.CodeAnalysis.CSharp; namespace ComputeSharp.D2D1.SourceGenerators.Models; /// /// A model representing info on a shader method that has requested to be precompiled at build time. /// -/// The modifiers for the annotated method. +/// The modifiers for the annotated method (these are values, which can't be equated directly). /// The name of the annotated method. /// The fully qualified name of the return type, if invalid. /// The HLSL source. /// The compiled shader bytecode, if available. internal sealed record EmbeddedBytecodeMethodInfo( - ImmutableArray Modifiers, + EquatableArray Modifiers, string MethodName, string? InvalidReturnType, string HlslSource, - ImmutableArray Bytecode) -{ - /// - public bool Equals(EmbeddedBytecodeMethodInfo? obj) - { - return Comparer.Default.Equals(this, obj); - } - - /// - public override int GetHashCode() - { - return Comparer.Default.GetHashCode(this); - } - - /// - /// An implementation for . - /// - private sealed class Comparer : Comparer - { - /// - protected override void AddToHashCode(ref HashCode hashCode, EmbeddedBytecodeMethodInfo obj) - { - hashCode.AddRange(obj.Modifiers); - hashCode.Add(obj.MethodName); - hashCode.Add(obj.InvalidReturnType); - hashCode.Add(obj.HlslSource); - hashCode.AddBytes(obj.Bytecode.AsSpan()); - } - - /// - protected override bool AreEqual(EmbeddedBytecodeMethodInfo x, EmbeddedBytecodeMethodInfo y) - { - return - MemoryMarshal.Cast(x.Modifiers.AsSpan()).SequenceEqual(MemoryMarshal.Cast(y.Modifiers.AsSpan())) && - x.MethodName == y.MethodName && - x.InvalidReturnType == y.InvalidReturnType && - x.HlslSource == y.HlslSource && - x.Bytecode.SequenceEqual(y.Bytecode); - } - } -} \ No newline at end of file + EquatableArray Bytecode); \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Models/FieldInfo.cs b/src/ComputeSharp.D2D1.SourceGenerators/Models/FieldInfo.cs index 89ff1281..c49ba8b6 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Models/FieldInfo.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Models/FieldInfo.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using ComputeSharp.SourceGeneration.Extensions; using ComputeSharp.SourceGeneration.Helpers; namespace ComputeSharp.D2D1.SourceGenerators.Models; @@ -17,43 +13,7 @@ internal abstract record FieldInfo /// The path of the field with respect to the shader instance. /// The full metadata name for the primitive type. /// The byte offset of the value within the root signature. - public sealed record Primitive(ImmutableArray FieldPath, string TypeName, int Offset) : FieldInfo - { - /// - public bool Equals(Primitive? obj) - { - return Comparer.Default.Equals(this, obj); - } - - /// - public override int GetHashCode() - { - return Comparer.Default.GetHashCode(this); - } - - /// - /// An implementation for . - /// - private sealed class Comparer : Comparer - { - /// - protected override void AddToHashCode(ref HashCode hashCode, Primitive obj) - { - hashCode.AddRange(obj.FieldPath); - hashCode.Add(obj.TypeName); - hashCode.Add(obj.Offset); - } - - /// - protected override bool AreEqual(Primitive x, Primitive y) - { - return - x.FieldPath.SequenceEqual(y.FieldPath) && - x.TypeName == y.TypeName && - x.Offset == y.Offset; - } - } - } + public sealed record Primitive(EquatableArray FieldPath, string TypeName, int Offset) : FieldInfo; /// /// A captured non linear matrix value. @@ -65,52 +25,10 @@ internal abstract record FieldInfo /// The number of columns in the matrix. /// The sequence of byte offsets for each row within the root signature. public sealed record NonLinearMatrix( - ImmutableArray FieldPath, + EquatableArray FieldPath, string TypeName, string ElementName, int Rows, int Columns, - ImmutableArray Offsets) : FieldInfo - { - /// - public bool Equals(NonLinearMatrix? obj) - { - return Comparer.Default.Equals(this, obj); - } - - /// - public override int GetHashCode() - { - return Comparer.Default.GetHashCode(this); - } - - /// - /// An implementation for . - /// - private sealed class Comparer : Comparer - { - /// - protected override void AddToHashCode(ref HashCode hashCode, NonLinearMatrix obj) - { - hashCode.AddRange(obj.FieldPath); - hashCode.Add(obj.TypeName); - hashCode.Add(obj.ElementName); - hashCode.Add(obj.Rows); - hashCode.Add(obj.Columns); - hashCode.AddRange(obj.Offsets); - } - - /// - protected override bool AreEqual(NonLinearMatrix x, NonLinearMatrix y) - { - return - x.FieldPath.SequenceEqual(y.FieldPath) && - x.TypeName == y.TypeName && - x.ElementName == y.ElementName && - x.Rows == y.Rows && - x.Columns == y.Columns && - x.Offsets.SequenceEqual(y.Offsets); - } - } - } + EquatableArray Offsets) : FieldInfo; } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Models/HlslShaderMethodSourceInfo.cs b/src/ComputeSharp.D2D1.SourceGenerators/Models/HlslShaderMethodSourceInfo.cs index 277c0cea..75ff95e0 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Models/HlslShaderMethodSourceInfo.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Models/HlslShaderMethodSourceInfo.cs @@ -1,16 +1,11 @@ -using System; -using System.Collections.Immutable; -using System.Runtime.InteropServices; -using ComputeSharp.SourceGeneration.Extensions; using ComputeSharp.SourceGeneration.Helpers; -using Microsoft.CodeAnalysis.CSharp; namespace ComputeSharp.D2D1.SourceGenerators.Models; /// /// A model for extracted info on a processed HLSL shader method. /// -/// The modifiers for the annotated method. +/// The modifiers for the annotated method (these are values, which can't be equated directly). /// The name of the annotated method. /// The fully qualified name of the return type, if invalid. /// The HLSL source. @@ -18,54 +13,10 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models; /// The compile options to use to compile the shader. /// Whether any errors have been detected, and therefore the shader compilation should be skipped. internal sealed record HlslShaderMethodSourceInfo( - ImmutableArray Modifiers, + EquatableArray Modifiers, string MethodName, string? InvalidReturnType, string HlslSource, D2D1ShaderProfile ShaderProfile, D2D1CompileOptions CompileOptions, - bool HasErrors) -{ - /// - public bool Equals(HlslShaderMethodSourceInfo? obj) - { - return Comparer.Default.Equals(this, obj); - } - - /// - public override int GetHashCode() - { - return Comparer.Default.GetHashCode(this); - } - - /// - /// An implementation for . - /// - private sealed class Comparer : Comparer - { - /// - protected override void AddToHashCode(ref HashCode hashCode, HlslShaderMethodSourceInfo obj) - { - hashCode.AddRange(obj.Modifiers); - hashCode.Add(obj.MethodName); - hashCode.Add(obj.InvalidReturnType); - hashCode.Add(obj.HlslSource); - hashCode.Add(obj.ShaderProfile); - hashCode.Add(obj.CompileOptions); - hashCode.Add(obj.HasErrors); - } - - /// - protected override bool AreEqual(HlslShaderMethodSourceInfo x, HlslShaderMethodSourceInfo y) - { - return - MemoryMarshal.Cast(x.Modifiers.AsSpan()).SequenceEqual(MemoryMarshal.Cast(y.Modifiers.AsSpan())) && - x.MethodName == y.MethodName && - x.InvalidReturnType == y.InvalidReturnType && - x.HlslSource == y.HlslSource && - x.ShaderProfile == y.ShaderProfile && - x.CompileOptions == y.CompileOptions && - x.HasErrors == y.HasErrors; - } - } -} \ No newline at end of file + bool HasErrors); \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Models/InputDescriptionsInfo.cs b/src/ComputeSharp.D2D1.SourceGenerators/Models/InputDescriptionsInfo.cs index e0500622..2ddb65f3 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Models/InputDescriptionsInfo.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Models/InputDescriptionsInfo.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Immutable; -using ComputeSharp.SourceGeneration.Extensions; using ComputeSharp.SourceGeneration.Helpers; namespace ComputeSharp.D2D1.SourceGenerators.Models; @@ -9,35 +6,4 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models; /// A model representing gathered input descriptions for a shader. /// /// The input descriptions for a given shader. -internal sealed record InputDescriptionsInfo(ImmutableArray InputDescriptions) -{ - /// - public bool Equals(InputDescriptionsInfo? obj) - { - return Comparer.Default.Equals(this, obj); - } - - /// - public override int GetHashCode() - { - return Comparer.Default.GetHashCode(this); - } - - /// - /// An implementation for . - /// - private sealed class Comparer : Comparer - { - /// - protected override void AddToHashCode(ref HashCode hashCode, InputDescriptionsInfo obj) - { - hashCode.AddRange(obj.InputDescriptions); - } - - /// - protected override bool AreEqual(InputDescriptionsInfo x, InputDescriptionsInfo y) - { - return x.InputDescriptions.SequenceEqual(y.InputDescriptions); - } - } -} \ No newline at end of file +internal sealed record InputDescriptionsInfo(EquatableArray InputDescriptions); \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Models/InputTypesInfo.cs b/src/ComputeSharp.D2D1.SourceGenerators/Models/InputTypesInfo.cs index f393e71e..bdbb2116 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Models/InputTypesInfo.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Models/InputTypesInfo.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using ComputeSharp.SourceGeneration.Extensions; using ComputeSharp.SourceGeneration.Helpers; namespace ComputeSharp.D2D1.SourceGenerators.Models; @@ -10,35 +6,4 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models; /// A model representing gathered info on a shader input types. /// /// The input types for a given shader. -internal sealed record InputTypesInfo(ImmutableArray InputTypes) -{ - /// - public bool Equals(InputTypesInfo? obj) - { - return Comparer.Default.Equals(this, obj); - } - - /// - public override int GetHashCode() - { - return Comparer.Default.GetHashCode(this); - } - - /// - /// An implementation for . - /// - private sealed class Comparer : Comparer - { - /// - protected override void AddToHashCode(ref HashCode hashCode, InputTypesInfo obj) - { - hashCode.AddRange(obj.InputTypes); - } - - /// - protected override bool AreEqual(InputTypesInfo x, InputTypesInfo y) - { - return x.InputTypes.SequenceEqual(y.InputTypes); - } - } -} \ No newline at end of file +internal sealed record InputTypesInfo(EquatableArray InputTypes); \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Models/ResourceTextureDescriptionsInfo.cs b/src/ComputeSharp.D2D1.SourceGenerators/Models/ResourceTextureDescriptionsInfo.cs index 40349dd3..4661508c 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Models/ResourceTextureDescriptionsInfo.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Models/ResourceTextureDescriptionsInfo.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Immutable; -using ComputeSharp.SourceGeneration.Extensions; using ComputeSharp.SourceGeneration.Helpers; namespace ComputeSharp.D2D1.SourceGenerators.Models; @@ -9,35 +6,4 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models; /// A model representing gathered resource texture descriptions for a shader. /// /// The resource textures for the current shader. -internal sealed record ResourceTextureDescriptionsInfo(ImmutableArray ResourceTextureDescriptions) -{ - /// - public bool Equals(ResourceTextureDescriptionsInfo? obj) - { - return Comparer.Default.Equals(this, obj); - } - - /// - public override int GetHashCode() - { - return Comparer.Default.GetHashCode(this); - } - - /// - /// An implementation for . - /// - private sealed class Comparer : Comparer - { - /// - protected override void AddToHashCode(ref HashCode hashCode, ResourceTextureDescriptionsInfo obj) - { - hashCode.AddRange(obj.ResourceTextureDescriptions); - } - - /// - protected override bool AreEqual(ResourceTextureDescriptionsInfo x, ResourceTextureDescriptionsInfo y) - { - return x.ResourceTextureDescriptions.SequenceEqual(y.ResourceTextureDescriptions); - } - } -} \ No newline at end of file +internal sealed record ResourceTextureDescriptionsInfo(EquatableArray ResourceTextureDescriptions); \ No newline at end of file diff --git a/src/ComputeSharp.SourceGeneration/Helpers/EquatableArray{T}.cs b/src/ComputeSharp.SourceGeneration/Helpers/EquatableArray{T}.cs index bd3f0417..ffb6c4b4 100644 --- a/src/ComputeSharp.SourceGeneration/Helpers/EquatableArray{T}.cs +++ b/src/ComputeSharp.SourceGeneration/Helpers/EquatableArray{T}.cs @@ -70,6 +70,15 @@ internal readonly struct EquatableArray : IEquatable>, IEnu get => AsImmutableArray().IsEmpty; } + /// + /// Gets a value indicating whether the current array is default or empty. + /// + public bool IsDefaultOrEmpty + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => AsImmutableArray().IsDefaultOrEmpty; + } + /// /// Gets the length of the current array. ///