Updated code sample
このコミットが含まれているのは:
1 親
518a02d17d
コミット
37bfb7db4b
1ファイル変更
+4
-40
@@ -1,13 +1,9 @@
|
||||
using DirectX12GameEngine.Graphics;
|
||||
using DirectX12GameEngine.Shaders;
|
||||
using DirectX12GameEngine.Shaders;
|
||||
using DirectX12GameEngine.Shaders.Numerics;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using DirectX12GameEngine.Graphics.Buffers;
|
||||
using SharpDX.Direct3D12;
|
||||
using Buffer = DirectX12GameEngine.Graphics.Buffers.Buffer;
|
||||
using CommandList = DirectX12GameEngine.Graphics.CommandList;
|
||||
using PipelineState = DirectX12GameEngine.Graphics.PipelineState;
|
||||
|
||||
namespace DirectX12ComputeShaderSample
|
||||
{
|
||||
@@ -15,9 +11,6 @@ namespace DirectX12ComputeShaderSample
|
||||
{
|
||||
private static void Main()
|
||||
{
|
||||
// Create the graphics device
|
||||
using GraphicsDevice device = new GraphicsDevice(true);
|
||||
|
||||
// Create the graphics buffer
|
||||
int width = 10;
|
||||
int height = 10;
|
||||
@@ -27,7 +20,7 @@ namespace DirectX12ComputeShaderSample
|
||||
array[i] = i + 1;
|
||||
}
|
||||
|
||||
using Buffer<float> gpuBuffer = Buffer.UnorderedAccess.New(device, array.AsSpan());
|
||||
using Buffer<float> gpuBuffer = Buffer.UnorderedAccess.New(Gpu.Default, array.AsSpan());
|
||||
|
||||
// Variables for closure
|
||||
uint size = (uint)width;
|
||||
@@ -39,37 +32,8 @@ namespace DirectX12ComputeShaderSample
|
||||
data[id.X + id.Y * size] *= 2;
|
||||
};
|
||||
|
||||
// Generate computer shader
|
||||
ShaderGenerator shaderGenerator = new ShaderGenerator(action);
|
||||
ShaderGenerationResult result = shaderGenerator.GenerateShaderForLambda();
|
||||
|
||||
byte[] shaderBytecode = ShaderCompiler.CompileShader(result.ShaderSource, SharpDX.D3DCompiler.ShaderVersion.ComputeShader, result.ComputeShader);
|
||||
|
||||
// Create the pipeline state
|
||||
|
||||
RootParameter[] rootParameters =
|
||||
{
|
||||
new RootParameter(ShaderVisibility.All, new DescriptorRange(DescriptorRangeType.UnorderedAccessView, 1, 0))
|
||||
};
|
||||
|
||||
var rootSignatureDescription = new RootSignatureDescription(RootSignatureFlags.None, rootParameters);
|
||||
var rootSignature = device.CreateRootSignature(rootSignatureDescription);
|
||||
|
||||
PipelineState pipelineState = new PipelineState(device, rootSignature, shaderBytecode);
|
||||
|
||||
|
||||
|
||||
// Execute computer shader
|
||||
|
||||
using (CommandList commandList = new CommandList(device, CommandListType.Compute))
|
||||
{
|
||||
commandList.SetPipelineState(pipelineState);
|
||||
|
||||
commandList.SetComputeRootDescriptorTable(0, gpuBuffer);
|
||||
|
||||
commandList.Dispatch(2, 2, 1);
|
||||
commandList.Flush(true);
|
||||
}
|
||||
// Run the shader
|
||||
Gpu.Default.For(100, action);
|
||||
|
||||
// Print matrix
|
||||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする