-
Notifications
You must be signed in to change notification settings - Fork 13
Headless rendering
Recent linux distributions now come with a newer version of libOSMesa.so built with multi-threaded rendering using LLVMpipe so the instructions on this page are no longer relevant as building Mesa should not be necessary.
(Based on testing on Ubuntu 20.04 and Centos 8.1)
To request an OSMesa software rendering build, just use the following command:
LV_OSMESA=1 pip install --no-binary :all: lavavu
The "no-binary" option prevents installing a pre-built wheel which links the default system libGL.so and not libOSMesa.so.
If building using make, the required flag is:
make OSMESA=1
If limited to a machine without graphics hardware: in order to gain the fastest possible software rendering, use a virtual X display with the Mesa llvmpipe build. This is available by installing the packages below, it will use all available CPU cores resulting in much faster output. Slower than a real GPU but much better then single-core OSMesa.
xvfb libgl1-mesa-dri libgl1-mesa-glx
Xvfb :0 -screen 0 1600x1200x16&
export DISPLAY=:0
If only an old or single-core version of Mesa is enabled you can build one fairly easily
Here are my steps from installing dependencies/building on an Ubuntu system for reference (see also: http://www.mesa3d.org/install.html)
Install dependencies (probably missing some here, see link above)
sudo apt-get install autoconf scons libedit-dev llvm-dev
Download and extract
wget ftp://ftp.freedesktop.org/pub/mesa/11.0.7/mesa-11.0.7.tar.gz
tar xvf mesa-11.0.7.tar.gz
cd mesa-11.0.7
Builds our own libGL that works with X11/glx apps
scons build=release libgl-xlib
Must be linked in directly when building LavaVu, eg:
make -j4 LIBDIR=$HOME/mesa-11.0.7/build/linux-x86_64/gallium/targets/libgl-xlib/
The user must be logged in to the local machine or OpenGL will not work, this is an OS X limitation and can't be worked around unfortunately.
The error message if not logged in will be something like:
RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
This is what worked for me with Mesa 17.1.5:
wget https://mesa.freedesktop.org/archive/mesa-17.1.5.tar.xz
tar xvf mesa-17.1.5.tar.xz
cd mesa-17.1.5
module load gcc/5.2.0
module load scons
module load python/2.7.11
pip install --user Mako
LLVM_BASE=/apps/llvm/4.0.0-gcc520
CPLUS_INCLUDE_PATH=${LLVM_BASE}/include:${CPLUS_INCLUDE_PATH}
LIBRARY_PATH=${LLVM_BASE}/lib:${PATH}
LD_LIBRARY_PATH=${LLVM_BASE}/lib:${LD_LIBRARY_PATH}
CPATH=${LLVM_BASE}/include:${CPATH}
PATH=${LLVM_BASE}/bin:${PATH}
LLVM_ROOT=${LLVM_BASE}
C_INCLUDE_PATH=${LLVM_BASE}/include:${C_INCLUDE_PATH}
LD_RUN_PATH=${LLVM_BASE}/lib:${LD_RUN_PATH}
LLVM_VERSION=4.0.0
scons build=release libgl-xlib
The Scons build no longer appears to support the target libgl-xlib...
ftp://ftp.freedesktop.org/pub/mesa/mesa-18.0.2.tar.gz
sudo apt-get install autoconf scons libedit-dev llvm-dev bison flex python-mako pkg-config libexpat1-dev
./configure --enable-glx=gallium-xlib --with-gallium-drivers=swrast --disable-dri --disable-gbm --disable-egl
The Scons build seems to have been fixed so it's back to like before:
wget https://mesa.freedesktop.org/archive/mesa-19.0.3.tar.gz
tar xzvf mesa-19.0.3.tar.gz
cd mesa-19.0.3
sudo apt install scons libedit-dev llvm-dev bison flex python-mako pkg-config libexpat1-dev
scons build=release libgl-xlib -j5
ls build/linux-x86_64/gallium/targets/libgl-xlib/
Now that we support GLESv2 only rendering, attempting a build of Mesa EGL surfaceless with GLESv2
This should allow headless multicore CPU rendering without an X server
wget ftp://ftp.freedesktop.org/pub/mesa/mesa-19.1.1.tar.xz
tar xvf mesa-19.1.1.tar.xz
rm mesa-19.1.1.tar.xz
cd mesa-19.1.1/
#Deps
sudo gvim /etc/apt/sources.list #Added deb-src entries
sudo apt update
sudo apt build-dep mesa
meson build/ -Degl=true -Dgles1=true -Dgles2=true -Dplatform=surfaceless
meson configure build/ -Dprefix=${PWD}/build/install
ninja -C build/ -j5
ls -ltr
ninja -C build/ install
ls build/install/
Then build LavaVu with...
make -j5 VIDEO=1 LIBPNG=1 TIFF=1 X11=0 EGL=1 GLES2=1 OPENGL_LIB=${HOME}/mesa-19.1.1/build/install/lib/x86_64-linux-gnu/ OPENGL_INC=${HOME}/mesa-19.1.1/build/install/include/
Tests... This runs nicely on first tests, uses all cores to do rendering, but it turns out the X display is still required, it seems things are not quite there yet and we've gained nothing.
So as a last ditch lets try building the old OSMesa interface we gave up on years ago, as according to the mesa docs it supports llvmpipe now:
wget ftp://ftp.freedesktop.org/pub/mesa/mesa-19.1.7.tar.xz
tar xvf mesa-19.1.7.tar.xz
rm mesa-19.1.7.tar.xz
cd mesa-19.1.7/
#Install dependencies
sudo apt install autopoint debhelper dh-autoreconf dh-strip-nondeterminism diffstat flex gettext intltool-debian lib32gcc1 lib32stdc++6 libarchive-zip-perl libc6-i386 libclang-8-dev libclang-common-8-dev libclang1-8 libclc-dev libfile-stripnondeterminism-perl libgc1c2 libobjc-7-dev libobjc4 libsensors4-dev libset-scalar-perl libtimedate-perl libva-dev libva-drm2 libva-glx2 libva-wayland2 libva-x11-2 libva2 libvdpau-dev libvdpau1 libvulkan-dev libvulkan1 libwayland-bin libwayland-dev libwayland-egl-backend-dev libxrandr-dev llvm-8 llvm-8-dev llvm-8-runtime meson ninja-build po-debconf python3-mako quilt wayland-protocols x11proto-randr-dev
#(To get/update deps list)
#sudo gvim /etc/apt/sources.list #Added deb-src entries
#sudo apt update
#sudo apt build-dep mesa
meson build/ -Dosmesa=gallium -Dgallium-drivers=swrast -Ddri-drivers= -Dvulkan-drivers= -Degl=false -Dgbm=false -Dgles1=false -Dgles2=false
meson configure build/ -Dprefix=${PWD}/build/install
ninja -C build/ -j5
ninja -C build/ install
Then build LavaVu
LV_LIB_DIRS=${HOME}/mesa-19.1.7/build/install/lib/x86_64-linux-gnu/ LV_INC_DIRS=${HOME}/mesa-19.1.7/build/install/include/ make -j5 VIDEO=1 LIBPNG=1 TIFF=1 X11=0 OSMESA=1
Success!
time lavavu/LavaVu -z1 voltest image
real 0m3.675s
Python build:
python setup.py clean --all
LV_OSMESA=1 LV_LIB_DIRS=${HOME}/mesa-19.1.7/build/install/lib/x86_64-linux-gnu LV_INC_DIRS=${HOME}/mesa-19.1.7/build/install/include python setup.py install