From 3adf7341d0346b75d14019ca46d683f7e0a1875b Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 27 Aug 2022 00:37:40 +0200 Subject: [PATCH 1/9] Use wildcards to import T4 files in .csproj --- .../ComputeSharp.Core.csproj | 205 +----------------- 1 file changed, 7 insertions(+), 198 deletions(-) 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 - From 7f99e59b129cc4208ed6c6249f87688e3cea8044 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 27 Aug 2022 01:00:57 +0200 Subject: [PATCH 2/9] Add HLSL intrinsics to convert to bool --- .../Intrinsics/Hlsl.Casts.g.cs | 724 ++++++++++++++++++ .../Intrinsics/Hlsl.Casts.tt | 54 ++ 2 files changed, 778 insertions(+) create mode 100644 src/ComputeSharp.Core/Intrinsics/Hlsl.Casts.g.cs create mode 100644 src/ComputeSharp.Core/Intrinsics/Hlsl.Casts.tt 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..ce787c2b --- /dev/null +++ b/src/ComputeSharp.Core/Intrinsics/Hlsl.Casts.g.cs @@ -0,0 +1,724 @@ +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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + public static Bool4x4 UIntToBool(UInt4x4 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..0d96cfda --- /dev/null +++ b/src/ComputeSharp.Core/Intrinsics/Hlsl.Casts.tt @@ -0,0 +1,54 @@ +<#@ 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 +{ +<# +foreach (var type in new[] { "Float", "Double", "Int", "UInt" }) +{ + int index = 0; + + 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}")); + } + } + + // Produce the intrinsics + foreach (var pair in typeNames) + { + 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()#>")] + public static <#=pair.Target#> <#=type#>ToBool(<#=pair.Source#> x) => default; +<# + } +} +#> +} From 31b8c7bc481725414bd0e29e0c2b785de05a26db Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 27 Aug 2022 01:03:29 +0200 Subject: [PATCH 3/9] Add HLSL intrinsics to convert from bool --- .../Intrinsics/Hlsl.Casts.g.cs | 720 ++++++++++++++++++ .../Intrinsics/Hlsl.Casts.tt | 41 +- 2 files changed, 760 insertions(+), 1 deletion(-) diff --git a/src/ComputeSharp.Core/Intrinsics/Hlsl.Casts.g.cs b/src/ComputeSharp.Core/Intrinsics/Hlsl.Casts.g.cs index ce787c2b..102c7d17 100644 --- a/src/ComputeSharp.Core/Intrinsics/Hlsl.Casts.g.cs +++ b/src/ComputeSharp.Core/Intrinsics/Hlsl.Casts.g.cs @@ -721,4 +721,724 @@ partial class Hlsl /// 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")] 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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")] + 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 index 0d96cfda..9d329bec 100644 --- a/src/ComputeSharp.Core/Intrinsics/Hlsl.Casts.tt +++ b/src/ComputeSharp.Core/Intrinsics/Hlsl.Casts.tt @@ -10,6 +10,7 @@ namespace ComputeSharp; partial class Hlsl { <# +// Numeric to bool foreach (var type in new[] { "Float", "Double", "Int", "UInt" }) { int index = 0; @@ -37,7 +38,6 @@ foreach (var type in new[] { "Float", "Double", "Int", "UInt" }) foreach (var pair in typeNames) { if (index++ != 0) WriteLine(""); - #> /// /// Converts the input value into a value (non-zero elements map to , zero elements map to ). @@ -50,5 +50,44 @@ foreach (var type in new[] { "Float", "Double", "Int", "UInt" }) <# } } + +// Bool to numeric +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}")); + } + } + + // Produce the intrinsics + foreach (var pair in typeNames) + { + 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()#>")] + public static <#=pair.Source#> BoolTo<#=type#>(<#=pair.Target#> x) => default; +<# + } +} #> } From 2a28fd93a323c4711d11c169b8a4d942ddf066e7 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 27 Aug 2022 01:08:09 +0200 Subject: [PATCH 4/9] Minor code refactoring --- .../Intrinsics/Hlsl.Casts.tt | 45 +++++++------------ 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/src/ComputeSharp.Core/Intrinsics/Hlsl.Casts.tt b/src/ComputeSharp.Core/Intrinsics/Hlsl.Casts.tt index 9d329bec..f49669fc 100644 --- a/src/ComputeSharp.Core/Intrinsics/Hlsl.Casts.tt +++ b/src/ComputeSharp.Core/Intrinsics/Hlsl.Casts.tt @@ -10,11 +10,11 @@ namespace ComputeSharp; partial class Hlsl { <# -// Numeric to bool +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" }) { - int index = 0; - List<(string Source, string Target)> typeNames = new List<(string, string)>(); typeNames.Add((type.ToLower(), "bool")); @@ -34,8 +34,15 @@ foreach (var type in new[] { "Float", "Double", "Int", "UInt" }) } } - // Produce the intrinsics - foreach (var pair in typeNames) + 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(""); #> @@ -46,35 +53,15 @@ foreach (var type in new[] { "Float", "Double", "Int", "UInt" }) /// 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()#>")] - public static <#=pair.Target#> <#=type#>ToBool(<#=pair.Source#> x) => default; + public static <#=pair.Target#> <#=intrinsic.Type#>ToBool(<#=pair.Source#> x) => default; <# } } // Bool to numeric -foreach (var type in new[] { "Float", "Double", "Int", "UInt" }) +foreach (var intrinsic in intrinsics) { - 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}")); - } - } - - // Produce the intrinsics - foreach (var pair in typeNames) + foreach (var pair in intrinsic.Info) { WriteLine(""); #> @@ -85,7 +72,7 @@ foreach (var type in new[] { "Float", "Double", "Int", "UInt" }) /// 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()#>")] - public static <#=pair.Source#> BoolTo<#=type#>(<#=pair.Target#> x) => default; + public static <#=pair.Source#> BoolTo<#=intrinsic.Type#>(<#=pair.Target#> x) => default; <# } } From 8bd2f80eae6024311c6bdf30e2f2f87a9b725ee1 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 27 Aug 2022 01:25:57 +0200 Subject: [PATCH 5/9] Add cast intrinsics to source generators --- .../ComputeSharp.D2D1.SourceGenerators.csproj | 3 ++- .../ComputeSharp.SourceGenerators.csproj | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) 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.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 @@ + From ab747f4b8044c22212ec8e5a3c7628422858cd43 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 27 Aug 2022 01:53:11 +0200 Subject: [PATCH 6/9] Add unit tests for bool intrinsics --- .../ComputeSharp.Tests/ShaderRewriterTests.cs | 157 ++++++++++++++++++ 1 file changed, 157 insertions(+) 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] From 57e3bb5fd797d1011592d00079d002e2c07bb648 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 27 Aug 2022 02:14:40 +0200 Subject: [PATCH 7/9] Move IsExternalInit to ComputeSharp.Core.NetStandard --- .../ComputeSharp.Core.NetStandard.projitems | 1 + .../Runtime.CompilerServices}/IsExternalInit.cs | 0 .../ComputeSharp.Core.SourceGenerators.csproj | 4 ++-- .../IsExternalInit.cs | 12 ------------ .../ComputeSharp.D2D1.NetStandard.projitems | 1 - .../ComputeSharp.NetStandard.projitems | 1 - 6 files changed, 3 insertions(+), 16 deletions(-) rename src/{ComputeSharp.NetStandard/System/Runtime/CompilerServices => ComputeSharp.Core.NetStandard/System/Runtime.CompilerServices}/IsExternalInit.cs (100%) delete mode 100644 src/ComputeSharp.Core.SourceGenerators/System.Runtime.CompilerServices/IsExternalInit.cs 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.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.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 @@ - From 24ed41afa48bb2285b92eee8c5c28e2be319421f Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 27 Aug 2022 02:58:03 +0200 Subject: [PATCH 8/9] Add HlslIntrinsicNameAttribute.RequiresParametersMatching property --- .../Attributes/HlslIntrinsicNameAttribute.cs | 5 + .../Intrinsics/Hlsl.Casts.g.cs | 320 +++++++++--------- .../Intrinsics/Hlsl.Casts.tt | 4 +- 3 files changed, 167 insertions(+), 162 deletions(-) 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 index 102c7d17..937ed920 100644 --- a/src/ComputeSharp.Core/Intrinsics/Hlsl.Casts.g.cs +++ b/src/ComputeSharp.Core/Intrinsics/Hlsl.Casts.g.cs @@ -11,7 +11,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool", RequiresParametersMatching = true)] public static bool FloatToBool(float x) => default; /// @@ -20,7 +20,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool2", RequiresParametersMatching = true)] public static Bool2 FloatToBool(Float2 x) => default; /// @@ -29,7 +29,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool3", RequiresParametersMatching = true)] public static Bool3 FloatToBool(Float3 x) => default; /// @@ -38,7 +38,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool4", RequiresParametersMatching = true)] public static Bool4 FloatToBool(Float4 x) => default; /// @@ -47,7 +47,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool1x1", RequiresParametersMatching = true)] public static Bool1x1 FloatToBool(Float1x1 x) => default; /// @@ -56,7 +56,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool1x2", RequiresParametersMatching = true)] public static Bool1x2 FloatToBool(Float1x2 x) => default; /// @@ -65,7 +65,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool1x3", RequiresParametersMatching = true)] public static Bool1x3 FloatToBool(Float1x3 x) => default; /// @@ -74,7 +74,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool1x4", RequiresParametersMatching = true)] public static Bool1x4 FloatToBool(Float1x4 x) => default; /// @@ -83,7 +83,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool2x1", RequiresParametersMatching = true)] public static Bool2x1 FloatToBool(Float2x1 x) => default; /// @@ -92,7 +92,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool2x2", RequiresParametersMatching = true)] public static Bool2x2 FloatToBool(Float2x2 x) => default; /// @@ -101,7 +101,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool2x3", RequiresParametersMatching = true)] public static Bool2x3 FloatToBool(Float2x3 x) => default; /// @@ -110,7 +110,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool2x4", RequiresParametersMatching = true)] public static Bool2x4 FloatToBool(Float2x4 x) => default; /// @@ -119,7 +119,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool3x1", RequiresParametersMatching = true)] public static Bool3x1 FloatToBool(Float3x1 x) => default; /// @@ -128,7 +128,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool3x2", RequiresParametersMatching = true)] public static Bool3x2 FloatToBool(Float3x2 x) => default; /// @@ -137,7 +137,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool3x3", RequiresParametersMatching = true)] public static Bool3x3 FloatToBool(Float3x3 x) => default; /// @@ -146,7 +146,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool3x4", RequiresParametersMatching = true)] public static Bool3x4 FloatToBool(Float3x4 x) => default; /// @@ -155,7 +155,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool4x1", RequiresParametersMatching = true)] public static Bool4x1 FloatToBool(Float4x1 x) => default; /// @@ -164,7 +164,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool4x2", RequiresParametersMatching = true)] public static Bool4x2 FloatToBool(Float4x2 x) => default; /// @@ -173,7 +173,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool4x3", RequiresParametersMatching = true)] public static Bool4x3 FloatToBool(Float4x3 x) => default; /// @@ -182,7 +182,7 @@ partial class Hlsl /// 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")] + [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 ). @@ -190,7 +190,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool", RequiresParametersMatching = true)] public static bool DoubleToBool(double x) => default; /// @@ -199,7 +199,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool2", RequiresParametersMatching = true)] public static Bool2 DoubleToBool(Double2 x) => default; /// @@ -208,7 +208,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool3", RequiresParametersMatching = true)] public static Bool3 DoubleToBool(Double3 x) => default; /// @@ -217,7 +217,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool4", RequiresParametersMatching = true)] public static Bool4 DoubleToBool(Double4 x) => default; /// @@ -226,7 +226,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool1x1", RequiresParametersMatching = true)] public static Bool1x1 DoubleToBool(Double1x1 x) => default; /// @@ -235,7 +235,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool1x2", RequiresParametersMatching = true)] public static Bool1x2 DoubleToBool(Double1x2 x) => default; /// @@ -244,7 +244,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool1x3", RequiresParametersMatching = true)] public static Bool1x3 DoubleToBool(Double1x3 x) => default; /// @@ -253,7 +253,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool1x4", RequiresParametersMatching = true)] public static Bool1x4 DoubleToBool(Double1x4 x) => default; /// @@ -262,7 +262,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool2x1", RequiresParametersMatching = true)] public static Bool2x1 DoubleToBool(Double2x1 x) => default; /// @@ -271,7 +271,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool2x2", RequiresParametersMatching = true)] public static Bool2x2 DoubleToBool(Double2x2 x) => default; /// @@ -280,7 +280,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool2x3", RequiresParametersMatching = true)] public static Bool2x3 DoubleToBool(Double2x3 x) => default; /// @@ -289,7 +289,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool2x4", RequiresParametersMatching = true)] public static Bool2x4 DoubleToBool(Double2x4 x) => default; /// @@ -298,7 +298,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool3x1", RequiresParametersMatching = true)] public static Bool3x1 DoubleToBool(Double3x1 x) => default; /// @@ -307,7 +307,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool3x2", RequiresParametersMatching = true)] public static Bool3x2 DoubleToBool(Double3x2 x) => default; /// @@ -316,7 +316,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool3x3", RequiresParametersMatching = true)] public static Bool3x3 DoubleToBool(Double3x3 x) => default; /// @@ -325,7 +325,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool3x4", RequiresParametersMatching = true)] public static Bool3x4 DoubleToBool(Double3x4 x) => default; /// @@ -334,7 +334,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool4x1", RequiresParametersMatching = true)] public static Bool4x1 DoubleToBool(Double4x1 x) => default; /// @@ -343,7 +343,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool4x2", RequiresParametersMatching = true)] public static Bool4x2 DoubleToBool(Double4x2 x) => default; /// @@ -352,7 +352,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool4x3", RequiresParametersMatching = true)] public static Bool4x3 DoubleToBool(Double4x3 x) => default; /// @@ -361,7 +361,7 @@ partial class Hlsl /// 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")] + [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 ). @@ -369,7 +369,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool", RequiresParametersMatching = true)] public static bool IntToBool(int x) => default; /// @@ -378,7 +378,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool2", RequiresParametersMatching = true)] public static Bool2 IntToBool(Int2 x) => default; /// @@ -387,7 +387,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool3", RequiresParametersMatching = true)] public static Bool3 IntToBool(Int3 x) => default; /// @@ -396,7 +396,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool4", RequiresParametersMatching = true)] public static Bool4 IntToBool(Int4 x) => default; /// @@ -405,7 +405,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool1x1", RequiresParametersMatching = true)] public static Bool1x1 IntToBool(Int1x1 x) => default; /// @@ -414,7 +414,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool1x2", RequiresParametersMatching = true)] public static Bool1x2 IntToBool(Int1x2 x) => default; /// @@ -423,7 +423,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool1x3", RequiresParametersMatching = true)] public static Bool1x3 IntToBool(Int1x3 x) => default; /// @@ -432,7 +432,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool1x4", RequiresParametersMatching = true)] public static Bool1x4 IntToBool(Int1x4 x) => default; /// @@ -441,7 +441,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool2x1", RequiresParametersMatching = true)] public static Bool2x1 IntToBool(Int2x1 x) => default; /// @@ -450,7 +450,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool2x2", RequiresParametersMatching = true)] public static Bool2x2 IntToBool(Int2x2 x) => default; /// @@ -459,7 +459,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool2x3", RequiresParametersMatching = true)] public static Bool2x3 IntToBool(Int2x3 x) => default; /// @@ -468,7 +468,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool2x4", RequiresParametersMatching = true)] public static Bool2x4 IntToBool(Int2x4 x) => default; /// @@ -477,7 +477,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool3x1", RequiresParametersMatching = true)] public static Bool3x1 IntToBool(Int3x1 x) => default; /// @@ -486,7 +486,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool3x2", RequiresParametersMatching = true)] public static Bool3x2 IntToBool(Int3x2 x) => default; /// @@ -495,7 +495,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool3x3", RequiresParametersMatching = true)] public static Bool3x3 IntToBool(Int3x3 x) => default; /// @@ -504,7 +504,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool3x4", RequiresParametersMatching = true)] public static Bool3x4 IntToBool(Int3x4 x) => default; /// @@ -513,7 +513,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool4x1", RequiresParametersMatching = true)] public static Bool4x1 IntToBool(Int4x1 x) => default; /// @@ -522,7 +522,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool4x2", RequiresParametersMatching = true)] public static Bool4x2 IntToBool(Int4x2 x) => default; /// @@ -531,7 +531,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool4x3", RequiresParametersMatching = true)] public static Bool4x3 IntToBool(Int4x3 x) => default; /// @@ -540,7 +540,7 @@ partial class Hlsl /// 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")] + [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 ). @@ -548,7 +548,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool", RequiresParametersMatching = true)] public static bool UIntToBool(uint x) => default; /// @@ -557,7 +557,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool2", RequiresParametersMatching = true)] public static Bool2 UIntToBool(UInt2 x) => default; /// @@ -566,7 +566,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool3", RequiresParametersMatching = true)] public static Bool3 UIntToBool(UInt3 x) => default; /// @@ -575,7 +575,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool4", RequiresParametersMatching = true)] public static Bool4 UIntToBool(UInt4 x) => default; /// @@ -584,7 +584,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool1x1", RequiresParametersMatching = true)] public static Bool1x1 UIntToBool(UInt1x1 x) => default; /// @@ -593,7 +593,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool1x2", RequiresParametersMatching = true)] public static Bool1x2 UIntToBool(UInt1x2 x) => default; /// @@ -602,7 +602,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool1x3", RequiresParametersMatching = true)] public static Bool1x3 UIntToBool(UInt1x3 x) => default; /// @@ -611,7 +611,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool1x4", RequiresParametersMatching = true)] public static Bool1x4 UIntToBool(UInt1x4 x) => default; /// @@ -620,7 +620,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool2x1", RequiresParametersMatching = true)] public static Bool2x1 UIntToBool(UInt2x1 x) => default; /// @@ -629,7 +629,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool2x2", RequiresParametersMatching = true)] public static Bool2x2 UIntToBool(UInt2x2 x) => default; /// @@ -638,7 +638,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool2x3", RequiresParametersMatching = true)] public static Bool2x3 UIntToBool(UInt2x3 x) => default; /// @@ -647,7 +647,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool2x4", RequiresParametersMatching = true)] public static Bool2x4 UIntToBool(UInt2x4 x) => default; /// @@ -656,7 +656,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool3x1", RequiresParametersMatching = true)] public static Bool3x1 UIntToBool(UInt3x1 x) => default; /// @@ -665,7 +665,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool3x2", RequiresParametersMatching = true)] public static Bool3x2 UIntToBool(UInt3x2 x) => default; /// @@ -674,7 +674,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool3x3", RequiresParametersMatching = true)] public static Bool3x3 UIntToBool(UInt3x3 x) => default; /// @@ -683,7 +683,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool3x4", RequiresParametersMatching = true)] public static Bool3x4 UIntToBool(UInt3x4 x) => default; /// @@ -692,7 +692,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool4x1", RequiresParametersMatching = true)] public static Bool4x1 UIntToBool(UInt4x1 x) => default; /// @@ -701,7 +701,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool4x2", RequiresParametersMatching = true)] public static Bool4x2 UIntToBool(UInt4x2 x) => default; /// @@ -710,7 +710,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool4x3", RequiresParametersMatching = true)] public static Bool4x3 UIntToBool(UInt4x3 x) => default; /// @@ -719,7 +719,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("bool4x4", RequiresParametersMatching = true)] public static Bool4x4 UIntToBool(UInt4x4 x) => default; /// @@ -728,7 +728,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("float", RequiresParametersMatching = true)] public static float BoolToFloat(bool x) => default; /// @@ -737,7 +737,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("float2", RequiresParametersMatching = true)] public static Float2 BoolToFloat(Bool2 x) => default; /// @@ -746,7 +746,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("float3", RequiresParametersMatching = true)] public static Float3 BoolToFloat(Bool3 x) => default; /// @@ -755,7 +755,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("float4", RequiresParametersMatching = true)] public static Float4 BoolToFloat(Bool4 x) => default; /// @@ -764,7 +764,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("float1x1", RequiresParametersMatching = true)] public static Float1x1 BoolToFloat(Bool1x1 x) => default; /// @@ -773,7 +773,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("float1x2", RequiresParametersMatching = true)] public static Float1x2 BoolToFloat(Bool1x2 x) => default; /// @@ -782,7 +782,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("float1x3", RequiresParametersMatching = true)] public static Float1x3 BoolToFloat(Bool1x3 x) => default; /// @@ -791,7 +791,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("float1x4", RequiresParametersMatching = true)] public static Float1x4 BoolToFloat(Bool1x4 x) => default; /// @@ -800,7 +800,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("float2x1", RequiresParametersMatching = true)] public static Float2x1 BoolToFloat(Bool2x1 x) => default; /// @@ -809,7 +809,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("float2x2", RequiresParametersMatching = true)] public static Float2x2 BoolToFloat(Bool2x2 x) => default; /// @@ -818,7 +818,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("float2x3", RequiresParametersMatching = true)] public static Float2x3 BoolToFloat(Bool2x3 x) => default; /// @@ -827,7 +827,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("float2x4", RequiresParametersMatching = true)] public static Float2x4 BoolToFloat(Bool2x4 x) => default; /// @@ -836,7 +836,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("float3x1", RequiresParametersMatching = true)] public static Float3x1 BoolToFloat(Bool3x1 x) => default; /// @@ -845,7 +845,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("float3x2", RequiresParametersMatching = true)] public static Float3x2 BoolToFloat(Bool3x2 x) => default; /// @@ -854,7 +854,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("float3x3", RequiresParametersMatching = true)] public static Float3x3 BoolToFloat(Bool3x3 x) => default; /// @@ -863,7 +863,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("float3x4", RequiresParametersMatching = true)] public static Float3x4 BoolToFloat(Bool3x4 x) => default; /// @@ -872,7 +872,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("float4x1", RequiresParametersMatching = true)] public static Float4x1 BoolToFloat(Bool4x1 x) => default; /// @@ -881,7 +881,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("float4x2", RequiresParametersMatching = true)] public static Float4x2 BoolToFloat(Bool4x2 x) => default; /// @@ -890,7 +890,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("float4x3", RequiresParametersMatching = true)] public static Float4x3 BoolToFloat(Bool4x3 x) => default; /// @@ -899,7 +899,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("float4x4", RequiresParametersMatching = true)] public static Float4x4 BoolToFloat(Bool4x4 x) => default; /// @@ -908,7 +908,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("double", RequiresParametersMatching = true)] public static double BoolToDouble(bool x) => default; /// @@ -917,7 +917,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("double2", RequiresParametersMatching = true)] public static Double2 BoolToDouble(Bool2 x) => default; /// @@ -926,7 +926,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("double3", RequiresParametersMatching = true)] public static Double3 BoolToDouble(Bool3 x) => default; /// @@ -935,7 +935,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("double4", RequiresParametersMatching = true)] public static Double4 BoolToDouble(Bool4 x) => default; /// @@ -944,7 +944,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("double1x1", RequiresParametersMatching = true)] public static Double1x1 BoolToDouble(Bool1x1 x) => default; /// @@ -953,7 +953,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("double1x2", RequiresParametersMatching = true)] public static Double1x2 BoolToDouble(Bool1x2 x) => default; /// @@ -962,7 +962,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("double1x3", RequiresParametersMatching = true)] public static Double1x3 BoolToDouble(Bool1x3 x) => default; /// @@ -971,7 +971,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("double1x4", RequiresParametersMatching = true)] public static Double1x4 BoolToDouble(Bool1x4 x) => default; /// @@ -980,7 +980,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("double2x1", RequiresParametersMatching = true)] public static Double2x1 BoolToDouble(Bool2x1 x) => default; /// @@ -989,7 +989,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("double2x2", RequiresParametersMatching = true)] public static Double2x2 BoolToDouble(Bool2x2 x) => default; /// @@ -998,7 +998,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("double2x3", RequiresParametersMatching = true)] public static Double2x3 BoolToDouble(Bool2x3 x) => default; /// @@ -1007,7 +1007,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("double2x4", RequiresParametersMatching = true)] public static Double2x4 BoolToDouble(Bool2x4 x) => default; /// @@ -1016,7 +1016,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("double3x1", RequiresParametersMatching = true)] public static Double3x1 BoolToDouble(Bool3x1 x) => default; /// @@ -1025,7 +1025,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("double3x2", RequiresParametersMatching = true)] public static Double3x2 BoolToDouble(Bool3x2 x) => default; /// @@ -1034,7 +1034,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("double3x3", RequiresParametersMatching = true)] public static Double3x3 BoolToDouble(Bool3x3 x) => default; /// @@ -1043,7 +1043,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("double3x4", RequiresParametersMatching = true)] public static Double3x4 BoolToDouble(Bool3x4 x) => default; /// @@ -1052,7 +1052,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("double4x1", RequiresParametersMatching = true)] public static Double4x1 BoolToDouble(Bool4x1 x) => default; /// @@ -1061,7 +1061,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("double4x2", RequiresParametersMatching = true)] public static Double4x2 BoolToDouble(Bool4x2 x) => default; /// @@ -1070,7 +1070,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("double4x3", RequiresParametersMatching = true)] public static Double4x3 BoolToDouble(Bool4x3 x) => default; /// @@ -1079,7 +1079,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("double4x4", RequiresParametersMatching = true)] public static Double4x4 BoolToDouble(Bool4x4 x) => default; /// @@ -1088,7 +1088,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("int", RequiresParametersMatching = true)] public static int BoolToInt(bool x) => default; /// @@ -1097,7 +1097,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("int2", RequiresParametersMatching = true)] public static Int2 BoolToInt(Bool2 x) => default; /// @@ -1106,7 +1106,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("int3", RequiresParametersMatching = true)] public static Int3 BoolToInt(Bool3 x) => default; /// @@ -1115,7 +1115,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("int4", RequiresParametersMatching = true)] public static Int4 BoolToInt(Bool4 x) => default; /// @@ -1124,7 +1124,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("int1x1", RequiresParametersMatching = true)] public static Int1x1 BoolToInt(Bool1x1 x) => default; /// @@ -1133,7 +1133,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("int1x2", RequiresParametersMatching = true)] public static Int1x2 BoolToInt(Bool1x2 x) => default; /// @@ -1142,7 +1142,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("int1x3", RequiresParametersMatching = true)] public static Int1x3 BoolToInt(Bool1x3 x) => default; /// @@ -1151,7 +1151,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("int1x4", RequiresParametersMatching = true)] public static Int1x4 BoolToInt(Bool1x4 x) => default; /// @@ -1160,7 +1160,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("int2x1", RequiresParametersMatching = true)] public static Int2x1 BoolToInt(Bool2x1 x) => default; /// @@ -1169,7 +1169,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("int2x2", RequiresParametersMatching = true)] public static Int2x2 BoolToInt(Bool2x2 x) => default; /// @@ -1178,7 +1178,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("int2x3", RequiresParametersMatching = true)] public static Int2x3 BoolToInt(Bool2x3 x) => default; /// @@ -1187,7 +1187,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("int2x4", RequiresParametersMatching = true)] public static Int2x4 BoolToInt(Bool2x4 x) => default; /// @@ -1196,7 +1196,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("int3x1", RequiresParametersMatching = true)] public static Int3x1 BoolToInt(Bool3x1 x) => default; /// @@ -1205,7 +1205,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("int3x2", RequiresParametersMatching = true)] public static Int3x2 BoolToInt(Bool3x2 x) => default; /// @@ -1214,7 +1214,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("int3x3", RequiresParametersMatching = true)] public static Int3x3 BoolToInt(Bool3x3 x) => default; /// @@ -1223,7 +1223,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("int3x4", RequiresParametersMatching = true)] public static Int3x4 BoolToInt(Bool3x4 x) => default; /// @@ -1232,7 +1232,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("int4x1", RequiresParametersMatching = true)] public static Int4x1 BoolToInt(Bool4x1 x) => default; /// @@ -1241,7 +1241,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("int4x2", RequiresParametersMatching = true)] public static Int4x2 BoolToInt(Bool4x2 x) => default; /// @@ -1250,7 +1250,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("int4x3", RequiresParametersMatching = true)] public static Int4x3 BoolToInt(Bool4x3 x) => default; /// @@ -1259,7 +1259,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("int4x4", RequiresParametersMatching = true)] public static Int4x4 BoolToInt(Bool4x4 x) => default; /// @@ -1268,7 +1268,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("uint", RequiresParametersMatching = true)] public static uint BoolToUInt(bool x) => default; /// @@ -1277,7 +1277,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("uint2", RequiresParametersMatching = true)] public static UInt2 BoolToUInt(Bool2 x) => default; /// @@ -1286,7 +1286,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("uint3", RequiresParametersMatching = true)] public static UInt3 BoolToUInt(Bool3 x) => default; /// @@ -1295,7 +1295,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("uint4", RequiresParametersMatching = true)] public static UInt4 BoolToUInt(Bool4 x) => default; /// @@ -1304,7 +1304,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("uint1x1", RequiresParametersMatching = true)] public static UInt1x1 BoolToUInt(Bool1x1 x) => default; /// @@ -1313,7 +1313,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("uint1x2", RequiresParametersMatching = true)] public static UInt1x2 BoolToUInt(Bool1x2 x) => default; /// @@ -1322,7 +1322,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("uint1x3", RequiresParametersMatching = true)] public static UInt1x3 BoolToUInt(Bool1x3 x) => default; /// @@ -1331,7 +1331,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("uint1x4", RequiresParametersMatching = true)] public static UInt1x4 BoolToUInt(Bool1x4 x) => default; /// @@ -1340,7 +1340,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("uint2x1", RequiresParametersMatching = true)] public static UInt2x1 BoolToUInt(Bool2x1 x) => default; /// @@ -1349,7 +1349,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("uint2x2", RequiresParametersMatching = true)] public static UInt2x2 BoolToUInt(Bool2x2 x) => default; /// @@ -1358,7 +1358,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("uint2x3", RequiresParametersMatching = true)] public static UInt2x3 BoolToUInt(Bool2x3 x) => default; /// @@ -1367,7 +1367,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("uint2x4", RequiresParametersMatching = true)] public static UInt2x4 BoolToUInt(Bool2x4 x) => default; /// @@ -1376,7 +1376,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("uint3x1", RequiresParametersMatching = true)] public static UInt3x1 BoolToUInt(Bool3x1 x) => default; /// @@ -1385,7 +1385,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("uint3x2", RequiresParametersMatching = true)] public static UInt3x2 BoolToUInt(Bool3x2 x) => default; /// @@ -1394,7 +1394,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("uint3x3", RequiresParametersMatching = true)] public static UInt3x3 BoolToUInt(Bool3x3 x) => default; /// @@ -1403,7 +1403,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("uint3x4", RequiresParametersMatching = true)] public static UInt3x4 BoolToUInt(Bool3x4 x) => default; /// @@ -1412,7 +1412,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("uint4x1", RequiresParametersMatching = true)] public static UInt4x1 BoolToUInt(Bool4x1 x) => default; /// @@ -1421,7 +1421,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("uint4x2", RequiresParametersMatching = true)] public static UInt4x2 BoolToUInt(Bool4x2 x) => default; /// @@ -1430,7 +1430,7 @@ partial class Hlsl /// 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")] + [HlslIntrinsicName("uint4x3", RequiresParametersMatching = true)] public static UInt4x3 BoolToUInt(Bool4x3 x) => default; /// @@ -1439,6 +1439,6 @@ partial class Hlsl /// 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")] + [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 index f49669fc..eeb80f9f 100644 --- a/src/ComputeSharp.Core/Intrinsics/Hlsl.Casts.tt +++ b/src/ComputeSharp.Core/Intrinsics/Hlsl.Casts.tt @@ -52,7 +52,7 @@ foreach (var intrinsic in intrinsics) /// 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()#>")] + [HlslIntrinsicName("<#=pair.Target.ToLower()#>", RequiresParametersMatching = true)] public static <#=pair.Target#> <#=intrinsic.Type#>ToBool(<#=pair.Source#> x) => default; <# } @@ -71,7 +71,7 @@ foreach (var intrinsic in intrinsics) /// 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()#>")] + [HlslIntrinsicName("<#=pair.Source.ToLower()#>", RequiresParametersMatching = true)] public static <#=pair.Source#> BoolTo<#=intrinsic.Type#>(<#=pair.Target#> x) => default; <# } From 8b2af5c62fbaee54fac16c82188ac88db02fa767 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 27 Aug 2022 03:04:17 +0200 Subject: [PATCH 9/9] Enable generators support for parameter matched intrinsics --- .../Mappings/HlslKnownMethods.cs | 99 +++++++++++++++++-- .../SyntaxRewriters/ShaderSourceRewriter.cs | 7 +- .../SyntaxRewriters/StaticFieldRewriter.cs | 8 +- 3 files changed, 103 insertions(+), 11 deletions(-) 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!)); } }