Repository navigation
fix(image): reclaim dead slots on shared atlas pages and bound ImageAtlas in pages, slots, and bytes - #2124
Merged
Conversation
…tlas in pages, slots, and bytes
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 #2103
Follow-up to #2115 (which fixed empty middle shelf pages retaining their CPU/GPU buffers).
Root cause
Slot(crates/rune-image/src/pixels.rs) tracked no per-slot liveness (Weak<FrameInner>,touched,shown, or last-drawn frame);ImageAtlas::end_frameandImageAtlas::restretained slots solely bypages[s.page].touched/pages[s.page].shown.slotsandstartsforever (contradictingrest()'s doc), its shelf space could never be reused until the whole page emptied, andImageAtlashad no cap in pages, slots, or decoded pixel bytes.Changes
crates/rune-image/src/shelf.rs(Shelves+ImagePage) partitioning each1024x1024shelf page into vertical bands with coalesced horizontal free spans and coalescing/popping empty bands, plusshrink_to_fit_rows()to reclaim unused bottom rows without moving live slots.Slot(Weak<FrameInner>,shown,touched,last_frame,relocate) and mid-frame resize deferred-free tracking incrates/rune-image/src/pixels.rs:end_frame()immediately drops undrawn slots whosePixelshandles were dropped and returns their rects to their shelf bands, while keeping slots drawn on the current frame intact for the frame's upload/draw.rest()evicts slots not shown in the last completed frame (or whose handles were dropped) per slot—including on page 0 and shared pages—cleans theirstartsentries, shrinks remaining shelf pages to their occupied rows, and empties pages left with zero slots.ImageAtlasretention across frames to 16 pages (IMAGE_ATLAS_MAX_PAGES), 64 MiB of decoded pixels (IMAGE_ATLAS_MAX_BYTES), and 4,096 slots (IMAGE_ATLAS_MAX_SLOTS) with LRU eviction of unshown entries and next-frame relocation of sparse overflow pages aboveIMAGE_ATLAS_MAX_PAGES.Before / after
end_frame)rest()rest())Verification
crates/rune-image/src/atlas_tests.rs(40-frame shared-page repro failed ondevwith 2 pages / 20 slots / 8,388,608 B and passes with fix; variable-size band coalescing; 20 persistent icons + thumbnail bursts;rest()per-slot + animationstartscleanup; filling past page, byte, and slot bounds with re-upload of returning evicted images;ImageCachecounts; mid-frame resize deferred reclamation) and 1 GPU test incrates/rune/src/render/image_tests.rs(gpu_shared_page_eviction_rest_shrink_and_reupload_draw_exact_pixels).cargo test -p rune-image(91 passed, 9 doctests passed),cargo test -p rune -p rune-mermaid -p rune-kit --features rune-kit/markdown,rune-kit/mermaid render::image_tests,sixty_(pixels_streaming: 0 allocations),render::upload::tests, macOScargo test -p rune-image pixelsandcargo clippy -p rune-image -p rune --lib --bins --tests, Linuxcargo check -p rune -p rune-kit --tests, andscripts/file-size.sh.