View source in Mesa

OpenSWR

A High Performance, Highly Scalable Software Rasterizer for OpenGL

Linux Build Instructions

NOTE

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 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.

  1. Setup
    1. Building and Installing LLVM
  2. Building Mesa with OpenSWR
  3. Using Mesa with OpenSWR

Setup

Mesa requires some dependencies to build:

as well as the following two Python modules installed via pip:

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 install
                
If you do not install LLVM locally, make sure you set your LD_LIBRARY_PATH and PATH environment variables to the LLVM lib and bin directories, respectively.

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:

-Dosmesa=gallium
                

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.

-Dswr-arches=avx,avx2,skx,knl
                

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 libGL.so, 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 LD_LIBRARY_PATH environment variable. Make sure you specifically add the lib or lib/gallium directory to LD_LIBRARY_PATH.

$ 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 the GALLIUM_DRIVER environment variable:

$ export GALLIUM_DRIVER=swr
                

You can verify that OpenSWR is used for rendering using the following command:

$ glxinfo | grep "OpenGL\ renderer\ string"
OpenGL renderer string: SWR (LLVM 8.0.0, 256 bits)