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

2.7 KiB

title date weight
Render Pass 2021-01-26T17:55:09-08:00 6

Render passes are a sort of intermediary between graphics pipelines and framebuffers that describe the kind of render targets that will be used in a particular section of rendering. This is probably a little hard to understand because we haven't talked about graphics pipelines or framebuffers yet, but I might as well introduce you to them now.

Render passes describe the kinds of targets that will be included in framebuffers so that the pipeline can set itself up correctly. They do this using ColorTargetDescriptions and an optional DepthStencilTargetDescription.

var myColorTargetDescription = new ColorTargetDescription
{
    Format = TextureFormat.R8G8B8A8,
    MultisampleCount = SampleCount.One,
    LoadOp = LoadOp.Clear,
    StoreOp = StoreOp.Store
};

var myRenderPass = new RenderPass(
    GraphicsDevice,
    myColorTargetDescription
);

With this definition we are saying that any framebuffer that will be used with this render pass will have exactly one render target in the RGBA8 format with no multisampling.

StoreOp tells the renderer what to do with the render target when the render pass finishes. Store means that the pixel data on the render target will be saved for later use. DontCare will do something or another, generally this operation will be whatever the driver thinks is fastest, but you don't have any guarantees about what it will be.

LoadOp tells the renderer what to do with the render target when the render pass starts. Load will load in the pixel information as it was stored. Clear will clear the render target to a single color that you provide when you begin the render pass. DontCare is same as above.

So in this example, we are saying that at the beginning of the render pass the render target will be cleared, and at the end of the render pass the render target will be stored for later use.

There is also a special type of description that you must use for depth/stencil targets.

var myDepthStencilTargetDescription = new DepthStencilTargetDescription
{
    Format = TextureFormat.D32S8,
    LoadOp = LoadOp.DontCare,
    StoreOp = StoreOp.DontCare,
    StencilLoadOp = LoadOp.DontCare,
    StencilStoreOp = StoreOp.DontCare
};

var myRenderPass = new RenderPass(
    GraphicsDevice,
    myDepthStencilTargetDescription,
    myColorTargetDescription
);

StencilLoadOp and StencilStoreOp allow you to specify different ops for the stencil buffer in particular. LoadOp and StoreOp here refer to the depth buffer. If your format does not provide a stencil format, StencilLoadOp and StencilStoreOp will be ignored.

That's it for render passes for now. Let's talk about framebuffers so this all starts making more sense.