Skip to content

#1487: size the GPU memory cap from the card's video memory where Linux reports it (depends on #1550) - #1706

Open
00xJS wants to merge 3 commits into
storytold:mainfrom
00xJS:gpu/memcap-vram
Open

00xJS wants to merge 3 commits into
storytold:mainfrom
00xJS:gpu/memcap-vram

Conversation

@00xJS

@00xJS 00xJS commented Oct 17, 2026

Copy link
Copy Markdown

Depends on #1550: this branch is #1550 (23da45dd) plus one commit (d02f000a). Review only the last commit; the rest is #1550's. Refs #1487.

Problem

#1487 is a 2–4 GB RX 550 on Fedora that took the whole system down during export (amdgpu_vm_validate() failed, Not enough memory for command submission!). #1550's default cap is 8 GiB for every discrete card, which is more memory than that card has, so the gate would never trigger there.

Change (crates/gpu/src/memcap.rs)

wgpu has no safe memory query, but on Linux the amdgpu driver publishes the card's memory in sysfs, and reading it needs no unsafe: /sys/class/drm/cardN/device/mem_info_vram_total. MemCap::new matches the DRM card by PCI vendor / device against AdapterInfo and caps discrete cards at min(8 GiB, ¾ × VRAM):

card cap
2 GB (RX 550) 1.5 GiB
4 GB (RX 550 / 6500 XT) 3 GiB
8 GB (RX 7600) 6 GiB
16 GB and up 8 GiB (unchanged)

Integrated GPUs keep 2 GiB (an APU's carve-out isn't its limit). EFFECTCRAFT_GPU_MEMCAP_MB still overrides it. Where the size isn't known (Windows, NVIDIA on Linux), the 8 GiB default applies as in #1550. Windows' WDDM pages video memory to system memory instead of hard-crashing like #1487, which is why this targets Linux.

Tests

  • known_video_memory_lowers_the_discrete_cap: the arithmetic above.
  • video_memory_is_read_from_the_matching_drm_card: a fake sysfs tree with an Intel card that has no mem_info_vram_total, the RX 550 (0x1002:0x699f, 4 GiB) and a card1-DP-1 connector entry; plus a non-matching id and a missing directory.

Run on Windows 11 / RX 6900 XT, Vulkan: cargo test -p effectcraft-gpu --lib --release gives 212 passed. The only 3 failures also fail on main (#1605). cargo clippy -p effectcraft-gpu --all-targets --release -- -D warnings is clean. Not tested on Linux: the fixture covers the parsing, but the real sysfs read still needs a Linux/amdgpu machine.

🤖 Generated with Claude Code

MatejKozlovsky and others added 3 commits October 15, 2026 03:27
… 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.
…where Linux reports it

storytold#1550's default cap is 8 GiB for every discrete card, above all of a 2-4 GB
card such as the RX 550 in storytold#1487, which ran out of memory during export and
took the system down. On Linux the amdgpu driver publishes the card's memory
in sysfs (mem_info_vram_total), readable without unsafe: match the DRM card by
PCI vendor and device id and cap discrete cards at min(8 GiB, 3/4 of it).
Integrated GPUs keep 2 GiB; EFFECTCRAFT_GPU_MEMCAP_MB still overrides.

Co-Authored-By: Claude <noreply@anthropic.com>

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.

2 participants