diff --git a/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs b/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs
index bf61fc4e..2c72d15f 100644
--- a/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs
+++ b/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs
@@ -22,7 +22,55 @@ namespace ComputeSharp
/// The input representing the compute shader to run
public static void For(this GraphicsDevice device, int x, Action action)
{
- ShaderRunner.Run(device, (x, 1), (1, 1), action);
+ int groupsX = (x - 1) / DefaultThreadGroupCount + 1;
+
+ ShaderRunner.Run(device, (DefaultThreadGroupCount, 1), (groupsX, 1), action);
+ }
+
+ ///
+ /// Compiles and runs the input shader on a target instance, with the specified parameters
+ ///
+ /// The to use to run the shader
+ /// The number of threads to run on the X axis
+ /// The number of threads to run on the Y axis
+ /// The input representing the compute shader to run
+ public static void For(this GraphicsDevice device, int x, int y, Action action)
+ {
+ int
+ groupsX = (x - 1) / DefaultThreadGroupCount + 1,
+ groupsY = (y - 1) / DefaultThreadGroupCount + 1;
+
+ ShaderRunner.Run(device, (DefaultThreadGroupCount, DefaultThreadGroupCount), (groupsX, groupsY), action);
+ }
+
+ ///
+ /// Compiles and runs the input shader on a target instance, with the specified parameters
+ ///
+ /// The to use to run the shader
+ /// The number of threads to run on the X axis
+ /// The number of threads to run on the Y axis
+ /// The number of threads to run on the Z axis
+ /// The input representing the compute shader to run
+ public static void For(this GraphicsDevice device, int x, int y, int z, Action action)
+ {
+ int
+ groupsX = (x - 1) / DefaultThreadGroupCount + 1,
+ groupsY = (y - 1) / DefaultThreadGroupCount + 1,
+ groupsZ = (z - 1) / DefaultThreadGroupCount + 1;
+
+ ShaderRunner.Run(device, (DefaultThreadGroupCount, DefaultThreadGroupCount, DefaultThreadGroupCount), (groupsX, groupsY, groupsZ), action);
+ }
+
+ ///
+ /// Compiles and runs the input shader on a target instance, with the specified parameters
+ ///
+ /// The to use to run the shader
+ /// The value that indicates the number of threads to run in each thread group
+ /// The value that indicates the number of thread groups to dispatch
+ /// The input representing the compute shader to run
+ public static void For(this GraphicsDevice device, NumThreads numThreads, NumThreads numGroups, Action action)
+ {
+ ShaderRunner.Run(device, numThreads, numGroups, action);
}
}
}
diff --git a/src/DirectX12ComputeShaderSample/Program.cs b/src/DirectX12ComputeShaderSample/Program.cs
index 813bd5b1..59e3cc8f 100644
--- a/src/DirectX12ComputeShaderSample/Program.cs
+++ b/src/DirectX12ComputeShaderSample/Program.cs
@@ -24,7 +24,9 @@ namespace DirectX12ComputeShaderSample
// Shader body
Action action = id =>
{
- gpuBuffer[id.X + id.Y * (uint)width] *= 2;
+ uint offset = id.X + id.Y * (uint)width;
+ if (offset > 99) return;
+ gpuBuffer[offset] *= 2;
};
// Run the shader