mirror of
https://github.com/VallierDev/uu-remote-linux.git
synced 2026-11-16 08:50:40 +01:00
NVENC: skip direct BGRA input when NVIDIA drives the display (#89)
#16: with display, capture and encode all on an RTX 5070 the packed-RGB input path is 19% slower in the probe and 25% end to end than CPU swscale, while on an iGPU-composited desktop it was neutral to faster. Keep it on by default only when no connected DRM connector belongs to an nvidia-bound card; UU_NVENC_RGB=1 forces it, =0 still disables it. Co-authored-by: VallierDev <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
4 files changed
+47
-3
No files matched your search
@@ -117,6 +117,7 @@ viewer does not reconnect them automatically.
|
||||
| `~/.config/uuremote/host_settings.json` | persisted 安全 settings: auto_lock, keep_mute, mute_permanent |
|
||||
| `UU_DESKTOP_BACKEND` | `auto` (default) / `x11` / `wayland` / `portal` / `kms` (experimental feature) / `none` (headless: no display; desktop offers ignored; tool peers get a nominal 1920x1080 screen + Allow permissions, which the port-mapping viewer requires) |
|
||||
| `UU_DESKTOP_RESIZE=0` | X11: the viewer's 分辨率 choice scales the encoded stream instead of changing the display mode. Default: `src/desktop_mode.rs` switches the primary output via xrandr (adds a CVT-RB mode when missing, re-applies once if mutter resets it), restores the original mode for resolution_type 3 and 2 s after the last desktop stream ends |
|
||||
| `UU_NVENC_RGB=0` / `=1` | NVENC 4:2:0 without scaling takes packed BGRA/BGR0 directly (no CPU swscale). Default: on, except when a connected DRM connector belongs to an nvidia-bound card (desktop composited on the encoding GPU; #16 measured 82.6 vs 98 fps at 4K). `0` forces CPU conversion, `1` forces the direct path |
|
||||
| `UU_INPUT_BACKEND` | `auto` (uinput on Wayland/portal when `/dev/uinput` is accessible, udev `uaccess` rule in README) / `uinput` / `native`. X11 keeps XTest (held-key autorepeat handling) |
|
||||
| Mac viewer Cmd | With 「使用 macOS 快捷键」 off the Mac viewer sends Cmd=VK_LWIN 0x5B, Option=0xA4, Ctrl=0xA2; connect header `controller_platform`=4 is macOS. For Mac controllers Cmd is held back: Cmd+C/V/A/F/X/Z → Ctrl+key (terminal: Cmd+C/V → Ctrl+Shift+C/V), other combos/alone → Super |
|
||||
| `UU_TERMINAL_SHORTCUTS=0` | disable Ctrl+V → Ctrl+Shift+V in focused X11 terminals (Mac Cmd and Ctrl both arrive as VK_LCONTROL) |
|
||||
|
||||
@@ -331,6 +331,7 @@ Common environment variables:
|
||||
| `UU_CONFIG` | Config file path (default `~/.config/uuremote/config.json`) |
|
||||
| `UU_DESKTOP_BACKEND` | `auto` / `x11` / `wayland` / `portal` / `kms` (experimental feature) / `none` (headless) |
|
||||
| `UU_DESKTOP_RESIZE=0` | on X11, keep the desktop resolution and only scale the encoded stream when the viewer picks a resolution |
|
||||
| `UU_NVENC_RGB=0` / `=1` | NVENC encodes BGRA directly (saves CPU). Off by default when a monitor is connected to the NVIDIA card (slower when the desktop is composited on the same GPU); `0` forces off, `1` forces on |
|
||||
| `UU_WAYLAND_MULTISCREEN=1` | Enable Hyprland physical monitor switching (off by default) |
|
||||
| `UU_WAYLAND_OUTPUT` | Initial native Wayland output name, e.g. `HDMI-A-1` |
|
||||
| `UU_WAYLAND_NO_VIRTUAL_KEYBOARD=1` | Native Wayland skips the virtual keyboard (e.g. Denial reserves it for its input method); keys go through uinput. Without wlr-virtual-pointer the pointer also uses uinput (#72) |
|
||||
|
||||
@@ -300,6 +300,7 @@ systemctl --user restart uuremote-native.service
|
||||
| `UU_CONFIG` | 配置文件路径(默认 `~/.config/uuremote/config.json`) |
|
||||
| `UU_DESKTOP_BACKEND` | `auto` / `x11` / `wayland` / `portal` / `kms`(实验性特性) / `none`(无头模式) |
|
||||
| `UU_DESKTOP_RESIZE=0` | X11 下控制端切换分辨率时不改桌面分辨率,只缩放编码画面 |
|
||||
| `UU_NVENC_RGB=0` / `=1` | NVENC 直接编码 BGRA(省 CPU)。显示器接在 NVIDIA 卡上时默认关闭(同卡合成时直吃反而更慢),`0` 强制关,`1` 强制开 |
|
||||
| `UU_WAYLAND_MULTISCREEN=1` | 启用 Hyprland 物理显示器切换(默认关闭) |
|
||||
| `UU_WAYLAND_OUTPUT` | 原生 Wayland 默认采集输出名称,例如 `HDMI-A-1` |
|
||||
| `UU_WAYLAND_NO_VIRTUAL_KEYBOARD=1` | 原生 Wayland 不创建虚拟键盘(如 Denial 只把它给自己的输入法),键盘改走 uinput。合成器没有 wlr-virtual-pointer 时鼠标也自动改走 uinput(#72) |
|
||||
|
||||
+44
-3
@@ -262,10 +262,29 @@ fn cpu_hevc_options(settings: &VideoSettings, gop: &str) -> Vec<String> {
|
||||
|
||||
/// NVENC converts packed RGB on the GPU (BT.601 limited range, tagged bt470bg like the swscale default;
|
||||
/// compared on the 3090), so 4:2:0 without scaling skips the CPU BGRA→YUV pass (#16: ~2 cores at 4K).
|
||||
/// `input` is the source pixel format; `UU_NVENC_RGB=0` restores CPU conversion.
|
||||
/// When the desktop is composited on the NVIDIA card itself, the packed-RGB path is slower than CPU
|
||||
/// conversion (#16: RTX 5070 at 4K, 82.6 vs 98 fps), so it stays off unless `UU_NVENC_RGB=1`.
|
||||
/// `input` is the source pixel format; `UU_NVENC_RGB=0` always restores CPU conversion.
|
||||
fn nvenc_rgb_input(settings: &VideoSettings, encoder: Encoder, input: &'static str) -> Option<&'static str> {
|
||||
(encoder == Encoder::Nvenc && settings.chroma != crate::capture_setting::CHROMA_444 && settings.output.is_none()
|
||||
&& std::env::var("UU_NVENC_RGB").as_deref() != Ok("0")).then_some(input)
|
||||
let wanted = match std::env::var("UU_NVENC_RGB").as_deref() {
|
||||
Ok("0") => false,
|
||||
Ok("1") => true,
|
||||
_ => !nvidia_drives_display(std::path::Path::new("/sys/class/drm")),
|
||||
};
|
||||
(encoder == Encoder::Nvenc && settings.chroma != crate::capture_setting::CHROMA_444 && settings.output.is_none() && wanted)
|
||||
.then_some(input)
|
||||
}
|
||||
|
||||
/// A connected DRM connector (`cardN-HDMI-A-1/status`) on a card bound to the nvidia driver.
|
||||
/// Only visible with nvidia-drm modeset, which Wayland compositors require.
|
||||
fn nvidia_drives_display(drm: &std::path::Path) -> bool {
|
||||
std::fs::read_dir(drm).into_iter().flatten().flatten().any(|entry| {
|
||||
let name = entry.file_name().to_string_lossy().into_owned();
|
||||
let Some((card, _)) = name.split_once('-') else { return false; };
|
||||
card.starts_with("card")
|
||||
&& std::fs::read_to_string(entry.path().join("status")).is_ok_and(|s| s.trim() == "connected")
|
||||
&& std::fs::read_link(drm.join(card).join("device/driver")).is_ok_and(|p| p.file_name().is_some_and(|n| n == "nvidia"))
|
||||
})
|
||||
}
|
||||
|
||||
fn encoder_options(settings: &VideoSettings, encoder: Encoder, gop: &str, rgb: Option<&'static str>) -> Vec<String> {
|
||||
@@ -1062,6 +1081,28 @@ pub async fn stream_desktop(pc: Arc<RTCPeerConnection>, track: Arc<crate::video_
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn nvidia_display_is_detected_from_connected_connectors() {
|
||||
use std::os::unix::fs::symlink;
|
||||
let root = std::env::temp_dir().join(format!("uu-drm-test-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&root);
|
||||
let card = |n: &str, driver: &str, connector: &str, status: &str| {
|
||||
std::fs::create_dir_all(root.join(format!("drivers/{driver}"))).unwrap();
|
||||
std::fs::create_dir_all(root.join(format!("drm/{n}/device"))).unwrap();
|
||||
let _ = symlink(root.join(format!("drivers/{driver}")), root.join(format!("drm/{n}/device/driver")));
|
||||
std::fs::create_dir_all(root.join(format!("drm/{n}-{connector}"))).unwrap();
|
||||
std::fs::write(root.join(format!("drm/{n}-{connector}/status")), format!("{status}\n")).unwrap();
|
||||
};
|
||||
let drm = root.join("drm");
|
||||
card("card0", "i915", "HDMI-A-1", "connected");
|
||||
card("card1", "nvidia", "DP-1", "disconnected");
|
||||
assert!(!super::nvidia_drives_display(&drm), "iGPU drives the display");
|
||||
card("card1", "nvidia", "DP-2", "connected");
|
||||
assert!(super::nvidia_drives_display(&drm), "NVIDIA drives a display");
|
||||
assert!(!super::nvidia_drives_display(&root.join("missing")));
|
||||
let _ = std::fs::remove_dir_all(&root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn native_frame_dimensions_are_padded_to_even() {
|
||||
// A scaled compositor can report an odd logical desktop (e.g. two stacked 150% monitors →
|
||||
|
||||
Reference in new issue
Block a user