Added more public APIs, fixed code sample

このコミットが含まれているのは:
Sergio Pedri committed 2019-08-12 15:25:17 +02:00
1 親 e639320b5c
コミット 8d79cb2aae
2ファイル変更
+52 -2

検索条件に一致するファイルはありません

+49 -1
ファイルの表示
@@ -22,7 +22,55 @@ namespace ComputeSharp
/// <param name="action">The input <see cref="Action{T}"/> representing the compute shader to run</param>
public static void For(this GraphicsDevice device, int x, Action<ThreadIds> action)
{
ShaderRunner.Run(device, (x, 1), (1, 1), action);
int groupsX = (x - 1) / DefaultThreadGroupCount + 1;
ShaderRunner.Run(device, (DefaultThreadGroupCount, 1), (groupsX, 1), action);
}
/// <summary>
/// Compiles and runs the input shader on a target <see cref="GraphicsDevice"/> instance, with the specified parameters
/// </summary>
/// <param name="device">The <see cref="GraphicsDevice"/> to use to run the shader</param>
/// <param name="x">The number of threads to run on the X axis</param>
/// <param name="y">The number of threads to run on the Y axis</param>
/// <param name="action">The input <see cref="Action{T}"/> representing the compute shader to run</param>
public static void For(this GraphicsDevice device, int x, int y, Action<ThreadIds> action)
{
int
groupsX = (x - 1) / DefaultThreadGroupCount + 1,
groupsY = (y - 1) / DefaultThreadGroupCount + 1;
ShaderRunner.Run(device, (DefaultThreadGroupCount, DefaultThreadGroupCount), (groupsX, groupsY), action);
}
/// <summary>
/// Compiles and runs the input shader on a target <see cref="GraphicsDevice"/> instance, with the specified parameters
/// </summary>
/// <param name="device">The <see cref="GraphicsDevice"/> to use to run the shader</param>
/// <param name="x">The number of threads to run on the X axis</param>
/// <param name="y">The number of threads to run on the Y axis</param>
/// <param name="z">The number of threads to run on the Z axis</param>
/// <param name="action">The input <see cref="Action{T}"/> representing the compute shader to run</param>
public static void For(this GraphicsDevice device, int x, int y, int z, Action<ThreadIds> 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);
}
/// <summary>
/// Compiles and runs the input shader on a target <see cref="GraphicsDevice"/> instance, with the specified parameters
/// </summary>
/// <param name="device">The <see cref="GraphicsDevice"/> to use to run the shader</param>
/// <param name="numThreads">The <see cref="NumThreads"/> value that indicates the number of threads to run in each thread group</param>
/// <param name="numGroups">The <see cref="NumThreads"/> value that indicates the number of thread groups to dispatch</param>
/// <param name="action">The input <see cref="Action{T}"/> representing the compute shader to run</param>
public static void For(this GraphicsDevice device, NumThreads numThreads, NumThreads numGroups, Action<ThreadIds> action)
{
ShaderRunner.Run(device, numThreads, numGroups, action);
}
}
}
+3 -1
ファイルの表示
@@ -24,7 +24,9 @@ namespace DirectX12ComputeShaderSample
// Shader body
Action<ThreadIds> 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