diff --git a/src/ComputeSharp.Graphics/GraphicsDevice.cs b/src/ComputeSharp.Graphics/GraphicsDevice.cs
index 893b4a2c..8aeb3983 100644
--- a/src/ComputeSharp.Graphics/GraphicsDevice.cs
+++ b/src/ComputeSharp.Graphics/GraphicsDevice.cs
@@ -15,6 +15,7 @@ namespace ComputeSharp.Graphics
if (enableDebugLayer) DebugInterface.Get().EnableDebugLayer();
#endif
NativeDevice = new Device(null, FeatureLevel);
+ WavefrontSize = NativeDevice.D3D12Options1.WaveLaneCountMin;
NativeComputeCommandQueue = NativeDevice.CreateCommandQueue(new CommandQueueDescription(SharpDX.Direct3D12.CommandListType.Compute));
NativeCopyCommandQueue = NativeDevice.CreateCommandQueue(new CommandQueueDescription(SharpDX.Direct3D12.CommandListType.Copy));
@@ -40,6 +41,11 @@ namespace ComputeSharp.Graphics
CopyCommandList.Close();
}
+ ///
+ /// Gets the number of lanes in a SIMD wave on the current device (also known as "wavefront size" or "warp width")
+ ///
+ public int WavefrontSize { get; }
+
public CommandList CommandList { get; }
public CommandList CopyCommandList { get; }
diff --git a/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs b/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs
index 2c72d15f..ff704cfa 100644
--- a/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs
+++ b/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs
@@ -9,23 +9,13 @@ namespace ComputeSharp
///
public static class GraphicsDeviceExtensions
{
- ///
- /// The default number of threads in a thead froup
- ///
- public const int DefaultThreadGroupCount = 64;
-
///
/// 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 input representing the compute shader to run
- public static void For(this GraphicsDevice device, int x, Action action)
- {
- int groupsX = (x - 1) / DefaultThreadGroupCount + 1;
-
- ShaderRunner.Run(device, (DefaultThreadGroupCount, 1), (groupsX, 1), action);
- }
+ public static void For(this GraphicsDevice device, int x, Action action) => device.For(x, 1, 1, action);
///
/// Compiles and runs the input shader on a target instance, with the specified parameters
@@ -34,14 +24,7 @@ namespace ComputeSharp
/// 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);
- }
+ public static void For(this GraphicsDevice device, int x, int y, Action action) => device.For(x, y, 1, action);
///
/// Compiles and runs the input shader on a target instance, with the specified parameters
@@ -54,11 +37,14 @@ namespace ComputeSharp
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;
+ threadsX = device.WavefrontSize,
+ threadsY = y > 1 ? device.WavefrontSize : 1,
+ threadsZ = z > 1 ? device.WavefrontSize : 1,
+ groupsX = (x - 1) / device.WavefrontSize + 1,
+ groupsY = (y - 1) / device.WavefrontSize + 1,
+ groupsZ = (z - 1) / device.WavefrontSize + 1;
- ShaderRunner.Run(device, (DefaultThreadGroupCount, DefaultThreadGroupCount, DefaultThreadGroupCount), (groupsX, groupsY, groupsZ), action);
+ ShaderRunner.Run(device, (threadsX, threadsY, threadsZ), (groupsX, groupsY, groupsZ), action);
}
///