[pr-fix][memory] RESIDENT_LATER: sends and descriptor writes wait until the memory asked for is resident and mapped #57
Loading…
Reference in a new issue
No description provided.
Delete branch "Sobo/Darner:resident-later"
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?
With DARNER_RESIDENT_LATER=1, before_send() only made the queue wait on
the card for the residency fence. Being resident is not being mapped:
lists could start before new memory was mapped into the card's address
space, and the device was lost a second into the start (RTX 3090; not
with the debug layer). before_send() now waits on the sending thread as
settle() does, for the fence and then for the mapping, and only when
something asked is not settled yet.
before_send() is now called before every ExecuteCommandLists of ours in
darner-gpu that lacked it (execute_unwaited, the present copy, the
defrag counter readback, the readback engine, the upload queue, the
awake keeper, the bus rig, hwrt, and the tests), except mapped()'s own
aside queue, which is what it waits with. The stats line counts sends
that waited. Nothing changes with DARNER_RESIDENT_LATER off: nothing is
asked, and before_send() returns at once.
Co-Authored-By: Claude Opus 5.5 [email protected]
Fluxer-ID: 1577742832095989771
Contributor role (optional)
What it changes
Affects only
DARNER_RESIDENT_LATER=1(off by default).mainalready hasresident_soon,ASKED/SETTLED,settle(),wait_asked()(fence, then mapping) and abefore_send(queue)at most send sites, but thatbefore_sendonly makes the queue wait on the card for the residency fence (queue.Wait): the memory is resident then, not necessarily mapped, and that is the case that removed the device here.before_send(queue)returns at once when nothing is asked or everything asked is settled; otherwise it waits on the sending thread withwait_asked(asked)(fence and mapping), counted inLATER_STATS[5].before_sendadded at the send sites that still lacked it (host.rs: the unwaited execute, the present copy, the defrag counter read-back; alias_rt, draw, gpu_owned, gpudetile, hwrt, indirect, tiles, host/awake, host/bus, host/card_steps, host/stamps, host/upq).mapped()'s own aside queue saying why it has none (the wait itself uses it); log and doc wording "sends that waited".How it was tested
main4a92569fb(git.gtahub.st) with this patch applied. Build check:cargo clippy -p darner-gpu --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings: clean.cargo testwas not run (no Windows machine for the checks). The gameplay numbers below come from my own builds, which carried this change together with other local changes (same scene, settings and hardware before and after).darner warm --used --againwithDARNER_WARM_SHARED=1.DARNER_RESIDENT_LATER=1the device was removed at startup every time (two builds with only extra queue waits still lost it; a run with the D3D12 debug layer did not, the timing changed).Checklist
main.docs/asset-policy.md.Checked for overlap
WIP: RESIDENT_LATER: sends and descriptor writes wait until the memory asked for is resident and mappedto [pr-fix][memory] RESIDENT_LATER: sends and descriptor writes wait until the memory asked for is resident and mappedCHANGES NEEDED
Review of
57f7f22e3.If
mapped(&device)fails inwait_asked, the error is only logged atcrates/darner-gpu/src/host.rs:793-795, thenSETTLEDis advanced at line 797. This makes later sends treat the request as settled even though mapping did not complete, and prevents a retry for that sequence. Propagate the mapping failure so the send cannot proceed, or otherwise keep the sequence unsettled until mapping succeeds.Windows validation: G1 PASS; G2 PASS;
cargo xtask policyPASS (542 files ok);pooltests — 77 passed, 0 failed, 3 ignored;tiles— 16 passed, 0 failed, 6 ignored;hwrt— 21 passed, 0 failed;indirect— 40 passed, 0 failed, 11 ignored. Thegpu_ownedselector had 9 passed and 1 failed;concurrent_faults_on_same_block_serialize_single_readbackalso failed on basemain(f3840d73d), so this is not attributed to this PR.Not run in-game.
AI-assisted: yes (GitHub Copilot, Auto mode).
Tested this PR on an RTX 4070 Ti. There was no device loss, and with
DARNER_RESIDENT_LATER=1the stalls right after the world first appears were gone in my run. The first long frame stayed.Setup
mainf3840d73with this PR's head57f7f22emerged locally, built withcargo build --locked --release -p darner.made=0).Stability: one run of 22 minutes in play with the switch on, with no device loss. The
new memory not waited for until it is mappedwarning never appeared, so the error path from the review didn't run.World load (same save, similar route). "Off" is four runs of the v2026.12.03.02 release plus one of this build with the switch unset.
DARNER_RESIDENT_LATER=1(1 run)So the stall while the world appears went from about 5.5–6.5 s to 3.7 s here. The first frame doesn't come from these waits: it was the same length (3.5 s) in an earlier run with
DARNER_WAIT_RESIDENT=textures.Caveats
MakeResidentonly and prints every 1,000 waits; the deferred line includes the mapping.Checked with AI assistance (Claude Code).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.