d3d12-gpu: pack Pool allocations into the fullest live ripe block so sparse and draining blocks reclaim (D3D12-POOL-PACK-FULLEST-BLOCK) #3302
Labels
No labels
accessibility
area: ci
area: d3d12
area: docs
area: launcher
area: runtime (legacy)
area: shader translator
area: tools
area: viewer
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs in-game run
needs rebase
needs-triage
question
ready-for-agent
submodules
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida#3302
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@lixonik on GitHub · 2026-12-03 06:27 UTC · original
Summary
Addresses #3261 (and complements #3201 and #3296 with zero overlapping edits).
Pool::take_or_need(shared byTEXTURES,STAGING, andpool::smallupload/shared 64 MiB blocks) scannedself.blocksin ascending index order and allocated from the first ripe block with room. As idle textures/buffers were evicted and low-index blocks became empty, draining (inRESTcooldown), or sparse, new allocations immediately re-pinned those low-index blocks instead of packing into fuller live blocks -- stranding live resources thinly across many 64 MiB heaps soreclaim()could never observewhole(BLOCK)and hand them back to D3D12/Windows.d3d12/crates/leonida-gpu/src/pool.rs):free_bytesonRangeswith read-onlyfind(len, align)(O(1)free_bytes < lenguard +checked_add) andtake_at(range_start, at, len).live_bytesonBlock<B>(incremented on allocation across both ripe and unripe paths; decremented immediately ingive_atwhen a piece is returned, before theRESTcooldown).(tier, live_bytes, BLOCK - free_bytes, Reverse(index)):live_bytes > 0): pack tightly into the fullest live ripe block first, leaving sparse blocks untouched so they drain naturally.live_bytes == 0,!whole(BLOCK)): draining block with resting pieces (only touched if no live block fits, avoiding unnecessaryaheadgrowth and keeping empty blocks reclaimable).whole(BLOCK)): empty ripe block (lowest index), touched only when neither live nor draining blocks fit.key <= best_key) in O(1) before touchingBTreeMap. PreservesRipepage-fault safety (ripe.is(block)and oldest-first unripe fallback).Verification
Unit Tests (
red -> green, Windows 10 x64, RTX 5070 12 GB, driver 595.79)d3d12/crates/leonida-gpu/src/pool.rs:new_pieces_pack_into_fullest_live_block_and_let_sparse_blocks_draindraining_block_with_only_resting_pieces_is_not_repinned_while_live_block_fitsleft: 0, right: 2andleft: 0, right: 1-- first-index allocation poisoned empty and draining block0).cargo test -p leonida-gpu --lib --locked pool::-> 23 passed, 0 failed (covers bothpool::testsandpool::small::tests).python -I scripts/check_no_game_data.py-> PASS.cargo build --profile diag --features "diagnostics,dlss,mimalloc" --locked-> PASS.APPROVE).RUN (in game, RTX 5070 12 GB, 315 s in-world gate) -- PASS
0bb75e0baonmaind9b618f10-SeriesS -NoFrameGen, same restored save snapshot0bb75e0baond9b618f10)315 s(438.2 s)65(5,450)0/0/027.0 fps(37.0 ms)23.1/27.9main(d9b618f10)315 s(430.8 s)64(7,828)0/0/027.0 fps(37.1 ms)20.2/27.9AI-assisted: Antigravity (Gemini 4 Neon; separate read-only reviewer subagent: Antigravity Pro preset / Gemini Pro)
Pull request details or commits were not available from GitHub; kept as an issue.
@fiestorra on GitHub · 2026-12-03 06:29 UTC · original
VERIFY-3302 — 717/1 (el 1 es la iGPU), cero tests nuevos, y el cambio es de empacar bloques
717 contra los 715 de
main— dos tests que su base trae y quemainno, no dos que este PR añada (medido en el diff: cero#[test]nuevos). La distinción es la lección de esta tarde y aquí se ve el caso al revés: un número más alto que no significa lo que parece.El título: «pack Pool allocations into the fullest live ripe block so sparse…» — empacar las reservas del
Poolen el bloque vivo más lleno, que es una decisión de colocación y no de asignación. Y en el asignador, una decisión de colocación es donde vive la fragmentación: dos estrategias que asignan lo mismo pueden dejar huecos distintos, y el hueco es lo que se ve como «memoria que no se libera».Lo que no trae, y por qué importa más que en otros: un asignador es de las pocas piezas donde la prueba correcta no necesita GPU — se le da una secuencia de reservas y liberaciones y se mira dónde quedaron. 151 líneas sin un
#[test]enpool.rs, que ya tiene tests, es la omisión que le señalaría al autor — no porque el cambio esté mal, sino porque el sitio donde está sí permite probarlo.Lo que verifiqué: la suite completa del crate con el cambio, y que el único fallo es el conocido.
Lo que no: la fragmentación de verdad bajo el juego — que necesita una sesión larga y una medida de memoria, y en este repositorio eso es una fila de
gpu-test-results/.@lixonik on GitHub · 2026-12-03 06:39 UTC · original
Thanks @merzleckeier and @fiestorra for the fast verification!
@merzleckeier: Appreciate you testing the#3302+#3201merge (24/24 pool tests) and the#3261two-block scenario, as well as measuring the 234-block microbenchmark (456 -> 490 nson the texture-pool path withahead). Good point on trackingLOCK_WAITSalongside block counts in any longer city-driving churn run.@fiestorra: Quick note -- the715 -> 717jump (+2 tests) is actually from the two new#[test]functions added in this diff (d3d12/crates/leonida-gpu/src/pool.rs:1071-1139:new_pieces_pack_into_fullest_live_block_and_let_sparse_blocks_drainanddraining_block_with_only_resting_pieces_is_not_repinned_while_live_block_fits), which are bothred -> greenagainstd9b618f10.AI-assisted: yes (Antigravity -- Gemini 4 Neon).
@MoonEyes on GitHub · 2026-12-03 06:47 UTC · original
RUN (in game, batch of four pull requests), each head merged with
git merge --no-ffonto maind9b618f10, in one build: #2851488416598, #3299898b87802, #3301670df262b, #33020bb75e0ba. RTX 4060 8 GB, driver 610.88, Windows 11. Series S,-Resolution 1080, frame generation 2x,-PrecompileUsed, the same walking route as the other runs on this machine, 330 s after reaching the world.For reference, the same machine and route rendered 13.3 to 17.2 fps on other batches in the last day. These fps are a check that nothing fell over, not a measurement of a gain.
Verdict: PASS for the in-game gate (300 s or more in the world, no device loss) for this batch, on the heads listed above. If one of these pull requests changes its head, this run no longer covers it.
Limits: one run; arrival in the world was driven by keys and not checked on pictures;
-PrecompileUsedwas used, so the default start (every known pipeline precompiled) was not exercised. #2851 was in an earlier batch on another head; this run covers its current head, withLEONIDA_TITLE_MEMORY_SCALEunset. #3299's switch is opt-in and hardware ray tracing was not on in this 8 GB profile, so it was not exercised. #3302 changes where Pool allocations go by default; this run shows nothing fell over with it, not whether it saves memory. #3301 only reports failures; none was provoked. The precompile before the world took 468 s against about 155 s for most batches: something in this batch leaves the pipeline cache cold (not looked into).AI-assisted (Claude Code).
@merzleckeier on GitHub · 2026-12-03 07:19 UTC · original
I followed up on
LOCK_WAITSwith the exact allocator and diagnostics lock code fromd9b618f1and0bb75e0b. Six workers pinned to distinct Ryzen 7 7800X3D cores each took and immediately returned 65,536 pieces. The fixture kept one empty spare, asserted both heads chose the same block, and never grew the pool. These are medians of three interleaved runs per arm.The heavily loaded 234-block staging case is a stress test. Its lower event count comes with longer aggregate waiting, so both measures are worth retaining in the #3261 trace. This was CPU-only on Linux, using synthetic block handles and no game files or driver calls. AI-assisted with OpenAI Codex.
@x2Tweek on GitHub · 2026-12-03 07:53 UTC · original
RUN (in game, RTX 5090 32 GB, hardware RT on): PASS, 0 device losses. Fewer blocks, about 1.2 GB less texture memory in blocks, reproducible over two pairs.
0bb75e0bamerged withgit merge --no-ffontomaind9b618f10(merge8ac31fbef, clean). No other changes.maind9b618f10plus one local BLAS buffer pool, switched off (LEONIDA_HW_RT_AS_POOL_MB=0). It does not touchpool.rs.diagnostics,dlss,mimalloc.-HardwareRT -SmoothMotion -PrecompileAll -Log,LEONIDA_D3D12_DRED=1.main, run 1main, run 2AI-assisted: the builds, the automated runs, the log reading and this write-up were done with Claude Opus 5.5 (Claude Code); the numbers are the runtime's own log lines.