Virtual displays for Sunshine/Moonlight without dongle on amdgpu in Bazzite-Gnome
Introduction
Users of GPUs leveraging the amdgpu driver can create virtual displays without using any dongle for use with Sunshine. This can be done via a kernel parameter as described here and here. However we opt for bringing up the screen during multiuser-target. This has the advantage of a faster boottime and it keeps the splash screen intact.
Preparation
Install Sunshine
To install Sunshine open a terminal and enter:
ujust setup-sunshine
Identify ports
You need to identify actual ports on your GPU to map the virtual display to. The following command will list potential ports (DP-1 - DP-X, HDMI-1 - HDMI-X).
for p in /sys/class/drm/*/status; do con=${p%/status}; echo -n "${con#*/card?-}: "; cat $p; done
Any disconnected port will do.
Prepare EDID firmware to accomodate your target screen
To make the kernel aware of the proper resolution and refresh rate of your virtual display we need an EDID firmware file. This can either be retrieved for example here [1]. Alternatively you can also create a tailored EDID file with this handy tool [2]. The tool takes a modeline from xorg and generates the EDID bin from it. To get a modeline for your target resolution you can use this website [3]. To prepare and use edid-generator on Bazzite-Gnome proceed as follows in a terminal:
ujust distrobox-assemble //Choose Ubuntu
distrobox enter ubuntu
sudo apt install zsh edid-decode automake dos2unix
mkdir -p ~/build/
cd ~/build/
git clone https://github.com/akatrevorjay/edid-generator
cd edid-generator
./modeline2edid - <<< 'Modeline "2560x1600" 348.16 2560 2752 3032 3504 1600 1601 1604 1656 -HSync +Vsync' //Replace with your modeline in the single brackets
make
You should now have a .bin file named according to the content of the first brackets in the modline. Copy this into your local firmware folder. Carry on in the terminal:
mkdir -p /usr/local/lib/firmware
sudo cp 2560x1600.bin /usr/local/lib/firmware/
Test your target display
We will now create a helper script to enable your virtual display.
Open the editor of your choice and paste the following, then replace DP-2 with a non connected interface and 2560x1600.bin with your EDID file:
#!/bin/bash
cat /usr/local/lib/firmware/2560x1600.bin > /sys/kernel/debug/dri/0/DP-2/edid_override
echo on > /sys/kernel/debug/dri/0/DP-2/force
echo 1 > /sys/kernel/debug/dri/0/DP-2/trigger_hotplug
Save the file as “enable-screens.sh”. Then make it available to the root user:
sudo cp enable-screens.sh /usr/local/sbin/
sudo chmod +x /usr/local/sbin/enable-screens.sh
You can now test if everything works:
sudo /usr/local/sbin/enable-screens.sh
gnome-control-center display
The control center should now start up with the display section and show the newly created display.
Automation
Automatically bring up screen via systemd
You can trigger the script on startup via a systemd unit file. For this open the editor of your choice and paste the following:
[Unit]
Description=Enable Virtual Displays
[Service]
ExecStart=/usr/bin/bash /usr/local/sbin/enable-screens.sh
[Install]
WantedBy=multi-user.target
Save under “/etc/systemd/system/enable-screens.service”. Then enable the service and reboot:
sudo systemctl daemon-reload
sudo systemctl enable enable-screens.service
systemctl reboot
After the system has restarted check your display is available in control center:
gnome-control-center display
Autostarting Sunshine
Sunshine autostart is currently not working in bazzite-gnome [4]. To work around this use xdg autostart.
sudo cp /usr/share/applications/sunshine.desktop /etc/xdg/autostart/
Switching screens in Sunshine
Gnome has recently added gdctl as a tool to manipulate screen layout across X and Wayland. This can be used in a Sunlight application in “Do Command” and “Undo Command” to setup the appropriate screen configuration. I use this to enable a multiscreen setup in desktop mode, but I also have an exclusive desktop mode just on my tablet and exclusive Big Picture to my tablet.
For the multiscreen “Do Command” add (I use scale on the small tablet screen to get a readable UI):
gdctl set --logical-monitor --primary --monitor DP-1 --logical-monitor --monitor DP-2 --scale 2 --right-of DP-1
In “Undo Command”:
gdctl set --logical-monitor --primary --monitor DP-1
You can now connect to the application from your device with Moonlight.
Conclusion
I hope this little guide was helpful. Please put pointers to problems and I will try to correct them in the original post. Feel free to also share your successes. Enjoy your virtual display and Sunshine/Moonlight.
I first had it running with the kernel parameters. For this see the second link in the introduction. The problem there was it added to boot time, as the kernel generates an error message. Passing an EDID as kernel parameter was complicated, due initramfs modification being tricky on Bazzite (at least acccording to my limited understanding). So I moved to this method where I initialize the virtual display via the KMS debug API later in the boot process. This can also be used to arbitrarily modify the virtual display. I have not looked into doing it via parameter. Can you share the example commands?