Bug 453386 - Multi/hybrid GPU double copy
Summary: Multi/hybrid GPU double copy
Status: REPORTED
Alias: None
Product: kwin
Classification: Plasma
Component: platform-drm (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR wishlist
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-05-04 13:27 UTC by ctj9512
Modified: 2023-12-12 02:00 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ctj9512 2022-05-04 13:27:17 UTC
Using a hybrid GPU system will cause the compositor to run on a single GPU. This is the integrated GPU by default. If the display is connected to the discrete GPU, and the application is rendered on the discrete GPU, the graphics data is first copied to the integrated GPU (where the compositor runs), then copied back to the discrete GPU. This causes significant performance loss.

GNOME has the ability to set the discrete GPU as primary, so the compositor runs on the discrete GPU. However, this causes it to crash every time the monitor connected to the discrete GPU is plugged or unplugged. 

Ideally, the compositor would run separately on each GPU.
Comment 1 ctj9512 2022-05-04 13:43:12 UTC
Plasma would crash immediately if `KWIN_DRM_DEVICES` is used to select the primary GPU.
Comment 2 Zamundaaa 2022-05-05 16:02:25 UTC
> Ideally, the compositor would run separately on each GPU
Technically speaking it is possible, but practically speaking it would be a multi-year effort. It will not happen in the foreseeable future.

What can be done though is that KWin is smarter with choosing the compositing GPU, and that it can switch between GPUs at runtime. The former could maybe still be done for 5.25, the latter is planned for 5.26.

> Plasma would crash immediately if `KWIN_DRM_DEVICES` is used to select the primary GPU
That can probably be fixed. Can you provide the backtrace for kwin_wayland?
Comment 3 ctj9512 2022-05-07 18:40:03 UTC
> Can you provide the backtrace for kwin_wayland?

Ah. I checked the logs, and it said:

kwin_wayland_drm: failed to open drm device at "/dev/dri/by-name/pci-0000"
kwin_wayland_drm: failed to open drm device at "03"
kwin_wayland_drm: failed to open drm device at "00.0-card"
kwin_wayland_drm: failed to open drm device at "/dev/dri/by-name/pci-0000"
kwin_wayland_drm: failed to open drm device at "07"
kwin_wayland_drm: failed to open drm device at "00.0-card"
kwin_wayland_drm: No suitable DRM devices have been found

Looks like I was being stupid when setting this up. I wanted to avoid using `card0` and `card1`, since they are not consistent across reboots.

Is there a way to reference the cards consistently?
Comment 4 Zamundaaa 2022-05-07 19:13:08 UTC
Ah. That is very unfortunate. A different separator would probably be good...
Comment 5 Zamundaaa 2022-05-07 19:24:53 UTC
https://invent.kde.org/plasma/kwin/-/merge_requests/2355 should fix that
Comment 6 ctj9512 2022-05-07 19:35:22 UTC
I tested using `card0` on a laptop. The discrete card runs the compositor, but the built in display dos not display anything. The Display Configuration settings only show the external monitor.
Comment 7 Zamundaaa 2022-05-07 20:16:47 UTC
What environment variable did you use exactly? If you only specify one card, then KWin will only use that one card and ignore all others
Comment 8 ctj9512 2022-05-07 20:31:46 UTC
(In reply to Zamundaaa from comment #7)
> What environment variable did you use exactly? If you only specify one card,
> then KWin will only use that one card and ignore all others

I only had one card listed. I will test it with 2 cards listed.
Comment 9 ctj9512 2022-05-07 21:13:15 UTC
I tested with 2 cards listed. Plasma does not crash if the external monitor is unplugged. However, the double copy is still occurring.
Comment 10 Vlad Zahorodnii 2022-05-09 08:29:04 UTC
Git commit a110aabbccf56019bdc324b3c751112f35ec3f6c by Vlad Zahorodnii, on behalf of Xaver Hugl.
Committed on 09/05/2022 at 08:16.
Pushed by vladz into branch 'master'.

backends/drm: consider escaped separators KWIN_DRM_DEVICES

':' conflicts with the file names in /dev/dri/by-path, so allow it to be
escaped with '\'

M  +23   -1    src/backends/drm/drm_backend.cpp

https://invent.kde.org/plasma/kwin/commit/a110aabbccf56019bdc324b3c751112f35ec3f6c
Comment 11 Vlad Zahorodnii 2022-05-09 08:30:58 UTC
Git commit 3b58fe4bde0722b352e4114adb992a2ed2c96423 by Vlad Zahorodnii, on behalf of Xaver Hugl.
Committed on 09/05/2022 at 08:30.
Pushed by vladz into branch 'Plasma/5.24'.

backends/drm: consider escaped separators KWIN_DRM_DEVICES

':' conflicts with the file names in /dev/dri/by-path, so allow it to be
escaped with '\'


(cherry picked from commit a110aabbccf56019bdc324b3c751112f35ec3f6c)

M  +23   -1    src/backends/drm/drm_backend.cpp

https://invent.kde.org/plasma/kwin/commit/3b58fe4bde0722b352e4114adb992a2ed2c96423
Comment 12 ctj9512 2022-05-14 04:53:34 UTC
Would double copy be affected by direct scanout?

I attempted using Sway and an application running fullscreen with direct scanout would not be affected by performance loss. However, only Weston supports direct scanout with an application that is windowed (not fullscreen).
Comment 13 Zamundaaa 2022-08-18 23:29:12 UTC
Sorry for the late reply; to answer your question: Direct scanout avoids copies and does indeed prevent performance losses