Repository navigation
gpu/pool/small: release pool mutex during CreateHeap block growth (D3D12-POOL-SMALL-GROW-UNLOCKED) - #2857
gpu/pool/small: release pool mutex during CreateHeap block growth (D3D12-POOL-SMALL-GROW-UNLOCKED)#2857djrolfes wants to merge 1 commit into
Conversation
|
Verified on Windows: the crate is green with it, and it adds two tests - measured against
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 And that is the interesting part of this change for that flake: 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 AI-assisted: yes - DeepSeek v4.1 (flash), one 37-second serial run. Written with an AI assistant. |
|
Independent check of 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. |
|
RUN (native Windows 10 + RTX 5070 verification; #2857, #2860, and #2862 merged cleanly together onto
GPUs tested: NVIDIA GeForce RTX 5070 12 GB (driver AI-assisted: Antigravity |
|
Verified by MoonEyes (another person than the author) on head In-game run with the six others of a batch on AI-assisted (Claude Code). |
|
I followed up on the mock allocator test with a real D3D12 heap handoff check at 2451b47 + 0ff8a53. 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). |
KelboLive
left a comment
There was a problem hiding this comment.
Approved (non-blocking). The lock scope is exactly as claimed: small.rs:118 takes from free memory without grow, the miss path takes grow (:123), re-checks (:124), runs make() with only grow held (:129), then re-adds under pool (:130-137). Because pool is declared after _grow, the block is published before a waiter can acquire grow, so the double-check cannot duplicate a 64 MiB heap. returned() keeps the back→pool order and room() only try_locks pool, so there is no inversion; the failure arm mirrors Pool::grow's 500 ms backoff (:139-141).
Both new tests are meaningful, not just existence checks: holding the pool guard across make() makes growth_unlocks_the_pool_and_concurrent_misses_share_one_block fail at its try_lock assertion (small.rs:412) — I verified that locally. pool::small is 5/5, ten consecutive growth runs are green, and the merged tree with current main builds and passes.
Two optional consistency follow-ups: Small has no LEONIDA_POOL_GROW_UNLOCKED=0-style switch back to under-lock growth, unlike pool.rs, and grow.lock() waits are not counted in the diagnostics LOCK_WAITS that pool.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.rs and pool.rs are byte-identical upstream.
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).