mpv-player / mpv

🎥 Command line video player
https://mpv.io
Other
28.66k stars 2.93k forks source link

Dual GPU not accelerating correctly with --vulkan-device #15311

Closed rijnhard closed 1 week ago

rijnhard commented 1 week ago

mpv Information

mpv 0.39.0 Copyright © 2000-2024 mpv/MPlayer/mplayer2 projects
libplacebo version: v7.349.0
FFmpeg version: 7.0.2
FFmpeg library versions:
   libavcodec      61.3.100
   libavdevice     61.1.100
   libavfilter     10.1.100
   libavformat     61.1.100
   libavutil       59.8.100
   libswresample   5.1.100
   libswscale      8.1.100

Other Information

- Linux version: Fedora Linux 41 (KDE Plasma)
- Kernel Version: 6.9.12 (also on 6.11.7)
- GPU Model:
    00:01.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Kaveri [Radeon R7 Graphics] [1002:130f]
    03:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Navi 24 [Radeon RX 6400/6500 XT/6500M] [1002:743f] (rev c7)
- Mesa/GPU Driver Version: 24.2.6
- Window Manager and Version: KWin 6.2.3-1
- Source of mpv: Fedora repo
- Latest known working version: ? 
- Issue started after the following happened: n/a

Reproduction Steps

Bare with me on this, I'm trying to make best of a broken world.

I have a TV connected to Kaveri (iGPU) HDMI, because of an outstanding amdgpu bug affecting my RX 6400 (which causes the TV to frequently disconnect), this means switcheroo is active. So the idea is to use the RX 6400 (dGPU) for the video decoding because the kaveri cannot handle H265@4k.

To simplify things, I can confirm that having the dGPU connected to the TV can play 4k H265 with hdr perfectly (barring screen disconnects), with the following profile.

vo=gpu-next
gpu-api=vulkan
gpu-context=waylandvk
hwdec=vaapi

Now after some digging I found --vulkan-device which returns:

mpv --vulkan-device=help
WARNING: radv is not a conformant Vulkan implementation, testing use only.
WARNING: radv is not a conformant Vulkan implementation, testing use only.
Available vulkan devices:
  'AMD Radeon R7 Graphics (RADV KAVERI)' (GPU 0, PCI ID 1002:130f, UUID 00000000-0000-0000-0100-000000000000)
  'AMD Radeon RX 6400 (RADV NAVI24)' (GPU 1, PCI ID 1002:743f, UUID 00000000-0300-0000-0000-000000000000)
  'llvmpipe (LLVM 19.1.0, 256 bits)' (GPU 2, PCI ID 10005:0, UUID 6d657361-3234-2e32-2e36-000000000000)

Now with the HDMI connected to the kaveri and switcheroo active, and simply adding the flag specifying the RX 6400 via name or uuid, doesn't error but doesn't change results. Results are as choppy as just using the kaveri without the RX 6400 installed.

Notes:

Expected Behavior

Should offload video decoding to the dGPU even under switcheroo when requested.

Actual Behavior

Always uses primary gpu for decoding.

Log File

mpv.log

Sample Files

No response

I carefully read all instruction and confirm that I did the following:

llyyr commented 1 week ago

You need to use DRI_PRIME=1 for this and a new enough Mesa (24.3 or newer) https://gitlab.freedesktop.org/mesa/mesa/-/commit/ed781c74032ec3ff893bd0d60d9b88a3055476f5

DRI_PRIME=1 will probably work under x11 on your current mesa, if you want to use that as well

Also --vulkan-device would control the rendering device here, not the hwdec device, you'd need to use hwdec=vulkan for this to affect hardware accelerated video decoding but your gpus probably don't support it. The vaapi equivalent --vaapi-device only works with vaapi-copy mode.

rijnhard commented 1 week ago

I have been using DRI_PRIME but didn't include it in the ticket because it had no effect, but I didn't know about the mesa bug! Thank you soo much for sharing that, 24.3 should be out soon, so that should then solve the problem.

And thank you for explaining the difference. It's been rough getting this new gpu and not being able to use it.

Yeah the mesa team AFAIK is still experimenting with the vulkan decoding on amd, so it totally fails and doesn't have the required extension.

llyyr commented 1 week ago

You can make it work right now as well if you switch to x11 session on kwin, or run mpv under xwayland with --gpu-context=x11vk

kasper93 commented 1 week ago

Yeah the mesa team AFAIK is still experimenting with the vulkan decoding on amd, so it totally fails and doesn't have the required extension.

For this you have to define RADV_PERFTEST=video_decode to expose extensions, if your gpu is supported.

rijnhard commented 1 week ago

You can make it work right now as well if you switch to x11 session on kwin, or run mpv under xwayland with --gpu-context=x11vk

I mean I can, but ewww. Tbh I haven't used x11 in the last 8 years on my htpc. And it's mostly been fine :p. I'd rather just keep experimenting and logging bugs and try to be helpful to the maintainers.

But I do appreciate the workaround

rijnhard commented 1 week ago

Yeah the mesa team AFAIK is still experimenting with the vulkan decoding on amd, so it totally fails and doesn't have the required extension.

For this you have to define RADV_PERFTEST=video_decode to expose extensions, if your gpu is supported.

Oooooooooo it worked on the kaveri! That's kinda insane, considering it's age. (I mean playback is still choppy, but it rendered), I'll be playing with this in the future.