Switch to EquatableArray<T> in ComputeSharp models

このコミットが含まれているのは:
Sergio Pedri committed 2022-10-20 03:11:30 +02:00
1 親 c46c0d0fd4
コミット 23e5300dee
12ファイル変更
+21 -493

検索条件に一致するファイルはありません

+1 -1
ファイルの表示
@@ -82,7 +82,7 @@ internal readonly struct EquatableArray<T> : IEquatable<EquatableArray<T>>, IEnu
/// <sinheritdoc/>
public bool Equals(EquatableArray<T> array)
{
return AsImmutableArray().SequenceEqual(array.AsImmutableArray());
return AsSpan().SequenceEqual(array.AsSpan());
}
/// <sinheritdoc/>
+1 -1
ファイルの表示
@@ -118,7 +118,7 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
// Output the diagnostics, if any
context.ReportDiagnostics(
shaderInfoWithErrors
.Select(static (item, _) => item.Diagnostcs)
.Select(static (item, _) => item.Diagnostcs.AsImmutableArray())
.WithComparer(EqualityComparer<DiagnosticInfo>.Default.ForImmutableArray()));
// Get the GetDispatchId() info (hierarchy and dispatch id info)
+2 -44
ファイルの表示
@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
namespace ComputeSharp.SourceGenerators.Models;
@@ -15,44 +11,6 @@ namespace ComputeSharp.SourceGenerators.Models;
/// <param name="Root32BitConstantCount">The size of the shader root signature, in 32 bit constants.</param>
internal sealed record DispatchDataInfo(
ShaderType Type,
ImmutableArray<FieldInfo> FieldInfos,
EquatableArray<FieldInfo> FieldInfos,
int ResourceCount,
int Root32BitConstantCount)
{
/// <inheritdoc/>
public bool Equals(DispatchDataInfo? obj)
{
return Comparer.Default.Equals(this, obj);
}
/// <inheritdoc/>
public override int GetHashCode()
{
return Comparer.Default.GetHashCode(this);
}
/// <summary>
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="DispatchDataInfo"/>.
/// </summary>
private sealed class Comparer : Comparer<DispatchDataInfo, Comparer>
{
/// <inheritdoc/>
protected override void AddToHashCode(ref HashCode hashCode, DispatchDataInfo obj)
{
hashCode.Add(obj.Type);
hashCode.AddRange(obj.FieldInfos);
hashCode.Add(obj.ResourceCount);
hashCode.Add(obj.Root32BitConstantCount);
}
/// <inheritdoc/>
protected override bool AreEqual(DispatchDataInfo x, DispatchDataInfo y)
{
return
x.Type == y.Type &&
x.FieldInfos.SequenceEqual(y.FieldInfos) &&
x.ResourceCount == y.ResourceCount &&
x.Root32BitConstantCount == y.Root32BitConstantCount;
}
}
}
int Root32BitConstantCount);
+1 -36
ファイルの表示
@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
namespace ComputeSharp.SourceGenerators.Models;
@@ -10,35 +6,4 @@ namespace ComputeSharp.SourceGenerators.Models;
/// A model representing gathered info on a shader dispatch id.
/// </summary>
/// <param name="Delegates">The list of delegate field names for the shader.</param>
internal sealed record DispatchIdInfo(ImmutableArray<string> Delegates)
{
/// <inheritdoc/>
public bool Equals(DispatchIdInfo? obj)
{
return Comparer.Default.Equals(this, obj);
}
/// <inheritdoc/>
public override int GetHashCode()
{
return Comparer.Default.GetHashCode(this);
}
/// <summary>
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="DispatchIdInfo"/>.
/// </summary>
private sealed class Comparer : Comparer<DispatchIdInfo, Comparer>
{
/// <inheritdoc/>
protected override void AddToHashCode(ref HashCode hashCode, DispatchIdInfo obj)
{
hashCode.AddRange(obj.Delegates);
}
/// <inheritdoc/>
protected override bool AreEqual(DispatchIdInfo x, DispatchIdInfo y)
{
return x.Delegates.SequenceEqual(y.Delegates);
}
}
}
internal sealed record DispatchIdInfo(EquatableArray<string> Delegates);
+1 -44
ファイルの表示
@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
namespace ComputeSharp.SourceGenerators.Models;
@@ -12,43 +8,4 @@ namespace ComputeSharp.SourceGenerators.Models;
/// <param name="Root32BitConstantCount">The size of the shader root signature, in 32 bit constants.</param>
/// <param name="IsSamplerUsed">Whether or not the static sampler is used.</param>
/// <param name="ResourceDescriptors">The sequence of resource descriptors for the shader.</param>
internal sealed record DispatchMetadataInfo(
int Root32BitConstantCount,
bool IsSamplerUsed,
ImmutableArray<ResourceDescriptor> ResourceDescriptors)
{
/// <inheritdoc/>
public bool Equals(DispatchMetadataInfo? obj)
{
return Comparer.Default.Equals(this, obj);
}
/// <inheritdoc/>
public override int GetHashCode()
{
return Comparer.Default.GetHashCode(this);
}
/// <summary>
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="DispatchMetadataInfo"/>.
/// </summary>
private sealed class Comparer : Comparer<DispatchMetadataInfo, Comparer>
{
/// <inheritdoc/>
protected override void AddToHashCode(ref HashCode hashCode, DispatchMetadataInfo obj)
{
hashCode.Add(obj.Root32BitConstantCount);
hashCode.Add(obj.IsSamplerUsed);
hashCode.AddRange(obj.ResourceDescriptors);
}
/// <inheritdoc/>
protected override bool AreEqual(DispatchMetadataInfo x, DispatchMetadataInfo y)
{
return
x.Root32BitConstantCount == y.Root32BitConstantCount &&
x.IsSamplerUsed == y.IsSamplerUsed &&
x.ResourceDescriptors.SequenceEqual(y.ResourceDescriptors);
}
}
}
internal sealed record DispatchMetadataInfo(int Root32BitConstantCount, bool IsSamplerUsed, EquatableArray<ResourceDescriptor> ResourceDescriptors);
+1 -43
ファイルの表示
@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
namespace ComputeSharp.SourceGenerators.Models;
@@ -13,42 +9,4 @@ namespace ComputeSharp.SourceGenerators.Models;
/// <param name="Y">The thread ids value for the Y axis.</param>
/// <param name="Z">The thread ids value for the Z axis.</param>
/// <param name="Bytecode">The compiled shader bytecode, if available.</param>
internal sealed record EmbeddedBytecodeInfo(int X, int Y, int Z, ImmutableArray<byte> Bytecode)
{
/// <inheritdoc/>
public bool Equals(EmbeddedBytecodeInfo? obj)
{
return Comparer.Default.Equals(this, obj);
}
/// <inheritdoc/>
public override int GetHashCode()
{
return Comparer.Default.GetHashCode(this);
}
/// <summary>
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="EmbeddedBytecodeInfo"/>.
/// </summary>
private sealed class Comparer : Comparer<EmbeddedBytecodeInfo, Comparer>
{
/// <inheritdoc/>
protected override void AddToHashCode(ref HashCode hashCode, EmbeddedBytecodeInfo obj)
{
hashCode.Add(obj.X);
hashCode.Add(obj.Y);
hashCode.Add(obj.Z);
hashCode.AddBytes(obj.Bytecode.AsSpan());
}
/// <inheritdoc/>
protected override bool AreEqual(EmbeddedBytecodeInfo x, EmbeddedBytecodeInfo y)
{
return
x.X == y.X &&
x.Y == y.Y &&
x.Z == y.Z &&
x.Bytecode.SequenceEqual(y.Bytecode);
}
}
}
internal sealed record EmbeddedBytecodeInfo(int X, int Y, int Z, EquatableArray<byte> Bytecode);
+4 -122
ファイルの表示
@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
namespace ComputeSharp.SourceGenerators.Models;
@@ -17,43 +13,7 @@ internal abstract record FieldInfo
/// <param name="FieldName">The name of the resource field.</param>
/// <param name="TypeName">The full metadata name for the resource type.</param>
/// <param name="Offset">The offset for the resource within the root signature.</param>
public sealed record Resource(string FieldName, string TypeName, int Offset) : FieldInfo
{
/// <inheritdoc/>
public bool Equals(Resource? obj)
{
return Comparer.Default.Equals(this, obj);
}
/// <inheritdoc/>
public override int GetHashCode()
{
return Comparer.Default.GetHashCode(this);
}
/// <summary>
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="Resource"/>.
/// </summary>
private sealed class Comparer : Comparer<Resource, Comparer>
{
/// <inheritdoc/>
protected override void AddToHashCode(ref HashCode hashCode, Resource obj)
{
hashCode.Add(obj.FieldName);
hashCode.Add(obj.TypeName);
hashCode.Add(obj.Offset);
}
/// <inheritdoc/>
protected override bool AreEqual(Resource x, Resource y)
{
return
x.FieldName == y.FieldName &&
x.TypeName == y.TypeName &&
x.Offset == y.Offset;
}
}
}
public sealed record Resource(string FieldName, string TypeName, int Offset) : FieldInfo;
/// <summary>
/// A captured primitive value (either a scalar, a vector, or a linear matrix).
@@ -61,43 +21,7 @@ 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
{
/// <inheritdoc/>
public bool Equals(Primitive? obj)
{
return Comparer.Default.Equals(this, obj);
}
/// <inheritdoc/>
public override int GetHashCode()
{
return 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;
}
}
}
public sealed record Primitive(EquatableArray<string> FieldPath, string TypeName, int Offset) : FieldInfo;
/// <summary>
/// A captured non linear matrix value.
@@ -109,52 +33,10 @@ internal abstract record FieldInfo
/// <param name="Columns">The number of columns in the matrix.</param>
/// <param name="Offsets">The sequence of byte offsets for each row within the root signature.</param>
public sealed record NonLinearMatrix(
ImmutableArray<string> FieldPath,
EquatableArray<string> FieldPath,
string TypeName,
string ElementName,
int Rows,
int Columns,
ImmutableArray<int> Offsets) : FieldInfo
{
/// <inheritdoc/>
public bool Equals(NonLinearMatrix? obj)
{
return Comparer.Default.Equals(this, obj);
}
/// <inheritdoc/>
public override int GetHashCode()
{
return Comparer.Default.GetHashCode(this);
}
/// <summary>
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="NonLinearMatrix"/>.
/// </summary>
private sealed class Comparer : Comparer<NonLinearMatrix, Comparer>
{
/// <inheritdoc/>
protected override void AddToHashCode(ref HashCode hashCode, NonLinearMatrix obj)
{
hashCode.AddRange(obj.FieldPath);
hashCode.Add(obj.TypeName);
hashCode.Add(obj.ElementName);
hashCode.Add(obj.Rows);
hashCode.Add(obj.Columns);
hashCode.AddRange(obj.Offsets);
}
/// <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);
}
}
}
EquatableArray<int> Offsets) : FieldInfo;
}
+3 -47
ファイルの表示
@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
namespace ComputeSharp.SourceGenerators.Models;
@@ -17,46 +13,6 @@ namespace ComputeSharp.SourceGenerators.Models;
internal sealed record HlslMethodSourceInfo(
string MetadataName,
string EntryPoint,
ImmutableArray<(string Name, string Definition)> DefinedTypes,
ImmutableArray<(string Name, string Value)> DefinedConstants,
ImmutableArray<(string Signature, string Definition)> DependentMethods)
{
/// <inheritdoc/>
public bool Equals(HlslMethodSourceInfo? obj)
{
return Comparer.Default.Equals(this, obj);
}
/// <inheritdoc/>
public override int GetHashCode()
{
return Comparer.Default.GetHashCode(this);
}
/// <summary>
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="HlslMethodSourceInfo"/>.
/// </summary>
private sealed class Comparer : Comparer<HlslMethodSourceInfo, Comparer>
{
/// <inheritdoc/>
protected override void AddToHashCode(ref HashCode hashCode, HlslMethodSourceInfo obj)
{
hashCode.Add(obj.MetadataName);
hashCode.Add(obj.EntryPoint);
hashCode.AddRange(obj.DefinedTypes);
hashCode.AddRange(obj.DefinedConstants);
hashCode.AddRange(obj.DependentMethods);
}
/// <inheritdoc/>
protected override bool AreEqual(HlslMethodSourceInfo x, HlslMethodSourceInfo y)
{
return
x.MetadataName == y.MetadataName &&
x.EntryPoint == y.EntryPoint &&
x.DefinedTypes.SequenceEqual(y.DefinedTypes) &&
x.DefinedConstants.SequenceEqual(y.DefinedConstants) &&
x.DependentMethods.SequenceEqual(y.DependentMethods);
}
}
}
EquatableArray<(string Name, string Definition)> DefinedTypes,
EquatableArray<(string Name, string Value)> DefinedConstants,
EquatableArray<(string Signature, string Definition)> DependentMethods);
+4 -66
ファイルの表示
@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
namespace ComputeSharp.SourceGenerators.Models;
@@ -34,65 +30,7 @@ internal sealed record HlslShaderSourceInfo(
string EntryPoint,
string? ImplicitTextureType,
bool IsSamplerUsed,
ImmutableArray<string> DefinedTypes,
ImmutableArray<string> DefinedConstants,
ImmutableArray<string> MethodSignatures,
ImmutableArray<string> Delegates)
{
/// <inheritdoc/>
public bool Equals(HlslShaderSourceInfo? obj)
{
return Comparer.Default.Equals(this, obj);
}
/// <inheritdoc/>
public override int GetHashCode()
{
return Comparer.Default.GetHashCode(this);
}
/// <summary>
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="HlslShaderSourceInfo"/>.
/// </summary>
private sealed class Comparer : Comparer<HlslShaderSourceInfo, Comparer>
{
/// <inheritdoc/>
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);
}
/// <inheritdoc/>
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);
}
}
}
EquatableArray<string> DefinedTypes,
EquatableArray<string> DefinedConstants,
EquatableArray<string> MethodSignatures,
EquatableArray<string> Delegates);
+1 -49
ファイルの表示
@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
using ComputeSharp.SourceGeneration.Models;
@@ -24,48 +20,4 @@ internal sealed record ShaderInfo(
DispatchMetadataInfo DispatchMetadata,
HlslShaderSourceInfo HlslShaderSource,
ThreadIdsInfo ThreadIds,
ImmutableArray<DiagnosticInfo> Diagnostcs)
{
/// <inheritdoc/>
public bool Equals(ShaderInfo? obj)
{
return Comparer.Default.Equals(this, obj);
}
/// <inheritdoc/>
public override int GetHashCode()
{
return Comparer.Default.GetHashCode(this);
}
/// <summary>
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="ShaderInfo"/>.
/// </summary>
private sealed class Comparer : Comparer<ShaderInfo, Comparer>
{
/// <inheritdoc/>
protected override void AddToHashCode(ref HashCode hashCode, ShaderInfo obj)
{
hashCode.Add(obj.Hierarchy);
hashCode.Add(obj.DispatchId);
hashCode.Add(obj.DispatchData);
hashCode.Add(obj.DispatchMetadata);
hashCode.Add(obj.HlslShaderSource);
hashCode.Add(obj.ThreadIds);
hashCode.AddRange(obj.Diagnostcs);
}
/// <inheritdoc/>
protected override bool AreEqual(ShaderInfo x, ShaderInfo y)
{
return
x.Hierarchy == y.Hierarchy &&
x.DispatchId == y.DispatchId &&
x.DispatchData == y.DispatchData &&
x.DispatchMetadata == y.DispatchMetadata &&
x.HlslShaderSource == y.HlslShaderSource &&
x.ThreadIds == y.ThreadIds &&
x.Diagnostcs.SequenceEqual(y.Diagnostcs);
}
}
}
EquatableArray<DiagnosticInfo> Diagnostcs);
+1 -39
ファイルの表示
@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
using ComputeSharp.SourceGeneration.Models;
@@ -12,38 +8,4 @@ namespace ComputeSharp.SourceGenerators.Models;
/// </summary>
/// <param name="HlslMethodSource">The processed HLSL source for the shader method.</param>
/// <param name="Diagnostcs">The discovered diagnostics, if any.</param>
internal sealed record ShaderMethodInfo(HlslMethodSourceInfo HlslMethodSource, ImmutableArray<DiagnosticInfo> Diagnostcs)
{
/// <inheritdoc/>
public bool Equals(ShaderMethodInfo? obj)
{
return Comparer.Default.Equals(this, obj);
}
/// <inheritdoc/>
public override int GetHashCode()
{
return Comparer.Default.GetHashCode(this);
}
/// <summary>
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="ShaderMethodInfo"/>.
/// </summary>
private sealed class Comparer : Comparer<ShaderMethodInfo, Comparer>
{
/// <inheritdoc/>
protected override void AddToHashCode(ref HashCode hashCode, ShaderMethodInfo obj)
{
hashCode.Add(obj.HlslMethodSource);
hashCode.AddRange(obj.Diagnostcs);
}
/// <inheritdoc/>
protected override bool AreEqual(ShaderMethodInfo x, ShaderMethodInfo y)
{
return
x.HlslMethodSource == y.HlslMethodSource &&
x.Diagnostcs.SequenceEqual(y.Diagnostcs);
}
}
}
internal sealed record ShaderMethodInfo(HlslMethodSourceInfo HlslMethodSource, EquatableArray<DiagnosticInfo> Diagnostcs);
+1 -1
ファイルの表示
@@ -48,7 +48,7 @@ public sealed partial class ShaderMethodSourceGenerator : IIncrementalGenerator
// Output the diagnostics, if any
context.ReportDiagnostics(
methodInfoWithErrors
.Select(static (item, _) => item.Diagnostcs)
.Select(static (item, _) => item.Diagnostcs.AsImmutableArray())
.WithComparer(EqualityComparer<DiagnosticInfo>.Default.ForImmutableArray()));
// Generate the [ShaderMethodSource] attributes