using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using ComputeSharp.D2D1Interop.SourceGenerators.Extensions;
namespace ComputeSharp.D2D1Interop.SourceGenerators.Models;
///
/// A model representing a shared and its compiled bytecode, if available.
///
/// The HLSL source for the shader.
/// The shader profile to use to compile the shader, if requested.
/// Whether linking is supported for the current shader.
/// The compiled shader bytecode, if available.
internal sealed record EmbeddedBytecodeInfo(string HlslSource, D2D1ShaderProfile? ShaderProfile, bool IsLinkingSupported, ImmutableArray Bytecode)
{
///
/// An implementation for .
///
public sealed class Comparer : IEqualityComparer
{
///
/// The singleton instance.
///
public static Comparer Default { get; } = new();
///
public bool Equals(EmbeddedBytecodeInfo? x, EmbeddedBytecodeInfo? 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.HlslSource == y.HlslSource &&
x.ShaderProfile == y.ShaderProfile &&
x.IsLinkingSupported == y.IsLinkingSupported &&
x.Bytecode.SequenceEqual(y.Bytecode);
}
///
public int GetHashCode(EmbeddedBytecodeInfo obj)
{
HashCode hashCode = default;
hashCode.Add(obj.HlslSource);
hashCode.Add(obj.ShaderProfile);
hashCode.Add(obj.IsLinkingSupported);
hashCode.AddBytes(obj.Bytecode.AsSpan());
return hashCode.ToHashCode();
}
}
}