Weird performance drop and other issues after updating my system on NVIDIA hybrid graphics laptop

Somewhere two weeks ago after another update I’ve gotten several problems with performance in some apps and games. Unfortunately at this point I already removed previous generations and cleared the cache so I can’t detect when these particular problems started. These problems could be unrelated, but I doubt it since they all appeared at once, and it all seems to be connected with OpenGL.
Some info about my system: I am on flake-enabled system set to the unstable channel. I use KDE with Wayland. My laptop (Acer Aspire serices) has both Intel integrated grapgics and NVIDIA GPU. I have set up nvidia in offload mode according to nixos.wiki:

part of my configuration.nix

  hardware.nvidia = {
    modesetting.enable = true;
    open = false;
    nvidiaSettings = true;
    package = config.boot.kernelPackages.nvidiaPackages.stable;
  };-

  hardware.nvidia.prime = {
    offload = {
      enable = true;
      enableOffloadCmd = true;
    };
    intelBusId = "PCI:0:2:0";
    nvidiaBusId = "PCI:1:0:0";
  };

Here are the problems I’ve encountered:

  1. Poor performance in Vesktop (Vencord Desktop, a modified Discord client)
    When starting Vesktop, it would fail to display most images, as well as have very poor performance and responsiveness (failing to register mouse inputs most of the time). When starting from a console, it would spam some errors related to GL (like “Skia shader compilation error”, portion of the output available here: vesktop weird gl output · GitHub)
    I tried different things in order to fix this and these in particular worked:
  • Setting variable NIXOS_OZONE_WL=1
  • Setting variable MESA_GL_VERSION_OVERRIDE=3.0 or 3.1 or 3.2
  • Removing GPUCache folder from app folder (~/.config/VencordDesktop), after which it worked without any additional settings or environment variables
  1. Poor performance in some games when using NVIDIA graphics (with nvidia-offload)
    So far I only tried two as I didn’t get much time to try other ones: Xonotoc and Team Fortress 2.
    In Xonotic, when launching it as nvidia-offload xonotic-sdl, the game would have significant visual stuttering (poor frames) even in the main menu. Adding SDL_VIDEODRIVER=wayland variable fixes that.
    In TF2 I had same symptopms, and also I’ve been getting IDirect3DQuery9::GetData() Occlusion query flush took 1.900ms error repeatedly in the in-game console. Searching this reveals very old unsolved reports. I haven’t found a fix to this, as this game doesn’t include support for Wayland, or for Vulkan as a backend instead of OpenGL which could also work.

  2. Having problems when developing Minecraft mods.
    Now this one is a bit specific. It also most likely to be unrelated, but again, this issue appeared at the same time.
    I develop mods on both modloading platforms, using Gradle. Now, up until recently, everything worked except audio (missing OpenAL library), but now the entire project fails to start with the following error:
    com.mojang.blaze3d.platform.Window$WindowInitFailed: GLFW error 65542: GLX: Failed to load GLX
    Quick search reveals that it is related to missing opengl libraries. But I do have them installed! And I am still able to launch the game using PrismLauncher without any problem. I checked PrismLauncher definition and found that it uses openal, glfw and libGL packages in the library path. So, by loading my flake and setting LD_LIBRARY_PATH variable to the result of lib.makeLibraryPath [ openal glfw libGL ], I was able to get my dev environment working again, though still with OpenAL broken.
    While this definetly works, it still feels quite hacky. And considering it “just worked” before, I doubt this is a proper solution, either.

My main question here: are those problems related? Did something change recently in how graphic drivers are installed system-wide? If yes, do I need to change my configuration, and how?
So far I tried, without success:
Setting option boot.kernelPackages = pkgs.linuxPackages_zen; (I used zen kernel before on Arch because it did help eliminate some issues, but on NixOS I never changed that up until now).
Adding extra packages to hardware.opengl.extraPackages according to new wiki: Integrated Intel Graphics | NixLang.wiki
Setting hardware.nvidia.package to config.boot.kernelPackages.nvidiaPackages.production (that downgraded nvidia driver from 545 to 535 but didn’t affect the system)
Something else that I don’t remember.

Let me know if other info can be useful (like some specific glxinfo output for example)

goddammmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm NVIDIA!!!

when i get a moment. I’ll look into this…

hopefully some else can get your success while i have my hands full.

2 Likes

hardware.opengl.enable doesn’t appear to be set by default by the KDE module. Do you have that set?

Can you monitor GPU usage with nvidia-settings or nvidia-dmon while running into performance problems, just to check if the nvidia GPU is actually used?

This does look more like the opengl libraries just aren’t being found by the applications in question; They’re all notably not compiled by nix, you presumably rely on something like programs.nix-ld - I wonder if that’s where it’s going wrong.

Have you tried glxgears from mesa-demos?

Yep. I missed that part of my config so here it is:

opengl in configuration.nix
  # Make sure opengl is enabled
  hardware.opengl = {
    enable = true;
    driSupport = true;
    driSupport32Bit = true;
    # These extrapackages I added later but it didn't help
    extraPackages = with pkgs; [
      intel-media-driver # LIBVA_DRIVER_NAME=iHD
      vaapiIntel # LIBVA_DRIVER_NAME=i965 (older but works better for Firefox/Chromium)
      vaapiVdpau
      libvdpau-va-gl
    ];
  };
  # Tell Xorg to use the nvidia driver (also valid for Wayland)
  services.xserver.videoDrivers = ["nvidia"];

I’m not sure what is nvidia-dmon and I don’t have that command. I do use nvidia-smi thought, and it shows GPU usage. I tried running nvidia-offload xonotic-sdl first (bad performance) and then SDL_VIDEODRIVER=wayland nvidia-offload xonotic-sdl (smooth performance):

nvidia-smi outputs
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 545.29.06              Driver Version: 545.29.06    CUDA Version: 12.3     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  NVIDIA GeForce 940MX           Off | 00000000:01:00.0 Off |                  N/A |
| N/A   71C    P5              N/A / 200W |    586MiB /  2048MiB |     13%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+
                                                                                         
+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A      1357      G   ...5b3a88as45-xorg-server-21.1.9/bin/X        2MiB |
|    0   N/A  N/A     80805      G   ...ofiles/per-user/lgm/bin/xonotic-sdl      578MiB |
+---------------------------------------------------------------------------------------+

+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 545.29.06              Driver Version: 545.29.06    CUDA Version: 12.3     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  NVIDIA GeForce 940MX           Off | 00000000:01:00.0 Off |                  N/A |
| N/A   83C    P0              N/A / 200W |    559MiB /  2048MiB |     11%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+
                                                                                         
+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A      1357      G   ...5b3a88as45-xorg-server-21.1.9/bin/X        2MiB |
|    0   N/A  N/A     81080      G   ...ofiles/per-user/lgm/bin/xonotic-sdl      552MiB |
+---------------------------------------------------------------------------------------+

Here’s also output when running TF2:

nvidia-smi
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 545.29.06              Driver Version: 545.29.06    CUDA Version: 12.3     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  NVIDIA GeForce 940MX           Off | 00000000:01:00.0 Off |                  N/A |
| N/A   80C    P0              N/A / 200W |    573MiB /  2048MiB |     43%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+
                                                                                         
+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A      1357      G   ...5b3a88as45-xorg-server-21.1.9/bin/X        2MiB |
|    0   N/A  N/A     81558      G   ...ps/common/Team Fortress 2/hl2_linux      567MiB |
+---------------------------------------------------------------------------------------+

So yep, GPU is actually utilized.
glxgears report stable ~59 FPS both with and without nvidia-offload

I’ve been saying this every 2 months for the past 6 years

1 Like

FYI got the following issue recently after an update element-desktop 1.11.35 broken due to shader compilation issues · Issue #244486 · NixOS/nixpkgs · GitHub (and there’s a fix in the comments) Maybe it’s linked?

Seeing this thread again now, I actually remember having had performance issues with nvidia-offload on my hybrid GPU laptop. I just rarely use the dedicated GPU so I didn’t care much.

SDL_VIDEODRIVER=wayland nvidia-offload xonotic-sdl

This line looks interesting. I will try this out tomorrow with different software and report back.

Thanks for the link, it is related since Vesktop (and Discord) is based on Electron.
Still wondering about the solution to other issues, though. I guess they might not be connected and just so happened to occur at the same time.

I managed to resolve the remaining issue with poor performance. All I had to do is enable vsync. Tested with Xonotic and TF2 so far.

(Actually, when launching Xonotic through XWayland, another option “Wait for GPU to finish each frame” also solved this without turning on vsync).

I clearly didn’t disable these options before in both games so I guess at some point XWayland on NVIDIA just broke without vsync. Maybe this is a bug that is worth reporting but unfortunately I don’t even know where is the appropriate issue tracker for XWayland…

It’ll probably be an nvidia driver issue then. Or rather, the drama between the wayland project not wanting to give nvidia special cookies and nvidia’s refusal to respect any of the upstream decisions.

Last I looked into vsync-related issues (I have a high refresh monitor that starts flickering if I enable gsync) there was something resembling a proposed solution that looked half implemented, but is probably another year or two away. I think it was something along the lines of “hard sync” but I can’t find it from a quick search.