Make all models directly equatable
このコミットが含まれているのは:
1 親
f27e98f2fa
コミット
87f2e04ca0
23ファイル変更
+287
-169
検索条件に一致するファイルはありません
@@ -13,15 +13,21 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models;
|
||||
/// <param name="ConstantBufferSizeInBytes">The size of the shader constant buffer.</param>
|
||||
internal sealed record DispatchDataInfo(ImmutableArray<FieldInfo> FieldInfos, int ConstantBufferSizeInBytes)
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public bool Equals(DispatchDataInfo? obj) => Comparer.Default.Equals(this, obj);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int GetHashCode() => Comparer.Default.GetHashCode(this);
|
||||
|
||||
/// <summary>
|
||||
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="DispatchDataInfo"/>.
|
||||
/// </summary>
|
||||
public sealed class Comparer : Comparer<DispatchDataInfo, Comparer>
|
||||
private sealed class Comparer : Comparer<DispatchDataInfo, Comparer>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
protected override void AddToHashCode(ref HashCode hashCode, DispatchDataInfo obj)
|
||||
{
|
||||
hashCode.AddRange(obj.FieldInfos, FieldInfo.Comparer.Default);
|
||||
hashCode.AddRange(obj.FieldInfos);
|
||||
hashCode.Add(obj.ConstantBufferSizeInBytes);
|
||||
}
|
||||
|
||||
@@ -29,7 +35,7 @@ internal sealed record DispatchDataInfo(ImmutableArray<FieldInfo> FieldInfos, in
|
||||
protected override bool AreEqual(DispatchDataInfo x, DispatchDataInfo y)
|
||||
{
|
||||
return
|
||||
x.FieldInfos.SequenceEqual(y.FieldInfos, FieldInfo.Comparer.Default) &&
|
||||
x.FieldInfos.SequenceEqual(y.FieldInfos) &&
|
||||
x.ConstantBufferSizeInBytes == y.ConstantBufferSizeInBytes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,10 +15,16 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models;
|
||||
/// <param name="Bytecode">The compiled shader bytecode, if available.</param>
|
||||
internal sealed record EmbeddedBytecodeInfo(string HlslSource, D2D1ShaderProfile? ShaderProfile, D2D1CompileOptions? CompileOptions, ImmutableArray<byte> Bytecode)
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public bool Equals(EmbeddedBytecodeInfo? obj) => Comparer.Default.Equals(this, obj);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int GetHashCode() => Comparer.Default.GetHashCode(this);
|
||||
|
||||
/// <summary>
|
||||
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="EmbeddedBytecodeInfo"/>.
|
||||
/// </summary>
|
||||
public sealed class Comparer : Comparer<EmbeddedBytecodeInfo, Comparer>
|
||||
private sealed class Comparer : Comparer<EmbeddedBytecodeInfo, Comparer>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
protected override void AddToHashCode(ref HashCode hashCode, EmbeddedBytecodeInfo obj)
|
||||
|
||||
@@ -23,10 +23,16 @@ internal sealed record EmbeddedBytecodeMethodInfo(
|
||||
string HlslSource,
|
||||
ImmutableArray<byte> Bytecode)
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public bool Equals(EmbeddedBytecodeMethodInfo? obj) => Comparer.Default.Equals(this, obj);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int GetHashCode() => Comparer.Default.GetHashCode(this);
|
||||
|
||||
/// <summary>
|
||||
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="EmbeddedBytecodeMethodInfo"/>.
|
||||
/// </summary>
|
||||
public sealed class Comparer : Comparer<EmbeddedBytecodeMethodInfo, Comparer>
|
||||
private sealed class Comparer : Comparer<EmbeddedBytecodeMethodInfo, Comparer>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
protected override void AddToHashCode(ref HashCode hashCode, EmbeddedBytecodeMethodInfo obj)
|
||||
|
||||
@@ -17,7 +17,37 @@ internal abstract record FieldInfo
|
||||
/// <param name="FieldPath">The path of the field with respect to the shader instance.</param>
|
||||
/// <param name="TypeName">The full metadata name for the primitive type.</param>
|
||||
/// <param name="Offset">The byte offset of the value within the root signature.</param>
|
||||
public sealed record Primitive(ImmutableArray<string> FieldPath, string TypeName, int Offset) : FieldInfo;
|
||||
public sealed record Primitive(ImmutableArray<string> FieldPath, string TypeName, int Offset) : FieldInfo
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public bool Equals(Primitive? obj) => Comparer.Default.Equals(this, obj);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int GetHashCode() => Comparer.Default.GetHashCode(this);
|
||||
|
||||
/// <summary>
|
||||
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="Primitive"/>.
|
||||
/// </summary>
|
||||
private sealed class Comparer : Comparer<Primitive, Comparer>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
protected override void AddToHashCode(ref HashCode hashCode, Primitive obj)
|
||||
{
|
||||
hashCode.AddRange(obj.FieldPath);
|
||||
hashCode.Add(obj.TypeName);
|
||||
hashCode.Add(obj.Offset);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override bool AreEqual(Primitive x, Primitive y)
|
||||
{
|
||||
return
|
||||
x.FieldPath.SequenceEqual(y.FieldPath) &&
|
||||
x.TypeName == y.TypeName &&
|
||||
x.Offset == y.Offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A captured non linear matrix value.
|
||||
@@ -34,58 +64,41 @@ internal abstract record FieldInfo
|
||||
string ElementName,
|
||||
int Rows,
|
||||
int Columns,
|
||||
ImmutableArray<int> Offsets) : FieldInfo;
|
||||
|
||||
/// <summary>
|
||||
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="FieldInfo"/>.
|
||||
/// </summary>
|
||||
public sealed class Comparer : Comparer<FieldInfo, Comparer>
|
||||
ImmutableArray<int> Offsets) : FieldInfo
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
protected override void AddToHashCode(ref HashCode hashCode, FieldInfo obj)
|
||||
{
|
||||
switch (obj)
|
||||
{
|
||||
case Primitive primitive:
|
||||
hashCode.AddRange(primitive.FieldPath);
|
||||
hashCode.Add(primitive.TypeName);
|
||||
hashCode.Add(primitive.Offset);
|
||||
break;
|
||||
case NonLinearMatrix matrix:
|
||||
hashCode.AddRange(matrix.FieldPath);
|
||||
hashCode.Add(matrix.TypeName);
|
||||
hashCode.Add(matrix.ElementName);
|
||||
hashCode.Add(matrix.Rows);
|
||||
hashCode.Add(matrix.Columns);
|
||||
hashCode.AddRange(matrix.Offsets);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
public bool Equals(NonLinearMatrix? obj) => Comparer.Default.Equals(this, obj);
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override bool AreEqual(FieldInfo x, FieldInfo y)
|
||||
public override int GetHashCode() => Comparer.Default.GetHashCode(this);
|
||||
|
||||
/// <summary>
|
||||
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="NonLinearMatrix"/>.
|
||||
/// </summary>
|
||||
private sealed class Comparer : Comparer<NonLinearMatrix, Comparer>
|
||||
{
|
||||
if (x is Primitive primitiveX && y is Primitive primitiveY)
|
||||
/// <inheritdoc/>
|
||||
protected override void AddToHashCode(ref HashCode hashCode, NonLinearMatrix obj)
|
||||
{
|
||||
return
|
||||
primitiveX.FieldPath.SequenceEqual(primitiveY.FieldPath) &&
|
||||
primitiveX.TypeName == primitiveY.TypeName &&
|
||||
primitiveX.Offset == primitiveY.Offset;
|
||||
}
|
||||
else if (x is NonLinearMatrix matrixX && y is NonLinearMatrix matrixY)
|
||||
{
|
||||
return
|
||||
matrixX.FieldPath.SequenceEqual(matrixY.FieldPath) &&
|
||||
matrixX.TypeName == matrixY.TypeName &&
|
||||
matrixX.ElementName == matrixY.ElementName &&
|
||||
matrixX.Rows == matrixY.Rows &&
|
||||
matrixY.Columns == matrixY.Columns &&
|
||||
matrixX.Offsets.SequenceEqual(matrixY.Offsets);
|
||||
hashCode.AddRange(obj.FieldPath);
|
||||
hashCode.Add(obj.TypeName);
|
||||
hashCode.Add(obj.ElementName);
|
||||
hashCode.Add(obj.Rows);
|
||||
hashCode.Add(obj.Columns);
|
||||
hashCode.AddRange(obj.Offsets);
|
||||
}
|
||||
|
||||
return false;
|
||||
/// <inheritdoc/>
|
||||
protected override bool AreEqual(NonLinearMatrix x, NonLinearMatrix y)
|
||||
{
|
||||
return
|
||||
x.FieldPath.SequenceEqual(y.FieldPath) &&
|
||||
x.TypeName == y.TypeName &&
|
||||
x.ElementName == y.ElementName &&
|
||||
x.Rows == y.Rows &&
|
||||
x.Columns == y.Columns &&
|
||||
x.Offsets.SequenceEqual(y.Offsets);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,10 +26,16 @@ internal sealed record HlslShaderMethodSourceInfo(
|
||||
D2D1CompileOptions CompileOptions,
|
||||
bool HasErrors)
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public bool Equals(HlslShaderMethodSourceInfo? obj) => Comparer.Default.Equals(this, obj);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int GetHashCode() => Comparer.Default.GetHashCode(this);
|
||||
|
||||
/// <summary>
|
||||
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="HlslShaderMethodSourceInfo"/>.
|
||||
/// </summary>
|
||||
public sealed class Comparer : Comparer<HlslShaderMethodSourceInfo, Comparer>
|
||||
private sealed class Comparer : Comparer<HlslShaderMethodSourceInfo, Comparer>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
protected override void AddToHashCode(ref HashCode hashCode, HlslShaderMethodSourceInfo obj)
|
||||
|
||||
@@ -11,10 +11,16 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models;
|
||||
/// <param name="InputDescriptions">The input descriptions for a given shader.</param>
|
||||
internal sealed record InputDescriptionsInfo(ImmutableArray<InputDescription> InputDescriptions)
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public bool Equals(InputDescriptionsInfo? obj) => Comparer.Default.Equals(this, obj);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int GetHashCode() => Comparer.Default.GetHashCode(this);
|
||||
|
||||
/// <summary>
|
||||
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="InputDescriptionsInfo"/>.
|
||||
/// </summary>
|
||||
public sealed class Comparer : Comparer<InputDescriptionsInfo, Comparer>
|
||||
private sealed class Comparer : Comparer<InputDescriptionsInfo, Comparer>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
protected override void AddToHashCode(ref HashCode hashCode, InputDescriptionsInfo obj)
|
||||
|
||||
@@ -12,10 +12,16 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models;
|
||||
/// <param name="InputTypes">The input types for a given shader.</param>
|
||||
internal sealed record InputTypesInfo(ImmutableArray<uint> InputTypes)
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public bool Equals(InputTypesInfo? obj) => Comparer.Default.Equals(this, obj);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int GetHashCode() => Comparer.Default.GetHashCode(this);
|
||||
|
||||
/// <summary>
|
||||
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="InputTypesInfo"/>.
|
||||
/// </summary>
|
||||
public sealed class Comparer : Comparer<InputTypesInfo, Comparer>
|
||||
private sealed class Comparer : Comparer<InputTypesInfo, Comparer>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
protected override void AddToHashCode(ref HashCode hashCode, InputTypesInfo obj)
|
||||
|
||||
@@ -11,10 +11,16 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models;
|
||||
/// <param name="ResourceTextureDescriptions">The resource textures for the current shader.</param>
|
||||
internal sealed record ResourceTextureDescriptionsInfo(ImmutableArray<ResourceTextureDescription> ResourceTextureDescriptions)
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public bool Equals(ResourceTextureDescriptionsInfo? obj) => Comparer.Default.Equals(this, obj);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int GetHashCode() => Comparer.Default.GetHashCode(this);
|
||||
|
||||
/// <summary>
|
||||
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="ResourceTextureDescriptionsInfo"/>.
|
||||
/// </summary>
|
||||
public sealed class Comparer : Comparer<ResourceTextureDescriptionsInfo, Comparer>
|
||||
private sealed class Comparer : Comparer<ResourceTextureDescriptionsInfo, Comparer>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
protected override void AddToHashCode(ref HashCode hashCode, ResourceTextureDescriptionsInfo obj)
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする