From 3ae80f1698de90b0aaa49638e0800996509a709c Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 1 Jan 2024 23:34:17 +0100 Subject: [PATCH] Remove diagnostics from D2D input descriptions generator --- ...erDescriptorGenerator.InputDescriptions.cs | 74 ++----------------- .../D2DPixelShaderDescriptorGenerator.cs | 1 - 2 files changed, 7 insertions(+), 68 deletions(-) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.InputDescriptions.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.InputDescriptions.cs index c03b4bf2..462591b2 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.InputDescriptions.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.InputDescriptions.cs @@ -1,11 +1,8 @@ -using System; using System.Collections.Immutable; using ComputeSharp.D2D1.SourceGenerators.Models; using ComputeSharp.SourceGeneration.Extensions; using ComputeSharp.SourceGeneration.Helpers; -using ComputeSharp.SourceGeneration.Models; using Microsoft.CodeAnalysis; -using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors; namespace ComputeSharp.D2D1.SourceGenerators; @@ -20,85 +17,28 @@ partial class D2DPixelShaderDescriptorGenerator /// /// Extracts the input descriptions for the current shader. /// - /// The collection of produced instances. /// The input instance to process. /// The produced input descriptions for the shader. public static void GetInfo( - ImmutableArrayBuilder diagnostics, INamedTypeSymbol structDeclarationSymbol, out ImmutableArray inputDescriptions) { - int inputCount = 0; - - using ImmutableArrayBuilder inputDescriptionsBuilder = new(); + using ImmutableArrayBuilder builder = new(); foreach (AttributeData attributeData in structDeclarationSymbol.GetAttributes()) { - using ImmutableArrayBuilder builder = new(); - - attributeData.AttributeClass?.AppendFullyQualifiedMetadataName(in builder); - - switch (builder.WrittenSpan) + if (attributeData.AttributeClass?.HasFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DInputDescriptionAttribute") == true) { - case "ComputeSharp.D2D1.D2DInputCountAttribute": - inputCount = (int)attributeData.ConstructorArguments[0].Value!; - break; - case "ComputeSharp.D2D1.D2DInputDescriptionAttribute": - if (attributeData.ConstructorArguments.Length == 2) - { - int index = (int)attributeData.ConstructorArguments[0].Value!; - D2D1Filter filter = (D2D1Filter)attributeData.ConstructorArguments[1].Value!; + int index = (int)attributeData.ConstructorArguments[0].Value!; + D2D1Filter filter = (D2D1Filter)attributeData.ConstructorArguments[1].Value!; - _ = attributeData.TryGetNamedArgument("LevelOfDetailCount", out int levelOfDetailCount); + _ = attributeData.TryGetNamedArgument("LevelOfDetailCount", out int levelOfDetailCount); - inputDescriptionsBuilder.Add(new InputDescription(index, filter, levelOfDetailCount)); - } - - break; - default: - break; + builder.Add(new InputDescription(index, filter, levelOfDetailCount)); } } - inputDescriptions = ImmutableArray.Empty; - - // Validate the input count (ignore if invalid, this will be validated by GetInputType() generator) - if (inputCount is not (>= 0 and <= 8)) - { - return; - } - - // All simple indices must be in range - foreach (InputDescription inputDescription in inputDescriptionsBuilder.WrittenSpan) - { - if (inputDescription.Index >= inputCount) - { - diagnostics.Add(OutOfRangeInputDescriptionIndex, structDeclarationSymbol, structDeclarationSymbol); - - return; - } - } - - Span selectedInputDescriptionIndices = stackalloc bool[8]; - - selectedInputDescriptionIndices.Clear(); - - // All input description indices must be unique - foreach (InputDescription inputDescription in inputDescriptionsBuilder.WrittenSpan) - { - ref bool isInputDescriptionIndexUsed = ref selectedInputDescriptionIndices[inputDescription.Index]; - - if (isInputDescriptionIndexUsed) - { - diagnostics.Add(RepeatedD2DInputDescriptionIndices, structDeclarationSymbol, structDeclarationSymbol); - - return; - } - - isInputDescriptionIndexUsed = true; - } - - inputDescriptions = inputDescriptionsBuilder.ToImmutable(); + inputDescriptions = builder.ToImmutable(); } } } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.cs index 290a7733..85c6317f 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.cs @@ -132,7 +132,6 @@ public sealed partial class D2DPixelShaderDescriptorGenerator : IIncrementalGene // Get the info for InputDescriptions InputDescriptions.GetInfo( - diagnostics, typeSymbol, out ImmutableArray inputDescriptions);