gpu/pool/small: release pool mutex during CreateHeap block growth (D3D12-POOL-SMALL-GROW-UNLOCKED) #2857
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2857"
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?
Imported from ubiquitarianism/leonida. Originally posted by djrolfes on 2026-12-01T10:02:49Z.
Claimed in the coordination issue as:
D3D12-POOL-SMALL-GROW-UNLOCKED(claim comment)What and why
Release the
Smallbuffer pool mutex (Small::pool) while creating and making resident a new 64 MiBID3D12Heapblock ind3d12/crates/leonida-gpu/src/pool/small.rs— direct companion to merged PR#2693(D3D12-POOL-GROW-UNLOCKED, which unlocked growth for texture and staging pools inpool.rsbut leftpool/small.rsholdingsmall.pool()acrossblock(device, kind)).grow: Mutex<()>toSmalland extractstake_with, reusingsuper::Pool::take_or_need,super::Pool::add, andsuper::Pool::growth_failedfrompool.rs:backand callstake_or_need(..., Ripe::ALL)without takinggrow, so threads taking free/returned pieces never wait behind a concurrentCreateHeap/MakeResident.grow, double-checktake_or_need(so concurrent misses share a single newly created block and respect failed-growth backoff), drop thepoolmutex, invokemake(), and then re-acquirepoolto add the new block (or recordgrowth_failed).KEPT = 2unchanged (zero VRAM/retention policy change).d3d12/crates/leonida-gpu/src/pool/small.rs+pool.rs#2693) + race-free deterministic multi-threaded unit tests verified red→green under Wine + MEASURED 300 s in-game gate on exact PR head2451b4744.Tested
python3 -I scripts/check_no_game_data.py d3d12/crates/leonida-gpu/src/pool/small.rs→ exit 0.cargo check --locked --target x86_64-pc-windows-msvc -p leonida-gpu --features diagnostics→ 0 errors, 0 warnings inpool/small.rs.leonida-gputest binary (x86_64-pc-windows-msvc) and ran under Wine:origin/main(testingorigin/main's lockedpool.takewithassert!(pool.try_lock().is_ok(), "heap creation must not own the pool lock")):2451b4744(rebased ontocd73ddab7):pool::small::tests:5 passed; 0 failed; 0 ignored(includinggrowth_unlocks_the_pool_and_concurrent_misses_share_one_block, verified 10/10 consecutive runs).pool::tests:14 passed; 0 failed; 0 ignored.docs/game_gate.md) on exact PR head2451b4744(leonida.exe--profile play --features mimalloc,dlss,diagnostics, Series S + DLSS Quality 1280×720 → 1920×1080):310.04 s(world_at_s = 77.49 s,>= 300 srequired)world + 60 sto stop):3,108presented frames (3,206total world presents),15.20median FPS,115.53 msp95 frame time (15.53end-window median FPS,4,372median draws/frame)3.884 s(<= 10.0 srequired)6,717 MiB(<= 7,400 MiBguard)0device losses,0crashes/faults,0panics,0kernelNVRM: XiderrorsGPUs tested: NVIDIA GeForce RTX 3070 Ti 8 GB, driver 620.73.04, Arch Linux (Wine 11.22 + VKD3D-Proton 3.2.0).
AI-assisted: yes (authored by Gemini 4 Neon; audited and approved in a separate independent review pass by Gemini 4 Neon).
Checklist
main(cd73ddab7) and merges cleanly.check_no_game_data.pyclean).docs/design.md(n/a — GPU small-buffer pool locking change).2451b4744).Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-01T10:09:52Z.
Verified on Windows: the crate is green with it, and it adds two tests - measured against
main's own file. Run on one thread on purpose.main3393ceec9, cherry-picked (one commit,merge-basecd73ddab7),cargo 1.98.1:Why one thread: this crate's tests interfere with each other when they share a process - sixteen runs with the default threads failed twice and eight with
--test-threads=1failed none (#2570). Existence control, not mutation: I did not remove the mutex release to watch a specific test fail.And that is the interesting part of this change for that flake:
pool/small.rsis a shared pool behind a mutex, which is exactly the shape that bites in parallel. 603 passing on one thread says the change is correct; it says nothing about whether it makes anything faster, because the property it is for - not holding the mutex acrossCreateHeap- is a timing property and this is a correctness run.What I could not test: the latency it is for. The best I can say is that the tests that do use the pool still pass, and the crate has a
--test-threads=1story it did not have this morning.AI-assisted: yes - DeepSeek v4.1 (flash), one 37-second serial run.
Written with an AI assistant.
Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-01T12:00:04Z.
Independent check of
2451b4744on21e6bbf4b, with #2854 and #2855 also applied. Both new pool tests passed in the Windows test binary under Wine. In a separate build, moving the pool lock back aroundmake()madegrowth_unlocks_the_pool_and_concurrent_misses_share_one_blockfail at the lock assertion. This verifies that the fixture catches the old lock scope.The new pool cases use a stub allocator. The surrounding test selection ran on AMD Raphael (RADV 26.3.1) and RTX 4070 SUPER (NVIDIA 620.73.4). Driver allocation latency was outside this run.
AI-assisted with OpenAI Codex.
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-12-01T14:01:50Z.
RUN (native Windows 10 + RTX 5070 verification; #2857, #2860, and #2862 merged cleanly together onto
mained867d7b2)cargo test --locked -p leonida-gpu --lib pool::small:5 passed, 0 failed.Series S,-NoFrameGen,731.6 scold precompile,180 sin world (321.3 stotal,38world samples>= 1000draws, median22.2 fps/45.1 ms,gpu_wait 0.0 ms,4,424median /5,346max draws):0crashes,0panics,0device-lost events.GPUs tested: NVIDIA GeForce RTX 5070 12 GB (driver
621.40, Windows 10 Pro 22H2 build 19045, Ryzen 9 5950X 16C/32T)AI-assisted: Antigravity
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-01T15:19:08Z.
Verified by MoonEyes (another person than the author) on head
2451b4744merged withmaincd0c52fcf: I read the whole diff.cargo test -p leonida-gpu: the only failure seen,committed_and_placed_r32_uint_textures_cast_to_r9g9b9e5_under_legacy_barriers, fails in 2 of 5 parallel runs of plainmaintoo. With the pool's lock held aroundmake(),growth_unlocks_the_pool_and_concurrent_misses_share_one_blockfails.In-game run with the six others of a batch on
main21e6bbf4b: RTX 4060 8 GB, NVIDIA 610.88, Windows 11 26300,-SeriesS -FrameGen 2, about 860 s in the world, then a second one of about 440 s, 0 device lost, 0 panic; pictures of the same scene compared withmain, same. Black surfaces in early cutscenes while the PC's memory is full are there on plainmaintoo.AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-01T15:34:36Z.
I followed up on the mock allocator test with a real D3D12 heap handoff check at
2451b474+0ff8a532f. On Radeon Raphael (RADV 26.3.1) and RTX 4070 SUPER (620.73.04), Win64 under Wine 11.22, I filled a real 64 MiB upload block with sixteen 4 MiB pieces. The growth thread made a second block through production block(), then waited inside make() before publishing the new block. A second worker reused the exact returned piece and its original heap while growth was still parked. The new block was distinct, and the stock GPU copy/reuse test and the rest of the small-pool selection passed (6/6 including the local fixture on each GPU).As a negative control I moved the pool lock back around make(). On RADV the same fixture timed out waiting for the returned piece before growth was released. The controlled pause is after the real driver allocation, so this checks lock scope and reuse during growth, without measuring natural driver latency. MEASURED with offscreen synthetic allocations. AI-assisted (Codex).
Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-01T17:44:11Z.
Review: COMMENTED
Approved (non-blocking). The lock scope is exactly as claimed:
small.rs:118takes from free memory withoutgrow, the miss path takesgrow(:123), re-checks (:124), runsmake()with onlygrowheld (:129), then re-adds underpool(:130-137). Becausepoolis declared after_grow, the block is published before a waiter can acquiregrow, so the double-check cannot duplicate a 64 MiB heap.returned()keeps theback→poolorder androom()onlytry_lockspool, so there is no inversion; the failure arm mirrorsPool::grow's 500 ms backoff (:139-141).Both new tests are meaningful, not just existence checks: holding the pool guard across
make()makesgrowth_unlocks_the_pool_and_concurrent_misses_share_one_blockfail at itstry_lockassertion (small.rs:412) — I verified that locally.pool::smallis 5/5, ten consecutive growth runs are green, and the merged tree with current main builds and passes.Two optional consistency follow-ups:
Smallhas noLEONIDA_POOL_GROW_UNLOCKED=0-style switch back to under-lock growth, unlikepool.rs, andgrow.lock()waits are not counted in the diagnosticsLOCK_WAITSthatpool.rs::lock()feeds.Not independently verified here: the 300 s in-game run and the claimed latency win (no game data), and the Wine/VKD3D driver timings. Unit and device tests only. Merge is clean; 383 commits behind, but both
small.rsandpool.rsare byte-identical upstream.Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-12-01T23:09:37Z.
In-game RUN of head
2451b4744, merged with #2852 (c4e286fdf) onto main1abef08d0(tree 32b6b8c23). RTX 4070 Laptop 8 GB, NVIDIA 621.40, Windows 11, -SeriesS -NoDlss -NoFrameGen.cargo test -p leonida-gpu --lib --locked: 647 passed, 0 failed.AI-assisted: Claude Code (oreofr-agent).
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-12-01T23:12:26Z.
Merging (added to the merge queue). Head
2451b4744merges cleanly with main913b88b90; since my test main gained only #2973, #2858, #2882, #2788, #2876 and #2884, none of which touches this pull request's file. Claim: D3D12-POOL-SMALL-GROW-UNLOCKED (coordination issue #2570). Red/green: merzleckeier (real 64 MiB D3D12 heap handoff under Wine on RADV and RTX 4070 SUPER), KelboLive review on this head (lock scope checked line by line), MoonEyes, fiestorra and lixonik earlier. I ran: #2857 and #2852 together on main1abef08d0, leonida-gpu 647 passed / 0 failed, and a 900 s warm in-game run on an RTX 4070 Laptop (621.40): 0 device lost, private memory flat at 24.0-24.3 GB (details in my RUN comment above). CI: green on head and main; the queue runs the full CI before merging. AI-assisted: Claude Code (oreofr-agent), merge approved in writing by OreoFR.Imported from ubiquitarianism/leonida. Originally posted by EdenBendheim on 2026-12-01T23:17:04Z.
Independent native Windows 11 + RTX 3090 verification (
VERIFY-2857-RTX3090, claimed in #2570): PASS2451b4744merged cleanly ontomainc4ca57615(diagnostics,mimalloc,exe_sha16:b37ba94a1ad2a01e).610.88).python -I scripts/check_no_game_data.pypassed onpool/small.rs.cargo test -p leonida-gpu --locked --lib -- pool::small::tests --test-threads=1):--features diagnostics): 5 passed, 0 failed in both configurations. (Transplanting the tests alone ontomainfails to compile because they call the newtake_withhelper.)scripts/game-gate.ps1, Series X 1080–1440p,-NoFrameGen,gate_drivermode=roam+LEONIDA_GAME_ACTIONS_RUN="120:wanted 2", same free-roam template asmainbaseline):PASS(reasons=[],warnings=[],exit=clean,stop=target,cache_saved=true,GATE CONTROLfired withmoved=1.16 m, maxfrom_control_m=2.7 m,0GATE FAIL).world_s=301.6s,world+60s, 5,572 presents, 7,176 median draws):23.08 FPSmedian,18.83 FPSp5,53.10 msp95 frame time,2.479 slongest present gap,0missed pipeline waits,26,375 MBmax private memory,2,540 MBmin commit left,8,211 MBmax VRAM (0 sover budget).mainc4ca57615roam +wanted 2baseline (exe_sha16:94748f45e468665a, max displacement8.7 m):PASS(300.9 s,22.29 FPSmedian,54.13 msp95,2.851 slongest gap,7,450median draws). (Single-run stability gate; not an ABBA FPS claim.)AI-assisted: yes (Gemini 4 Neon orchestrator; Codex GPT-6.2 Astra build, unit tests, and serialized RTX 3090 gate execution).
Imported from ubiquitarianism/leonida. Originally posted by imShangLi on 2026-12-02T00:19:28Z.
VERIFY-2857 — Linux, Fedora 45, Rust 1.98.1 (the pinned toolchain), Wine 11.21, no GPU device, no game files
Verdict: PASS. The pool no longer holds its lock across the driver's heap creation, the new test checks exactly that, and nothing that passed before fails now. One test failed once in a full run; it fails on the base at the same rate, so it is not this pull request's doing.
Head
2451b474, base the currentmain, merge basecd73ddab, 1 file, +145/−8:d3d12/crates/leonida-gpu/src/pool/small.rs.1. What it changes
The small-buffer pool kept its mutex across
CreateHeap— the driver's call, which is the slow part — so a miss blocked every other user of the pool, including the ones that only wanted an existing piece. The change splits the two: the pool's lock is taken to look for a piece and released again, and a separategrowmutex keeps the misses among themselves:The second lookup is what keeps two concurrent misses from each creating a block: the second one finds the first one's block.
2. The new test checks the property that matters
The test parks a growing worker inside
make()while six other threads wait, and asserts that the pool's lock is free at that moment — that is the pull request's whole point, and it needs no device: the pool holdsu32s, not real heaps.3. What the tests do here
leonida-gpudoes not build on Linux (upstream: "The crates are Windows-only today … Linux follows #2577"), so I cross-compiled it forx86_64-pc-windows-gnuand ran the tests under Wine 11.21.The red side (the merge base with only this pull request's tests) does not compile — the new test calls
take_with, which the change introduces — so the base and the head were compared instead:watch::many_askers_tests::holes_are_known_until_the_runtime_tells,watch::many_askers_tests::no_mapping_is_lost_between_askersandwatch::tests::what_is_left_alone_is_no_known_hole4. The one failure I saw, and why it is not this pull request
watch::tests::a_block_just_written_restsfailed in one full-suite run on the head and passed on the base, which looks like a regression. It is a flake, and it is not this change's:The base fails it at the same rate, so I do not attribute it to the pull request. It is one of the
watchtests that depend on Microsoft'sVirtualAlloc/VirtualQuerybehaviour, which Wine does not have.5. What I did not check
make; the realCreateHeap(which can take milliseconds) was not exercised, and neither was the driver's own behaviour under the released lock.CreateHeapcan make two misses each create a block. The second lookup under thegrowlock is meant to prevent it; I read it, I did not stress it.AI-assisted: MiniMax M3.1 Flash.