Repository navigation
fix(gpu): by_address leaks its cap and inflates WINDOW_CARD_BYTES - #2981
Luislariosss wants to merge 1 commit into
Conversation
by_address() kept its card-memory cap in a function-local USED counter that was incremented on every attempt, including over the cap and when uav_buffer() returned None, and was never decremented when the arena went: cap headroom leaked for the rest of the session. It also added every arena, card or PC fallback alike, to WINDOW_CARD_BYTES. - BY_ADDRESS_USED: a single counter, reserved with fetch_update and checked_add and rolled back only when the allocation fails; released on drop. - Card::account (CardAccount) picks the counter Drop releases, so a shadow cannot be in two accounting buckets at once. - by_address no longer touches WINDOW_CARD_BYTES; BY_ADDRESS_USED is included in live_span_bytes() and card_stats(). - Behaviour: by-address arenas no longer eat LEONIDA_CARD_WINDOWS_MB nor the window room kept in card_room_kept(), and PC-memory fallbacks drop out of the span and the card stats. - Tests: cap boundary, u64 overflow, rollback, all four accounts on release and drop; land_tests now balances CARD_BYTES[0]; the shared counter tests take one lock so they can run in parallel.
|
Verified the cap and fallback through by_address() with actual D3D12 allocations on an RTX 5070, driver 616.92, at b020637. I set LEONIDA_MEMORY_CARD_MB=1 in a fresh process and requested three 1 MiB arenas backed by distinct synthetic CPU ranges. The first arena used card memory. The second used the shared fallback while the first was held. Dropping the first returned BY_ADDRESS_USED, live_span_bytes() and card_stats()[8] to zero even with the fallback still live. The third arena then used card memory. Dropping the fallback left all three counters at 1 MiB, and dropping the third returned them to zero. WINDOW_CARD_BYTES stayed zero throughout. I checked the actual CardAccount selected for each allocation and resolved the card name from the D3D12 device LUID. This covers exact-cap allocation, fallback, and reuse on hardware. The test used small allocations to exercise the configured cap. Codex-assisted for #2570. |
|
Real by-address allocations regain the device heap after dropping the previous allocation. I called production
With the first two live, main added 1,310,720 bytes to both window and total live-span accounting. The PR added zero window bytes and counted 1,048,576 bytes in the aggregate. Oversized shared fallback added no card bytes on the PR, and all deltas were zero after drops. The three stock by-address tests passed on each GPU. The test uses actual D3D12 resource heap properties at a small configured cap, with the separate DXGI video-memory budget check satisfied. AI-assisted, independently checked against the raw results. |
Claimed in the coordination issue as: D3D12-GPU-BY-ADDRESS-ACCOUNTING (#2570 (comment))
What and why
shadow::by_address()kept the card-memory cap (LEONIDA_MEMORY_CARD_MB) in a function-localUSEDcounter:uav_buffer()returnedNone, so headroom leaked for the rest of the session;WINDOW_CARD_BYTES, so by-address copies ateLEONIDA_CARD_WINDOWS_MBand the window roomcard_room_kept()keeps for real windows.This moves the counter to module scope (
BY_ADDRESS_USED), reserves it withfetch_update+checked_add(rollback only when the allocation fails) and releases it on drop.Card::account(CardAccount) picks which counterDropreleases, so a shadow cannot be in two accounting buckets at once. By-address arenas no longer touchWINDOW_CARD_BYTES;BY_ADDRESS_USEDis included inlive_span_bytes()andcard_stats().Behaviour change, both behind opt-in switches: by-address arenas no longer consume
LEONIDA_CARD_WINDOWS_MBnorcard_room_kept(), and PC-memory fallbacks drop out of the span and the card stats.Tested
cargo test -p leonida-gpu --offline --lib -- --test-threads=1: 647 passed, 0 failed, 59 ignored.cargo test -p leonida-gpu --offline --lib --features diagnostics -- --test-threads=1: 728 passed, 0 failed, 59 ignored.cargo clippy -p leonida-gpu --all-targets --offline: clean (one pre-existing warning outside this file).New tests: cap boundary (
used + len == most),u64::MAXoverflow, rollback, all fourCardAccountvariants on release and drop;land_testsnow balancesCARD_BYTES[0]; the shared counter tests take one lock so they can run in parallel.GPUs tested: n/a (unit tests only; no in-game run).
AI-assisted: yes — implementation and review by coding agents, reviewed by the submitter.
Checklist
mainand merges cleanly (rebased onc4ca5761).