Merge pull request #413 from Sergio0694/dev/equatable-array

Add and use new EquatableArray<T> type in source generators
このコミットが含まれているのは:
Sergio Pedri authored and GitHub committed 2022-10-21 03:56:25 -07:00
コミット 2e9da5cf85
35ファイル変更
+282 -1356

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

+1 -39
ファイルの表示
@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
namespace ComputeSharp.Core.SourceGenerators.Models;
@@ -11,38 +7,4 @@ namespace ComputeSharp.Core.SourceGenerators.Models;
/// </summary>
/// <param name="Parameters">The <see cref="ParameterInfo"/> values for the constructor.</param>
/// <param name="DefaultedFields">The names of ignored fields that should be defaulted.</param>
internal sealed record ConstructorInfo(ImmutableArray<ParameterInfo> Parameters, ImmutableArray<string> DefaultedFields)
{
/// <inheritdoc/>
public bool Equals(ConstructorInfo? 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="ConstructorInfo"/>.
/// </summary>
private sealed class Comparer : Comparer<ConstructorInfo, Comparer>
{
/// <inheritdoc/>
protected override void AddToHashCode(ref HashCode hashCode, ConstructorInfo obj)
{
hashCode.AddRange(obj.Parameters);
hashCode.AddRange(obj.DefaultedFields);
}
/// <inheritdoc/>
protected override bool AreEqual(ConstructorInfo x, ConstructorInfo y)
{
return
x.Parameters.SequenceEqual(y.Parameters) &&
x.DefaultedFields.SequenceEqual(y.DefaultedFields);
}
}
}
internal sealed record ConstructorInfo(EquatableArray<ParameterInfo> Parameters, EquatableArray<string> DefaultedFields);
+1 -1
ファイルの表示
@@ -87,7 +87,7 @@ partial class D2DPixelShaderSourceGenerator
// <METHOD_BODY>
return
MethodDeclaration(returnType, Identifier(bytecodeInfo.MethodName))
.AddModifiers(bytecodeInfo.Modifiers.Select(Token).ToArray())
.AddModifiers(bytecodeInfo.Modifiers.Select(static m => Token((SyntaxKind)m)).ToArray())
.AddAttributeLists(
AttributeList(SingletonSeparatedList(
Attribute(IdentifierName("global::System.CodeDom.Compiler.GeneratedCode"))
+2 -4
ファイルの表示
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using ComputeSharp.D2D1.SourceGenerators.Models;
@@ -41,7 +40,7 @@ public sealed partial class D2DPixelShaderSourceGenerator : IIncrementalGenerato
token.ThrowIfCancellationRequested();
// Get the remaining info for the current shader
ImmutableArray<SyntaxKind> modifiers = methodDeclaration.Modifiers.Select(token => token.Kind()).ToImmutableArray();
ImmutableArray<ushort> modifiers = methodDeclaration.Modifiers.Select(token => (ushort)token.Kind()).ToImmutableArray();
string methodName = methodSymbol.Name;
string? invalidReturnType = Execute.GetInvalidReturnType(diagnostics, methodSymbol);
D2D1ShaderProfile shaderProfile = Execute.GetShaderProfile(diagnostics, methodSymbol);
@@ -63,8 +62,7 @@ public sealed partial class D2DPixelShaderSourceGenerator : IIncrementalGenerato
// Output the diagnostics
context.ReportDiagnostics(
shaderInfoWithErrors
.Select(static (item, _) => item.Diagnostcs)
.WithComparer(EqualityComparer<DiagnosticInfo>.Default.ForImmutableArray()));
.Select(static (item, _) => item.Diagnostcs));
// Compile the requested shader bytecodes
IncrementalValuesProvider<(HierarchyInfo Hierarchy, EmbeddedBytecodeMethodInfo BytecodeInfo, DeferredDiagnosticInfo? Diagnostic)> embeddedBytecodeWithErrors =
+1 -3
ファイルの表示
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Text;
@@ -135,8 +134,7 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
// Output the diagnostics, if any
context.ReportDiagnostics(
shaderInfoWithErrors
.Select(static (item, _) => item.Diagnostcs)
.WithComparer(EqualityComparer<DiagnosticInfo>.Default.ForImmutableArray()));
.Select(static (item, _) => item.Diagnostcs));
// Get the GetInputCount() info (hierarchy and input count)
IncrementalValuesProvider<(HierarchyInfo Hierarchy, int InputCount)> inputCountInfo =
+1 -41
ファイルの表示
@@ -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;
@@ -16,40 +12,4 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models;
internal sealed record D2D1PixelShaderSourceInfo(
HierarchyInfo Hierarchy,
HlslShaderMethodSourceInfo HlslShaderMethodSource,
ImmutableArray<DiagnosticInfo> Diagnostcs)
{
/// <inheritdoc/>
public bool Equals(D2D1PixelShaderSourceInfo? 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="D2D1PixelShaderSourceInfo"/>.
/// </summary>
private sealed class Comparer : Comparer<D2D1PixelShaderSourceInfo, Comparer>
{
/// <inheritdoc/>
protected override void AddToHashCode(ref HashCode hashCode, D2D1PixelShaderSourceInfo obj)
{
hashCode.Add(obj.Hierarchy);
hashCode.Add(obj.HlslShaderMethodSource);
hashCode.AddRange(obj.Diagnostcs);
}
/// <inheritdoc/>
protected override bool AreEqual(D2D1PixelShaderSourceInfo x, D2D1PixelShaderSourceInfo y)
{
return
x.Hierarchy == y.Hierarchy &&
x.HlslShaderMethodSource == y.HlslShaderMethodSource &&
x.Diagnostcs.SequenceEqual(y.Diagnostcs);
}
}
}
EquatableArray<DiagnosticInfo> Diagnostcs);
+1 -53
ファイルの表示
@@ -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;
@@ -28,52 +24,4 @@ internal sealed record D2D1ShaderInfo(
OutputBufferInfo OutputBuffer,
InputDescriptionsInfo InputDescriptions,
D2D1PixelOptions PixelOptions,
ImmutableArray<DiagnosticInfo> Diagnostcs)
{
/// <inheritdoc/>
public bool Equals(D2D1ShaderInfo? 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="D2D1ShaderInfo"/>.
/// </summary>
private sealed class Comparer : Comparer<D2D1ShaderInfo, Comparer>
{
/// <inheritdoc/>
protected override void AddToHashCode(ref HashCode hashCode, D2D1ShaderInfo obj)
{
hashCode.Add(obj.Hierarchy);
hashCode.Add(obj.DispatchData);
hashCode.Add(obj.InputTypes);
hashCode.Add(obj.ResourceTextureDescriptions);
hashCode.Add(obj.HlslShaderSource);
hashCode.Add(obj.OutputBuffer);
hashCode.Add(obj.InputDescriptions);
hashCode.Add(obj.PixelOptions);
hashCode.AddRange(obj.Diagnostcs);
}
/// <inheritdoc/>
protected override bool AreEqual(D2D1ShaderInfo x, D2D1ShaderInfo y)
{
return
x.Hierarchy == y.Hierarchy &&
x.DispatchData == y.DispatchData &&
x.InputTypes == y.InputTypes &&
x.ResourceTextureDescriptions == y.ResourceTextureDescriptions &&
x.HlslShaderSource == y.HlslShaderSource &&
x.OutputBuffer == y.OutputBuffer &&
x.InputDescriptions == y.InputDescriptions &&
x.PixelOptions == y.PixelOptions &&
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;
namespace ComputeSharp.D2D1.SourceGenerators.Models;
@@ -11,38 +7,4 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models;
/// </summary>
/// <param name="FieldInfos">The description on shader instance fields.</param>
/// <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)
{
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.AddRange(obj.FieldInfos);
hashCode.Add(obj.ConstantBufferSizeInBytes);
}
/// <inheritdoc/>
protected override bool AreEqual(DispatchDataInfo x, DispatchDataInfo y)
{
return
x.FieldInfos.SequenceEqual(y.FieldInfos) &&
x.ConstantBufferSizeInBytes == y.ConstantBufferSizeInBytes;
}
}
}
internal sealed record DispatchDataInfo(EquatableArray<FieldInfo> FieldInfos, int ConstantBufferSizeInBytes);
+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.D2D1.SourceGenerators.Models;
@@ -13,42 +9,4 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models;
/// <param name="ShaderProfile">The shader profile to use to compile the shader, if requested.</param>
/// <param name="CompileOptions">The compile options to use to compile the shader.</param>
/// <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)
{
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.HlslSource);
hashCode.Add(obj.ShaderProfile);
hashCode.Add(obj.CompileOptions);
hashCode.AddBytes(obj.Bytecode.AsSpan());
}
/// <inheritdoc/>
protected override bool AreEqual(EmbeddedBytecodeInfo x, EmbeddedBytecodeInfo y)
{
return
x.HlslSource == y.HlslSource &&
x.ShaderProfile == y.ShaderProfile &&
x.CompileOptions == y.CompileOptions &&
x.Bytecode.SequenceEqual(y.Bytecode);
}
}
}
internal sealed record EmbeddedBytecodeInfo(string HlslSource, D2D1ShaderProfile? ShaderProfile, D2D1CompileOptions? CompileOptions, EquatableArray<byte> Bytecode);
+3 -49
ファイルの表示
@@ -1,64 +1,18 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Runtime.InteropServices;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
using Microsoft.CodeAnalysis.CSharp;
namespace ComputeSharp.D2D1.SourceGenerators.Models;
/// <summary>
/// A model representing info on a shader method that has requested to be precompiled at build time.
/// </summary>
/// <param name="Modifiers">The modifiers for the annotated method.</param>
/// <param name="Modifiers">The modifiers for the annotated method (these are <see cref="Microsoft.CodeAnalysis.CSharp.SyntaxKind"/> values, which can't be equated directly).</param>
/// <param name="MethodName">The name of the annotated method.</param>
/// <param name="InvalidReturnType">The fully qualified name of the return type, if invalid.</param>
/// <param name="HlslSource">The HLSL source.</param>
/// <param name="Bytecode">The compiled shader bytecode, if available.</param>
internal sealed record EmbeddedBytecodeMethodInfo(
ImmutableArray<SyntaxKind> Modifiers,
EquatableArray<ushort> Modifiers,
string MethodName,
string? InvalidReturnType,
string HlslSource,
ImmutableArray<byte> Bytecode)
{
/// <inheritdoc/>
public bool Equals(EmbeddedBytecodeMethodInfo? 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="EmbeddedBytecodeMethodInfo"/>.
/// </summary>
private sealed class Comparer : Comparer<EmbeddedBytecodeMethodInfo, Comparer>
{
/// <inheritdoc/>
protected override void AddToHashCode(ref HashCode hashCode, EmbeddedBytecodeMethodInfo obj)
{
hashCode.AddRange(obj.Modifiers);
hashCode.Add(obj.MethodName);
hashCode.Add(obj.InvalidReturnType);
hashCode.Add(obj.HlslSource);
hashCode.AddBytes(obj.Bytecode.AsSpan());
}
/// <inheritdoc/>
protected override bool AreEqual(EmbeddedBytecodeMethodInfo x, EmbeddedBytecodeMethodInfo y)
{
return
MemoryMarshal.Cast<SyntaxKind, ushort>(x.Modifiers.AsSpan()).SequenceEqual(MemoryMarshal.Cast<SyntaxKind, ushort>(y.Modifiers.AsSpan())) &&
x.MethodName == y.MethodName &&
x.InvalidReturnType == y.InvalidReturnType &&
x.HlslSource == y.HlslSource &&
x.Bytecode.SequenceEqual(y.Bytecode);
}
}
}
EquatableArray<byte> Bytecode);
+3 -85
ファイルの表示
@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
namespace ComputeSharp.D2D1.SourceGenerators.Models;
@@ -17,43 +13,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.
@@ -65,52 +25,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 -52
ファイルの表示
@@ -1,16 +1,11 @@
using System;
using System.Collections.Immutable;
using System.Runtime.InteropServices;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
using Microsoft.CodeAnalysis.CSharp;
namespace ComputeSharp.D2D1.SourceGenerators.Models;
/// <summary>
/// A model for extracted info on a processed HLSL shader method.
/// </summary>
/// <param name="Modifiers">The modifiers for the annotated method.</param>
/// <param name="Modifiers">The modifiers for the annotated method (these are <see cref="Microsoft.CodeAnalysis.CSharp.SyntaxKind"/> values, which can't be equated directly).</param>
/// <param name="MethodName">The name of the annotated method.</param>
/// <param name="InvalidReturnType">The fully qualified name of the return type, if invalid.</param>
/// <param name="HlslSource">The HLSL source.</param>
@@ -18,54 +13,10 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models;
/// <param name="CompileOptions">The compile options to use to compile the shader.</param>
/// <param name="HasErrors">Whether any errors have been detected, and therefore the shader compilation should be skipped.</param>
internal sealed record HlslShaderMethodSourceInfo(
ImmutableArray<SyntaxKind> Modifiers,
EquatableArray<ushort> Modifiers,
string MethodName,
string? InvalidReturnType,
string HlslSource,
D2D1ShaderProfile ShaderProfile,
D2D1CompileOptions CompileOptions,
bool HasErrors)
{
/// <inheritdoc/>
public bool Equals(HlslShaderMethodSourceInfo? 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="HlslShaderMethodSourceInfo"/>.
/// </summary>
private sealed class Comparer : Comparer<HlslShaderMethodSourceInfo, Comparer>
{
/// <inheritdoc/>
protected override void AddToHashCode(ref HashCode hashCode, HlslShaderMethodSourceInfo obj)
{
hashCode.AddRange(obj.Modifiers);
hashCode.Add(obj.MethodName);
hashCode.Add(obj.InvalidReturnType);
hashCode.Add(obj.HlslSource);
hashCode.Add(obj.ShaderProfile);
hashCode.Add(obj.CompileOptions);
hashCode.Add(obj.HasErrors);
}
/// <inheritdoc/>
protected override bool AreEqual(HlslShaderMethodSourceInfo x, HlslShaderMethodSourceInfo y)
{
return
MemoryMarshal.Cast<SyntaxKind, ushort>(x.Modifiers.AsSpan()).SequenceEqual(MemoryMarshal.Cast<SyntaxKind, ushort>(y.Modifiers.AsSpan())) &&
x.MethodName == y.MethodName &&
x.InvalidReturnType == y.InvalidReturnType &&
x.HlslSource == y.HlslSource &&
x.ShaderProfile == y.ShaderProfile &&
x.CompileOptions == y.CompileOptions &&
x.HasErrors == y.HasErrors;
}
}
}
bool HasErrors);
+1 -35
ファイルの表示
@@ -1,6 +1,3 @@
using System;
using System.Collections.Immutable;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
namespace ComputeSharp.D2D1.SourceGenerators.Models;
@@ -9,35 +6,4 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models;
/// A model representing gathered input descriptions for a shader.
/// </summary>
/// <param name="InputDescriptions">The input descriptions for a given shader.</param>
internal sealed record InputDescriptionsInfo(ImmutableArray<InputDescription> InputDescriptions)
{
/// <inheritdoc/>
public bool Equals(InputDescriptionsInfo? 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="InputDescriptionsInfo"/>.
/// </summary>
private sealed class Comparer : Comparer<InputDescriptionsInfo, Comparer>
{
/// <inheritdoc/>
protected override void AddToHashCode(ref HashCode hashCode, InputDescriptionsInfo obj)
{
hashCode.AddRange(obj.InputDescriptions);
}
/// <inheritdoc/>
protected override bool AreEqual(InputDescriptionsInfo x, InputDescriptionsInfo y)
{
return x.InputDescriptions.SequenceEqual(y.InputDescriptions);
}
}
}
internal sealed record InputDescriptionsInfo(EquatableArray<InputDescription> InputDescriptions);
+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.D2D1.SourceGenerators.Models;
@@ -10,35 +6,4 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models;
/// A model representing gathered info on a shader input types.
/// </summary>
/// <param name="InputTypes">The input types for a given shader.</param>
internal sealed record InputTypesInfo(ImmutableArray<uint> InputTypes)
{
/// <inheritdoc/>
public bool Equals(InputTypesInfo? 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="InputTypesInfo"/>.
/// </summary>
private sealed class Comparer : Comparer<InputTypesInfo, Comparer>
{
/// <inheritdoc/>
protected override void AddToHashCode(ref HashCode hashCode, InputTypesInfo obj)
{
hashCode.AddRange(obj.InputTypes);
}
/// <inheritdoc/>
protected override bool AreEqual(InputTypesInfo x, InputTypesInfo y)
{
return x.InputTypes.SequenceEqual(y.InputTypes);
}
}
}
internal sealed record InputTypesInfo(EquatableArray<uint> InputTypes);
+1 -35
ファイルの表示
@@ -1,6 +1,3 @@
using System;
using System.Collections.Immutable;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
namespace ComputeSharp.D2D1.SourceGenerators.Models;
@@ -9,35 +6,4 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models;
/// A model representing gathered resource texture descriptions for a shader.
/// </summary>
/// <param name="ResourceTextureDescriptions">The resource textures for the current shader.</param>
internal sealed record ResourceTextureDescriptionsInfo(ImmutableArray<ResourceTextureDescription> ResourceTextureDescriptions)
{
/// <inheritdoc/>
public bool Equals(ResourceTextureDescriptionsInfo? 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="ResourceTextureDescriptionsInfo"/>.
/// </summary>
private sealed class Comparer : Comparer<ResourceTextureDescriptionsInfo, Comparer>
{
/// <inheritdoc/>
protected override void AddToHashCode(ref HashCode hashCode, ResourceTextureDescriptionsInfo obj)
{
hashCode.AddRange(obj.ResourceTextureDescriptions);
}
/// <inheritdoc/>
protected override bool AreEqual(ResourceTextureDescriptionsInfo x, ResourceTextureDescriptionsInfo y)
{
return x.ResourceTextureDescriptions.SequenceEqual(y.ResourceTextureDescriptions);
}
}
}
internal sealed record ResourceTextureDescriptionsInfo(EquatableArray<ResourceTextureDescription> ResourceTextureDescriptions);
+1 -4
ファイルの表示
@@ -13,11 +13,8 @@
<Compile Include="$(MSBuildThisFileDirectory)Extensions\IncrementalValueProviderExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\CompilationExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\DiagnosticsExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\HashCodeExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\IEqualityComparerExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\ImmutableArrayExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\ISymbolExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\Comparer{T,TSelf}.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\EquatableArray{T}.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\HashCode.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\ImmutableArrayBuilder{T}.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\ObjectPool{T}.cs" />
+1 -2
ファイルの表示
@@ -1,4 +1,3 @@
using System.Collections.Immutable;
using ComputeSharp.SourceGeneration.Helpers;
using ComputeSharp.SourceGeneration.Models;
using Microsoft.CodeAnalysis;
@@ -57,7 +56,7 @@ internal static class DiagnosticsExtensions
/// </summary>
/// <param name="context">The input <see cref="IncrementalGeneratorInitializationContext"/> instance.</param>
/// <param name="diagnostics">The input <see cref="IncrementalValuesProvider{TValues}"/> sequence of diagnostics.</param>
public static void ReportDiagnostics(this IncrementalGeneratorInitializationContext context, IncrementalValuesProvider<ImmutableArray<DiagnosticInfo>> diagnostics)
public static void ReportDiagnostics(this IncrementalGeneratorInitializationContext context, IncrementalValuesProvider<EquatableArray<DiagnosticInfo>> diagnostics)
{
context.RegisterSourceOutput(diagnostics, static (context, diagnostics) =>
{
-40
ファイルの表示
@@ -1,40 +0,0 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
namespace ComputeSharp.SourceGeneration.Extensions;
/// <summary>
/// Extension methods for <see cref="HashCode"/>.
/// </summary>
internal static class HashCodeExtensions
{
/// <summary>
/// Adds all items from a given <see cref="ImmutableArray{T}"/> instance to an hashcode.
/// </summary>
/// <typeparam name="T">The type of items to hash.</typeparam>
/// <param name="hashCode">The target <see cref="HashCode"/> instance.</param>
/// <param name="items">The input items to hash.</param>
public static void AddRange<T>(this ref HashCode hashCode, ImmutableArray<T> items)
{
foreach (T item in items)
{
hashCode.Add(item);
}
}
/// <summary>
/// Adds all items from a given <see cref="ImmutableArray{T}"/> instance to an hashcode.
/// </summary>
/// <typeparam name="T">The type of items to hash.</typeparam>
/// <param name="hashCode">The target <see cref="HashCode"/> instance.</param>
/// <param name="comparer">A comparer to get hashcodes for <typeparamref name="T"/> items.</param>
/// <param name="items">The input items to hash.</param>
public static void AddRange<T>(this ref HashCode hashCode, ImmutableArray<T> items, IEqualityComparer<T> comparer)
{
foreach (T item in items)
{
hashCode.Add(item, comparer);
}
}
}
-59
ファイルの表示
@@ -1,59 +0,0 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
namespace ComputeSharp.SourceGeneration.Extensions;
/// <summary>
/// Extension methods for <see cref="IEqualityComparer{T}"/>.
/// </summary>
internal static class IEqualityComparerExtensions
{
/// <summary>
/// Gets an <see cref="IEqualityComparer{T}"/> for an <see cref="ImmutableArray{T}"/> sequence.
/// </summary>
/// <typeparam name="T">The type of items to compare.</typeparam>
/// <param name="comparer">The compare for individual <typeparamref name="T"/> items.</param>
public static IEqualityComparer<ImmutableArray<T>> ForImmutableArray<T>(this IEqualityComparer<T> comparer)
{
return new Comparer<T>(comparer);
}
/// <summary>
/// An <see cref="IEqualityComparer{T}"/> implementation for an <see cref="ImmutableArray{T}"/> value.
/// </summary>
private sealed class Comparer<T> : IEqualityComparer<ImmutableArray<T>>
{
/// <summary>
/// The <typeparamref name="T"/> comparer.
/// </summary>
private readonly IEqualityComparer<T> comparer;
/// <summary>
/// Creates a new <see cref="Comparer{T}"/> instance with the specified parameters.
/// </summary>
/// <param name="comparer">The <typeparamref name="T"/> comparer.</param>
public Comparer(IEqualityComparer<T> comparer)
{
this.comparer = comparer;
}
/// <inheritdoc/>
public bool Equals(ImmutableArray<T> x, ImmutableArray<T> y)
{
return
x == y ||
x.SequenceEqual(y, this.comparer);
}
/// <inheritdoc/>
public int GetHashCode(ImmutableArray<T> obj)
{
HashCode hashCode = default;
hashCode.AddRange(obj, this.comparer);
return hashCode.ToHashCode();
}
}
}
-50
ファイルの表示
@@ -1,50 +0,0 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
namespace ComputeSharp.SourceGeneration.Extensions;
/// <summary>
/// Extension methods for <see cref="ImmutableArray{T}"/>.
/// </summary>
internal static class ImmutableArrayExtensions
{
/// <summary>
/// Compares two sequences for equality.
/// </summary>
/// <typeparam name="T">The items to compare.</typeparam>
/// <param name="left">The left sequence of items.</param>
/// <param name="right">The right sequence of items.</param>
/// <returns>Whether or not <paramref name="left"/> equals <paramref name="right"/>.</returns>
public static bool SequenceEqual<T>(this ImmutableArray<T> left, ImmutableArray<T> right)
where T : IEquatable<T>
{
return left.AsSpan().SequenceEqual(right.AsSpan());
}
/// <summary>
/// Compares two sequences for equality.
/// </summary>
/// <typeparam name="T">The items to compare.</typeparam>
/// <param name="left">The left sequence of items.</param>
/// <param name="right">The right sequence of items.</param>
/// <param name="comparer">The <see cref="IEqualityComparer{T}"/> instance used to compare <typeparamref name="T"/> items.</param>
/// <returns>Whether or not <paramref name="left"/> equals <paramref name="right"/>.</returns>
public static bool SequenceEqual<T>(this ImmutableArray<T> left, ImmutableArray<T> right, IEqualityComparer<T> comparer)
{
if (left.Length != right.Length)
{
return false;
}
for (int i = 0; i < left.Length; i++)
{
if (!comparer.Equals(left[i], right[i]))
{
return false;
}
}
return true;
}
}
-68
ファイルの表示
@@ -1,68 +0,0 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
namespace ComputeSharp.SourceGeneration.Helpers;
/// <summary>
/// A base <see cref="IEqualityComparer{T}"/> implementation for <typeparamref name="T"/> instances.
/// </summary>
/// <typeparam name="T">The type of items to compare.</typeparam>
/// <typeparam name="TSelf">The concrete comparer type.</typeparam>
internal abstract class Comparer<T, TSelf> : IEqualityComparer<T>
where TSelf : Comparer<T, TSelf>, new()
{
/// <summary>
/// The singleton <typeparamref name="TSelf"/> instance.
/// </summary>
public static TSelf Default { get; } = new();
/// <inheritdoc/>
public bool Equals(T? x, T? 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 AreEqual(x, y);
}
/// <inheritdoc/>
public int GetHashCode(T obj)
{
HashCode hashCode = default;
AddToHashCode(ref hashCode, obj);
return hashCode.ToHashCode();
}
/// <summary>
/// Adds the current instance to an incremental <see cref="HashCode"/> value.
/// </summary>
/// <param name="hashCode">The target <see cref="HashCode"/> value.</param>
/// <param name="obj">The <typeparamref name="T"/> instance being inspected.</param>
protected abstract void AddToHashCode(ref HashCode hashCode, T obj);
/// <summary>
/// Compares two <typeparamref name="T"/> instances for equality.
/// </summary>
/// <param name="x">The first <typeparamref name="T"/> instance to compare.</param>
/// <param name="y">The second <typeparamref name="T"/> instance to compare.</param>
/// <returns>Whether or not <paramref name="x"/> and <paramref name="y"/> are equal.</returns>
protected abstract bool AreEqual(T x, T y);
}
+236
ファイルの表示
@@ -0,0 +1,236 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace ComputeSharp.SourceGeneration.Helpers;
/// <summary>
/// Extensions for <see cref="EquatableArray{T}"/>.
/// </summary>
internal static class EquatableArray
{
/// <summary>
/// Creates an <see cref="EquatableArray{T}"/> instance from a given <see cref="ImmutableArray{T}"/>.
/// </summary>
/// <typeparam name="T">The type of items in the input array.</typeparam>
/// <param name="array">The input <see cref="ImmutableArray{T}"/> instance.</param>
/// <returns>An <see cref="EquatableArray{T}"/> instance from a given <see cref="ImmutableArray{T}"/>.</returns>
public static EquatableArray<T> AsEquatableArray<T>(this ImmutableArray<T> array)
where T : IEquatable<T>
{
return new(array);
}
}
/// <summary>
/// An imutable, equatable array. This is equivalent to <see cref="ImmutableArray{T}"/> but with value equality support.
/// </summary>
/// <typeparam name="T">The type of values in the array.</typeparam>
internal readonly struct EquatableArray<T> : IEquatable<EquatableArray<T>>, IEnumerable<T>
where T : IEquatable<T>
{
/// <summary>
/// The underlying <typeparamref name="T"/> array.
/// </summary>
private readonly T[]? array;
/// <summary>
/// Creates a new <see cref="EquatableArray{T}"/> instance.
/// </summary>
/// <param name="array">The input <see cref="ImmutableArray{T}"/> to wrap.</param>
public EquatableArray(ImmutableArray<T> array)
{
this.array = Unsafe.As<ImmutableArray<T>, T[]?>(ref array);
}
/// <summary>
/// Gets a reference to an item at a specified position within the array.
/// </summary>
/// <param name="index">The index of the item to retrieve a reference to.</param>
/// <returns>A reference to an item at a specified position within the array.</returns>
public ref readonly T this[int index]
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => ref AsImmutableArray().ItemRef(index);
}
/// <summary>
/// Gets a value indicating whether the current array is empty.
/// </summary>
public bool IsEmpty
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => AsImmutableArray().IsEmpty;
}
/// <summary>
/// Gets a value indicating whether the current array is default or empty.
/// </summary>
public bool IsDefaultOrEmpty
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => AsImmutableArray().IsDefaultOrEmpty;
}
/// <summary>
/// Gets the length of the current array.
/// </summary>
public int Length
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => AsImmutableArray().Length;
}
/// <sinheritdoc/>
public bool Equals(EquatableArray<T> array)
{
return AsSpan().SequenceEqual(array.AsSpan());
}
/// <sinheritdoc/>
public override bool Equals(object? obj)
{
return obj is EquatableArray<T> array && Equals(this, array);
}
/// <sinheritdoc/>
public override unsafe int GetHashCode()
{
if (this.array is not T[] array)
{
return 0;
}
HashCode hashCode = default;
if (typeof(T) == typeof(byte))
{
ReadOnlySpan<T> span = array;
ref T r0 = ref MemoryMarshal.GetReference(span);
ref byte r1 = ref Unsafe.As<T, byte>(ref r0);
fixed (byte* p = &r1)
{
ReadOnlySpan<byte> bytes = new(p, span.Length);
hashCode.AddBytes(bytes);
}
}
else
{
foreach (T item in array)
{
hashCode.Add(item);
}
}
return hashCode.ToHashCode();
}
/// <summary>
/// Gets an <see cref="ImmutableArray{T}"/> instance from the current <see cref="EquatableArray{T}"/>.
/// </summary>
/// <returns>The <see cref="ImmutableArray{T}"/> from the current <see cref="EquatableArray{T}"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ImmutableArray<T> AsImmutableArray()
{
return Unsafe.As<T[]?, ImmutableArray<T>>(ref Unsafe.AsRef(in this.array));
}
/// <summary>
/// Creates an <see cref="EquatableArray{T}"/> instance from a given <see cref="ImmutableArray{T}"/>.
/// </summary>
/// <param name="array">The input <see cref="ImmutableArray{T}"/> instance.</param>
/// <returns>An <see cref="EquatableArray{T}"/> instance from a given <see cref="ImmutableArray{T}"/>.</returns>
public static EquatableArray<T> FromImmutableArray(ImmutableArray<T> array)
{
return new(array);
}
/// <summary>
/// Returns a <see cref="ReadOnlySpan{T}"/> wrapping the current items.
/// </summary>
/// <returns>A <see cref="ReadOnlySpan{T}"/> wrapping the current items.</returns>
public ReadOnlySpan<T> AsSpan()
{
return AsImmutableArray().AsSpan();
}
/// <summary>
/// Copies the contents of this <see cref="EquatableArray{T}"/> instance. to a mutable array.
/// </summary>
/// <returns>The newly instantiated array.</returns>
public T[] ToArray()
{
return AsImmutableArray().ToArray();
}
/// <summary>
/// Gets an <see cref="ImmutableArray{T}.Enumerator"/> value to traverse items in the current array.
/// </summary>
/// <returns>An <see cref="ImmutableArray{T}.Enumerator"/> value to traverse items in the current array.</returns>
public ImmutableArray<T>.Enumerator GetEnumerator()
{
return AsImmutableArray().GetEnumerator();
}
/// <sinheritdoc/>
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
return ((IEnumerable<T>)AsImmutableArray()).GetEnumerator();
}
/// <sinheritdoc/>
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable)AsImmutableArray()).GetEnumerator();
}
/// <summary>
/// Implicitly converts an <see cref="ImmutableArray{T}"/> to <see cref="EquatableArray{T}"/>.
/// </summary>
/// <returns>An <see cref="EquatableArray{T}"/> instance from a given <see cref="ImmutableArray{T}"/>.</returns>
public static implicit operator EquatableArray<T>(ImmutableArray<T> array)
{
return FromImmutableArray(array);
}
/// <summary>
/// Implicitly converts an <see cref="EquatableArray{T}"/> to <see cref="ImmutableArray{T}"/>.
/// </summary>
/// <returns>An <see cref="ImmutableArray{T}"/> instance from a given <see cref="EquatableArray{T}"/>.</returns>
public static implicit operator ImmutableArray<T>(EquatableArray<T> array)
{
return array.AsImmutableArray();
}
/// <summary>
/// Checks whether two <see cref="EquatableArray{T}"/> values are the same.
/// </summary>
/// <param name="left">The first <see cref="EquatableArray{T}"/> value.</param>
/// <param name="right">The second <see cref="EquatableArray{T}"/> value.</param>
/// <returns>Whether <paramref name="left"/> and <paramref name="right"/> are equal.</returns>
public static bool operator ==(EquatableArray<T> left, EquatableArray<T> right)
{
return left.Equals(right);
}
/// <summary>
/// Checks whether two <see cref="EquatableArray{T}"/> values are not the same.
/// </summary>
/// <param name="left">The first <see cref="EquatableArray{T}"/> value.</param>
/// <param name="right">The second <see cref="EquatableArray{T}"/> value.</param>
/// <returns>Whether <paramref name="left"/> and <paramref name="right"/> are not equal.</returns>
public static bool operator !=(EquatableArray<T> left, EquatableArray<T> right)
{
return !left.Equals(right);
}
}
+1 -37
ファイルの表示
@@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
using Microsoft.CodeAnalysis;
@@ -13,20 +10,8 @@ namespace ComputeSharp.SourceGeneration.Models;
/// </summary>
/// <param name="Descriptor">The wrapped <see cref="DiagnosticDescriptor"/> instance.</param>
/// <param name="Arguments">The diagnostic arguments.</param>
internal sealed record DeferredDiagnosticInfo(DiagnosticDescriptor Descriptor, ImmutableArray<string> Arguments)
internal sealed record DeferredDiagnosticInfo(DiagnosticDescriptor Descriptor, EquatableArray<string> Arguments)
{
/// <inheritdoc/>
public bool Equals(DeferredDiagnosticInfo? obj)
{
return Comparer.Default.Equals(this, obj);
}
/// <inheritdoc/>
public override int GetHashCode()
{
return Comparer.Default.GetHashCode(this);
}
/// <summary>
/// Creates a new <see cref="DeferredDiagnosticInfo"/> instance with the specified parameters.
/// </summary>
@@ -37,25 +22,4 @@ internal sealed record DeferredDiagnosticInfo(DiagnosticDescriptor Descriptor, I
{
return new(descriptor, args.Select(static arg => arg.ToString()).ToImmutableArray());
}
/// <summary>
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="DeferredDiagnosticInfo"/>.
/// </summary>
private sealed class Comparer : Comparer<DeferredDiagnosticInfo, Comparer>
{
/// <inheritdoc/>
protected override void AddToHashCode(ref HashCode hashCode, DeferredDiagnosticInfo obj)
{
hashCode.Add(obj.Descriptor);
hashCode.AddRange(obj.Arguments);
}
/// <inheritdoc/>
protected override bool AreEqual(DeferredDiagnosticInfo x, DeferredDiagnosticInfo y)
{
return
x.Descriptor.Equals(y.Descriptor) &&
x.Arguments.SequenceEqual(y.Arguments);
}
}
}
+1 -45
ファイルの表示
@@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
@@ -16,24 +13,8 @@ namespace ComputeSharp.SourceGeneration.Models;
/// <param name="SyntaxTree">The tree to use as location for the diagnostic, if available.</param>
/// <param name="TextSpan">The span to use as location for the diagnostic.</param>
/// <param name="Arguments">The diagnostic arguments.</param>
internal sealed record DiagnosticInfo(
DiagnosticDescriptor Descriptor,
SyntaxTree? SyntaxTree,
TextSpan TextSpan,
ImmutableArray<string> Arguments)
internal sealed record DiagnosticInfo(DiagnosticDescriptor Descriptor, SyntaxTree? SyntaxTree, TextSpan TextSpan, EquatableArray<string> Arguments)
{
/// <inheritdoc/>
public bool Equals(DiagnosticInfo? obj)
{
return Comparer.Default.Equals(this, obj);
}
/// <inheritdoc/>
public override int GetHashCode()
{
return Comparer.Default.GetHashCode(this);
}
/// <summary>
/// Creates a new <see cref="Diagnostic"/> instance with the state from this model.
/// </summary>
@@ -75,29 +56,4 @@ internal sealed record DiagnosticInfo(
return new(descriptor, location.SourceTree, location.SourceSpan, args.Select(static arg => arg.ToString()).ToImmutableArray());
}
/// <summary>
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="DiagnosticInfo"/>.
/// </summary>
private sealed class Comparer : Comparer<DiagnosticInfo, Comparer>
{
/// <inheritdoc/>
protected override void AddToHashCode(ref HashCode hashCode, DiagnosticInfo obj)
{
hashCode.Add(obj.Descriptor);
hashCode.Add(obj.SyntaxTree);
hashCode.Add(obj.TextSpan);
hashCode.AddRange(obj.Arguments);
}
/// <inheritdoc/>
protected override bool AreEqual(DiagnosticInfo x, DiagnosticInfo y)
{
return
x.Descriptor.Equals(y.Descriptor) &&
x.SyntaxTree == y.SyntaxTree &&
x.TextSpan.Equals(y.TextSpan) &&
x.Arguments.SequenceEqual(y.Arguments);
}
}
}
+1 -41
ファイルの表示
@@ -1,6 +1,3 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
using Microsoft.CodeAnalysis;
@@ -18,7 +15,7 @@ namespace ComputeSharp.SourceGeneration.Models;
/// <param name="FullyQualifiedMetadataName">The fully qualified metadata name for the current type.</param>
/// <param name="Namespace">Gets the namespace for the current type.</param>
/// <param name="Hierarchy">Gets the sequence of type definitions containing the current type.</param>
internal sealed partial record HierarchyInfo(string FilenameHint, string FullyQualifiedMetadataName, string Namespace, ImmutableArray<TypeInfo> Hierarchy)
internal sealed partial record HierarchyInfo(string FilenameHint, string FullyQualifiedMetadataName, string Namespace, EquatableArray<TypeInfo> Hierarchy)
{
/// <summary>
/// Creates a new <see cref="HierarchyInfo"/> instance from a given <see cref="INamedTypeSymbol"/>.
@@ -110,41 +107,4 @@ internal sealed partial record HierarchyInfo(string FilenameHint, string FullyQu
.AddMembers(typeDeclarationSyntax))
.NormalizeWhitespace(eol: "\n");
}
/// <inheritdoc/>
public bool Equals(HierarchyInfo? 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="HierarchyInfo"/>.
/// </summary>
private sealed class Comparer : Comparer<HierarchyInfo, Comparer>
{
/// <inheritdoc/>
protected override void AddToHashCode(ref HashCode hashCode, HierarchyInfo obj)
{
hashCode.Add(obj.FilenameHint);
hashCode.Add(obj.FullyQualifiedMetadataName);
hashCode.Add(obj.Namespace);
hashCode.AddRange(obj.Hierarchy);
}
/// <inheritdoc/>
protected override bool AreEqual(HierarchyInfo x, HierarchyInfo y)
{
return
x.FilenameHint == y.FilenameHint &&
x.FullyQualifiedMetadataName == y.FullyQualifiedMetadataName &&
x.Namespace == y.Namespace &&
x.Hierarchy.SequenceEqual(y.Hierarchy);
}
}
}
+1 -3
ファイルの表示
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Text;
@@ -118,8 +117,7 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
// Output the diagnostics, if any
context.ReportDiagnostics(
shaderInfoWithErrors
.Select(static (item, _) => item.Diagnostcs)
.WithComparer(EqualityComparer<DiagnosticInfo>.Default.ForImmutableArray()));
.Select(static (item, _) => item.Diagnostcs));
// Get the GetDispatchId() info (hierarchy and dispatch id info)
IncrementalValuesProvider<(HierarchyInfo Hierarchy, DispatchIdInfo DispatchId)> dispatchIdInfo =
+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 -2
ファイルの表示
@@ -48,8 +48,7 @@ public sealed partial class ShaderMethodSourceGenerator : IIncrementalGenerator
// Output the diagnostics, if any
context.ReportDiagnostics(
methodInfoWithErrors
.Select(static (item, _) => item.Diagnostcs)
.WithComparer(EqualityComparer<DiagnosticInfo>.Default.ForImmutableArray()));
.Select(static (item, _) => item.Diagnostcs));
// Generate the [ShaderMethodSource] attributes
context.RegisterSourceOutput(methodInfoWithErrors, static (context, item) =>