Memory waits: told apart by kind and thread, mapping copies waited for together, upload buffers not waited for #630

Open
0xkn0wh3r3 wants to merge 5 commits from upstream-pr/630 into main
0xkn0wh3r3 commented 2026-11-28 02:05:19 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by 0xkn0wh3r3 on 2026-11-28T02:05:19Z.


Why

A 9-minute play log (16 GB RTX card) had 52,000 MakeResident waits for 27.3 s, the longest 1,128 ms while a scene loaded with the card at 10 GB, and 48,000 mapping copies waited for, 7.2 s. Each was one number for every thread. That included the thread that makes buffers ahead (crate::ahead, 8,000 buffers in the first 6 s), whose waits no frame stands for, so the log could not tell stalls from background work. mapped() also held one lock for its whole GPU round trip, so a frame's thread that made a texture or a card buffer waited behind that low-priority thread.

What

  • The waits told apart. A new 5-second line says which kind of new memory was waited for (upload, shared and card buffers, textures of their own, texture blocks, depth twins), by which thread, and how much of a mapping wait was another thread's lock.
  • Mapping copies waited for together. mapped() holds its lock only while it sends its copy. The copy comes from a ring of 8 lists, each sent again only once the card is done with it, and each thread then waits for its own copy. VICTORY_MAPPED_TOGETHER=0: one at a time, as before.
  • Upload buffers: the first commit stopped waiting for them. The benches below found no difference either way, so a later commit puts the wait back, and its switch is gone. Their waits are still counted in the new line, so a play log can say otherwise.
  • Clippy: the four findings that stop CI on main: CI on main (8fc2254) fails at clippy (Rust 1.98: let_and_return, two manual_is_multiple_of, some_filter). Fixed with no change in behaviour, so this PR and the ones stacked on it can go green. Drop it if main fixes them first.
  • main is merged in (no conflicts), so the branch is up to date without a force-push.

Before / after

cargo test --release -p victory-gpu --lib -- bench_ --ignored --nocapture, RTX card, three runs each. VICTORY_BENCH_AHEAD_KB=65536 adds a thread like the one that makes buffers ahead (its name, its low priority), making 64 MiB buffers all the time, so the system pages as it does while a scene loads.

Card buffers of 64 KiB, beside 64 MiB buffers being made mean median 99th percentile
one waiter at a time (VICTORY_MAPPED_TOGETHER=0) 0.87–0.91 ms 0.98–1.17 ms 1.63–1.74 ms
waiting together 0.70–0.71 ms 0.58–0.69 ms 1.36–1.48 ms

On an idle card there is no difference (both about 0.30 ms).

Upload buffers, beside 64 MiB buffers being made 64 KiB, mean 8 MiB, mean
waited for 0.96–0.99 ms 3.57–3.74 ms
not waited for 0.97–0.98 ms 3.75–3.77 ms

Correctness

  • buffers_made_at_once_are_mapped_and_hold_what_is_copied_in: twelve threads make card and upload buffers at once (more than the ring has lists). Every buffer holds what the card copied into it. It passes with the switch either way, and with VICTORY_D3D12_DEBUG=1 in a diagnostics build it asserts the debug layer reported nothing (so a list sent again while the card still read it would fail it).
  • waits_are_counted_by_kind_and_thread: a wait is counted once, under its kind and its thread, and taken by the 5-second line.
  • CI steps run locally: cargo clippy --workspace --all-targets --locked -- -D warnings, the same with --all-features, and cargo test --workspace --locked all pass. watch::tests::what_the_kernel_writes_through_is_not_guarded_for_another_view and what_is_put_in_beside_the_guards_is_told_at_every_view fail now and then; they did in 1 of 10 runs on unchanged main too.
  • Not yet measured in play: the next play log's new line is that measurement.

Stacked on this PR: #682, #683, and on that one #684, then #685.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5535648133 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/630). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-28T02:05:19Z. --- ## Why A 9-minute play log (16 GB RTX card) had 52,000 `MakeResident` waits for 27.3 s, the longest 1,128 ms while a scene loaded with the card at 10 GB, and 48,000 mapping copies waited for, 7.2 s. Each was one number for every thread. That included the thread that makes buffers ahead (`crate::ahead`, 8,000 buffers in the first 6 s), whose waits no frame stands for, so the log could not tell stalls from background work. `mapped()` also held one lock for its whole GPU round trip, so a frame's thread that made a texture or a card buffer waited behind that low-priority thread. ## What - **The waits told apart.** A new 5-second line says which kind of new memory was waited for (upload, shared and card buffers, textures of their own, texture blocks, depth twins), by which thread, and how much of a mapping wait was another thread's lock. - **Mapping copies waited for together.** `mapped()` holds its lock only while it sends its copy. The copy comes from a ring of 8 lists, each sent again only once the card is done with it, and each thread then waits for its own copy. `VICTORY_MAPPED_TOGETHER=0`: one at a time, as before. - Upload buffers: the first commit stopped waiting for them. The benches below found no difference either way, so a later commit puts the wait back, and its switch is gone. Their waits are still counted in the new line, so a play log can say otherwise. - `Clippy: the four findings that stop CI on main`: CI on `main` (8fc2254) fails at clippy (Rust 1.98: `let_and_return`, two `manual_is_multiple_of`, `some_filter`). Fixed with no change in behaviour, so this PR and the ones stacked on it can go green. Drop it if `main` fixes them first. - `main` is merged in (no conflicts), so the branch is up to date without a force-push. ## Before / after `cargo test --release -p victory-gpu --lib -- bench_ --ignored --nocapture`, RTX card, three runs each. `VICTORY_BENCH_AHEAD_KB=65536` adds a thread like the one that makes buffers ahead (its name, its low priority), making 64 MiB buffers all the time, so the system pages as it does while a scene loads. | Card buffers of 64 KiB, beside 64 MiB buffers being made | mean | median | 99th percentile | |---|---|---|---| | one waiter at a time (`VICTORY_MAPPED_TOGETHER=0`) | 0.87–0.91 ms | 0.98–1.17 ms | 1.63–1.74 ms | | waiting together | 0.70–0.71 ms | 0.58–0.69 ms | 1.36–1.48 ms | On an idle card there is no difference (both about 0.30 ms). | Upload buffers, beside 64 MiB buffers being made | 64 KiB, mean | 8 MiB, mean | |---|---|---| | waited for | 0.96–0.99 ms | 3.57–3.74 ms | | not waited for | 0.97–0.98 ms | 3.75–3.77 ms | ## Correctness - `buffers_made_at_once_are_mapped_and_hold_what_is_copied_in`: twelve threads make card and upload buffers at once (more than the ring has lists). Every buffer holds what the card copied into it. It passes with the switch either way, and with `VICTORY_D3D12_DEBUG=1` in a diagnostics build it asserts the debug layer reported nothing (so a list sent again while the card still read it would fail it). - `waits_are_counted_by_kind_and_thread`: a wait is counted once, under its kind and its thread, and taken by the 5-second line. - CI steps run locally: `cargo clippy --workspace --all-targets --locked -- -D warnings`, the same with `--all-features`, and `cargo test --workspace --locked` all pass. `watch::tests::what_the_kernel_writes_through_is_not_guarded_for_another_view` and `what_is_put_in_beside_the_guards_is_told_at_every_view` fail now and then; they did in 1 of 10 runs on unchanged `main` too. - Not yet measured in play: the next play log's new line is that measurement. Stacked on this PR: #682, #683, and on that one #684, then #685.
CuteBooty commented 2026-11-28 04:42:06 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by CuteBooty on 2026-11-28T04:42:06Z.


In-game numbers for this PR from an 8 GB card that runs near its budget, since the description says it had not been measured in play yet.

  • PC: RTX 3070 8 GB (driver 621.24), Ryzen 7 5800X3D, 32 GB, Windows 11. Series S, 1920x1080, DLSS performance + frame generation 2x, started with victory.exe run, diag profile with diagnostics.
  • Build: main 63b902fe1 + this PR's four non-merge commits cherry-picked (50131e5, 0cbfe4d, 1dbd6eb, c3a2310) + #697 + a few unrelated local commits.
  • Settings that matter here: VICTORY_MAPPED_TOGETHER at its default (on), VICTORY_BUFFERS_AHEAD=0 (I keep the buffers made ahead off to save card memory), VICTORY_WAIT_RESIDENT unset, VICTORY_TEXTURE_POOL=1, VICTORY_TEXTURE_ROOM_PERCENT=85, VICTORY_SLOT_EVICT=1, VICTORY_CARD_ROOM_FOR_TARGETS_MB=2048, VICTORY_SOFT_VIEWS=copies.
  • One session of 16.7 minutes: loading, then on foot in town and driving. The card sat at about 6.25 GB in use of a 6.7-6.9 GB budget; the texture queue said "no room, new textures wait" in 144 of 192 samples. No error lines.

The new line, summed over the session (188 lines = 15.7 minutes): 73.7 s waited for new memory by the title's threads and ours, 0 by the ahead thread (it is off).

kind times resident mapped of the mapping, waiting for another thread's longest (resident / mapped)
shared buffers 63,209 29.6 s 18.9 s 43.8 ms 32.5 / 36.2 ms
upload buffers 64,728 20.2 s 0 0 314.1 ms / -
card buffers 12,440 3.0 s 1.1 s 13.6 ms 5.8 / 4.2 ms
textures of their own 916 0.4 s 0.1 s 20.8 ms 8.4 / 19.9 ms
depth twins 226 0.1 s 0 0 2.8 ms / -
texture blocks 46 0.1 s 0.0 s 0 3.2 / 0.4 ms
  • In settled play (the last 10.2 minutes): 41.4 s, about 67 ms of waiting per second of play, which is roughly 4 ms a frame at 16 frames a second, summed over threads. Shared buffers 35,733 times (19.8 s resident + 13.4 s mapped), upload buffers 27,318 times (7.7 s).
  • The busiest 5 seconds were during loading: 3,280.8 ms, with one upload buffer waiting 314.1 ms to be resident.
  • Waiting for another thread's mapping copy is almost nothing on this setup: 78 ms in the whole session against 20 s of mapping. With the ahead thread off there is little to collide with, so the "together" part has little to win here. What the line shows on this card, running near its budget, is that the waits are the residency of shared and upload buffers, about 64,000 of each in 16 minutes.

Two lines as logged, the busiest (cut after the third kind) and a typical one in play:

new memory waited for in the last 5 seconds (VICTORY_WAIT_RESIDENT=0: none): 3280.8 ms by the title's threads and ours, 0.0 ms by the thread that makes buffers ahead ("ahead", which no frame waits for); upload buffers 167x: 651.4 ms resident (longest 314.1) + 0.0 ms mapped (longest 0.0, 0.0 ms of it waiting for another thread's); shared buffers 3969x: 1190.4 ms resident (longest 16.9) + 280.9 ms mapped (longest 4.9, 1.1 ms of it waiting for another thread's); card buffers 3943x: 618.0 ms resident (longest 5.0) + 258.3 ms mapped (longest 2.4, 6.4 ms of it waiting for another thread's) ...
new memory waited for in the last 5 seconds (VICTORY_WAIT_RESIDENT=0: none): 412.8 ms by the title's threads and ours, 0.0 ms by the thread that makes buffers ahead ("ahead", which no frame waits for); upload buffers 252x: 63.0 ms resident (longest 2.1) + 0.0 ms mapped (longest 0.0, 0.0 ms of it waiting for another thread's); shared buffers 328x: 185.8 ms resident (longest 6.6) + 161.1 ms mapped (longest 6.2, 0.0 ms of it waiting for another thread's); card buffers 6x: 1.7 ms resident (longest 0.5) + 1.1 ms mapped (longest 0.6, 0.0 ms of it waiting for another thread's)

Not done: a session with VICTORY_MAPPED_TOGETHER=0 to compare against, and one with the buffers made ahead on (#682). Say which of the two is more useful and I will run it.

Measurements and this report were prepared with an AI assistant (Claude Code); the run was played on my machine.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7234204729 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/630#issuecomment-7234204729). Originally posted by [CuteBooty](https://github.com/CuteBooty) on 2026-11-28T04:42:06Z. --- In-game numbers for this PR from an 8 GB card that runs near its budget, since the description says it had not been measured in play yet. - PC: RTX 3070 8 GB (driver 621.24), Ryzen 7 5800X3D, 32 GB, Windows 11. Series S, 1920x1080, DLSS performance + frame generation 2x, started with `victory.exe run`, diag profile with diagnostics. - Build: main `63b902fe1` + this PR's four non-merge commits cherry-picked (50131e5, 0cbfe4d, 1dbd6eb, c3a2310) + #697 + a few unrelated local commits. - Settings that matter here: `VICTORY_MAPPED_TOGETHER` at its default (on), `VICTORY_BUFFERS_AHEAD=0` (I keep the buffers made ahead off to save card memory), `VICTORY_WAIT_RESIDENT` unset, `VICTORY_TEXTURE_POOL=1`, `VICTORY_TEXTURE_ROOM_PERCENT=85`, `VICTORY_SLOT_EVICT=1`, `VICTORY_CARD_ROOM_FOR_TARGETS_MB=2048`, `VICTORY_SOFT_VIEWS=copies`. - One session of 16.7 minutes: loading, then on foot in town and driving. The card sat at about 6.25 GB in use of a 6.7-6.9 GB budget; the texture queue said "no room, new textures wait" in 144 of 192 samples. No error lines. The new line, summed over the session (188 lines = 15.7 minutes): **73.7 s waited for new memory by the title's threads and ours**, 0 by the ahead thread (it is off). | kind | times | resident | mapped | of the mapping, waiting for another thread's | longest (resident / mapped) | |---|---|---|---|---|---| | shared buffers | 63,209 | 29.6 s | 18.9 s | 43.8 ms | 32.5 / 36.2 ms | | upload buffers | 64,728 | 20.2 s | 0 | 0 | 314.1 ms / - | | card buffers | 12,440 | 3.0 s | 1.1 s | 13.6 ms | 5.8 / 4.2 ms | | textures of their own | 916 | 0.4 s | 0.1 s | 20.8 ms | 8.4 / 19.9 ms | | depth twins | 226 | 0.1 s | 0 | 0 | 2.8 ms / - | | texture blocks | 46 | 0.1 s | 0.0 s | 0 | 3.2 / 0.4 ms | - In settled play (the last 10.2 minutes): 41.4 s, about 67 ms of waiting per second of play, which is roughly 4 ms a frame at 16 frames a second, summed over threads. Shared buffers 35,733 times (19.8 s resident + 13.4 s mapped), upload buffers 27,318 times (7.7 s). - The busiest 5 seconds were during loading: 3,280.8 ms, with one upload buffer waiting 314.1 ms to be resident. - Waiting for another thread's mapping copy is almost nothing on this setup: 78 ms in the whole session against 20 s of mapping. With the ahead thread off there is little to collide with, so the "together" part has little to win here. What the line shows on this card, running near its budget, is that the waits are the residency of shared and upload buffers, about 64,000 of each in 16 minutes. Two lines as logged, the busiest (cut after the third kind) and a typical one in play: ``` new memory waited for in the last 5 seconds (VICTORY_WAIT_RESIDENT=0: none): 3280.8 ms by the title's threads and ours, 0.0 ms by the thread that makes buffers ahead ("ahead", which no frame waits for); upload buffers 167x: 651.4 ms resident (longest 314.1) + 0.0 ms mapped (longest 0.0, 0.0 ms of it waiting for another thread's); shared buffers 3969x: 1190.4 ms resident (longest 16.9) + 280.9 ms mapped (longest 4.9, 1.1 ms of it waiting for another thread's); card buffers 3943x: 618.0 ms resident (longest 5.0) + 258.3 ms mapped (longest 2.4, 6.4 ms of it waiting for another thread's) ... new memory waited for in the last 5 seconds (VICTORY_WAIT_RESIDENT=0: none): 412.8 ms by the title's threads and ours, 0.0 ms by the thread that makes buffers ahead ("ahead", which no frame waits for); upload buffers 252x: 63.0 ms resident (longest 2.1) + 0.0 ms mapped (longest 0.0, 0.0 ms of it waiting for another thread's); shared buffers 328x: 185.8 ms resident (longest 6.6) + 161.1 ms mapped (longest 6.2, 0.0 ms of it waiting for another thread's); card buffers 6x: 1.7 ms resident (longest 0.5) + 1.1 ms mapped (longest 0.6, 0.0 ms of it waiting for another thread's) ``` Not done: a session with `VICTORY_MAPPED_TOGETHER=0` to compare against, and one with the buffers made ahead on (#682). Say which of the two is more useful and I will run it. Measurements and this report were prepared with an AI assistant (Claude Code); the run was played on my machine.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/630:upstream-pr/630'
git switch 'upstream-pr/630'

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 'upstream-pr/630'
git switch 'upstream-pr/630'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/630'
git switch 'upstream-pr/630'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/630'
git switch 'main'
git merge --squash 'upstream-pr/630'
git switch 'main'
git merge --ff-only 'upstream-pr/630'
git switch 'main'
git merge 'upstream-pr/630'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
trustno1-coder/VIctory-NVIDIA!630
No description provided.