Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nvidia: prime render offload #66601

Merged
merged 7 commits into from Mar 1, 2020
Merged

Conversation

eadwu
Copy link
Member

@eadwu eadwu commented Aug 14, 2019

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.
Notify maintainers

cc @

@eadwu
Copy link
Member Author

eadwu commented Aug 14, 2019

Patched xorg.xorgserver
Loaded modesetting and glamoregl
Added Option "AllowNVIDIAGPUScreens"
Got NVIDIA(G0) in journalctl
Got NVIDIA-G0 provider in xrandr
Loaded nvidia_drm

Device is detected, nvidia-smi output

➜ nvidia-smi
Tue Aug 13 22:44:48 2019
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 435.17       Driver Version: 435.17       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  GeForce GTX 105...  Off  | 00000000:01:00.0 Off |                  N/A |
| N/A   59C    P8    N/A /  N/A |     36MiB /  4042MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
+-----------------------------------------------------------------------------+

Still broken

➜ __NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia glxinfo
name of display: :0
X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  156 (NV-GLX)
  Minor opcode of failed request:  43 ()
  Serial number of failed request:  17
  Current serial number in output stream:  18

@eadwu eadwu mentioned this pull request Aug 14, 2019
10 tasks
@eadwu eadwu force-pushed the nvidia/prime-render-offload branch 4 times, most recently from db99540 to 3fc022e Compare August 14, 2019 16:43
@eadwu eadwu marked this pull request as ready for review August 14, 2019 16:44
@eadwu eadwu force-pushed the nvidia/prime-render-offload branch 3 times, most recently from d12e300 to 5a80896 Compare August 14, 2019 17:33
@eadwu
Copy link
Member Author

eadwu commented Aug 14, 2019

Confirmed PRIME synchronization and render offload works fine on my device.

~
➜ glxinfo | rg vendor
server glx vendor string: SGI
client glx vendor string: Mesa Project and SGI
OpenGL vendor string: Intel

~
➜ nvidia-offload glxinfo | rg vendor
server glx vendor string: NVIDIA Corporation
client glx vendor string: NVIDIA Corporation
OpenGL vendor string: NVIDIA Corporation

~
➜ nvidia-smi
Wed Aug 14 13:45:53 2019
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 435.17       Driver Version: 435.17       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  GeForce GTX 105...  Off  | 00000000:01:00.0 Off |                  N/A |
| N/A   61C    P3    N/A /  N/A |     37MiB /  4042MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
+-----------------------------------------------------------------------------+

@eadwu eadwu force-pushed the nvidia/prime-render-offload branch 2 times, most recently from e03a73c to d81c3a1 Compare August 18, 2019 16:45
@eadwu eadwu mentioned this pull request Aug 30, 2019
10 tasks
@eadwu eadwu force-pushed the nvidia/prime-render-offload branch 2 times, most recently from 17c28dc to 721f3f8 Compare August 31, 2019 19:51
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like hashes are changing

pkgs/servers/x11/xorg/overrides.nix Outdated Show resolved Hide resolved
pkgs/servers/x11/xorg/overrides.nix Outdated Show resolved Hide resolved
pkgs/servers/x11/xorg/overrides.nix Outdated Show resolved Hide resolved
pkgs/servers/x11/xorg/overrides.nix Outdated Show resolved Hide resolved
pkgs/servers/x11/xorg/overrides.nix Outdated Show resolved Hide resolved
pkgs/servers/x11/xorg/overrides.nix Outdated Show resolved Hide resolved
@ghost
Copy link

ghost commented Sep 1, 2019

@eadwu
Can't get it work correctly

Devices

00:02.0 VGA compatible controller: Intel Corporation HD Graphics 620 (rev 02)
01:00.0 3D controller: NVIDIA Corporation GP108M [GeForce MX150] (rev a1)

Configuration

  services.xserver.videoDrivers = [ "modesetting" "nvidia" ];
  hardware.nvidia.prime.offload.enable = true;
  hardware.nvidia.prime.nvidiaBusId = "PCI:1:0:0";
  hardware.nvidia.prime.intelBusId = "PCI:0:2:0";

Interesting why X server is listed here?

$ nvidia-smi
Sun Sep  1 11:02:54 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  GeForce MX150       Off  | 00000000:01:00.0 Off |                  N/A |
| N/A   40C    P8    N/A /  N/A |     28MiB /  2002MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1136      G   ...gbim0idpi4fn42-xorg-server-1.20.5/bin/X    28MiB |
+-----------------------------------------------------------------------------+
$ xrandr --listproviders
Providers: number : 2
Provider 0: id: 0x1df cap: 0xf, Source Output, Sink Output, Source Offload, Sink Offload crtcs: 3 outputs: 4 associated providers: 0 name:modesetting
Provider 1: id: 0x1b8 cap: 0x0 crtcs: 0 outputs: 0 associated providers: 0 name:NVIDIA-G0
$ glxinfo | grep vendor
server glx vendor string: SGI
client glx vendor string: Mesa Project and SGI
OpenGL vendor string: Intel Open Source Technology Center

$ __NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia glxinfo | grep vendor
server glx vendor string: NVIDIA Corporation
client glx vendor string: NVIDIA Corporation
OpenGL vendor string: NVIDIA Corporation

Don't see any picture with these

$ __NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia glxgears
$ __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0 __GLX_VENDOR_LIBRARY_NAME=nvidia glxgears

@eadwu eadwu force-pushed the nvidia/prime-render-offload branch from 721f3f8 to aa55960 Compare September 1, 2019 19:24
@eadwu
Copy link
Member Author

eadwu commented Sep 1, 2019

Not sure why the X process is there. Reproduced the glxgears issue. Not sure why it doesn't show but I'll have a look whenever I have more time.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/fix-bumblebee-kernel-panic/3933/2

@ghost
Copy link

ghost commented Sep 6, 2019

Got Vulkan to work eadwu#17

@eadwu
Copy link
Member Author

eadwu commented Sep 6, 2019

I'm probably only going to have time to look into this later during the weekend, depending on the time I finish university things.

@eadwu
Copy link
Member Author

eadwu commented Jan 26, 2020

As of the current point, if there aren't any bugs anyone is experiencing, I would say this PR is good to go.

@lovesegfault
Copy link
Member

Is @baracoder the only missing review?

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review-may-2019/3032/114

@disassembler disassembler modified the milestones: 20.03, 20.09 Feb 5, 2020
@patrl
Copy link
Contributor

patrl commented Feb 10, 2020

Is there anything preventing this from being merged? I've been eagerly waiting for this to land in master.

@cawilliamson
Copy link
Member

I'd love to see this merged! My battery life is suffering every day this isn't merged! :(

@romildo romildo self-requested a review March 1, 2020 17:24
Copy link
Contributor

@romildo romildo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on a Dell G3 3579 (Intel Corporation UHD Graphics 630 / GeForce GTX 1050 Ti Mobile). Looks good to me.

@romildo romildo merged commit 74f5358 into NixOS:master Mar 1, 2020
@ghost
Copy link

ghost commented Apr 21, 2020

Backport to 20.03 anyone?

@eadwu
Copy link
Member Author

eadwu commented Apr 21, 2020

I was under the thought that new features shouldn't be backported? Though if some people want to be on 20.03 instead of unstable I can open a PR.

@ghost
Copy link

ghost commented Apr 22, 2020

@eadwu Imho this is 2019 year feature, would be cool to see it on 20.03

@eadwu
Copy link
Member Author

eadwu commented Apr 26, 2020

I'll open one up later today and see how it goes.

@eadwu
Copy link
Member Author

eadwu commented Apr 27, 2020

#86094

dtzWill pushed a commit to dtzWill/nixpkgs that referenced this pull request Jun 2, 2020
nvidia: prime render offload
(cherry picked from commit 74f5358)
@nh2
Copy link
Contributor

nh2 commented Jun 15, 2020

@shyim I think your 2 edits to the Nvidia NixOS wiki article are in error:

I believe you may have missed the

Currently only in unstable, to be included in 20.09.

mentioned there, and changed it back because those settings don't exist in 20.03 (this sentence also currently unfortunately is present in only 1 of the 2 sections that refer to 20.09-only attributes).

I think we should undo the first change, and modify the second change so that it describes how to enable sync mode for both 20.09 (unstable) and 20.03.

@nh2
Copy link
Contributor

nh2 commented Jun 15, 2020

@eadwu Offloading seems to work well for me (I tested on 20.30 with your backport #86094 applied).

But even in offload mode, resume-from-suspend still does not work: #73494 (comment)

@nh2
Copy link
Contributor

nh2 commented Jun 15, 2020

I think we should undo the first change, and modify the second change so that it describes how to enable sync mode for both 20.09 (unstable) and 20.03.

I have done this now, and also cleaned up some syntax: https://nixos.wiki/index.php?title=Nvidia&diff=4266&oldid=4211

@delan
Copy link
Member

delan commented Oct 20, 2020

Thanks for the hard work on this feature. I’m looking forward to reverse PRIME!

I’ve updated the wiki page to clarify that just like offload mode, only some laptops need modesetting to be added to videoDrivers. For example, doing so on my X1 Extreme (20QV) breaks external monitors and glxinfo, makes picom segfault, and makes firefox and chrome flicker every few seconds.

@eadwu eadwu deleted the nvidia/prime-render-offload branch November 17, 2020 23:33
'';
};

hardware.nvidia.prime.sync.enable = mkOption {
Copy link
Contributor

@nh2 nh2 Jun 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eadwu and others:

Soes prime.sync have anything to do with PRIME Synchronization? (Arch wiki link and NVIDIA link)

Or is it just the old name for "Optimus Prime's sync mode" as described in https://nixos.wiki/wiki/Nvidia#sync_mode ?

If the former, we should probably rename it, or at write this in the docs here and into the NixOS wiki.

Do you know?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes prime.sync refers to PRIME Synchronization. It was previously put as optimus_prime https://github.com/NixOS/nixpkgs/pull/66601/files#diff-28ea4da3a9a595f8bd1a37a555c229f998f3a11b0715ebc5842ba266384eba73L55 as why the section has two different versions.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/laptop-graphics-card-not-detected-by-nixos-generate-config/22450/10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet