swaywm / sway

i3-compatible Wayland compositor
https://swaywm.org
MIT License
14.43k stars 1.1k forks source link

Low frames and stuttering on display attached to second GPU #4596

Open mruediger opened 4 years ago

mruediger commented 4 years ago

I am using sway on my Laptop with an attached eGPU Radeon RX 580.The display attached to my eGPU feels very laggy. Running glxgears shows me ~16fps on my second display while the builtin display using the Intel card gives me ~60fps. I can only reproduce this on sway. Gnome, also with wayland, gives me 60fps on both displays.

I would love to track down the differences between Gnome and sway, but I don't know where to start.

ascent12 commented 4 years ago

By default, it's likely that your iGPU is selected as the "primary" GPU which actually does all of the rendering, leaving the RX580 basically underutilized. Try launching sway with WLR_DRM_DEVICES=/dev/dri/card1:/dev/dri/card0 to swap them around.

emersion commented 4 years ago

Note that doing so will cause frames displayed on the internal screen to do a roundtrip between the iGPU and the eGPU. Generally laptop eGPUs have less bandwidth available, so this could be an issue when using WLR_DRM_DEVICES=/dev/dri/card1:/dev/dri/card0.

I don't get why you have 60FPS on the internal screen but not on the eGPU's screen. We just render everything on the first GPU (the iGPU if you don't set WLR_DRM_DEVICES) and copy the frame to other GPUs.

Since you get 60FPS on the internal screen, you should also get 60FPS on the external screen: the only difference is a copy to the eGPU.

ascent12 commented 4 years ago

That copy could be slow as hell, making us miss vblank (possibly multiple) and we'll get fewer page flips, meaning fewer frame callbacks, meaning less FPS. The DRM backend multi-GPU code really needs to take damage into account.

emersion commented 4 years ago

Ah, right, that's a good point, haven't thought about damage. We should also allow DMA-BUFs to be directly scanned out, since the iGPU uses RAM for buffers it should just work in this case.

(And also other fallback mechanisms mentioned in https://gitlab.freedesktop.org/wayland/weston/issues/76)

mruediger commented 4 years ago

Thanks @ascent12 and @emersion. I honestly didn't expect a reaction that quickly.

Swapping the GPUs did what you predicted. I now have ~60fps on my external but only ~18fps on my internal GPU. If I understand it correctly, the content is rendered on my eGPU now and than copied back to my iGPU using only the few PCIe lanes dedicated to Thunderbolt and hence the stuttering.

The question now is what Gnome/Mutter does differently.

emersion commented 4 years ago

The question now is what Gnome/Mutter does differently.

This comment explains what Mutter does: https://gitlab.freedesktop.org/wayland/weston/issues/76#note_239702

mruediger commented 4 years ago

Just saw that as well. Sorry for commenting without reading the issue first. I will take a dive into it. Thank you!

emersion commented 4 years ago

No worries.

For reference, the current multi-GPU copy code is here: https://github.com/swaywm/wlroots/blob/master/backend/drm/renderer.c#L258

geekuillaume commented 4 years ago

Is there any news related to implementing other multi-GPU copy strategy that could improve performance?

Edit: it seems this PR should improve the situation a lot https://github.com/swaywm/wlroots/pull/2133

ardevd commented 4 years ago

I'm wondering the same thing.

m01 commented 3 years ago

How do you display the fps in sway?

Zeioth commented 2 years ago

I can confirm I also experience this issue with 2 AMD gpus. It's very obvious even on the desktop.

FIXED: Installed wlroots-git and sway-git, restarted the session and now the issue is gone! EDIT: It seem to improve the issue, but it's still there.

Zeioth commented 2 years ago

I tested with the RX 550 as main GPU and the 6700 as the secondary one, and I don't have the issue. It seems it's necessary to use two of the same GPU (or a slightly more powerful secondary one?) for optimal results.

This is for gaming, mostly. For video and productivity, about any GPU will do just fine.

yurikhan commented 8 months ago

Getting something like this as well.

Measurement methods:

Results:

pulkin commented 3 months ago

I also have a similar issue with a thunderbolt-connected egpu. My setup: Intel graphics laptop, Fedora, Wayland, thunderbolt epgu with Radeon graphics and an HDMI output connected to an egpu. This setup works fine (i.e. I can offload compute tasks to egpu for example) but the desktop performance of the external screen is not great and visually below 30fps. 3D benchmarks show low scores in line with user expereince.

Frankly speaking, this issue was there for quite a while (one or two Fedora upgrades). I am just wondering if there is any movement here. My temporary "solution" is to reboot and disable intel graphics completely via unloading the kernel module i915.modeset=0. This also makes my laptop screen unusable.

UPD: glxgears report 90fps for the internal screen (expected) and 30fps for the HDMI output (I expect it to be 60fps). Setting to "mirror displays" will make it close to 45fps. Not sure if it is expected. Visually either setting looks poorly.