NVIDIA Optimus via PRIME on laptop not working

Hi Maybe somebody can advise on how to setup correctly NVIDIA Optimus via PRIME for the new laptop.

Current Hardware Configuration:
Intel and Nvidia RTX 4000 on laptop

lspci | grep -i VGA
00:02.0 VGA compatible controller: Intel Corporation Device 3e9b (rev 02)
01:00.0 VGA compatible controller: NVIDIA Corporation Device 1eb6 (rev a1)
nvidia-smi
Sun Sep 22 15:24:13 2019       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 435.21       Driver Version: 435.21       CUDA Version: 10.1     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Quadro RTX 4000     Off  | 00000000:01:00.0 Off |                  N/A |
| N/A   37C    P8     8W /  N/A |     98MiB /  7982MiB |      2%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      3346      G   ...bxhy9vnr16qpyn-xorg-server-1.20.5/bin/X    94MiB |
|    0      3484      G   /run/current-system/sw/bin/nvidia-settings     2MiB |
+-----------------------------------------------------------------------------+

xrander --listproviders
Providers: number : 2
Provider 0: id: 0x28d cap: 0x1, Source Output crtcs: 4 outputs: 3 associated providers: 1 name:NVIDIA-0
Provider 1: id: 0x43 cap: 0x2, Sink Output crtcs: 3 outputs: 1 associated providers: 1 name:modesetting

Current NixOs Configuration

  hardware = {
    opengl.driSupport32Bit = true;
    nvidia = {
      optimus_prime = {                                             
        enable = true;                                                              
        intelBusId = "PCI:0:2:0";                                                   
        nvidiaBusId = "PCI:1:0:0";                                                  
      };
      modesetting.enable = true;
    };
  };

  services = {
    xserver = {
      enable = true;
#      videoDrivers = [ "intel" ];
      videoDrivers = [ "nvidia" ];

      layout = "us";
      xkbOptions = "eurosign:e";
      libinput.enable = true;
      desktopManager = {
        default = "none";
        xterm.enable = false;
      };
      displayManager = {
        lightdm = {
          enable = true;
          greeter.enable = false;
          autoLogin.enable = true;
          autoLogin.user = "xxxxxx";
        };
      };

      windowManager = {
        default = "i3";
        i3.enable = true;
        i3.package = pkgs.i3-gaps;
      };
    };
  };
nix run nixpkgs.nix-info -c nix-info -m
 - system: `"x86_64-linux"`
 - host os: `Linux 5.3.0, NixOS, 19.09beta304.b66fb91f170 (Loris)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.3`
 - channels(root): `"nixos-19.09beta304.b66fb91f170"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

Issue: I can not switch between video card using

xrandr --setprovideroutputsource NVIDIA-0 modesetting

X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  140 (RANDR)
  Minor opcode of failed request:  35 (RRSetProviderOutputSource)
  Value in failed request:  0x28d
  Serial number of failed request:  16
  Current serial number in output stream:  17

The only option that is working without error is

xrandr --setprovideroutputsource modesetting NVIDIA-0 

Note: I can’t see option for Prime Profiles in GUI nvidia-settings

Note: Only option to use Intel VGA is to swithch in configuration.nix between

  services.xserver.videoDrivers = [ "intel" ];
  services.xserver.videoDrivers = [ "nvidia" ];

and rerun “nixos-rebuild switch” after change every time need to change VGA device.

Is anything missing from my configuration to make change devices work with Optimus via Prime?

2 Likes

I don’t see any problem with setup, it looks like it’s working correctly. If you’re trying to perform offloading, PRIME sync doesn’t do that.

@eadwu

Thx for the reply.

As far as I know offload Prime sync was implemented in latest Nvdia drivers

Prime sync is not the same thing as prime render offload, and prime render offload hasn’t been implemented in nixpkgs.

Also, I would suggest reading the docs on prime render offload instead of running random commands hoping it would do what you want.

1 Like

I don’t think you understood the exact requirements.

  1. PRIME render offload is the ability to have an X screen rendered by one GPU, but choose certain applications within that X screen to be rendered on a different GPU
    Source: Chapter 35. PRIME Render Offload
    And to make it work you need to patch X server
  2. Requirements is to switch between GPU from Intel and Nvidia without modifying configuration.nix and running nixos-rebuild switch
    Chapter 34. Offloading Graphics Display with RandR 1.4

Like I said before PRIME render offload is not PRIME sync.

If you’re trying to disable the NVIDIA gpu through a restart of X server, you need a new generation and a reboot to cleanly do so.

Thx for the help.
I thought maybe an easier solution exist rather than restarting X.Org server, will wait until X.Org will add patches for offload to official release soon.

See nvidia: prime render offload by eadwu · Pull Request #66601 · NixOS/nixpkgs · GitHub.