using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using ComputeSharp.SourceGeneration.Extensions;
namespace ComputeSharp.SourceGenerators.Models;
///
/// A model containing info on shader dispatch metadata.
///
/// The size of the shader root signature, in 32 bit constants.
/// Whether or not the static sampler is used.
/// The sequence of resource descriptors for the shader.
internal sealed record DispatchMetadataInfo(
int Root32BitConstantCount,
bool IsSamplerUsed,
ImmutableArray ResourceDescriptors)
{
///
/// An implementation for .
///
public sealed class Comparer : IEqualityComparer
{
///
/// The singleton instance.
///
public static Comparer Default { get; } = new();
///
public bool Equals(DispatchMetadataInfo? x, DispatchMetadataInfo? 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
x.Root32BitConstantCount == y.Root32BitConstantCount &&
x.IsSamplerUsed == y.IsSamplerUsed &&
x.ResourceDescriptors.SequenceEqual(y.ResourceDescriptors, ResourceDescriptor.Comparer.Default);
}
///
public int GetHashCode(DispatchMetadataInfo obj)
{
HashCode hashCode = default;
hashCode.Add(obj.Root32BitConstantCount);
hashCode.Add(obj.IsSamplerUsed);
hashCode.AddRange(obj.ResourceDescriptors, ResourceDescriptor.Comparer.Default);
return hashCode.ToHashCode();
}
}
}