APIs refactored, implemented automatic bounds checking

このコミットが含まれているのは:
Sergio Pedri committed 2019-08-12 16:47:32 +02:00
1 親 09f5e8e6e5
コミット 13fc51df4a
4ファイル変更
+38 -34

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

+15
ファイルの表示
@@ -15,6 +15,21 @@ namespace ComputeSharp.Shaders.Renderer.Models
/// </summary>
public IReadOnlyList<FieldInfoBase> FieldsList { get; set; }
/// <summary>
/// Gets or sets the total number of threads to run on the X axis
/// </summary>
public int ThreadsX { get; set; }
/// <summary>
/// Gets or sets the total number of threads to run on the Y axis
/// </summary>
public int ThreadsY { get; set; }
/// <summary>
/// Gets or sets the total number of threads to run on the Z axis
/// </summary>
public int ThreadsZ { get; set; }
/// <summary>
/// Gets or sets the number of threads in the X group
/// </summary>
+20 -7
ファイルの表示
@@ -19,11 +19,21 @@ namespace ComputeSharp.Shaders
/// 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="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 Run(GraphicsDevice device, NumThreads numThreads, NumThreads numGroups, Action<ThreadIds> action)
public static void Run(GraphicsDevice device, int x, int y, int z, Action<ThreadIds> action)
{
// Calculate the optimized thread num and group values
int
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;
// Load the input shader
ShaderLoader shaderLoader = ShaderLoader.Load(action);
@@ -31,9 +41,12 @@ namespace ComputeSharp.Shaders
ShaderInfo shaderInfo = new ShaderInfo
{
FieldsList = shaderLoader.FieldsInfo,
NumThreadsX = numThreads.X,
NumThreadsY = numThreads.Y,
NumThreadsZ = numThreads.Z,
ThreadsX = x,
ThreadsY = y,
ThreadsZ = z,
NumThreadsX = threadsX,
NumThreadsY = threadsY,
NumThreadsZ = threadsZ,
ThreadsIdsVariableName = shaderLoader.ThreadsIdsVariableName,
ShaderBody = shaderLoader.MethodBody
};
@@ -58,7 +71,7 @@ namespace ComputeSharp.Shaders
}
// Dispatch and wait for completion
commandList.Dispatch(numGroups.X, numGroups.Y, numGroups.Z);
commandList.Dispatch(groupsX, groupsY, groupsZ);
commandList.Flush(true);
}
}
+3 -26
ファイルの表示
@@ -15,7 +15,7 @@ namespace ComputeSharp
/// <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="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) => device.For(x, 1, 1, action);
public static void For(this GraphicsDevice device, int x, Action<ThreadIds> action) => ShaderRunner.Run(device, x, 1, 1, action);
/// <summary>
/// Compiles and runs the input shader on a target <see cref="GraphicsDevice"/> instance, with the specified parameters
@@ -24,7 +24,7 @@ namespace ComputeSharp
/// <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) => device.For(x, y, 1, action);
public static void For(this GraphicsDevice device, int x, int y, Action<ThreadIds> action) => ShaderRunner.Run(device, x, y, 1, action);
/// <summary>
/// Compiles and runs the input shader on a target <see cref="GraphicsDevice"/> instance, with the specified parameters
@@ -34,29 +34,6 @@ namespace ComputeSharp
/// <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
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, (threadsX, threadsY, threadsZ), (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);
}
public static void For(this GraphicsDevice device, int x, int y, int z, Action<ThreadIds> action) => ShaderRunner.Run(device, x, y, z, action);
}
}
-1
ファイルの表示
@@ -25,7 +25,6 @@ namespace DirectX12ComputeShaderSample
Action<ThreadIds> action = id =>
{
uint offset = id.X + id.Y * (uint)width;
if (offset > 99) return;
gpuBuffer[offset] *= 2;
};