From 130f30f3a07bb54630239bf9be83aa12af02e316 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 30 Dec 2023 23:58:31 +0100 Subject: [PATCH] Remove leftover diagnostics from D2D generator --- ...orGenerator.ResourceTextureDescriptions.cs | 81 ++----------------- .../D2DPixelShaderDescriptorGenerator.cs | 2 - 2 files changed, 5 insertions(+), 78 deletions(-) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.ResourceTextureDescriptions.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.ResourceTextureDescriptions.cs index ca0c4849..b5f5a68e 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.ResourceTextureDescriptions.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.ResourceTextureDescriptions.cs @@ -1,12 +1,9 @@ -using System; using System.Collections.Immutable; using ComputeSharp.D2D1.SourceGenerators.Models; using ComputeSharp.SourceGeneration.Extensions; using ComputeSharp.SourceGeneration.Helpers; using ComputeSharp.SourceGeneration.Mappings; -using ComputeSharp.SourceGeneration.Models; using Microsoft.CodeAnalysis; -using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors; namespace ComputeSharp.D2D1.SourceGenerators; @@ -21,23 +18,19 @@ partial class D2DPixelShaderDescriptorGenerator /// /// Extracts the resource texture descriptions for the current shader. /// - /// The collection of produced instances. /// The input instance to process. - /// The number of inputs for the shader. /// The produced resource texture descriptions for the shader. public static void GetInfo( - ImmutableArrayBuilder diagnostics, INamedTypeSymbol structDeclarationSymbol, - int inputCount, out ImmutableArray resourceTextureDescriptions) { - using ImmutableArrayBuilder<(int? Index, int Rank)> resourceTextureInfos = new(); + using ImmutableArrayBuilder builder = new(); - foreach (IFieldSymbol fieldSymbol in structDeclarationSymbol.GetMembers().OfType()) + foreach (ISymbol memberSymbol in structDeclarationSymbol.GetMembers().OfType()) { // Only look for fields of a named type symbol (diagnostics is emitted by the HLSL rewriter if it's not the case). // We're only looking for instance fields of unmanaged types in this case (as resource textures are structs). - if (fieldSymbol is not { IsStatic: false, Type: INamedTypeSymbol { IsUnmanagedType: true, IsGenericType: true } typeSymbol }) + if (memberSymbol is not IFieldSymbol { IsStatic: false, Type: INamedTypeSymbol { IsUnmanagedType: true, IsGenericType: true } typeSymbol } fieldSymbol) { continue; } @@ -63,76 +56,12 @@ partial class D2DPixelShaderDescriptorGenerator index = resourceIndex; } } - else - { - // If the attribute is missing, emit a diagnostic - diagnostics.Add(MissingD2DResourceTextureIndexAttribute, fieldSymbol, fieldSymbol.Name, structDeclarationSymbol); - } - resourceTextureInfos.Add((index, rank)); + builder.Add(new ResourceTextureDescription(index ?? 0, rank)); } } - // Extract the resource texture descriptions for the rest of the pipeline - using (ImmutableArrayBuilder resourceTextureDescriptionsBuilder = new()) - { - foreach ((int? index, int rank) in resourceTextureInfos.WrittenSpan) - { - resourceTextureDescriptionsBuilder.Add(new ResourceTextureDescription(index ?? 0, rank)); - } - - resourceTextureDescriptions = resourceTextureDescriptionsBuilder.ToImmutable(); - } - - // If the input count is invalid, do nothing and avoid emitting potentially incorrect - // diagnostics based on the resource texture indices with respect to the input count. - // The GetInputType() generator has already emitted diagnostic for this error, so this - // generator can just wait for users to go back and fix that issue before proceeding. - if (inputCount is not (>= 0 and <= 8)) - { - return; - } - - // Validate that the resource texture indices don't overlap with the shader inputs - foreach ((int? index, _) in resourceTextureInfos.WrittenSpan) - { - if (index < inputCount) - { - diagnostics.Add(ResourceTextureIndexOverlappingWithInputIndex, structDeclarationSymbol, structDeclarationSymbol); - - return; - } - } - - // Validate that no resource texture has an index greater than or equal to 16 - foreach ((int? index, _) in resourceTextureInfos.WrittenSpan) - { - if (index >= 16) - { - diagnostics.Add(OutOfRangeResourceTextureIndex, structDeclarationSymbol, structDeclarationSymbol); - - return; - } - } - - Span selectedResourceTextureIndices = stackalloc bool[16]; - - selectedResourceTextureIndices.Clear(); - - // All input description indices must be unique (also take this path for invalid indices) - foreach ((int? index, _) in resourceTextureInfos.WrittenSpan) - { - ref bool isResourceTextureIndexUsed = ref selectedResourceTextureIndices[index ?? 0]; - - if (isResourceTextureIndexUsed) - { - diagnostics.Add(RepeatedD2DResourceTextureIndices, structDeclarationSymbol, structDeclarationSymbol); - - return; - } - - isResourceTextureIndexUsed = true; - } + resourceTextureDescriptions = 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 2bf72336..2afaaf07 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.cs @@ -109,9 +109,7 @@ public sealed partial class D2DPixelShaderDescriptorGenerator : IIncrementalGene // Get the resource texture info for ResourceTextureDescriptions ResourceTextureDescriptions.GetInfo( - diagnostics, typeSymbol, - inputCount, out ImmutableArray resourceTextureDescriptions); token.ThrowIfCancellationRequested();