docs: display v2 design + plan (pluggable scanout backend)

Keep the GOP framebuffer as the floor, make scanout a pluggable backend, and
upgrade to a native virtio-gpu driver when it announces itself (dynamic
hot-attach; GOP stays the fallback for "no driver ever"). v2 builds the shm
cross-process memory capability, shared with the future client-surface path.
Milestones V1 (backend seam) → V6 (resilience + tests), each with a gate.
This commit is contained in:
Daniel Samson
2026-07-14 09:28:31 +01:00
parent a01a4f3b3d
commit 2723b6f778
3 changed files with 252 additions and 1 deletions
+123
View File
@@ -0,0 +1,123 @@
# Display v2 — build plan (pluggable scanout: GOP floor + virtio-gpu native)
The ordered, checkpointable build-out for [display-v2.md](display-v2.md). Each milestone
lands on its own and ends in a **verifiable gate** — shaped for a `/loop` run, like
[display-plan.md](display-plan.md). Read display-v2.md first for the *why*.
## Locked decisions (do not relitigate)
- **First native backend = virtio-gpu** (VM standard: mode-set + present/flush + vsync).
- **Dynamic hot-attach**: boot on GOP, upgrade to native when the driver **announces**
(push, not polling); re-attach across driver restarts; GOP is the floor for "no driver
ever," not a live fall-back after a reprogram.
- **v2 builds the `shm` capability** (endpoints → memory objects), shared with the future
client-surface path.
- The compositor's layers/back-buffer/damage are **unchanged**; only scanout is pluggable.
## Conventions
Follow [coding-standards.md](coding-standards.md): spell out non-acronym abbreviations,
kebab-case file names, no `Co-Authored-By` trailers. New user binaries go through
`addUserBinary` and get packed into the initial-ramdisk; protocols are
`b.addModule("…-protocol", …)` imported into `runtime`; new syscalls extend
[abi.zig](../system/abi.zig) `SystemCall` + a `library/runtime` wrapper.
## How to verify along the way
- `zig build test` — host unit tests (backend selection logic, virtio structs/encodings).
- `python3 test/qemu_test.py <case>` — boots the kernel in QEMU; assert on serial markers.
The virtio path boots with `-device virtio-gpu` (a new per-case `qemu_extra`).
- The `run-x86-64` target renders to a window for visual confirmation.
---
## V1 — The scanout backend seam (refactor, no behaviour change)
Extract scanout from the compositor so today's path becomes one backend among future ones.
- [ ] A `Backend` interface in `system/services/display/`: `surface() -> {ptr, pitch,
format, width, height}`, `present(damage: Rect)`, and capability flags
(`canModeSet`, `hasVsync`, both false for now).
- [ ] Wrap the v1 GOP path as `GopBackend` (claim the `display` node, WC-map the LFB,
`present` = the current damage-rect WC copy). The compositor composes into
`backend.surface()` and calls `backend.present(damage)` — no direct LFB references
left in the compositor core.
- [ ] Pure backend-selection logic factored so it's host-testable.
**Gate:** `display-service` + `display-demo` still pass unchanged (pure refactor; GOP is
the only backend), and `zig build test` stays green.
## V2 — The `shm` cross-process memory capability (kernel)
- [ ] [abi.zig](../system/abi.zig): `shm_create`, `shm_map` syscalls (+ a `ServiceId`/cap
convention if needed). Kernel handlers: `shm_create(len)` allocates page-aligned RAM,
returns a handle + maps it; passing the handle as an `ipc_call` `send_cap` shares it;
`shm_map(cap)` maps the same physical pages into the receiver. Reclaimed on death.
- [ ] `library/runtime/shm.zig` (+ barrel export): `create(len) -> Region{handle, ptr}`,
`map(cap) -> ptr`.
- [ ] Reuse the M13 capability-passing machinery (endpoints → memory objects).
**Gate:** a kernel/qemu `shm` test — process A `shm_create`s a region, writes a pattern,
passes the cap to process B, which `shm_map`s it and reads the same bytes back (proving
shared physical pages, not a copy). Heartbeat `shm: shared N bytes ok`.
## V3 — The virtio-gpu driver: bring-up + a frame on screen
- [ ] `system/drivers/virtio-gpu/`: claim the virtio-gpu PCI function (device-manager
match on its PCI/virtio id), map BARs, negotiate features, set up the control
virtqueue. `virtio-gpu-protocol.zig` for the control structs (host-tested sizes).
- [ ] Create a 2D scanout resource backed by an `shm` region, `attach_backing`,
`set_scanout` to CRTC 0, and `resource_flush` a test pattern.
- [ ] Register a `scanout` service (new `ServiceId`).
**Gate:** QEMU `-device virtio-gpu`: the driver comes up and logs
`virtio-gpu: scanout {w}x{h} online`, and a flushed test pattern is visible (screenshot)
— proving virtqueue + resource + set_scanout + flush end to end.
## V4 — The native backend + hot-attach
- [ ] `VirtioGpuBackend` in the compositor: `surface()` = the shared scanout resource,
`present(damage)` = `resource_flush` of the damaged rect.
- [ ] The driver **announces** to `.display` (looks it up, sends *attach-scanout* with its
`scanout` endpoint + the shared surface as capabilities). The compositor switches
backends and re-presents the current frame full-screen.
- [ ] Boot still starts on `GopBackend`; the upgrade happens on announce.
**Gate:** boot with virtio-gpu + `display-demo`; the compositor logs
`display: scanout upgraded to virtio-gpu`, and the demo animates through the native
backend (serial heartbeat + screenshot). Without `-device virtio-gpu`, it stays on GOP
(the v1 gates still pass).
## V5 — Mode-setting, EDID, and vsync
- [ ] virtio-gpu `GET_EDID` → a mode list; `set_scanout` at a chosen mode = runtime
resolution change. `runtime.display` gains `modes()` / `setMode(m)`.
- [ ] A vsync/fenced `resource_flush` present path → genuinely tear-free.
- [ ] The compositor reports the native backend's `canModeSet`/`hasVsync` = true.
**Gate:** a `display-modeset` case changes resolution at runtime and confirms the new mode
(`display: mode set to {w}x{h}`); a vsync present path is exercised without tearing
artifacts in the frame counter/log.
## V6 — Resilience (restart + re-attach) + tests + docs
- [ ] The virtio-gpu driver is supervised (device-manager / init) and restartable; on
driver loss the compositor freezes the last frame and **re-attaches** when the driver
re-announces. Only a permanent give-up (crash-loop cap) attempts GOP again.
- [ ] `test/qemu_test.py` cases: `virtio-gpu`, hot-attach, `display-modeset`, and a
driver-kill/re-attach case. Update [display-v2.md](display-v2.md) status; README index.
**Gate:** kill the virtio-gpu driver mid-run; the compositor survives and re-attaches on
restart (`display: scanout re-attached`); all v1 + v2 cases pass; default `zig build` clean.
---
## Deferred (explicitly not in this plan)
- **Client-rendered surfaces** — now unblocked by the `shm` capability (V2): an app renders
its own bitmap and hands the compositor a reference. A natural follow-on.
- **Bochs DISPI backend** — a simpler second native backend (mode-set only, dumb scanout);
slots behind the same interface if wanted.
- **Real-GPU (NVIDIA/AMD/Intel) drivers** — out of scope; those devices stay on the GOP
floor by design.
- **Hardware-accelerated compositing / multiple heads** — future.