# NVIDIA Optimus via PRIME on laptop not working

**URL:** https://discourse.nixosstag.fcio.net/t/nvidia-optimus-via-prime-on-laptop-not-working/4124
**Category:** Deployments
**Created:** [September 22, 2019, 7:31am UTC](https://discourse.nixosstag.fcio.net/t/nvidia-optimus-via-prime-on-laptop-not-working/4124 "2019-09-22T07:31:18Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![mudrii](https://discourse.nixosstag.fcio.net/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@mudrii](https://discourse.nixosstag.fcio.net/u/mudrii)
#### Post date: [September 22, 2019, 7:31am UTC](https://discourse.nixosstag.fcio.net/t/nvidia-optimus-via-prime-on-laptop-not-working/4124/1 "2019-09-22T07:31:18Z")

</div>

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

```auto
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)

```

```auto
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 |
+-----------------------------------------------------------------------------+

```

```auto
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

```auto
  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;
      };
    };
  };

```

```auto
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

```auto
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

```auto
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

```auto
  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?

---

<div class="post-metadata">

### Author: ![eadwu](https://discourse.nixosstag.fcio.net/user_avatar/discourse.nixosstag.fcio.net/eadwu/32/2454_2.png) [@eadwu](https://discourse.nixosstag.fcio.net/u/eadwu)
#### Post date: [September 22, 2019, 5:09pm UTC](https://discourse.nixosstag.fcio.net/t/nvidia-optimus-via-prime-on-laptop-not-working/4124/2 "2019-09-22T17:09:46Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![mudrii](https://discourse.nixosstag.fcio.net/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@mudrii](https://discourse.nixosstag.fcio.net/u/mudrii)
#### Post date: [September 23, 2019, 9:56am UTC](https://discourse.nixosstag.fcio.net/t/nvidia-optimus-via-prime-on-laptop-not-working/4124/3 "2019-09-23T09:56:03Z")

</div>

@eadwu

Thx for the reply.

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

> **[PRIME render offloading on Nvidia Optimus](https://forums.developer.nvidia.com/t/prime-render-offloading-on-nvidia-optimus/44439)**
>
> As per aplattner’s suggestion from https://devtalk.nvidia.com/default/topic/957814/linux/prime-and-prime-synchronization/post/4953175/#4953175, I’ve taken the liberty to open a new thread for discussing on PRIME GPU render offload feature on...

---

<div class="post-metadata">

### Author: ![eadwu](https://discourse.nixosstag.fcio.net/user_avatar/discourse.nixosstag.fcio.net/eadwu/32/2454_2.png) [@eadwu](https://discourse.nixosstag.fcio.net/u/eadwu)
#### Post date: [September 23, 2019, 11:37am UTC](https://discourse.nixosstag.fcio.net/t/nvidia-optimus-via-prime-on-laptop-not-working/4124/4 "2019-09-23T11:37:55Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![mudrii](https://discourse.nixosstag.fcio.net/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@mudrii](https://discourse.nixosstag.fcio.net/u/mudrii)
#### Post date: [September 23, 2019, 2:08pm UTC](https://discourse.nixosstag.fcio.net/t/nvidia-optimus-via-prime-on-laptop-not-working/4124/5 "2019-09-23T14:08:32Z")

</div>

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&nbsp;35.&nbsp;PRIME Render Offload](https://download.nvidia.com/XFree86/Linux-x86_64/435.17/README/primerenderoffload.html)  
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&nbsp;34.&nbsp;Offloading Graphics Display with RandR 1.4](http://download.nvidia.com/XFree86/Linux-x86_64/435.21/README/randr14.html)

---

<div class="post-metadata">

### Author: ![eadwu](https://discourse.nixosstag.fcio.net/user_avatar/discourse.nixosstag.fcio.net/eadwu/32/2454_2.png) [@eadwu](https://discourse.nixosstag.fcio.net/u/eadwu)
#### Post date: [September 23, 2019, 2:25pm UTC](https://discourse.nixosstag.fcio.net/t/nvidia-optimus-via-prime-on-laptop-not-working/4124/6 "2019-09-23T14:25:06Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![mudrii](https://discourse.nixosstag.fcio.net/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@mudrii](https://discourse.nixosstag.fcio.net/u/mudrii)
#### Post date: [September 23, 2019, 2:36pm UTC](https://discourse.nixosstag.fcio.net/t/nvidia-optimus-via-prime-on-laptop-not-working/4124/7 "2019-09-23T14:36:39Z")

</div>

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

---

<div class="post-metadata">

### Author: ![eadwu](https://discourse.nixosstag.fcio.net/user_avatar/discourse.nixosstag.fcio.net/eadwu/32/2454_2.png) [@eadwu](https://discourse.nixosstag.fcio.net/u/eadwu)
#### Post date: [September 23, 2019, 9:58pm UTC](https://discourse.nixosstag.fcio.net/t/nvidia-optimus-via-prime-on-laptop-not-working/4124/8 "2019-09-23T21:58:46Z")

</div>

See [nvidia: prime render offload by eadwu · Pull Request #66601 · NixOS/nixpkgs · GitHub](https://github.com/NixOS/nixpkgs/pull/66601).
