Multi-GPU Optimus and xrandr

Is it possible to utilize xrandr in an optimus-enabled laptop to redirect output from the integrated RTX 2060 to a plugged-in GTX 960? Possibly using xrandr? I’ve got such a setup… the Intel chipset is a cannonlake (i7 8750H) with an integrated RTX 2060… and a GTX 960 plugged in via a “graphics accelerator” port on the laptop. All three devices are detected, and I can fully utilize the GTX 960… but of course I’d like to use the power of the RTX 2060.

Why do I have such a setup? I’m really just using the 960 to output to four displays, whereas the built-in RTX 2060 can only output to two displays (1x via mini-DP, 1x via thunderbolt… or 2x each if I used MST, but only at 30Hz each… I’d much rather have at least 60 Hz).

Here’s some lspci output:

rich@graendal ~ $ lspci
00:00.0 Host bridge: Intel Corporation 8th Gen Core Processor Host Bridge/DRAM Registers (rev 07)
00:01.0 PCI bridge: Intel Corporation Xeon E3-1200 v5/E3-1500 v5/6th Gen Core Processor PCIe Controller (x16) (rev 07)
00:01.1 PCI bridge: Intel Corporation Xeon E3-1200 v5/E3-1500 v5/6th Gen Core Processor PCIe Controller (x8) (rev 07)
00:01.2 PCI bridge: Intel Corporation Xeon E3-1200 v5/E3-1500 v5/6th Gen Core Processor PCIe Controller (x4) (rev 07)
00:02.0 VGA compatible controller: Intel Corporation UHD Graphics 630 (Mobile)
00:04.0 Signal processing controller: Intel Corporation Xeon E3-1200 v5/E3-1500 v5/6th Gen Core Processor Thermal Subsystem (rev 07)
00:08.0 System peripheral: Intel Corporation Xeon E3-1200 v5/v6 / E3-1500 v5 / 6th/7th Gen Core Processor Gaussian Mixture Model
00:12.0 Signal processing controller: Intel Corporation Cannon Lake PCH Thermal Controller (rev 10)
00:13.0 Serial controller: Intel Corporation Device a37c (rev 10)
00:14.0 USB controller: Intel Corporation Cannon Lake PCH USB 3.1 xHCI Host Controller (rev 10)
00:14.2 RAM memory: Intel Corporation Cannon Lake PCH Shared SRAM (rev 10)
00:15.0 Serial bus controller [0c80]: Intel Corporation Device a368 (rev 10)
00:15.1 Serial bus controller [0c80]: Intel Corporation Device a369 (rev 10)
00:16.0 Communication controller: Intel Corporation Cannon Lake PCH HECI Controller (rev 10)
00:17.0 SATA controller: Intel Corporation Device a353 (rev 10)
00:1b.0 PCI bridge: Intel Corporation Cannon Lake PCH PCI Express Root Port #21 (rev f0)
00:1d.0 PCI bridge: Intel Corporation Cannon Lake PCH PCI Express Root Port #9 (rev f0)
00:1d.6 PCI bridge: Intel Corporation Cannon Lake PCH PCI Express Root Port #15 (rev f0)
00:1d.7 PCI bridge: Intel Corporation Cannon Lake PCH PCI Express Root Port #16 (rev f0)
00:1e.0 Communication controller: Intel Corporation Device a328 (rev 10)
00:1f.0 ISA bridge: Intel Corporation Device a30d (rev 10)
00:1f.3 Audio device: Intel Corporation Cannon Lake PCH cAVS (rev 10)
00:1f.4 SMBus: Intel Corporation Cannon Lake PCH SMBus Controller (rev 10)
00:1f.5 Serial bus controller [0c80]: Intel Corporation Cannon Lake PCH SPI Controller (rev 10)
01:00.0 VGA compatible controller: NVIDIA Corporation Device 1f11 (rev a1)
01:00.1 Audio device: NVIDIA Corporation Device 10f9 (rev a1)
01:00.2 USB controller: NVIDIA Corporation Device 1ada (rev a1)
01:00.3 Serial bus controller [0c80]: NVIDIA Corporation Device 1adb (rev a1)
02:00.0 PCI bridge: Intel Corporation JHL6340 Thunderbolt 3 Bridge (C step) [Alpine Ridge 2C 2016] (rev ff)
03:00.0 PCI bridge: Intel Corporation JHL6340 Thunderbolt 3 Bridge (C step) [Alpine Ridge 2C 2016] (rev ff)
03:01.0 PCI bridge: Intel Corporation JHL6340 Thunderbolt 3 Bridge (C step) [Alpine Ridge 2C 2016] (rev ff)
03:02.0 PCI bridge: Intel Corporation JHL6340 Thunderbolt 3 Bridge (C step) [Alpine Ridge 2C 2016] (rev ff)
6c:00.0 USB controller: Intel Corporation Device 15db (rev ff)
6d:00.0 VGA compatible controller: NVIDIA Corporation GM206 [GeForce GTX 960] (rev a1)
6d:00.1 Audio device: NVIDIA Corporation GM206 High Definition Audio Controller (rev a1)
6e:00.0 Non-Volatile memory controller: Intel Corporation Device f1a8 (rev 03)
6f:00.0 Non-Volatile memory controller: Intel Corporation Device f1a8 (rev 03)
70:00.0 Ethernet controller: Qualcomm Atheros Killer E2500 Gigabit Ethernet Controller (rev 10)
71:00.0 Network controller: Intel Corporation Wireless-AC 9260 (rev 29)

From the above, at ID 00:02.0 is my intel VGA chipset, 01:00.0 is my RTX 2060 chipset, and 6d:00.0 is my GTX 960. I’ve cobbled together an xorg.conf to output via the 960:

Section "Module" 
   Load "modesetting" 
EndSection 

Section "Device" 
   Identifier "nvidia external" 
   Driver "nvidia" 
   VendorName   "NVIDIA Corporation" 
   BoardName   "GeForce GTX 960" 
   BusID "PCI:109:0:0" 
   Option "AllowEmptyInitialConfiguration" 
EndSection 

Section "Device" 
   Identifier "nvidia internal" 
   Driver "nvidia" 
   BusID "PCI:1:0:0" 
   Option "AllowEmptyInitialConfiguration" 
   Option "IgnoreEDID" "false" 
   Option "UseEDID" "true" 
EndSection 

Section "Screen" 
   Identifier "Screen0" 
   Device "nvidia external" 
   DefaultDepth 24 
   Option   "nvidiaXineramaInfoOrder" "DFP-4" 
   Option   "metamodes" "DP-2: nvidia-auto-select +3840+1080 {AllowGSYNC=Off}, DP-1: nvidia-auto-select +3840+0, DP-4: nvidia-auto-select +0+551, HDMI-0: nvidia-auto-select +7680+446 {AllowGSYNC=Off}" 
   Option "ModeValidation" "AllowNonEdidModes" 
   SubSection "Display" 
      Depth 24 
   EndSubSection 
EndSection

From here I was hoping to see three providers under xrandr, but I only see two :(

rich@graendal ~ $ xrandr --listproviders
Providers: number : 2
Provider 0: id: 0x24a cap: 0x1, Source Output crtcs: 4 outputs: 9 associated providers: 0 name:NVIDIA-0
Provider 1: id: 0x47 cap: 0x2, Sink Output crtcs: 3 outputs: 5 associated providers: 0 name:modesetting

Is what I’d like to do possible? I figured I’d have a shot if I saw two nvidia providers under xrandr :/

This does not really work, earlier experiments:
https://devtalk.nvidia.com/default/topic/1046154/linux/split-kernel-driver-working-now-i-need-to-configure-the-monitors-on-second-gpu-i-m-lost-/
https://devtalk.nvidia.com/default/topic/1045979
https://devtalk.nvidia.com/default/topic/1030717/linux/xorg-configuration-two-nvidia-cards-xinerama-breaks-hardware-acceleration-390-25-current-driver/post/5243978/#5243978
But since you only want to use the outputs on the 960, you could try a bumblebee/virtualgl setup.

Thanks, that’s a lot of good data… Using some of that, I’ve enabled all five displays successfully (four external, and using xrandr, I’ve also enabled PRIME on the laptop’s internal display and moved it below my right monitor using the below code in my ~/.xsession (I’m currently using gnome):

xrandr --setprovideroutputsink modesetting NVIDIA-0
xrandr --auto
if [ -d /sys/devices/pci0000:00/0000:00:01.2/0000:6d:00.0 ] ; then
#       If the GTX 960 is detected...
        xrandr --output eDP-1-1 --below HDMI-0
        gsettings set org.gnome.desktop.interface text-scaling-factor 1.5
else
#       Otherwise, we're standalone
        gsettings set org.gnome.desktop.interface text-scaling-factor 2.5
fi

I was kinda expecting that if the built-in screen was on and functional, that it would utilize the 2060 just on that screen… I’m not at all sure I’m seeing that. glxgears shows continuous glx capabilities across all screens (surprised me - I was expecting it to go blank on the built-in screen crossing the GTX/RTX boundary)… and glxinfo shows the 960 as the renderer. Is the 960 really doing all the rendering? Can that be somehow reversed?

I may also look into a bumblebee/vgl approach, reading up on those now…

I don’t know what kind of setup you’re running right now.
Please run nvidia-bug-report.sh as root and attach the resulting .gz file to your post. Hovering the mouse over an existing post of yours will reveal a paperclip icon.
https://devtalk.nvidia.com/default/topic/1043347/announcements/attaching-files-to-forum-topics-posts/

Ok, I’ll attach it to this post
nvidia-bug-report.log.gz (139 KB)

You’re currently running PRIME output gtx960->intel, which is the standard case. You want PRIME output 2060->960, this means you’ll have to set up the ‘split driver’ config, using the nouveau kernel driver on the 960 and the nvidia proprietary driver on the 2060. Which is fiddly.

I’ll try the split-kernel, then. It looks like nouveau doesn’t support the 960 yet (it’s part of the NV110 family, specifically the NV126, 2D is still a WIP)… yet despite that I see some GL benchmarks with the 960 and nouveau vs nvidia… so maybe it has support and nobody updated the feature matrix page?

All I know is that no live linux distro I’ve tried appears to be able to fire up the 960… but maybe they haven’t been running recent kernels.

EDIT: It’s as I feared… the 960 doesn’t appear at all well supported by nouveau. I get a bunch of errors when I modprobe it and kernel panics galore when I rmmod it under 4.19.37. I was able to get the split-kernel working (verified that the nvidia module bound only to the 2060 via lspci -k - the 960 had no module bound until I modprobed it). Hoping that the above was all harmless, I tried to start X anyways… and was only rewarded with all black screens. From another terminal, I was able to run “DISPLAY=:0 xrandr --listproviders”… which showed modesetting and nouveau (no nvidia).

I was able to snag some output from nvidia-bug-report.sh in this setup as attached
nvidia-bug-report.log.gz (1.15 MB)

Kernel drivers seem to be set up right, you should rather try with iommu disabled iommu=off), might interfere.
The xorg.conf is malformed, though. Try this one:

Section "ServerLayout"
    Identifier     "layout"
    Screen      0  "nvidia" 0 0
    Inactive       "nvidia_external"
EndSection

Section "Monitor"
    Identifier     "Monitor0"
EndSection

Section "Device"
    Identifier "nvidia_external"
    Driver     "modesetting"
    Option     "AccelMethod" "none"
    VendorName "NVIDIA Corporation"
    BoardName  "GeForce GTX 960"
    BusID      "PCI:109:0:0"
EndSection

Section "Device"
    Identifier "nvidia"
    Driver     "nvidia"
    VendorName "NVIDIA Corporation"
    BoardName  "GeForce RTX 2060"
    BusID      "PCI:1:0:0"
    Option     "AllowEmptyInitialConfiguration"
EndSection

Section "Screen"
    Identifier     "nvidia"
    Device         "nvidia"
    Monitor        "Monitor0"
EndSection

This should give you the providers modesetting and NVIDIA-0, so you need to run
xrandr --setprovideroutputsource modesetting NVIDIA-0 && xrandr --auto

Since the internal display is connected to the intel gpu, this will not take part, maybe can be changed by setting graphics to discrete in bios, if available.