How to use "prime-select on-demand" in latest Kubuntu 19.10

Solution 1:

This is a confusing new 'option' that isn't described and generally of no use to most users. The bug report that lead to this being added stated -

"Per current NV and intel GPU driver, if we load nvidia.ko only, we can do display on intel GPU and leave the NV to deep learning for a graphic workstation."

Report here - https://bugs.launchpad.net/ubuntu/+source/nvidia-prime/+bug/1824282

Bug filed about how poorly this was implemented here -

https://bugs.launchpad.net/ubuntu/+source/nvidia-settings/+bug/1851416

Solution 2:

In ubuntu 19.10 xorg needs some patches that are only available for 18.04 and 19.04 here You can read all information here

first you need to remove intel drivers to use software based rendering (modeseting aka llvmpipe renderer). Install latest drivers from this ppa and finally, compile/install patched xorg.

The easiest solution today is upgrade to ubuntu 20.04 and install nvidia drivers

sudo ubuntu-drivers install

I explicitly configure the iGPU and dGPU devices in xorg.conf.d (BusID could be different in other systems):

$ sudo cat /etc/X11/xorg.conf.d/20-intel.conf 
    Section "Device"
      Identifier  "Intel Graphics"
      Driver      "intel"
      Option      "AccelMethod"    "sna"
    EndSection 

$ sudo cat /etc/X11/xorg.conf.d/90-nvidia.conf 
    Section "ServerLayout"
      Identifier "layout"
      Screen 0 "iGPU"
      Option "AllowNVIDIAGPUScreens"
    EndSection
    
    Section "Device"
      Identifier "iGPU"
      Driver "modesetting"
      BusID          "PCI:0:2:0"  
    EndSection
    
    Section "Screen"
      Identifier "iGPU"
      Device "iGPU"
    EndSection
    
    Section "Device"
      Identifier "dGPU"
      Driver "nvidia"
      BusID          "PCI:3:0:0"  
    EndSection

... reboot and get prime working:

$ offload-glx glxinfo | grep "OpenGL renderer"
OpenGL renderer string: GeForce 940M/PCIe/SSE2

$ glxinfo | grep "OpenGL renderer"
OpenGL renderer string: Mesa Intel(R) HD Graphics 5500 (BDW GT2)

offload_glx comes from mate-prime-select and is an alias of this: __NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia glxgears

So install nvidia drivers, and configure xorg.