diff --git a/src/ComputeSharp.Core.NetStandard/ComputeSharp.Core.NetStandard.projitems b/src/ComputeSharp.Core.NetStandard/ComputeSharp.Core.NetStandard.projitems index 22578e69..c73e175d 100644 --- a/src/ComputeSharp.Core.NetStandard/ComputeSharp.Core.NetStandard.projitems +++ b/src/ComputeSharp.Core.NetStandard/ComputeSharp.Core.NetStandard.projitems @@ -12,6 +12,7 @@ + diff --git a/src/ComputeSharp.NetStandard/System/Runtime/CompilerServices/IsExternalInit.cs b/src/ComputeSharp.Core.NetStandard/System/Runtime.CompilerServices/IsExternalInit.cs similarity index 100% rename from src/ComputeSharp.NetStandard/System/Runtime/CompilerServices/IsExternalInit.cs rename to src/ComputeSharp.Core.NetStandard/System/Runtime.CompilerServices/IsExternalInit.cs diff --git a/src/ComputeSharp.Core.SourceGenerators/ComputeSharp.Core.SourceGenerators.csproj b/src/ComputeSharp.Core.SourceGenerators/ComputeSharp.Core.SourceGenerators.csproj index 4c8fc75c..41726b30 100644 --- a/src/ComputeSharp.Core.SourceGenerators/ComputeSharp.Core.SourceGenerators.csproj +++ b/src/ComputeSharp.Core.SourceGenerators/ComputeSharp.Core.SourceGenerators.csproj @@ -16,8 +16,8 @@ and to match members based on full name, so the types being in the generator assembly are not an issue.--> - - + + diff --git a/src/ComputeSharp.Core.SourceGenerators/System.Runtime.CompilerServices/IsExternalInit.cs b/src/ComputeSharp.Core.SourceGenerators/System.Runtime.CompilerServices/IsExternalInit.cs deleted file mode 100644 index a914bf06..00000000 --- a/src/ComputeSharp.Core.SourceGenerators/System.Runtime.CompilerServices/IsExternalInit.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.ComponentModel; - -namespace System.Runtime.CompilerServices; - -/// -/// Reserved to be used by the compiler for tracking metadata. -/// This class should not be used by developers in source code. -/// -[EditorBrowsable(EditorBrowsableState.Never)] -internal static class IsExternalInit -{ -} diff --git a/src/ComputeSharp.Core/ComputeSharp.Core.csproj b/src/ComputeSharp.Core/ComputeSharp.Core.csproj index 23c797b5..f95c4771 100644 --- a/src/ComputeSharp.Core/ComputeSharp.Core.csproj +++ b/src/ComputeSharp.Core/ComputeSharp.Core.csproj @@ -22,208 +22,17 @@ + - + + %(Filename).g.cs + TextTemplatingFileGenerator + + + $([System.IO.Path]::GetFileNameWithoutExtension('%(Filename)')).tt True True - Hlsl.Void.tt - - True - True - Hlsl.tt - - - True - True - Bool2.tt - - - True - True - Bool3.tt - - - True - True - Bool4.tt - - - True - True - BoolMxN.tt - - - True - True - Double2.tt - - - True - True - Double3.tt - - - True - True - Double4.tt - - - True - True - DoubleMxN.tt - - - True - True - Float2.tt - - - True - True - Float3.tt - - - True - True - Float4.tt - - - True - True - FloatMxN.tt - - - True - True - Int2.tt - - - True - True - Int3.tt - - - True - True - Int4.tt - - - True - True - IntMxN.tt - - - True - True - UInt2.tt - - - True - True - UInt3.tt - - - True - True - UInt4.tt - - - True - True - UIntMxN.tt - - - - - - TextTemplatingFileGenerator - Hlsl.Void.g.cs - - - TextTemplatingFileGenerator - Hlsl.g.cs - - - TextTemplatingFileGenerator - Bool2.g.cs - - - TextTemplatingFileGenerator - Bool3.g.cs - - - TextTemplatingFileGenerator - Bool4.g.cs - - - TextTemplatingFileGenerator - BoolMxN.g.cs - - - TextTemplatingFileGenerator - Double2.g.cs - - - TextTemplatingFileGenerator - Double3.g.cs - - - TextTemplatingFileGenerator - Double4.g.cs - - - TextTemplatingFileGenerator - DoubleMxN.g.cs - - - TextTemplatingFileGenerator - Float2.g.cs - - - TextTemplatingFileGenerator - Float3.g.cs - - - TextTemplatingFileGenerator - Float4.g.cs - - - TextTemplatingFileGenerator - FloatMxN.g.cs - - - TextTemplatingFileGenerator - Int2.g.cs - - - TextTemplatingFileGenerator - Int3.g.cs - - - TextTemplatingFileGenerator - Int4.g.cs - - - TextTemplatingFileGenerator - IntMxN.g.cs - - - TextTemplatingFileGenerator - UInt2.g.cs - - - TextTemplatingFileGenerator - UInt3.g.cs - - - TextTemplatingFileGenerator - UInt4.g.cs - - - TextTemplatingFileGenerator - UIntMxN.g.cs - diff --git a/src/ComputeSharp.Core/Intrinsics/Attributes/HlslIntrinsicNameAttribute.cs b/src/ComputeSharp.Core/Intrinsics/Attributes/HlslIntrinsicNameAttribute.cs index d85e1295..5a5b0df5 100644 --- a/src/ComputeSharp.Core/Intrinsics/Attributes/HlslIntrinsicNameAttribute.cs +++ b/src/ComputeSharp.Core/Intrinsics/Attributes/HlslIntrinsicNameAttribute.cs @@ -23,4 +23,9 @@ internal sealed class HlslIntrinsicNameAttribute : Attribute /// Gets the name of the HLSL intrinsic. /// public string Name { get; } + + /// + /// Gets whether or not matching parameters is also required to extract the name of this intrinsic. + /// + public bool RequiresParametersMatching { get; init; } } diff --git a/src/ComputeSharp.Core/Intrinsics/Hlsl.Casts.g.cs b/src/ComputeSharp.Core/Intrinsics/Hlsl.Casts.g.cs new file mode 100644 index 00000000..937ed920 --- /dev/null +++ b/src/ComputeSharp.Core/Intrinsics/Hlsl.Casts.g.cs @@ -0,0 +1,1444 @@ +using ComputeSharp.Core.Intrinsics.Attributes; + +namespace ComputeSharp; + +/// +partial class Hlsl +{ + /// + /// 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("bool", RequiresParametersMatching = true)] + public static bool FloatToBool(float x) => default; + + /// + /// 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("bool2", RequiresParametersMatching = true)] + public static Bool2 FloatToBool(Float2 x) => default; + + /// + /// 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("bool3", RequiresParametersMatching = true)] + public static Bool3 FloatToBool(Float3 x) => default; + + /// + /// 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("bool4", RequiresParametersMatching = true)] + public static Bool4 FloatToBool(Float4 x) => default; + + /// + /// 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("bool1x1", RequiresParametersMatching = true)] + public static Bool1x1 FloatToBool(Float1x1 x) => default; + + /// + /// 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("bool1x2", RequiresParametersMatching = true)] + public static Bool1x2 FloatToBool(Float1x2 x) => default; + + /// + /// 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("bool1x3", RequiresParametersMatching = true)] + public static Bool1x3 FloatToBool(Float1x3 x) => default; + + /// + /// 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("bool1x4", RequiresParametersMatching = true)] + public static Bool1x4 FloatToBool(Float1x4 x) => default; + + /// + /// 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("bool2x1", RequiresParametersMatching = true)] + public static Bool2x1 FloatToBool(Float2x1 x) => default; + + /// + /// 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("bool2x2", RequiresParametersMatching = true)] + public static Bool2x2 FloatToBool(Float2x2 x) => default; + + /// + /// 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("bool2x3", RequiresParametersMatching = true)] + public static Bool2x3 FloatToBool(Float2x3 x) => default; + + /// + /// 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("bool2x4", RequiresParametersMatching = true)] + public static Bool2x4 FloatToBool(Float2x4 x) => default; + + /// + /// 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("bool3x1", RequiresParametersMatching = true)] + public static Bool3x1 FloatToBool(Float3x1 x) => default; + + /// + /// 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("bool3x2", RequiresParametersMatching = true)] + public static Bool3x2 FloatToBool(Float3x2 x) => default; + + /// + /// 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("bool3x3", RequiresParametersMatching = true)] + public static Bool3x3 FloatToBool(Float3x3 x) => default; + + /// + /// 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("bool3x4", RequiresParametersMatching = true)] + public static Bool3x4 FloatToBool(Float3x4 x) => default; + + /// + /// 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("bool4x1", RequiresParametersMatching = true)] + public static Bool4x1 FloatToBool(Float4x1 x) => default; + + /// + /// 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("bool4x2", RequiresParametersMatching = true)] + public static Bool4x2 FloatToBool(Float4x2 x) => default; + + /// + /// 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("bool4x3", RequiresParametersMatching = true)] + public static Bool4x3 FloatToBool(Float4x3 x) => default; + + /// + /// 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("bool4x4", RequiresParametersMatching = true)] + public static Bool4x4 FloatToBool(Float4x4 x) => default; + /// + /// 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("bool", RequiresParametersMatching = true)] + public static bool DoubleToBool(double x) => default; + + /// + /// 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("bool2", RequiresParametersMatching = true)] + public static Bool2 DoubleToBool(Double2 x) => default; + + /// + /// 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("bool3", RequiresParametersMatching = true)] + public static Bool3 DoubleToBool(Double3 x) => default; + + /// + /// 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("bool4", RequiresParametersMatching = true)] + public static Bool4 DoubleToBool(Double4 x) => default; + + /// + /// 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("bool1x1", RequiresParametersMatching = true)] + public static Bool1x1 DoubleToBool(Double1x1 x) => default; + + /// + /// 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("bool1x2", RequiresParametersMatching = true)] + public static Bool1x2 DoubleToBool(Double1x2 x) => default; + + /// + /// 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("bool1x3", RequiresParametersMatching = true)] + public static Bool1x3 DoubleToBool(Double1x3 x) => default; + + /// + /// 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("bool1x4", RequiresParametersMatching = true)] + public static Bool1x4 DoubleToBool(Double1x4 x) => default; + + /// + /// 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("bool2x1", RequiresParametersMatching = true)] + public static Bool2x1 DoubleToBool(Double2x1 x) => default; + + /// + /// 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("bool2x2", RequiresParametersMatching = true)] + public static Bool2x2 DoubleToBool(Double2x2 x) => default; + + /// + /// 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("bool2x3", RequiresParametersMatching = true)] + public static Bool2x3 DoubleToBool(Double2x3 x) => default; + + /// + /// 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("bool2x4", RequiresParametersMatching = true)] + public static Bool2x4 DoubleToBool(Double2x4 x) => default; + + /// + /// 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("bool3x1", RequiresParametersMatching = true)] + public static Bool3x1 DoubleToBool(Double3x1 x) => default; + + /// + /// 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("bool3x2", RequiresParametersMatching = true)] + public static Bool3x2 DoubleToBool(Double3x2 x) => default; + + /// + /// 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("bool3x3", RequiresParametersMatching = true)] + public static Bool3x3 DoubleToBool(Double3x3 x) => default; + + /// + /// 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("bool3x4", RequiresParametersMatching = true)] + public static Bool3x4 DoubleToBool(Double3x4 x) => default; + + /// + /// 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("bool4x1", RequiresParametersMatching = true)] + public static Bool4x1 DoubleToBool(Double4x1 x) => default; + + /// + /// 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("bool4x2", RequiresParametersMatching = true)] + public static Bool4x2 DoubleToBool(Double4x2 x) => default; + + /// + /// 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("bool4x3", RequiresParametersMatching = true)] + public static Bool4x3 DoubleToBool(Double4x3 x) => default; + + /// + /// 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("bool4x4", RequiresParametersMatching = true)] + public static Bool4x4 DoubleToBool(Double4x4 x) => default; + /// + /// 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("bool", RequiresParametersMatching = true)] + public static bool IntToBool(int x) => default; + + /// + /// 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("bool2", RequiresParametersMatching = true)] + public static Bool2 IntToBool(Int2 x) => default; + + /// + /// 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("bool3", RequiresParametersMatching = true)] + public static Bool3 IntToBool(Int3 x) => default; + + /// + /// 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("bool4", RequiresParametersMatching = true)] + public static Bool4 IntToBool(Int4 x) => default; + + /// + /// 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("bool1x1", RequiresParametersMatching = true)] + public static Bool1x1 IntToBool(Int1x1 x) => default; + + /// + /// 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("bool1x2", RequiresParametersMatching = true)] + public static Bool1x2 IntToBool(Int1x2 x) => default; + + /// + /// 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("bool1x3", RequiresParametersMatching = true)] + public static Bool1x3 IntToBool(Int1x3 x) => default; + + /// + /// 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("bool1x4", RequiresParametersMatching = true)] + public static Bool1x4 IntToBool(Int1x4 x) => default; + + /// + /// 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("bool2x1", RequiresParametersMatching = true)] + public static Bool2x1 IntToBool(Int2x1 x) => default; + + /// + /// 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("bool2x2", RequiresParametersMatching = true)] + public static Bool2x2 IntToBool(Int2x2 x) => default; + + /// + /// 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("bool2x3", RequiresParametersMatching = true)] + public static Bool2x3 IntToBool(Int2x3 x) => default; + + /// + /// 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("bool2x4", RequiresParametersMatching = true)] + public static Bool2x4 IntToBool(Int2x4 x) => default; + + /// + /// 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("bool3x1", RequiresParametersMatching = true)] + public static Bool3x1 IntToBool(Int3x1 x) => default; + + /// + /// 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("bool3x2", RequiresParametersMatching = true)] + public static Bool3x2 IntToBool(Int3x2 x) => default; + + /// + /// 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("bool3x3", RequiresParametersMatching = true)] + public static Bool3x3 IntToBool(Int3x3 x) => default; + + /// + /// 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("bool3x4", RequiresParametersMatching = true)] + public static Bool3x4 IntToBool(Int3x4 x) => default; + + /// + /// 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("bool4x1", RequiresParametersMatching = true)] + public static Bool4x1 IntToBool(Int4x1 x) => default; + + /// + /// 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("bool4x2", RequiresParametersMatching = true)] + public static Bool4x2 IntToBool(Int4x2 x) => default; + + /// + /// 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("bool4x3", RequiresParametersMatching = true)] + public static Bool4x3 IntToBool(Int4x3 x) => default; + + /// + /// 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("bool4x4", RequiresParametersMatching = true)] + public static Bool4x4 IntToBool(Int4x4 x) => default; + /// + /// 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("bool", RequiresParametersMatching = true)] + public static bool UIntToBool(uint x) => default; + + /// + /// 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("bool2", RequiresParametersMatching = true)] + public static Bool2 UIntToBool(UInt2 x) => default; + + /// + /// 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("bool3", RequiresParametersMatching = true)] + public static Bool3 UIntToBool(UInt3 x) => default; + + /// + /// 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("bool4", RequiresParametersMatching = true)] + public static Bool4 UIntToBool(UInt4 x) => default; + + /// + /// 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("bool1x1", RequiresParametersMatching = true)] + public static Bool1x1 UIntToBool(UInt1x1 x) => default; + + /// + /// 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("bool1x2", RequiresParametersMatching = true)] + public static Bool1x2 UIntToBool(UInt1x2 x) => default; + + /// + /// 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("bool1x3", RequiresParametersMatching = true)] + public static Bool1x3 UIntToBool(UInt1x3 x) => default; + + /// + /// 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("bool1x4", RequiresParametersMatching = true)] + public static Bool1x4 UIntToBool(UInt1x4 x) => default; + + /// + /// 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("bool2x1", RequiresParametersMatching = true)] + public static Bool2x1 UIntToBool(UInt2x1 x) => default; + + /// + /// 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("bool2x2", RequiresParametersMatching = true)] + public static Bool2x2 UIntToBool(UInt2x2 x) => default; + + /// + /// 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("bool2x3", RequiresParametersMatching = true)] + public static Bool2x3 UIntToBool(UInt2x3 x) => default; + + /// + /// 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("bool2x4", RequiresParametersMatching = true)] + public static Bool2x4 UIntToBool(UInt2x4 x) => default; + + /// + /// 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("bool3x1", RequiresParametersMatching = true)] + public static Bool3x1 UIntToBool(UInt3x1 x) => default; + + /// + /// 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("bool3x2", RequiresParametersMatching = true)] + public static Bool3x2 UIntToBool(UInt3x2 x) => default; + + /// + /// 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("bool3x3", RequiresParametersMatching = true)] + public static Bool3x3 UIntToBool(UInt3x3 x) => default; + + /// + /// 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("bool3x4", RequiresParametersMatching = true)] + public static Bool3x4 UIntToBool(UInt3x4 x) => default; + + /// + /// 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("bool4x1", RequiresParametersMatching = true)] + public static Bool4x1 UIntToBool(UInt4x1 x) => default; + + /// + /// 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("bool4x2", RequiresParametersMatching = true)] + public static Bool4x2 UIntToBool(UInt4x2 x) => default; + + /// + /// 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("bool4x3", RequiresParametersMatching = true)] + public static Bool4x3 UIntToBool(UInt4x3 x) => default; + + /// + /// 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("bool4x4", RequiresParametersMatching = true)] + public static Bool4x4 UIntToBool(UInt4x4 x) => default; + + /// + /// 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("float", RequiresParametersMatching = true)] + public static float BoolToFloat(bool x) => default; + + /// + /// 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("float2", RequiresParametersMatching = true)] + public static Float2 BoolToFloat(Bool2 x) => default; + + /// + /// 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("float3", RequiresParametersMatching = true)] + public static Float3 BoolToFloat(Bool3 x) => default; + + /// + /// 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("float4", RequiresParametersMatching = true)] + public static Float4 BoolToFloat(Bool4 x) => default; + + /// + /// 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("float1x1", RequiresParametersMatching = true)] + public static Float1x1 BoolToFloat(Bool1x1 x) => default; + + /// + /// 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("float1x2", RequiresParametersMatching = true)] + public static Float1x2 BoolToFloat(Bool1x2 x) => default; + + /// + /// 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("float1x3", RequiresParametersMatching = true)] + public static Float1x3 BoolToFloat(Bool1x3 x) => default; + + /// + /// 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("float1x4", RequiresParametersMatching = true)] + public static Float1x4 BoolToFloat(Bool1x4 x) => default; + + /// + /// 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("float2x1", RequiresParametersMatching = true)] + public static Float2x1 BoolToFloat(Bool2x1 x) => default; + + /// + /// 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("float2x2", RequiresParametersMatching = true)] + public static Float2x2 BoolToFloat(Bool2x2 x) => default; + + /// + /// 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("float2x3", RequiresParametersMatching = true)] + public static Float2x3 BoolToFloat(Bool2x3 x) => default; + + /// + /// 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("float2x4", RequiresParametersMatching = true)] + public static Float2x4 BoolToFloat(Bool2x4 x) => default; + + /// + /// 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("float3x1", RequiresParametersMatching = true)] + public static Float3x1 BoolToFloat(Bool3x1 x) => default; + + /// + /// 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("float3x2", RequiresParametersMatching = true)] + public static Float3x2 BoolToFloat(Bool3x2 x) => default; + + /// + /// 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("float3x3", RequiresParametersMatching = true)] + public static Float3x3 BoolToFloat(Bool3x3 x) => default; + + /// + /// 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("float3x4", RequiresParametersMatching = true)] + public static Float3x4 BoolToFloat(Bool3x4 x) => default; + + /// + /// 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("float4x1", RequiresParametersMatching = true)] + public static Float4x1 BoolToFloat(Bool4x1 x) => default; + + /// + /// 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("float4x2", RequiresParametersMatching = true)] + public static Float4x2 BoolToFloat(Bool4x2 x) => default; + + /// + /// 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("float4x3", RequiresParametersMatching = true)] + public static Float4x3 BoolToFloat(Bool4x3 x) => default; + + /// + /// 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("float4x4", RequiresParametersMatching = true)] + public static Float4x4 BoolToFloat(Bool4x4 x) => default; + + /// + /// 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("double", RequiresParametersMatching = true)] + public static double BoolToDouble(bool x) => default; + + /// + /// 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("double2", RequiresParametersMatching = true)] + public static Double2 BoolToDouble(Bool2 x) => default; + + /// + /// 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("double3", RequiresParametersMatching = true)] + public static Double3 BoolToDouble(Bool3 x) => default; + + /// + /// 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("double4", RequiresParametersMatching = true)] + public static Double4 BoolToDouble(Bool4 x) => default; + + /// + /// 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("double1x1", RequiresParametersMatching = true)] + public static Double1x1 BoolToDouble(Bool1x1 x) => default; + + /// + /// 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("double1x2", RequiresParametersMatching = true)] + public static Double1x2 BoolToDouble(Bool1x2 x) => default; + + /// + /// 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("double1x3", RequiresParametersMatching = true)] + public static Double1x3 BoolToDouble(Bool1x3 x) => default; + + /// + /// 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("double1x4", RequiresParametersMatching = true)] + public static Double1x4 BoolToDouble(Bool1x4 x) => default; + + /// + /// 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("double2x1", RequiresParametersMatching = true)] + public static Double2x1 BoolToDouble(Bool2x1 x) => default; + + /// + /// 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("double2x2", RequiresParametersMatching = true)] + public static Double2x2 BoolToDouble(Bool2x2 x) => default; + + /// + /// 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("double2x3", RequiresParametersMatching = true)] + public static Double2x3 BoolToDouble(Bool2x3 x) => default; + + /// + /// 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("double2x4", RequiresParametersMatching = true)] + public static Double2x4 BoolToDouble(Bool2x4 x) => default; + + /// + /// 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("double3x1", RequiresParametersMatching = true)] + public static Double3x1 BoolToDouble(Bool3x1 x) => default; + + /// + /// 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("double3x2", RequiresParametersMatching = true)] + public static Double3x2 BoolToDouble(Bool3x2 x) => default; + + /// + /// 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("double3x3", RequiresParametersMatching = true)] + public static Double3x3 BoolToDouble(Bool3x3 x) => default; + + /// + /// 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("double3x4", RequiresParametersMatching = true)] + public static Double3x4 BoolToDouble(Bool3x4 x) => default; + + /// + /// 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("double4x1", RequiresParametersMatching = true)] + public static Double4x1 BoolToDouble(Bool4x1 x) => default; + + /// + /// 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("double4x2", RequiresParametersMatching = true)] + public static Double4x2 BoolToDouble(Bool4x2 x) => default; + + /// + /// 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("double4x3", RequiresParametersMatching = true)] + public static Double4x3 BoolToDouble(Bool4x3 x) => default; + + /// + /// 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("double4x4", RequiresParametersMatching = true)] + public static Double4x4 BoolToDouble(Bool4x4 x) => default; + + /// + /// 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("int", RequiresParametersMatching = true)] + public static int BoolToInt(bool x) => default; + + /// + /// 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("int2", RequiresParametersMatching = true)] + public static Int2 BoolToInt(Bool2 x) => default; + + /// + /// 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("int3", RequiresParametersMatching = true)] + public static Int3 BoolToInt(Bool3 x) => default; + + /// + /// 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("int4", RequiresParametersMatching = true)] + public static Int4 BoolToInt(Bool4 x) => default; + + /// + /// 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("int1x1", RequiresParametersMatching = true)] + public static Int1x1 BoolToInt(Bool1x1 x) => default; + + /// + /// 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("int1x2", RequiresParametersMatching = true)] + public static Int1x2 BoolToInt(Bool1x2 x) => default; + + /// + /// 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("int1x3", RequiresParametersMatching = true)] + public static Int1x3 BoolToInt(Bool1x3 x) => default; + + /// + /// 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("int1x4", RequiresParametersMatching = true)] + public static Int1x4 BoolToInt(Bool1x4 x) => default; + + /// + /// 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("int2x1", RequiresParametersMatching = true)] + public static Int2x1 BoolToInt(Bool2x1 x) => default; + + /// + /// 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("int2x2", RequiresParametersMatching = true)] + public static Int2x2 BoolToInt(Bool2x2 x) => default; + + /// + /// 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("int2x3", RequiresParametersMatching = true)] + public static Int2x3 BoolToInt(Bool2x3 x) => default; + + /// + /// 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("int2x4", RequiresParametersMatching = true)] + public static Int2x4 BoolToInt(Bool2x4 x) => default; + + /// + /// 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("int3x1", RequiresParametersMatching = true)] + public static Int3x1 BoolToInt(Bool3x1 x) => default; + + /// + /// 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("int3x2", RequiresParametersMatching = true)] + public static Int3x2 BoolToInt(Bool3x2 x) => default; + + /// + /// 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("int3x3", RequiresParametersMatching = true)] + public static Int3x3 BoolToInt(Bool3x3 x) => default; + + /// + /// 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("int3x4", RequiresParametersMatching = true)] + public static Int3x4 BoolToInt(Bool3x4 x) => default; + + /// + /// 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("int4x1", RequiresParametersMatching = true)] + public static Int4x1 BoolToInt(Bool4x1 x) => default; + + /// + /// 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("int4x2", RequiresParametersMatching = true)] + public static Int4x2 BoolToInt(Bool4x2 x) => default; + + /// + /// 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("int4x3", RequiresParametersMatching = true)] + public static Int4x3 BoolToInt(Bool4x3 x) => default; + + /// + /// 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("int4x4", RequiresParametersMatching = true)] + public static Int4x4 BoolToInt(Bool4x4 x) => default; + + /// + /// 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("uint", RequiresParametersMatching = true)] + public static uint BoolToUInt(bool x) => default; + + /// + /// 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("uint2", RequiresParametersMatching = true)] + public static UInt2 BoolToUInt(Bool2 x) => default; + + /// + /// 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("uint3", RequiresParametersMatching = true)] + public static UInt3 BoolToUInt(Bool3 x) => default; + + /// + /// 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("uint4", RequiresParametersMatching = true)] + public static UInt4 BoolToUInt(Bool4 x) => default; + + /// + /// 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("uint1x1", RequiresParametersMatching = true)] + public static UInt1x1 BoolToUInt(Bool1x1 x) => default; + + /// + /// 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("uint1x2", RequiresParametersMatching = true)] + public static UInt1x2 BoolToUInt(Bool1x2 x) => default; + + /// + /// 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("uint1x3", RequiresParametersMatching = true)] + public static UInt1x3 BoolToUInt(Bool1x3 x) => default; + + /// + /// 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("uint1x4", RequiresParametersMatching = true)] + public static UInt1x4 BoolToUInt(Bool1x4 x) => default; + + /// + /// 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("uint2x1", RequiresParametersMatching = true)] + public static UInt2x1 BoolToUInt(Bool2x1 x) => default; + + /// + /// 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("uint2x2", RequiresParametersMatching = true)] + public static UInt2x2 BoolToUInt(Bool2x2 x) => default; + + /// + /// 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("uint2x3", RequiresParametersMatching = true)] + public static UInt2x3 BoolToUInt(Bool2x3 x) => default; + + /// + /// 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("uint2x4", RequiresParametersMatching = true)] + public static UInt2x4 BoolToUInt(Bool2x4 x) => default; + + /// + /// 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("uint3x1", RequiresParametersMatching = true)] + public static UInt3x1 BoolToUInt(Bool3x1 x) => default; + + /// + /// 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("uint3x2", RequiresParametersMatching = true)] + public static UInt3x2 BoolToUInt(Bool3x2 x) => default; + + /// + /// 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("uint3x3", RequiresParametersMatching = true)] + public static UInt3x3 BoolToUInt(Bool3x3 x) => default; + + /// + /// 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("uint3x4", RequiresParametersMatching = true)] + public static UInt3x4 BoolToUInt(Bool3x4 x) => default; + + /// + /// 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("uint4x1", RequiresParametersMatching = true)] + public static UInt4x1 BoolToUInt(Bool4x1 x) => default; + + /// + /// 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("uint4x2", RequiresParametersMatching = true)] + public static UInt4x2 BoolToUInt(Bool4x2 x) => default; + + /// + /// 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("uint4x3", RequiresParametersMatching = true)] + public static UInt4x3 BoolToUInt(Bool4x3 x) => default; + + /// + /// 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("uint4x4", RequiresParametersMatching = true)] + public static UInt4x4 BoolToUInt(Bool4x4 x) => default; +} diff --git a/src/ComputeSharp.Core/Intrinsics/Hlsl.Casts.tt b/src/ComputeSharp.Core/Intrinsics/Hlsl.Casts.tt new file mode 100644 index 00000000..eeb80f9f --- /dev/null +++ b/src/ComputeSharp.Core/Intrinsics/Hlsl.Casts.tt @@ -0,0 +1,80 @@ +<#@ 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; + +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; +<# + } +} +#> +} diff --git a/src/ComputeSharp.D2D1.NetStandard/ComputeSharp.D2D1.NetStandard.projitems b/src/ComputeSharp.D2D1.NetStandard/ComputeSharp.D2D1.NetStandard.projitems index 5e0080d3..51af99e0 100644 --- a/src/ComputeSharp.D2D1.NetStandard/ComputeSharp.D2D1.NetStandard.projitems +++ b/src/ComputeSharp.D2D1.NetStandard/ComputeSharp.D2D1.NetStandard.projitems @@ -15,7 +15,6 @@ - \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj index 2af1c50f..b261d67a 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj +++ b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj @@ -1,4 +1,4 @@ - + netstandard2.0 @@ -18,6 +18,7 @@ + diff --git a/src/ComputeSharp.NetStandard/ComputeSharp.NetStandard.projitems b/src/ComputeSharp.NetStandard/ComputeSharp.NetStandard.projitems index 9c229e84..5f0f1683 100644 --- a/src/ComputeSharp.NetStandard/ComputeSharp.NetStandard.projitems +++ b/src/ComputeSharp.NetStandard/ComputeSharp.NetStandard.projitems @@ -19,7 +19,6 @@ - diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownMethods.cs b/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownMethods.cs index 5856846c..dd7f890b 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownMethods.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownMethods.cs @@ -17,6 +17,11 @@ internal static partial class HlslKnownMethods /// private static readonly IReadOnlyDictionary KnownMethods = BuildKnownMethodsMap(); + /// + /// The mapping of supported known methods that require parameters mapping to HLSL names. + /// + private static readonly IReadOnlyDictionary KnownMethodsParametersMapping = BuildKnownMethodsParametersMappingMap(); + /// /// Builds the mapping of supported known methods to HLSL names. /// @@ -122,19 +127,32 @@ internal static partial class HlslKnownMethods [$"{typeof(Vector4).FullName}.{nameof(Vector4.Normalize)}"] = "normalize" }; - // Programmatically load mappings from the Hlsl class as well + // Programmatically load mappings from the Hlsl class as well (the ones with no parameter matching) foreach (var method in from method in typeof(Hlsl).GetMethods(BindingFlags.Public | BindingFlags.Static) group method by method.Name into groups select groups.First()) { - // Check whether the current method should be translated with the original name - // or with the lowercase version. This is needed because all C# methods are exposed - // with the upper camel case format, while HLSL intrinsics use multiple different formats. - string hlslName = method.GetCustomAttribute()?.Name ?? method.Name; + HlslIntrinsicNameAttribute? attribute = method.GetCustomAttribute(); - knownMethods.Add($"{typeof(Hlsl).FullName}{Type.Delimiter}{method.Name}", hlslName); + // If the intrinsic requires parameters matching, skip it. It will be tracked separately. + // To avoid processing all types again, add a special identifier for it to detect it. + if (attribute is { RequiresParametersMatching: true }) + { + knownMethods.Add($"{typeof(Hlsl).FullName}{Type.Delimiter}{method.Name}", nameof(HlslIntrinsicNameAttribute.RequiresParametersMatching)); + + continue; + } + else + { + // Check whether the current method should be translated with the original name + // or with the lowercase version. This is needed because all C# methods are exposed + // with the upper camel case format, while HLSL intrinsics use multiple different formats. + string hlslName = attribute?.Name ?? method.Name; + + knownMethods.Add($"{typeof(Hlsl).FullName}{Type.Delimiter}{method.Name}", hlslName); + } } // Let other types inject additional methods @@ -143,6 +161,38 @@ internal static partial class HlslKnownMethods return knownMethods; } + /// + /// Builds the mapping of supported known methods that require parameters mapping to HLSL names. + /// + private static IReadOnlyDictionary BuildKnownMethodsParametersMappingMap() + { + ILookup methodsLookup = typeof(Hlsl).GetMethods(BindingFlags.Public | BindingFlags.Static).ToLookup(static method => method.Name); + + Dictionary knownMethods = new(); + + // Go through the previously discovered methods to find the ones requiring parameters mapping + foreach (var pair in KnownMethods) + { + // Only process methods marked as requiring parameters mapping + if (pair.Value != nameof(HlslIntrinsicNameAttribute.RequiresParametersMatching)) + { + continue; + } + + // Go through the intrinsics with the current name, and track the method name and parameters. We don't need + // to also track the fully qualified type name, as that part has already been matched previously at this point. + foreach (MethodInfo method in methodsLookup[pair.Key.Split('.').Last()]) + { + // The key is in the format "()", and the intrinsic name is guaranteed to be available + knownMethods.Add( + $"{method.Name}({string.Join(", ", method.GetParameters().Select(static p => p.ParameterType.Name))})", + method.GetCustomAttribute()!.Name); + } + } + + return knownMethods; + } + /// /// Adds more known methods to the mapping to use. /// @@ -176,9 +226,40 @@ internal static partial class HlslKnownMethods /// /// The input fully qualified method name. /// The mapped name, if one is found. - /// The HLSL-compatible member name that can be used in an HLSL shader. - public static bool TryGetMappedName(string name, out string? mapped) + /// Whether the method is an intrinsic, but it requires matching parameters too. + /// Whether the input method was an intrinsic. + public static bool TryGetMappedName(string name, out string? mapped, out bool requiresParametersMapping) { - return KnownMethods.TryGetValue(name, out mapped); + if (KnownMethods.TryGetValue(name, out string? value)) + { + if (value == nameof(HlslIntrinsicNameAttribute.RequiresParametersMatching)) + { + mapped = null; + requiresParametersMapping = true; + } + else + { + mapped = value; + requiresParametersMapping = false; + } + + return true; + } + + mapped = null; + requiresParametersMapping = false; + + return false; + } + + /// + /// Gets the mapped HLSL-compatible method name for the input method name and parameters. + /// + /// The method name (previously validated with ). + /// The sequence of type names for the method. + /// The intrinsic name for the current method. + public static string GetMappedNameWithParameters(string name, IEnumerable parameterTypeNames) + { + return KnownMethodsParametersMapping[$"{name}({string.Join(", ", parameterTypeNames)})"]; } } diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs index 38d46a49..f5334d9b 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs @@ -353,8 +353,13 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter // If the invocation consists of invoking a static method that has a direct // mapping to HLSL, rewrite the expression in the current invocation node. // For instance: Math.Abs(expr) => abs(expr). - if (HlslKnownMethods.TryGetMappedName(metadataName, out string? mapping)) + if (HlslKnownMethods.TryGetMappedName(metadataName, out string? mapping, out bool requiresParametersMapping)) { + if (requiresParametersMapping) + { + mapping = HlslKnownMethods.GetMappedNameWithParameters(method.Name, method.Parameters.Select(static p => p.Type.Name)); + } + // Allow specialized types to track the method invocation, if needed TrackKnownMethodInvocation(metadataName); diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/StaticFieldRewriter.cs b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/StaticFieldRewriter.cs index 319e43f4..8c871706 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/StaticFieldRewriter.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/StaticFieldRewriter.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Globalization; +using System.Linq; using ComputeSharp.SourceGeneration.Extensions; using ComputeSharp.SourceGeneration.Helpers; using ComputeSharp.SourceGeneration.Mappings; @@ -98,8 +99,13 @@ internal sealed partial class StaticFieldRewriter : HlslSourceRewriter method.IsStatic) { // Rewrite HLSL intrinsic methods - if (HlslKnownMethods.TryGetMappedName(method.GetFullMetadataName(), out string? mapping)) + if (HlslKnownMethods.TryGetMappedName(method.GetFullMetadataName(), out string? mapping, out bool requiresParametersMapping)) { + if (requiresParametersMapping) + { + mapping = HlslKnownMethods.GetMappedNameWithParameters(method.Name, method.Parameters.Select(static p => p.Type.Name)); + } + return updatedNode.WithExpression(ParseExpression(mapping!)); } } diff --git a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj index a436e08f..e23d0319 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj +++ b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj @@ -20,6 +20,7 @@ + diff --git a/tests/ComputeSharp.Tests/ShaderRewriterTests.cs b/tests/ComputeSharp.Tests/ShaderRewriterTests.cs index 9f2dc298..8b9cb27c 100644 --- a/tests/ComputeSharp.Tests/ShaderRewriterTests.cs +++ b/tests/ComputeSharp.Tests/ShaderRewriterTests.cs @@ -237,6 +237,163 @@ public partial class ShaderRewriterTests } } + [CombinatorialTestMethod] + [AllDevices] + public void ToBooleanConversionHlslIntrinsics(Device device) + { + float[] data1 = new[] { 3.14f, 0, 1.44f, 0, 0, 0.4445f }; + int[] data2 = new[] { 3, 0, 1, 0, 0, 156 }; + + using ReadOnlyBuffer buffer1 = device.Get().AllocateReadOnlyBuffer(data1); + using ReadOnlyBuffer buffer2 = device.Get().AllocateReadOnlyBuffer(data2); + using ReadWriteBuffer buffer3 = device.Get().AllocateReadWriteBuffer(18, AllocationMode.Clear); + + device.Get().For(1, new ToBooleanConversionIntrinsicsShader(buffer1, buffer2, buffer3)); + + int[] results = buffer3.ToArray(); + + CollectionAssert.AreEqual( + expected: new[] { 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1 }, + actual: results); + } + + [AutoConstructor] + internal readonly partial struct ToBooleanConversionIntrinsicsShader : IComputeShader + { + public readonly ReadOnlyBuffer buffer1; + public readonly ReadOnlyBuffer buffer2; + public readonly ReadWriteBuffer result; + + public void Execute() + { + float f1 = buffer1[0]; + float f2 = buffer1[1]; + float4 f4 = new(buffer1[2], buffer1[3], buffer1[4], buffer1[5]); + + int i1 = buffer2[0]; + int i2 = buffer2[1]; + int4 i4 = new(buffer2[2], buffer2[3], buffer2[4], buffer2[5]); + + uint u1 = (uint)buffer2[0]; + uint u2 = (uint)buffer2[1]; + uint4 u4 = new((uint)buffer2[2], (uint)buffer2[3], (uint)buffer2[4], (uint)buffer2[5]); + + result[0] = Hlsl.FloatToBool(f1) ? 1 : 0; + result[1] = Hlsl.FloatToBool(f2) ? 1 : 0; + + bool4 f4b = Hlsl.FloatToBool(f4); + + result[2] = f4b[0] ? 1 : 0; + result[3] = f4b[1] ? 1 : 0; + result[4] = f4b[2] ? 1 : 0; + result[5] = f4b[3] ? 1 : 0; + + result[6] = Hlsl.IntToBool(i1) ? 1 : 0; + result[7] = Hlsl.IntToBool(i2) ? 1 : 0; + + bool4 i4b = Hlsl.IntToBool(i4); + + result[8] = i4b[0] ? 1 : 0; + result[9] = i4b[1] ? 1 : 0; + result[10] = i4b[2] ? 1 : 0; + result[11] = i4b[3] ? 1 : 0; + + result[12] = Hlsl.UIntToBool(u1) ? 1 : 0; + result[13] = Hlsl.UIntToBool(u2) ? 1 : 0; + + bool4 u4b = Hlsl.UIntToBool(u4); + + result[14] = u4b[0] ? 1 : 0; + result[15] = u4b[1] ? 1 : 0; + result[16] = u4b[2] ? 1 : 0; + result[17] = u4b[3] ? 1 : 0; + } + } + + [CombinatorialTestMethod] + [AllDevices] + public void FromBooleanConversionHlslIntrinsics(Device device) + { + int[] data = new[] { 1, 0, 1, 0, 0, 1 }; + + using ReadOnlyBuffer buffer1 = device.Get().AllocateReadOnlyBuffer(data); + using ReadWriteBuffer buffer2 = device.Get().AllocateReadWriteBuffer(6, AllocationMode.Clear); + using ReadWriteBuffer buffer3 = device.Get().AllocateReadWriteBuffer(6, AllocationMode.Clear); + using ReadWriteBuffer buffer4 = device.Get().AllocateReadWriteBuffer(6, AllocationMode.Clear); + + device.Get().For(1, new FromBooleanConversionIntrinsicsShader(buffer1, buffer2, buffer3, buffer4)); + + float[] results1 = buffer2.ToArray(); + int[] results2 = buffer3.ToArray(); + uint[] results3 = buffer4.ToArray(); + + CollectionAssert.AreEqual( + expected: new float[] { 1, 0, 1, 0, 0, 1 }, + actual: results1); + + CollectionAssert.AreEqual( + expected: new int[] { 1, 0, 1, 0, 0, 1 }, + actual: results2); + + CollectionAssert.AreEqual( + expected: new uint[] { 1, 0, 1, 0, 0, 1 }, + actual: results3); + } + + [AutoConstructor] + internal readonly partial struct FromBooleanConversionIntrinsicsShader : IComputeShader + { + public readonly ReadOnlyBuffer source; + public readonly ReadWriteBuffer destination1; + public readonly ReadWriteBuffer destination2; + public readonly ReadWriteBuffer destination3; + + public void Execute() + { + bool b1 = source[0] != 0; + bool b2 = source[1] != 0; + bool4 b4 = new(source[2] != 0, source[3] != 0, source[4] != 0, source[5] != 0); + + bool b11 = source[0] != 0; + bool b22 = source[1] != 0; + bool4 b44 = new(source[2] != 0, source[3] != 0, source[4] != 0, source[5] != 0); + + bool b111 = source[0] != 0; + bool b222 = source[1] != 0; + bool4 b444 = new(source[2] != 0, source[3] != 0, source[4] != 0, source[5] != 0); + + destination1[0] = Hlsl.BoolToFloat(b1); + destination1[1] = Hlsl.BoolToFloat(b2); + + float4 f4 = Hlsl.BoolToFloat(b4); + + destination1[2] = f4.X; + destination1[3] = f4.Y; + destination1[4] = f4.Z; + destination1[5] = f4.W; + + destination2[0] = Hlsl.BoolToInt(b11); + destination2[1] = Hlsl.BoolToInt(b22); + + int4 i4 = Hlsl.BoolToInt(b44); + + destination2[2] = i4.X; + destination2[3] = i4.Y; + destination2[4] = i4.Z; + destination2[5] = i4.W; + + destination3[0] = Hlsl.BoolToUInt(b111); + destination3[1] = Hlsl.BoolToUInt(b222); + + uint4 u4 = Hlsl.BoolToUInt(b444); + + destination3[2] = u4.X; + destination3[3] = u4.Y; + destination3[4] = u4.Z; + destination3[5] = u4.W; + } + } + // See: https://github.com/Sergio0694/ComputeSharp/issues/259 [CombinatorialTestMethod] [AllDevices]