MoonWorks-docs/content/Graphics/Resources/ComputePipeline.md

35 lines
1.3 KiB
Markdown
Raw Normal View History

2021-01-28 22:03:19 +00:00
---
2021-01-28 22:03:29 +00:00
title: "Compute Pipeline"
2021-01-28 22:03:19 +00:00
date: 2021-01-28T13:55:13-08:00
weight: 9
---
There is another kind of pipeline we have access to other than graphics pipelines, and that is compute pipelines. Whereas graphics pipelines are specifically constructed for rendering, compute pipelines can do parallel processing on any kind of input data and output any kind of data we want. Some common use cases for compute pipelines are particle systems and sprite batching.
Describing exactly how to use compute pipelines is (my favorite phrase!) beyond the scope of this tutorial, so you should seek out other resources to learn how to use them. Many games will never need a compute pipeline and at the point where you could benefit from one you will probably know.
To construct a compute pipeline, we need a shader stage state containing a compute shader module, a buffer binding count, and an image binding count.
```cs
var myComputeShader = new ShaderModule(
GraphicsDevice,
"ParticleCompute.spv"
);
var myComputeShaderState = new ShaderStageState
{
ShaderModule = myComputeShader,
EntryPointName = "main",
UniformBufferSize = 0
};
var myComputePipeline = new ComputePipeline(
GraphicsDevice,
myComputeShaderState,
1,
0
);
```
This example creates a compute pipeline with no uniform input, one buffer binding, and no image bindings.