Write watch: guarded view memory asked unguarded asks no kernel #2745

Closed
github-bot wants to merge 0 commits from github-bot/gh-2745 into main AGit
Owner

@⁠gabrielecabrini on GitHub · 2026-11-29 16:46 UTC · original
gabrielecabrini:perf/writes-skip-refused-askings → main · +45 −0 · 1 files · 1 commits · closed without merging

What

A texture refresh (texture.rs, refresh_timed) asks watch::writes(start, end, false) first and, given None, asks again guarded. For a texture in view memory that the guards hold read-only (PROTECTED), the unguarded asking still went to GetWriteWatch, which refuses memory that is not write-watched. The answer was the same None, but only after a kernel call, once per such texture per refresh.

Evidence

Same scene of a Linux run (boat, Series S, RTX 4070 SUPER, Proton Experimental, diagnostics build), before and after, 2026-11-29:

before after
kernel askings refused, a frame 361 2–4
time in kernel askings, all threads 34.1 ms 7–17 ms
texture refreshes, all threads 40.7 ms 9.0 ms
… of them asking the write watch and the guards 33.1 ms 2.9 ms
the submitting thread's preparing 41.7 ms 36.4 ms

The frame rate did not move (about 22 fps): the submitting thread's whole work stays near the frame, and the card now idles 6 to 12 ms a frame instead of 22. The two samples are different moments of the same scene, so the small differences carry noise; the large ones do not.

Fix

crates/victory-gpu/src/watch.rs, writes():

  • Asked unguarded, a range with a block in PROTECTED returns None before Asking::hold, as the kernel would have answered.
  • This mirrors the existing refused shortcut, which already skips the kernel for such memory when asked guarded.
  • PROTECTED is a lock-free bit set, so write-watched memory pays one bit test.
  • Buffers that ask unguarded on view memory take the same shortcut.

Tests

  • New guarded_view_memory_asked_unguarded_asks_no_kernel:
    • checks the unguarded answer is None and the guarded one still answers;
    • in diagnostics builds, also checks that no refused kernel asking was counted (ASKS[10]);
    • fails without the change.
  • watch:: tests under Proton: 59 pass. These four fail with and without this change, on main too:
    • many_askers_tests::bits_and_holes_with_faults_that_take_no_lock
    • many_askers_tests::holes_are_known_until_the_runtime_tells
    • many_askers_tests::no_mapping_is_lost_between_askers
    • tests::what_is_left_alone_is_no_known_hole
  • clippy -p victory-gpu reports nothing in the changed lines; the watch.rs warning about an unused nothing_new_with is already on main.
**@⁠gabrielecabrini** on GitHub · 2026-11-29 16:46 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2745) `gabrielecabrini:perf/writes-skip-refused-askings` → `main` · +45 −0 · 1 files · 1 commits · closed without merging ## What A texture refresh (`texture.rs`, `refresh_timed`) asks `watch::writes(start, end, false)` first and, given `None`, asks again guarded. For a texture in view memory that the guards hold read-only (`PROTECTED`), the unguarded asking still went to `GetWriteWatch`, which refuses memory that is not write-watched. The answer was the same `None`, but only after a kernel call, once per such texture per refresh. ## Evidence Same scene of a Linux run (boat, Series S, RTX 4070 SUPER, Proton Experimental, diagnostics build), before and after, 2026-11-29: | | before | after | |---|---|---| | kernel askings refused, a frame | 361 | 2–4 | | time in kernel askings, all threads | 34.1 ms | 7–17 ms | | texture refreshes, all threads | 40.7 ms | 9.0 ms | | … of them asking the write watch and the guards | 33.1 ms | 2.9 ms | | the submitting thread's preparing | 41.7 ms | 36.4 ms | The frame rate did not move (about 22 fps): the submitting thread's whole work stays near the frame, and the card now idles 6 to 12 ms a frame instead of 22. The two samples are different moments of the same scene, so the small differences carry noise; the large ones do not. ## Fix `crates/victory-gpu/src/watch.rs`, `writes()`: - Asked unguarded, a range with a block in `PROTECTED` returns `None` before `Asking::hold`, as the kernel would have answered. - This mirrors the existing `refused` shortcut, which already skips the kernel for such memory when asked guarded. - `PROTECTED` is a lock-free bit set, so write-watched memory pays one bit test. - Buffers that ask unguarded on view memory take the same shortcut. ## Tests - New `guarded_view_memory_asked_unguarded_asks_no_kernel`: - checks the unguarded answer is `None` and the guarded one still answers; - in diagnostics builds, also checks that no refused kernel asking was counted (`ASKS[10]`); - fails without the change. - `watch::` tests under Proton: 59 pass. These four fail with and without this change, on `main` too: - `many_askers_tests::bits_and_holes_with_faults_that_take_no_lock` - `many_askers_tests::holes_are_known_until_the_runtime_tells` - `many_askers_tests::no_mapping_is_lost_between_askers` - `tests::what_is_left_alone_is_no_known_hole` - `clippy -p victory-gpu` reports nothing in the changed lines; the `watch.rs` warning about an unused `nothing_new_with` is already on `main`.
A texture refresh asks `writes(start, end, false)` first and, given
`None`, asks again guarded. For a texture in view memory the guards hold
read-only (PROTECTED), the unguarded asking still went to
GetWriteWatch, which refuses memory that is not write-watched; the
answer was `None` after a kernel call. writes() already skips the
kernel for such memory when asked guarded (`refused`); asked unguarded
it now returns `None` before Asking::hold, as the kernel would have.
PROTECTED is a lock-free bit set, so the check costs nothing for
write-watched memory.

Same scene of a Linux run (boat, Series S, RTX 4070 SUPER, Proton
Experimental, diagnostics build), before and after (2026-11-29):

- kernel askings refused: 361 a frame -> 2 to 4
- time in kernel askings, all threads: 34.1 ms -> 7 to 17 ms
- texture refreshes, all threads: 40.7 ms (33.1 asking the write watch
  and the guards) -> 9.0 ms (2.9)
- the submitting thread's preparing: 41.7 -> 36.4 ms

The frame rate did not move (about 22 fps): the submitting thread's
whole work stays near the frame, and the card now idles 6 to 12 ms a
frame instead of 22.

guarded_view_memory_asked_unguarded_asks_no_kernel checks the answer and,
in diagnostics builds, that no refused asking was counted; it fails
without the change.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 16:49:25 +00:00
Author
Owner

@⁠dyshay on GitHub · 2026-11-29 17:48 UTC · original

Merged into our fork's integration branch for testing (dyshay/VIctory-NVIDIA, branch janus-prs). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with --profile diag --features diagnostics, and the CPU tests of the touched crates pass. Runs on an RTX 4090 are queued (Series S with ray tracing, and Series X, DLSS Quality). Frame times will follow here.

**@⁠dyshay** on GitHub · 2026-11-29 17:48 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2745#issuecomment-7259986093) Merged into our fork's integration branch for testing ([dyshay/VIctory-NVIDIA](https://github.com/dyshay/VIctory-NVIDIA/tree/janus-prs), branch `janus-prs`). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with `--profile diag --features diagnostics`, and the CPU tests of the touched crates pass. Runs on an RTX 4090 are queued (Series S with ray tracing, and Series X, DLSS Quality). Frame times will follow here.
Author
Owner

@⁠CopiiDeco on GitHub · 2026-11-29 19:42 UTC · original

Measured this on Windows; flagging a possible correctness side effect.

Rig: Ryzen 5 5600X (6C/12T), RTX 3080 10 GB (driver 616.92), 32 GB DDR4-3600, B450 (PCIe 3.0), Windows 11 26200.
Setup: diagnostics build, scripts/bench.ps1 -Dlss performance -FrameGen off -RayTracing off, Series S profile, VICTORY_WC_BAR=1 VICTORY_WINDOWS_BAR_MB=2048, same save and opening cutscene each run, 30 s warm-up + 120 s measured, pipelines precompiled.

median fps preparing p99 (1 % low) p99.9 "a texture picked by index changed after its upload with nothing to tell of it"
main 829188e9 18.2 42.8 ms 131 ms (7.6 fps) 199 ms 30
main + this PR 18.2 42.7 ms 123 ms (8.2 fps) 162 ms 201
main + #2776 (in place) + #2656 + #2647 20.2 32.7 ms 134 ms (7.5 fps) 206 ms 133
the same + this PR 18.9 37.4 ms 161 ms (6.2 fps) 218 ms 202

On its own it is neutral in fps with somewhat better tails, but the warning above (the safety net catching a write that the watch/guards did not report) goes from 30 to ~200 in a run, which suggests guarded view memory asked unguarded now misses some writes. Textures are re-uploaded by that net; buffers may not be. On top of the other three PRs it also costs about 1.3 fps and a worse p99 here.

One run per configuration, about ±0.4 fps run-to-run noise on this rig, so the fps deltas are indicative; the warning count is the part I'd look at. Happy to rerun with other switches or a timeline.

**@⁠CopiiDeco** on GitHub · 2026-11-29 19:42 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2745#issuecomment-7261487526) Measured this on Windows; flagging a possible correctness side effect. **Rig:** Ryzen 5 5600X (6C/12T), RTX 3080 10 GB (driver 616.92), 32 GB DDR4-3600, B450 (PCIe 3.0), Windows 11 26200. **Setup:** diagnostics build, `scripts/bench.ps1 -Dlss performance -FrameGen off -RayTracing off`, Series S profile, `VICTORY_WC_BAR=1 VICTORY_WINDOWS_BAR_MB=2048`, same save and opening cutscene each run, 30 s warm-up + 120 s measured, pipelines precompiled. | | median fps | preparing | p99 (1 % low) | p99.9 | "a texture picked by index changed after its upload with nothing to tell of it" | |---|---|---|---|---|---| | main 829188e9 | 18.2 | 42.8 ms | 131 ms (7.6 fps) | 199 ms | 30 | | main + this PR | 18.2 | 42.7 ms | 123 ms (8.2 fps) | 162 ms | **201** | | main + #2776 (in place) + #2656 + #2647 | 20.2 | 32.7 ms | 134 ms (7.5 fps) | 206 ms | 133 | | the same + this PR | 18.9 | 37.4 ms | 161 ms (6.2 fps) | 218 ms | 202 | On its own it is neutral in fps with somewhat better tails, but the warning above (the safety net catching a write that the watch/guards did not report) goes from 30 to ~200 in a run, which suggests guarded view memory asked unguarded now misses some writes. Textures are re-uploaded by that net; buffers may not be. On top of the other three PRs it also costs about 1.3 fps and a worse p99 here. One run per configuration, about ±0.4 fps run-to-run noise on this rig, so the fps deltas are indicative; the warning count is the part I'd look at. Happy to rerun with other switches or a timeline.
Author
Owner

@⁠CopiiDeco on GitHub · 2026-11-29 19:56 UTC · original

Correction to my comment above: please disregard the "a texture picked by index changed after its upload with nothing to tell of it" counts. I counted that warning across all of today's runs of unmodified main on this rig and it is bimodal from run to run (8, 27, 30, 52, 124, 160, 200, 201, 204 …), so the ~200 I saw with this PR is within main's own range and says nothing about missed writes. Sorry for the noise.

The rest stands as measured (one run per configuration, so treat the fps deltas as indicative).

**@⁠CopiiDeco** on GitHub · 2026-11-29 19:56 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2745#issuecomment-7261684610) **Correction to my comment above:** please disregard the "a texture picked by index changed after its upload with nothing to tell of it" counts. I counted that warning across all of today's runs of **unmodified main** on this rig and it is bimodal from run to run (8, 27, 30, 52, 124, 160, 200, 201, 204 …), so the ~200 I saw with this PR is within main's own range and says nothing about missed writes. Sorry for the noise. The rest stands as measured (one run per configuration, so treat the fps deltas as indicative).
Author
Owner

@⁠gabrielecabrini on GitHub · 2026-11-29 21:18 UTC · original

Thanks for measuring. With #2776 its REFUSED memo already skips nearly every refused kernel asking this PR saves, so on top of it #2745 is little more than a bit test in place of a mutex; it matters mostly under Proton, where each refusal costs about 1.3 ms, against microseconds on Windows.

**@⁠gabrielecabrini** on GitHub · 2026-11-29 21:18 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2745#issuecomment-7262774275) Thanks for measuring. With #2776 its REFUSED memo already skips nearly every refused kernel asking this PR saves, so on top of it #2745 is little more than a bit test in place of a mutex; it matters mostly under Proton, where each refusal costs about 1.3 ms, against microseconds on Windows.
github-bot closed this pull request 2026-11-29 22:12:23 +00:00
Author
Owner

@⁠gabrielecabrini on GitHub · 2026-11-29 22:08 UTC · original

Closing: #2776's REFUSED memo already skips nearly every refused kernel asking this saved, so what is left is a bit test in place of a mutex. Not worth a review on its own.

**@⁠gabrielecabrini** on GitHub · 2026-11-29 22:08 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2745#issuecomment-7263434069) Closing: #2776's REFUSED memo already skips nearly every refused kernel asking this saved, so what is left is a bit test in place of a mutex. Not worth a review on its own.

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!2745
No description provided.