Refactor diagnostic models to be properly equatable

このコミットが含まれているのは:
Sergio Pedri committed 2022-09-17 17:58:44 +02:00
1 親 bdaf402a4c
コミット 9eac3c779d
26ファイル変更
+247 -134

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

+11 -11
ファイルの表示
@@ -26,10 +26,10 @@ partial class D2DPixelShaderSourceGenerator
/// <summary>
/// Validates that the return type of the annotated method is valid and returns the type name.
/// </summary>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
/// <param name="methodSymbol">The input <see cref="IMethodSymbol"/> instance to process.</param>
/// <returns>The HLSL source to compile, if present.</returns>
public static string? GetInvalidReturnType(ImmutableArray<Diagnostic>.Builder diagnostics, IMethodSymbol methodSymbol)
public static string? GetInvalidReturnType(ImmutableArray<DiagnosticInfo>.Builder diagnostics, IMethodSymbol methodSymbol)
{
if (!(methodSymbol.ReturnType is INamedTypeSymbol
{
@@ -55,10 +55,10 @@ partial class D2DPixelShaderSourceGenerator
/// <summary>
/// Extracts the HLSL source from a method with the <see cref="D2DPixelShaderSourceAttribute"/> annotation.
/// </summary>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
/// <param name="methodSymbol">The input <see cref="IMethodSymbol"/> instance to process.</param>
/// <returns>The HLSL source to compile, if present.</returns>
public static string GetHlslSource(ImmutableArray<Diagnostic>.Builder diagnostics, IMethodSymbol methodSymbol)
public static string GetHlslSource(ImmutableArray<DiagnosticInfo>.Builder diagnostics, IMethodSymbol methodSymbol)
{
_ = methodSymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DPixelShaderSourceAttribute", out AttributeData? attributeData);
@@ -77,10 +77,10 @@ partial class D2DPixelShaderSourceGenerator
/// <summary>
/// Extracts the shader profile for a target method, if present.
/// </summary>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
/// <param name="methodSymbol">The input <see cref="IMethodSymbol"/> instance to process.</param>
/// <returns>The shader profile to use to compile the shader, if present.</returns>
public static D2D1ShaderProfile GetShaderProfile(ImmutableArray<Diagnostic>.Builder diagnostics, IMethodSymbol methodSymbol)
public static D2D1ShaderProfile GetShaderProfile(ImmutableArray<DiagnosticInfo>.Builder diagnostics, IMethodSymbol methodSymbol)
{
if (methodSymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DShaderProfileAttribute", out AttributeData? attributeData))
{
@@ -104,10 +104,10 @@ partial class D2DPixelShaderSourceGenerator
/// <summary>
/// Extracts the compile options for the current shader.
/// </summary>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
/// <param name="methodSymbol">The input <see cref="IMethodSymbol"/> instance to process.</param>
/// <returns>The compile options to use to compile the shader, if present.</returns>
public static D2D1CompileOptions GetCompileOptions(ImmutableArray<Diagnostic>.Builder diagnostics, IMethodSymbol methodSymbol)
public static D2D1CompileOptions GetCompileOptions(ImmutableArray<DiagnosticInfo>.Builder diagnostics, IMethodSymbol methodSymbol)
{
if (methodSymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DCompileOptionsAttribute", out AttributeData? attributeData))
{
@@ -135,7 +135,7 @@ partial class D2DPixelShaderSourceGenerator
/// <param name="token">The <see cref="CancellationToken"/> used to cancel the operation, if needed.</param>
/// <param name="diagnostic">The resulting diagnostic from the processing operation, if any.</param>
/// <returns>The <see cref="ImmutableArray{T}"/> instance with the compiled shader bytecode.</returns>
public static unsafe ImmutableArray<byte> GetBytecode(HlslShaderMethodSourceInfo sourceInfo, CancellationToken token, out DiagnosticInfo? diagnostic)
public static unsafe ImmutableArray<byte> GetBytecode(HlslShaderMethodSourceInfo sourceInfo, CancellationToken token, out DeferredDiagnosticInfo? diagnostic)
{
ImmutableArray<byte> bytecode = ImmutableArray<byte>.Empty;
@@ -169,7 +169,7 @@ partial class D2DPixelShaderSourceGenerator
}
catch (Win32Exception e)
{
diagnostic = new DiagnosticInfo(
diagnostic = DeferredDiagnosticInfo.Create(
D2DPixelShaderSourceCompilationFailedWithWin32Exception,
sourceInfo.MethodName,
e.HResult,
@@ -177,7 +177,7 @@ partial class D2DPixelShaderSourceGenerator
}
catch (FxcCompilationException e)
{
diagnostic = new DiagnosticInfo(
diagnostic = DeferredDiagnosticInfo.Create(
D2DPixelShaderSourceCompilationFailedWithFxcCompilationException,
sourceInfo.MethodName,
ID2D1ShaderGenerator.LoadBytecode.FixupExceptionMessage(e.Message));
+11 -10
ファイルの表示
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using ComputeSharp.D2D1.SourceGenerators.Models;
@@ -31,7 +32,7 @@ public sealed partial class D2DPixelShaderSourceGenerator : IIncrementalGenerato
MethodDeclarationSyntax methodDeclaration = (MethodDeclarationSyntax)context.TargetNode;
IMethodSymbol methodSymbol = (IMethodSymbol)context.TargetSymbol;
ImmutableArray<Diagnostic>.Builder diagnostics = ImmutableArray.CreateBuilder<Diagnostic>();
ImmutableArray<DiagnosticInfo>.Builder diagnostics = ImmutableArray.CreateBuilder<DiagnosticInfo>();
// Get the processed HLSL first and check for cancellation
string hlslSource = Execute.GetHlslSource(diagnostics, methodSymbol);
@@ -59,17 +60,20 @@ public sealed partial class D2DPixelShaderSourceGenerator : IIncrementalGenerato
});
// Output the diagnostics
context.ReportDiagnostics(shaderInfoWithErrors.Select(static (item, _) => item.Diagnostcs));
context.ReportDiagnostics(
shaderInfoWithErrors
.Select(static (item, _) => item.Diagnostcs)
.WithComparer(EqualityComparer<DiagnosticInfo>.Default.ForImmutableArray()));
// Compile the requested shader bytecodes
IncrementalValuesProvider<(HierarchyInfo Hierarchy, EmbeddedBytecodeMethodInfo BytecodeInfo, DiagnosticInfo? Diagnostic)> embeddedBytecodeWithErrors =
IncrementalValuesProvider<(HierarchyInfo Hierarchy, EmbeddedBytecodeMethodInfo BytecodeInfo, DeferredDiagnosticInfo? Diagnostic)> embeddedBytecodeWithErrors =
shaderInfoWithErrors
.Select(static (item, token) =>
{
ImmutableArray<byte> bytecode = Execute.GetBytecode(
item.HlslShaderMethodSource,
token,
out DiagnosticInfo? diagnostic);
out DeferredDiagnosticInfo? diagnostic);
token.ThrowIfCancellationRequested();
@@ -84,7 +88,7 @@ public sealed partial class D2DPixelShaderSourceGenerator : IIncrementalGenerato
});
// Gather the diagnostics
IncrementalValuesProvider<Diagnostic> embeddedBytecodeDiagnostics =
IncrementalValuesProvider<DiagnosticInfo> embeddedBytecodeDiagnostics =
embeddedBytecodeWithErrors
.Select(static (item, token) => (item.Hierarchy.FullyQualifiedMetadataName, item.Diagnostic))
.Where(static item => item.Diagnostic is not null)
@@ -92,11 +96,8 @@ public sealed partial class D2DPixelShaderSourceGenerator : IIncrementalGenerato
.Select(static (item, token) =>
{
INamedTypeSymbol typeSymbol = item.Right.GetTypeByMetadataName(item.Left.FullyQualifiedMetadataName)!;
return Diagnostic.Create(
item.Left.Diagnostic!.Descriptor,
typeSymbol.Locations.FirstOrDefault(),
new object[] { typeSymbol }.Concat(item.Left.Diagnostic.Args).ToArray());
return DiagnosticInfo.Create(item.Left.Diagnostic!.Descriptor, typeSymbol, new object[] { typeSymbol }.Concat(item.Left.Diagnostic.Arguments).ToArray());
});
// Output the diagnostics
@@ -39,7 +39,7 @@ public sealed class InvalidD2DResourceTextureIndexUseAnalyzer : DiagnosticAnalyz
{
Diagnostic diagnostic = Diagnostic.Create(
InvalidD2DResourceTextureIndexAttributeUse,
fieldSymbol.Locations.FirstOrDefault(),
fieldSymbol.Locations.First(),
fieldSymbol.Name,
fieldSymbol.ContainingType,
fieldSymbol.Type);
@@ -6,6 +6,7 @@ using System.Text;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
using ComputeSharp.SourceGeneration.Mappings;
using ComputeSharp.SourceGeneration.Models;
using ComputeSharp.SourceGeneration.SyntaxRewriters;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
@@ -28,7 +29,7 @@ partial class ID2D1ShaderGenerator
/// <summary>
/// Gathers all necessary information on a transpiled HLSL source for a given shader type.
/// </summary>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
/// <param name="compilation">The input <see cref="Compilation"/> object currently in use.</param>
/// <param name="structDeclaration">The <see cref="StructDeclarationSyntax"/> node to process.</param>
/// <param name="structDeclarationSymbol">The <see cref="INamedTypeSymbol"/> for <paramref name="structDeclaration"/>.</param>
@@ -37,7 +38,7 @@ partial class ID2D1ShaderGenerator
/// <param name="inputComplexIndices">The indicess of the complex shader inputs.</param>
/// <returns>The HLSL source for the shader.</returns>
public static string GetHlslSource(
ImmutableArray<Diagnostic>.Builder diagnostics,
ImmutableArray<DiagnosticInfo>.Builder diagnostics,
Compilation compilation,
StructDeclarationSyntax structDeclaration,
INamedTypeSymbol structDeclarationSymbol,
@@ -94,13 +95,13 @@ partial class ID2D1ShaderGenerator
/// <summary>
/// Gets a sequence of captured fields and their mapped names.
/// </summary>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
/// <param name="types">The collection of currently discovered types.</param>
/// <param name="valueFields">The sequence of captured fields in <paramref name="structDeclarationSymbol"/>.</param>
/// <param name="resourceTextureFields">The sequence of captured resource textures in <paramref name="structDeclarationSymbol"/>.</param>
private static void GetInstanceFields(
ImmutableArray<Diagnostic>.Builder diagnostics,
ImmutableArray<DiagnosticInfo>.Builder diagnostics,
INamedTypeSymbol structDeclarationSymbol,
ICollection<INamedTypeSymbol> types,
out ImmutableArray<(string Name, string HlslType)> valueFields,
@@ -182,7 +183,7 @@ partial class ID2D1ShaderGenerator
/// <summary>
/// Gets a sequence of shader static fields and their mapped names.
/// </summary>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
/// <param name="semanticModel">The <see cref="SemanticModelProvider"/> instance for the type to process.</param>
/// <param name="structDeclaration">The <see cref="StructDeclarationSyntax"/> instance for the current type.</param>
/// <param name="structDeclarationSymbol">The type symbol for the shader type.</param>
@@ -191,7 +192,7 @@ partial class ID2D1ShaderGenerator
/// <param name="needsD2D1RequiresScenePosition">Whether or not the shader needs the <c>[D2DRequiresScenePosition]</c> annotation.</param>
/// <returns>A sequence of static constant fields in <paramref name="structDeclarationSymbol"/>.</returns>
private static ImmutableArray<(string Name, string TypeDeclaration, string? Assignment)> GetStaticFields(
ImmutableArray<Diagnostic>.Builder diagnostics,
ImmutableArray<DiagnosticInfo>.Builder diagnostics,
SemanticModelProvider semanticModel,
StructDeclarationSyntax structDeclaration,
INamedTypeSymbol structDeclarationSymbol,
@@ -251,7 +252,7 @@ partial class ID2D1ShaderGenerator
/// <summary>
/// Gets a sequence of processed methods declared within a given type.
/// </summary>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
/// <param name="structDeclarationSymbol">The type symbol for the shader type.</param>
/// <param name="structDeclaration">The <see cref="StructDeclarationSyntax"/> instance for the current type.</param>
/// <param name="semanticModel">The <see cref="SemanticModelProvider"/> instance for the type to process.</param>
@@ -261,7 +262,7 @@ partial class ID2D1ShaderGenerator
/// <param name="needsD2D1RequiresScenePosition">Whether or not the shader needs the <c>[D2DRequiresScenePosition]</c> annotation.</param>
/// <returns>A sequence of processed methods in <paramref name="structDeclaration"/>, and the entry point.</returns>
private static (string EntryPoint, ImmutableArray<(string Signature, string Definition)> Methods) GetProcessedMethods(
ImmutableArray<Diagnostic>.Builder diagnostics,
ImmutableArray<DiagnosticInfo>.Builder diagnostics,
StructDeclarationSyntax structDeclaration,
INamedTypeSymbol structDeclarationSymbol,
SemanticModelProvider semanticModel,
@@ -370,12 +371,12 @@ partial class ID2D1ShaderGenerator
/// <summary>
/// Gets the sequence of processed discovered custom types.
/// </summary>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
/// <param name="structDeclarationSymbol">The type symbol for the shader type.</param>
/// <param name="types">The sequence of discovered custom types.</param>
/// <returns>A sequence of custom type definitions to add to the shader source.</returns>
private static ImmutableArray<(string Name, string Definition)> GetDeclaredTypes(
ImmutableArray<Diagnostic>.Builder diagnostics,
ImmutableArray<DiagnosticInfo>.Builder diagnostics,
INamedTypeSymbol structDeclarationSymbol,
IEnumerable<INamedTypeSymbol> types)
{
@@ -434,9 +435,9 @@ partial class ID2D1ShaderGenerator
/// <summary>
/// Finds and reports all invalid declared properties in a shader.
/// </summary>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
private static void DetectAndReportInvalidPropertyDeclarations(ImmutableArray<Diagnostic>.Builder diagnostics, INamedTypeSymbol structDeclarationSymbol)
private static void DetectAndReportInvalidPropertyDeclarations(ImmutableArray<DiagnosticInfo>.Builder diagnostics, INamedTypeSymbol structDeclarationSymbol)
{
foreach (var memberSymbol in structDeclarationSymbol.GetMembers())
{
@@ -457,12 +458,12 @@ partial class ID2D1ShaderGenerator
/// <summary>
/// Reports diagnostics for invalid uses of <c>[D2DRequiresScenePosition]</c> in a shader.
/// </summary>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
/// <param name="requiresScenePosition">Whether the shader type is declaring the need for scene position.</param>
/// <param name="usesPositionDependentMethods">Whether the shader is using APIs that rely on scene position.</param>
private static void ReportInvalidD2DRequiresScenePositionUse(
ImmutableArray<Diagnostic>.Builder diagnostics,
ImmutableArray<DiagnosticInfo>.Builder diagnostics,
INamedTypeSymbol structDeclarationSymbol,
bool requiresScenePosition,
bool usesPositionDependentMethods)
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Models;
using Microsoft.CodeAnalysis;
using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors;
@@ -19,14 +20,14 @@ partial class ID2D1ShaderGenerator
/// <summary>
/// Extracts the input info for the current shader.
/// </summary>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
/// <param name="inputCount">The number of shader inputs to declare.</param>
/// <param name="inputSimpleIndices">The indicess of the simple shader inputs.</param>
/// <param name="inputComplexIndices">The indices of the complex shader inputs.</param>
/// <param name="combinedInputTypes">The combined and serialized input types for each available input.</param>
public static void GetInfo(
ImmutableArray<Diagnostic>.Builder diagnostics,
ImmutableArray<DiagnosticInfo>.Builder diagnostics,
INamedTypeSymbol structDeclarationSymbol,
out int inputCount,
out ImmutableArray<int> inputSimpleIndices,
@@ -48,10 +48,10 @@ partial class ID2D1ShaderGenerator
/// <summary>
/// Extracts the compile options for the current shader.
/// </summary>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
/// <returns>The compile options to use to compile the shader, if present.</returns>
public static D2D1CompileOptions? GetCompileOptions(ImmutableArray<Diagnostic>.Builder diagnostics, INamedTypeSymbol structDeclarationSymbol)
public static D2D1CompileOptions? GetCompileOptions(ImmutableArray<DiagnosticInfo>.Builder diagnostics, INamedTypeSymbol structDeclarationSymbol)
{
if (structDeclarationSymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DCompileOptionsAttribute", out AttributeData? attributeData))
{
@@ -123,7 +123,7 @@ partial class ID2D1ShaderGenerator
HlslShaderSourceInfo sourceInfo,
CancellationToken token,
out D2D1CompileOptions options,
out DiagnosticInfo? diagnostic)
out DeferredDiagnosticInfo? diagnostic)
{
ImmutableArray<byte> bytecode = ImmutableArray<byte>.Empty;
@@ -165,12 +165,12 @@ partial class ID2D1ShaderGenerator
catch (Win32Exception e)
{
options = default;
diagnostic = new DiagnosticInfo(EmbeddedBytecodeFailedWithWin32Exception, e.HResult, FixupExceptionMessage(e.Message));
diagnostic = DeferredDiagnosticInfo.Create(EmbeddedBytecodeFailedWithWin32Exception, e.HResult, FixupExceptionMessage(e.Message));
}
catch (FxcCompilationException e)
{
options = default;
diagnostic = new DiagnosticInfo(EmbeddedBytecodeFailedWithFxcCompilationException, FixupExceptionMessage(e.Message));
diagnostic = DeferredDiagnosticInfo.Create(EmbeddedBytecodeFailedWithFxcCompilationException, FixupExceptionMessage(e.Message));
}
End:
@@ -7,6 +7,7 @@ using ComputeSharp.Core.Helpers;
using ComputeSharp.D2D1.SourceGenerators.Models;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Mappings;
using ComputeSharp.SourceGeneration.Models;
using Microsoft.CodeAnalysis;
using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors;
@@ -23,12 +24,12 @@ partial class ID2D1ShaderGenerator
/// <summary>
/// Explores a given type hierarchy and generates statements to load fields.
/// </summary>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
/// <param name="structDeclarationSymbol">The current shader type being explored.</param>
/// <param name="constantBufferSizeInBytes">The size of the shader constant buffer.</param>
/// <returns>The sequence of <see cref="FieldInfo"/> instances for all captured resources and values.</returns>
public static ImmutableArray<FieldInfo> GetInfo(
ImmutableArray<Diagnostic>.Builder diagnostics,
ImmutableArray<DiagnosticInfo>.Builder diagnostics,
ITypeSymbol structDeclarationSymbol,
out int constantBufferSizeInBytes)
{
@@ -4,6 +4,7 @@ using System.Collections.Immutable;
using System.Linq;
using ComputeSharp.D2D1.SourceGenerators.Models;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Models;
using Microsoft.CodeAnalysis;
using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors;
@@ -20,11 +21,11 @@ partial class ID2D1ShaderGenerator
/// <summary>
/// Extracts the input descriptions for the current shader.
/// </summary>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
/// <param name="inputDescriptions">The produced input descriptions for the shader.</param>
public static void GetInfo(
ImmutableArray<Diagnostic>.Builder diagnostics,
ImmutableArray<DiagnosticInfo>.Builder diagnostics,
INamedTypeSymbol structDeclarationSymbol,
out ImmutableArray<InputDescription> inputDescriptions)
{
@@ -4,6 +4,7 @@ using System.Linq;
using ComputeSharp.D2D1.SourceGenerators.Models;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Mappings;
using ComputeSharp.SourceGeneration.Models;
using Microsoft.CodeAnalysis;
using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors;
@@ -20,12 +21,12 @@ partial class ID2D1ShaderGenerator
/// <summary>
/// Extracts the resource texture descriptions for the current shader.
/// </summary>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
/// <param name="inputCount">The number of inputs for the shader.</param>
/// <param name="resourceTextureDescriptions">The produced resource texture descriptions for the shader.</param>
public static void GetInfo(
ImmutableArray<Diagnostic>.Builder diagnostics,
ImmutableArray<DiagnosticInfo>.Builder diagnostics,
INamedTypeSymbol structDeclarationSymbol,
int inputCount,
out ImmutableArray<ResourceTextureDescription> resourceTextureDescriptions)
+11 -10
ファイルの表示
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Text;
@@ -41,7 +42,7 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
return default;
}
ImmutableArray<Diagnostic>.Builder diagnostics = ImmutableArray.CreateBuilder<Diagnostic>();
ImmutableArray<DiagnosticInfo>.Builder diagnostics = ImmutableArray.CreateBuilder<DiagnosticInfo>();
// LoadDispatchData() info
ImmutableArray<FieldInfo> fieldInfos = LoadDispatchData.GetInfo(
@@ -130,7 +131,10 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
compilation.HasAccessibleTypeWithMetadataName("System.Runtime.CompilerServices.SkipLocalsInitAttribute"));
// Output the diagnostics
context.ReportDiagnostics(shaderInfoWithErrors.Select(static (item, _) => item.Diagnostcs));
context.ReportDiagnostics(
shaderInfoWithErrors
.Select(static (item, _) => item.Diagnostcs)
.WithComparer(EqualityComparer<DiagnosticInfo>.Default.ForImmutableArray()));
// Get the GetInputCount() info (hierarchy and input count)
IncrementalValuesProvider<(HierarchyInfo Hierarchy, int InputCount)> inputCountInfo =
@@ -217,7 +221,7 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
.Select(static (item, _) => (item.Hierarchy, item.HlslShaderSource));
// Compile the requested shader bytecodes
IncrementalValuesProvider<(HierarchyInfo Hierarchy, EmbeddedBytecodeInfo BytecodeInfo, DiagnosticInfo? Diagnostic)> embeddedBytecodeWithErrors =
IncrementalValuesProvider<(HierarchyInfo Hierarchy, EmbeddedBytecodeInfo BytecodeInfo, DeferredDiagnosticInfo? Diagnostic)> embeddedBytecodeWithErrors =
shaderBytecodeInfo
.Select(static (item, token) =>
{
@@ -225,7 +229,7 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
item.Source,
token,
out D2D1CompileOptions options,
out DiagnosticInfo? diagnostic);
out DeferredDiagnosticInfo? diagnostic);
token.ThrowIfCancellationRequested();
@@ -239,7 +243,7 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
});
// Gather the diagnostics
IncrementalValuesProvider<Diagnostic> embeddedBytecodeDiagnostics =
IncrementalValuesProvider<DiagnosticInfo> embeddedBytecodeDiagnostics =
embeddedBytecodeWithErrors
.Select(static (item, _) => (item.Hierarchy.FullyQualifiedMetadataName, item.Diagnostic))
.Where(static item => item.Diagnostic is not null)
@@ -247,11 +251,8 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
.Select(static (item, _) =>
{
INamedTypeSymbol typeSymbol = item.Right.GetTypeByMetadataName(item.Left.FullyQualifiedMetadataName)!;
return Diagnostic.Create(
item.Left.Diagnostic!.Descriptor,
typeSymbol.Locations.FirstOrDefault(),
new object[] { typeSymbol }.Concat(item.Left.Diagnostic.Args).ToArray());
return DiagnosticInfo.Create(item.Left.Diagnostic!.Descriptor, typeSymbol, new object[] { typeSymbol }.Concat(item.Left.Diagnostic.Arguments).ToArray());
});
// Output the diagnostics
+1 -2
ファイルの表示
@@ -4,7 +4,6 @@ using System.Collections.Immutable;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
using ComputeSharp.SourceGeneration.Models;
using Microsoft.CodeAnalysis;
namespace ComputeSharp.D2D1.SourceGenerators.Models;
@@ -17,7 +16,7 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models;
internal sealed record D2D1PixelShaderSourceInfo(
HierarchyInfo Hierarchy,
HlslShaderMethodSourceInfo HlslShaderMethodSource,
ImmutableArray<Diagnostic> Diagnostcs)
ImmutableArray<DiagnosticInfo> Diagnostcs)
{
/// <inheritdoc/>
public bool Equals(D2D1PixelShaderSourceInfo? obj) => Comparer.Default.Equals(this, obj);
+1 -2
ファイルの表示
@@ -4,7 +4,6 @@ using System.Collections.Immutable;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
using ComputeSharp.SourceGeneration.Models;
using Microsoft.CodeAnalysis;
namespace ComputeSharp.D2D1.SourceGenerators.Models;
@@ -29,7 +28,7 @@ internal sealed record D2D1ShaderInfo(
OutputBufferInfo OutputBuffer,
InputDescriptionsInfo InputDescriptions,
D2D1PixelOptions PixelOptions,
ImmutableArray<Diagnostic> Diagnostcs)
ImmutableArray<DiagnosticInfo> Diagnostcs)
{
/// <inheritdoc/>
public bool Equals(D2D1ShaderInfo? obj) => Comparer.Default.Equals(this, obj);