using System.Collections.Immutable;
using ComputeSharp.D2D1.SourceGenerators.Models;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
using Microsoft.CodeAnalysis;
namespace ComputeSharp.D2D1.SourceGenerators;
///
partial class D2DPixelShaderDescriptorGenerator
{
///
/// A helper with all logic to generate the InputDescriptions property.
///
private static partial class InputDescriptions
{
///
/// Extracts the input descriptions for the current shader.
///
/// The input instance to process.
/// The produced input descriptions for the shader.
public static void GetInfo(
INamedTypeSymbol structDeclarationSymbol,
out ImmutableArray inputDescriptions)
{
using ImmutableArrayBuilder builder = new();
foreach (AttributeData attributeData in structDeclarationSymbol.GetAttributes())
{
if (attributeData.AttributeClass?.HasFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DInputDescriptionAttribute") == true)
{
int index = (int)attributeData.ConstructorArguments[0].Value!;
D2D1Filter filter = (D2D1Filter)attributeData.ConstructorArguments[1].Value!;
_ = attributeData.TryGetNamedArgument("LevelOfDetailCount", out int levelOfDetailCount);
builder.Add(new InputDescription(index, filter, levelOfDetailCount));
}
}
inputDescriptions = builder.ToImmutable();
}
}
}