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.
Update to this script! I just released a version of this that I have been working on that adds an entirely different approach that I am calling "Method 2". The original functions and everything I am calling "Method 1" is still in place and work the same as before. However, now there is a separate method to try if Method 1 doesn't work for you.
This Method 2 is less extreme than the previous method as it works by simply flipping the boot_vga flag used by most wayland compositors to tell which GPU should be default. So this will not disable the iGPU or anything, it simply indicates to the compositor that the eGPU should be default. This method might not work with all compositors, but in my testing I found this method to work with GNOME, KDE Plasma and Sway so far.
To get this update simply download and install the latest release by running the following in a terminal:
Then to try this Method 2, run:
This will prompt you to restart the display manager, which can typically be done by simply logging out and then logging back in. After logging back in, the eGPU should be used as the primary GPU for rendering.
Rebooting or running the same command with "internal" instead of "egpu" will reset the boot_vga back to normal.
If it works and you want to set it to use the eGPU on every bootup, run the setup and answer "y" to "Attempt to set boot_vga flag at startup?"
More info can be found in the `help` command or on the github project page: https://github.com/ewagner12/all-ways-egpu . Feel free to let me know here or on github if this method works out for you.
Another update to this Wayland Linux script. If you install the latest release you should get an icon in your application menu like this (your desktop may vary):
Simply click on the All-Ways-eGPU icon and it will take you to a new menu system:
The script can then be setup and used from this menu in addition to the old terminal commands. I recommend using 1. Guided setup, then 4. Set boot-vga Flag (Method 2) to switch to the eGPU.
This release also includes some other technical stuff like OpenRC support and some bug fixes. Feedback is welcome here or on github.
Just released another update to this script on github. This update may be interesting to people as it should allow the new "user-install" method to install on Steam Deck/SteamOS 3.0 without requiring write privileges to the system files, the only requirement would be setting a root password to enable sudo. I don’t have a Steam Deck to test on, but I will be looking to test on and support SteamOS 3.0 when it officially launches.