Skip to content

fix(overlay): reclaim spare GPU pools and runtime caches while resting - #1933

Merged
Hona merged 1 commit into
devfrom
fix/1875-overlay-rest
Nov 24, 2026
Merged

Hona merged 1 commit into
devfrom
fix/1875-overlay-rest

Conversation

@Hona

@Hona Hona commented Nov 24, 2026

Copy link
Copy Markdown
Member

Refs #1875

Root cause

  • Unlike window::Host (crates/rune/src/window/state/rest.rs, crates/rune/src/window/host/lifecycle.rs), OverlayCore had no Rest state machine and never called Renderer::give_back, TextSystem::rest, ImageAtlas::rest, or Rewind::rest.
  • A visible overlay therefore kept spare layer targets (up to 32 MiB), unused El::cache textures (up to 64 MiB), unused backdrops/blur pyramids, oversized staging chunks, and stale text/image/rewind caches indefinitely while idle.

Changes

stateDiagram-v2
    [*] --> Rested
    Rested --> Drawing: Drew (!prewarm)
    Drawing --> Drawing: Drew (postpones deadline)
    Drawing --> Idle: Woke (now >= due) / GiveBackUnused
    Drawing --> Rested: Unseen (hide/occluded) / GiveBackAll + Retire
    Idle --> Rested: Unseen (hide/occluded) / GiveBackAll + Retire
    Idle --> Drawing: Drew
Loading
  • Promoted window::state::rest (Rest, RestEvent, RestEffect, step, low_memory, REST_AFTER, PRESSED_AFTER) to pub(crate) and re-exported them from crates/rune/src/window.rs.
  • Wired Rest into OverlayCore (crates/rune/src/overlay.rs, overlay/draw.rs, overlay/any_host.rs, overlay/input.rs, overlay/lifetime.rs):
    • OverlayFrame::settle records RestEvent::Drew when !prewarm.
    • OverlayCore::wake_deadline chains self.rest.deadline() (one-shot; clears to None in Rest::Idle and Rest::Rested, so idle overlays wake zero times and draw zero frames).
    • OverlayCore::wake_due steps RestEvent::Woke after presence_due and before retire.poll_due.
    • OverlayCore::stop_drawing (when release != Release::Now) and macOS OverlayCore::occluded(true) step RestEvent::Unseen; park() and Release::Now reset self.rest = Rest::Rested.
    • OverlayCore::give_back mirrors window::Host::give_back, polling once non-blocking only when !all && renderer.has_oversized_uploads_in_flight(), and on all calling self.retire.retire_now(&gpu, now) plus renderer.trim_uploads() instead of blocking wait_indefinitely() on shared GPU devices.
  • Added crates/rune/src/overlay/rest_tests.rs covering one-shot idle rest with zero wakes/frames, 100+ alternating keyed opacity-transition swaps reclaiming both spare layer targets (spare_layers() == 0, HAL textures -2) after REST_AFTER, and Unseen reclaiming live scratch targets.

Verification

  • Windows: cargo test -p rune --lib --features rune/test-gpu-counters overlay:: (81 passed), window:: (168 passed), and confirmed all 3 new tests fail before wiring Rest.
  • macOS: cargo test -p rune --lib overlay:: (101 passed, covering macOS occluded(true) rest path).
  • Linux: cargo check -p rune -p rune-kit --tests.
  • Web: cargo check -p rune --no-default-features --target wasm32-unknown-unknown.
  • Hygiene: scripts/file-size.sh (0 errors).
  • Not verified: live on-screen window/DirectComposition overlay on Intel Iris Xe hardware.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant