Graphics: Difference between revisions
m Add VDPAU failing to detect correct driver on Wayland |
m →OpenGL: Changed wording, as NixOS 24.11 has been released now. |
||
Line 22: | Line 22: | ||
== OpenGL == | == OpenGL == | ||
{{Note|<code>hardware.opengl</code> | {{Note|<code>hardware.opengl</code> was renamed to <code>hardware.graphics</code> in NixOS 24.11.}} | ||
Userspace-level graphics support is provided through OpenGL. The kernel module is used just for interfacing with the hardware, the OpenGL driver is what Wayland (or the X server) actually uses for rendering. | Userspace-level graphics support is provided through OpenGL. The kernel module is used just for interfacing with the hardware, the OpenGL driver is what Wayland (or the X server) actually uses for rendering. |
Latest revision as of 21:33, 12 December 2024
This is intended to be an overview of how setting up graphics on NixOS works.
Hardware-Specific Pages
Kernel-Level
Kernel-level GPU support is provided by a kernel module. E.g. for AMD GPUs (including iGPUs) that's amdgpu
.
The module is loaded automatically based on the detected hardware.
On x86 devices, detection is done automatically through ACPI. On ARM devices such as the Raspberry Pi, information about hardware is provided through a devicetree, normally by the bootloader.
When loading the module, the kernel uses *Kernel Mode Setting* (KMS) to configure the video mode. This allows native resolution during boot and in tty's. See also the Arch Wiki.
Normally, the kernel module is loaded and KMS is performed after the initrd stage ("late KMS"), i.e. after entering the encryption password if you use full disk encryption. This will produce some flickering.
The kernel module can also be added to the initrd itself ("early KMS") by adding the kernel module for your hardware to boot.initrd.kernelModules
. Early KMS is especially desirable when using something like Plymouth for flicker-free fancy graphics during boot. If you don't use Plymouth, early KMS might actually make the boot sequence worse, because the flicker might heppen during encryption password entry.
OpenGL
Userspace-level graphics support is provided through OpenGL. The kernel module is used just for interfacing with the hardware, the OpenGL driver is what Wayland (or the X server) actually uses for rendering.
The OpenGL implementation used on Linux is the Mesa graphics library. Mesa contains drivers for various hardware, the exact driver is selected automatically. Note that Mesa also supports software rendering if no compatible hardware driver is available, but this is very slow.
Mesa can installed using the option hardware.opengl.enable
, but note that most desktop environment modules set this themselves anyway. This option writes the driver files to /run/opengl-driver
. Additional graphics drivers packages can be added using hardware.opengl.extraPackages
.
To verify which Mesa driver is used: nix shell nixpkgs#glxinfo -c glxinfo
Vulkan
Apart from the OpenGL API, there's also the more modern Vulkan API. Vulkan drivers are also included in Mesa (e.g., for AMD hardware that's RADV). See also the Arch Wiki.
For the installed Vulkan drivers, see /run/opengl-driver/share/vulkan/icd.d/
. To verify which driver is used: nix shell nixpkgs#vulkan-tools -c vulkaninfo
OpenCL
Computing things on the GPU is supported through the OpenCL API. To enable OpenCL support, add the right packages for your hardware to hardware.opengl.extraPackages
. See also the Arch Wiki.
To verify OpenCL support: nix shell nixpkgs#clinfo -c clinfo
Hardware Video Acceleration
GPUs have built-in hardware for decoding / encoding video. Using this is much more efficient than using the CPU. See also the Arch Wiki.
There are two main APIs for video accel on Linux.
VA-API
Developed by Intel, open spec, FOSS library. Seems to be generally broader supported than VDPAU.
Many VA-API drivers are also included in Mesa.
For available drivers, see /run/opengl-driver/lib/dri
. The file names are {DRIVER_NAME}_drv_video.so
.
The driver used for VA-API can be overridden with the env var LIBVA_DRIVER_NAME
. E.g. for AMD, it's radeonsi
.
To verify VA-API support and view supported codecs: nix shell nixpkgs#libva-utils -c vainfo
VDPAU
Authored by Nvidia, developed by freedesktop.org, open spec, FOSS library.
Many VDPAU drivers are also included in Mesa.
For available drivers, see /run/opengl-driver/lib/vdpau
. The file names are libvdpau_{DRIVER_NAME}.so
.
The driver used for VDPAU can be overridden with the env var VDPAU_DRIVER
. E.g. for AMD, it's radeonsi
.
To verify VDPAU support and view supported codecs: nix shell nixpkgs#vdpauinfo -c vdpauinfo
Note that VDPAU will not be able to detect the correct drive to use in most Wayland enviroments, as there is no DRI2 support. The driver will always fall back to nvidia
if it wasn't set using VDPAU_DRIVER
.[1]
See also
- The Arch Wiki has good articles on a lot of these topics, which are linked above.
- writeup about setting up graphics in Eisfunke's NixOS config repo (this article was originally based on that)