Home/docs/kernel/Rendering pipeline

Rendering pipeline

Render Pipeline

Video, subtitles, and danmaku are sampled, color converted, tone mapped, scaled, and composited in a single pass graph, and reach the screen in one render pass. pipeline::build_graph builds the pass graph conditionally, based on the color state of the source and the target.

Pass graph#

RenderPassKind defines all 11 pass types. To render a frame, build_graph chains them in order, from frame import to output transform, and skips any pass whose conditions are not met:

PassResponsibility
ImportFrameImports the decoded frame as a GPU texture (zero-copy or CPU upload).
NeuralUpscaleArtCNN 2× luma upscaling; inserted only when enabled and supported by the backend.
PlaneSamplingYCbCr plane sampling, UV upsampling, and chroma reconstruction.
ChromaReconstructionChroma plane reconstruction.
TransferDecodeDecodes the transfer function to recover linear light from the encoded format.
GamutMapGamut mapping; inserted when the source and target primaries differ.
ToneMapTone mapping; inserted when the source is HDR and its peak exceeds the target's by about 1.05×.
ScaleScales to the output size.
OverlayCompositeComposites the subtitle layer (the kernel's internal overlay) and danmaku.
DitherDithering when the output bit depth is reduced.
OutputTransformEncodes to the output format (SDR / EDR / HDR10 PQ / scRGB).

The two conditional passes are decided by comparing SourceColorState with TargetColorState. Tone mapping is inserted only when the source is HDR and its peak exceeds the target's by about 5%. Gamut mapping is inserted only when the source and target primaries differ. SDR content on an SDR target goes straight through sampling and the output transform.

Backend implementations#

BackendPlatformDescription
MetalmacOS / iOS / tvOSNative implementation. YCbCr sampling, color conversion, tone mapping, and overlay compositing. ArtCNN uses simdgroup matrix.
Direct3D 11WindowsNative implementation. D3D11VA texture interop, HDR10 output, and overlay compositing.
wgpuAndroid / HarmonyOSVulkan backend, with GLES and recovery paths available. HarmonyOS presents through OHNativeWindow.

The Presenter configuration determines the rendering backend, independent of how the surface is attached. Color decisions all go through the pipeline module, and the three backends share the same pass graph description.

Compositing and geometry#

Subtitles and danmaku are composited in the OverlayComposite pass. Subtitles stay within the aspect-fit video viewport; danmaku can also use the letterbox area.

Video content is placed centered in the output surface with aspect_fit, and the letterbox area is filled with the clear color (currently black on all backends). The compositing order is video, subtitles, then danmaku.

The HDR rendering chain and the screenshot chain share the same pass graph. A screenshot is rendered to an offscreen target with the same pixel format as the surface and converted to RGBA8 on readback (HDR values are clamped to the SDR range). The original screenshot API composites only video and subtitles; they exclude danmaku and the debug HUD.

The original native capture composites video and subtitles, excluding danmaku and the debug HUD. Version 0.3.1 adds a separate capture with danmaku; native frame texture export includes subtitles and enabled danmaku.

liberika v0.3.8 Section Kernel License MPL-2.0