How to use graphics in base: core22 snaps¶
This document describes how to use the graphics-core22 Snap interface, what are the requirements to create a content provider snap as well as discusses the design of the interface.
The basics¶
Snaps are software packages that are meant to bring all of their dependencies along. But to support graphical applications, userspace drivers matching the hardware used, and sometimes the kernel, are necessary. What’s more, those drivers on some systems are not available as open source, or even at all - outside of commercial engagements. This makes it impractical, or even impossible, to have application snaps ship drivers supporting the breadth of graphics hardware available.
The long-term solution is for SnapD (the daemon managing snaps on your system) to have explicit support for this, and other hardware-specific pieces of software (kernel modules, firmware, udev rules etc.). While this is being worked on, we’ve designed a content interface that allows application snaps to use the graphics hardware by providing the userspace drivers and environment in a content snap.
This interface is an evolution of How to use graphics in base: core20 snaps - if your application uses base: core20, you’ll need to rely on that, or move to the newer base.
Consuming the interface¶
This section explains how graphical application snaps can consume this interface to enable graphics acceleration. We maintain a set of helpers that are the easiest to use, but if you have specific reasons, we also detail how to consume the provided userspace in your application snap.
Using the helpers provided¶
The simplest way to enable your snap to consume the interface are the helpers we maintain in gpu-snap repository.
There’s just a few things you have to do in your snap/snapcraft.yaml to make use of it:
plug the
graphics-core22interface (the wrapper assumes it’s put under$SNAP/graphics):plugs: graphics-core22: interface: content target: $SNAP/graphics default-provider: mesa-core22
lay out these paths in your snap:
layout: /usr/share/libdrm: bind: $SNAP/graphics/libdrm /usr/share/drirc.d: symlink: $SNAP/graphics/drirc.d
If your app needs X11 support:
/usr/share/X11/XErrorDB: symlink: $SNAP/graphics/X11/XErrorDB /usr/share/X11/locale: symlink: $SNAP/graphics/X11/locale
use
bin/graphics-core22-wrapperin yourcommand-chains:apps: my-app: command-chain: - bin/graphics-core22-wrapper command: my-app
use
bin/graphics-core22-cleanupafter priming any staged packages to avoid shipping any libraries already provided by thegraphics-core22providers:parts: my-app: stage-packages: # ... graphics-core22: after: [my-app] source: https://github.com/canonical/gpu-snap.git plugin: dump override-prime: | craftctl default ${CRAFT_PART_SRC}/bin/graphics-core22-cleanup mesa-core22 nvidia-core22 prime: - bin/graphics-core22-wrapper
You can override
$CRAFT_PRIMEif you have Mesa primed in a different location:override-prime: | craftctl default CRAFT_PRIME=${CRAFT_PRIME}/custom/prefix \ ${CRAFT_PART_SRC}/bin/graphics-core22-cleanup mesa-core22 nvidia-core22
Your snap, when installed, will pull in the default mesa-core22 provider, which supports a wide range of hardware. It also supports Nvidia drivers installed with debs on your host system.
Migrating from graphics-core20¶
If your snap currently uses the graphics-core20 interface, here are the steps when you’re migrating to base: core22:
replace all references to
graphics-core20withgraphics-core22replace all references to
mesa-core20withmesa-core22remove all environment variables / paths pointing at
graphicspaths (the wrapper takes care of these):LD_LIBRARY_PATH LIBGL_DRIVERS_PATH LIBVA_DRIVERS_PATH __EGL_VENDOR_LIBRARY_DIRS
prepend
bin/graphics-core22-wrapperto your apps’command-chain:add the X11 layouts, if your app needs them
replace the
cleanuppart withgraphics-core22above
Going the manual route¶
If, for whatever reason, you don’t want to use the helpers, here is a description of the steps you should perform in your snap:
connect the
graphics-core22, see above.lay out the paths, see above.
wrap your apps with
<target>/bin/graphics-core22-provider-wrapper. This script, coming from the provider side, is what sets up all the environment - paths to the libraries, drivers and any supporting files.remove any libraries that are provided by the content providers (see below for a list). If you need to provide your own versions of any of those, you need to make sure they are ABI-compatible with Ubuntu 22.04.
Creating a provider snap¶
The requirements for a snap providing the content are purposefully quite simple:
include a
bin/graphics-core22-provider-wrapperthat sets up all the environment and executes the provided arguments, usually:#!/bin/sh export VAR=value exec "$@"
it should support (include, in Ubuntu 22.04 ABI-compatible versions, and ensure the application can find them) as many of the supported API libraries (and their dependencies) as possible/applicable
if your provider uses the Mesa stack:
provide the
drirc.dcontent source holding the app-specific workarounds
if your provider supports X11:
provide the
X11/localeandX11/XErrorDBcontent source with the appropriate assets
optionally, if there are Mir-specific workarounds required:
provide the
mir-quirkscontent source, with any options needed.
The rest is left to the author of the provider snap. The default provider - mesa-core22 - is a good reference.
Multi-architecture providers¶
In some cases, it may be desirable to include libraries for more than one architecture. The main use case would be supporting software for legacy architectures running on newer hardware that supports the legacy architecture (e.g. i386 on amd64, armhf on arm64). The default mesa-core22 implements that for the amd64 architecture.
The requirements remain as above - your wrapper needs to extend the environment for the additional architecture supported.
Testing your provider snap¶
The graphics-test-tools set of utilities will help you determine how well your provider works. Install and connect it to your provider and run to see what is supported and how well:
$ sudo snap install graphics-test-tools --channel 22/stable
graphics-test-tools (22/stable) 22.04 from Canonical✓ installed
$ sudo snap connect graphics-test-tools:graphics-core22 <your-snap>:graphics-core22
$ graphics-test-tools.drm-info
# ...
$ graphics-test-tools.eglinfo
# ...
Refer to the documentation of the individual tools to see what the results mean.
Lists¶
Supported APIs¶
graphics
GL (libGL.so.1)
EGL (libEGL.so.1)
GLES (libGLESv2.so.2)
DRM (libdrm.so.2)
Vulkan (libvulkan.so.1)
GBM (libgbm.so.1)
video acceleration
VA-API (libva.so.2)
libva-drm.so.2
libva-x11.so.2
libva-wayland.so.2
VDPAU (libvdpau.so.1)
X11 support
libglx0
libx11-6
libx11-xcb1
libxcb-dri2-0
libxcb-dri3-0
libxcb-glx0,
libxcb-present0
libxcb-shm0
libxcb-sync1
libxcb-xfixes0
libxcb1
libxext6
libxfixes3
libxshmfence1
libxxf86vm1
Wayland support
libwayland-client0
libwayland-server0
libwayland-egl1
libwayland-cursor0
Libraries shipped¶
The lists of files shipped by a selection of snaps is maintained in the graphics-core22 repository here:
https://github.com/canonical/gpu-snap/tree/main/lists
The cleanup wrapper above uses that to prune the application snap from things it will receive through the content interface.