Add support for NaN/infinity constants for float/double

このコミットが含まれているのは:
Sergio Pedri committed 2022-04-24 21:04:33 +02:00
1 親 b27c89acc0
コミット 14fa96998f
8ファイル変更
+151 -1

検索条件に一致するファイルはありません

@@ -11,6 +11,7 @@
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Extensions\StringExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\SyntaxNodeExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Mappings\HlslKnownFields.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Mappings\HlslKnownKeywords.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Mappings\HlslKnownMethods.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Mappings\HlslKnownProperties.cs" />
+44
ファイルの表示
@@ -0,0 +1,44 @@
using System.Collections.Generic;
namespace ComputeSharp.SourceGeneration.Mappings;
/// <summary>
/// A <see langword="class"/> that contains and maps known HLSL field names to common .NET fields.
/// </summary>
internal static partial class HlslKnownFields
{
/// <summary>
/// The mapping of supported known fields to HLSL names.
/// </summary>
private static readonly IReadOnlyDictionary<string, string> KnownFields = BuildKnownFieldsMap();
/// <summary>
/// Builds the mapping of supported known fields to HLSL names.
/// </summary>
private static IReadOnlyDictionary<string, string> BuildKnownFieldsMap()
{
Dictionary<string, string> 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;
}
/// <summary>
/// Tries to get the mapped HLSL-compatible field name for the input field name.
/// </summary>
/// <param name="name">The input fully qualified field name.</param>
/// <param name="mapped">The mapped name, if one is found.</param>
/// <returns>The HLSL-compatible field name that can be used in an HLSL shader.</returns>
public static bool TryGetMappedName(string name, out string? mapped)
{
return KnownFields.TryGetValue(name, out mapped);
}
}
+1 -1
ファイルの表示
@@ -9,7 +9,7 @@ using System.Text.RegularExpressions;
namespace ComputeSharp.SourceGeneration.Mappings;
/// <summary>
/// A <see langword="class"/> that contains and maps known HLSL properties names to common .NET members.
/// A <see langword="class"/> that contains and maps known HLSL properties names to common .NET properties.
/// </summary>
internal static partial class HlslKnownProperties
{