using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
namespace ComputeSharp.SourceGenerators.Models;
///
/// A model for extracted info on a processed HLSL shader.
///
/// The shader generated header and threadsX count declaration.
/// The threadsY count declaration.
/// The threadsZ count declaration.
/// The define statements, if any.
/// The static fields and declared types, if any.
/// The captured fields, and method forward declarations.
/// The captured method implementations.
/// The shader entry point.
/// The type of the implicit texture type, if any.
/// Whether or not the static sampler is used.
/// The names of declared types.
/// The names of defined constants.
/// The signatures for captured methods.
/// The list of delegate fields.
internal sealed record HlslShaderSourceInfo(
string HeaderAndThreadsX,
string ThreadsY,
string ThreadsZ,
string Defines,
string StaticFieldsAndDeclaredTypes,
string CapturedFieldsAndResourcesAndForwardDeclarations,
string CapturedMethods,
string EntryPoint,
string? ImplicitTextureType,
bool IsSamplerUsed,
ImmutableArray DefinedTypes,
ImmutableArray DefinedConstants,
ImmutableArray MethodSignatures,
ImmutableArray Delegates)
{
///
public bool Equals(HlslShaderSourceInfo? obj) => Comparer.Default.Equals(this, obj);
///
public override int GetHashCode() => Comparer.Default.GetHashCode(this);
///
/// An implementation for .
///
private sealed class Comparer : Comparer
{
///
protected override void AddToHashCode(ref HashCode hashCode, HlslShaderSourceInfo obj)
{
hashCode.Add(obj.HeaderAndThreadsX);
hashCode.Add(obj.ThreadsY);
hashCode.Add(obj.ThreadsZ);
hashCode.Add(obj.Defines);
hashCode.Add(obj.StaticFieldsAndDeclaredTypes);
hashCode.Add(obj.CapturedFieldsAndResourcesAndForwardDeclarations);
hashCode.Add(obj.CapturedMethods);
hashCode.Add(obj.EntryPoint);
hashCode.Add(obj.ImplicitTextureType);
hashCode.Add(obj.IsSamplerUsed);
hashCode.AddRange(obj.DefinedTypes);
hashCode.AddRange(obj.DefinedConstants);
hashCode.AddRange(obj.MethodSignatures);
hashCode.AddRange(obj.Delegates);
}
///
protected override bool AreEqual(HlslShaderSourceInfo x, HlslShaderSourceInfo y)
{
return
x.HeaderAndThreadsX == y.HeaderAndThreadsX &&
x.ThreadsY == y.ThreadsY &&
x.ThreadsZ == y.ThreadsZ &&
x.Defines == y.Defines &&
x.StaticFieldsAndDeclaredTypes == y.StaticFieldsAndDeclaredTypes &&
x.CapturedFieldsAndResourcesAndForwardDeclarations == y.CapturedFieldsAndResourcesAndForwardDeclarations &&
x.CapturedMethods == y.CapturedMethods &&
x.EntryPoint == y.EntryPoint &&
x.ImplicitTextureType == y.ImplicitTextureType &&
x.IsSamplerUsed == y.IsSamplerUsed &&
x.DefinedTypes.SequenceEqual(y.DefinedTypes) &&
x.DefinedConstants.SequenceEqual(y.DefinedTypes) &&
x.MethodSignatures.SequenceEqual(y.MethodSignatures) &&
x.Delegates.SequenceEqual(y.Delegates);
}
}
}