Change main Videocard for X11 Server

Hello.

I’m trying to implement gaming without rebooting(KVM + GPU passthrought).
Problem is with my videocards.
If i’m installing in my system both videocards, i’m getting low performance in Ubuntu desktop.
Based on OS behavior and GPU temps, i see that R7 tries to render everything and RX5500XT does’t do anything.
Moving windows, viewing youtube is very laggy.
Also if i tried to launch game in Ubuntu, i saw that it runs on R7.

I need some hints and documentations, to understand how can i change main videocard for Ubuntu.
But somehow, i’m not very successful by googling this.

Can someone help me?

System info:
OS Host: Ubuntu 20.04 Mate desktop with Compiz
OS guest Win 10
M/B MSI B550M Mortar
Main videocard Radeon RX 5500 XT (Main PCIE slot with one display)
Secondary R7 250 (Secondary PCIE slot with second display)

If you’re going to do GPU passthrough, one of the cards isn’t going to be used, that is, assuming you’re gonna be binding/passing it through to the VM at boot.
Just make sure it is passed through and only install/setup the drivers for the one that is going to be used by the host. It will pick the one not being passed through by itself.

You are are saying, that it is impossible to use RX5500XT for host OS at all?
I thought that it is possibly to do something like this:

  1. Boot in Ubuntu.
  2. Use Ubuntu for some daily activities with acceleration on RX5500XT.
  3. Start VM for gaming, where while starting script detaches RX5500XT from Ubuntu and makes R7 as main videocard.
  4. Stop VM for gaming, where after shutdown script reattaches RX5500XT to Ubuntu for normal use.

I found some manuals that described single GPU Passthrough.
Here is youtube link for it

I have more troubles to assign RX5500XT as main videocard while starting Ubuntu.

What you are wanting to do is dynamic binding of the GPU. In that case, it is going to be slightly different from most VFIO guides out there that just do the binding during boot (usually, with a kernel command line option). I have not dwelled into dynamic binding myself. Also, those two GPUs use different drivers, as you may have noticed. One uses AMDGPU and the other the older radeonsi/radeon drivers. What you’re gonna have to do is have two or, if you want, a single file under /etc/X11/xorg.conf.d/ along the lines of this:

videocards.conf:
Section "Device"
     Name "RX5500XT"
     Driver "AMDGPU"
     BusID "PCI:123:456:789"
EndSection
Section "Device"
    Name "R7"
    Driver "radeon"
    BusID "PCI:123:45:789"
EndSection

again, that is slightly how it should be. I am more used to mailling lists where I can respond after a week or so. But forums like this seem to require faster reply speeds. So I am doing that mostly off the top of my head as I am at work. Here are the relevant manpages that may help you with doing dynamic binding and setting up the relevant xorg.conf files:

https://manpages.debian.org/buster/xserver-xorg-video-amdgpu/amdgpu.4.en.html
https://manpages.debian.org/buster/xserver-xorg-video-radeon/radeon.4.en.html
https://wiki.archlinux.org/title/PCI_passthrough_via_OVMF#Dynamically_isolating_CPUs
https://www.kernel.org/doc/Documentation/vfio.txt

As you can see, the dynamic binding of the GPU has to be done by going around /proc/ as root and unbinding it and then reattaching as needed. You’ll also have to restart Xorg whenever detaching the GPU to use it in the VM and when attaching it again. A more complicated setup would be having 2 different Xorg servers, one per gpu, so that restarting wouldn’t be much of an issue.

Thanks for your answers.
I have read this manuals and some extra documentations.
Also found that i need to restart X11.
It is bad, cause i was trying to omit restarts of my daily applications.
But such switching needs restart X11, its session and applications.