Linux Build Instructions
These instructions are for Mesa 19.0.0 and newer, which has migrated to using Meson+Ninja for configuring and building. Previous versions—18.3.4 and older—used GNU Autotools. If you are using a previous version, or would still like to use Autotools before it is removed, please click here.
On Linux, OpenSWR is built within Mesa using the Meson build system with Ninja, as described in Mesa's
Meson installation page, with the addition of
swr to the list of gallium drivers.
The instructions below describe how to compile Mesa using the Mesa released tarballs. Compiling directly from the git repository is more complex and is beyond the scope of these instructions. If you want to compile from the git repository and you run into issues, please contact us directly.
Mesa requires some dependencies to build:
as well as the following two Python modules installed via
Please make sure you install them prior to building. Refer to Mesa's installation page for more information on its requirements.
Building and Installing LLVM
One of the major Mesa requirements is LLVM, but with some additional flags required at compile time. If you do not already have LLVM, you will need to install it first. LLVM source is available as tarball on their release download page. Currently, LLVM versions 6.x through 7.0.1 are supported. Once downloaded, use the following steps to build and install LLVM. In this example we are installing them locally.
$ pwd /home/openswr/llvm $ ls llvm-x.y.z.src.tar.xz $ tar xJf llvm-x.y.z.src.tar.xz $ mkdir build $ cd build $ cmake -G "Unix Makefiles" \ -D CMAKE_BUILD_TYPE=Release \ -D LLVM_TARGETS_TO_BUILD=X86 \ -D BUILD_SHARED_LIBS=1 \ -D LLVM_ENABLE_RTTI=1 \ -D CMAKE_INSTALL_PREFIX=/home/openswr/.local/ \ ../llvm-x.y.z.src $ make -j `nproc` $ make installIf you do not install LLVM locally, make sure you set your
PATHenvironment variables to the LLVM
Building Mesa with OpenSWR
Download a Mesa source distribution from Mesa's download page. We recommend the latest non-release-candidate version for the best compatibility.
Once downloaded, use the following steps to build Mesa with OpenSWR.
$ pwd /home/openswr/mesa $ ls mesa-x.y.z.tar.gz $ tar xf mesa-x.y.z.tar.gz $ cd mesa-x.y.z $ mkdir build
Now we can configure Mesa with OpenSWR. In this example, we are installing Mesa locally.
$ meson --buildtype=release \ -Dglx=gallium-xlib \ -Dvulkan-drivers= \ -Ddri-drivers= \ -Dgallium-drivers=swrast,swr \ -Dplatforms=x11 \ -Dgallium-omx=disabled \ -Dprefix=/home/openswr/.local \ build
If you also want to compile OSMesa (off-screen rendering support), please add the following flag:
By default, the build will compile with support for AVX and AVX2 targets. If you want to also compile for Skylake and/or Knight's Landing architectures (AVX512), please add the following flag. Make sure your compiler supports the necessary compiler flags to compile for the specified architectures.
Once configured, you can use
ninja to build Mesa.
$ ninja -C build
And you can use
meson to install.
$ meson install -C build
Once installed, you will see
libOSMesa.so (if it was enabled), and
libSWR<arch>.so for each architecture selected.
Using Mesa with OpenSWR
If you installed Mesa with OpenSWR to a local directory as in the examples above, it should already be usable by
applications. If you installed elsewhere, you will need to include the path in your
environment variable. Make sure you specifically add the
lib/gallium directory to
$ export LD_LIBRARY_PATH=/your/path/to/mesa/lib:$LD_LIBRARY_PATH
Now any application seeking GL will use the Mesa installation. To enable the OpenSWR driver, you need to specify it with
GALLIUM_DRIVER environment variable:
$ export GALLIUM_DRIVER=swr
You should see a message printed to the terminal when running a GL application when OpenSWR is set as the gallium driver. For example:
$ glxgears SWR detected AVX2 instruction support (using: libswrAVX2.so).