Skip to content

Release glyph masks with the GPU surface of a hidden overlay #3295

Backlog

Description

@purian23

On Wayland, a non-prewarmed overlay configured with release_gpu_when_hidden() or release_gpu_after() gives back its
surface and renderer once it hides, but the runtime keeps the CPU side of what it drew: the glyph and icon mask pages
(at least one 256 KiB page), the outline records, colour glyphs and icons, the cached glyph runs and the text quads of
its last visible frame. They are only useful to a renderer that no longer exists.

On a Linux desktop shell (RTX 4070 Ti, nested niri), heaptrack after ten open-and-hide cycles, live bytes allocated
during the cycles and still held after the hide, without any release:

overlay Atlas::put_bordered / Atlas::put TextQuads::insert
launcher-sized list, text and icons 278,528 57,984
panel with tabs 278,528 26,976
small popup 262,144 3,296

With the change, a launcher-sized overlay and a popup hold no atlas, outline, glyph-run or text-quad bytes after the
hide, nor after a stream of state changes that reach them while hidden (volume and network updates). An earlier form
of the change, releasing at the same point for release_gpu_when_hidden, did not move the time from show request to
first committed buffer outside the noise (16-44 ms either way, 5 opens each).

The change

  • When the overlay gives its GPU surface back (the ReleaseGpu step of the presence machine, after any fade-out and
    after the window hid), a non-prewarmed overlay also calls RuntimeCore::drop_hidden_masks. It covers
    release_gpu_when_hidden and release_gpu_after alike.
  • drop_hidden_masks clears the text flights (a hidden overlay shows none, and the next show's reveal settle would
    land them), calls TextSystem::release_masks and clears the text quads.
  • TextSystem::release_masks frees the atlas pages, placement map, icon map and fill queues, the outline store's
    records (keeping the renderer's support and the row limit), the glyph run cache, colour glyphs, colour icon images
    and animated icon slots, and moves the page generation on so no earlier placement or slot matches again. Compiled
    icon animations stay: an icon is classified, and its animation compiled, only once.
  • A hidden overlay still commits when a handler runs while it is hidden: the blur and keys_lost its own hide
    reports for a key-taking overlay, or a key release that arrives after the hide. That build places masks again, so
    commit_at drops them once more when the overlay is hidden with its GPU given back. Skipping the build while hidden
    would be cheaper, but the build also refreshes hit rects and per-node paint state that the rest of the frame reads,
    and a retained macOS overlay commits hidden on purpose.
  • The next show places what it draws again. A prewarmed overlay keeps its masks. The docs of
    release_gpu_when_hidden, release_gpu_after and OverlayOptions::prewarm say so.

Tests

  • atlas::tests::released_masks_free_every_page_and_no_old_slot_matches_again (rune-text): pages 0 and 1 in use,
    release, one empty page left, stale slots on both pages refused before and after the pages exist again.
  • overlay::rest_tests (rune): the masks go at the hide and come back on show; a hidden handler that rebuilds the
    view leaves them released; release_gpu_after keeps them until its release and Keep keeps them; a text flight in
    the air at the hide doesn't hold them.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions