Install Vulkan on a Raspberry Pi 4.
Last updated: January 10, 2022
This page guides you through the installation of Vulkan on a Raspberry Pi 4. Vulkan is a low-level 3D graphics accelerator using a balanced mix of CPU and GPU instructions and optimized for parallel tasking with multiple CPU cores. Many platforms are already using Vulkan, and now the Raspberry Pi is on board too.
One important point to mention, the software is still under construction. All the hard work is done by Igalia's lago Toral. And that's not easy considering the lack of a detailed VideoCore VI datasheet. At the moment (Jan 2023), after many tests, the Vulkan driver is upgraded to Vulkan 1.2 conformance, thereby getting an official status.
For those looking for a graphical improvement to their games on a Raspberry Pi 4, the Vulkan API is the best (and only) solution.
On the other hand, for all the people looking to use the Vulkan library to boost their deep learning frameworks, a big disappointment awaits. The API is not yet well equipped to perform tensor calculations. The required operations are currently not supported. Maybe the near future will bring us good news.
Although the latest Bullseye operating system comes with the Mesa branch 20.3.5, we are building and installing it from scratch. This way, the Vulkan libraries are system-wide accessible.
One last remark, the Vulkan API works only on the Raspberry Pi 4. The Raspberry Pi 3 has another VideoCore GPU on board which is incompatible with the version found on the Pi 4.
The installation procedure differs between the Buster and Bullseye operating systems. Also between the 32 and 64-bit versions.
Time to check your operating system before installing Vulkan on your Raspberry Pi 4. Run the command uname -a and verify your version with the screen dump below.
By far, the easiest way to install Vulkan on your Raspberry Pi 4 with the Buster OS is to use PiKISS. PiKISS is a collection of installation and configuration scripts packed in a menu structure. It works only for 32-bit operating systems, 64-bit are not supported yet. Complicated installations are becoming one mouse click. A tip: keep your PiKISS up to date because of the ever-changing software. Install PiKISS with the following instruction.
# install PiKISS
$ sudo apt-get install curl
$ curl -sSL https://git.io/JfAPE | bash
# or update PiKISS once installed
$ cd ~/piKiss
$ git pull
Once PiKISS is installed, you can find the application in the system tools menu.
There are a lot of tutorials and videos on the net explaining the many features of PiKISS. We will mention this one from the maker of PiKISS.
Now that PiKISS is up and running, Vulkan can be installed. Just follow the screen dumps, and the installation will start. It will take a while. In the end, you will end up with the following screen. In fact, PiKISS follows all the steps given in this guide in just one go.
Installation from scratch.
The Vulkan API has a many dependencies. Please, install the list below.
# check for updates
$ sudo apt-get update
$ sudo apt-get upgrade
# install dependencies
$ sudo apt-get install libxcb-randr0-dev libxrandr-dev
$ sudo apt-get install libxcb-xinerama0-dev libxinerama-dev libxcursor-dev
$ sudo apt-get install libxcb-cursor-dev libxkbcommon-dev xutils-dev
$ sudo apt-get install xutils-dev libpthread-stubs0-dev libpciaccess-dev
$ sudo apt-get install libffi-dev x11proto-xext-dev libxcb1-dev libxcb-*dev
$ sudo apt-get install libssl-dev libgnutls28-dev x11proto-dri2-dev
$ sudo apt-get install x11proto-dri3-dev libx11-dev libxcb-glx0-dev
$ sudo apt-get install libx11-xcb-dev libxext-dev libxdamage-dev libxfixes-dev
$ sudo apt-get install libva-dev x11proto-randr-dev x11proto-present-dev
$ sudo apt-get install libclc-dev libelf-dev mesa-utils
$ sudo apt-get install libvulkan-dev libvulkan1 libassimp-dev
$ sudo apt-get install libdrm-dev libxshmfence-dev libxxf86vm-dev libunwind-dev
$ sudo apt-get install libwayland-dev wayland-protocols
$ sudo apt-get install libwayland-egl-backend-dev
$ sudo apt-get install valgrind libzstd-dev vulkan-tools
$ sudo apt-get install git build-essential bison flex ninja-build
$ sudo apt-get install python-mako vulkan-utilsor Bullseye
$ sudo apt-get install python3-mako
Raspberry Pi 4 + Ubuntu.
We received an email from Ben Ferguson. He installed the Vulkan SDK on a Raspberry Pi (400) running an Ubuntu operating system. In this case, some additional libraries are needed. We are happy to share this information with you.
# additional dependencies for Ubuntu OS
$ sudo apt-get install libxcb-glx0-dev libx11-xcb-dev libxcb-dri2-0-dev
$ sudo apt-get install libxcb-dri3-dev libxcb-present-dev
With the dependencies installed, the Vulkan API can be built.
If the installation was successful, the screen below shows all the relevant information after the $ glxinfo -B command.
If you get the error: ERROR_EXTENSION_NOT_PRESENT, you have most likely used the 32-bit installation on a 64-bit machine. Remove the whole mesa_vulkan directory and start cloning the GitHub repo again.
Time to do some testing with the famous Sascha Willems Vulkan demos.
As mentioned, the library is still under development, so not all examples work on the current version. But still, some very impressive pictures can still be drawn. Follow the commands below to install the demo.
# download the demos
$ git clone --recursive https://github.com/SaschaWillems/Vulkan.git sascha-willems$ cd sascha-willems
# download some fonts
$ python3 download_assets.py$ mkdir build# build the demos
$ cd build
$ cmake -DCMAKE_BUILD_TYPE=Debug ..
$ make -j4
Go into the build/bin folder with $ cd build/bin and run some examples like:
Deep learning with Vulkan.
We've done some disappointing tests with the Vulkan API used as a backend in various deep learning frameworks. Alibaba's MNN and Tencent's ncnn both use Vulkan as an accelerator for their tensor calculations. However, the current Vulkan API for the Raspberry Pi 4 isn't suited well for deep learning tasks. Neural networks love to use 16-bit floating points or 8-bit integers to speed up the calculations. Both are not well supported in the current release yet. No wonder considering the focus on 32 and 64-floating point math used to render graphics. In practice, the performance drops by a factor of four when using the Vulkan backend. See the benchmarks below.
All times in mSec
The Raspberry Pi 4 with 2 GByte RAM was running at a default clock speed of 1500 MHz.
MNN build with cmake -D CMAKE_BUILD_TYPE=Release -D MNN_VULKAN=ON -D MNN_BUILD_BENCHMARK=ON ..
ncnn build with cmake -D CMAKE_TOOLCHAIN_FILE=../toolchains/aarch64-linux-gnu.toolchain.cmake -D NCNN_VULKAN=ON -D CMAKE_BUILD_TYPE=Release ..