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:
| Pass | Responsibility |
|---|---|
| ImportFrame | Imports the decoded frame as a GPU texture (zero-copy or CPU upload). |
| NeuralUpscale | ArtCNN 2× luma upscaling; inserted only when enabled and supported by the backend. |
| PlaneSampling | YCbCr plane sampling, UV upsampling, and chroma reconstruction. |
| ChromaReconstruction | Chroma plane reconstruction. |
| TransferDecode | Decodes the transfer function to recover linear light from the encoded format. |
| GamutMap | Gamut mapping; inserted when the source and target primaries differ. |
| ToneMap | Tone mapping; inserted when the source is HDR and its peak exceeds the target's by about 1.05×. |
| Scale | Scales to the output size. |
| OverlayComposite | Composites the subtitle layer (the kernel's internal overlay) and danmaku. |
| Dither | Dithering when the output bit depth is reduced. |
| OutputTransform | Encodes 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バックエンド#
| Backend | Platform | Description |
|---|---|---|
| Metal | macOS / iOS / tvOS | Native implementation. YCbCr sampling, color conversion, tone mapping, and overlay compositing. ArtCNN uses simdgroup matrix. |
| Direct3D 11 | Windows | Native implementation. D3D11VA texture interop, HDR10 output, and overlay compositing. |
| wgpu | Android / HarmonyOS | Vulkan 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.