diff --git a/src/ComputeSharp.Core/ComputeSharp.Core.csproj b/src/ComputeSharp.Core/ComputeSharp.Core.csproj index 1ead8b6a..8aa6a689 100644 --- a/src/ComputeSharp.Core/ComputeSharp.Core.csproj +++ b/src/ComputeSharp.Core/ComputeSharp.Core.csproj @@ -23,6 +23,11 @@ + + Hlsl.Void.tt + True + True + True True @@ -131,6 +136,10 @@ + + Hlsl.Void.g.cs + TextTemplatingFileGenerator + TextTemplatingFileGenerator Hlsl.g.cs diff --git a/src/ComputeSharp.Core/Intrinsics/Hlsl.Void.g.cs b/src/ComputeSharp.Core/Intrinsics/Hlsl.Void.g.cs new file mode 100644 index 00000000..a58bc20b --- /dev/null +++ b/src/ComputeSharp.Core/Intrinsics/Hlsl.Void.g.cs @@ -0,0 +1,308 @@ +using ComputeSharp.Core.Intrinsics.Attributes; +using ComputeSharp.Exceptions; + +namespace ComputeSharp; + +/// +partial class Hlsl +{ + /// + /// Discards the current pixel if the specified value is less than zero. + /// + /// The specified value. + /// + /// Use the clip HLSL intrinsic function to simulate clipping planes if each component of the x parameter represents the distance from a plane. + /// Also, use the clip function to test for alpha behavior, as shown in the following example: + /// + /// Hlsl.Clip(color.A < 0.1f ? -1 : 1); + /// + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + /// + [HlslIntrinsicName("clip")] + public static void Clip(float x) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(Clip)}({typeof(float)})"); + + /// + /// Discards the current pixel if the specified value is less than zero. + /// + /// The specified value. + /// + /// Use the clip HLSL intrinsic function to simulate clipping planes if each component of the x parameter represents the distance from a plane. + /// Also, use the clip function to test for alpha behavior, as shown in the following example: + /// + /// Hlsl.Clip(color.A < 0.1f ? -1 : 1); + /// + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + /// + [HlslIntrinsicName("clip")] + public static void Clip(Float2 x) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(Clip)}({typeof(Float2)})"); + + /// + /// Discards the current pixel if the specified value is less than zero. + /// + /// The specified value. + /// + /// Use the clip HLSL intrinsic function to simulate clipping planes if each component of the x parameter represents the distance from a plane. + /// Also, use the clip function to test for alpha behavior, as shown in the following example: + /// + /// Hlsl.Clip(color.A < 0.1f ? -1 : 1); + /// + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + /// + [HlslIntrinsicName("clip")] + public static void Clip(Float3 x) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(Clip)}({typeof(Float3)})"); + + /// + /// Discards the current pixel if the specified value is less than zero. + /// + /// The specified value. + /// + /// Use the clip HLSL intrinsic function to simulate clipping planes if each component of the x parameter represents the distance from a plane. + /// Also, use the clip function to test for alpha behavior, as shown in the following example: + /// + /// Hlsl.Clip(color.A < 0.1f ? -1 : 1); + /// + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + /// + [HlslIntrinsicName("clip")] + public static void Clip(Float4 x) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(Clip)}({typeof(Float4)})"); + + /// + /// Discards the current pixel if the specified value is less than zero. + /// + /// The specified value. + /// + /// Use the clip HLSL intrinsic function to simulate clipping planes if each component of the x parameter represents the distance from a plane. + /// Also, use the clip function to test for alpha behavior, as shown in the following example: + /// + /// Hlsl.Clip(color.A < 0.1f ? -1 : 1); + /// + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + /// + [HlslIntrinsicName("clip")] + public static void Clip(Float1x1 x) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(Clip)}({typeof(Float1x1)})"); + + /// + /// Discards the current pixel if the specified value is less than zero. + /// + /// The specified value. + /// + /// Use the clip HLSL intrinsic function to simulate clipping planes if each component of the x parameter represents the distance from a plane. + /// Also, use the clip function to test for alpha behavior, as shown in the following example: + /// + /// Hlsl.Clip(color.A < 0.1f ? -1 : 1); + /// + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + /// + [HlslIntrinsicName("clip")] + public static void Clip(Float1x2 x) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(Clip)}({typeof(Float1x2)})"); + + /// + /// Discards the current pixel if the specified value is less than zero. + /// + /// The specified value. + /// + /// Use the clip HLSL intrinsic function to simulate clipping planes if each component of the x parameter represents the distance from a plane. + /// Also, use the clip function to test for alpha behavior, as shown in the following example: + /// + /// Hlsl.Clip(color.A < 0.1f ? -1 : 1); + /// + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + /// + [HlslIntrinsicName("clip")] + public static void Clip(Float1x3 x) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(Clip)}({typeof(Float1x3)})"); + + /// + /// Discards the current pixel if the specified value is less than zero. + /// + /// The specified value. + /// + /// Use the clip HLSL intrinsic function to simulate clipping planes if each component of the x parameter represents the distance from a plane. + /// Also, use the clip function to test for alpha behavior, as shown in the following example: + /// + /// Hlsl.Clip(color.A < 0.1f ? -1 : 1); + /// + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + /// + [HlslIntrinsicName("clip")] + public static void Clip(Float1x4 x) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(Clip)}({typeof(Float1x4)})"); + + /// + /// Discards the current pixel if the specified value is less than zero. + /// + /// The specified value. + /// + /// Use the clip HLSL intrinsic function to simulate clipping planes if each component of the x parameter represents the distance from a plane. + /// Also, use the clip function to test for alpha behavior, as shown in the following example: + /// + /// Hlsl.Clip(color.A < 0.1f ? -1 : 1); + /// + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + /// + [HlslIntrinsicName("clip")] + public static void Clip(Float2x1 x) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(Clip)}({typeof(Float2x1)})"); + + /// + /// Discards the current pixel if the specified value is less than zero. + /// + /// The specified value. + /// + /// Use the clip HLSL intrinsic function to simulate clipping planes if each component of the x parameter represents the distance from a plane. + /// Also, use the clip function to test for alpha behavior, as shown in the following example: + /// + /// Hlsl.Clip(color.A < 0.1f ? -1 : 1); + /// + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + /// + [HlslIntrinsicName("clip")] + public static void Clip(Float2x2 x) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(Clip)}({typeof(Float2x2)})"); + + /// + /// Discards the current pixel if the specified value is less than zero. + /// + /// The specified value. + /// + /// Use the clip HLSL intrinsic function to simulate clipping planes if each component of the x parameter represents the distance from a plane. + /// Also, use the clip function to test for alpha behavior, as shown in the following example: + /// + /// Hlsl.Clip(color.A < 0.1f ? -1 : 1); + /// + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + /// + [HlslIntrinsicName("clip")] + public static void Clip(Float2x3 x) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(Clip)}({typeof(Float2x3)})"); + + /// + /// Discards the current pixel if the specified value is less than zero. + /// + /// The specified value. + /// + /// Use the clip HLSL intrinsic function to simulate clipping planes if each component of the x parameter represents the distance from a plane. + /// Also, use the clip function to test for alpha behavior, as shown in the following example: + /// + /// Hlsl.Clip(color.A < 0.1f ? -1 : 1); + /// + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + /// + [HlslIntrinsicName("clip")] + public static void Clip(Float2x4 x) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(Clip)}({typeof(Float2x4)})"); + + /// + /// Discards the current pixel if the specified value is less than zero. + /// + /// The specified value. + /// + /// Use the clip HLSL intrinsic function to simulate clipping planes if each component of the x parameter represents the distance from a plane. + /// Also, use the clip function to test for alpha behavior, as shown in the following example: + /// + /// Hlsl.Clip(color.A < 0.1f ? -1 : 1); + /// + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + /// + [HlslIntrinsicName("clip")] + public static void Clip(Float3x1 x) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(Clip)}({typeof(Float3x1)})"); + + /// + /// Discards the current pixel if the specified value is less than zero. + /// + /// The specified value. + /// + /// Use the clip HLSL intrinsic function to simulate clipping planes if each component of the x parameter represents the distance from a plane. + /// Also, use the clip function to test for alpha behavior, as shown in the following example: + /// + /// Hlsl.Clip(color.A < 0.1f ? -1 : 1); + /// + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + /// + [HlslIntrinsicName("clip")] + public static void Clip(Float3x2 x) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(Clip)}({typeof(Float3x2)})"); + + /// + /// Discards the current pixel if the specified value is less than zero. + /// + /// The specified value. + /// + /// Use the clip HLSL intrinsic function to simulate clipping planes if each component of the x parameter represents the distance from a plane. + /// Also, use the clip function to test for alpha behavior, as shown in the following example: + /// + /// Hlsl.Clip(color.A < 0.1f ? -1 : 1); + /// + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + /// + [HlslIntrinsicName("clip")] + public static void Clip(Float3x3 x) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(Clip)}({typeof(Float3x3)})"); + + /// + /// Discards the current pixel if the specified value is less than zero. + /// + /// The specified value. + /// + /// Use the clip HLSL intrinsic function to simulate clipping planes if each component of the x parameter represents the distance from a plane. + /// Also, use the clip function to test for alpha behavior, as shown in the following example: + /// + /// Hlsl.Clip(color.A < 0.1f ? -1 : 1); + /// + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + /// + [HlslIntrinsicName("clip")] + public static void Clip(Float3x4 x) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(Clip)}({typeof(Float3x4)})"); + + /// + /// Discards the current pixel if the specified value is less than zero. + /// + /// The specified value. + /// + /// Use the clip HLSL intrinsic function to simulate clipping planes if each component of the x parameter represents the distance from a plane. + /// Also, use the clip function to test for alpha behavior, as shown in the following example: + /// + /// Hlsl.Clip(color.A < 0.1f ? -1 : 1); + /// + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + /// + [HlslIntrinsicName("clip")] + public static void Clip(Float4x1 x) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(Clip)}({typeof(Float4x1)})"); + + /// + /// Discards the current pixel if the specified value is less than zero. + /// + /// The specified value. + /// + /// Use the clip HLSL intrinsic function to simulate clipping planes if each component of the x parameter represents the distance from a plane. + /// Also, use the clip function to test for alpha behavior, as shown in the following example: + /// + /// Hlsl.Clip(color.A < 0.1f ? -1 : 1); + /// + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + /// + [HlslIntrinsicName("clip")] + public static void Clip(Float4x2 x) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(Clip)}({typeof(Float4x2)})"); + + /// + /// Discards the current pixel if the specified value is less than zero. + /// + /// The specified value. + /// + /// Use the clip HLSL intrinsic function to simulate clipping planes if each component of the x parameter represents the distance from a plane. + /// Also, use the clip function to test for alpha behavior, as shown in the following example: + /// + /// Hlsl.Clip(color.A < 0.1f ? -1 : 1); + /// + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + /// + [HlslIntrinsicName("clip")] + public static void Clip(Float4x3 x) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(Clip)}({typeof(Float4x3)})"); + + /// + /// Discards the current pixel if the specified value is less than zero. + /// + /// The specified value. + /// + /// Use the clip HLSL intrinsic function to simulate clipping planes if each component of the x parameter represents the distance from a plane. + /// Also, use the clip function to test for alpha behavior, as shown in the following example: + /// + /// Hlsl.Clip(color.A < 0.1f ? -1 : 1); + /// + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + /// + [HlslIntrinsicName("clip")] + public static void Clip(Float4x4 x) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(Clip)}({typeof(Float4x4)})"); +} diff --git a/src/ComputeSharp.Core/Intrinsics/Hlsl.Void.tt b/src/ComputeSharp.Core/Intrinsics/Hlsl.Void.tt new file mode 100644 index 00000000..aedffb22 --- /dev/null +++ b/src/ComputeSharp.Core/Intrinsics/Hlsl.Void.tt @@ -0,0 +1,71 @@ +<#@include file="Hlsl.Void.ttinclude" #> +using ComputeSharp.Core.Intrinsics.Attributes; +using ComputeSharp.Exceptions; + +namespace ComputeSharp; + +/// +partial class Hlsl +{ +<# +PushIndent(" "); + +bool isFirst = true; + +foreach (var intrinsic in Intrinsics) +{ + foreach (var overload in intrinsic.Overloads) + { + if (isFirst) isFirst = false; + else WriteLine(""); + + WriteLine("/// "); + WriteLine($"/// {intrinsic.Summary}"); + WriteLine("/// "); + + foreach (var param in intrinsic.Parameters) + { + WriteLine($"/// {param.Info}"); + } + + if (intrinsic.Remarks.Length > 0) + { + var lines = intrinsic.Remarks.Replace("\r", "").Split('\n'); + + WriteLine("/// "); + + foreach (var line in lines) + { + string trimmedLine = line.Trim(); + + if (trimmedLine.Length > 0) + { + WriteLine($"/// {trimmedLine}"); + } + } + + WriteLine("/// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior."); + WriteLine("/// "); + } + else + { + WriteLine("/// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior."); + } + + WriteLine($"[HlslIntrinsicName(\"{intrinsic.HlslName}\")]"); + + Write($"public static void {intrinsic.Name}("); + Write(string.Join(", ", intrinsic.Parameters.Zip(overload, (a, b) => $"{(a.IsOut ? "out " : "")}{b} {a.Name}"))); + Write(")"); + + Write(" => throw new InvalidExecutionContextException("); + + var parameters = string.Join(", ", overload.Select(t => $"{{typeof({t})}}")); + + WriteLine($"$\"{{typeof(Hlsl)}}.{{nameof({intrinsic.Name})}}({parameters})\");"); + } +} + +PopIndent(); +#> +} diff --git a/src/ComputeSharp.Core/Intrinsics/Hlsl.Void.ttinclude b/src/ComputeSharp.Core/Intrinsics/Hlsl.Void.ttinclude new file mode 100644 index 00000000..90dc8adf --- /dev/null +++ b/src/ComputeSharp.Core/Intrinsics/Hlsl.Void.ttinclude @@ -0,0 +1,51 @@ +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ assembly name="System.Core" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Text" #> +<#@ import namespace="System.Text.RegularExpressions" #> +<#@ import namespace="System.Collections.Generic" #> +<#@ output extension=".g.cs"#> +<# +var Intrinsics = new[] +{ + new + { + Name = "Clip", + HlslName = "clip", + Summary = "Discards the current pixel if the specified value is less than zero.", + Remarks = @" + Use the clip HLSL intrinsic function to simulate clipping planes if each component of the x parameter represents the distance from a plane. + Also, use the clip function to test for alpha behavior, as shown in the following example: + + Hlsl.Clip(color.A < 0.1f ? -1 : 1); + ", + Parameters = new[] + { + new { IsOut = false, IsRef = false, Name = "x", Info = "The specified value." } + }, + Overloads = new[] + { + new[] { "float" }, + new[] { "Float2" }, + new[] { "Float3" }, + new[] { "Float4" }, + new[] { "Float1x1" }, + new[] { "Float1x2" }, + new[] { "Float1x3" }, + new[] { "Float1x4" }, + new[] { "Float2x1" }, + new[] { "Float2x2" }, + new[] { "Float2x3" }, + new[] { "Float2x4" }, + new[] { "Float3x1" }, + new[] { "Float3x2" }, + new[] { "Float3x3" }, + new[] { "Float3x4" }, + new[] { "Float4x1" }, + new[] { "Float4x2" }, + new[] { "Float4x3" }, + new[] { "Float4x4" } + } + } +}; +#> \ No newline at end of file diff --git a/src/ComputeSharp.Core/Intrinsics/Hlsl.g.cs b/src/ComputeSharp.Core/Intrinsics/Hlsl.g.cs index e74bba24..931bfcea 100644 --- a/src/ComputeSharp.Core/Intrinsics/Hlsl.g.cs +++ b/src/ComputeSharp.Core/Intrinsics/Hlsl.g.cs @@ -4,7 +4,7 @@ using ComputeSharp.Exceptions; namespace ComputeSharp; /// -public static partial class Hlsl +partial class Hlsl { /// /// Returns the absolute value of the specified value. diff --git a/src/ComputeSharp.Core/Intrinsics/Hlsl.tt b/src/ComputeSharp.Core/Intrinsics/Hlsl.tt index 676840f0..65c93f07 100644 --- a/src/ComputeSharp.Core/Intrinsics/Hlsl.tt +++ b/src/ComputeSharp.Core/Intrinsics/Hlsl.tt @@ -5,7 +5,7 @@ using ComputeSharp.Exceptions; namespace ComputeSharp; /// -public static partial class Hlsl +partial class Hlsl { <# PushIndent(" ");