[pr-fix][memory] RESIDENT_LATER: sends and descriptor writes wait until the memory asked for is resident and mapped #57

Open
Sobo wants to merge 1 commit from Sobo/Darner:resident-later into main
Contributor

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)

  • Fluxer ID: 1577742832095989771

What it changes

Affects only DARNER_RESIDENT_LATER=1 (off by default).

main already has resident_soon, ASKED/SETTLED, settle(), wait_asked() (fence, then mapping) and a before_send(queue) at most send sites, but that before_send only 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 with wait_asked(asked) (fence and mapping), counted in LATER_STATS[5].
  • before_send added 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).
  • A note at 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

  • Tested revision: Darner main 4a92569fb (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 test was 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).
  • Hardware and setup: i7-10700K (8 cores, 16 threads), RTX 3090 24 GB, 32 GB RAM, Windows 11; page file 128 GB; NVIDIA shader cache 100 GB; shaders prepared with the preload, then darner warm --used --again with DARNER_WARM_SHARED=1.
  • Gameplay: Series X profile (and Series S where said), DLSS quality, FSR 3 frame generation 2x, ray tracing off.
  • Before: with DARNER_RESIDENT_LATER=1 the 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).
  • After: stable through many hour-long sessions with the switch on. The wait costs 1.9-2.7 % of the list-translating threads' time in a sampling profile (city).
  • Coverage gaps: one PC only; the device loss was never captured with the debug layer (it did not happen under it).

Checklist

  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: none for the same problem. Open PRs that share files only: #3, #23, #27 (hwrt.rs), #14, #15, #17, #29 (draw.rs), #31-#49 (indirect.rs or card_steps.rs), and many that touch host.rs.
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 <!-- Thanks for the pull request. Please label it (pr-fix, pr-feature, pr-performance, pr-diagnostics, pr-refactor, pr-docs or pr-tests, plus the area labels), or put the label in the title, like [pr-fix]. --> <!-- Use Fixes #N for a complete fix or Refs #N for a partial change. --> ## Contributor role (optional) - Fluxer ID: 1577742832095989771 ## What it changes Affects only `DARNER_RESIDENT_LATER=1` (off by default). `main` already has `resident_soon`, `ASKED`/`SETTLED`, `settle()`, `wait_asked()` (fence, then mapping) and a `before_send(queue)` at most send sites, but that `before_send` only 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 with `wait_asked(asked)` (fence and mapping), counted in `LATER_STATS[5]`. - `before_send` added 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). - A note at `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 - Tested revision: Darner `main` 4a92569fb (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 test` was 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). - Hardware and setup: i7-10700K (8 cores, 16 threads), RTX 3090 24 GB, 32 GB RAM, Windows 11; page file 128 GB; NVIDIA shader cache 100 GB; shaders prepared with the preload, then `darner warm --used --again` with `DARNER_WARM_SHARED=1`. - Gameplay: Series X profile (and Series S where said), DLSS quality, FSR 3 frame generation 2x, ray tracing off. - Before: with `DARNER_RESIDENT_LATER=1` the 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). - After: stable through many hour-long sessions with the switch on. The wait costs 1.9-2.7 % of the list-translating threads' time in a sampling profile (city). - Coverage gaps: one PC only; the device loss was never captured with the debug layer (it did not happen under it). ## Checklist - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: none for the same problem. Open PRs that share files only: #3, #23, #27 (hwrt.rs), #14, #15, #17, #29 (draw.rs), #31-#49 (indirect.rs or card_steps.rs), and many that touch host.rs.
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
Sobo changed title from WIP: RESIDENT_LATER: sends and descriptor writes wait until the memory asked for is resident and mapped to [pr-fix][memory] RESIDENT_LATER: sends and descriptor writes wait until the memory asked for is resident and mapped 2026-12-03 18:33:43 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'resident-later:Sobo-resident-later'
git switch 'Sobo-resident-later'

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.

git switch 'main'
git merge --no-ff 'Sobo-resident-later'
git switch 'Sobo-resident-later'
git rebase 'main'
git switch 'main'
git merge --ff-only 'Sobo-resident-later'
git switch 'Sobo-resident-later'
git rebase 'main'
git switch 'main'
git merge --no-ff 'Sobo-resident-later'
git switch 'main'
git merge --squash 'Sobo-resident-later'
git switch 'main'
git merge --ff-only 'Sobo-resident-later'
git switch 'main'
git merge 'Sobo-resident-later'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!57
No description provided.