using System; using System.Collections.Generic; using System.Collections.Immutable; using ComputeSharp.SourceGeneration.Extensions; namespace ComputeSharp.SourceGenerators.Models; /// /// A model representing gathered info on a shader dispatch data. /// /// The hierarchy data for the shader. /// The shader interface type. /// The description on shader instance fields. /// The total number of captured resources. /// The size of the shader root signature, in 32 bit constants. internal sealed record DispatchDataInfo( HierarchyInfo Hierarchy, Type Type, ImmutableArray FieldInfos, int ResourceCount, int Root32BitConstantCount) { /// /// An implementation for . /// public sealed class Comparer : IEqualityComparer { /// /// The singleton instance. /// public static Comparer Default { get; } = new(); /// public bool Equals(DispatchDataInfo? x, DispatchDataInfo? y) { if (x is null && y is null) { return true; } if (x is null || y is null) { return false; } if (ReferenceEquals(x, y)) { return true; } return HierarchyInfo.Comparer.Default.Equals(x.Hierarchy, y.Hierarchy) && x.Type == y.Type && x.FieldInfos.SequenceEqual(y.FieldInfos, FieldInfo.Comparer.Default) && x.ResourceCount == y.ResourceCount && x.Root32BitConstantCount == y.Root32BitConstantCount; } /// public int GetHashCode(DispatchDataInfo obj) { HashCode hashCode = default; hashCode.Add(HierarchyInfo.Comparer.Default.GetHashCode(obj.Hierarchy)); hashCode.Add(obj.Type); hashCode.AddRange(obj.FieldInfos, FieldInfo.Comparer.Default); hashCode.Add(obj.ResourceCount); hashCode.Add(obj.Root32BitConstantCount); return hashCode.ToHashCode(); } } }