Skip to content

GPU WebGL/WebGPU rendering options for Linux VMs and bwrap sandboxes #2173

Open

Description

@JacobStephens2

This was generated by AI during triage.

Summary

Following #1665 (ADR 0003 amendment specializing thirdshift on Linux and running Apple Silicon workloads inside Linux VMs), we benchmarked and root-caused the options for hardware-accelerated browser WebGL2 / WebGPU rendering (e.g., Three.js workloads) across local Apple Silicon Lima VMs and Linux bwrap sandboxes on 2026-11-13 (macOS Tahoe, Apple M5 Pro, Lima 2.2.1).

Empirical Findings

1. Option 2: Lima krunkit VM (Virtio-GPU Venus on macOS) — Vulkan compute works, Chromium WebGL2/WebGPU does not

Tested in an isolated Fedora 44 aarch64 VM (--vm-type=krunkit, krunkit 1.3.2, libkrun 1.19.8, molten-vk 1.4.2, 6 vCPUs, 12 GiB RAM, --mount-none):

  • Vulkan compute (vulkaninfo):
    • Stock Fedora 44 mesa-vulkan-drivers (26.2.6) fails vkCreateInstance with ERROR_OUT_OF_HOST_MEMORY (virtio_gpu 0x208 RESOURCE_MAP_BLOB → 0x1200; krun_vmm MemoryMap error) because Fedora's 4 KiB guest kernel allocates 4 KiB-aligned blob offsets that Apple Silicon's 16 KiB Hypervisor.framework (hv_vm_map) rejects.
    • Installing Lima's documented slp/mesa-libkrun-vulkan COPR (25.3.6-102.fc44) resolves alignment and exposes Virtio-GPU Venus (Apple M5 Pro) (Vulkan 1.2.0, DRIVER_ID_MESA_VENUS) on /dev/dri/renderD128 (0666).
  • Headless Chromium (156.0.8078.79) WebGL2 & WebGPU: Every browser rendering path rejects Virtio-GPU Venus or falls back to CPU rendering due to macOS MoltenVK / libkrun capability gaps:
    • ANGLE → Vulkan (--use-gl=angle --use-angle=vulkan): Fails initialization (Extension not supported: VK_KHR_swapchain, even under --ozone-platform=headless and MESA_VK_WSI_HEADLESS_SWAPCHAIN=1). Upstream Mesa Venus (vn_physical_device.c) only advertises VK_KHR_swapchain when renderer_sync_fd.semaphore_importable is true, and host MoltenVK on macOS lacks Linux SYNC_FD (VK_KHR_external_semaphore_fd).
    • ANGLE/EGL → Mesa Zink (GALLIUM_DRIVER=zink): Fails with Zink requires the nullDescriptor feature of KHR/EXT robustness2 (unsupported by MoltenVK on Metal).
    • ANGLE/EGL → Virgl (--use-angle=gl-egl): libkrun on macOS initializes Venus without a host Virgl OpenGL context (failed to create dri2 screen), falling back to Mesa llvmpipe.
    • WebGPU (Dawn, --enable-unsafe-webgpu --enable-features=Vulkan,WebGPU): Falls back to google / swiftshader for the same missing Vulkan WSI / external-fd extensions.
    • (Playwright note: chromium.launch({ headless: true }) appends --use-angle=swiftshader-webgl after caller args, overriding --use-angle unless headless: false is combined with '--headless=new' in args.)

2. Option 1: Host headless Chrome on macOS over CDP — 65×–153× faster, crosses VM isolation boundary

Tested a dedicated headless Chrome (--headless=new --remote-debugging-address=127.0.0.1) on the Mac connected from Playwright inside the Lima guest:

  • Connection details: Connecting to http://host.lima.internal:<port> by hostname returns HTTP 500 from Chrome's DevTools DNS-rebinding check (Host header must be localhost or an IP literal). Resolving host.lima.internal to its IP (192.168.5.2) and calling connectOverCDP('http://192.168.5.2:<port>') succeeds; Lima's hostagent dynamically forwards guest 0.0.0.0:<port> dev servers to Mac 127.0.0.1:<port>.
  • Renderer: ANGLE (Apple, ANGLE Metal Renderer: Apple M5 Pro).
  • Isolation trade-off:
    • Sandboxed Trials, Model Graders, Code Graders, and Private Sessions: Blocked (ENETUNREACH). Their bwrap sandbox uses --unshare-net, and the allowlisting CONNECT proxy permits only Harness provider hosts while refusing loopback and host addresses.
    • Ordinary Runs (ADR 0013): Run unsandboxed inside the Linux VM and can reach 192.168.5.2:<port>. Exposing a host Chrome CDP port lets guest Runs drive a browser running as the macOS host user outside the --mount-none VM boundary, so adopting this path would require an explicit ADR and boundary controls.

3. Three.js WebGL2 Benchmark Comparison (Apple M5 Pro)

Synchronized per-frame timings (renderer.render + gl.readPixels fence) and PNG page.screenshot() timings across two Three.js scenes (ACESFilmicToneMapping, PCFSoftShadowMap, PBR InstancedMesh, alpha-blended cones):

Environment & Renderer Maquette (1280×720, ~38k tris, 1024² shadow) 720p Screenshot Heavy (1920×1080, ~581k tris, 2048² shadow) 1080p Screenshot
Option 1: Mac Chrome over CDP (ANGLE Metal: Apple M5 Pro) 1.31 ms/frame (763.4 fps, p50 1.2 ms) 78.0 ms 3.67 ms/frame (272.2 fps, p50 3.7 ms) 373.7 ms
Linux VM: SwiftShader (6 M5 Pro vCPUs) 84.62 ms/frame (11.8 fps, p50 87.6 ms) 62.0 ms 562.05 ms/frame (1.8 fps, p50 525.9 ms) 262.7 ms
Linux VM: Mesa llvmpipe (LLVM 22.1, 6 M5 Pro vCPUs) 87.95 ms/frame (11.4 fps, p50 84.0 ms) 92.0 ms 587.77 ms/frame (1.7 fps, p50 571.6 ms) 302.0 ms

Sampled RGBA pixels matched within ±1/255 across all three renderers (gl.getError() === 0). For functional and visual Playwright assertions on moderate 3D scenes, software rendering (~85 ms/frame) inside a standard Linux VM is already fast and deterministic; hardware GPU rendering is only needed for high-frame-rate capture or heavy shader/shadow workloads.

4. bwrap Sandbox GPU Passthrough Requirements (for Linux / Cloud GPU Hosts)

On a native Linux GPU host (e.g., a DigitalOcean NVIDIA GPU Droplet, where native Vulkan exposes VK_KHR_swapchain and SYNC_FD with no MoltenVK/Venus translation), ordinary Runs already see /dev/dri under ADR 0013, whereas bwrap-sandboxed Trials, Model Graders, and Code Graders hide host devices behind --dev /dev.

Testing thirdshift's bwrap launch flags against /dev/dri/renderD128 showed a critical detail:

  1. Current bwrap launch (--dev /dev): /dev/dri is absent; vulkaninfo fails (ERROR_INITIALIZATION_FAILED).
  2. --dev-bind-try /dev/dri /dev/dri alone still fails (ERROR_INITIALIZATION_FAILED), because libdrm's drmGetDevices2() walks /sys/dev/char and /sys/devices to enumerate DRM devices, and the Trial / Grader sandbox does not bind /sys.
  3. Working bwrap bind set: Adding --dev-bind-try /dev/dri /dev/dri together with read-only binds of /sys/dev/char and /sys/devices (plus /dev/nvidia* device nodes on NVIDIA hosts) exposes the Vulkan GPU cleanly inside bwrap, including under --unshare-user --cap-drop ALL.

(Also verified on Fedora 44 krunkit: both unprivileged bwrap namespaces and systemd-run --user --scope --property=MemoryMax=2G pass out of the box without AppArmor profile overrides.)

Why ready-for-human — Decisions Needed

Before turning any part of this into ready-for-agent implementation work:

  1. Local macOS VMs: Keep using software WebGL (SwiftShader) inside Lima VMs for ordinary 3D Playwright checks (recommended default — zero sandbox holes), or explore an ADR for opt-in host-CDP browser access?
  2. Linux / Cloud GPU sandboxes: Should Trial and Code Grader bwrap sandboxes bind /dev/dri + read-only /sys/dev/char and /sys/devices (and /dev/nvidia* when present) automatically whenever a GPU exists on the Linux host, or behind an explicit configuration / Experiment setting?

Activity

  1. added
    enhancement
    ready-for-human
    on Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementready-for-human

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions