GL, Vulkan and Video

Guest GL on the page's WebGL2, guest Vulkan on its WebGPU, and VA-API video on WebCodecs.

Note

All three are browser-only. Node has no WebGL, WebGPU or WebCodecs, so there gl, vk and va are ignored with a log line.

#GL

const vm = await createKernel({ distro: "/distros/debian.erofs", gl: true });
await vm.gl.ready; // the guest is linked; the renderer loads on its first GL use
await vm.exec("sudo", ["apt-get", "install", "-y", "mesa-utils", "libegl-mesa0", "libgles2"]);
const r = await vm.exec("sh", ["-c", "GALLIUM_DRIVER=virpipe LIBGL_ALWAYS_SOFTWARE=1 eglinfo -B -p surfaceless"]);

The guest's Mesa (Debian; its virpipe driver) renders through virglrenderer compiled to wasm on one WebGL2 context of the page, and gets its frames back by readback: GL 2.1 and GLES 3.0, surfaceless or under Xvfb.

virgl.wasm is fetched only with gl, and only on the guest's first GL use. vm.gl.status tells its state, vm.gl.load() starts it, and gl: { eager: true } loads it before the boot so that a failure shows up front.

#virtio-gpu

With gpu: true as well (and a kernel with kwvirtio), the guest gets a virtio-gpu device with 3D on the same renderer: stock Mesa finds /dev/dri/renderD128 and card0 (driver virtio_gpu) and renders through it with no variables set, and a KMS client's frames (kmscube, glmark2-es2-drm, a Wayland compositor) come from the renderer's texture:

const vm = await createKernel({ distro, gl: true, gpu: true, display: { width: 1280, height: 720 } });
// per animation frame: the scanout's latest frame, no readback (null: no GL client on it)
if (vm.gl.gpu.drawFrame(ctx) === null) {
  /* show vm.frame() instead */
}
// the window resized: a hotplug with a new preferred mode, which KMS clients may take
vm.updateDisplaySize({ width: 1600, height: 900 });

#Vulkan

const vm = await createKernel({ distro: "/distros/debian.erofs", vk: true });
await vm.exec("sudo", ["apt-get", "install", "-y", "libvulkan1", "vulkan-tools"]);
const r = await vm.exec("vulkaninfo", ["--summary"]); // deviceName = kwvk (WebGPU)

The base carries a Vulkan driver (an ICD the Vulkan loader finds by itself) that sends the guest's Vulkan calls to a renderer on the page's WebGPU device; SPIR-V shaders become WGSL through kwvk-naga.wasm. Nothing loads before the guest's first Vulkan program (vm.vk.status).

Vulkan 1.2 with Wayland, X11 and headless presentation (frames come back by readback); vkcube, vkmark, SDL's GPU API and GTK 4's Vulkan renderer run on it.

#Video (VA-API)

const vm = await createKernel({ distro: "/distros/debian.erofs", gl: true, gpu: true, va: true });
await vm.exec("sudo", ["apt-get", "install", "-y", "vainfo"]);
const r = await vm.exec("vainfo"); // the kwva driver and the profiles it decodes

The base carries a VA-API driver that Debian's libva loads for the virtio-gpu device with no variables set. It hands each compressed picture to a WebCodecs VideoDecoder on the page, so the guest's ffmpeg, mpv and Chromium decode video in the browser's decoder, in hardware where it has one. It decodes VP9 profile 0, H.264, AV1 Main and HEVC Main where WebCodecs does, and encodes VP9 where the page has a VideoEncoder for it (ffmpeg's vp9_vaapi).

Decoded pictures come back as NV12. With gl they can instead be exported as dmabufs that the host fills on the GPU, so mpv's --hwdec=vaapi with --vo=dmabuf-wayland shows video without a copy through the guest. libva needs the virtio-gpu device (gpu: true), and the driver is built for glibc, so it works on Debian. vm.va.status lists the profiles offered and whether WebCodecs decodes them in hardware. Nothing is asked of WebCodecs before the guest first opens the driver.