feat(display): zero-copy presentation toggle and compositor display buffers (#2905)

* feat(display): zero-copy presentation toggle and compositor display buffers

Adds a Zero-copy presentation switch under Steam Settings, Display,
Session Display (on by default), and a display-buffer allocator in the
compositor: a Vulkan driver that states displayBuffers asks it for the
memory of the images it exports, so frames presented through the nested
compositor are gralloc buffers that go on the display layer without a
copy. Compressed buffers are offered only where the device's allocator
matches the layout the drivers render to; everything else stays on the
copy path.

The private buffer protocol is renamed to droiddeck-ahb-v1.

* fix(display): zero-copy frames keep the full refresh rate

Two buffers set on the game layer inside one refresh replaced each other, and a frame that slipped into the next refresh made the compositor hold and drop the on-time frame behind it. The layer now queues buffers, and a refresh takes a second frame when the one before it took none. The pacing tool no longer counts its dump time in the frame rate.

* Keep cropped scenes on the display layer and pace layer frames evenly

Accept any in-bounds source crop for the display layer and map the draw
geometry the same way the copy path does. Time layer frames against the
display's frame timeline, and when the game's rate is a steady whole
fraction of the refresh rate show each frame a fixed number of refreshes
after the last so uneven arrivals no longer reach the screen.

* List zero-copy in the settings map

* Hold display buffers until the display releases them

A buffer the game or gamescope rendered straight into went back to its
client as soon as the next one was latched, with the display's release
fence attached to the dma-buf. The KGSL driver does not wait on that
fence, so the client could draw into a buffer the panel was still
reading. Display buffers now wait for the release fence before the
release event, and gamescope composites only into output images the
host has released.

* Keep the game picture copy-free when an overlay has no display layer

When the display cannot give a second layer of its own to an overlay,
the compositor tells gamescope how many planes it can show directly.
gamescope then composes its overlays into the game picture, which still
reaches the display without a copy.

* feat(session): the panel refresh rate follows the session's frame rate

The session learns the panel's refresh rates and reports the refresh rate and
frame rate it wants. The panel moves to the highest rate the frame rate divides
evenly, frame generation counts at its output rate, and a panel whose rate the
system holds offers only that rate.

* feat(session): the panel follows a frame rate the game holds on its own

The compositor reports the game's frame rate once a second. A rate that
holds for three seconds and divides a panel rate becomes the content
rate when neither the app's limit nor the session's limiter is setting
the pace, so a game capped in its own settings gets a panel rate its
frames divide into. A rate that was dropped has to hold twice as long
before it is used again.

* Show generated frames on the game's display layer

With frame generation on, the game's own frames stay on their display
layer untouched and each generated frame is placed on the same layer
between them, timed across the game's frame interval. The compositor
pass is kept when effects, HDR routing or a cursor need it, or when the
panel cannot show the multiplied rate.

* Keep scaling, generated frames and HDR on the display layer

A scaler or frame generation with zero-copy on now draws once into the
display layer instead of falling back to the copied surface. HDR output
goes to the layer when the panel supports it; on a panel without HDR the
picture is tone-mapped on the same path, and the toggle is labelled to
match what the panel can do.

* Spread a frame limit the refresh rate does not divide evenly across refreshes

* Cover the spare-tick and panel-rate paths in the compositor source tests

* Pin the gamescope build with the display-plane, release, refresh and limiter patches

* Give the layer and terminal-caller harnesses the black fill state they compile against

* feat(display): switch HDR during a session without restarting the app

The compositor now offers HDR whenever the device can present it, and the
HDR setting only decides whether the session uses it. Both HDR switches set
gamescope's hdr_enabled, the compositor's HDR output and zero-copy for the
running session. gamescope patch 0139 lets hdr_enabled change after start.
The 'Restart the app to apply.' hint is removed from every locale.

* Remake the output images in the new format when HDR is switched during a session

* Pin the gamescope build that switches HDR during a session

* Apply a saved HDR opt-out at session start and keep HDR retries with their session

* Serialise the HDR output switch with the gate opening

* feat(display): keep the client's HDR setting and the session's in step

The session publishes its HDR state with the other device controls and the
client helper applies it to the client's own display setting. A change made in
the client is reported back and goes through the same switch the drawer and
Session Display use, so all three always show one value.

* fix(desktop): keep the display-buffer socket when the runtime directory is cleared

The desktop launcher removed everything in the runtime directory except the
compositor's Wayland socket, which took the display-buffer socket with it, so
no desktop program could ask for display buffers and every frame was copied.

* fix(display): the client's HDR setting follows the session in every client mode

The bridge only ran when a variable nothing sets was present, so the client's
HDR setting and the session's never met. It now runs whenever the session
publishes an HDR state, and a client that has no such setting is asked again
only every ten seconds.

* fix(display): harden display-buffer hand-off, layer fallbacks and HDR sync

- Stop closing a buffer handle's descriptor the allocator still owns, and free an allocation whose reply could not be sent.
- Rebuild the advertised buffer formats when zero-copy is switched during a session.
- Fall back to the copy path when a layer buffer cannot be allocated, and hide the game layer when it is skipped for a frame.
- Keep a release fence that has not signalled instead of rendering into a buffer the display still reads.
- Ignore a refresh-target reset from a client that does not own the target.
- Restart the content-rate measurement after a pause, clear it when the game stops, and lengthen engagement only for a rate that was released before.
- Compare colour conversions by their values, and read padded cursor buffers at their row width.
- Use the running session's mode for the HDR and zero-copy settings, probe the display before screen effects are pushed, retry a held panel mode, and ignore callbacks after the activity is destroyed.
- Write a newer HDR value while an earlier write is settling, and reapply the value after the bridge is reinstalled.
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-21 00:26:50 -05:00
1 parent f29f72d5d9
commit 4349563fd1
101 files changed
+3927 -624

No files matched your search

+48
View File
@@ -358,3 +358,51 @@ and clears the held flag. wlroots counts repeated presses of one button and send
reaches zero, so a second finger touching before the first lifted left the button pressed in the seat for good: the
game saw a held click, and later taps only raised and lowered the count. A finger now presses the button only when no
earlier finger holds it. `tools/tests/test_gamescope_touch_click.py` compiles the rule from this patch.
## 0135 Wayland backend: a limit on the planes handed to the host
`wayland_overlay_planes` says how many planes above the base one the host compositor shows without composing them
itself. With more layers than that, gamescope composites them into one picture, as it already does for a scaler or
`composite_force`. -1, the default, keeps every layer on its own plane. The app sets it while a host that shows the
game picture directly cannot give an overlay a display layer of its own, so the overlay is drawn into the game
picture here and the frame still reaches the display without a copy.
## 0136 rendervulkan, Wayland backend: composite only into output images the host has released
The composite output images were used in a fixed rotation of three, with no check that the host compositor had
released the one about to be written. A host that puts the buffer on the display itself, without copying it, was
still reading that image when the next composite wrote into it. A backend framebuffer now says whether the host
holds it, the Wayland backend answers from the buffer's release event, and the composite takes the next image the
host does not hold. Backends that are not a session get five images instead of three, so one is free while the
host holds two and the last and deferred pictures stay intact. Session backends keep three images and their order.
## 0137 Wayland backend: the host's refresh rates and the app's target
A nested session had one refresh rate, the host's, so Steam offered no refresh control and a frame limit never moved
the display. The backend binds the host's `droiddeck_refresh_v1`, takes the list of rates the host display can switch
between and returns it as the connector's dynamic refresh rates, so the rates reach Steam with the rest of the
display state and are sent again when the list changes. On every present it tells the host the refresh rate the
frame limit resolves to and the limit itself; the host switches its display and the new rate comes back through
`wl_output`, which the nested refresh already follows. A host without the global leaves all of this as it was.
## 0138 Frame limiter: a limit the refresh rate does not divide is spread evenly
The limiter held a window for a whole number of refreshes, the refresh rate divided by the limit and rounded down. A
limit of 45 or 40 on a 60 Hz display rounded to one refresh per frame, so the limit did nothing, and each frame was
timed from the moment the previous one was shown, so a late frame pushed every frame after it. The limited cycle is
now the exact time between frames at the limit, and each window keeps the time its next frame is due on that line.
A frame is released on the refresh nearest its due time: 45 on 60 Hz shows frames for one, one and two refreshes in
turn, 40 for one and two, and a limit that divides the refresh rate is paced as before. A frame that arrives most of a
refresh late, or more than a refresh early, starts the line again from that frame, so a stall is not followed by a
burst. `tools/tests/test_gamescope_limiter_cadence.py` compiles the two rules from this patch and runs them across
refresh rates and limits.
## 0139 HDR output can be switched while a session runs
The Wayland backend read `hdr_enabled` once, when the host compositor described its output, and kept the answer: a
session started with HDR off told its clients the display had no HDR for as long as it ran, and its environment
carried `DXVK_HDR=0`. Whether the display can show HDR now comes from the host's output description alone, and
`hdr_enabled` decides only whether HDR is used, so setting it during a session takes effect on the next frame in
either direction. The 10-bit output format is chosen only while HDR is enabled, so an SDR session keeps the 8-bit
output it had, and the output images are made again in the other format when the setting changes. On a display that can show HDR, a session that starts with HDR off leaves `DXVK_HDR` unset instead of
forcing it to 0, so a game started after HDR is switched on finds it.