Repository navigation
gpu: memory back-pressure for frames in flight (fixes OOM at 3–4 frames in flight) - #1550
Open
MatejKozlovsky wants to merge 2 commits into
Open
MatejKozlovsky wants to merge 2 commits into
MatejKozlovsky wants to merge 2 commits into
Conversation
… end A GPU frame keeps its encoder open while the CPU renderer runs layers with GPU effects (Gpu::effects -> run_chain). Each call's Enc handed its textures back to the shared pool, where they waited for every open encoder, so all effect intermediates of a frame stayed allocated until the frame ended (17.7 GB by layer 17 of a heavy 4K comp, then OOM). Effect calls now borrow a pool owner (Enc::lent) that is given back once the call's work is submitted or discarded; its kept textures are trimmed to the pool budget, so the rest are freed after each call.
Once the wgpu allocator holds more than a cap (8 GiB on discrete GPUs, 2 GiB otherwise; EFFECTCRAFT_GPU_MEMCAP_MB overrides, 0 = off), a frame submits its encoder and waits for the queue so wgpu destroys dropped textures and pending pool textures free up. Checked every 8 effect calls / layers. Fixes out-of-memory errors at 3-4 frames in flight on 4K comps.
This was referenced Oct 16, 2026
This branch has not been deployed
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.
Depends on #1523 (fx-owner, 13a49c9).
Root cause
With several frames in flight, VRAM fills up with resources we already let go of. A
gpu.mem=detailtrace of 4K d_blurglow at 3 in flight, just before the out-of-memory error:GpuImagehandle, all in the upload cache. The other 39 (~5.8 GB) were dropped on our side, but wgpu
hadn't destroyed them yet: it does that only once the submissions that used them complete.
textures owned by frames.
"pending", and it hit more OOM errors.
So nothing leaks for good: frames in flight record work faster than the GPU retires it.
Fix
Enc::mem_gateruns after each effect call and each layer. Every 8th call it reads the wgpuallocator report, and if more than the cap is allocated, the frame submits its encoder and waits
for the queue. wgpu then frees what was dropped, and pending pool textures become free.
8 GiB on discrete GPUs and 2 GiB on integrated/other adapters.
EFFECTCRAFT_GPU_MEMCAP_MBoverrides it; 0 turns it off.
Results
AMD Ryzen 7 5800X / NVIDIA GeForce RTX 3090 (24 GB), Vulkan, 4K, 6 frames, wall-clock seconds,
no environment variables. 3 runs each, interleaved base/memcap; min / median:
the same card, an earlier session measured 3–4 in flight at 36–38 s median; the 8 GiB default
trades some of that for headroom on smaller cards.
Tests:
cargo test -p effectcraft-gpu(EFFECTCRAFT_REQUIRE_GPU=1) on Apple M4: 212 passed, 1failed (
tests_init::opengl_adapters_get_cpu_compositing_at_once: no GL adapter on macOS; italso fails on base). Metal has no allocator report, so the gate is a no-op there. New unit test
memcap::tests::defaults_and_cadence.