Guards: a submission's view memory guarded in one go, beside its asking (VICTORY_GUARD_BATCH, VICTORY_GUARD_BESIDE) #4877

Closed
github-bot wants to merge 1 commit from github-bot/gh-4876 into main AGit
Owner

@⁠Kenzim on GitHub · 2026-12-01 12:28 UTC · original
Kenzim:guards → main · +335 −6 · 3 files · 1 commits · closed without merging

Who waits for the guards' lock, measured: in the street scene it was taken 440 times a frame, 198 of them behind another thread, waited for 28.7 ms and held for 5.1 ms, summed over threads. Nearly all of it is the refreshes in front of a submission (eight victory-wide threads plus the submitting thread). The lock is held for about 12 µs at a time, and a wait is about 150 µs: threads sleep for a lock that is free again long before they wake.

What changes:

  • watch::guard_ahead: a submission guards, in one go, every range its lists' Step::Refresh steps refresh of guarded copies (Shadow::guarded_copy).
    • It holds the ranges, notes the written blocks in the journal and publishes the ranges.
    • The refreshes then find them published and read the journal without the guards' lock.
    • A block written after that is not published, and is guarded by its own refresh as before.
    • guard's locked body becomes guard_locked (the lock handed in and back).
    • The idea is from Grein-BR/VIctory-foxhound dd8c48ab, ported by hand onto this tree's guard.
  • The batch is begun on a kept thread (victory-guard, guard_ahead_begin) when the submission's one asking of the write watch begins, and waited for when the asking is made, before the first refresh. The asking is of write-watched memory and the guards are of views; neither reads what the other makes.
  • Both on by default: VICTORY_GUARD_BATCH, VICTORY_GUARD_BESIDE.
  • Diagnostics: the batch's time and the submitting thread's wait for it on the frame line.

Measurements (RTX 3090, 32 threads, native 2560x1440, DLSS off, street scene; switches flipped inside one run with VICTORY_AB), per frame:

off batch on submitting thread batch beside the asking
submitting thread's submissions 21.2 21.1 20.0
its refreshes 8.9 5.9 6.0
asking + guards 4.25 7.2 5.7
guards' lock waited, all threads 28.7 3.1 2.3

The lock waits are consistent over three runs. The 1.2 ms on the submitting thread (21.2 -> 20.0) rests on one clean run.

Correctness: under VICTORY_REFRESH_CHECK=1, 0 stale-copy warnings in twelve phases with the batch and eleven without. The picture was intact in the A/B runs.

In this card-bound scene the frame time does not move. The gains are in the processor stages named above.

Not measured: scenes other than the street. The victory-guard thread itself is not exercised by a unit test (tests run the batch on the submitting thread).

To restore the old behaviour: VICTORY_GUARD_BATCH=0 (every refresh guards its own range, as before); VICTORY_GUARD_BESIDE=0 (batch made on the submitting thread after its asking).

Shader cache / translator key: not affected.

Tests: watch::many_askers_tests::no_write_to_views_is_lost_with_batched_guards (batches before half the askings, many threads, faults with and without the lock). watch:: 70 pass. Clippy on victory-gpu is clean apart from the five errors main already has (#4152).

**@⁠Kenzim** on GitHub · 2026-12-01 12:28 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4876) `Kenzim:guards` → `main` · +335 −6 · 3 files · 1 commits · closed without merging Who waits for the guards' lock, measured: in the street scene it was taken 440 times a frame, 198 of them behind another thread, waited for 28.7 ms and held for 5.1 ms, summed over threads. Nearly all of it is the refreshes in front of a submission (eight `victory-wide` threads plus the submitting thread). The lock is held for about 12 µs at a time, and a wait is about 150 µs: threads sleep for a lock that is free again long before they wake. What changes: - `watch::guard_ahead`: a submission guards, in one go, every range its lists' `Step::Refresh` steps refresh of guarded copies (`Shadow::guarded_copy`). - It holds the ranges, notes the written blocks in the journal and publishes the ranges. - The refreshes then find them published and read the journal without the guards' lock. - A block written after that is not published, and is guarded by its own refresh as before. - `guard`'s locked body becomes `guard_locked` (the lock handed in and back). - The idea is from Grein-BR/VIctory-foxhound dd8c48ab, ported by hand onto this tree's `guard`. - The batch is begun on a kept thread (`victory-guard`, `guard_ahead_begin`) when the submission's one asking of the write watch begins, and waited for when the asking is made, before the first refresh. The asking is of write-watched memory and the guards are of views; neither reads what the other makes. - Both on by default: `VICTORY_GUARD_BATCH`, `VICTORY_GUARD_BESIDE`. - Diagnostics: the batch's time and the submitting thread's wait for it on the frame line. Measurements (RTX 3090, 32 threads, native 2560x1440, DLSS off, street scene; switches flipped inside one run with `VICTORY_AB`), per frame: | | off | batch on submitting thread | batch beside the asking | |---|---|---|---| | submitting thread's submissions | 21.2 | 21.1 | 20.0 | | its refreshes | 8.9 | 5.9 | 6.0 | | asking + guards | 4.25 | 7.2 | 5.7 | | guards' lock waited, all threads | 28.7 | 3.1 | 2.3 | The lock waits are consistent over three runs. The 1.2 ms on the submitting thread (21.2 -> 20.0) rests on one clean run. Correctness: under `VICTORY_REFRESH_CHECK=1`, 0 stale-copy warnings in twelve phases with the batch and eleven without. The picture was intact in the A/B runs. **In this card-bound scene the frame time does not move.** The gains are in the processor stages named above. Not measured: scenes other than the street. The `victory-guard` thread itself is not exercised by a unit test (tests run the batch on the submitting thread). To restore the old behaviour: `VICTORY_GUARD_BATCH=0` (every refresh guards its own range, as before); `VICTORY_GUARD_BESIDE=0` (batch made on the submitting thread after its asking). Shader cache / translator key: not affected. Tests: `watch::many_askers_tests::no_write_to_views_is_lost_with_batched_guards` (batches before half the askings, many threads, faults with and without the lock). `watch::` 70 pass. Clippy on `victory-gpu` is clean apart from the five errors main already has (#4152).
Who waits for the guards' lock, measured (the lock by the line that took it
and the kind of thread, hold and wait): in the street scene it was taken
440 times a frame, 198 of them behind another thread, waited for 28.7 ms
and held for 5.1 ms, summed over threads. Nearly all of it is the
refreshes in front of a submission: eight victory-wide threads and the
submitting thread itself, which then waits for the others at the join. The
lock is held some 12 microseconds at a time and a wait is 150: threads
asleep for a lock that is free again long before they wake.

watch::guard_ahead guards every range the lists' Step::Refresh steps
refresh of guarded copies (Shadow::guarded_copy) with the ranges held,
notes the written blocks in the journal and publishes the ranges
(publish_range, as writes does, also where nothing was written); the
refreshes then find them published and read the journal without the
guards' lock. A block written after that is not published and its range is
guarded by its own refresh, as before. guard's body under the lock is now
guard_locked (the lock handed in and back). The idea is from
Grein-BR/VIctory-foxhound dd8c48ab, ported by hand onto this tree's guard;
the heap hooks' writes are told first, as guard does.

Made on the submitting thread after its asking, it gave that thread
nothing: refreshes 8.9 -> 5.9 ms a frame, asking and guards 4.25 -> 7.2,
its submissions 21.2 -> 21.1. So the batch is begun on a thread kept for it
(victory-guard) when the asking begins, and waited for when the asking is
made: the asking is of write-watched memory and the guards are of views,
neither reads what the other makes. Measured within one run, switches
flipped every 12 s, three phases each way (20261201-025510-cg-ab-batch, RTX
3090, 32 threads, 2560x1440, DLSS off), per frame:

- the guards' lock waited for, all threads: 28.7 -> 2.3 ms (consistent
  over three runs);
- the submitting thread's submissions 21.2 -> 20.0 ms (one clean run);
- its refreshes 8.9 -> 6.0 ms, asking and guards 4.25 -> 5.7 ms.

The frame time itself does not move there: the scene is bound by the card.
Under VICTORY_REFRESH_CHECK=1 no copy was found stale in twelve phases with
the batch and eleven without (20261201-074544-cg-ab-v3).

VICTORY_GUARD_BATCH=0 makes every refresh guard its own range, as before;
VICTORY_GUARD_BESIDE=0 makes the batch on the submitting thread after its
asking.

Tests: watch::many_askers_tests::no_write_to_views_is_lost_with_batched_guards
(batches before half the askings; in tests the batch is on and made on the
asking thread).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 12:32:09 +00:00
Author
Owner

@⁠Freeman022026 on GitHub · 2026-12-01 14:04 UTC · original

Tested stacked together with #4876 and #4878 (VICTORY_REFRESH_WITHIN only, keeping #4572's 512 KiB ask_once gap) on an RTX 4090 24 GB (driver 621.14), Ryzen 7 7800X3D, 64 GB RAM, Windows 11, Series X profile at 2560x1440, DLSS Performance, 2x DLSS Frame Generation, ray tracing off. Local MSVC release build (rustc 1.99.1) on v2026.11.30.02 (84bd61e2) with a local PR stack.

Comparing gameplay seconds with at least 180 title lists per frame between the prior run (first 1,000 gameplay seconds) and the run with #4876, #4877, and #4878 added (554 gameplay seconds):

  • refreshes: median dropped from 14.50 ms (p90 19.20 ms) to 10.80 ms (p90 13.00 ms).
  • lists' steps: median dropped from 20.65 ms (p90 28.00 ms) to 17.20 ms (p90 20.40 ms).
  • asking the write watch: median rose from 4.20 ms (p90 5.30 ms) to 7.40 ms (p90 8.90 ms) because beside.wait() sits inside that timed span, while total submitting-thread p90 fell from 42.80 ms to 37.10 ms (median 32.40 ms to 31.40 ms).

One merge note: this PR defines pub(crate) fn guard_ahead in crates/victory-gpu/src/watch.rs, which collides with #3411's pub(crate) fn guard_ahead when both are in the same tree. Renaming this PR's function locally resolved the conflict cleanly, and the guard_ahead, guard_batch, and refresh_within tests passed.

Not tested: #4877 isolated on clean main or a fixed input replay (the two runs were separate live gameplay sessions).

**@⁠Freeman022026** on GitHub · 2026-12-01 14:04 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4876#issuecomment-7313652180) Tested stacked together with #4876 and #4878 (`VICTORY_REFRESH_WITHIN` only, keeping #4572's 512 KiB `ask_once` gap) on an RTX 4090 24 GB (driver 621.14), Ryzen 7 7800X3D, 64 GB RAM, Windows 11, Series X profile at 2560x1440, DLSS Performance, 2x DLSS Frame Generation, ray tracing off. Local MSVC release build (`rustc 1.99.1`) on `v2026.11.30.02` (`84bd61e2`) with a local PR stack. Comparing gameplay seconds with at least 180 title lists per frame between the prior run (first 1,000 gameplay seconds) and the run with #4876, #4877, and #4878 added (554 gameplay seconds): - `refreshes`: median dropped from 14.50 ms (p90 19.20 ms) to 10.80 ms (p90 13.00 ms). - `lists' steps`: median dropped from 20.65 ms (p90 28.00 ms) to 17.20 ms (p90 20.40 ms). - `asking the write watch`: median rose from 4.20 ms (p90 5.30 ms) to 7.40 ms (p90 8.90 ms) because `beside.wait()` sits inside that timed span, while total submitting-thread p90 fell from 42.80 ms to 37.10 ms (median 32.40 ms to 31.40 ms). One merge note: this PR defines `pub(crate) fn guard_ahead` in `crates/victory-gpu/src/watch.rs`, which collides with #3411's `pub(crate) fn guard_ahead` when both are in the same tree. Renaming this PR's function locally resolved the conflict cleanly, and the `guard_ahead`, `guard_batch`, and `refresh_within` tests passed. Not tested: #4877 isolated on clean `main` or a fixed input replay (the two runs were separate live gameplay sessions).
Author
Owner

@⁠albertik322-sudo on GitHub · 2026-12-01 17:00 UTC · original

Tested as part of a batch cherry-picked onto main @ 5fabb46e (with #4295, #4341, #4494, #4207). PC: RTX 3070 Laptop 8 GB, i7-11800H, 32 GB RAM, Windows 11. Series S, DLSS Performance, FG x4.

No isolated measurement, but the batch dropped fixed cost per frame from ~47 ms to ~25.5 ms and nothing in the guard path regressed: the write-watch asking line stayed ~12-16 ms with no new stalls, no corruption in hours of play. Confirming it is safe at least on a laptop where the guard/write-watch path is genuinely hot.

**@⁠albertik322-sudo** on GitHub · 2026-12-01 17:00 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4876#issuecomment-7318605581) Tested as part of a batch cherry-picked onto main @ 5fabb46e (with #4295, #4341, #4494, #4207). PC: RTX 3070 Laptop 8 GB, i7-11800H, 32 GB RAM, Windows 11. Series S, DLSS Performance, FG x4. No isolated measurement, but the batch dropped fixed cost per frame from ~47 ms to ~25.5 ms and nothing in the guard path regressed: the write-watch asking line stayed ~12-16 ms with no new stalls, no corruption in hours of play. Confirming it is safe at least on a laptop where the guard/write-watch path is genuinely hot.
github-bot closed this pull request 2026-12-01 18:30:41 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:29 UTC · original

Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

**@⁠trustno1-coder** on GitHub · 2026-12-01 18:29 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4876#issuecomment-7321034698) Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

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