www@edenist:~$

Building mesa-git on Solus Linux

UPDATE 2021-04-23: This post initially forgot to include the 32bit build commands. It has been updated to include them.

One of the benefits of running AMDGPU is that the userland component [from Mesa] can be specified at runtime.

For example, fixes for Cyberpunk2077 were merged into Mesa but the version from the Solus repository is usually a few versions behind. To get these new features [or perhaps you have a need for a specific version of Mesa], it must be built from source.

We can build mesa and install it in a non-standard location, then specify this version to run using the LD_LIBRARY_PATH variable.

The following dependencies are required to build mesa on Solus. They should be similar on most other major distributions. At the very least, meson will tell you if a dependency is missing, and you can find out which package provides it and install it. Note there is a large dependency list, particularly with the 32bit libraries, but building 32bit support is necessary to run 32bit applications such as Steam.

sudo eopkg install system.devel meson ninja llvm-devel llvm-32bit-devel llvm-clang-32bit-devel expat-devel expat-32bit-devel mako xrandr libxxf86vm-devel libxshmfence-devel glproto libva libzstd libnettle-devel libnettle-32bit-devel libva-devel zstd-devel zstd-32bit-devel libxrandr-devel libxrandr-32bit-devel libx11-devel libx11-32bit-devel libxxf86vm-32bit-devel libxshmfence-32bit-devel libxext-devel libxext-32bit-devel libxdamage-devel libxdamage-32bit-devel libelf-devel libelf-32bit-devel libunwind-devel libunwind-32bit-devel zlib-devel zlib-32bit-devel libglvnd-devel libglvnd-32bit-devel libvdpau-devel libvdpau-32bit-devel wayland-protocols-devel fakeroot-32bit libgcc libgcc-32bit xorgproto glibc-devel glibc-32bit-devel libxcb-devel libxcb-32bit-devel wayland-32bit-devel libxfixes-devel libxfixes-32bit-devel libdrm-devel libdrm-32bit-devel libstdc++ libstdc++-32bit libva-32bit-devel xorg-server-devel glslang-devel vulkan vulkan-tools vulkan-32bit

In this example, we will be installing mesa into /opt

Obtain a copy of the source code, then configure and build. Take note of the -Dprefix option, which tells ninja where to install the drivers. The build is run twice, once each for 32bit and 64bit builds. The following file is used as a crossfile to tell the compiler how to compile the 32bit version. Place it in the build32 directory prior to running meson.

llvm32.native

sudo mkdir -p /opt/mesa/mesa-git-20210410
sudo chown -R $USER /opt/mesa

git clone https://gitlab.freedesktop.org/mesa/mesa.git
cd mesa
mkdir build
mkdir build32

#Build 64bit
cd build
meson .. -Dprefix=/opt/mesa/mesa-git-20210410 -Dplatforms=x11 -Dgallium-drivers=radeonsi,svga,swrast,virgl -Dgallium-vdpau=true -Dgallium-xa=true -Dgallium-nine=true -Dvulkan-drivers=amd -Dshader-cache=true -Dgbm=true -Degl=true -Dglvnd=false -Dllvm=true -Dosmesa=true -Dvulkan-device-select-layer=true -Dvulkan-overlay-layer=true
meson configure #[shows the current configuration to check the options]
ninja
ninja install

#Build 32bit
cd ../build32
#copy llvm32.native here
meson .. --cross-file llvm32.native --libdir=/opt/mesa/mesa-git-20210410/lib32 -Dprefix=/opt/mesa/mesa-git-20210410 -Dplatforms=x11 -Dgallium-drivers=radeonsi,svga,swrast,virgl -Dgallium-vdpau=true -Dgallium-xa=true -Dgallium-nine=true -Dvulkan-drivers=amd -Dshader-cache=true -Dgbm=true -Degl=true -Dglvnd=false -Dllvm=true -Dosmesa=true -Dvulkan-device-select-layer=true -Dvulkan-overlay-layer=true
ninja
ninja install

Mesa git is now built and installed in /opt/mesa/mesa-git-20210410

To use them, simply set the variables LD_LIBRARY_PATH and VK_ICD_FILENAMES at runtime. The latter is required if you are using vulkan, including dxvk and vkd3d in the case of Cyberpunk.

To best check the correct driver is being loaded, I recommend using an overlay such as mangohud, which can be configured to display the driver version currently in use by an application. It is available via eopkg in Solus.

Test out your drivers by running vkcube…

LD_LIBRARY_PATH=/opt/mesa/mesa-git-20210410/lib64:/opt/mesa/mesa-git-20210410/lib32:$LD_LIBRARY_PATH VK_ICD_FILENAMES=/opt/mesa/mesa-git-20210410/share/vulkan/icd.d/radeon_icd.x86_64.json:/opt/mesa/mesa-git-20210410/share/vulkan/icd.d/radeon_icd.i686.json MANGOHUD=1 vkcube

The driver version should be 21.0.99, indicating the driver has been built directly from git.

When using this driver for Steam games, it is best to set the variables when running Steam itself, as the games will then inherit the variables. The steam runtime does a lot of library overrides, so setting the variables in a game’s launch options won’t work.

My steam launch command looks like this:

LD_LIBRARY_PATH=/opt/mesa/mesa-git-20210410/lib64:/opt/mesa/mesa-git-20210410/lib32:$LD_LIBRARY_PATH VK_ICD_FILENAMES=/opt/mesa/mesa-git-20210410/share/vulkan/icd.d/radeon_icd.x86_64.json:/opt/mesa/mesa-git-20210410/share/vulkan/icd.d/radeon_icd.i686.json MANGOHUD=1 ENABLE_VKBASALT=1 steam

And that’s it.

If you ever want to try a newer version from git, simply perform a git pull, make a new prefix directory and run the meson and ninja commands again [and adjust the variables to the new prefix accordingly].