
# GL and Vulkan

> Guest GL on the page's WebGL2 and guest Vulkan on its WebGPU.

::note
Both are browser-only. Node has no WebGL or WebGPU, so there `gl` and `vk` are ignored with a log line.
::

## GL

```js
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:

```js
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

```js
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.
