Files
looking-glass-2/host/platform/Windows/capture/DXGI/MULTIMONITOR.md
T
donny e425b15a87
build / client (Debug, map[cc:clang cxx:clang++], libdecor) (push) Failing after 19s
build / client (Debug, map[cc:clang cxx:clang++], xdg-shell) (push) Failing after 19s
build / client (Debug, map[cc:gcc cxx:g++], libdecor) (push) Failing after 19s
build / client (Debug, map[cc:gcc cxx:g++], xdg-shell) (push) Failing after 19s
build / client (Release, map[cc:clang cxx:clang++], libdecor) (push) Failing after 19s
build / client (Release, map[cc:clang cxx:clang++], xdg-shell) (push) Failing after 20s
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 19s
build / module (push) Failing after 16s
build / host-linux (push) Failing after 19s
build / host-windows-cross (push) Failing after 19s
build / docs (push) Failing after 3s
build / obs (clang) (push) Failing after 19s
build / obs (gcc) (push) Failing after 19s
build / host-windows-native (push) Canceled after 0s
build / idd (push) Canceled after 0s
doc: record DXGI multi-monitor support and its limits
Marks the DXGI path as implemented but unproven on hardware, documents
the fallback conditions, and notes that packing every display into one
frame means they share a frame rate.
2026-07-28 08:36:08 +00:00

4.6 KiB

Multi-monitor capture on DXGI

This backend duplicates every attached output on the chosen adapter and composes them into a single atlas frame. It is on by default and can be turned off with:

dxgi:multiMonitor=no

This code has never run on hardware. It cross compiles cleanly, which catches type and API errors, but acquire, release and timing behaviour can only be proven with a real multi-monitor Windows machine. Treat the first run as a bring-up exercise, and see "If it misbehaves" below.

How it works

dxgi_initMultiMonitor() runs once the primary duplication exists and the capture format is known, but before the copy backend is created, since it changes the frame dimensions to those of the atlas.

  1. Enumerates the adapter's attached outputs and duplicates each one. The primary keeps this->dup; the rest live in this->extraDup[].
  2. Builds an LGDisplayInfo per output from DesktopCoordinates, which is already in virtual desktop space, and packs them with lgDisplaysPack().
  3. Creates an atlas ID3D11Texture2D of the packed size and sets this->width / this->height to it.

Each capture composes into that atlas with CopySubresourceRegion and hands it to ppRun() in place of the acquired texture, so the post processors, the copy backend and everything past them are unaware of the difference. dxgi_waitFrame then reports the layout, with the virtual desktop as the screen size and the atlas as the frame.

Deliberate choices

Secondary outputs are polled, not waited on. Outputs present independently, so AcquireNextFrame is called with a zero timeout for each secondary; waiting on each in turn would drag the frame rate down to that of the slowest monitor. An output with nothing new keeps the pixels already in its atlas region, which is correct because it has not changed.

Frames are released late. Acquired frames are released at the start of the next capture, not after their copy. CopySubresourceRegion only records into the device context, and releasing a frame invalidates its surface. This mirrors what the primary output already did.

Anything unsafe falls back to a single output. That is not an error path, it is the design: a wrong atlas is worse than one working display. It happens when

  • capture formats differ between outputs, since a subresource copy cannot convert, which occurs when one monitor is HDR and another is not
  • any output is rotated, since the packer expects pixels in their final orientation
  • dxgi:output names a specific output
  • fewer than two outputs are attached

Known gaps

Damage is reported as full frame while composing. GetFrameDirtyRects returns rectangles for the primary alone, in its own coordinates, so they say nothing about the other displays. Reporting them unchanged would leave stale pixels on screen. Fixing this means collecting dirty rectangles per output, translating each into atlas space, and falling back to full damage when the combined count exceeds KVMFR_MAX_DAMAGE_RECTS. This is the single biggest performance win available here.

HDR metadata is per output. this->outputDesc, dxgiColorSpace and displayPathInfo describe the primary only, and the frame format carries one set of HDR static metadata. Mixed HDR and SDR monitors are refused rather than guessed at.

Rotation is refused rather than handled. KVMFRDisplay::rotation exists for it, but composition would have to rotate during the copy, which CopySubresourceRegion cannot do — it needs a shader pass.

If it misbehaves

Start with dxgi:multiMonitor=no to confirm the fault is in this path.

  • Only one display, and the log says so — read the reason it logged; it will name the precondition that failed.
  • One display is frozen while others update — a ReleaseFrame is being missed for that output, so its duplication stopped delivering. Look at extraNeedsRelease handling in dxgi_releaseFrame.
  • Torn or interleaved pixels — a copy is racing the release. Check that frames are still held until the next capture.
  • A display shows stale content — expected for a display that has not presented; suspicious if it never updates.

Testing

Cross compile from Linux to type check without a Windows machine:

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

host/tests/lg-verify-atlas.c subscribes to a running host as a client would and checks the published layout: every display 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 confirm this backend's output is well formed.