diff --git a/src/ComputeSharp.Shaders/Primitives/NumThreads.cs b/src/ComputeSharp.Shaders/Primitives/NumThreads.cs new file mode 100644 index 00000000..06a6e852 --- /dev/null +++ b/src/ComputeSharp.Shaders/Primitives/NumThreads.cs @@ -0,0 +1,64 @@ +using System.Runtime.CompilerServices; + +namespace ComputeSharp +{ + /// + /// A that indicates the number of threads to use to run a given compute shader + /// + public readonly struct NumThreads + { + /// + /// The X id of the current thread + /// + public readonly int X; + + /// + /// The Y id of the current thread + /// + public readonly int Y; + + /// + /// The Z id of the current thread + /// + public readonly int Z; + + /// + /// Creates a new instance with the specified parameters + /// + /// The number of threads in the X axis + /// The number of threads in the Y axis + public NumThreads(int x, int y) + { + X = x; + Y = y; + Z = 1; + } + + /// + /// Creates a new instance with the specified parameters + /// + /// The number of threads in the X axis + /// The number of threads in the Y axis + /// The number of threads in the Z axis + public NumThreads(int x, int y, int z) + { + X = x; + Y = y; + Z = z; + } + + /// + /// Creates a new instance from a value tuple + /// + /// The tuple with the thread X and Y counts + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator NumThreads((int X, int Y) xy) => new NumThreads(xy.X, xy.Y); + + /// + /// Creates a new instance from a value tuple + /// + /// The tuple with the thread X, Y and Z counts + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator NumThreads((int X, int Y, int Z) xyz) => new NumThreads(xyz.X, xyz.Y, xyz.Z); + } +}