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

35 lines
1.4 KiB
Markdown
Raw Permalink 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"
);
2022-03-04 18:34:23 +00:00
var myComputeShaderInfo = new ComputeShaderInfo
2021-01-28 22:03:19 +00:00
{
ShaderModule = myComputeShader,
EntryPointName = "main",
2022-03-04 18:34:23 +00:00
UniformBufferSize = 0,
BufferBindingCount = 1,
ImageBindingCount = 0,
2021-01-28 22:03:19 +00:00
};
var myComputePipeline = new ComputePipeline(
GraphicsDevice,
2022-03-04 18:34:23 +00:00
myComputeShaderInfo
2021-01-28 22:03:19 +00:00
);
```
This example creates a compute pipeline with no uniform input, one buffer binding, and no image bindings.