Skip to content

fix(image): release CPU ImagePage shadow buffers after GPU upload - #2688

Merged
Hona merged 1 commit into
devfrom
fix/image-atlas-drop-cpu-backing
Nov 28, 2026
Merged

Hona merged 1 commit into
devfrom
fix/image-atlas-drop-cpu-backing

Conversation

@Hona

@Hona Hona commented Nov 28, 2026

Copy link
Copy Markdown
Member

Addresses #163

Summary

  • Add sub-rectangle texture uploads (Staging::write_texture_rect, DirectTextureRect, and Metal replace_texture_rect / write_texture_rect_in_place) so individual image slots upload directly to GPU textures without requiring a full-page CPU row buffer.
  • Stop retaining ImagePage::data in GPU mode (ImageAtlas::set_backing(Backing::Gpu) / release_cpu_pages). GPU-first windows and overlays switch to Backing::Gpu before frame 0 (never allocating ImagePage::data in ImagePage::new or ImagePage::allocate), and Renderer::upload_images automatically releases any existing CPU page buffers after uploading.
  • Keep resize, hide/wake, device-loss recovery, and CPU rendering safe:
    • Shelf growth, rest() shrinking, give_back(true) hide/wake, invalidate(), and staging.lost() re-upload all live slots directly from their Pixels handles (Slot::live) plus any in-frame pending snapshots.
    • ImagePage::is_active() and ImagePage::pixel_bytes() decouple page liveness and IMAGE_ATLAS_MAX_BYTES / IMAGE_ATLAS_MAX_PAGES bounds from page.data.len().
    • cpu_boot::Scene::new continues borrowing ImagePage::data with zero allocation during CPU-boot (and Windows handover keeps CPU backing via upload_images_retaining_cpu until SurfaceMode::Handed commits), and falls back to on-demand ImageAtlas::read_page_rgba if called on a GPU-released atlas.

Verification

  • cargo test -p rune-staging --lib (12 passed, including write_texture_rect_writes_unaligned_subrects_without_clobbering_neighbors)
  • cargo test -p rune-image --lib pixels:: (28 passed, including gpu_backing_holds_zero_cpu_page_bytes_and_uploads_dirty_rects_and_full_rebuilds)
  • cargo test -p rune --lib render::upload::tests (13 passed, including gpu_upload_drops_cpu_page_buffers_and_survives_growth_device_loss_and_cpu_paint)
  • cargo test -p rune --lib render::image_tests (15 passed), overlay::rest_tests (6 passed), render::cpu_boot:: (28 passed), --test pixels_streaming (3 passed)
  • cargo check -p rune-staging -p rune-image -p rune --target wasm32-unknown-unknown (passed)
  • Not run on macOS/Metal hardware in this Windows environment (pending Mac malloc rerun on Images: every atlas page keeps a CPU copy beside its GPU texture #163).

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