luisbocanegra / plasma-smart-video-wallpaper-reborn

Smart Video Wallpaper for KDE Plasma 6
https://store.kde.org/p/2139746
GNU General Public License v2.0
45 stars 1 forks source link

hardware video acceleration for discrete graphics failed #10

Closed paladin4fan closed 3 months ago

paladin4fan commented 3 months ago

Hi. I'm using a PC with integrated gpu and discrete gpu (Intel UHD 770 and AMD radeon rx 6950XT), and monitor connected via discrete gpu. I've installed the intel-media-driver and libva-mesa-driver. I verivied them via ffmpeg cli with -vaapi_device and both of them worked (encode without error and I can obtain the progress using 'enc' or 'video' resource in amdgpu_top and intel_gpu_top)

If I keeps everything as default, the video-wallpaper plugin uses iGPU as vaapi device, and it works perfect in x11. But once I switch to wayland backend, the video decoding corruption. Looks like moving blurred screen. (Intel_cpu_top shows the plasmashell is using video)

If I set environment variables LIBVA_DRIVER_NAME=radeonsi , the video play normally in both x11 and wayland. but I see 0% in amdgpu_top.

luisbocanegra commented 3 months ago

Do you have mesa-vdpau installed?

If I set environment variables LIBVA_DRIVER_NAME=radeonsi , the video play normally in both x11 and wayland. but I see 0% in amdgpu_top.

Does it show video decoding usage when you run mpv --hwdec=auto video_filename?

Have you tried nvtop? Not sure how well it works with AMD but if it supports video decoding it should show a DEC bar:

image

I don't have an AMD GPU to test this plugin so all I can do is speculate, if decoding doesn't work with this plugin but works with mpv, this could be yet another qt+amd bug.

If that's the case can you try switching to Qt Media Backend to Gstreamer?

paladin4fan commented 3 months ago

Do you have mesa-vdpau installed?

If I set environment variables LIBVA_DRIVER_NAME=radeonsi , the video play normally in both x11 and wayland. but I see 0% in amdgpu_top.

Does it show video decoding usage when you run mpv --hwdec=auto video_filename?

Have you tried nvtop? Not sure how well it works with AMD but if it supports video decoding it should show a DEC bar:

image

I don't have an AMD GPU to test this plugin so all I can do is speculate, if decoding doesn't work with this plugin but works with mpv, this could be yet another qt+amd bug.

If that's the case can you try switching to Qt Media Backend to Gstreamer?

Thanks for replying.

With mpv --hwdec=auto I can only use amd gpu. $ mpv --vo=gpu --hwdec=auto 3840\ 2160\ 35\ long.mp4 (+) Video --vid=1 (*) (h264 3840x2160 60.000fps) Using hardware decoding (vaapi). VO: [gpu] 3840x2160 vaapi[nv12] Then in nvtop I can obtained DEC useage on amdgpu. image

~~But I can't use intel vaapi driver in mpv. LIBVA_DRIVER_NAME=iHD LIBVA_DRIVERS_PATH=/usr/lib/dri/iHD_drv_video.so mpv --vo=gpu --hwdec=vaapi --vaapi-device=/dev/dri/renderD128 3840\ 2160\ 35\ long.mp4 doesn't return any 'Using hardware decoding' and no dev/enc usage in nvtop. Just using 'LIBVA_DRIVER_NAME=iHD' along returns '[vaapi] libva: /usr/lib/dri/iHD_drv_video.so init failed' Using '--vaapi-device=/dev/dri/renderD128' along it shows hwdec works but in nvtop I found the mpv still using amd gpu as vaapi device (it should be renderD129)~~

BTW if I use ffmpeg encoder, both of them works. ffmpeg -threads 4 -i 3840\ 2160\ 35\ long.mp4 -vaapi_device /dev/dri/renderD129 -vcodec h264_vaapi -vf format='nv12|vaapi,hwupload' output1.mp4 image

LIBVA_DRIVER_NAME=iHD ffmpeg -threads 4 -i 3840\ 2160\ 35\ long.mp4 -vaapi_device /dev/dri/renderD128 -vcodec h264_vaapi -vf format='nv12|vaapi,hwupload' output1.mp4 image

Then I've tried to use export QT_MEDIA_BACKEND=gstreamer but the plasmashell keeps crashing after reboot. plasmashell-20240409-005419.txt

As for vdpau, I haven't installed it yet. If I install it now, how to switch the hw decoder for the plugin?

------Update------ After I lookup the manual of mpv, I found I need to use --hwdec=vaapi-copy to use --vaapi-device option. So I tried LIBVA_DRIVER_NAME=iHD mpv 3840\ 2160\ 35\ long.mp4 --hwdec=vaapi-copy --vaapi-device=/dev/dri/renderD128 And nvtop shows the usage bar of DEC/ENC on Intel iGPU. But with --hwdec=auto it will not be used.

luisbocanegra commented 3 months ago

So if you switch back to ffmpeg there is no gpu decoding usage in nvtop when the wallpaper is playing even if LIBVA_DRIVER_NAME=radeonsi is set?

paladin4fan commented 3 months ago

So if you switch back to ffmpeg there is no gpu decoding usage in nvtop even if LIBVA_DRIVER_NAME=radeonsi is set?

If I use ffmpeg both of them works and I can see encoding usage bar because I use ffmpeg cli to encode a video.

luisbocanegra commented 3 months ago

Sorry I wasn't clear enough, I mean is there gpu video decoding usage when the wallpaper is playing

Also encoding is irrelevant for playing videos.

paladin4fan commented 3 months ago

Also encoding is irrelevant for playing videos

I see. I just tried the ffmpeg cli to ensure the program could use mesa-vaapi. As for now, I setted export LIBVA_DRIVER_NAME=radeonsi in ~/.bash_profile But plasmashell just keep high cpu usage, and no decoder usage of amd gpu in nvtop.

luisbocanegra commented 3 months ago

Also encoding is irrelevant for playing videos

I see. I just tried the ffmpeg cli to ensure the program could use mesa-vaapi. As for now, I setted export LIBVA_DRIVER_NAME=radeonsi in ~/.bash_profile But plasmashell just keep high cpu usage, and no decoder usage of amd gpu in nvtop.

Try setting it in ~/.config/plasma-workspace/env/qt-media-backend.sh instead:

export LIBVA_DRIVER_NAME=radeonsi

https://userbase.kde.org/Session_Environment_Variables

paladin4fan commented 3 months ago

Also encoding is irrelevant for playing videos

I see. I just tried the ffmpeg cli to ensure the program could use mesa-vaapi. As for now, I setted export LIBVA_DRIVER_NAME=radeonsi in ~/.bash_profile But plasmashell just keep high cpu usage, and no decoder usage of amd gpu in nvtop.

Try setting it in ~/.config/plasma-workspace/env/qt-media-backend.sh instead:

export LIBVA_DRIVER_NAME=radeonsi

https://userbase.kde.org/Session_Environment_Variables

Switched. nothing change

luisbocanegra commented 3 months ago

Please run the test.qml linked in the readme

LIBVA_DRIVER_NAME=radeonsi QSG_INFO=1 QT_LOGGING_RULES="qml.debug=true" qml6 test.qml

Share the output and let me know if decoding works

paladin4fan commented 3 months ago
qt.scenegraph.general: threaded render loop
qt.scenegraph.general: Using sg animation driver
qt.scenegraph.general: Animation Driver: using vsync: 16.68 ms
qt.scenegraph.general: Using sg animation driver
qt.scenegraph.general: Animation Driver: using vsync: 16.68 ms
qt.scenegraph.general: Creating QRhi with backend OpenGL for window 0x5f6632437750 (wflags 0x1)
  Graphics API debug/validation layers: 0
  Debug markers: 0
  Timestamps: 0
  Prefer software device: 0
  Shader/pipeline cache collection: 0
qt.rhi.general: Created OpenGL context QSurfaceFormat(version 4.6, options QFlags<QSurfaceFormat::FormatOption>(DeprecatedFunctions), depthBufferSize 24, redBufferSize 8, greenBufferSize 8, blueBufferSize 8, alphaBufferSize 8, stencilBufferSize 8, samples 0, swapBehavior QSurfaceFormat::DefaultSwapBehavior, swapInterval 1, colorSpace QColorSpace(), profile  QSurfaceFormat::CompatibilityProfile)
qt.rhi.general: OpenGL VENDOR: AMD RENDERER: AMD Radeon RX 6950 XT (radeonsi, navi21, LLVM 17.0.6, DRM 3.57, 6.8.4-arch1-1) VERSION: 4.6 (Compatibility Profile) Mesa 24.0.4-arch1.2
qt.scenegraph.general: Created QRhi 0x783014001cb0 for window 0x5f6632437750
qt.scenegraph.general: MSAA sample count for the swapchain is 1. Alpha channel requested = no.
qt.scenegraph.general: rhi texture atlas dimensions: 2048x2048
Failed to open VDPAU backend libvdpau_nvidia.so: Unable to open shared target file: No such file or directory available
iris: driver missing

No decoder bar shows. Is that means only VDPAU could be used?

luisbocanegra commented 3 months ago

install mesa-vdpau reboot and send output of vdpauinfo https://wiki.archlinux.org/title/Hardware_video_acceleration#Verifying_VDPAU

I think you need to configure VDPAU

paladin4fan commented 3 months ago

All right, I made it. Thanks alot.

I still need to specify

export LIBVA_DRIVER_NAME=radeonsi

Otherwise the plasmashell will use iHD automatically. In wayland the decoded video looks like this: image

Meanwhile I also need to add

export VDPAU_DRIVER=radeonsi

so that vdpauinfo could load the driver correctly. Now I can find the plasmashell use around 10%-20% decode on my amdgpu (but still 45% cpu usage?)

BTW a little unrelated topic, the ffmpeg with iHD driver doesn't work, but I can use iGPU decoder in mpv with 'vaapi-copy' VDPAU of amdgpu finally works on the ffmpeg player, but it can not be used directly in mpv, it also need 'vdpau-copy' Seems a little strange

luisbocanegra commented 3 months ago

Now I can find the plasmashell use around 10%-20% decode on my amdgpu (but still 45% cpu usage?)

Where do you get this metric?

This is the usage I get with Intel UHD Graphics 630 image

Smaller video: image

BTW a little unrelated topic, the ffmpeg with iHD driver doesn't work, but I can use iGPU decoder in mpv with 'vaapi-copy'

For iGPU maybe you need to set export LIBVA_DRIVER_NAME VDPAU_DRIVER to intel counterparts too?

VDPAU of amdgpu finally works on the ffmpeg player, but it can not be used directly in mpv, it also need 'vdpau-copy' Seems a little strange

How about vlc/firefox, do you get accelerated video decoding there? If you do, how's the performance?

paladin4fan commented 3 months ago

Where do you get this metric?

For amd gpu there is a util named amdgpu_top. image

For iGPU maybe you need to set export LIBVA_DRIVER_NAME VDPAU_DRIVER to intel counterparts too?

It seems iGPU has no directly VDPAU driver? Maybe I need libvdpau-va-gl? But iGPU works well in x11 before. The distortion appears after I switched to wayland.

How about vlc/firefox, do you get accelerated video decoding there? If you do, how's the performance?

I'm not using VLC/Firefox. I'll try them later today. For current player/browser mpv's hardware decoding works well, almost no cpu usage. Chrome shows hardware acceleration has been enable, but when I watching videos on YouTube, there is Chrome progress in intel_gpu_top, but no usage. (As for amdgpu, chrome returns me 'libva init failed')

luisbocanegra commented 3 months ago

Where do you get this metric?

For amd gpu there is a util named amdgpu_top. image

Hmm, maybe is the qt multimedia implementation not being good enough for amd? Is the usage the same from the test.qml? (make sure the plasma wallpaper is no longer playing when you test the qml)

For iGPU maybe you need to set export LIBVA_DRIVER_NAME VDPAU_DRIVER to intel counterparts too?

It seems iGPU has no directly VDPAU driver? Maybe I need libvdpau-va-gl? But iGPU works well in x11 before. The distortion appears after I switched to wayland.

Maybe, hard to tell until I get my hands on a system like this (I don't even have a desktop so...).

How about vlc/firefox, do you get accelerated video decoding there? If you do, how's the performance? I'm not using VLC/Firefox. I'll try them later today. For current player/browser mpv's hardware decoding works well, almost no cpu usage. Chrome shows hardware acceleration has been enable, but when I watching videos on YouTube, there is Chrome progress in intel_gpu_top, but no usage. (As for amdgpu, chrome returns me 'libva init failed')

Could the performance issues be related to which gpu is the main one? If you can please try booting with each card alone to see if there's any difference

paladin4fan commented 3 months ago

Hmm, maybe is the qt multimedia implementation not being good enough for amd? Is the usage the same from the test.qml? (make sure the plasma wallpaper is no longer playing when you test the qml)

test.qml returns me a 1% dec usage with 10% cpu usage

For iGPU maybe you need to set export LIBVA_DRIVER_NAME VDPAU_DRIVER to intel counterparts too?

I tested it in test.qml.

LIBVA_DRIVER_NAME=iHD QSG_INFO=1 QT_LOGGING_RULES="qml.debug=true" qml6 test.qml

Return a broken decode frame,

In log I can see

libva error: /usr/lib/dri/iHD_drv_video.so init failed

The same error with 'vainfo', but for vainfo I could use '--display drm --device /dev/dri/renderD128', don't know how to achive it with test.qml

If I use

LIBVA_DRIVERS_PATH=/usr/lib/dri/iHD_drv_video.so LIBVA_DRIVER_NAME=iHD QSG_INFO=1 QT_LOGGING_RULES="qml.debug=true" qml6 test.qml

Video play normally but the dec useage bar is on amd gpu instead of igpu

If I use

LIBVA_DRIVERS_PATH=/usr/lib/dri/iHD_drv_video.so LIBVA_DRIVER_NAME=iHD VDPAU_DRIVER=va_gl QSG_INFO=1 QT_LOGGING_RULES="qml.debug=true" qml6 test.qml

It returns me 'Failed setup for format vdpau: hwaccel initialisation returned error.' Nither iGPU or dGPU hw accel got dec usage.

Could the performance issues be related to which gpu is the main one? If you can please try booting with each card alone to see if there's any difference

I can try to disable iGPU in bios. But for amd gpu, it's hard to remove it because it's installed with custom liquid cooling system.

luisbocanegra commented 3 months ago

Hmm, maybe is the qt multimedia implementation not being good enough for amd? Is the usage the same from the test.qml? (make sure the plasma wallpaper is no longer playing when you test the qml)

test.qml returns me a 1% dec usage with 10% cpu usage

Hmm, then it could be that running from the wallpaper (it's basically the same code) has some extra overhead due to Plasma for some reason.

For iGPU maybe you need to set export LIBVA_DRIVER_NAME VDPAU_DRIVER to intel counterparts too?

I tested it in test.qml.

LIBVA_DRIVER_NAME=iHD QSG_INFO=1 QT_LOGGING_RULES="qml.debug=true" qml6 test.qml

Return a broken decode frame,

In log I can see

libva error: /usr/lib/dri/iHD_drv_video.so init failed

The same error with 'vainfo', but for vainfo I could use '--display drm --device /dev/dri/renderD128', don't know how to achive it with test.qml

If I use

LIBVA_DRIVERS_PATH=/usr/lib/dri/iHD_drv_video.so LIBVA_DRIVER_NAME=iHD QSG_INFO=1 QT_LOGGING_RULES="qml.debug=true" qml6 test.qml

Video play normally but the dec useage bar is on amd gpu instead of igpu

If I use

LIBVA_DRIVERS_PATH=/usr/lib/dri/iHD_drv_video.so LIBVA_DRIVER_NAME=iHD VDPAU_DRIVER=va_gl QSG_INFO=1 QT_LOGGING_RULES="qml.debug=true" qml6 test.qml

It returns me 'Failed setup for format vdpau: hwaccel initialisation returned error.' Nither iGPU or dGPU hw accel got dec usage.

Could the performance issues be related to which gpu is the main one? If you can please try booting with each card alone to see if there's any difference

I can try to disable iGPU in bios. But for amd gpu, it's hard to remove it because it's installed with custom liquid cooling system.

Weird, maybe those errors are caused by the dual gpu.

How did you setup the cards? I mean what's the primary renderer? You can get that it with glxinfo | grep -E "OpenGL vendor|OpenGL renderer"

paladin4fan commented 3 months ago

How did you setup the cards? I mean what's the primary renderer? You can get that it with glxinfo | grep -E "OpenGL vendor|OpenGL renderer"

I keeped it as default. In the output of test.qml it obviously use amdgpu.

luisbocanegra commented 3 months ago

You could try switching primary renderer to see it that makes any difference https://www.reddit.com/r/kde/comments/1ainwf5/how_i_worked_around_poor_performance_with/

paladin4fan commented 3 months ago

You could try switching primary renderer to see it that makes any difference

Did you mean :

LIBVA_DRIVER_NAME=iHD KWIN_DRM_DEVICES=/dev/dri/renderD128 QSG_INFO=1 QT_LOGGING_RULES="qml.debug=true" qml6 test.qml

It seems not helpful for render device.

But afte I found this thread: https://bbs.archlinux.org/viewtopic.php?id=264899

I tried

LIBVA_DRIVER_NAME=iHD DRI_PRIME=1 QSG_INFO=1 QT_LOGGING_RULES="qml.debug=true" qml6 test.qml

Then it works! The video play without error. Not only 'Video' but also 'Render/3D' usage bar appeared in intel_gpu_top. (Even lower usage of 'video' engine than amd gpu, is that normal?) image

And another little issue is once the test.qml start running, once I click 'exit fullscreen' the window disappeared with logs below:

[destroyed object]: error 7: importing the supplied dmabufs failed
The Wayland connection experienced a fatal error: protocol error 

It seems a issue relate to wayland.

luisbocanegra commented 3 months ago

You could try switching primary renderer to see it that makes any difference

Did you mean :

LIBVA_DRIVER_NAME=iHD KWIN_DRM_DEVICES=/dev/dri/renderD128 QSG_INFO=1 QT_LOGGING_RULES="qml.debug=true" qml6 test.qml

It seems not helpful for render device.

Similar but not quite. The linked reddit post sets the primary renderer for the whole plasma session instead of just a single process

But afte I found this thread: https://bbs.archlinux.org/viewtopic.php?id=264899

I tried

LIBVA_DRIVER_NAME=iHD DRI_PRIME=1 QSG_INFO=1 QT_LOGGING_RULES="qml.debug=true" qml6 test.qml

Then it works! The video play without error. Not only 'Video' but also 'Render/3D' usage bar appeared in intel_gpu_top. (Even lower usage of 'video' engine than amd gpu, is that normal?) image

Yeah, the same happens with Nvidia for some reason intel is better at doing this??

Maybe you can set the iGPU as primary renderer and run your gpu intensive tasks with dGPU? Or somehow force plasmashell to run on iGPU and everything else on dGPU, not sure if that's even possible

And another little issue is once the test.qml start running, once I click 'exit fullscreen' the window disappeared with logs below:

[destroyed object]: error 7: importing the supplied dmabufs failed
The Wayland connection experienced a fatal error: protocol error 

It seems a issue relate to wayland.

Yeah it seems it doesn't like rendering with another gpu that isn't the main one.

paladin4fan commented 3 months ago

Maybe you can set the iGPU as primary renderer and run your gpu intensive tasks with dGPU? Or somehow force plasmashell to run on iGPU and everything else on dGPU, not sure if that's even possible

Yes. I think it is difficult to make plasmashell use iGPU render along