omarchy icon indicating copy to clipboard operation
omarchy copied to clipboard

mpv wakes the runtime-suspended NVIDIA dGPU on hybrid laptops: ~3.5 s before the first frame (still true with #11690)

Open sergihrs opened this issue 1 month ago • 5 comments

System details

  • ASUS ROG Zephyrus G16 (GU605CP): Intel Core Ultra 9 285H, Arc 140T iGPU (i915, boot_vga=1, drives eDP) + RTX 5070 Laptop (nvidia-open 610.57.04, boot_vga=0, runtime-suspended when idle)
  • Omarchy 4.0.4-1, kernel 7.2.5-3-omarchy, mpv 0.41.0-6, mesa/vulkan-intel 26.2.2, vulkan-icd-loader 1.4.357

What's wrong?

Opening any video with Omarchy's default player (mpv, vo=gpu-next on Vulkan) wakes the dGPU: libplacebo enumerates every Vulkan device, the NVIDIA ICD resumes the card, and the first frame appears only after the resume (~3.5 s). The dGPU then stays awake while mpv runs.

This is independent of the VA-API/GLX env: with LIBVA_DRIVER_NAME and __GLX_VENDOR_LIBRARY_NAME unset (what #11690 does on this laptop), it still happens.

Measured on the same 4K60 VP9 file, launched like mpv.desktop, dGPU idle (suspended) before each run:

env first frame dGPU
Omarchy 4.0.4 default 3.8–4.0 s resumed
LIBVA_DRIVER_NAME/__GLX_VENDOR_LIBRARY_NAME unset (#11690) 3.7 s resumed
+ VK_LOADER_DRIVERS_DISABLE='*nvidia*' 0.5–0.8 s stays suspended

(first frame = mpv's playback restart complete in --log-file; dGPU state from /sys/bus/pci/devices/0000:01:00.0/power/runtime_status.)

Steps to reproduce

  1. On a hybrid laptop where the iGPU drives the display, let the dGPU suspend (runtime_status = suspended).
  2. Open a video from the file manager (or mpv --player-operation-mode=pseudo-gui -- file.mkv).
  3. The window stays empty for ~3.5 s; runtime_status becomes active.

Possible fix

VK_LOADER_DRIVERS_DISABLE='*nvidia*' is vendor-neutral (works for Intel and AMD iGPUs) and only affects the process it is set for. It could be applied to mpv when NVIDIA does not drive the display, e.g. with the omarchy-hw-nvidia-display detector from #11690, through Omarchy's mpv.desktop / a small launcher. It should not be set session-wide: games and prime-run need the NVIDIA Vulkan driver.

With VA-API on the iGPU as well (--hwdec=vaapi, iHD), 4K60 VP9 playback drops from ~1.6 CPU cores (software decode) to ~0.1 here, without waking the dGPU.

Filed by Claude Opus 5.5 via Claude Code.

sergihrs avatar Oct 04 '26 22:10 sergihrs

Thanks for the measurements. I read this against quattro (a6dcc31). It was not reproduced: none of our workers has a hybrid NVIDIA laptop.

What I found. Nothing in Omarchy points mpv at the NVIDIA card. applications/mpv.desktop runs plain mpv --player-operation-mode=pseudo-gui, etc/mpv/mpv.conf only sets hwdec=auto-safe, and on your boot_vga layout default/hypr/nvidia.lua already skips the VA-API/GLX overrides (#11690). The wake comes from upstream: libplacebo, which draws mpv's gpu-next output, creates a Vulkan instance and lists every physical device before it picks one, and listing the NVIDIA device resumes the card. That matches your result with VK_LOADER_DRIVERS_DISABLE, which removes the NVIDIA driver before anything is listed. mpv's --vulkan-device can't avoid this, because mpv 0.41 lists all the devices just to check the option's value. This isn't a duplicate. #12506 (the shell holding the dGPU awake) is the closest match, but the trigger there is different.

Why there is no fix PR. Hiding NVIDIA's Vulkan driver from mpv when the iGPU drives the panel is a policy choice, not a correction to broken code, so the maintainer has to decide it. The trade-offs:

  • Changing mpv.desktop alone leaves out the webcam overlay and the playback notification in omarchy-capture-screenrecording, the yt-dlp download playback in omarchy-chromium-ytdlp-host, and mpv started from a terminal.
  • omarchy-hw-nvidia-display reads boot_vga, which says which GPU drove the display at boot. It does not say which GPU each port is wired to. On laptops whose HDMI port is wired to the dGPU, mpv on that external screen would render on the iGPU, and each frame would be copied to the dGPU for display. That card would be awake anyway, so the change saves nothing there.
  • Anyone who wants mpv rendering on the dGPU would need a way to opt out, because --vulkan-device can't select a driver that has been filtered out.

One number would help the decision: does mpv --gpu-api=opengl (or --gpu-context=wayland) also leave the card suspended? If it does, that is an mpv-level option rather than a process environment variable. Measuring --hwdec=no the same way would show whether hwdec=auto-safe plays any part in the wake.

Reviewed by Claude Opus 5.5, with Codex Medium as a second opinion. Codex agreed it is a product decision and added the --vulkan-device and gpu-api=opengl points above. Its independence is not guaranteed. Labelled bug and compatibility. This is waiting on the maintainer.

omarchybot avatar Oct 18 '26 10:10 omarchybot

Measured what you asked on the same laptop (GU605CP, RTX 5070 Laptop runtime-suspended before every run): stock /usr/bin/mpv 0.41.0 with the #11690 env (LIBVA_DRIVER_NAME/__GLX_VENDOR_LIBRARY_NAME unset), hwdec=auto-safe as in etc/mpv/mpv.conf, a 1080p30 H.264 clip, 3 runs per row:

options dGPU first frame
default (gpu-next on Vulkan) resumed 4.7 s
--gpu-api=opengl resumed 2.8 s
--gpu-context=wayland resumed 2.8 s
--hwdec=no resumed 4.7 s
--hwdec=vaapi resumed 4.6 s
--gpu-api=opengl --hwdec=no stays suspended 0.14 s
--gpu-api=opengl --hwdec=vaapi stays suspended 0.11 s

So there are two separate wakes, and OpenGL alone removes only the first one:

  1. Vulkan: libplacebo lists the devices and picks the NVIDIA one.
  2. hwdec=auto-safe: with OpenGL, mpv tries h264-nvdec before h264-vaapi and loads the CUDA interop. CUDA init resumes the card (2.7 s), then cuGLGetDevices fails with CUDA_ERROR_INVALID_GRAPHICS_CONTEXT (the GL context is on the iGPU) and mpv falls back to VA-API on iHD.

--gpu-api=opengl --hwdec=vaapi keeps hardware decoding on the iGPU and never touches the dGPU, with mpv options only, no environment variable. It would still need the same gate, since it's the wrong choice where NVIDIA drives the display.

Note: the test window was on a headless Hyprland output. There, the NVIDIA Vulkan device also failed vkGetPhysicalDeviceSurfacePresentModesKHR (VK_ERROR_UNKNOWN) and mpv fell back to OpenGL, which is why the default row is ~1 s slower than in my first post.

Measured with Claude Code (Claude Opus 5.5).

sergihrs avatar Oct 19 '26 18:10 sergihrs

Thanks for running these. They change the picture: the wake doesn't need an environment variable to avoid. --gpu-api=opengl --hwdec=vaapi keeps the card suspended using mpv options alone, and --hwdec=vaapi still decodes in hardware on the iGPU.

What I checked. I read your numbers against quattro (82662dd) and against mpv 0.41's source. Your two-wake explanation fits the code. In the decoder probe order (video/decode/vd_lavc.c), NVDEC comes before VA-API. Under OpenGL, the CUDA interop check (video/out/hwdec/hwdec_cuda.c) calls cuInit before cuGLGetDevices can find out that the GL context belongs to the iGPU, so CUDA resumes the card and then falls back. That is why OpenGL alone wasn't enough. Nothing on quattro has changed this since my last reply. etc/mpv/mpv.conf still sets only hwdec=auto-safe, and default/hypr/nvidia.lua still gates only the VA-API/GLX environment. There is a pattern a fix could copy: bin/omarchy-install-video-decode writes a per-hardware hwdec into ~/.config/mpv/mpv.conf on Snapdragon laptops and leaves a user's own hwdec alone. The same could be done for hybrid NVIDIA laptops, gated on omarchy-hw-nvidia-display. This still wasn't reproduced, because no worker has a hybrid NVIDIA GPU.

One caveat on the rows. Your test window was on a headless output where mpv fell back from Vulkan to OpenGL, so the default, --hwdec=no and --hwdec=vaapi rows show a wake somewhere on Vulkan's setup path. They don't show successful Vulkan playback, and the timings can't be added up to prove two separate resumes. The two OpenGL rows that stayed suspended are the result that matters, and that caveat doesn't affect them. A run on the laptop's own panel with -v would show which API was tried and which one was used, if anyone wants it confirmed.

What it would cost. hwdec=vaapi instead of auto-safe gives up NVDEC, Vulkan decoding and the copy-back variants on those machines. A codec or profile the iGPU's VA-API can't handle would then fall back to software decoding rather than to the NVIDIA decoder. gpu-api=opengl gives up Vulkan rendering, but it keeps gpu-next and libplacebo's tone mapping. I can't point to a specific HDR or colour-management regression from it, so I'm not claiming one. The concerns from my earlier reply still apply: other mpv launch paths, boot_vga not saying which GPU each port is wired to, and an opt-out for anyone who wants mpv on the dGPU.

What happens next. Whether hybrid laptops should get this default is a product decision, so I haven't opened a fix PR. This is waiting on the maintainer.

Reviewed by Claude Opus 5.5, with Codex Medium as a second opinion. Codex agreed it is the maintainer's decision. It added the mpv source references for the probe order and the CUDA check, the headless-output caveat, and the costs above. Its independence is not guaranteed.

omarchybot avatar Oct 21 '26 17:10 omarchybot

Adding data from a hybrid laptop on its own panel, as requested. These are short runs with mpv -v, and I can share log excerpts on request.

Setup: Intel HD 520 (Skylake) + GTX 960M (Maxwell, nvidia-580xx 580.178.04, offload only). The internal panel (eDP-1) is on the Intel GPU, which has boot_vga=1. Omarchy 4.5.0-rc1 (omarchy-settings 4.5.0rc1-1), kernel 7.2.8-9-omarchy, mpv 0.41.0, libplacebo 7.360.1, FFmpeg 9.0.2, Mesa 26.2.5, intel-media-driver 26.3.5. Stock config: /etc/mpv/mpv.conf has only hwdec=auto-safe, and there is no user mpv config. 1080p30 clips in H.264, HEVC Main 8-bit (15 s) and VP9 profile 0, played with --end=8. Each row is 1 run, except where a count is given.

Run Vulkan/GL device used Decoder used NVIDIA touched?
A: default, H.264 Vulkan on GTX 960M vulkan (Using hardware decoding (vulkan). after libplacebo picked Device Name: NVIDIA GeForce GTX 960M) yes (NVIDIA device handles open, P5)
A: default, HEVC (3 runs) Vulkan on GTX 960M vaapi attempt fails at output, then software. 0 frames shown within --end=8, exit 2, in 3 of 3 runs yes (P0)
A: default, VP9 Vulkan on GTX 960M software yes (P0, ~28% SM)
B: --gpu-api=opengl --hwdec=vaapi GL on Intel HD 520 vaapi (H.264, HEVC), software (VP9, HW limit) no (no NVIDIA handles, stays P8)
C: VK_LOADER_DRIVERS_DISABLE='*nvidia*' Vulkan on Intel HD 520 vaapi (H.264, HEVC), software (VP9) yes: auto-safe still tries nvdec and opens /dev/nvidia0, nvidiactl, nvidia-uvm (VP9 also tries nvdec-copy, P5)

libplacebo enumerates both GPUs (GPU 0: Intel(R) HD Graphics 520 (integrated), GPU 1: NVIDIA GeForce GTX 960M (discrete)) and picks the NVIDIA one in run A.

In the default setup, HEVC also skips its opening. I played the same 15 s clip once more with --end=15. The first frame appeared only at the second keyframe (playback restart complete @ 8.333333), so the first 8.3 s were never shown. The chain in the log:

  1. hevc-vulkan and hevc-nvdec fail (Maxwell has no HEVC decode).
  2. hevc-vaapi decodes on Intel. Then the NVIDIA Vulkan output can't import Intel's tiled NV12 (DRM modifier INTEL 0x2 not available for format r8), and scale_vaapi fails (Hardware does not support output format bgr0 / Cannot convert decoder/filter output to any format supported by the output).
  3. mpv falls back to software decoding. That decoder then reports Could not find ref with POC 4 ... 248 until the next keyframe. It looks like the first keyframe was used up by the failed VA-API attempt.

The fallback behaviour itself looks like an upstream mpv/libplacebo issue rather than something Omarchy causes. But the Vulkan-on-dGPU default is what triggers it here. So on this kind of laptop the default also affects HEVC playback, not just power. Run B avoids both problems.

Caveats:

  • The card never suspended during testing. power/runtime_status read active, with control=on and suspended_time_ms=0, before and during every run. control=on means runtime PM is off for this device, and Maxwell has no RTD3 support anyway (it needs Turing or newer). So I can't show an actual wake from D3, only that mpv opens or uses the NVIDIA device (handles, P-state, nvidia-smi pmon).
  • Run C supports the earlier observation that hiding the NVIDIA Vulkan ICD isn't enough on its own: hwdec also has to skip nvdec/CUDA. I haven't tested ICD filtering combined with a restricted hwdec.
  • These were short runs only, with no power or battery measurements.

Happy to test a patch, for example a per-hardware gpu-api=opengl / hwdec=vaapi written by omarchy-install-video-decode when omarchy-hw-nvidia-display is false.

Heineck66 avatar Oct 21 '26 22:10 Heineck66

Thanks @Heineck66. This is the own-panel run my last reply asked for, and it fills a gap: on your laptop, with the iGPU driving the panel, stock mpv still renders on the NVIDIA card.

Why it picks NVIDIA. This is expected from the source, not a quirk of your machine. In libplacebo 7.360.1, pl_vulkan_choose_device() (src/vulkan/context.c) ranks discrete GPUs above integrated ones and takes the highest-ranked device that can present. Nothing there asks which GPU drives the panel. mpv 0.41 passes device choice straight to libplacebo. So on hybrid laptops the gpu-next Vulkan default lands on the dGPU whenever its driver is visible. One correction to my earlier wording: in mpv's probe order (hwdec_autoprobe_info[] in video/decode/vd_lavc.c), Vulkan decoding comes first, then NVDEC, then VA-API. NVDEC comes before VA-API, but it isn't first overall.

What it adds. On this hardware the default costs more than power. HEVC decoded by VA-API on the Intel GPU couldn't be imported by the NVIDIA Vulkan output (DRM modifier INTEL 0x2 not available). mpv then fell back to software decoding, and the opening 8.3 s of your clip were never shown. I'm taking that from your log as reported. I haven't traced the fallback myself, and the import failure is shown for this Intel/NVIDIA pair only, not for NVIDIA in general. Your run C also matches the earlier finding that hiding the NVIDIA Vulkan driver isn't enough on its own, because auto-safe still opens the card for NVDEC. Run B (--gpu-api=opengl --hwdec=vaapi) avoided both problems on your machine, as it did on @sergihrs's.

What it doesn't show. Your 960M has runtime power management off and doesn't support runtime D3 (NVIDIA's 580 driver needs Turing or newer for that), so this run shows mpv using the NVIDIA card, not a wake from suspend. The startup wake is still the original report's result.

What I checked. I read this against quattro (7075b61c6). etc/mpv/mpv.conf, applications/mpv.desktop, default/hypr/nvidia.lua, bin/omarchy-install-video-decode and bin/omarchy-hw-nvidia-display haven't changed since my last reply, and no open pull request touches this. It still isn't reproduced on our side, because no worker has a hybrid NVIDIA GPU.

What happens next. These results make a stronger case for a gated default on hybrid laptops, for example gpu-api=opengl and hwdec=vaapi written by omarchy-install-video-decode when omarchy-hw-nvidia-display says NVIDIA doesn't drive the display. They don't settle its scope. boot_vga still doesn't say which GPU each port is wired to, the other mpv launch paths still apply, and anyone who wants mpv on the dGPU would still need an opt-out. So no fix PR has been opened: this is still the maintainer's decision. The HEVC import-and-fallback behaviour is worth raising upstream with mpv/libplacebo whatever Omarchy decides.

Reviewed by Claude Opus 5.5, with Codex Medium as a second opinion. Codex couldn't fetch this thread itself, so it reviewed from a summary of your comment rather than your logs. It agreed this is still the maintainer's decision. It added the libplacebo device ranking, the probe-order correction and the runtime-D3 caveat above. Its independence is not guaranteed.

omarchybot avatar Oct 21 '26 23:10 omarchybot