using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
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)
{
///
public bool Equals(DispatchMetadataInfo? 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, DispatchMetadataInfo obj)
{
hashCode.Add(obj.Root32BitConstantCount);
hashCode.Add(obj.IsSamplerUsed);
hashCode.AddRange(obj.ResourceDescriptors);
}
///
protected override bool AreEqual(DispatchMetadataInfo x, DispatchMetadataInfo y)
{
return
x.Root32BitConstantCount == y.Root32BitConstantCount &&
x.IsSamplerUsed == y.IsSamplerUsed &&
x.ResourceDescriptors.SequenceEqual(y.ResourceDescriptors);
}
}
}