using System.Collections.Generic;
namespace ComputeSharp.SourceGeneration.Mappings;
///
/// A that contains and maps known HLSL field names to common .NET fields.
///
internal static partial class HlslKnownFields
{
///
/// The mapping of supported known fields to HLSL names.
///
private static readonly IReadOnlyDictionary KnownFields = BuildKnownFieldsMap();
///
/// Builds the mapping of supported known fields to HLSL names.
///
private static IReadOnlyDictionary BuildKnownFieldsMap()
{
Dictionary knownMembers = new()
{
[$"float.{nameof(float.NaN)}"] = "asfloat(0xFFC00000)",
[$"float.{nameof(float.PositiveInfinity)}"] = "asfloat(0x7F800000)",
[$"float.{nameof(float.NegativeInfinity)}"] = "asfloat(0xFF800000)",
[$"double.{nameof(double.NaN)}"] = "asdouble(0x00000000, 0xFFF80000)",
[$"double.{nameof(double.PositiveInfinity)}"] = "asdouble(0x00000000, 0x7FF00000)",
[$"double.{nameof(double.NegativeInfinity)}"] = "asdouble(0x00000000, 0xFFF00000)"
};
return knownMembers;
}
///
/// Tries to get the mapped HLSL-compatible field name for the input field name.
///
/// The input fully qualified field name.
/// The mapped name, if one is found.
/// The HLSL-compatible field name that can be used in an HLSL shader.
public static bool TryGetMappedName(string name, out string? mapped)
{
return KnownFields.TryGetValue(name, out mapped);
}
}