Building the i965 mesa driver on FreeBSD

Today I wanted to see if I can build mesa on FreeBSD. I had to do a few fixes in the code of libdrm and mesa, but the rest of the process was very similar to the steps I follow to build mesa on Linux. Only some paths and a few commands and settings had to be slightly different.

Below you can find the steps to build mesa on FreeBSD.


Mesa prerequisites on FreeBSD are the same packages we need on Linux. You can fimd them in the official documentation or by checking the mesa dependencies with pkg info -dx mesa.

The kernel driver must be installed in the system otherwise the software rasterizer is going to be used:

The user that is going to use OpenGL needs to be in the video group in /etc/group. Note that there’s only one group for graphics, there’s no separate render group like on Linux.

File /etc/rc.conf needs to be modified to contain the following line for the kernel module to be automatically loaded:

I’ve written a minimal Xorg.conf in /etc/X11 to force DRI3. This is not required for OpenGL as far as I remember. I created it because I want to experiment with the Vulkan driver in the future (although my GPU is not well supported).

Enabling DRI3 is recommended for the anv (Vulkan) driver to work.


My setup is similar to the one I use on Linux. On FreeBSD I use bash with sh scripts because I want to reuse my scripts on both FreeBSD and Linux. In case you are using another shell on FreeBSD you might need to replace all export FOO=bar with setenv FOO bar below.

I usually create a “code” directory where I clone repositories and an installation directory where I install everything I build. I set the library path to include this directory so that I can link with all the libraries I’ve built instead of the system ones.

So for i965, I have a directory mesastuff where I checkout every repository I’ll need to build for the mesa drivers to work. The mesastuff directory tree is this:

I checkout the git repositories in code and I use the path to the directory install as install prefix when I build repositories from code. Directories include, lib, libdata, and share are generated later from the installation scripts, I’ve only created code and install and then cloned drm and mesa in the first one.

I am using the following environment variables:

Note that the paths are different for Linux, on FreeBSD everything is installed under lib/ and there’s no separate x86_64 directory.

Getting the source code:

Inside the code directory I clone the git repositories for drm and mesa:

Or you can do:

if you have an account on Freedesktop.

Building drm and mesa:

The instructions are for the i965 driver but the process to build other drivers is similar. Because gcc and g++ that are the recommended tools for mesa aren’t installed by default on FreeBSD (clang is the default compiler), it’s recommended you install gcc and export (or setenv) the following variables:

To build and install libdrm enter the drm directory and run:

After that the dri drivers shared libraries should be found under install/lib/dri:

Mesa will find them because this directory is in the LD_LIBRARY_PATH we’ve set above.

This is how I build mesa:

Note that I’ve built the iris driver (the gallium replacement of i965) for this example, although I can’t enable it on my card which is a 9 year old Ivybridge. I am going to try crocus at some point (crocus is a gallium i965 replacement driver for older cards).

Testing the installation using glxinfo and glxgears:

To test the installation:
In the same terminal where we’ve set the environment variables (I’ve put all the above commands in a script) we can run:

If the renderer string is softpipe, something is wrong with hardware acceleration (most probably the kernel module wasn’t loaded)._

If the OpenGL version string ends in something like Mesa <a number>-devel (git-dc883225c5) (ends with the last git commit hash) then the mesa driver from git is being used (the one we’ve just built).

Next run glxgears. _GL_SYNC_TO_VBLANK doesn’t seem to work so if you want to check the FPS without the vsync being enabled you must run:

And this is how glxinfo output and glxgears look on my FreeBSD desktop:

Note the version and the renderer string that is IVB (Intel Ivybridge).


I had to make a few fixes in drm and mesa before the build was successful on FreeBSD. I am writing this post right after having sent the patches and as you can guess they aren’t upstream. You can grab them from their merge requests to build mesa but keep in mind that they might not be the final as they haven’t been reviewed yet!:

DRM patch: MR 173
Mesa patch: MR 11203

The End!

Yes, you’ve just reached it!

See you next time!

Leave a Reply

Your email address will not be published. Required fields are marked *