Repository navigation
Description
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) failsvkCreateInstancewithERROR_OUT_OF_HOST_MEMORY(virtio_gpu0x208RESOURCE_MAP_BLOB→0x1200;krun_vmmMemoryMaperror) because Fedora's 4 KiB guest kernel allocates 4 KiB-aligned blob offsets that Apple Silicon's 16 KiBHypervisor.framework(hv_vm_map) rejects. - Installing Lima's documented
slp/mesa-libkrun-vulkanCOPR (25.3.6-102.fc44) resolves alignment and exposesVirtio-GPU Venus (Apple M5 Pro)(Vulkan 1.2.0,DRIVER_ID_MESA_VENUS) on/dev/dri/renderD128(0666).
- Stock Fedora 44
- Headless Chromium (
156.0.8078.79) WebGL2 & WebGPU: Every browser rendering path rejectsVirtio-GPU Venusor falls back to CPU rendering due to macOSMoltenVK/libkruncapability gaps:- ANGLE → Vulkan (
--use-gl=angle --use-angle=vulkan): Fails initialization (Extension not supported: VK_KHR_swapchain, even under--ozone-platform=headlessandMESA_VK_WSI_HEADLESS_SWAPCHAIN=1). Upstream Mesa Venus (vn_physical_device.c) only advertisesVK_KHR_swapchainwhenrenderer_sync_fd.semaphore_importableis true, and hostMoltenVKon macOS lacks LinuxSYNC_FD(VK_KHR_external_semaphore_fd). - ANGLE/EGL → Mesa Zink (
GALLIUM_DRIVER=zink): Fails withZink requires the nullDescriptor feature of KHR/EXT robustness2(unsupported byMoltenVKon Metal). - ANGLE/EGL → Virgl (
--use-angle=gl-egl):libkrunon macOS initializes Venus without a host Virgl OpenGL context (failed to create dri2 screen), falling back toMesa llvmpipe. - WebGPU (Dawn,
--enable-unsafe-webgpu --enable-features=Vulkan,WebGPU): Falls back togoogle / swiftshaderfor the same missing Vulkan WSI / external-fd extensions. - (Playwright note:
chromium.launch({ headless: true })appends--use-angle=swiftshader-webglafter callerargs, overriding--use-angleunlessheadless: falseis combined with'--headless=new'inargs.)
- ANGLE → Vulkan (
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 HTTP500from Chrome's DevTools DNS-rebinding check (Hostheader must belocalhostor an IP literal). Resolvinghost.lima.internalto its IP (192.168.5.2) and callingconnectOverCDP('http://192.168.5.2:<port>')succeeds; Lima'shostagentdynamically forwards guest0.0.0.0:<port>dev servers to Mac127.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). Theirbwrapsandbox 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-noneVM boundary, so adopting this path would require an explicit ADR and boundary controls.
- Sandboxed Trials, Model Graders, Code Graders, and Private Sessions: Blocked (
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:
- Current
bwraplaunch (--dev /dev):/dev/driis absent;vulkaninfofails (ERROR_INITIALIZATION_FAILED). --dev-bind-try /dev/dri /dev/drialone still fails (ERROR_INITIALIZATION_FAILED), becauselibdrm'sdrmGetDevices2()walks/sys/dev/charand/sys/devicesto enumerate DRM devices, and the Trial / Grader sandbox does not bind/sys.- Working
bwrapbind set: Adding--dev-bind-try /dev/dri /dev/dritogether with read-only binds of/sys/dev/charand/sys/devices(plus/dev/nvidia*device nodes on NVIDIA hosts) exposes the Vulkan GPU cleanly insidebwrap, 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:
- 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? - Linux / Cloud GPU sandboxes: Should Trial and Code Grader
bwrapsandboxes bind/dev/dri+ read-only/sys/dev/charand/sys/devices(and/dev/nvidia*when present) automatically whenever a GPU exists on the Linux host, or behind an explicit configuration / Experiment setting?
Activity