using ComputeSharp.Core.Intrinsics.Attributes; using ComputeSharp.Exceptions; namespace ComputeSharp; /// /// A that maps the supported HLSL intrinsic functions that can be used in compute shaders. /// 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. /// /// /// A memory barrier guarantees that outstanding memory operations have completed. /// Threads are synchronized at GroupSync barriers. /// This may stall a thread or threads if memory operations are in progress. /// 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 AllMemoryBarrier() => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(AllMemoryBarrier)}()"); /// /// Blocks execution of all threads in a group until all memory accesses have been completed and all threads in the group have reached this call. /// /// /// A memory barrier guarantees that outstanding memory operations have completed. /// Threads are synchronized at GroupSync barriers. /// This may stall a thread or threads if memory operations are in progress. /// 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 AllMemoryBarrierWithGroupSync() => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(AllMemoryBarrierWithGroupSync)}()"); /// /// Blocks execution of all threads in a group until all device memory accesses have been completed. /// /// 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 DeviceMemoryBarrier() => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(DeviceMemoryBarrier)}()"); /// /// Blocks execution of all threads in a group until all device memory accesses have been completed and all threads in the group have reached this call. /// /// 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 DeviceMemoryBarrierWithGroupSync() => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(DeviceMemoryBarrierWithGroupSync)}()"); /// /// Blocks execution of all threads in a group until all group shared accesses have been completed. /// /// 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 GroupMemoryBarrier() => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(GroupMemoryBarrier)}()"); /// /// Blocks execution of all threads in a group until all group shared accesses have been completed and all threads in the group have reached this call. /// /// 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. /// /// The dot product of the normalized surface normal and the light vector. /// The dot product of the half-angle vector and the surface normal. /// A specular exponent. /// The lighting coefficient vector. /// /// This function returns a lighting coefficient vector (ambient, diffuse, specular, 1) where: /// /// Ambient: 1. /// Diffuse: n * l < 0 ? 0 : n * l. /// Specular: n * l < 0 || n * h < 0 ? 0 : (n * h) ^ m. /// /// Where the vector n is the normal vector, l is the direction to light and h is the half vector. /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. /// [HlslIntrinsicName("lit")] public static float Lit(float nDotL, float nDotH, float m) => default; }