Skip to content

fix(gpu): cap GPU readback staging buffers to prevent memory exhaustion - #713

Open
mjohnson7cd wants to merge 1 commit into
storytold:mainfrom
mjohnson7cd:fix/2081-rendering-hang
Open

mjohnson7cd wants to merge 1 commit into
storytold:mainfrom
mjohnson7cd:fix/2081-rendering-hang

Conversation

@mjohnson7cd

Copy link
Copy Markdown
Contributor

Summary

Fixes storytold/artcraft#2081 - Rendering stops at frame 970/1570, PC lags until app closed on high-end system (i7-12700KF, RTX 3090, 32GB RAM).

Problem

GPU readback staging buffers accumulated unbounded when layer bounds changed every frame (animated scale, blur radius, growing shapes). Each 1080p RGBA f32 buffer ≈ 33 MB in system RAM. At 970 frames × 33 MB ≈ 32 GB, the system exhausted available memory.

The buffers are kept for reuse (up to 2 per size), but there was no limit on total memory across all sizes.

Solution

Capped GPU readback staging buffers to 256 MB total. When adding a new buffer would exceed the cap, drop buffers of other sizes while keeping the current size for reuse. Renders with consistent frame sizes still benefit from buffer reuse.

Implementation

Changed: crates/gpu/src/context.rs, crates/gpu/tests.rs (+34/-1)

  • Added 256 MB budget for readback staging buffers
  • Eviction policy: drop other sizes when budget exceeded, keep current size
  • New test: readback_staging_stays_bounded_across_sizes

Test Results

Without fix: Test reads 120 different sizes (~480 MB), holds 620 MB, takes 28.5s (Apple M4/Metal)
With fix: Same test passes in 0.54s, stays within 256 MB budget

✓ cargo fmt
✓ cargo clippy --workspace --all-targets -- -D warnings
✓ cargo test -p effectcraft-gpu (204 tests passed)

Notes


— sent on behalf of @mjohnson7cd by Claude Code

@mjohnson7cd
mjohnson7cd marked this pull request as ready for review October 11, 2026 05:10

This branch has not been deployed

No deployments
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.

Effect craft rendering issue

1 participant