Files
looking-glass-2/CLAUDE.md
donnyandClaude Fable 5 6ac02cd6b0
build / client (Debug, map[cc:clang cxx:clang++], libdecor) (push) Failing after 24s
build / client (Debug, map[cc:clang cxx:clang++], xdg-shell) (push) Failing after 25s
build / client (Debug, map[cc:gcc cxx:g++], libdecor) (push) Failing after 25s
build / client (Release, map[cc:clang cxx:clang++], xdg-shell) (push) Failing after 21s
build / client (Release, map[cc:clang cxx:clang++], libdecor) (push) Failing after 21s
build / client (Debug, map[cc:gcc cxx:g++], xdg-shell) (push) Failing after 22s
build / module (push) Failing after 17s
build / client (Release, map[cc:gcc cxx:g++], libdecor) (push) Failing after 21s
build / client (Release, map[cc:gcc cxx:g++], xdg-shell) (push) Failing after 21s
build / host-linux (push) Failing after 25s
build / obs (clang) (push) Failing after 25s
build / host-windows-cross (push) Failing after 26s
build / docs (push) Failing after 4s
build / obs (gcc) (push) Failing after 26s
build / host-windows-native (push) Canceled after 0s
build / idd (push) Canceled after 0s
CLAUDE.md: record the hardware bring-up results and remaining gaps
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WxYTZ8oBdHX3YrHGgdLKwC
2026-08-20 16:55:22 -07:00

9.8 KiB

Looking Glass — multi-monitor fork

A fork of LookingGlass that carries a multi-monitor guest over a single session. The host packs every guest display into one frame (the atlas) and the client composes it back into the guest's desktop.

Work lives on branch multi-monitor. Remote is gitea (ssh://git@gitea.dev.blueoceanswim.com:2222/donny/looking-glass-2.git).

The SSH key used previously was generated on a live boot and no longer exists. If pushing fails with Permission denied (publickey), generate a key at ~/.ssh/id_ed25519_gitea (the path ~/.ssh/config expects, port 2222) and have the user add the public half in Gitea under Settings → SSH Keys. Ask before creating credentials.


Start here

DXGI multi-monitor capture was brought up on real hardware on 2026-08-20 and works end to end — two 2560x1440 VDD displays on a passed-through RTX 3090, packed into a 2560x2880 atlas, composed and cropped per display by the client. Three client bugs found during bring-up are fixed on this branch (see the two egl: commits). The host must currently run with dxgi:allowRGB24=no — see Known gaps.

Environment answers (were open questions):

  1. The guest gets its displays from a VDD (virtual display driver) on the passed-through GPU; the monitor count lives in the VDD's settings. The VM's emulated VGA <video> device adds a ghost 800x600 display that skews the desktop's input mapping — disconnect it in Windows display settings or set <model type='none'/>.
  2. One client per guest display works: app:display=0 and app:display=1 spice:enable=no (indices 0-based; only one client may keep SPICE or the server kicks the other).

Environment setup

The environment may be ephemeral — earlier work was done from a live USB boot where nothing survives a reboot. If the build tools are missing:

./scripts/setup-dev.sh          # everything, incl. tests and cross compiler
./scripts/setup-dev.sh --minimal # just the client and Linux host

Builds (each is an out-of-tree directory; in-source builds are refused):

mkdir -p client/build && cd client/build && cmake .. && make -j$(nproc)
mkdir -p host/build   && cd host/build   && cmake .. && make -j$(nproc)

# Windows host, cross compiled from Linux — type checks DXGI without Windows
mkdir -p host/build-win && cd host/build-win
cmake -DCMAKE_TOOLCHAIN_FILE=../toolchain-mingw64.cmake .. && make -j$(nproc)

Testing

host/tests/run-tests.sh      # unit tests, live capture, client render test
host/tests/demo-multimon.sh ./host/build/looking-glass-host \
    ./client/build/looking-glass-client   # visible end to end demo, writes a PNG

host/tests/lg-verify-atlas.c subscribes to a running host as a client would and checks the published layout — displays inside the frame, no overlaps, packed without scaling. It is backend agnostic, so pointing it at a Windows host over the same shared memory is the fastest way to validate DXGI output.

Bringing up DXGI

  1. Build host/build-win/looking-glass-host.exe, copy it into the guest, run it.
  2. Look for this in the host log:
    Multi-monitor     : 3 outputs, desktop 5120x1440, atlas 2560x2880
      \\.\DISPLAY1  2560x1440 desktop +0+0 -> atlas +0+0 (primary)
    
    If it is absent, the backend fell back to a single output and logged the reason — read it. Fallback is deliberate, not a bug.
  3. Start the client and look for Composing N displays from a WxH atlas.
  4. Run lg-verify-atlas against the same shared memory to check the layout independently of what it looks like on screen.

If anything misbehaves, first set dxgi:multiMonitor=no to confirm the fault is in this path. host/platform/Windows/capture/DXGI/MULTIMONITOR.md has a symptom-to-cause table (frozen display, torn pixels, stale content).

Size IVSHMEM generously: the atlas holds every display. Roughly total pixels x 4 x 2, rounded up to a power of two. The host logs the atlas size at startup.

Architecture

Deliberate decisions — understand before changing:

  • displayCount == 0 means a conventional single-display frame. All the old behaviour is preserved on that path. Backward compatibility with single-display guests is not optional.
  • The client composes as its own pass (client/renderers/EGL/compose.c), before post processing. Everything downstream — scaling, HDR, cursor, damage, input mapping — then works on one ordinary frame and needs no multi-display awareness.
  • Anything unsafe falls back to single-display capture. Mixed capture formats, rotated outputs, a specific output requested. A wrong atlas is worse than one working display. Always log why.
  • Packing is shared (common/src/displays.c) so backends do not each invent one. lgDisplaysPack picks a minimum-area layout; lgDisplaysRepack does CPU copies; lgDisplaysRectToAtlas translates damage. All unit tested — extend the tests when changing them.
  • Every display's atlas offset is aligned for direct scanout (LG_DISPLAY_ALIGN_PIXELS). This exists so a consumer can point display hardware straight at one display's region of the frame instead of copying it. Do not drop it to save a few pixels of padding; a unit test enforces it.

Downstream consumer

The user is building a custom Wayland compositor (Smithay) that consumes this frame directly — importing the shared memory as a dmabuf and page-flipping each display's region independently, so guest pixels never pass through an extra copy. That is why the alignment guarantee and the damage-in-atlas-space semantics matter beyond the Looking Glass client itself.

The contract that consumer relies on is written up under "Consuming frames directly" in doc/multimonitor.rst — layout, alignment, frame lifetime (two-deep queue, one second subscriber timeout) and damage. Treat it as an interface: changing it breaks a separate codebase.

Gotchas

Things learned the hard way; re-learning them costs hours.

  • compose.vert must not flip Y. It renders into a framebuffer that the desktop shader samples, and that shader treats row 0 as the top. Flipping produced an upside-down desktop that passed every geometry check. The rendering test exists to catch exactly this — each test display carries a marker in its top-left corner.
  • GL container objects are per context. onFrameFormat runs on the frame thread with its own shared context; VAOs and FBOs created there do not exist in the render thread's context and the draw silently renders nothing. Defer such setup to the render thread (see composeSetupPending). Textures, buffers and programs are shared and safe.
  • The host writes its log next to the exe (and prints nothing to the console on Windows); os:logFile= redirects it. Writing it onto the virtiofs share lets the Linux side read it live.
  • framebuffer_write needs a 32-byte aligned source. It uses aligned streaming loads. malloc only guarantees 16 and will segfault; use aligned_alloc. Real capture buffers are page aligned, so only test code hits this.
  • Damage scaling comes after atlas placement, never before. The downscale factor applies to the frame as a whole.
  • Under a Wayland session the XWayland root window is blank, so XCB capture of :0/:1 yields black. This is environmental, not a bug. Use demo-multimon.sh, which runs its own X server with real content.
  • Xvfb and Xephyr accept xrandr --setmonitor and silently ignore it. Use xcb:monitors=1280x800+0+0,1280x800+1280+0 to describe a layout directly.

Pre-existing upstream bugs fixed here

These are unrelated to multi-monitor but were blocking. Do not "clean them up" as unrelated changes:

  • captureStop() never called the capture interface's stop(), so backend threads were not joined before teardown — segfault.
  • The XCB pointer thread ran before the host had allocated pointer buffers.
  • XCB wrote one row per frame instead of the whole image (pitch vs pitch * height).

Known gaps

  • RGB24 frames cannot be composed. dxgi:allowRGB24 defaults to on and packs SDR frames as BGR_32, which egl_composeSetup refuses, so the client silently falls back to showing the packed atlas. Until compose learns the format, either the host should force RGB24 off while multi-monitor capture is active, or the user must pass dxgi:allowRGB24=no. The next session should fix the host side.
  • The cursor-view scaling fix is lightly tested. It follows the same view-not-desktop rule as input mapping, but user verification stopped before it was confirmed on both displays.
  • HDR metadata is per output, but the frame format carries one set. Mixed HDR and SDR monitors are refused rather than guessed at.
  • Rotation is refused, not handled. KVMFRDisplay::rotation exists for it, but composition would have to rotate during the copy, which CopySubresourceRegion cannot do — it needs a shader pass.
  • The client redraws the whole composed view each frame. Damage governs the transfer, which is the expensive part; per-region redraw after composition is a smaller, GPU-side win.
  • All displays share one frame rate, inherent to packing them into one frame. Monitors of differing refresh rates cannot update independently.

Docs

  • doc/multimonitor.rst — user facing: configuration, shared memory sizing, running one client per guest display, limitations.
  • host/platform/Windows/capture/DXGI/MULTIMONITOR.md — DXGI internals, design decisions and the bring-up troubleshooting table.

Conventions

Match the upstream style: two-space indent, brace on its own line, this as the module state pointer, DEBUG_* macros for logging. Builds use -Wall -Werror, so warnings break the build. Comments should explain why, not restate the code — upstream is sparse and consistent about this.