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 PixelOptions property.
///
private static class PixelOptions
{
///
/// Extracts the pixel options for the current shader.
///
/// The input instance to process.
/// The pixel options for the shader.
public static void GetInfo(INamedTypeSymbol structDeclarationSymbol, out D2D1PixelOptions pixelOptions)
{
if (structDeclarationSymbol.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DPixelOptionsAttribute", out AttributeData? attributeData))
{
pixelOptions = (D2D1PixelOptions)attributeData.ConstructorArguments[0].Value!;
}
else
{
pixelOptions = D2D1PixelOptions.None;
}
}
///
/// Writes the PixelOptions property.
///
/// The input instance with gathered shader info.
/// The instance to write into.
public static void WriteSyntax(D2D1ShaderInfo info, IndentedTextWriter writer)
{
// Set the right expression if the pixel options are valid
string pixelOptionsExpression = (info.PixelOptions is D2D1PixelOptions.None or D2D1PixelOptions.TrivialSampling) switch
{
true => $"global::ComputeSharp.D2D1.D2D1PixelOptions.{info.PixelOptions}",
false => "default"
};
writer.WriteLine("/// ");
writer.WriteGeneratedAttributes(GeneratorName);
writer.WriteLine($"static ComputeSharp.D2D1.D2D1PixelOptions global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.PixelOptions => {pixelOptionsExpression};");
}
}
}