d3d12: blocks of textures and staging buffers are made with their pool's lock released (D3D12-POOL-GROW-UNLOCKED) #2693
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2693"
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 TheGeogeo on 2026-11-30T04:17:36Z.
Claimed in the coordination issue as: D3D12-POOL-GROW-UNLOCKED (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7268138898)
What and why
On
main, the texture pool and the staging pool make a new 64 MiB block while they hold the pool's mutex:lock(&TEXTURES).take_ripe(.., || CreateHeap + MakeResident + wait for the mapping);lock(&STAGING).take(.., || upload_buffer(BLOCK)).With blocks made ahead (
LEONIDA_RIPE_BLOCKS, 12), a block is made each time one is begun. While it is being made, everything else that takes the same mutex waits:release->give);texture_room(), which the residency policy (resource.rs) and the once-a-second sweep read;This change:
Pool::take_or_needfinds a piece, or says that a block has to be made first. It never makes anything.take_unlockedmakes the block with the lock released, then adds it.texture_room()reads a block count kept next to the pool and takes no lock.LEONIDA_POOL_GROW_UNLOCKED=0keeps the old path.diagnostics, the memory line now also reports the blocks made and their time, and the waits for the pools' locks and for blocks being made.The callers of
pool::texture/pool::stagingare unchanged. The two call sites only change the function they call.Tested
On Windows 11, from
d3d12\:pool::tests:the_room_in_texture_blocks_is_read_without_their_lock: fails onmain(texture_room()waits for the lock held by the test) and passes with the change;a_piece_or_a_block_to_make_first,a_block_is_made_with_its_pools_lock_free,threads_wanting_room_wait_for_the_block_being_made(four threads that each need an eighth of a block make one block),a_block_that_failed_is_not_made_again_at_once,a_maker_that_panics_leaves_no_one_waiting.cargo test -p leonida-gpu --locked: 558 passed, 49 ignored. Thepooltests also pass with--features diagnostics.cargo clippy -p leonida-gpu --all-targets --locked --features diagnostics: nothing in the changed lines.git diff --checkandcheck_no_game_data.pyare clean.MakeResidentand the mapping wait are no longer nested inside it. Its other findings are fixed in this change.build-nvidia.ps1,diagnostics,dlss,mimalloc) built.texture), #2569 (staging's signature; that pull request's own conflicts withmainare elsewhere) and #2692 (git merge-tree).=0(old path)=0(old path, cutscene cut short at 69 s)How to read it:
Limits of this measurement:
GPUs tested: NVIDIA GeForce RTX 3080 10 GB, driver 32.0.16.2140, Windows 11 Pro 10.0.26300.
AI-assisted: yes
Checklist
mainand merges cleanly (also with #2660, #2569 and #2692).docs/design.md, with how it was confirmed. (Not applicable: no translator change.)Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-30T04:31:43Z.
Independent native Windows 10 check of
c78140d110d141d874076af301b6bf9a29816113merged locally into1d22590b9fb5c0f51a6a7c0405f1f136e0696c0d. Windows 10 22H2 build 19045, Ryzen 9 5950X, Rust 1.98.1 MSVC.cargo test --locked --offline --profile diag -p leonida-gpu --features diagnostics --lib pool::testsreported 14 passes. In a follow-up focused on CPU coverage, all 13 host-independent pool cases passed with four test threads. The four-request contention case separately passed in five fresh processes, each asserting exactly one block creation and no overlapping ranges. The lock-free room reader, growth-failure backoff and panic cleanup fixtures also passed.This checks the pool's synthetic allocation and synchronization behavior. The GPU-only test can return early on setup, so I did not count it as verified driver-side growth. The no-game-data check passed on both changed files.
AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T07:13:51Z.
Independent check on Windows 11 (Rust toolchain from
d3d12/rust-toolchain.toml, CPU only, no game run). Headc78140d11merged (no commit) intomainbbd45f5cc:cargo test -p leonida-gpu --lib --locked:main559 passed, 50 ignored; with this PR 565 passed, 0 failed (the 6 new tests pass).pool.rswith the code they test.cargo clippy -p leonida-gpu --locked -- -D warnings: 9 findings onmain, the same 9 with this PR.mainand does not force a rebase of #2566.AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-30T07:19:22Z.
The
semantic-testsfailure here is not from this change, which only touches Rust files underd3d12/. The same test,test_interp_computed_ij_fallback(ComputedIJDerivativeFallbackTests), also fails in CI onmain(run 46365003804). The other checks pass.Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-30T09:01:53Z.
Independent Wine A/B for
c78140d110d141d874076af301b6bf9a29816113locally merged intomaindcba958e52efe681343fc25bbb9706b40420e222. CachyOS, Wine 11.22, VKD3D-Proton 3.1.0, Rust 1.98.1 MSVC (diag,diagnostics,pool::, one test thread). Tested on an RTX 4070 SUPER (NVIDIA 620.73.04) and Radeon 610M (RADV 26.3.1), selecting each Vulkan ICD separately.On each GPU,
mainpassed 11/11 pool tests. The PR passed 17/17 with the variable unset and 17/17 withLEONIDA_POOL_GROW_UNLOCKED=0.A separate synthetic D3D12 probe called
take_stagingwith real mapped upload buffers. It left exactly 64 KiB free in a 64 MiB block and held an 8 MiB request's growth closure at a channel gate. A second thread's 64 KiB request completed before release with the default setting on both GPUs. WithLEONIDA_POOL_GROW_UNLOCKED=0, it completed after release on both. In every run the 64 KiB allocation used the tail of block 0, the 8 MiB allocation used offset 0 of block 1, andGetDeviceRemovedReasonreturned success. This checks the ordering under controlled contention. The runs used synthetic buffers and covered no in-game timing.I also reproduced the reported F16 semantic failure on
dcba958e5(7/9 passed) and confirmed 9/9 with the existing test-only fix #2633 (71db4c405) applied to that same base.AI-assisted: yes (Codex).
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T11:36:12Z.
RUN - in-game gate (Verified by OreoFR), PROVISIONAL - RTX 4070 Laptop 8 GB, NVIDIA 621.40, Windows 11.
e1fe82f63; B = main + this PR atc78140d11(git merge --no-ff), diag build ofleonida.exe.play-d3d12.ps1 -SeriesS -NoDlss -NoFrameGen, BAR 0, texture budget 1024, standing in the world, warm pipeline cache, 600 s per run. Runs interleaved with main.Result: PASS - 0 device loss, 0 panics, every run alive at the end (653-668 s of world frames).
LEONIDA_POOL_GROW_UNLOCKED=0(one run, 21.2 fps): 124 ms in total, longest 13.7 ms, over 910 waits.This run was AI-assisted (Claude Code, oreofr-agent).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T11:47:20Z.
@TheGeogeo the in-game gate on an RTX 4070 (OreoFR, above) passes on this head, and the only red check is
semantic-tests, which comes from the older base (fixed onmainby #2566). Could you merge currentmaininto this branch (a merge, no rebase or force-push) so CI runs again? Merging needs a fully green CI.AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T12:08:15Z.
Closing and reopening so that CI runs against current
main: the only red check here (semantic-tests) comes from the older base. The head does not change, so the verdicts above still stand. @TheGeogeo no need to update the branch if this is enough.AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T13:42:51Z.
Verified by MoonEyes on head
6619d9294(a merge ofmainon top ofc78140d11; the pull request's own change is the same), onmainf9f3ec4c6. Windows 11, Rust toolchain ofd3d12/rust-toolchain.toml.cargo test -p leonida-gpu --lib --locked:main563 passed, 52 ignored; with this pull request 569 passed, 0 failed. Red: not separable (tests and code are in one file).-SeriesS -FrameGen 2, standing, 600 s,main+ #2692 + #2693 + #2701 in one build: no device loss, no unhandled exception, median 17.8 fps in the world. One run, the three together, so it says nothing of this one's gain; the picture was not looked at. OreoFR's numbers on the previous head stand for the lock waits.AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T13:43:39Z.
Merging. Head
6619d9294merges cleanly withmain3c07d1677and does not force a rebase of #2566. Verdict and a 600 s in-game run on this head above; OreoFR's gate on an RTX 4070 (lock waits 5-10 ms a run against 124) and lixonik's, merzleckeier's checks were on the head before main was merged in. Its CI is green. main's Runtime workflow is red for a known reason (macos, ps_exp_f32_denorm_rt); merging green pull requests meanwhile is agreed with aslan2142. Merged by MoonEyes.AI-assisted (Claude Code).