Code refactoring to the Gpu class, moved to extension class

このコミットが含まれているのは:
Sergio Pedri committed 2019-08-12 15:15:37 +02:00
1 親 d890f78550
コミット 4c533ad2f6
2ファイル変更
+29 -54

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

+28
ファイルの表示
@@ -0,0 +1,28 @@
using System;
using ComputeSharp.Graphics;
using ComputeSharp.Shaders;
namespace ComputeSharp
{
/// <summary>
/// A <see langword="class"/> that contains extension methods for the <see cref="GraphicsDevice"/> type, used to run compute shaders
/// </summary>
public static class GraphicsDeviceExtensions
{
/// <summary>
/// The default number of threads in a thead froup
/// </summary>
public const int DefaultThreadGroupCount = 64;
/// <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="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);
}
}
}
+1 -54
ファイルの表示
@@ -1,14 +1,4 @@
using System;
using System.Linq;
using ComputeSharp.Graphics;
using ComputeSharp.Shaders;
using ComputeSharp.Shaders.Renderer;
using ComputeSharp.Shaders.Renderer.Models;
using ComputeSharp.Shaders.Translation;
using SharpDX.Direct3D12;
using CommandList = ComputeSharp.Graphics.CommandList;
using PipelineState = ComputeSharp.Graphics.PipelineState;
using ShaderBytecode = SharpDX.Direct3D12.ShaderBytecode;
using ComputeSharp.Graphics;
namespace ComputeSharp
{
@@ -24,47 +14,4 @@ namespace ComputeSharp
/// </summary>
public static GraphicsDevice Default => _Default ??= new GraphicsDevice(true);
}
public static class GraphicsDeviceExtensions
{
public static void For(this GraphicsDevice device, int n, Action<ThreadIds> action)
{
// Load the input shader
ShaderLoader shaderLoader = ShaderLoader.Load(action);
// Render the loaded shader
ShaderInfo shaderInfo = new ShaderInfo
{
FieldsList = shaderLoader.FieldsInfo,
ThreadsX = n,
ThreadsY = 1,
ThreadsZ = 1,
ThreadsIdsVariableName = shaderLoader.ThreadsIdsVariableName,
ShaderBody = shaderLoader.MethodBody
};
string shaderSource = ShaderRenderer.Instance.Render(shaderInfo);
// Compile the loaded shader to HLSL bytecode
ShaderBytecode shaderBytecode = ShaderCompiler.Instance.CompileShader(shaderSource);
// Create the root signature for the pipeline and the pipeline state
RootSignatureDescription rootSignatureDescription = new RootSignatureDescription(RootSignatureFlags.None, shaderLoader.RootParameters);
RootSignature rootSignature = device.CreateRootSignature(rootSignatureDescription);
PipelineState pipelineState = new PipelineState(device, rootSignature, shaderBytecode);
// Create the commands list
using CommandList commandList = new CommandList(device, CommandListType.Compute);
commandList.SetPipelineState(pipelineState);
// Load the captured buffers
foreach (var buffer in shaderLoader.ReadWriteBuffers.Select((r, i) => (Resource: r, Index: i)))
{
commandList.SetComputeRootDescriptorTable(buffer.Index, buffer.Resource);
}
// Dispatch and wait for completion
commandList.Dispatch(1, 1, 1);
commandList.Flush(true);
}
}
}