All-ways-eGPU: Script for Wayland Linux Desktops
For Linux-based systems, desktops using Wayland have become more and more popular as a replacement for the X (Xorg) display server. Most recently, the transition of Ubuntu 21.04 to a Wayland-based GNOME desktop by default has made the most news, however many other distros and desktops exist using a Wayland protocol either optionally or by default. This includes desktops such as KDE Plasma, Weston and Sway.
If you have an Xorg based desktop, existing solutions such as gswitch or egpu-switcher allow for setting the eGPU as the primary display renderer for best performance and responsiveness. For Xorg desktops, these solutions are still the best option and should be preferred over this script. However, due to the nature of the Wayland protocol, there is not yet any universal way (at least as far as I know) to specify the primary GPU renderer for the compositor. This seems to be left to the specific way the compositor is implemented. Thus, GNOME's mutter may have a different process compared to Sway's wl-roots or KDE's KWin, etc.
This results in 2 options. Either the compositor could implement a specific way to control the primary renderer, or the user could use DRI_PRIME to offload rendering to a secondary GPU. Neither of these are optimal. The first requires specific work from the project developing the compositor and their specific method of control may not be the same as for other compositors. The second method of using DRI_PRIME (or similar offloading techniques) results in significantly reduced performance for eGPUs due to unnecessary transfer of display data across the eGPU's bandwidth-limited connection. The purpose of this script is to use a universal system that works across all compositors and enables maximum possible eGPU performance.
How does this script work?:
This script requests that the user disables their iGPU graphics device(s) at boot. This leaves the compositor no other choice except to use the eGPU when booting. This may seem like an extreme solution and it is in some ways, however, as this script was designed for portability across desktops and distros, this method makes for the most universal solution. Note that there is also an option to re-enable the iGPU device after login or if no other GPU is found (if the eGPU is not plugged in or not working).
In order to disable the iGPU graphics, their PCI Bus IDs and drivers are stored in /usr/share/all-ways-egpu/user-bus-ids, which is then used by the script to unbind the virtual terminals, drivers and finally PCIe device addresses.
It is again stressed that this script is focussed on maximum performance on eGPU connected displays. Displays connected to the iGPU such as the laptop’s internal display may stay blank.
Installation and Usage:
Installation of the script can be done with the following one-line command in the terminal:
After installing, setup the script with the following command:
After following the prompts, the script should now be ready to use. If you have the eGPU connected, you may try it out by manually switching to the eGPU.
If this works, you may configure the script to automatically switch every bootup:
Wayland based desktops have continued to pick up steam and become more stable. Some have even started adding GPU hot-plugging support, though none can currently switch the primary rendering GPU without restarting the display manager. However, not every desktop can implement every feature. This script was made to specifically bring the best possible eGPU performance to all Linux desktops without needing any changes. However, this comes with the shortcomings that iGPU connected displays (such as the laptop’s screen) and anything requiring the iGPU may not work while in this mode. As a result, nearly any other method of enabling the eGPU as primary is preferable to this one. Xorg desktop users should stick with gswitch or egpu-switcher. Gnome Wayland users may try gnome-egpu and Sway users should try sway-eGPU-setup. But if none of these work for your particular desktop, all-ways-egpu is the solution that should always work to get the most out of any eGPU connected displays.
That's it, it's official... I'm in love with you (Purely your eGPU.io persona tho hahaha)
I'll try this out in a few hours but if this works a need a donation link or something to reward you for your efforts
O.K. Tried it on my Fedora 34 KDE spin and...
No go yet. Raised and issue on GitHub and will work with Ninja to get this going.
Looking forward to hearing of other testing it.
Didn't not harm my system, rebooted and everything was back to normal (Obviously I didn't do the last step to make it permanent)
Hoping to get this working... Sooooo excited
UPDATE: After a recommendation from @nu_ninja I:
A) Changed my display manager from SDDM to GDM (I tried LightDM which ninja said would work but I didn't have any luck with it. I booted but the Login screen did not come up so I couldn't continue any further with it and dropped down to TTY to reverse the switch and went with GDM)
B) Tried the eGPU script and had what was expected with only the External display working. I tried to enable the Laptop screen as well which was doable in Display Settings but ended up hanging the system so for the moment I would recommend against it
C) Noticed a change in laptop fans running lower so it seems like the load has shifted, my Ext performance isn't much better than when I was running mirrored but the system is less loaded which is a positive.
Love to see others give this a try and put up some feedback. Hopefully, we can make this work better moving forward. I'm personally happy to put some $$ behind it if it'll help so that a dev or devs can spend their time on it
Glad you got it at least somewhat working! If you want to enable the laptop screen you can do the switch internal command after you've logged in with the egpu and it should bring up the internal screen while still keeping the eGPU as primary.
Definitely would like to see people try it out. I'm not a pro dev or anything, just one guy with an old macbook who likes to make things work. But the more machines testing it out, the better.
@nu_ninja, As always Thanks soooo much. I appreciate you doing what you've already done.
I'll start running some comparison benchmarks soon so people (and we) can see the differences between the setups and also comparatively against windows so we know the goal post. I'll be doing this as I also finally document my build for this site and my signature lol.