Repository navigation
fix(macos,render): shrink hidden Metal drawables to 1x1 and drop retained damage on unseen rest - #2687
Merged
Conversation
…ined damage on unseen rest Addresses #161. - Add an explicit HiddenDrawable state machine (window/surface/hidden_drawable.rs) and platform::macos::set_drawable_size seam via gpu::with_layer (works on both Rune's native Metal backend and wgpu's Metal backend). - On macOS, shrink CAMetalLayer.drawableSize to 1x1 when a non-launcher window hides (Host::hide_window) or when a non-released overlay finishes hiding (OverlayCore::carry_out after exit fade), so Core Animation releases unused full-size drawables from its pool while leaving any displayed surface intact. - Restore drawableSize to (config.width, config.height) before showing (Win::show, OverlayCore::show_fading) and as a guard before acquiring a drawable, and clear the shrunk state on surface reconfigures. - Drop the renderer's full-window retained partial-damage texture in Renderer::give_back(true, ...) while keeping visible idle rest unchanged. - Trim overlay staging uploads when OverlayCore::retire.poll_due finishes retiring in-flight work while rested.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #161
Summary
Fresh macOS
footprint -vmeasurements ondev(dacf5d89, #161 (comment)) showed that image textures and upload staging already free on hide, leaving two GPU-side retention sources on hidden windows and overlays:CAMetalLayerdrawables (34 MB across hidden main window, region overlay, and HUD): Nothing changedCAMetalLayer.drawableSizeon hide, so QuartzCore kept two (up tomaximumDrawableCount) full-size IOSurface drawables per hidden window and overlay.Renderer::give_back(true, ...)cleared scratch layers, image textures, backdrop copies, and blur pyramids, but keptDamageState::retained(a full-window GPU texture, e.g. 12.8 MB at 2200×1520 on an opaque main window) indefinitely while hidden or covered.Changes
CAMetalLayerdrawable shrink/restore (macOS):HiddenDrawablestate machine (Full/Shrunk) and window/overlay shrink policies incrates/rune/src/window/surface/hidden_drawable.rs(with unit tests inhidden_drawable_tests.rs).platform::macos::set_drawable_size(surface, width, height)viagpu::with_layerso both Rune's native Metal backend and wgpu's Metal backend updateCAMetalLayer.drawableSize.release_gpu_when_closed, fading overlays, andRelease::Now) and restore-before-show / restore-before-acquire intoWin(Host::hide_window,Win::show,WindowFrame::acquire, plus configure resets) andOverlayCore(carry_out,show_fading,OverlayFrame::acquire,rescale,reblend_surface).CAMetalLayerregression test incrates/rune/src/platform/macos/surface_tests.rscovering shrink to1×1, restore to full size, and clean full-size redraw on both native Metal and wgpu Metal (preserving all existing HAL counter tests untouched).Renderer::give_back(true, ...)now dropsDamageState::retainedviaRenderer::release_damage_retained()while leaving visible idle rest (give_back(false, ...)) unchanged; the next armed frame catches up whole (KeptDraw::Whole) and resumes partial redraws cleanly.give_back_unseen_drops_retained_damage_texture_and_wakes_cleanlyincrates/rune/src/render/damaged_tests.rs.Retire::poll_duenow returns whether a pending retirement finished, andOverlayCore::wake_duecallsrenderer.trim_uploads()once in-flight work retires while rested.changelog/unreleased/2026-11-28-hidden-window-drawable-and-damage-reclaim.md.Verification
--features rune/test-gpu-counters,rune-gpu/test-gpu-counters):cargo check -p rune --lib: passed with 0 errors, 0 warnings in touched files.cargo test -p rune --features rune/test-gpu-counters,rune-gpu/test-gpu-counters --lib -- hidden_drawable give_back_unseen_drops_retained_damage_texture overlay::rest_tests retire_state_machine: 12 passed, 0 failed (verifiesHiddenDrawabletransitions/policies and provesgive_back(true)drops the retained damage HAL texture back to baseline and wakes with pixel-exact catch-up).cargo test -p rune --features rune/test-gpu-counters,rune-gpu/test-gpu-counters --lib -- window::tests::: 26 passed, 0 failed.CAMetalLayersetDrawableSizeruntime test and live macOSfootprint -vIOSurface / owned-unmapped measurements (needs macOS CI / hardware verification).