From 80f35ddcd2237e2994d1ce85506b886eaefe3c28 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 12 Apr 2020 20:33:25 +0200 Subject: [PATCH] Added new generic extensions --- .../Extensions/GraphicsDeviceExtensions.cs | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs b/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs index db36a328..49f5f7df 100644 --- a/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs +++ b/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs @@ -52,5 +52,69 @@ namespace ComputeSharp int x, int y, int z, int threadsX, int threadsY, int threadsZ, Action action) => ShaderRunner.Run(device, x, y, z, threadsX, threadsY, threadsZ, action); + + /// + /// Compiles and runs the input shader on a target instance, with the specified parameters + /// + /// The type of compute shader to run + /// The to use to run the shader + /// The number of iterations to run on the X axis + /// The input instance representing the compute shader to run + public static void For(this GraphicsDevice device, int x, in T shader) + where T : struct, IComputeShader + { + ShaderRunner.Run(device, x, 1, 1, shader); + } + + /// + /// Compiles and runs the input shader on a target instance, with the specified parameters + /// + /// The type of compute shader to run + /// The to use to run the shader + /// The number of iterations to run on the X axis + /// The number of iterations to run on the Y axis + /// The input instance representing the compute shader to run + public static void For(this GraphicsDevice device, int x, int y, in T shader) + where T : struct, IComputeShader + { + ShaderRunner.Run(device, x, y, 1, shader); + } + + /// + /// Compiles and runs the input shader on a target instance, with the specified parameters + /// + /// The type of compute shader to run + /// The to use to run the shader + /// The number of iterations to run on the X axis + /// The number of iterations to run on the Y axis + /// The number of iterations to run on the Z axis + /// The input instance representing the compute shader to run + public static void For(this GraphicsDevice device, int x, int y, int z, in T shader) + where T : struct, IComputeShader + { + ShaderRunner.Run(device, x, y, z, shader); + } + + /// + /// Compiles and runs the input shader on a target instance, with the specified parameters + /// + /// The type of compute shader to run + /// The to use to run the shader + /// The number of iterations to run on the X axis + /// The number of iterations to run on the Y axis + /// The number of iterations to run on the Z axis + /// The number of threads in each thread group for the X axis + /// The number of threads in each thread group for the Y axis + /// The number of threads in each thread group for the Z axis + /// The input instance representing the compute shader to run + public static void For( + this GraphicsDevice device, + int x, int y, int z, + int threadsX, int threadsY, int threadsZ, + in T shader) + where T : struct, IComputeShader + { + ShaderRunner.Run(device, x, y, z, threadsX, threadsY, threadsZ, shader); + } } }