Remove leftover diagnostics from D2D generator
このコミットが含まれているのは:
1 親
a22b6e4b7b
コミット
130f30f3a0
2ファイル変更
+5
-78
検索条件に一致するファイルはありません
+5
-76
@@ -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
|
||||
/// <summary>
|
||||
/// Extracts the resource texture descriptions for the current shader.
|
||||
/// </summary>
|
||||
/// <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(
|
||||
ImmutableArrayBuilder<DiagnosticInfo> diagnostics,
|
||||
INamedTypeSymbol structDeclarationSymbol,
|
||||
int inputCount,
|
||||
out ImmutableArray<ResourceTextureDescription> resourceTextureDescriptions)
|
||||
{
|
||||
using ImmutableArrayBuilder<(int? Index, int Rank)> resourceTextureInfos = new();
|
||||
using ImmutableArrayBuilder<ResourceTextureDescription> builder = new();
|
||||
|
||||
foreach (IFieldSymbol fieldSymbol in structDeclarationSymbol.GetMembers().OfType<IFieldSymbol>())
|
||||
foreach (ISymbol memberSymbol in structDeclarationSymbol.GetMembers().OfType<IFieldSymbol>())
|
||||
{
|
||||
// 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<ResourceTextureDescription> 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<bool> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,9 +109,7 @@ public sealed partial class D2DPixelShaderDescriptorGenerator : IIncrementalGene
|
||||
|
||||
// Get the resource texture info for ResourceTextureDescriptions
|
||||
ResourceTextureDescriptions.GetInfo(
|
||||
diagnostics,
|
||||
typeSymbol,
|
||||
inputCount,
|
||||
out ImmutableArray<ResourceTextureDescription> resourceTextureDescriptions);
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする