View source in Mesa

OpenSWR

A High Performance, Highly Scalable Software Rasterizer for OpenGL

Linux Build Instructions

On Linux, OpenSWR is built within Mesa using the standard autoconf package as described in Mesa's 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. 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
                

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
$ cd build
                

Now we can configure Mesa with OpenSWR - note the addition of swr as a gallium driver. In this example, we are installing Mesa locally.

$ ../configure --disable-dri \
               --disable-egl \
               --disable-gbm \
               --with-gallium-drivers=swrast,swr \
               --with-platforms=x11 \
               --prefix=/home/openswr/.local
                

If you run into problems due to VL on your system, add the following flags to the above configure call:

--disable-xvmc --disable-vdpau --disable-va
                

If you also want to compile OSMesa (off-screen rendering support), please add the following flag:

--enable-gallium-osmesa
                

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.

--with-swr-archs=avx,avx2,skx,knl
                

After you have the appropriate configure command for your system, you can build and install with make

$ make -j `nproc`
$ make install
                

Once installed, you will see libGL.so, libOSMesa.so, and libSWR<arch>.so (for each architecture selected) in lib/gallium/ in your build directory as well as in lib/ in your installation directory.

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=/some/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 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).