Render Pipeline Injection
Plugins and packages can add their own render passes to render pipelines without anyone editing a pipeline asset. A plugin registers a pass at startup and names an injection point, such as "in front of the transparent pass" or "behind the tonemapper". Whenever the engine creates a pipeline from its asset, it places every registered pass at its point and connects its pins.
This is how a water package draws its surfaces in a project that uses the engine's shipped pipelines, and how the engine itself adds FXAA, sharpening, weather precipitation and graph post effects to every pipeline. A project no longer needs hand-edited copies of the pipeline assets for a package's passes to show up.
This page is for C++ plugin authors. As a user you only notice injection when a package's effect appears in every view, and you can switch single injections off with the cvars below.
Injection points
The engine finds every point in every pipeline by itself. A pipeline in which a point is not found (shadow map views, for example) gets nothing injected there; that is not an error.
| Point | Where the pass goes | Streams it can bind |
|---|---|---|
FrameStart | Pipelines with an opaque forward, G-buffer or depth pass. Ordered before every other pass, injected ones included. | none |
AfterAmbientOcclusion | Behind each AO pass. | AO, Depth (read only) |
BeforeTransparent | In front of each transparent forward pass. | Color, DepthStencil, ResolvedDepth and GBuffer1 (read only) |
AfterTransparent | Behind each transparent forward pass. | Color, DepthStencil, ResolvedDepth (read only) |
AfterTransparentResolved | Behind the MSAA resolve of the transparent pass's colour. Without such a resolve, behind the transparent pass and everything injected at AfterTransparent. | Color (single sampled), ResolvedDepth, GBuffer0, GBuffer1 and Velocity (read only) |
AfterTonemap | Behind each tonemap pass. | Color (display referred), ResolvedDepth, GBuffer0, GBuffer1 and Velocity (read only) |
The point names are constants in plRenderPipelineInjectionPoints (RendererCore/Pipeline/RenderPipelineInjection.h).
GBuffer0,GBuffer1andVelocityare whatever feeds the first pass input of that name in the pipeline asset, so a pipeline without them does not offer them. They stay at render resolution while the colour after an upscaler has the output resolution, so read them by UV.- At
AfterTonemapa history pass that stores the tonemapped image for the next frame keeps what the tonemapper wrote, so an injected effect is not fed back into passes that reproject that history. - At
AfterTransparentResolved, a view whose colour is still multisampled there (reflection probes render that way) skips the injected pass.
Registering a pass
An injection is a plRenderPipelineInjectionDesc: pure data, the engine does all the wiring. Register it when the plugin starts and unregister it when it shuts down, for example from a subsystem:
#include <RendererCore/Pipeline/RenderPipelineInjection.h>
void MyPlugin::RegisterInjections()
{
plRenderPipelineInjectionDesc desc;
desc.m_sName.Assign("my.package/Outline"); // unique; used in reports and in the Disabled cvar
desc.m_sOwner.Assign("my.package"); // UnregisterOwner removes everything under this name
desc.m_sPoint.Assign(plRenderPipelineInjectionPoints::AfterTransparentResolved);
desc.m_pPassType = plGetStaticRTTI<plMyOutlinePass>(); // a plRenderPipelinePass with a default allocator
desc.m_fOrder = 500.0f; // lower runs earlier at the same point; ties sort by name
desc.Bind("Color", "Color", "Output"); // take the colour over: Color in, Output out
desc.Read("ResolvedDepth", "Depth", false); // read the depth if the pipeline has it (optional)
desc.m_ExtractorTypes.PushBack(plGetStaticRTTI<plMyOutlineExtractor>()); // added once per pipeline
plRenderPipelineInjections::Register(desc).IgnoreResult();
}
void MyPlugin::UnregisterInjections()
{
plRenderPipelineInjections::UnregisterOwner("my.package");
}
Each pin binding names a stream of the point and the pass's pins:
| Binding | Meaning |
|---|---|
Bind(stream, input, output) | The pass takes the stream over. What fed the next pass now feeds the input pin, and the output pin feeds the next pass. |
Read(stream, input) | The pass only reads the stream; nothing is rewired. |
Publish(stream, output) | The pass publishes a private stream that another injection of the same pipeline can read by name, for example my.package/ExitDepth. Private streams never touch the pipeline's own connections. |
A binding is required by default: if its stream is not there, the injection is not placed in that pipeline. Pass false as the last argument to leave the pin unconnected instead.
Register fails if the descriptor is incomplete, and replaces an earlier injection with the same name. Registering and unregistering change plRenderPipelineInjections::GetVersion(); views notice the change and recreate their pipelines the next time they are extracted. A plugin that unloads at run time therefore has to unregister before the last frame it is still loaded for.
The engine's own injections are good examples: plasma.engine/PostEffectsScene and plasma.engine/PostEffectsDisplay (graph post effects), plasma.engine/FXAA, plasma.engine/Sharpening and plasma.weather/Precipitation.
What the engine guarantees
Injection is built so that a broken or missing plugin cannot take a pipeline down:
- Each injection is placed on its own. If a pin is missing, a required stream is not there, or the pipeline can no longer be ordered, that one injection is taken out again and the pipeline is exactly as its asset describes it.
- A pipeline keeps its own pass. If the asset already contains a pass of the injected type, the injection stands down for that pipeline.
- A failing pass is bypassed. An injected pass that fails to build is skipped: its input streams are forwarded to its outputs, so the passes behind it get what they would have had without it, and a warning is logged. After three failed builds in a row it is switched off for that pipeline.
- A missing pass type does not break the asset. When a pipeline asset names a pass whose plugin is not loaded, the loader puts a stand-in pass in its place that renders nothing and keeps the connections: pass-through pins keep passing through, and a typical post-process shape (Color in, Output out) forwards its image.
What injection cannot do: a crash inside an injected pass still takes the process down.
plRenderPipelineInjections::GetReports() returns, for every injection, how many pipelines took it, stood it down, did not have its point, rejected it or switched it off, and the reason of the last problem.
Placing a point by hand
A hand-built pipeline that lacks the pass a default rule looks for, or whose author wants injected passes somewhere else, can mark the point itself. Add an Injection Point Pass node (category Utilities) in the render pipeline asset editor, set its Point property to the point's name (default BeforeTransparent) and route the textures through it. Injected passes are then inserted in front of this node and take over whatever feeds its connected pins.
The node renders nothing. Color, DepthStencil and AO pass through; ResolvedDepth, GBuffer1 and Depth are read only. Only connected pins are offered as streams. When a pipeline holds such nodes for a point, they replace the default rule for that point.
Point can also be a name of your own: an injection whose m_sPoint is that name is placed only at those nodes.
CVars
| CVar | Default | Description |
|---|---|---|
Rendering.Pipeline.Injections | true | Lets plugins add their passes to render pipelines. Off: every pipeline is exactly what its asset describes. |
Rendering.Pipeline.Injections.Disabled | empty | Names of injections to leave out, separated by ;, for example plasma.engine/FXAA;my.package/Outline. |
Both are useful to find out whether a visual problem comes from a package's pass.
Replacing render pipeline extensions
plRenderPipelineExtension is deprecated. Register the passes with plRenderPipelineInjections instead.
Troubleshooting
| Symptom | Cause and fix |
|---|---|
| The injected pass does not show up in a pipeline | Check the report from GetReports(): the point may not exist in that pipeline, a required stream may be missing, or the asset already contains a pass of that type. Make optional bindings optional, or place an Injection Point Pass in the asset. |
| The pass shows up in game views but not in reflection probes | At AfterTransparentResolved multisampled views skip the pass. Use another point if the effect must reach those views. |
| A pass stays in the pipeline after its plugin shut down | Unregister in the plugin's shutdown, before the plugin's last frame. |
| An effect from a package looks wrong and you are not sure which pass causes it | Add the injection's name to Rendering.Pipeline.Injections.Disabled, or turn Rendering.Pipeline.Injections off. |