diff --git a/AGENTS.md b/AGENTS.md index d47fbe0..894d89a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -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) | diff --git a/README.en.md b/README.en.md index f93b083..8c5f112 100644 --- a/README.en.md +++ b/README.en.md @@ -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) | diff --git a/README.md b/README.md index 1f45105..971d057 100644 --- a/README.md +++ b/README.md @@ -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) | diff --git a/src/video.rs b/src/video.rs index 77c9911..c21555d 100644 --- a/src/video.rs +++ b/src/video.rs @@ -262,10 +262,29 @@ fn cpu_hevc_options(settings: &VideoSettings, gop: &str) -> Vec { /// 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 { @@ -1062,6 +1081,28 @@ pub async fn stream_desktop(pc: Arc, track: Arc