Files
looking-glass-2/host/platform/Windows/capture/DXGI/MULTIMONITOR.md
T
donny 456462f8fb
build / client (Debug, map[cc:clang cxx:clang++], xdg-shell) (push) Failing after 20s
build / client (Debug, map[cc:clang cxx:clang++], libdecor) (push) Failing after 20s
build / client (Debug, map[cc:gcc cxx:g++], libdecor) (push) Failing after 22s
build / client (Release, map[cc:clang cxx:clang++], libdecor) (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 20s
build / module (push) Failing after 16s
build / client (Release, map[cc:gcc cxx:g++], libdecor) (push) Failing after 20s
build / client (Release, map[cc:gcc cxx:g++], xdg-shell) (push) Failing after 21s
build / host-linux (push) Failing after 19s
build / host-windows-cross (push) Failing after 19s
build / obs (clang) (push) Failing after 19s
build / docs (push) Failing after 3s
build / obs (gcc) (push) Failing after 20s
build / host-windows-native (push) Canceled after 0s
build / idd (push) Canceled after 0s
dxgi: document what multi-monitor capture requires on Windows
The frame format, packer and client compositor are backend agnostic and
already work; this backend still reports a single display. Records the
shape of the change and the hazards found reading it: mixed formats,
per-output HDR and rotation, frame timing, release discipline and COM
lifetime.
2026-07-28 07:37:37 +00:00

5.2 KiB

Multi-monitor capture on DXGI

The multi-monitor frame format, the atlas packer and the client side compositor are all implemented and in use by the Linux XCB backend. This backend does not yet produce multi-display frames: it reports displayCount = 0, so the host publishes a conventional single display frame and everything behaves as it always has.

This note records what adding it involves, and the specific hazards found while reading this backend, so the work does not have to start from scratch.

What already exists

Nothing in the frame format or the client needs changing. A backend opts in purely by filling in three things on CaptureFrame in its waitFrame:

  • displayCount — how many displays are packed
  • displays[] — the layout, produced by lgDisplaysPack()
  • screenWidth / screenHeight — the guest's virtual desktop size, while frameWidth / frameHeight stay the size of the packed frame

lgDisplaysPack() (in common/src/displays.c) takes the displays and their virtual desktop positions and chooses a layout that minimises the packed area. lgDisplaysRepack() alongside it does the CPU copy, but a D3D backend should composite on the GPU instead — see below.

Shape of the change

  1. Enumerate every attached output, not just the first match. The current loop in dxgi_init breaks out of IDXGIAdapter1_EnumOutputs as soon as it finds an output with AttachedToDesktop. Collect them all instead, and build an LGDisplayInfo per output from DXGI_OUTPUT_DESC::DesktopCoordinates, which is already in virtual desktop space.

  2. Duplicate each output. IDXGIOutput5_DuplicateOutput1 is per output, so this becomes an array of IDXGIOutputDuplication. Note the existing retry loop that treats E_ACCESSDENIED as "keep trying" — each output needs the same treatment, and a secure desktop transition invalidates all of them at once.

  3. Composite into an atlas texture. Create one ID3D11Texture2D of the packed size and, for each output that produced a frame, ID3D11DeviceContext_CopySubresourceRegion its texture into its atlas rectangle. Pass that atlas texture to ppRun() in place of *src. The post processors and the copy backend then see a single larger texture and need no changes.

  4. Report the layout from dxgi_waitFrame.

Hazards

These are the parts that make it more than a mechanical change.

Mixed formats. Each output negotiates its own format, and CopySubresourceRegion cannot convert. An HDR monitor duplicating as R16G16B16A16_FLOAT next to an SDR one as B8G8R8A8_UNORM cannot be copied into a shared atlas directly. Either promote everything to FP16 with a shader pass, or refuse multi-monitor when formats differ and fall back to a single output. The latter is a reasonable first version, but detect it explicitly rather than producing a corrupt atlas.

HDR metadata is per output. this->outputDesc, dxgiColorSpace and displayPathInfo all describe one monitor, and the frame carries a single set of HDR static metadata. With mixed monitors there is no single correct answer; the frame format has no per-display HDR metadata today.

Rotation is per output. DXGI_MODE_ROTATION differs per output, while the frame carries one rotation. KVMFRDisplay::rotation exists for this, but the packer assumes pixels are already in their final orientation, so a rotated output must be rotated during composition.

Frame timing. Outputs present independently. AcquireNextFrame blocks per duplication, so the current 1000ms wait cannot simply be repeated for each output or the frame rate collapses to the slowest monitor. Wait on the primary and poll the others with a zero timeout, reusing the previous contents for any output with nothing new.

Release discipline. Every successful AcquireNextFrame needs a matching ReleaseFrame. dxgi_releaseFrame() currently tracks one needsRelease flag; this has to become per output, and the error paths must release everything already acquired or the duplication deadlocks.

COM lifetime. This file manages COM references through the comRef helpers (comRef_defineLocal, comRef_toGlobal, comRef_scopePush). Arrays of interfaces must be registered the same way or they leak on reinitialisation, which happens on every resolution change and desktop switch.

Damage rectangles. GetFrameDirtyRects returns rectangles in each output's own coordinates. They must be translated into atlas space, and the combined count can exceed KVMFR_MAX_DAMAGE_RECTS, in which case fall back to full frame damage.

Testing

The Windows host cross-compiles from Linux, which catches type and API errors without a Windows machine:

cd host && mkdir build-win && cd build-win
cmake -DCMAKE_TOOLCHAIN_FILE=../toolchain-mingw64.cmake ..
make

Compiling is not evidence that duplication, timing and release discipline are right; those need real hardware with more than one monitor attached.

host/tests/lg-verify-atlas.c subscribes to a running host as a client would and checks the published layout for consistency — displays inside the frame, no overlaps, packed without scaling — and dumps each display to a PPM. It is backend agnostic and is the fastest way to confirm a new backend's output.