Files
looking-glass-2/doc/multimonitor.rst
donny 5e2fd18b5c
build / client (Debug, map[cc:clang cxx:clang++], libdecor) (push) Failing after 22s
build / client (Debug, map[cc:gcc cxx:g++], libdecor) (push) Failing after 21s
build / client (Debug, map[cc:clang cxx:clang++], xdg-shell) (push) Failing after 21s
build / client (Debug, map[cc:gcc cxx:g++], xdg-shell) (push) Failing after 21s
build / client (Release, map[cc:clang cxx:clang++], libdecor) (push) Failing after 21s
build / client (Release, map[cc:clang cxx:clang++], xdg-shell) (push) Failing after 21s
build / module (push) Failing after 18s
build / client (Release, map[cc:gcc cxx:g++], xdg-shell) (push) Failing after 21s
build / client (Release, map[cc:gcc cxx:g++], libdecor) (push) Failing after 21s
build / host-linux (push) Failing after 21s
build / host-windows-cross (push) Failing after 19s
build / obs (clang) (push) Failing after 20s
build / docs (push) Failing after 3s
build / obs (gcc) (push) Failing after 19s
build / host-windows-native (push) Canceled after 0s
build / idd (push) Canceled after 0s
common: align each display's atlas offset for direct scanout
The alignment argument only rounded up the atlas width, so a display's X
offset was an arbitrary running sum of the widths before it. A consumer
pointing display hardware at one display's region needs that region's base
address 256 byte aligned, and with unaligned offsets some displays would
land on legal addresses and some would not — giving the fast path to only
some monitors, which is worse than uniform slowness because the difference
is hard to diagnose.

Each display's X offset is now aligned as well, and the candidate shelf
widths account for the padding so they still describe shelves that can
hold the set. Both capture backends pass an alignment derived from their
pixel size.

Costs nothing for common resolutions: 3840, 2560 and 1920 are all
multiples of 64. Only unusual widths pad at all — a 2160 wide portrait
display grows the atlas by 16 pixels.

Also documents the consumer contract: the alignment guarantee, frame
lifetime under the two deep queue and one second subscriber timeout, and
that damage is in packed frame coordinates.
2026-07-28 09:09:24 +00:00

242 lines
8.2 KiB
ReStructuredText

.. _multimonitor:
Multiple Monitors
#################
A guest with several displays can be carried over a single Looking Glass
session. The host packs every display into one frame, and the client
composes that frame back into the guest's desktop.
.. _multimonitor_how_it_works:
How it works
------------
Running one Looking Glass instance per guest display would mean one shared
memory device, one host process and one capture pipeline each. Instead the
host places all displays side by side into a single frame, called the
**atlas**, and describes the arrangement in the frame's metadata.
The atlas is not a picture of the guest's desktop. Displays are packed to
waste as little space as possible, so a display's position in the atlas
usually has nothing to do with where it sits on the guest's desktop. The
metadata records both rectangles for each display:
* where its pixels are in the packed frame
* where it belongs on the guest's virtual desktop
The client uses that to compose the desktop before anything else happens, so
scaling, HDR, the cursor and damage tracking all work on one ordinary image
and behave exactly as they do for a single display guest.
Nothing changes for a single display guest. Such frames carry no layout, and
both host and client take the same path they always have.
.. _multimonitor_host:
Host configuration
------------------
Multi-monitor capture is enabled by default on capture backends that support
it. To turn it off and capture only as a single display:
.. code:: text
dxgi:multiMonitor=no
xcb:multiMonitor=no
Supported backends:
* ``DXGI`` (Windows) duplicates every attached output on the chosen adapter
and composes them on the GPU. It falls back to capturing a single display
if the outputs cannot be combined safely — if their capture formats differ,
which happens when one monitor is HDR and another is not, or if any output
is rotated. The reason is always logged.
* ``XCB`` (Linux) enumerates RandR monitors and packs them.
Backends that do not implement it capture a single display exactly as before.
.. warning::
The DXGI implementation has not yet been run on real multi-monitor
hardware. If you hit trouble, set ``dxgi:multiMonitor=no`` to confirm the
fault lies there, and see ``MULTIMONITOR.md`` beside the DXGI source for
what each symptom points at.
.. note::
All displays are sent as one frame, so they share a single frame rate.
Monitors of differing refresh rates cannot update independently: the
fastest is limited by the frame rate the host achieves for the whole
atlas.
.. _multimonitor_shm_size:
Shared memory sizing
^^^^^^^^^^^^^^^^^^^^
**This is the setting most likely to catch you out.** The atlas holds every
display, so it needs considerably more shared memory than a single display
would. If the shared memory is too small the frame is truncated and the
client reports how much is required.
Estimate the requirement as::
total pixels of all displays x 4 bytes x 2 frames
Then round up to the next power of two. For example, three 1920x1080
displays::
3 x 1920 x 1080 x 4 x 2 = 49.8 MB -> 64 MB
Three 4K displays need 256 MB, and larger or mixed sets can need more.
Packing is rarely perfect when displays differ in size, so allow some
headroom. The host logs the atlas size at startup:
.. code:: text
Multi-monitor : 3 monitors, desktop 5760x1080, atlas 1920x3240
.. _multimonitor_client:
Client configuration
--------------------
By default the client shows the entire guest desktop, with the displays
arranged as the guest has them:
.. code:: text
app:display=all
To show a single guest display, give its index or its name as the host
reported it:
.. code:: text
app:display=1
app:display=DP-2
If the selection matches no display the client logs the available displays
and falls back to showing the whole desktop.
.. _multimonitor_one_window_per_display:
One window per guest display
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Several clients can subscribe to the same host at once, so a natural way to
use a multi-monitor guest is to run one client per display and put each on
its own physical monitor:
.. code:: bash
looking-glass-client app:display=0 win:fullScreen=yes &
looking-glass-client app:display=1 win:fullScreen=yes &
looking-glass-client app:display=2 win:fullScreen=yes &
Each instance receives the same packed frames and crops its own display, so
the guest is captured and transferred only once no matter how many clients
are watching.
.. _multimonitor_input:
Input
-----
The guest positions its cursor across the whole virtual desktop, so the
client translates between the region it is showing and that desktop. This
happens automatically, including when a single display is selected.
Be aware that when showing one display of several, the guest's cursor can
move onto a display you are not watching, and will appear to vanish. Show
the whole desktop, or run a client per display, if that is a problem.
.. _multimonitor_consuming:
Consuming frames directly
-------------------------
The packed frame is designed so a consumer other than the Looking Glass
client — a custom compositor, for instance — can use each display's region
without copying it out first. This section is the contract such a consumer
can rely on.
Layout
^^^^^^
``KVMFRFrame::displays`` holds ``displayCount`` entries. Each gives the
display's rectangle in the packed frame (``atlasX/Y/Width/Height``) and where
it belongs on the guest's virtual desktop (``desktopX/Y/Width/Height``). The
two rectangles are always the same size: packing relocates a display, it never
scales it. Rotation is already applied to the pixels and is informational.
A display's base address within the frame is::
atlasY * pitch + atlasX * bytesPerPixel
.. _multimonitor_alignment:
Alignment guarantee
^^^^^^^^^^^^^^^^^^^
Both ``atlasX`` and the frame's width are aligned so that every display's base
address is a multiple of 256 bytes, which is what display controllers
typically require of a scanout buffer. A consumer can therefore create one
framebuffer per display, all pointing into the same underlying memory at
different offsets, and page-flip them independently.
This holds for the 32 and 64 bit-per-pixel formats. It cannot be relied on for
``FRAME_TYPE_RGB_24``, which most display hardware cannot scan out regardless.
Frame lifetime
^^^^^^^^^^^^^^
A consumer that scans out directly holds a frame for at least a full vblank,
rather than copying it and releasing immediately. That is safe, but the limits
are worth knowing:
* The frame queue is **two** buffers deep. Pinning one leaves the host a
single spare, so the host blocks waiting for room rather than overwriting a
frame still in use. It will not recycle a buffer out from under a consumer
that is keeping up.
* The subscriber timeout is **one second**. A consumer that holds a frame
longer than that is considered dead and its subscription is dropped. A
vblank is far inside that, but a consumer stalled across a mode set should
expect to reconnect rather than assume its frame is still valid.
The practical consequence is that the host cannot run ahead of a pinning
consumer. For direct scanout that is the desired behaviour: it is what stops
stale frames queueing up.
Damage
^^^^^^
Damage rectangles are always in packed frame coordinates, so they can be
intersected against each display's atlas rectangle to find which displays
changed, and a display with no intersecting damage can skip its flip
entirely. A ``damageRectsCount`` of zero means the whole frame changed.
Format changes
^^^^^^^^^^^^^^
Any change to the display arrangement bumps ``formatVer``. A consumer must
re-read the layout when it changes rather than caching it for the life of the
session, since both the atlas dimensions and each display's position can move.
.. _multimonitor_limitations:
Limitations
-----------
* At most 8 guest displays.
* The packed frame cannot exceed 16384 pixels on any edge, which is the
texture size limit on current hardware. Very large display sets may not
fit.
* Damage tracking is per frame rather than per display once composed, so a
multi-monitor session redraws the whole view each frame. Frame transfer
still honours damage, so the cost is on the client's GPU rather than the
link.
* All displays are captured and sent even when the client is showing only
one of them.