Unable to play games with amdgpu

I haven’t played games in a few years, and today I thought opening The Forest would be fun. Unfortunately, NixOS had other plans…

Problem:
I’m running Sway on a Ryzen 9 5950X with an RX 6700 XT. During game startup, GPU usage spikes to ~70%, which seems fine, but once the game launches I get ~20 FPS on low settings, GPU usage drops to 25–30%, and CPU usage skyrockets to ~1500% (I have 16 cores, 32 threads)

What I tried:
I’ve followed suggestions from the NixOS wiki, Reddit threads, tried Flatpak Steam, running game natively and with proton and experimented with various configurations.

My latest attempt:

hardware = {
  enableRedistributableFirmware = true;
  enableAllFirmware = true;
  amdgpu = {
    opencl.enable = true;
    initrd.enable = true;
  };
  graphics = {
    enable = true;
    enable32Bit = true;
    extraPackages = with pkgs; [
      libva-vdpau-driver
      libvdpau-va-gl
      rocmPackages.clr.icd
      vulkan-extension-layer
      vulkan-loader
      vulkan-tools
      vulkan-validation-layers
    ];
    extraPackages32 = with pkgs.pkgsi686Linux; [
      libva-vdpau-driver
      libvdpau-va-gl
      vulkan-extension-layer
      vulkan-loader
      vulkan-tools
      vulkan-validation-layers
    ];
  };
  cpu.amd.updateMicrocode = true;
};

I also tried this script to launch the game:

(pkgs.writeShellScriptBin "amdvlk-run" ''
  export VK_ICD_FILENAMES="/run/opengl-driver/share/vulkan/icd.d/radeon_icd.x86_64.json:/run/opengl-driver-32/share/vulkan/icd.d/radeon_icd.i686.json"
  exec "$@"
'')

At this point, I’m pretty lost. Any help or guidance would be greatly appreciated!

Ummm… Guess what! I tried running it with Proton GE and it works great, high settings on 55-60fps (probably with vsync)

On unrelated note, i don’t think i wanna play it anymore. Imma go on the couch and open Netflix

Also if anyone knows the one true correct config - please share it, i feel like i should have been able to get similar fps with standard proton/native. I am not sure whats so special about proton GE, maybe ill poke around its derivation, thats probably where magic is. Nope, not there. It has no fancy wrappers

Maybe I am misunderstanding the problem but the way i see it is that native games and standard proton does not detect my GPU, or detects it but for some reason prefers to use llvmpipe.

While what you shared might be the answer, few bullet ponts might be related but I wish I knew exact reason why/how

I had the same GPU and it was running well. I did not do anything very custom. Just programs.steam.enable and

inputs.nixos-hardware.nixosModules.common-cpu-intel
inputs.nixos-hardware.nixosModules.common-gpu-amd

from GitHub - NixOS/nixos-hardware: A collection of NixOS modules covering hardware quirks.
I had some audio issues with pipewire but it was solved by using cachyos kernel GitHub - chaotic-cx/nyx: Nix flake for "too much bleeding-edge" and unreleased packages (e.g., mesa_git, linux_cachyos, firefox_nightly, sway_git, gamescope_git). And experimental modules (e.g., HDR, duckdns).

I think a lot of the code you’ve shown there should be removed.

This one is probably fine but also probably not helping for gaming.

This one should be removed unless you need kexec and / or hibernation (as opposed to suspend) to work. It basically makes your initrd about 30MiB larger, which is quite costly on your /boot file system, and the only benefit is that the GPU driver gets to load earlier during the boot process than it would normally, which can make kexec and resuming from hibernation more reliable.

I think these can all be removed. IIUC, vaapi is generally considered better than vdpau, and should be supported out of the box with just the default mesa packages. Plus vdpau has nothing to do with games working. The vulkan-* things are not driver packages; adding them here does nothing.

IIRC this is just redundant and doing what vulkan / mesa would do out of the box. Also calling it amdvlk-run is misleading because amdvlk is a different vulkan driver for AMDGPU that is probably worse and probably not what you want to use :stuck_out_tongue: The default radv driver is the good one these days.

2 Likes

Yep, after last post i’ve looked into all this and already removed all that. At that point i was just copying configs from various places trying to figure this out.

Between last post and now I’ve discovered that my initial assumption of games running with llvmpipe was wrong so none of this thread is really relevant

My current theory is that XWayland is slowing things down and proton-ge has some optimizations for it. I still need to prove it tho

Generally I find AMD graphics a lot easier to get going than Nvidia

These are mostly my AMD graphics related settings:

  boot = {
    initrd.kernelModules = [
      "amdgpu"
    ];
  };
  hardware.graphics = {
    enable = true; # auto includes mesa
    package = pkgs.mesa;
    extraPackages = with pkgs; [
      libglvnd
      libva-vdpau-driver
      libvdpau-va-gl
      rocmPackages.clr.icd
    ];
  };
  services.xserver = {
    enable = true;
    videoDrivers = [ "amdgpu" ];
    xkb = {
      layout = "us";
      variant = "";
    };
  };

My home.nix includes packages:

    #gpu monitoring
    rocmPackages.rocminfo
    rocmPackages.rocm-smi
    rocmPackages.rocm-core
    lact
    # https://github.com/aristocratos/btop
    btop-rocm

    # https://github.com/ollama/ollama
    ollama-rocm

I made a small video about using ollama with AMD GPUs on NixOS, which is sort of related

As @ElvishJerricco is saying, you probably don’t want to use vdpau.

I’m fairly certain your entire hardware.graphics config can also be removed without impacting any of your use cases - even hardware.graphics.enable itself is almost definitely set by your DE/WM.

You probably also don’t want to manually set that kernel module, it’s the same initrd thing @ElvishJerricco mentions except you did it manually instead of with the option.

Oh cool. Thanks. I’ll give it a try :pray: