Add CLAUDE.md to hand this work over
build / client (Debug, map[cc:gcc cxx:g++], libdecor) (push) Failing after 19s
build / client (Debug, map[cc:clang cxx:clang++], libdecor) (push) Failing after 20s
build / client (Debug, map[cc:clang cxx:clang++], xdg-shell) (push) Failing after 20s
build / client (Debug, map[cc:gcc cxx:g++], xdg-shell) (push) Failing after 20s
build / client (Release, map[cc:clang cxx:clang++], xdg-shell) (push) Failing after 19s
build / client (Release, map[cc:clang cxx:clang++], libdecor) (push) Failing after 20s
build / module (push) Failing after 17s
build / client (Release, map[cc:gcc cxx:g++], libdecor) (push) Failing after 19s
build / client (Release, map[cc:gcc cxx:g++], xdg-shell) (push) Failing after 20s
build / host-linux (push) Failing after 25s
build / host-windows-cross (push) Failing after 28s
build / docs (push) Failing after 11s
build / obs (clang) (push) Failing after 46s
build / obs (gcc) (push) Failing after 28s
build / host-windows-native (push) Canceled after 0s
build / idd (push) Canceled after 0s
build / client (Debug, map[cc:gcc cxx:g++], libdecor) (push) Failing after 19s
build / client (Debug, map[cc:clang cxx:clang++], libdecor) (push) Failing after 20s
build / client (Debug, map[cc:clang cxx:clang++], xdg-shell) (push) Failing after 20s
build / client (Debug, map[cc:gcc cxx:g++], xdg-shell) (push) Failing after 20s
build / client (Release, map[cc:clang cxx:clang++], xdg-shell) (push) Failing after 19s
build / client (Release, map[cc:clang cxx:clang++], libdecor) (push) Failing after 20s
build / module (push) Failing after 17s
build / client (Release, map[cc:gcc cxx:g++], libdecor) (push) Failing after 19s
build / client (Release, map[cc:gcc cxx:g++], xdg-shell) (push) Failing after 20s
build / host-linux (push) Failing after 25s
build / host-windows-cross (push) Failing after 28s
build / docs (push) Failing after 11s
build / obs (clang) (push) Failing after 46s
build / obs (gcc) (push) Failing after 28s
build / host-windows-native (push) Canceled after 0s
build / idd (push) Canceled after 0s
Records what is proven versus unproven, how to rebuild and test from nothing, the DXGI bring-up procedure, the design decisions that should not be undone, and the gotchas that cost time to find the first time.
This commit is contained in:
1 parent
9331696db4
commit
57fae1bf31
1 file changed
+168
@@ -0,0 +1,168 @@
|
||||
# Looking Glass — multi-monitor fork
|
||||
|
||||
A fork of [LookingGlass](https://github.com/gnif/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
|
||||
|
||||
**The immediate task is bringing up DXGI multi-monitor capture on real
|
||||
hardware.** Everything else is implemented and tested. The DXGI path is
|
||||
written and cross-compiles, but has never run on a machine with more than one
|
||||
output attached.
|
||||
|
||||
Two things to establish from the user before assuming anything:
|
||||
|
||||
1. **How does the Windows guest get its displays?** Dummy plugs on the
|
||||
passed-through GPU, the Looking Glass IDD, or something else. This changes
|
||||
what the outputs look like to DXGI.
|
||||
2. **Where does the client run?** The guest is captured once and any number of
|
||||
clients can subscribe, so one client per physical monitor is viable.
|
||||
|
||||
## 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:
|
||||
|
||||
```bash
|
||||
./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):
|
||||
|
||||
```bash
|
||||
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
|
||||
|
||||
```bash
|
||||
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.
|
||||
|
||||
## 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.
|
||||
- **`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
|
||||
|
||||
- **DXGI multi-output is unproven on hardware.** The top priority.
|
||||
- **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.
|
||||
Reference in new issue
Block a user