Building ParaView with GPU accelerated MESA

Note: This tutorial used this wiki article as a base.
https://www.paraview.org/Wiki/ParaView/ParaView_And_Mesa_3D

Before getting into details of Mesa graphics hardware drivers, a disclaimer. If you have graphics hardware Mesa is not your best option. To get the best performance from your graphics card you’ll need to install the vendor provided driver. Vendor provided OpenGL drivers are typically much faster of a much higher quality than Mesa’s which can be quite buggy. Many distros now provide third-party non-opensource source drivers through specialized package repositories. The details of installing vendor provided drivers in beyond the scope of this document. Please consult distro and/or vendor-specific documentation.

If you’re running a Linux OS with X11 and graphics hardware and have not installed any OpenGL libraries you’re probably already using Mesa or Nouveau! Note that the windowing system, in this case X11, is required for on-screen interactive rendering. On Linux systems the easiest way to install Mesa is through your distro’s package manager. Most distros also provide packages for Mesa’s software-based renderers as well. Unfortunately, some OpenGL features may be disabled by your distro’s package maintainers to avoid patent or other licensing restrictions. If you find that this is the case and if for some reason you do not want to use your graphics hardware vendor software then you’ll likely want to build Mesa from source.

1. Download, Build and Install LLVM

$ wget http://releases.llvm.org/7.0.1/llvm-7.0.1.src.tar.xz
$ mkdir llvm
$ cd llvm
$ tar -xvf /path/to/llvm-7.0.1.src.tar.xz
$ mkdir llvm_build
$ mkdir llvm_install
$ cd  llvm_build
$ cmake                                           \
  -DCMAKE_BUILD_TYPE=Release                    \
  -DBUILD_SHARED_LIBS=ON                            \
  -DCMAKE_INSTALL_PREFIX=/path/to/llvm_install  \
  -DLLVM_ENABLE_RTTI=ON                         \
  -DLLVM_INSTALL_UTILS=ON                       \
  -DLLVM_TARGETS_TO_BUILD:STRING=X86            \
  ../llvm-7.0.1.src
$ make -j8 install

2. Download, Build and Install Mesa
Mesa download usually contains llvm-dependent preprocessed files. We do not want that, as they may rely on another version of llvm so we download a specific version without these.

$ wget https://gitlab.freedesktop.org/mesa/mesa/-/archive/mesa-18.3.3/mesa-mesa-18.3.3.tar.bz2
$ mkdir mesa
$ cd mesa
$ tar -xvf /path/to/mesa-mesa-18.3.3.tar.bz2
$ cd mesa-mesa-18.3.3
$ autoreconf --force --verbose --install
$ cd ../
$ mkdir mesa_build
$ mkdir mesa_install
$ cd mesa_build
$ ../mesa-mesa-18.3.3/configure --prefix=/path/to/mesa_install \
--enable-opengl --disable-osmesa --disable-gallium-osmesa \
--enable-glx --with-platforms=x11 --disable-gles1 --disable-gles2 \
--disable-va --disable-gbm --disable-xvmc --disable-vdpau \
--disable-shared-glapi --disable-dri --with-dri-drivers= \ 
--enable-llvm  --with-llvm-prefix=/path/to/llvm_install  \
--with-gallium-drivers=swrast,swr --with-swr-archs=avx,avx2 --disable-egl 
$ make -j8 install

In more recent version, mesa switched to meson build system, here is how to build it:

$ wget https://gitlab.freedesktop.org/mesa/mesa/-/archive/mesa-18.3.3/mesa-mesa-20.2.3.tar.bz2
$ mkdir mesa
$ cd mesa
$ tar -xvf /path/to/mesa-mesa-18.3.3.tar.bz2
$ mkdir mesa_install
$ cd mesa-mesa-20.2.3
$  meson -Dopengl=true -Dosmesa=none -Dglx=gallium-xlib -Dplatforms=x11 -Dgles1=disabled  \
-Dgles2=disabled -Dgbm=disabled -Dshared-glapi=disabled -Ddri-drivers= -Dllvm=enabled \ 
-Dgallium-drivers=swrast,swr -Dswr-arches=avx,avx2 -Degl=disabled build \
-Dprefix=/path/to/mesa/intall .
$ ninja -C build/
$ ninja -C build/ install

3. Download and Build ParaView with mesa
Note : a glx related warning may be seen, that’s ok.
https://gitlab.kitware.com/paraview/paraview/issues/18777

$ mkdir paraview
$ cd paraview
$ git clone https://gitlab.kitware.com/paraview/paraview
$ cd paraview
$ git submodule update --init --recursive
$ cd ../
$ mkdir paraview_build
$ cd paraview_build
$ cmake -GNinja -DOPENGL_gl_LIBRARY=/path/to/mesa/install/lib/libGL.so \
-DOPENGL_INCLUDE_DIR=/path/to/mesa/install/include/GL \
-DOPENGL_EGL_INCLUDE_DIR= -DOPENGL_GLES2_INCLUDE_DIR= \
-DOPENGL_GLES3_INCLUDE_DIR= -DOPENGL_GLX_INCLUDE_DIR= \
-DOPENGL_egl_LIBRARY= -DOPENGL_gles2_LIBRARY=  \
-DOPENGL_gles3_LIBRARY= -DOPENGL_glu_LIBRARY= \
-DOPENGL_glx_LIBRARY= -DOPENGL_opengl_LIBRARY= ../paraview
$ LD_LIBRARY_PATH=/path/to/llvm_install/lib ninja

Note : depending of your version of ParaView, some cmake options may be ignored. This is ok.

4. Run ParaView (5.6.0 and earlier versions)

To Run it with mesa :

$ LD_LIBRARY_PATH=/path/to/llvm_install/lib:/path/to/mesa_install/lib ./bin/paraview
Help -> About : OpenGL : Mesa, llvmpipe...

If you have your GPU hardware vendor driver installed and module loaded, you can still use it :

LD_LIBRARY_PATH= ./bin/paraview
Help->About : OpenGL : Nvidia ...

5. Run ParaView (master version)
Note : This may change fast, see here :
https://gitlab.kitware.com/paraview/paraview/issues/18780

To Run it with mesa :

$ LD_LIBRARY_PATH=/path/to/llvm_install/lib:/path/to/mesa_install/lib ./bin/paraview
Help -> About : OpenGL : Mesa, llvmpipe...

If you have your GPU hardware vendor driver installed and module loaded, you can still use it :

LD_LIBRARY_PATH=/path/to/llvm/install/lib/:/path/to/mesa/install/lib  LD_PRELOAD=/usr/lib/libGL.so ./bin/paraview
Help->About : OpenGL : Nvidia ...
2 Likes

@cory.quammen : I have no idea why the coloring and bolding is all over the place.

Use ```bash to start the script portion. That seems to fix the formatting for me.

Thanks to @mwestphal for the great tips.
I have been running ParaView 5.6 with Mesa 17.2.8 compiled with LLVM 5 for several months and things work well. Switching to Mesa 18.3.3 and following the recipes above, I get a run-time error:

ERROR: In /apps/daint/UES/ParaView/src/ParaView-v5.6.0/VTK/Rendering/OpenGL2/vtkShaderProgram.cxx, line 447

vtkShaderProgram (0x1bc0920): 0:1(10): error: GLSL 1.50 is not supported. Supported versions are: 1.10, and 1.20

and

indentERROR: In /apps/daint/UES/ParaView/src/ParaView-v5.6.0/VTK/Rendering/OpenGL2/vtkOpenGLRenderWindow.cxx, line 749

vtkOSOpenGLRenderWindow (0x1579a60): Unable to find a valid OpenGL 3.2 or later implementation. Please update your video card driver to the latest version. If you are using Mesa please make sure you have version 11.2 or later and make sure your driver in Mesa supports OpenGL 3.2 such as llvmpipe or openswr.

is this error with GLSL 1.5 not supported specific to ParaView 5.6? Is it worth it trying with the development branch?

I did not experience this issue with any version. I tested master, 5.6.0 and 5.5.0.

Sorry to open this thread again.
Are these steps still valid for 5.8 ?
I am getting error at build:

In file included from VTK/GUISupport/Qt/QVTKWidgetPlugin_autogen/mocs_compilation.cpp:2:0:
VTK/GUISupport/Qt/QVTKWidgetPlugin_autogen/EWIEGA46WW/moc_Q4VTKWidgetPlugin.cpp:9:123: fatal error: …/…/…/…/…/…/…/…/…/…/rt/7.2/opt/paraview/5.8.0_mesa/src/paraview/VTK/GUISupport/Qt/Q4VTKWidgetPlugin.h: No such file or directory

Any thoughts ?

Unrelated error. build from scratch and disable the designer plugin.

Updated for a more recent mesa.