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

Closed
gabrielecabrini wants to merge 0 commits from upstream-pr/2745 into main
gabrielecabrini commented 2026-11-29 16:46:41 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by gabrielecabrini on 2026-11-29T16:46:41Z.


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.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5552872875 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2745). Originally posted by [gabrielecabrini](https://github.com/gabrielecabrini) on 2026-11-29T16:46:41Z. --- ## 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`.
dyshay commented 2026-11-29 17:48:59 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by dyshay on 2026-11-29T17:48:59Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7259986093 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2745#issuecomment-7259986093). Originally posted by [dyshay](https://github.com/dyshay) on 2026-11-29T17:48:59Z. --- 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.
CopiiDeco commented 2026-11-29 19:42:10 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by CopiiDeco on 2026-11-29T19:42:10Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7261487526 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2745#issuecomment-7261487526). Originally posted by [CopiiDeco](https://github.com/CopiiDeco) on 2026-11-29T19:42:10Z. --- 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 commented 2026-11-29 19:56:52 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by CopiiDeco on 2026-11-29T19:56:52Z.


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).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7261684610 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2745#issuecomment-7261684610). Originally posted by [CopiiDeco](https://github.com/CopiiDeco) on 2026-11-29T19:56:52Z. --- **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).
gabrielecabrini commented 2026-11-29 21:18:44 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by gabrielecabrini on 2026-11-29T21:18:44Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7262774275 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2745#issuecomment-7262774275). Originally posted by [gabrielecabrini](https://github.com/gabrielecabrini) on 2026-11-29T21:18:44Z. --- 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 commented 2026-11-29 22:08:21 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by gabrielecabrini on 2026-11-29T22:08:21Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7263434069 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2745#issuecomment-7263434069). Originally posted by [gabrielecabrini](https://github.com/gabrielecabrini) on 2026-11-29T22:08:21Z. --- 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

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