Skip to content

Running flutter pi with vulkan

Hannes Winkler edited this page Apr 7, 2023 · 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=disabled -Damdgpu=disabled -Dnouveau=disabled -Dvmwgfx=disabled -Dfreedreno=disabled -Detnaviv=disabled -Dc_args="-march=native -mcpu=native -mtune=native" ./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=disabled -Dvulkan-drivers=broadcom -Dglx=disabled -Dplatforms= -Dc_args="-march=native -mcpu=native -mtune=native" ./mesa ./mesa/build
$ ninja -C ./mesa/build install

Running flutter-pi using vulkan

Additional build dependencies

sudo apt install 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 -DVULKAN_DEBUG=OFF
$ ninja

The VULKAN_DEBUG option must be off because the vulkan validation layers that come with Raspbian are broken (at least with the latest mesa that's being used here), and enabling them will result in a segfault at some point. There's of course a way to build the latest validation layers yourself and use those.

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