Repository navigation
fix(render): drop freed and hidden image atlas GPU textures in give_back - #2126
Merged
Merged
Conversation
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.
Fixes #2102
Root cause
Host::give_back(crates/rune/src/window/host/lifecycle.rs) andOverlayCore::give_back(crates/rune/src/overlay/lifetime.rs) calledrt.images.rest()(freeing CPUImagePage::dataand truncating trailing empty pages) and thenrenderer.give_back(all, ...)(crates/rune/src/render/layers.rs).Renderer::give_backnever updatedself.imagesor cleared layer targett.imagesbind groups referencing those textures; image GPU textures were only dropped on the nextupload_imagesdraw call (or Wayland/Xwayland overlay hide / warmup). Because resting and hidden windows draw no frames, freed pages at idle rest and all image pages while hidden stayed resident in VRAM.Changes
crates/rune/src/render/upload.rs: addRenderer::prune_images(&mut self, images: &ImageAtlas)to truncateself.imagestoimages.pages.len()and drop any slot whose page haspage.data.is_empty()or mismatched dimensions, clearing layer image bind groups (self.layers.clear_images()) and bumpingimage_generation(self.images_changed()) whenever anything drops so no layer target retains a reference to a freed texture.crates/rune/src/render/layers.rs: passimages: &ImageAtlasintoRenderer::give_back; callself.clear_images()whenall == true(hidden/covered) andself.prune_images(images)whenall == false(idle rest).crates/rune/src/window/host/lifecycle.rsandcrates/rune/src/overlay/lifetime.rs: pass&rt.imagestorenderer.give_back, right afterrt.images.rest()and before GPU retirement/polling.crates/rune/src/render/upload/tests.rsandcrates/rune/src/overlay/rest_tests.rs: add headless real-GPU regression tests withtest-gpu-counterscovering idle rest (interior emptied page and trailing truncated page), hidden/coveredGiveBackAll, layer image bind group release,ImageCacheretention, and pixel-exact first-frame wake.changelog/unreleased/2026-11-25-give-back-image-textures.md: changelog entry.Before / after (2-page scene: 1024×128 shelf page + 1025×64 standalone page, small image hidden)
GiveBackUnused, page 0 emptied)GiveBackAll)Verification
test-gpu-counters):cargo test -p rune -p rune-mermaid -p rune-kit --features rune-kit/markdown,rune-kit/mermaid,rune/test-gpu-counters,rune-gpu/test-gpu-countersonrender::upload::tests(13 passed),overlay::rest_tests(4 passed), andrender::image_tests(13 passed);cargo clippy -p rune --lib --bins --tests --features rune/test-gpu-counters,rune-gpu/test-gpu-countersclean;cargo check-wasmclean.test-gpu-counters):cargo test -p rune --features rune/test-gpu-counters,rune-gpu/test-gpu-counters give_back(3 passed).cargo check -p rune -p rune-kit --testsclean (compile check only; headless container has no GPU).scripts/file-size.sh: 0 errors.