diff --git a/src/ComputeSharp.Core/Intrinsics/Hlsl.Void.g.cs b/src/ComputeSharp.Core/Intrinsics/Hlsl.Void.g.cs index a58bc20b..bf15e76d 100644 --- a/src/ComputeSharp.Core/Intrinsics/Hlsl.Void.g.cs +++ b/src/ComputeSharp.Core/Intrinsics/Hlsl.Void.g.cs @@ -6,6 +6,16 @@ namespace ComputeSharp; /// partial class Hlsl { + /// + /// Submits an error message to the information queue and terminates the current draw or dispatch call being executed. + /// + /// + /// This operation does nothing on rasterizers that do not support it. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + /// + [HlslIntrinsicName("abort")] + public static void Abort() => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(Abort)}()"); + /// /// Discards the current pixel if the specified value is less than zero. /// @@ -305,4 +315,268 @@ partial class Hlsl /// [HlslIntrinsicName("clip")] public static void Clip(Float4x4 x) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(Clip)}({typeof(Float4x4)})"); + + /// + /// Performs a guaranteed atomic add of a value to a destination. + /// + /// The destination value. + /// The input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedAdd(int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAdd)}({typeof(int)}, {typeof(int)})"); + + /// + /// Performs a guaranteed atomic add of a value to a destination. + /// + /// The destination value. + /// The input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedAdd(uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAdd)}({typeof(uint)}, {typeof(uint)})"); + + /// + /// Performs a guaranteed atomic add of a value to a destination. + /// + /// The destination value. + /// The input value. + /// The original input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedAdd(int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAdd)}({typeof(int)}, {typeof(int)}, {typeof(int)})"); + + /// + /// Performs a guaranteed atomic add of a value to a destination. + /// + /// The destination value. + /// The input value. + /// The original input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedAdd(uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAdd)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})"); + + /// + /// Performs a guaranteed atomic and of a value to a destination. + /// + /// The destination value. + /// The input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedAnd(int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAnd)}({typeof(int)}, {typeof(int)})"); + + /// + /// Performs a guaranteed atomic and of a value to a destination. + /// + /// The destination value. + /// The input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedAnd(uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAnd)}({typeof(uint)}, {typeof(uint)})"); + + /// + /// Performs a guaranteed atomic and of a value to a destination. + /// + /// The destination value. + /// The input value. + /// The original input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedAnd(int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAnd)}({typeof(int)}, {typeof(int)}, {typeof(int)})"); + + /// + /// Performs a guaranteed atomic and of a value to a destination. + /// + /// The destination value. + /// The input value. + /// The original input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedAnd(uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAnd)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})"); + + /// + /// Atomically compares the destination with the comparison value. If they are identical, the destination + /// is overwritten with the input value. The original value is set to the destination's original value. + /// + /// The destination value. + /// The comparison value. + /// The input value. + /// The original input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedCompareExchange(int destination, int comparison, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedCompareExchange)}({typeof(int)}, {typeof(int)}, {typeof(int)}, {typeof(int)})"); + + /// + /// Atomically compares the destination with the comparison value. If they are identical, the destination + /// is overwritten with the input value. The original value is set to the destination's original value. + /// + /// The destination value. + /// The comparison value. + /// The input value. + /// The original input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedCompareExchange(uint destination, uint comparison, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedCompareExchange)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)}, {typeof(uint)})"); + + /// + /// Atomically compares the destination to the comparison value. If they + /// are identical, the destination is overwritten with the input value. + /// + /// The destination value. + /// The comparison value. + /// The input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedCompareStore(int destination, int comparison, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedCompareStore)}({typeof(int)}, {typeof(int)}, {typeof(int)})"); + + /// + /// Atomically compares the destination to the comparison value. If they + /// are identical, the destination is overwritten with the input value. + /// + /// The destination value. + /// The comparison value. + /// The input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedCompareStore(uint destination, uint comparison, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedCompareStore)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})"); + + /// + /// Assigns value to dest and returns the original value. + /// + /// The destination value. + /// The input value. + /// The original input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedExchange(int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedExchange)}({typeof(int)}, {typeof(int)}, {typeof(int)})"); + + /// + /// Assigns value to dest and returns the original value. + /// + /// The destination value. + /// The input value. + /// The original input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedExchange(uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedExchange)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})"); + + /// + /// Performs a guaranteed atomic max. + /// + /// The destination value. + /// The input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedMax(int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMax)}({typeof(int)}, {typeof(int)})"); + + /// + /// Performs a guaranteed atomic max. + /// + /// The destination value. + /// The input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedMax(uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMax)}({typeof(uint)}, {typeof(uint)})"); + + /// + /// Performs a guaranteed atomic max. + /// + /// The destination value. + /// The input value. + /// The original input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedMax(int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMax)}({typeof(int)}, {typeof(int)}, {typeof(int)})"); + + /// + /// Performs a guaranteed atomic max. + /// + /// The destination value. + /// The input value. + /// The original input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedMax(uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMax)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})"); + + /// + /// Performs a guaranteed atomic min. + /// + /// The destination value. + /// The input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedMin(int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMin)}({typeof(int)}, {typeof(int)})"); + + /// + /// Performs a guaranteed atomic min. + /// + /// The destination value. + /// The input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedMin(uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMin)}({typeof(uint)}, {typeof(uint)})"); + + /// + /// Performs a guaranteed atomic min. + /// + /// The destination value. + /// The input value. + /// The original input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedMin(int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMin)}({typeof(int)}, {typeof(int)}, {typeof(int)})"); + + /// + /// Performs a guaranteed atomic min. + /// + /// The destination value. + /// The input value. + /// The original input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedMin(uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMin)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})"); + + /// + /// Performs a guaranteed atomic or. + /// + /// The destination value. + /// The input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedOr(int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedOr)}({typeof(int)}, {typeof(int)})"); + + /// + /// Performs a guaranteed atomic or. + /// + /// The destination value. + /// The input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedOr(uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedOr)}({typeof(uint)}, {typeof(uint)})"); + + /// + /// Performs a guaranteed atomic or. + /// + /// The destination value. + /// The input value. + /// The original input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedOr(int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedOr)}({typeof(int)}, {typeof(int)}, {typeof(int)})"); + + /// + /// Performs a guaranteed atomic or. + /// + /// The destination value. + /// The input value. + /// The original input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedOr(uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedOr)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})"); + + /// + /// Performs a guaranteed atomic xor. + /// + /// The destination value. + /// The input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedXor(int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedXor)}({typeof(int)}, {typeof(int)})"); + + /// + /// Performs a guaranteed atomic xor. + /// + /// The destination value. + /// The input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedXor(uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedXor)}({typeof(uint)}, {typeof(uint)})"); + + /// + /// Performs a guaranteed atomic xor. + /// + /// The destination value. + /// The input value. + /// The original input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedXor(int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedXor)}({typeof(int)}, {typeof(int)}, {typeof(int)})"); + + /// + /// Performs a guaranteed atomic xor. + /// + /// The destination value. + /// The input value. + /// The original input value. + /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. + public static void InterlockedXor(uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedXor)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})"); } diff --git a/src/ComputeSharp.Core/Intrinsics/Hlsl.Void.tt b/src/ComputeSharp.Core/Intrinsics/Hlsl.Void.tt index aedffb22..87acc1d4 100644 --- a/src/ComputeSharp.Core/Intrinsics/Hlsl.Void.tt +++ b/src/ComputeSharp.Core/Intrinsics/Hlsl.Void.tt @@ -20,10 +20,20 @@ foreach (var intrinsic in Intrinsics) else WriteLine(""); WriteLine("/// "); - WriteLine($"/// {intrinsic.Summary}"); + + foreach (var line in intrinsic.Summary.Replace("\r", "").Split('\n')) + { + string trimmedLine = line.Trim(); + + if (trimmedLine.Length > 0) + { + WriteLine($"/// {line.Trim()}"); + } + } + WriteLine("/// "); - foreach (var param in intrinsic.Parameters) + foreach (var param in intrinsic.Parameters.Where(p => p.Name is not "")) { WriteLine($"/// {param.Info}"); } @@ -52,15 +62,18 @@ foreach (var intrinsic in Intrinsics) 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}\")]"); + if (intrinsic.Name != intrinsic.HlslName) + { + 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(string.Join(", ", intrinsic.Parameters.Where(p => p.Name is not "").Zip(overload, (a, b) => $"{(a.IsOut ? "out " : "")}{b} {a.Name}"))); Write(")"); Write(" => throw new InvalidExecutionContextException("); - var parameters = string.Join(", ", overload.Select(t => $"{{typeof({t})}}")); + var parameters = string.Join(", ", overload.Where(o => o.Length > 0).Select(t => $"{{typeof({t})}}")); WriteLine($"$\"{{typeof(Hlsl)}}.{{nameof({intrinsic.Name})}}({parameters})\");"); } diff --git a/src/ComputeSharp.Core/Intrinsics/Hlsl.Void.ttinclude b/src/ComputeSharp.Core/Intrinsics/Hlsl.Void.ttinclude index 90dc8adf..0a4939c8 100644 --- a/src/ComputeSharp.Core/Intrinsics/Hlsl.Void.ttinclude +++ b/src/ComputeSharp.Core/Intrinsics/Hlsl.Void.ttinclude @@ -8,6 +8,18 @@ <# var Intrinsics = new[] { + new + { + Name = "Abort", + HlslName = "abort", + Summary = "Submits an error message to the information queue and terminates the current draw or dispatch call being executed.", + Remarks = "This operation does nothing on rasterizers that do not support it.", + Parameters = new[] + { + new { IsOut = false, IsRef = false, Name = "", Info = "" } + }, + Overloads = new[] { new string[0] } + }, new { Name = "Clip", @@ -46,6 +58,275 @@ var Intrinsics = new[] new[] { "Float4x3" }, new[] { "Float4x4" } } + }, + new + { + Name = "InterlockedAdd", + HlslName = "InterlockedAdd", + Summary = "Performs a guaranteed atomic add of a value to a destination.", + Remarks = "", + Parameters = new[] + { + new { IsOut = false, IsRef = true, Name = "destination", Info = "The destination value." }, + new { IsOut = false, IsRef = false, Name = "value", Info = "The input value." } + }, + Overloads = new[] + { + new[] { "int", "int" }, + new[] { "uint", "uint" } + } + }, + new + { + Name = "InterlockedAdd", + HlslName = "InterlockedAdd", + Summary = "Performs a guaranteed atomic add of a value to a destination.", + Remarks = "", + Parameters = new[] + { + new { IsOut = false, IsRef = true, Name = "destination", Info = "The destination value." }, + new { IsOut = false, IsRef = false, Name = "value", Info = "The input value." }, + new { IsOut = true, IsRef = false, Name = "original", Info = "The original input value." } + }, + Overloads = new[] + { + new[] { "int", "int", "int" }, + new[] { "uint", "uint", "uint" } + } + }, + new + { + Name = "InterlockedAnd", + HlslName = "InterlockedAnd", + Summary = "Performs a guaranteed atomic and of a value to a destination.", + Remarks = "", + Parameters = new[] + { + new { IsOut = false, IsRef = true, Name = "destination", Info = "The destination value." }, + new { IsOut = false, IsRef = false, Name = "value", Info = "The input value." } + }, + Overloads = new[] + { + new[] { "int", "int" }, + new[] { "uint", "uint" } + } + }, + new + { + Name = "InterlockedAnd", + HlslName = "InterlockedAnd", + Summary = "Performs a guaranteed atomic and of a value to a destination.", + Remarks = "", + Parameters = new[] + { + new { IsOut = false, IsRef = true, Name = "destination", Info = "The destination value." }, + new { IsOut = false, IsRef = false, Name = "value", Info = "The input value." }, + new { IsOut = true, IsRef = false, Name = "original", Info = "The original input value." } + }, + Overloads = new[] + { + new[] { "int", "int", "int" }, + new[] { "uint", "uint", "uint" } + } + }, + new + { + Name = "InterlockedCompareExchange", + HlslName = "InterlockedCompareExchange", + Summary = @" + Atomically compares the destination with the comparison value. If they are identical, the destination + is overwritten with the input value. The original value is set to the destination's original value.", + Remarks = "", + Parameters = new[] + { + new { IsOut = false, IsRef = true, Name = "destination", Info = "The destination value." }, + new { IsOut = false, IsRef = false, Name = "comparison", Info = "The comparison value." }, + new { IsOut = false, IsRef = false, Name = "value", Info = "The input value." }, + new { IsOut = true, IsRef = false, Name = "original", Info = "The original input value." } + }, + Overloads = new[] + { + new[] { "int", "int", "int", "int" }, + new[] { "uint", "uint", "uint", "uint" } + } + }, + new + { + Name = "InterlockedCompareStore", + HlslName = "InterlockedCompareStore", + Summary = @" + Atomically compares the destination to the comparison value. If they + are identical, the destination is overwritten with the input value.", + Remarks = "", + Parameters = new[] + { + new { IsOut = false, IsRef = true, Name = "destination", Info = "The destination value." }, + new { IsOut = false, IsRef = false, Name = "comparison", Info = "The comparison value." }, + new { IsOut = false, IsRef = false, Name = "value", Info = "The input value." } + }, + Overloads = new[] + { + new[] { "int", "int", "int" }, + new[] { "uint", "uint", "uint" } + } + }, + new + { + Name = "InterlockedExchange", + HlslName = "InterlockedExchange", + Summary = "Assigns value to dest and returns the original value.", + Remarks = "", + Parameters = new[] + { + new { IsOut = false, IsRef = true, Name = "destination", Info = "The destination value." }, + new { IsOut = false, IsRef = false, Name = "value", Info = "The input value." }, + new { IsOut = true, IsRef = false, Name = "original", Info = "The original input value." } + }, + Overloads = new[] + { + new[] { "int", "int", "int" }, + new[] { "uint", "uint", "uint" } + } + }, + new + { + Name = "InterlockedMax", + HlslName = "InterlockedMax", + Summary = "Performs a guaranteed atomic max.", + Remarks = "", + Parameters = new[] + { + new { IsOut = false, IsRef = true, Name = "destination", Info = "The destination value." }, + new { IsOut = false, IsRef = false, Name = "value", Info = "The input value." } + }, + Overloads = new[] + { + new[] { "int", "int" }, + new[] { "uint", "uint" } + } + }, + new + { + Name = "InterlockedMax", + HlslName = "InterlockedMax", + Summary = "Performs a guaranteed atomic max.", + Remarks = "", + Parameters = new[] + { + new { IsOut = false, IsRef = true, Name = "destination", Info = "The destination value." }, + new { IsOut = false, IsRef = false, Name = "value", Info = "The input value." }, + new { IsOut = true, IsRef = false, Name = "original", Info = "The original input value." } + }, + Overloads = new[] + { + new[] { "int", "int", "int" }, + new[] { "uint", "uint", "uint" } + } + }, + new + { + Name = "InterlockedMin", + HlslName = "InterlockedMin", + Summary = "Performs a guaranteed atomic min.", + Remarks = "", + Parameters = new[] + { + new { IsOut = false, IsRef = true, Name = "destination", Info = "The destination value." }, + new { IsOut = false, IsRef = false, Name = "value", Info = "The input value." } + }, + Overloads = new[] + { + new[] { "int", "int" }, + new[] { "uint", "uint" } + } + }, + new + { + Name = "InterlockedMin", + HlslName = "InterlockedMin", + Summary = "Performs a guaranteed atomic min.", + Remarks = "", + Parameters = new[] + { + new { IsOut = false, IsRef = true, Name = "destination", Info = "The destination value." }, + new { IsOut = false, IsRef = false, Name = "value", Info = "The input value." }, + new { IsOut = true, IsRef = false, Name = "original", Info = "The original input value." } + }, + Overloads = new[] + { + new[] { "int", "int", "int" }, + new[] { "uint", "uint", "uint" } + } + }, + new + { + Name = "InterlockedOr", + HlslName = "InterlockedOr", + Summary = "Performs a guaranteed atomic or.", + Remarks = "", + Parameters = new[] + { + new { IsOut = false, IsRef = true, Name = "destination", Info = "The destination value." }, + new { IsOut = false, IsRef = false, Name = "value", Info = "The input value." } + }, + Overloads = new[] + { + new[] { "int", "int" }, + new[] { "uint", "uint" } + } + }, + new + { + Name = "InterlockedOr", + HlslName = "InterlockedOr", + Summary = "Performs a guaranteed atomic or.", + Remarks = "", + Parameters = new[] + { + new { IsOut = false, IsRef = true, Name = "destination", Info = "The destination value." }, + new { IsOut = false, IsRef = false, Name = "value", Info = "The input value." }, + new { IsOut = true, IsRef = false, Name = "original", Info = "The original input value." } + }, + Overloads = new[] + { + new[] { "int", "int", "int" }, + new[] { "uint", "uint", "uint" } + } + }, + new + { + Name = "InterlockedXor", + HlslName = "InterlockedXor", + Summary = "Performs a guaranteed atomic xor.", + Remarks = "", + Parameters = new[] + { + new { IsOut = false, IsRef = true, Name = "destination", Info = "The destination value." }, + new { IsOut = false, IsRef = false, Name = "value", Info = "The input value." } + }, + Overloads = new[] + { + new[] { "int", "int" }, + new[] { "uint", "uint" } + } + }, + new + { + Name = "InterlockedXor", + HlslName = "InterlockedXor", + Summary = "Performs a guaranteed atomic xor.", + Remarks = "", + Parameters = new[] + { + new { IsOut = false, IsRef = true, Name = "destination", Info = "The destination value." }, + new { IsOut = false, IsRef = false, Name = "value", Info = "The input value." }, + new { IsOut = true, IsRef = false, Name = "original", Info = "The original input value." } + }, + Overloads = new[] + { + new[] { "int", "int", "int" }, + new[] { "uint", "uint", "uint" } + } } }; #> \ No newline at end of file diff --git a/src/ComputeSharp.Core/Intrinsics/Hlsl.cs b/src/ComputeSharp.Core/Intrinsics/Hlsl.cs index a09a054b..3687dfc2 100644 --- a/src/ComputeSharp.Core/Intrinsics/Hlsl.cs +++ b/src/ComputeSharp.Core/Intrinsics/Hlsl.cs @@ -8,13 +8,6 @@ namespace ComputeSharp; /// public static partial class Hlsl { - /// - /// Submits an error message to the information queue and terminates the current draw or dispatch call being executed. - /// - /// This operation does nothing on rasterizers that do not support it. - [HlslIntrinsicName("abort")] - public static void Abort() => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(Abort)}()"); - /// /// Blocks execution of all threads in a group until all memory accesses have been completed. /// @@ -61,270 +54,6 @@ public static 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. public static void GroupMemoryBarrierWithGroupSync() => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(GroupMemoryBarrierWithGroupSync)}()"); - /// - /// Performs a guaranteed atomic add of a value to a destination. - /// - /// The destination value. - /// The input value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedAdd(ref int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAdd)}({typeof(int)}, {typeof(int)})"); - - /// - /// Performs a guaranteed atomic add of a value to a destination. - /// - /// The destination value. - /// The input value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedAdd(ref uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAdd)}({typeof(uint)}, {typeof(uint)})"); - - /// - /// Performs a guaranteed atomic add of a value to a destination. - /// - /// The destination value. - /// The input value. - /// The original input value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedAdd(ref int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAdd)}({typeof(int)}, {typeof(int)}, {typeof(int)})"); - - /// - /// Performs a guaranteed atomic add of a value to a destination. - /// - /// The destination value. - /// The input value. - /// The original input value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedAdd(ref uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAdd)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})"); - - /// - /// Performs a guaranteed atomic and of a value to a destination. - /// - /// The destination value. - /// The input value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedAnd(ref int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAnd)}({typeof(int)}, {typeof(int)})"); - - /// - /// Performs a guaranteed atomic and of a value to a destination. - /// - /// The destination value. - /// The input value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedAnd(ref uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAnd)}({typeof(uint)}, {typeof(uint)})"); - - /// - /// Performs a guaranteed atomic and of a value to a destination. - /// - /// The destination value. - /// The input value. - /// The original input value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedAnd(ref int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAnd)}({typeof(int)}, {typeof(int)}, {typeof(int)})"); - - /// - /// Performs a guaranteed atomic and of a value to a destination. - /// - /// The destination value. - /// The input value. - /// The original input value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedAnd(ref uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAnd)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})"); - - /// - /// Atomically compares the destination with the comparison value. If they are identical, the destination - /// is overwritten with the input value. The original value is set to the destination's original value. - /// - /// The destination value. - /// The comparison value. - /// The input value. - /// The original value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedCompareExchange(ref int destination, int comparison, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedCompareExchange)}({typeof(int)}, {typeof(int)}, {typeof(int)}, {typeof(int)})"); - - /// - /// Atomically compares the destination with the comparison value. If they are identical, the destination - /// is overwritten with the input value. The original value is set to the destination's original value. - /// - /// The destination value. - /// The comparison value. - /// The input value. - /// The original value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedCompareExchange(ref uint destination, uint comparison, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedCompareExchange)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)}, {typeof(uint)})"); - - /// - /// Atomically compares the destination to the comparison value. If they - /// are identical, the destination is overwritten with the input value. - /// - /// The destination value. - /// The comparison value. - /// The input value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedCompareStore(ref int destination, int comparison, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedCompareStore)}({typeof(int)}, {typeof(int)}, {typeof(int)})"); - - /// - /// Atomically compares the destination to the comparison value. If they - /// are identical, the destination is overwritten with the input value. - /// - /// The destination value. - /// The comparison value. - /// The input value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedCompareStore(ref uint destination, uint comparison, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedCompareStore)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})"); - - /// - /// Assigns value to dest and returns the original value. - /// - /// The destination value. - /// The input value. - /// The original value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedExchange(ref int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedExchange)}({typeof(int)}, {typeof(int)}, {typeof(int)})"); - - /// - /// Assigns value to dest and returns the original value. - /// - /// The destination value. - /// The input value. - /// The original value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedExchange(ref uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedExchange)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})"); - - /// - /// Performs a guaranteed atomic max. - /// - /// The destination value. - /// The input value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedMax(ref int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMax)}({typeof(int)}, {typeof(int)})"); - - /// - /// Performs a guaranteed atomic max. - /// - /// The destination value. - /// The input value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedMax(ref uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMax)}({typeof(uint)}, {typeof(uint)})"); - - /// - /// Performs a guaranteed atomic max. - /// - /// The destination value. - /// The input value. - /// The original value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedMax(ref int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMax)}({typeof(int)}, {typeof(int)}, {typeof(int)})"); - - /// - /// Performs a guaranteed atomic max. - /// - /// The destination value. - /// The input value. - /// The original value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedMax(ref uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMax)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})"); - - /// - /// Performs a guaranteed atomic min. - /// - /// The destination value. - /// The input value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedMin(ref int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMin)}({typeof(int)}, {typeof(int)})"); - - /// - /// Performs a guaranteed atomic min. - /// - /// The destination value. - /// The input value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedMin(ref uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMin)}({typeof(uint)}, {typeof(uint)})"); - - /// - /// Performs a guaranteed atomic min. - /// - /// The destination value. - /// The input value. - /// The original value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedMin(ref int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMin)}({typeof(int)}, {typeof(int)}, {typeof(int)})"); - - /// - /// Performs a guaranteed atomic min. - /// - /// The destination value. - /// The input value. - /// The original value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedMin(ref uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMin)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})"); - - /// - /// Performs a guaranteed atomic or. - /// - /// The destination value. - /// The input value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedOr(ref int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedOr)}({typeof(int)}, {typeof(int)})"); - - /// - /// Performs a guaranteed atomic or. - /// - /// The destination value. - /// The input value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedOr(ref uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedOr)}({typeof(uint)}, {typeof(uint)})"); - - /// - /// Performs a guaranteed atomic or. - /// - /// The destination value. - /// The input value. - /// The original value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedOr(ref int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedOr)}({typeof(int)}, {typeof(int)}, {typeof(int)})"); - - /// - /// Performs a guaranteed atomic or. - /// - /// The destination value. - /// The input value. - /// The original value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedOr(ref uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedOr)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})"); - - /// - /// Performs a guaranteed atomic xor. - /// - /// The destination value. - /// The input value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedXor(ref int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedXor)}({typeof(int)}, {typeof(int)})"); - - /// - /// Performs a guaranteed atomic xor. - /// - /// The destination value. - /// The input value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedXor(ref uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedXor)}({typeof(uint)}, {typeof(uint)})"); - - /// - /// Performs a guaranteed atomic xor. - /// - /// The destination value. - /// The input value. - /// The original value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedXor(ref int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedXor)}({typeof(int)}, {typeof(int)}, {typeof(int)})"); - - /// - /// Performs a guaranteed atomic xor. - /// - /// The destination value. - /// The input value. - /// The original value. - /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. - public static void InterlockedXor(ref uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedXor)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})"); - /// /// Returns a lighting coefficient vector. /// diff --git a/src/ComputeSharp.Core/Intrinsics/Hlsl.tt b/src/ComputeSharp.Core/Intrinsics/Hlsl.tt index 7e1b863f..543defc9 100644 --- a/src/ComputeSharp.Core/Intrinsics/Hlsl.tt +++ b/src/ComputeSharp.Core/Intrinsics/Hlsl.tt @@ -39,7 +39,10 @@ foreach (var intrinsic in Intrinsics) 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}\")]"); + if (intrinsic.Name != intrinsic.HlslName) + { + WriteLine($"[HlslIntrinsicName(\"{intrinsic.HlslName}\")]"); + } Write($"public static {overload.Return} {intrinsic.Name}("); Write(string.Join(", ", intrinsic.Parameters.Zip(overload.Params, (a, b) => $"{(a.IsOut ? "out " : "")}{b} {a.Name}"))); diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj index 095fcb7d..254db83b 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj +++ b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj @@ -20,6 +20,7 @@ + diff --git a/tests/ComputeSharp.D2D1.Tests/Assets/Landscape_CheckerboardClip.png b/tests/ComputeSharp.D2D1.Tests/Assets/Landscape_CheckerboardClip.png new file mode 100644 index 00000000..bed52a7d Binary files /dev/null and b/tests/ComputeSharp.D2D1.Tests/Assets/Landscape_CheckerboardClip.png differ diff --git a/tests/ComputeSharp.D2D1.Tests/Assets/Landscape_Pixelate.png b/tests/ComputeSharp.D2D1.Tests/Assets/Landscape_Pixelate.png index eac0297f..ef3e318b 100644 Binary files a/tests/ComputeSharp.D2D1.Tests/Assets/Landscape_Pixelate.png and b/tests/ComputeSharp.D2D1.Tests/Assets/Landscape_Pixelate.png differ diff --git a/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj b/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj index 5816c386..8c49cd29 100644 --- a/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj +++ b/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj @@ -29,6 +29,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/tests/ComputeSharp.D2D1.Tests/Effects/CheckerboardClipEffect.cs b/tests/ComputeSharp.D2D1.Tests/Effects/CheckerboardClipEffect.cs new file mode 100644 index 00000000..028f59b6 --- /dev/null +++ b/tests/ComputeSharp.D2D1.Tests/Effects/CheckerboardClipEffect.cs @@ -0,0 +1,32 @@ +namespace ComputeSharp.D2D1.Tests.Effects; + +[D2DInputCount(1)] +[D2DInputSimple(0)] +[D2DRequiresScenePosition] +[D2DEmbeddedBytecode(D2D1ShaderProfile.PixelShader50)] +[AutoConstructor] +public partial struct CheckerboardClipEffect : ID2D1PixelShader +{ + public int width; + public int height; + public int cellSize; + + /// + public float4 Execute() + { + float2 position = D2D.GetScenePosition().XY; + uint x = (uint)Hlsl.Floor(position.X); + uint y = (uint)Hlsl.Floor(position.Y); + + uint cellX = (uint)(int)Hlsl.Floor(x / cellSize); + uint cellY = (uint)(int)Hlsl.Floor(y / cellSize); + + if ((cellX % 2 == 0 && cellY % 2 == 0) || + (cellX % 2 == 1 && cellY % 2 == 1)) + { + Hlsl.Clip(-1); + } + + return D2D.GetInput(0); + } +} diff --git a/tests/ComputeSharp.D2D1.Tests/Effects/InvertEffect.cs b/tests/ComputeSharp.D2D1.Tests/Effects/InvertEffect.cs index cf3c79d0..277fcd82 100644 --- a/tests/ComputeSharp.D2D1.Tests/Effects/InvertEffect.cs +++ b/tests/ComputeSharp.D2D1.Tests/Effects/InvertEffect.cs @@ -3,7 +3,6 @@ [D2DInputCount(1)] [D2DInputSimple(0)] [D2DEmbeddedBytecode(D2D1ShaderProfile.PixelShader50)] -[AutoConstructor] public partial struct InvertEffect : ID2D1PixelShader { /// diff --git a/tests/ComputeSharp.D2D1.Tests/EndToEndTests.cs b/tests/ComputeSharp.D2D1.Tests/EndToEndTests.cs index 47e91438..a8e2fc4d 100644 --- a/tests/ComputeSharp.D2D1.Tests/EndToEndTests.cs +++ b/tests/ComputeSharp.D2D1.Tests/EndToEndTests.cs @@ -29,7 +29,7 @@ public class EndToEndTests public unsafe void Pixelate() { RunAndCompareShader( - new PixelateEffect.Shader(new PixelateEffect.Shader.Constants(1280, 720, 16)), + new PixelateEffect.Shader(new PixelateEffect.Shader.Constants(1280, 840, 16)), static () => new PixelateEffect(), "Landscape.png", "Landscape_Pixelate.png"); @@ -41,6 +41,12 @@ public class EndToEndTests RunAndCompareShader(new ZonePlateEffect(1280, 720, 800), null, 1280, 720, "ZonePlate.png"); } + [TestMethod] + public unsafe void CheckerboardClip() + { + RunAndCompareShader(new CheckerboardClipEffect(1280, 840, 32), null, "Landscape.png", "Landscape_CheckerboardClip.png"); + } + /// /// Executes a pixel shader and compares the expected results. ///