Bad performance on AMD Laptop

Hello!

I got NixOs on my laptop recently. But the performance when browsing the web sucks. I can feel the latency when typing and moving the mouse in Chrome (firefox feels right though).

I’m not sre I got hardware acceleration right, or it is something else. Or it is just chrome being chrome.

The laptop is a Thinkpad L14 AMD:

  • AMD Ryzen 7 PRO 5875U with Radeon Graphic
  • 16 G RAM
  • 500 G nvme
  • NixOs

Where should I start debugging this?

I have these in my configuration.nix:

  boot.initrd.kernelModules = [ "amdgpu" ];
  boot.kernelParams = [
    # Force use of the thinkpad_acpi driver for backlight control.
    # This allows the backlight save/load systemd service to work.
    "acpi_backlight=native"

    # AMD CPU scaling
    # https://www.kernel.org/doc/html/latest/admin-guide/pm/amd-pstate.html
    # https://wiki.archlinux.org/title/CPU_frequency_scaling#amd_pstate
    # On recent AMD CPUs this can be more energy efficient.
    "amd_pstate=guided"

    # Load amdgpu at stage 1
    "amdgpu"
  ];

  # AMD GPU
  hardware.opengl.extraPackages = with pkgs; [
    # VA-API and VDPAU
    vaapiVdpau

    # AMD ROCm OpenCL runtime
    rocmPackages.clr
    rocmPackages.clr.icd

    # AMDVLK drivers can be used in addition to the Mesa RADV drivers.
    #amdvlk
  ];
  hardware.opengl.extraPackages32 = with pkgs; [
    driversi686Linux.amdvlk
  ];

  environment.variables = {
    # VAAPI and VDPAU config for accelerated video.
    # See https://wiki.archlinux.org/index.php/Hardware_video_acceleration
    "VDPAU_DRIVER" = "radeonsi";
    "LIBVA_DRIVER_NAME" = "radeonsi";
  };
  # Most software has the HIP libraries hard-coded. Workaround:
  systemd.tmpfiles.rules = [
    "L+    /opt/rocm/hip   -    -    -     -    ${pkgs.rocmPackages.clr}"
  ];

glxgears gives me ~36 FPS on my external monitor and ~45 on the laptop screen.

I can dump here the output of {glx,vdpau,vaapi,vulkan,opencl-}info, is that useful or just spam right now?

1 Like

You could consult chrome://gpu

Just found out vkcube, I get around ~33 FPS in there as well. Similar number to glxgears.

Chrome seems to be a symptom of the problem? (surprised that Firefox has a much better performance in my case).

I think my integrated GPU is somehow not being used.

Edit: Here’s the top part of chrome://gpu:

Graphics Feature Status
=======================
*   Canvas: Hardware accelerated
*   Canvas out-of-process rasterization: Enabled
*   Direct Rendering Display Compositor: *Disabled*
*   Compositing: Hardware accelerated
*   Multiple Raster Threads: Enabled
*   OpenGL: Enabled
*   Rasterization: Hardware accelerated
*   Raw Draw: *Disabled*
*   Skia Graphite: **Disabled**
*   Video Decode: Hardware accelerated
*   Video Encode: *Software only. Hardware acceleration disabled*
*   Vulkan: **Disabled**
*   WebGL: Hardware accelerated
*   WebGL2: Hardware accelerated
*   WebGPU: **Disabled**

I think I got it.

From the Arch Wiki:

On AMD GPU devices, VA-API does not work according to Chromium bug 1445074. A patch is available, but it only works under X11/XWayland.

https://issues.chromium.org/issues/40267998

I think that’s part of it. glxgears and vkcubes performance is very low, there’s something missing in there. Chrome being slow maybe because uses one of those APIs to render?

1 Like

I actually have decent performance on both Vivaldi and Brave on my AMD Vega 8 laptop :man_shrugging:

Can you share your AMD gpu configs? I do use vivaldi even i do have vega 8 as you do.

This is my current settings:

{
  imports = [ ./hardware-configuration.nix ];
  hardware.cpu.amd.updateMicrocode = true;

  # Machine specific packages
  environment.systemPackages = with pkgs; [
    radeontop # Like htop, but for AMD GPUs
    nvtopPackages.amd # nvtop for AMD GPUs
  ];

  # Load amdgpu at stage 1
  boot.initrd.kernelModules = [ "amdgpu" ];
  boot.kernelParams = [
    "acpi_backlight=native"
    "amd_pstate=guided"
    "amdgpu"
    "iommu=soft"
  ];

  # AMD GPU
  hardware.graphics = {
     extraPackages = with pkgs; [
      vaapiVdpau

      rocmPackages.clr
      rocmPackages.clr.icd

      amdvlk
    ];
    extraPackages32 = with pkgs; [ driversi686Linux.amdvlk ];
  };

  environment.variables = {
    "VDPAU_DRIVER" = "radeonsi";
    "LIBVA_DRIVER_NAME" = "radeonsi";
  };
  # Most software has the HIP libraries hard-coded. Workaround:
  systemd.tmpfiles.rules = [
    "L+    /opt/rocm/hip   -    -    -     -    ${pkgs.rocmPackages.clr}"
  ];

  services.xserver.videoDrivers = lib.mkDefault [ "modesetting" ];
}

The full machine configuration is on my GitHub: configuration.nix.

Do you spot any differences to yours?

1 Like

To my old configs, yes a lot. But i used this now, thank you.

Are you getting good performance? glxgears gives what fps to you? I get <50

I am getting 301 frames in 5.0 seconds = 60.056 FPS i tested with this command [nix-shell:~]$ glxgears. Also i use the hyprland and i stayed on there if i go to another workspace then i get different results.

Do you get better performance on other distro? have you tested?

Oh, didn’t test with other distros. I just assumed this was an issue with my configs. glxgears is an ancient benchmarking tool, i assumed any modern machine would just get excellent performance from it.

I’m using Sway, with an external monitor. I get a bit better performance when the gears are on the laptop’s screen.

You should try, NO?
Also what kernel you use?
Do you use NixOS stable with unstable? And what you did with your mesa drivers?
For you information i had really bad performance on NixOS with my old global config, And because of unstable & stable branch's mix I was used to use unstable with stable which caused the issue, To fix that i recreated the global config and removed unstable branch