diff --git a/NixOS.md b/NixOS.md index c607c98..c491dbc 100644 --- a/NixOS.md +++ b/NixOS.md @@ -869,27 +869,45 @@ Usually most of this should work out of the box on NixOS. Vulkan: - Verification: - If `vulkaninfo` returns information about your GPU, Vulkan is working. https://wiki.archlinux.org/title/Vulkan#Verification + - `nix-shell -p vulkan-tools --run vulkaninfo` - Run `vkcube` (X11) or `vkcube-wayland` (Wayland). It should view a spinning 3D cube and output e.g. `Selected GPU 0: AMD Radeon Graphics (RADV RENOIR)` + - `nix-shell -p vulkan-tools --run vkcube-wayland` OpenGL: - Verification: https://wiki.archlinux.org/title/OpenGL#Verification - `eglinfo -B` should not return `eglInitialize failed` + - `nix-shell -p glxinfo --run 'eglinfo -B'` - `eglgears_x11` and `eglgears_wayland` -> ![eglgears.png](assets/doc/eglgears.png) + - `nix-shell -p mesa-demos --run eglgears_wayland` Video acceleration: - VA-API + - Video Acceleration API (VA-API). Provides both hardware accelerated video encoding and decoding. - Verifying: `vainfo` -> E.g. `Driver version: Mesa Gallium driver 23.1.9 for AMD Radeon Graphics`. https://wiki.archlinux.org/title/Hardware_video_acceleration#Verifying_VA-API + - `nix-shell -p libva-utils --run vainfo` - Driver comparison chart. https://wiki.archlinux.org/title/Hardware_video_acceleration#VA-API_drivers - With `libva-mesa-driver` on "Radeon RX 7900 and higher/newer" a codec for encoding AV1 8 and 10 bit is available. - VDPAU - - Video Decode and Presentation API for Unix (VDPAU). + - Video Decode and Presentation API for Unix (VDPAU). Offload portions of the video decoding process and video post-processing to the GPU video-hardware. - Verifying: `vdpauinfo`. https://wiki.archlinux.org/title/Hardware_video_acceleration#Verifying_VDPAU + - `nix-shell -p vdpauinfo --run vdpauinfo` + +GPGPU (General-purpose computing on graphics processing units): + - OpenCL + - Verification using `clinfo` + - `nix-shell -p clinfo --run 'clinfo -l'` + - Should produce non-empty output, e.g. `Platform #0: AMD Accelerated Parallel Processing` + - `nix-shell -p clinfo --run clinfo` + - This output is more verbose. + - `Number of platforms` should be >= 1 Verify video driver in use: - `lspci -k | grep -EA3 'VGA|3D|Display'`. Example: `Kernel driver in use: amdgpu` + - `nix-shell -p pciutils --run 'lspci -k | grep -EA3 "VGA|3D|Display"'` Verification in general: - Encode a video or play a game and watch AMD GPU usage with `radeontop`. + - `nix-shell -p radeontop --run radeontop` Configuration example to disable integrated GUP: See [./hosts/yodaGaming/configuration.nix](./hosts/yodaGaming/configuration.nix) diff --git a/modules/gpu-amd.nix b/modules/gpu-amd.nix index 813925f..ad352b5 100644 --- a/modules/gpu-amd.nix +++ b/modules/gpu-amd.nix @@ -1,36 +1,50 @@ +# See `NixOS.md` at section "Graphic drivers". +# There more details are given including commands to verify working hardware acceleration. + { config, pkgs, ... }: +let + extra = [ + ]; +in { - # See `NixOS.md` at section "Graphic drivers" + hardware = { + graphics = { + # This is enabled by default. We have this for cosmetical reasons only. + # It provides the RADV driver. + enable = true; + # Required for wine. + enable32Bit = true; - hardware.opengl = { - enable = true; + # Additional packages to add to the default graphics driver lookup path. This can be used to add OpenCL drivers, VA-API/VDPAU drivers, etc. + extraPackages = extra; + # Required for wine. + extraPackages32 = extra; + }; - # Whether to enable accelerated OpenGL rendering through the Direct Rendering Interface (DRI). - # The Direct Rendering Infrastructure (DRI) is the framework comprising the modern Linux graphics [...]. The main use of DRI is to provide hardware acceleration for the Mesa implementation of OpenGL. - driSupport = true; - driSupport32Bit = true; - - extraPackages = [ - # AMD Open Source Driver For Vulkan - pkgs.amdvlk - - # Encoding/decoding acceleration - # - # VDPAU driver with OpenGL/VAAPI backend - pkgs.libvdpau-va-gl - # VDPAU driver for the VAAPI library - pkgs.vaapiVdpau + amdgpu = { + # Load amdgpu kernelModule in stage 1. Can fix lower resolution in boot screen during initramfs phase. + #initrd.enable = true; # OpenCL (Open Computing Language) is a framework for writing programs that execute across heterogeneous platforms. - # - # OpenCL ICD definition for AMD GPUs using the ROCm stack. - pkgs.rocm-opencl-icd - # OpenCL runtime for AMD GPUs, part of the ROCm stack. - pkgs.rocm-opencl-runtime + opencl.enable = true; - # Xorg driver for AMD Radeon GPUs using the amdgpu kernel driver - # https://gitlab.freedesktop.org/xorg/driver/xf86-video-amdgpu - pkgs.xorg.xf86videoamdgpu - ]; + # AMD driver for Vulkan. + # + # => Please use RADV instead except if some Windows games don't run with it. + # https://www.reddit.com/r/NixOS/comments/1dmkim8/comment/l9zaz75/ + # > Side note: you don't need to enable amdvlk unless you have a very specific reason to. Mesa has radv by default which is better for vulkan. + # + #amdvlk.enable = true; + #amdvlk.support32Bit.enable = true; + }; + }; + + environment.variables = { + # VDPAU does not pick up correct driver. Thus, we need to configure it manually. + # https://wiki.archlinux.org/title/Hardware_video_acceleration#Failed_to_open_VDPAU_backend + # + # https://discourse.nixos.org/t/24-11-amd-gpu-how-to-use-mesa-radv-instead-of-amdvlk/57110/5 + # https://github.com/NixOS/nixpkgs/issues/221535#issuecomment-1473815585 + "VDPAU_DRIVER" = "radeonsi"; }; }