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);
+5 -4
ファイルの表示
@@ -6,6 +6,7 @@ using System.Linq;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
using ComputeSharp.SourceGeneration.Mappings;
using ComputeSharp.SourceGeneration.Models;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
@@ -42,9 +43,9 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
protected readonly IDictionary<IFieldSymbol, string> ConstantDefinitions;
/// <summary>
/// The collection of produced <see cref="Diagnostic"/> instances.
/// The collection of produced <see cref="DiagnosticInfo"/> instances.
/// </summary>
protected readonly ImmutableArray<Diagnostic>.Builder Diagnostics;
protected readonly ImmutableArray<DiagnosticInfo>.Builder Diagnostics;
/// <summary>
/// Creates a new <see cref="HlslSourceRewriter"/> instance with the specified parameters.
@@ -52,12 +53,12 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
/// <param name="semanticModel">The <see cref="Microsoft.CodeAnalysis.SemanticModel"/> instance for the target syntax tree.</param>
/// <param name="discoveredTypes">The set of discovered custom types.</param>
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
protected HlslSourceRewriter(
SemanticModelProvider semanticModel,
ICollection<INamedTypeSymbol> discoveredTypes,
IDictionary<IFieldSymbol, string> constantDefinitions,
ImmutableArray<Diagnostic>.Builder diagnostics)
ImmutableArray<DiagnosticInfo>.Builder diagnostics)
{
SemanticModel = semanticModel;
DiscoveredTypes = discoveredTypes;
+5 -4
ファイルの表示
@@ -6,6 +6,7 @@ using System.Linq;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
using ComputeSharp.SourceGeneration.Mappings;
using ComputeSharp.SourceGeneration.Models;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
@@ -63,7 +64,7 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter
/// <param name="discoveredTypes">The set of discovered custom types.</param>
/// <param name="staticMethods">The set of discovered and processed static methods.</param>
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
/// <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="isEntryPoint">Whether or not the current instance is processing a shader entry point.</param>
public ShaderSourceRewriter(
INamedTypeSymbol shaderType,
@@ -71,7 +72,7 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter
ICollection<INamedTypeSymbol> discoveredTypes,
IDictionary<IMethodSymbol, MethodDeclarationSyntax> staticMethods,
IDictionary<IFieldSymbol, string> constantDefinitions,
ImmutableArray<Diagnostic>.Builder diagnostics,
ImmutableArray<DiagnosticInfo>.Builder diagnostics,
bool isEntryPoint)
: base(semanticModel, discoveredTypes, constantDefinitions, diagnostics)
{
@@ -89,13 +90,13 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter
/// <param name="discoveredTypes">The set of discovered custom types.</param>
/// <param name="staticMethods">The set of discovered and processed static methods.</param>
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
public ShaderSourceRewriter(
SemanticModelProvider semanticModel,
ICollection<INamedTypeSymbol> discoveredTypes,
IDictionary<IMethodSymbol, MethodDeclarationSyntax> staticMethods,
IDictionary<IFieldSymbol, string> constantDefinitions,
ImmutableArray<Diagnostic>.Builder diagnostics)
ImmutableArray<DiagnosticInfo>.Builder diagnostics)
: base(semanticModel, discoveredTypes, constantDefinitions, diagnostics)
{
this.staticMethods = staticMethods;
+3 -2
ファイルの表示
@@ -6,6 +6,7 @@ using System.Linq;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
using ComputeSharp.SourceGeneration.Mappings;
using ComputeSharp.SourceGeneration.Models;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
@@ -25,12 +26,12 @@ internal sealed partial class StaticFieldRewriter : HlslSourceRewriter
/// <param name="semanticModel">The <see cref="SemanticModelProvider"/> instance for the target syntax tree.</param>
/// <param name="discoveredTypes">The set of discovered custom types.</param>
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
public StaticFieldRewriter(
SemanticModelProvider semanticModel,
ICollection<INamedTypeSymbol> discoveredTypes,
IDictionary<IFieldSymbol, string> constantDefinitions,
ImmutableArray<Diagnostic>.Builder diagnostics)
ImmutableArray<DiagnosticInfo>.Builder diagnostics)
: base(semanticModel, discoveredTypes, constantDefinitions, diagnostics)
{
}
+1
ファイルの表示
@@ -19,6 +19,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Helpers\Comparer{T,TSelf}.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\HashCode.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\SemanticModelProvider.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Models\DeferredDiagnosticInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Models\DiagnosticInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Models\HierarchyInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Models\Result{T}.cs" />
+12 -12
ファイルの表示
@@ -1,5 +1,5 @@
using System.Collections.Immutable;
using System.Linq;
using ComputeSharp.SourceGeneration.Models;
using Microsoft.CodeAnalysis;
namespace ComputeSharp.SourceGeneration.Extensions;
@@ -12,33 +12,33 @@ internal static class DiagnosticsExtensions
/// <summary>
/// Adds a new diagnostics to the target builder.
/// </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="descriptor">The input <see cref="DiagnosticDescriptor"/> for the diagnostics to create.</param>
/// <param name="symbol">The source <see cref="ISymbol"/> to attach the diagnostics to.</param>
/// <param name="args">The optional arguments for the formatted message to include.</param>
public static void Add(
this ImmutableArray<Diagnostic>.Builder diagnostics,
this ImmutableArray<DiagnosticInfo>.Builder diagnostics,
DiagnosticDescriptor descriptor,
ISymbol symbol,
params object[] args)
{
diagnostics.Add(Diagnostic.Create(descriptor, symbol.Locations.FirstOrDefault(), args));
diagnostics.Add(DiagnosticInfo.Create(descriptor, symbol, args));
}
/// <summary>
/// Adds a new diagnostics to the target builder.
/// </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="descriptor">The input <see cref="DiagnosticDescriptor"/> for the diagnostics to create.</param>
/// <param name="node">The source <see cref="SyntaxNode"/> to attach the diagnostics to.</param>
/// <param name="args">The optional arguments for the formatted message to include.</param>
public static void Add(
this ImmutableArray<Diagnostic>.Builder diagnostics,
this ImmutableArray<DiagnosticInfo>.Builder diagnostics,
DiagnosticDescriptor descriptor,
SyntaxNode node,
params object[] args)
{
diagnostics.Add(Diagnostic.Create(descriptor, node.GetLocation(), args));
diagnostics.Add(DiagnosticInfo.Create(descriptor, node, args));
}
/// <summary>
@@ -46,11 +46,11 @@ 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<Diagnostic> diagnostics)
public static void ReportDiagnostics(this IncrementalGeneratorInitializationContext context, IncrementalValuesProvider<DiagnosticInfo> diagnostics)
{
context.RegisterSourceOutput(diagnostics, static (context, diagnostic) =>
{
context.ReportDiagnostic(diagnostic);
context.ReportDiagnostic(diagnostic.ToDiagnostic());
});
}
@@ -59,13 +59,13 @@ 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<Diagnostic>> diagnostics)
public static void ReportDiagnostics(this IncrementalGeneratorInitializationContext context, IncrementalValuesProvider<ImmutableArray<DiagnosticInfo>> diagnostics)
{
context.RegisterSourceOutput(diagnostics, static (context, diagnostics) =>
{
foreach (Diagnostic diagnostic in diagnostics)
foreach (DiagnosticInfo diagnostic in diagnostics)
{
context.ReportDiagnostic(diagnostic);
context.ReportDiagnostic(diagnostic.ToDiagnostic());
}
});
}
+1 -1
ファイルの表示
@@ -22,7 +22,7 @@ internal static class IEqualityComparerExtensions
/// <summary>
/// An <see cref="IEqualityComparer{T}"/> implementation for an <see cref="ImmutableArray{T}"/> value.
/// </summary>
public sealed class Comparer<T> : IEqualityComparer<ImmutableArray<T>>
private sealed class Comparer<T> : IEqualityComparer<ImmutableArray<T>>
{
/// <summary>
/// The <typeparamref name="T"/> comparer.
+55
ファイルの表示
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
using Microsoft.CodeAnalysis;
namespace ComputeSharp.SourceGeneration.Models;
/// <summary>
/// A model for a serializeable diagnostic info to be reconstructed later in a pipeline.
/// </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)
{
/// <inheritdoc/>
public bool Equals(DeferredDiagnosticInfo? obj) => Comparer.Default.Equals(this, obj);
/// <inheritdoc/>
public override int GetHashCode() => Comparer.Default.GetHashCode(this);
/// <summary>
/// Creates a new <see cref="DeferredDiagnosticInfo"/> instance with the specified parameters.
/// </summary>
/// <param name="descriptor">The input <see cref="DiagnosticDescriptor"/> for the diagnostics to create.</param>
/// <param name="args">The optional arguments for the formatted message to include.</param>
/// <returns>A new <see cref="DeferredDiagnosticInfo"/> instance with the specified parameters.</returns>
public static DeferredDiagnosticInfo Create(DiagnosticDescriptor descriptor, params object[] args)
{
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);
}
}
}
+60 -9
ファイルの表示
@@ -1,17 +1,26 @@
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;
namespace ComputeSharp.SourceGeneration.Models;
/// <summary>
/// A model for a serializeable diagnostic provider.
/// A model for a serializeable diagnostic info.
/// </summary>
/// <param name="Descriptor">The wrapped <see cref="DiagnosticDescriptor"/> instance.</param>
/// <param name="Args">The diagnostic args.</param>
internal sealed record DiagnosticInfo(DiagnosticDescriptor Descriptor, params object[] Args)
/// <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)
{
/// <inheritdoc/>
public bool Equals(DiagnosticInfo? obj) => Comparer.Default.Equals(this, obj);
@@ -19,6 +28,48 @@ internal sealed record DiagnosticInfo(DiagnosticDescriptor Descriptor, params ob
/// <inheritdoc/>
public override int GetHashCode() => Comparer.Default.GetHashCode(this);
/// <summary>
/// Creates a new <see cref="Diagnostic"/> instance with the state from this model.
/// </summary>
/// <returns>A new <see cref="Diagnostic"/> instance with the state from this model.</returns>
public Diagnostic ToDiagnostic()
{
if (SyntaxTree is not null)
{
return Diagnostic.Create(Descriptor, Location.Create(SyntaxTree, TextSpan), Arguments.ToArray());
}
return Diagnostic.Create(Descriptor, null, Arguments.ToArray());
}
/// <summary>
/// Creates a new <see cref="DiagnosticInfo"/> instance with the specified parameters.
/// </summary>
/// <param name="descriptor">The input <see cref="DiagnosticDescriptor"/> for the diagnostics to create.</param>
/// <param name="symbol">The source <see cref="ISymbol"/> to attach the diagnostics to.</param>
/// <param name="args">The optional arguments for the formatted message to include.</param>
/// <returns>A new <see cref="DiagnosticInfo"/> instance with the specified parameters.</returns>
public static DiagnosticInfo Create(DiagnosticDescriptor descriptor, ISymbol symbol, params object[] args)
{
Location location = symbol.Locations.First();
return new(descriptor, location.SourceTree, location.SourceSpan, args.Select(static arg => arg.ToString()).ToImmutableArray());
}
/// <summary>
/// Creates a new <see cref="DiagnosticInfo"/> instance with the specified parameters.
/// </summary>
/// <param name="descriptor">The input <see cref="DiagnosticDescriptor"/> for the diagnostics to create.</param>
/// <param name="node">The source <see cref="SyntaxNode"/> to attach the diagnostics to.</param>
/// <param name="args">The optional arguments for the formatted message to include.</param>
/// <returns>A new <see cref="DiagnosticInfo"/> instance with the specified parameters.</returns>
public static DiagnosticInfo Create(DiagnosticDescriptor descriptor, SyntaxNode node, params object[] args)
{
Location location = node.GetLocation();
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>
@@ -28,11 +79,9 @@ internal sealed record DiagnosticInfo(DiagnosticDescriptor Descriptor, params ob
protected override void AddToHashCode(ref HashCode hashCode, DiagnosticInfo obj)
{
hashCode.Add(obj.Descriptor);
foreach (object arg in obj.Args)
{
hashCode.Add(arg);
}
hashCode.Add(obj.SyntaxTree);
hashCode.Add(obj.TextSpan);
hashCode.AddRange(obj.Arguments);
}
/// <inheritdoc/>
@@ -40,7 +89,9 @@ internal sealed record DiagnosticInfo(DiagnosticDescriptor Descriptor, params ob
{
return
x.Descriptor.Equals(y.Descriptor) &&
x.Args.SequenceEqual(y.Args);
x.SyntaxTree == y.SyntaxTree &&
x.TextSpan.Equals(y.TextSpan) &&
x.Arguments.SequenceEqual(y.Arguments);
}
}
}
+1 -2
ファイルの表示
@@ -1,5 +1,4 @@
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
namespace ComputeSharp.SourceGeneration.Models;
@@ -9,4 +8,4 @@ namespace ComputeSharp.SourceGeneration.Models;
/// <typeparam name="TValue">The type of the wrapped value.</typeparam>
/// <param name="Value">The wrapped value for the current result.</param>
/// <param name="Errors">The associated diagnostic errors, if any.</param>
internal sealed record Result<TValue>(TValue Value, ImmutableArray<Diagnostic> Errors);
internal sealed record Result<TValue>(TValue Value, ImmutableArray<DiagnosticInfo> Errors);
+15 -14
ファイルの表示
@@ -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 ComputeSharp.SourceGenerators.Models;
using ComputeSharp.SourceGenerators.SyntaxRewriters;
@@ -39,9 +40,9 @@ partial class IShaderGenerator
Compilation compilation,
StructDeclarationSyntax structDeclaration,
INamedTypeSymbol structDeclarationSymbol,
out ImmutableArray<Diagnostic> diagnostics)
out ImmutableArray<DiagnosticInfo> diagnostics)
{
ImmutableArray<Diagnostic>.Builder builder = ImmutableArray.CreateBuilder<Diagnostic>();
ImmutableArray<DiagnosticInfo>.Builder builder = ImmutableArray.CreateBuilder<DiagnosticInfo>();
// Detect invalid properties
DetectAndReportInvalidPropertyDeclarations(builder, structDeclarationSymbol);
@@ -94,7 +95,7 @@ partial class IShaderGenerator
/// <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="isComputeShader">Indicates whether or not <paramref name="structDeclarationSymbol"/> represents a compute shader.</param>
@@ -103,7 +104,7 @@ partial class IShaderGenerator
ImmutableArray<(string MetadataName, string Name, string HlslType)>,
ImmutableArray<(string Name, string HlslType)>)
GetInstanceFields(
ImmutableArray<Diagnostic>.Builder diagnostics,
ImmutableArray<DiagnosticInfo>.Builder diagnostics,
INamedTypeSymbol structDeclarationSymbol,
ICollection<INamedTypeSymbol> types,
bool isComputeShader)
@@ -186,7 +187,7 @@ partial class IShaderGenerator
/// <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>
@@ -194,7 +195,7 @@ partial class IShaderGenerator
/// <param name="constantDefinitions">The collection of discovered constant definitions.</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,
@@ -256,12 +257,12 @@ partial class IShaderGenerator
/// <summary>
/// Gets a sequence of captured members 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>
/// <returns>A sequence of captured members in <paramref name="structDeclarationSymbol"/>.</returns>
private static ImmutableArray<(string Name, string Type, int? Count)> GetSharedBuffers(
ImmutableArray<Diagnostic>.Builder diagnostics,
ImmutableArray<DiagnosticInfo>.Builder diagnostics,
INamedTypeSymbol structDeclarationSymbol,
ICollection<INamedTypeSymbol> types)
{
@@ -312,7 +313,7 @@ partial class IShaderGenerator
/// <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>
@@ -322,7 +323,7 @@ partial class IShaderGenerator
/// <param name="isComputeShader">Indicates whether or not <paramref name="structDeclarationSymbol"/> represents a compute shader.</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, bool IsSamplerUser) GetProcessedMethods(
ImmutableArray<Diagnostic>.Builder diagnostics,
ImmutableArray<DiagnosticInfo>.Builder diagnostics,
StructDeclarationSyntax structDeclaration,
INamedTypeSymbol structDeclarationSymbol,
SemanticModelProvider semanticModel,
@@ -441,10 +442,10 @@ partial class IShaderGenerator
/// </summary>
/// <param name="types">The sequence of discovered custom types.</param>
/// <param name="sourceSymbol">The symbol for the current object being processed.</param>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
/// <returns>A sequence of custom type definitions to add to the shader source.</returns>
internal static ImmutableArray<(string Name, string Definition)> GetDeclaredTypes(
ImmutableArray<Diagnostic>.Builder diagnostics,
ImmutableArray<DiagnosticInfo>.Builder diagnostics,
ISymbol sourceSymbol,
IEnumerable<INamedTypeSymbol> types)
{
@@ -503,9 +504,9 @@ partial class IShaderGenerator
/// <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())
{
+5 -5
ファイルの表示
@@ -42,9 +42,9 @@ partial class IShaderGenerator
INamedTypeSymbol structDeclarationSymbol,
bool isDynamicShader,
bool supportsDynamicShaders,
out ImmutableArray<Diagnostic> diagnostics)
out ImmutableArray<DiagnosticInfo> diagnostics)
{
ImmutableArray<Diagnostic>.Builder builder = ImmutableArray.CreateBuilder<Diagnostic>();
ImmutableArray<DiagnosticInfo>.Builder builder = ImmutableArray.CreateBuilder<DiagnosticInfo>();
AttributeData? attribute = structDeclarationSymbol
.GetAttributes()
@@ -149,7 +149,7 @@ partial class IShaderGenerator
ThreadIdsInfo threadIds,
string hlslSource,
CancellationToken token,
out DiagnosticInfo? diagnostic)
out DeferredDiagnosticInfo? diagnostic)
{
ImmutableArray<byte> bytecode = ImmutableArray<byte>.Empty;
@@ -189,11 +189,11 @@ partial class IShaderGenerator
}
catch (Win32Exception e)
{
diagnostic = new DiagnosticInfo(EmbeddedBytecodeFailedWithWin32Exception, e.HResult, FixupExceptionMessage(e.Message));
diagnostic = DeferredDiagnosticInfo.Create(EmbeddedBytecodeFailedWithWin32Exception, e.HResult, FixupExceptionMessage(e.Message));
}
catch (DxcCompilationException e)
{
diagnostic = new DiagnosticInfo(EmbeddedBytecodeFailedWithDxcCompilationException, FixupExceptionMessage(e.Message));
diagnostic = DeferredDiagnosticInfo.Create(EmbeddedBytecodeFailedWithDxcCompilationException, FixupExceptionMessage(e.Message));
}
End:
+3 -2
ファイルの表示
@@ -6,6 +6,7 @@ using System.Runtime.CompilerServices;
using ComputeSharp.Core.Helpers;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Mappings;
using ComputeSharp.SourceGeneration.Models;
using ComputeSharp.SourceGenerators.Models;
using Microsoft.CodeAnalysis;
using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors;
@@ -34,7 +35,7 @@ partial class IShaderGenerator
Type shaderInterfaceType,
out int resourceCount,
out int root32BitConstantCount,
out ImmutableArray<Diagnostic> diagnostics)
out ImmutableArray<DiagnosticInfo> diagnostics)
{
// Helper method that uses boxes instead of ref-s (illegal in enumerators)
static IEnumerable<FieldInfo> GetCapturedFieldInfos(
@@ -87,7 +88,7 @@ partial class IShaderGenerator
}
}
ImmutableArray<Diagnostic>.Builder builder = ImmutableArray.CreateBuilder<Diagnostic>();
ImmutableArray<DiagnosticInfo>.Builder builder = ImmutableArray.CreateBuilder<DiagnosticInfo>();
// Setup the resource and byte offsets for tracking. Pixel shaders have only two
// implicitly captured int values, as they're always dispatched over a 2D texture.
+8 -11
ファイルの表示
@@ -88,7 +88,7 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
item.Left.Left.Type,
out int resourceCount,
out int root32BitConstantCount,
out ImmutableArray<Diagnostic> dispatchDataDiagnostics);
out ImmutableArray<DiagnosticInfo> dispatchDataDiagnostics);
token.ThrowIfCancellationRequested();
@@ -106,7 +106,7 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
item.Right,
item.Left.Left.Syntax,
item.Left.Left.Symbol,
out ImmutableArray<Diagnostic> hlslSourceDiagnostics);
out ImmutableArray<DiagnosticInfo> hlslSourceDiagnostics);
token.ThrowIfCancellationRequested();
@@ -115,7 +115,7 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
item.Left.Left.Symbol,
!hlslSourceInfo.Delegates.IsEmpty,
item.Left.Right,
out ImmutableArray<Diagnostic> threadIdsDiagnostics);
out ImmutableArray<DiagnosticInfo> threadIdsDiagnostics);
token.ThrowIfCancellationRequested();
@@ -206,11 +206,11 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
.Select(static (item, token) => (item.Dispatch.Hierarchy, BuildHlslSource.GetNonDynamicHlslSource(item.Hlsl), item.ThreadIds));
// 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) =>
{
ImmutableArray<byte> bytecode = LoadBytecode.GetBytecode(item.ThreadIds, item.Hlsl, token, out DiagnosticInfo? diagnostic);
ImmutableArray<byte> bytecode = LoadBytecode.GetBytecode(item.ThreadIds, item.Hlsl, token, out DeferredDiagnosticInfo? diagnostic);
token.ThrowIfCancellationRequested();
@@ -224,7 +224,7 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
});
// 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)
@@ -232,11 +232,8 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
.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
+5 -5
ファイルの表示
@@ -46,7 +46,7 @@ public sealed partial class ShaderMethodSourceGenerator : IIncrementalGenerator
item.Right,
item.Left.Syntax,
item.Left.Symbol,
out ImmutableArray<Diagnostic> diagnostics);
out ImmutableArray<DiagnosticInfo> diagnostics);
return new Result<HlslMethodSourceInfo>(sourceInfo, diagnostics);
});
@@ -85,9 +85,9 @@ public sealed partial class ShaderMethodSourceGenerator : IIncrementalGenerator
Compilation compilation,
CSharpSyntaxNode methodDeclaration,
IMethodSymbol methodSymbol,
out ImmutableArray<Diagnostic> diagnostics)
out ImmutableArray<DiagnosticInfo> diagnostics)
{
ImmutableArray<Diagnostic>.Builder builder = ImmutableArray.CreateBuilder<Diagnostic>();
ImmutableArray<DiagnosticInfo>.Builder builder = ImmutableArray.CreateBuilder<DiagnosticInfo>();
// We need to sets to track all discovered custom types and static methods
HashSet<INamedTypeSymbol> discoveredTypes = new(SymbolEqualityComparer.Default);
@@ -112,14 +112,14 @@ public sealed partial class ShaderMethodSourceGenerator : IIncrementalGenerator
/// <summary>
/// Gets a sequence of processed methods from a target method declaration.
/// </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="methodDeclaration">The <see cref="MethodDeclarationSyntax"/> or <see cref="LocalFunctionStatementSyntax"/> instance for the current method.</param>
/// <param name="semanticModel">The <see cref="SemanticModelProvider"/> instance for the method to process.</param>
/// <param name="discoveredTypes">The collection of currently discovered types.</param>
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
/// <returns>A sequence of processed methods in <paramref name="methodDeclaration"/> (main method and all captured methods).</returns>
private static (string TargetMethod, ImmutableArray<(string Signature, string Definition)> DependentMethods) GetProcessedMethods(
ImmutableArray<Diagnostic>.Builder diagnostics,
ImmutableArray<DiagnosticInfo>.Builder diagnostics,
CSharpSyntaxNode methodDeclaration,
SemanticModelProvider semanticModel,
ICollection<INamedTypeSymbol> discoveredTypes,