Skip to content

Running flutter pi with vulkan

Hannes Winkler edited this page Jul 22, 2022 · 6 revisions

Flutter-pi now supports vulkan for rendering. (As of today, that work is contained in the feature/compositor-ng branch)

Using vulkan for rendering has some benefits:

  • it cuts CPU usage roughly in half
  • app is smooth right from the beginning
  • theoretically, it enables more efficient usage of GPU resources by the renderer (flutter) so it should result in more/more stable FPS
  • but I'm not seeing that right now, maybe it's limited by skia
  • if skia is the cause, flutters new skia replacement, impeller might result in better performance, once it's stable

To use flutter-pi with vulkan rendering, you first need a vulkan graphics driver on your pi.

There's a vulkan driver bundled with raspbian bullseye, but it's a bit outdated and doesn't work with flutter-pi at all. Furthermore the development on the pis vulkan driver is pretty fast-paced, so it's probably better to go for a more recent driver version.

The way to do that is by compiling the graphics driver ourselves.

Compiling mesa

Build requirements

$ sudo apt install git python3 python3-pip ninja-build bison flex pkg-config
$ pip3 install mako

If you have meson installed using sudo apt install meson, you need to uninstall it and reinstall it using pip, because mesa requires a newer meson version than provided by raspbian.

$ sudo apt remove meson
$ pip3 install meson

Build

$ git clone --depth 1 https://gitlab.freedesktop.org/mesa/mesa.git
$ git clone --depth 1 https://gitlab.freedesktop.org/mesa/drm.git
$ meson setup --prefix ~/mesa-install -Dbuildtype=release -Dradeon=false -Damdgpu=false -Dnouveau=false -Dvmwgfx=false -Dfreedreno=false ./drm ./drm/build
$ ninja -C ./drm/build install
$ PKG_CONFIG_PATH=~/mesa-install/lib/arm-linux-gnueabihf/pkgconfig meson setup --prefix=~/mesa-install -Dbuildtype=release -Dgallium-drivers= -Dllvm=false -Dvulkan-drivers=broadcom -Dglx=disabled ./mesa ./mesa/build
$ ninja -C ./mesa/build install
$ VK_ICD_DRIVERS_PATH=~/mesa-install/share/vulkan.d/

Running flutter-pi using vulkan

Additional build dependencies

sudo apt install vulkan-headers libvulkan-dev

Build flutter-pi with vulkan enabled

$ git clone https://github.com/ardera/flutter-pi.git
$ cd flutter-pi
$ git checkout feature/compositor-ng
$ mkdir build
$ cd build
$ cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release -DENABLE_VULKAN=On
$ ninja

Run flutter-pi with vulkan enabled

$ VK_ICD_FILENAMES=~/mesa-install/share/vulkan/icd.d/broadcom_icd.armv7l.json ./flutter-pi/build/flutter-pi --vulkan /path/to/your/app
Clone this wiki locally