From 37ae26b4bed2935c01d449ef8c08287bdb11a7f0 Mon Sep 17 00:00:00 2001 From: enricobuehler Date: Tue, 9 Jun 2026 20:42:41 +0000 Subject: [PATCH] =?UTF-8?q?perf:=20M2=20=E2=80=94=20auto=202-way=20NVENC?= =?UTF-8?q?=20split-encode=20for=20high=20pixel=20rates=20(5K@240)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GB203 has two NVENC engines. A single HEVC p1 session tops out ~1 Gpix/s, so 5120x1440@240 (1.77 Gpix/s) is encoder-bound on one engine; split-frame encode runs it across both (~1.8x, latency-neutral, output is standard HEVC the client decodes normally). NVENC's AUTO split won't engage below ~2112px height, so force split_encode_mode=2 when the pixel rate exceeds ~1 Gpix/s (HEVC/AV1 only — not H.264). Below that (e.g. 5K@120) stay single-engine to avoid the ~2% BD-rate cost. Override with LUMEN_SPLIT_ENCODE. Verified: engages at 240, not at 120. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/lumen-host/src/encode/linux.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/crates/lumen-host/src/encode/linux.rs b/crates/lumen-host/src/encode/linux.rs index 0577d20..564d55f 100644 --- a/crates/lumen-host/src/encode/linux.rs +++ b/crates/lumen-host/src/encode/linux.rs @@ -194,6 +194,25 @@ impl NvencEncoder { opts.set("delay", "0"); opts.set("forced-idr", "1"); // RFI/request_keyframe → real IDR under the infinite GOP + // Split-frame encode across both NVENC engines (GB203 has 2) when the pixel rate exceeds + // a single engine's HEVC capacity (~1 Gpix/s); e.g. 5120x1440@240 = 1.77 Gpix/s needs it, + // @120 = 0.88 Gpix/s does not. HEVC/AV1 only (not H.264). AUTO won't engage below ~2112px + // height, so we force `2`; below the threshold we leave it AUTO (split costs ~2% BD-rate). + // Output is standard HEVC — transparent to the client. Override with LUMEN_SPLIT_ENCODE. + let pix_rate = width as u64 * height as u64 * fps as u64; + let split = std::env::var("LUMEN_SPLIT_ENCODE").ok(); + match split.as_deref() { + Some(mode) => opts.set("split_encode_mode", mode), + None if matches!(codec, Codec::H265 | Codec::Av1) && pix_rate > 1_000_000_000 => { + opts.set("split_encode_mode", "2"); + tracing::info!( + pix_rate, + "NVENC: forcing 2-way split encode (high pixel rate)" + ); + } + None => {} + } + let enc = video .open_with(opts) .with_context(|| format!("open {name} ({width}x{height}@{fps}, {bitrate_bps} bps)"))?;