Skip to content

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

Merged
h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
mjohnson7cd:fix/2081-rendering-hang
Oct 12, 2026
Merged

h-a-n-a-s-h-i merged 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
@mjohnson7cd

Copy link
Copy Markdown
Contributor Author

Hi @echelon! 👋

This PR has been ready for review for a while and addresses issue storytold/artcraft#2081 (rendering stops at 970/1570 fps, system exhaustion).

The fix caps GPU readback staging buffers to 256 MB to prevent unbounded memory growth when layer bounds change every frame. All tests pass (204 tests in effectcraft-gpu).

Is there anything blocking this from being merged, or any changes you'd like to see?

Thanks for your time reviewing! 🙏

— sent on behalf of @mjohnson7cd by Claude Code

@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit 0ae711b into storytold:main Oct 12, 2026
@echelon

echelon commented Oct 12, 2026

Copy link
Copy Markdown
Member

Merged. Thank you for the contribution, @mjohnson7cd!

If you haven't already, come join us on Discord: https://discord.gg/artcraft. It's the best place to discuss what you're working on next and to coordinate with other contributors.

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

3 participants