Skip to content

Experimental virtio-gpu display: msb display / msb run --display (macOS) - #1482

Draft
ya-luotao wants to merge 6 commits into
superradcompany:mainfrom
ya-luotao:gpu-m0
Draft

Experimental virtio-gpu display: msb display / msb run --display (macOS)#1482
ya-luotao wants to merge 6 commits into
superradcompany:mainfrom
ya-luotao:gpu-m0

Conversation

@ya-luotao

Copy link
Copy Markdown
Contributor

Draft: shows the whole path end to end, but it depends on three msb_krun changes that are not published yet (superradcompany/libkrun#116, #117, #118), vendored here under third_party/ with [patch.crates-io]. Once those land and 0.1.33 is out the third_party/ commit goes away. It also overlaps with #1194's --gpu plumbing: this branch gates the device with an MSB_GPU environment variable for now and should be rebased onto that option (SandboxRuntimeOptions.gpu) rather than keep its own switch.

What it does

msb run --display … (or msb display <sandbox> on a running one) opens the guest's virtio-gpu scanout in a native macOS window with keyboard and pointer. Demo: Omarchy (Hyprland + quickshell) on Arch Linux ARM in a microVM — https://github.com/ya-luotao/msb-omarchy.

How

  • Runtime (crates/runtime/lib/gpu_display/): a krun_display backend copies each presented frame into a 2-slot memory-mapped file per scanout under the sandbox runtime dir and announces configure / frame{slot,seq,rect} / disable as JSON lines on display.sock (next to agent.sock); the viewer's evdev-style input comes back on the same socket and is queued into two virtio-input devices (keyboard; absolute pointer shaped like QEMU's tablet). present_frame never waits for a viewer (200 ms write timeout, then the viewer is dropped), so a stalled window cannot stall the guest's FLUSH.
  • Viewer (crates/cli/lib/commands/display.rs, macOS-only deps winit + softbuffer): runs the event loop on the main thread before Tokio starts, like msb sandbox; BGRX frames are a straight copy into softbuffer's 0RGB buffer. The sandbox process cannot own the window because Vm::enter() takes its main thread.
  • MSB_GPU_DUMP=<dir> installs a frame-dump backend instead (debugging without a window); MSB_GPU_DISPLAY=WxH sizes the scanout (default 1920x1080).
  • Sandbox cleanup (ipc.rs) also removes display.sock.

Findings worth knowing

  • On macOS there is no virgl; the device must run on rutabaga's 2D component or every 2D command is rejected (libkrun#117).
  • msb_krun's input feature never delivered an event on macOS because of an eventfd flag bug (libkrun#116).
  • The guest must not set LIBGL_ALWAYS_SOFTWARE=1: aquamarine then finds no DRM EGL device. Mesa 26 falls back to llvmpipe on its own (kms_swrast for the compositor, swrast for clients).

Not done / open questions

  • Wiring via MSB_GPU env instead of Add --gpu: virtio-gpu Venus (Vulkan) device for sandboxes #1194's option; no Linux viewer (the runtime side is portable, the viewer is macOS-only by cfg).
  • HiDPI: the window is the scanout's physical size (960x540 points on Retina); no clipboard.
  • Tests: cargo test -p microsandbox-runtime passes; the display path itself has no unit tests yet.

🤖 Generated with Claude Code

https://claude.ai/code/session_01A2DMienRTQjgR5CF3uQ2AZ

ya-luotao and others added 6 commits August 30, 2026 20:09
…nout)

Enable msb_krun's gpu feature and attach a virtio-gpu device when MSB_GPU=1
(2D, VIRGL_RENDERER_NO_VIRGL) or MSB_GPU=venus (adds Venus). One scanout,
sized by MSB_GPU_DISPLAY (default 1920x1080), via a gpu_display builder
method that lives in a local msb_krun 0.1.32 patch (path override in the
workspace Cargo.toml) until it is upstreamed.

Verified on HVF/Apple Silicon: guest gets /dev/dri/card0 + renderD128,
KMS enabled, connector Virtual-1 with EDID; modetest -s sets 1920x1080.
Host-side 2D commands are rejected by virglrenderer without virgl, so
scanout content does not reach the host yet.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A2DMienRTQjgR5CF3uQ2AZ
Use the local msb_krun_devices patch that runs the virtio-gpu on rutabaga's
2D component when virgl is off, so guest scanouts reach the host on macOS.
MSB_GPU_DUMP=<dir> installs a display backend that keeps the latest frame of
each scanout in <dir>/scanout<N>.raw for verification without a window.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A2DMienRTQjgR5CF3uQ2AZ
The sandbox serves virtio-gpu scanout frames through a memory-mapped file
per scanout and a JSON-lines socket (display.sock next to agent.sock); the
new `msb display <sandbox>` command (macOS: winit + softbuffer, run on the
main thread before Tokio) maps the frames into a native window and sends
keyboard and absolute-pointer events back, which reach the guest as two
virtio-input devices. Sandbox cleanup now removes display.sock as well.

Needs the local msb_krun (input_device builder), msb_krun_devices (2D-only
gpu) and msb_krun_utils (macOS eventfd non-blocking flag) patches.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A2DMienRTQjgR5CF3uQ2AZ
@greptile-apps

greptile-apps Bot commented Aug 30, 2026

Copy link
Copy Markdown

Too many files changed for review (196 files, 100 file limit).

Bypass the limit by tagging @greptile-apps to review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant