#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".g.cs"#>
using ComputeSharp.Core.Intrinsics.Attributes;
#pragma warning disable IDE0022
namespace ComputeSharp;
///
partial class Hlsl
{
<#
List<(string Type, List<(string Source, string Target)> Info)> intrinsics = new List<(string, List<(string, string)>)>();
// Prepare the intrinsic names
foreach (var type in new[] { "Float", "Double", "Int", "UInt" })
{
List<(string Source, string Target)> typeNames = new List<(string, string)>();
typeNames.Add((type.ToLower(), "bool"));
// Vector types
for (int i = 2; i <= 4; i++)
{
typeNames.Add(($"{type}{i}", $"Bool{i}"));
}
// Matrix types
for (int i = 1; i <= 4; i++)
{
for (int j = 1; j <= 4; j++)
{
typeNames.Add(($"{type}{i}x{j}", $"Bool{i}x{j}"));
}
}
intrinsics.Add((type, typeNames));
}
// Numeric to bool
foreach (var intrinsic in intrinsics)
{
int index = 0;
foreach (var pair in intrinsic.Info)
{
if (index++ != 0) WriteLine("");
#>
///
/// Converts the input value into a value (non-zero elements map to , zero elements map to ).
///
/// The input value.
/// The converted value.
/// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.
[HlslIntrinsicName("<#=pair.Target.ToLower()#>", RequiresParametersMatching = true)]
public static <#=pair.Target#> <#=intrinsic.Type#>ToBool(<#=pair.Source#> x) => default;
<#
}
}
// Bool to numeric
foreach (var intrinsic in intrinsics)
{
foreach (var pair in intrinsic.Info)
{
WriteLine("");
#>
///
/// Converts the input value into a value ( elements map to 1, map to 0).
///
/// The input value.
/// The converted value.
/// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.
[HlslIntrinsicName("<#=pair.Source.ToLower()#>", RequiresParametersMatching = true)]
public static <#=pair.Source#> BoolTo<#=intrinsic.Type#>(<#=pair.Target#> x) => default;
<#
}
}
#>
}