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

41 lines
1.5 KiB
Markdown

---
title: "Compute Pipeline"
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.
Similar to graphics pipelines, uniforms can also be pushed to compute pipelines.
```cs
var myComputeUniformOffset = myComputePipeline.PushComputeShaderUniforms(myComputeUniforms);
```