Write watch: a submission's askings hold only the pages they ask about #697

Merged
0xkn0wh3r3 merged 1 commit from upstream-pr/697 into main 2026-11-28 19:39:39 +00:00
0xkn0wh3r3 commented 2026-11-28 03:38:47 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by 0xkn0wh3r3 on 2026-11-28T03:38:47Z.


What

A submission's two write-watch askings now hold only the pages they ask about, instead of all memory.

ask_ahead and ask_rest each took Asking::hold_all(). So every submission's asking waited for every other asking in the process to end, and made every other asking wait for it. Other threads ask while a submission is being prepared:

  • The descriptor heaps' thread holds a heap's pages through its asking and through guarding them again. It begins its round just before the submission's asking. In a log from 2026-11-28 its asking took 5.1–6.4 ms a frame, over about 16 rounds.
  • Texture refreshes on the helper threads ask too.

With the change they only wait for each other when they ask about the same pages, which is what the hold is for.

VICTORY_ASK_HOLD_ALL=1 restores the old behaviour.

How

  • Askings (watch.rs): a new hold of several page ranges, taken all at once or not at all. Two threads that each hold several ranges can never wait for each other in a circle. It uses the same ASKING list and condvar as Asking, so the two kinds of hold exclude each other.
  • ask_ahead: works out its runs first, then holds exactly those runs. That includes the pages between a run's pieces, since the kernel's asking walks and resets those too. The hold lasts until the answers are in the journal, as before.
  • ask_rest: works out the ranges ask_ahead left, holds them, and asks exactly those ranges.
    • Their guard bits can change after the choice. A range whose bits cleared since then is no reason to ask about one it doesn't hold.
    • It reads the journal's ahead instead of taking it out while it asks. Holding only its own pages, it now lets other threads ask meanwhile, and the journal goes on answering them for what ask_ahead asked.
  • Unchanged: the rule itself, that no two threads ask about the same pages at once, and the asking numbers.

Tests

  • New watch::ask_holds::ranges_are_merged_in_order_and_told_apart checks the range helpers (merged, overlaps).
  • New watch::ask_holds::an_asking_waits_only_for_the_pages_it_asks_about:
    • An asking of a held page waits until the holder lets go. Asking about other pages goes ahead at once.
    • Several ranges are let go together.
    • It fails with the hold made a no-op.
  • New host::refresh_tests::askings_of_other_threads_beside_a_submission:
    • Copies of the same title memory, both write-watched and view memory, are refreshed by a submission on one thread and one range at a time on another. A third thread asks about other memory nonstop.
    • Over 300 rounds of random writes, every copy must hold what title memory holds after each round.
  • Tests that ask as a submission does now take one lock (one_submission). The layer prepares one submission at a time, but in the test process unchanged_ranges_are_known asked as a submission does alongside other tests' submissions.
    • One test's asking could end another's mid-submission. Running refresh_tests:: with watch:: 40 times, the new test above lost a copy in 4 runs with page holds and in 1 run with all-memory holds. It never failed in 60 runs on its own.
    • With the lock: 0 failures in 80 runs with page holds and 0 in 40 with all-memory holds.
  • cargo test -p victory-gpu --lib on this branch: 455 passed, 0 failed, both with the switch on and with VICTORY_ASK_HOLD_ALL=1, three runs and two.
  • 40 runs each of refresh_tests::+watch::+ask_holds and of many_askers_tests, in both modes: no failures.
  • cargo clippy -p victory-gpu --all-targets: 3 warnings, the same 3 as main.

Performance, before and after

Not measured in the game yet. In unit benchmarks the askings don't contend, so they show nothing either way. The expected effect is that the submitting thread no longer waits for the heaps' thread's asking and guarding, nor the other way round, when they ask about different memory.

The diagnostics build's "ranges held" figure in watch::lock_waits shows the waits per frame. Comparing a run with VICTORY_ASK_HOLD_ALL=1 against one without will say how much this saves.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5536307539 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/697). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-28T03:38:47Z. --- ## What A submission's two write-watch askings now hold only the pages they ask about, instead of all memory. `ask_ahead` and `ask_rest` each took `Asking::hold_all()`. So every submission's asking waited for every other asking in the process to end, and made every other asking wait for it. Other threads ask while a submission is being prepared: - The descriptor heaps' thread holds a heap's pages through its asking and through guarding them again. It begins its round just before the submission's asking. In a log from 2026-11-28 its asking took 5.1–6.4 ms a frame, over about 16 rounds. - Texture refreshes on the helper threads ask too. With the change they only wait for each other when they ask about the same pages, which is what the hold is for. `VICTORY_ASK_HOLD_ALL=1` restores the old behaviour. ## How - **`Askings` (watch.rs):** a new hold of several page ranges, taken all at once or not at all. Two threads that each hold several ranges can never wait for each other in a circle. It uses the same `ASKING` list and condvar as `Asking`, so the two kinds of hold exclude each other. - **`ask_ahead`:** works out its runs first, then holds exactly those runs. That includes the pages between a run's pieces, since the kernel's asking walks and resets those too. The hold lasts until the answers are in the journal, as before. - **`ask_rest`:** works out the ranges `ask_ahead` left, holds them, and asks exactly those ranges. - Their guard bits can change after the choice. A range whose bits cleared since then is no reason to ask about one it doesn't hold. - It reads the journal's `ahead` instead of taking it out while it asks. Holding only its own pages, it now lets other threads ask meanwhile, and the journal goes on answering them for what `ask_ahead` asked. - **Unchanged:** the rule itself, that no two threads ask about the same pages at once, and the asking numbers. ## Tests - New `watch::ask_holds::ranges_are_merged_in_order_and_told_apart` checks the range helpers (`merged`, `overlaps`). - New `watch::ask_holds::an_asking_waits_only_for_the_pages_it_asks_about`: - An asking of a held page waits until the holder lets go. Asking about other pages goes ahead at once. - Several ranges are let go together. - It fails with the hold made a no-op. - New `host::refresh_tests::askings_of_other_threads_beside_a_submission`: - Copies of the same title memory, both write-watched and view memory, are refreshed by a submission on one thread and one range at a time on another. A third thread asks about other memory nonstop. - Over 300 rounds of random writes, every copy must hold what title memory holds after each round. - **Tests that ask as a submission does now take one lock (`one_submission`).** The layer prepares one submission at a time, but in the test process `unchanged_ranges_are_known` asked as a submission does alongside other tests' submissions. - One test's asking could end another's mid-submission. Running `refresh_tests::` with `watch::` 40 times, the new test above lost a copy in 4 runs with page holds and in 1 run with all-memory holds. It never failed in 60 runs on its own. - With the lock: 0 failures in 80 runs with page holds and 0 in 40 with all-memory holds. - `cargo test -p victory-gpu --lib` on this branch: 455 passed, 0 failed, both with the switch on and with `VICTORY_ASK_HOLD_ALL=1`, three runs and two. - 40 runs each of `refresh_tests::`+`watch::`+`ask_holds` and of `many_askers_tests`, in both modes: no failures. - `cargo clippy -p victory-gpu --all-targets`: 3 warnings, the same 3 as `main`. ## Performance, before and after Not measured in the game yet. In unit benchmarks the askings don't contend, so they show nothing either way. The expected effect is that the submitting thread no longer waits for the heaps' thread's asking and guarding, nor the other way round, when they ask about different memory. The diagnostics build's "ranges held" figure in `watch::lock_waits` shows the waits per frame. Comparing a run with `VICTORY_ASK_HOLD_ALL=1` against one without will say how much this saves.
ArturoWolff commented 2026-11-28 03:52:52 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by ArturoWolff on 2026-11-28T03:52:52Z.


Linux/Proton actual-title A/B of your exact head 3055afdc724079de319f73df611d1f1e6699c1be (base .10 8fc22547), since your description notes that the range-hold timing hasn't been measured in the game yet.

RTX 4060 desktop 8 GB, 16 GB system RAM, GE-Proton11-14 / vkd3d-proton 3.2.0. One locked MSVC release executable with --features diagnostics. Both arms retain our identical previously described Linux backing/DXC adaptations and one-second read-only renderer-clock observer (details and previous baseline). Fresh separate external caches, same cloned prefix seed, Series X 1080to1440, 30 cap, DLSS/FG off, full requested RT/water effects, write-back and waits intact; both advanced without recorded input. The effective graphics/settings headers differ only in VICTORY_ASK_HOLD_ALL=1 versus 0.

Observation All-memory hold (1) Range hold (0)
Periodic lock reports 10 10
Median reported ranges-held ms/frame, all 10 intervals 0.475 0.205
Median reported ranges-held ms/frame, last 4 intervals 1.355 0.990
Largest reported ranges-held ms/frame 2.14 1.53
Minimum sampled available system RAM (MiB) 2,133 1,936
Elapsed including startup (s) 127.147 129.002
Actual exit 5 5

Whole-interval ranges-held values, in order, are 0.03, 0, 0, 0, 0.10, 0.99, 0.85, 1.43, 1.28, 2.14 versus 0, 0, 0, 0, 0.02, 0.39, 0.95, 1.53, 0.78, 1.03 ms/frame. These are the diagnostic's aggregate acquisition times across all threads, not a critical-path timing or FPS gain. The intervals and loading artwork are not exactly scene-matched; this is one cold-cache pair, not a statistical performance conclusion. The result is consistent with lower range-lock acquisition cost in this startup workload.

Both arms ended during the existing #628 loading failure, after visible artwork and black overlay. The final clock sent/completed and started/finished counters caught up respectively to 3761/3761 and 3686/3686, stationary for the last 28.05 and 16.03 sampled seconds. No device-removal/fence-error report, OOM delta, memory-guard stop or recorded kernel GPU fault in either run. Both created the previously refused compute pipeline and the two DXC fallbacks succeeded. No live-world correctness or performance established. The range-lock optimization is not sufficient to restore world entry on this configuration; useful to revisit once active gameplay can be measured.

AI assistance: Hermes Agent, working on behalf of ArturoWolff. (GPT 6.2 Sol High).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7233473575 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/697#issuecomment-7233473575). Originally posted by [ArturoWolff](https://github.com/ArturoWolff) on 2026-11-28T03:52:52Z. --- Linux/Proton actual-title A/B of your exact head `3055afdc724079de319f73df611d1f1e6699c1be` (base `.10` `8fc22547`), since your description notes that the range-hold timing hasn't been measured in the game yet. RTX 4060 desktop 8 GB, 16 GB system RAM, GE-Proton11-14 / vkd3d-proton 3.2.0. One locked MSVC release executable with `--features diagnostics`. Both arms retain our identical previously described Linux backing/DXC adaptations and one-second read-only renderer-clock observer ([details and previous baseline](https://github.com/trustno1-coder/VIctory-NVIDIA/issues/628#issuecomment-7233278386)). Fresh separate external caches, same cloned prefix seed, Series X `1080to1440`, 30 cap, DLSS/FG off, full requested RT/water effects, write-back and waits intact; both advanced without recorded input. The effective graphics/settings headers differ only in `VICTORY_ASK_HOLD_ALL=1` versus `0`. | Observation | All-memory hold (1) | Range hold (0) | |---|---:|---:| | Periodic lock reports | 10 | 10 | | Median reported ranges-held ms/frame, all 10 intervals | 0.475 | 0.205 | | Median reported ranges-held ms/frame, last 4 intervals | 1.355 | 0.990 | | Largest reported ranges-held ms/frame | 2.14 | 1.53 | | Minimum sampled available system RAM (MiB) | 2,133 | 1,936 | | Elapsed including startup (s) | 127.147 | 129.002 | | Actual exit | 5 | 5 | Whole-interval ranges-held values, in order, are `0.03, 0, 0, 0, 0.10, 0.99, 0.85, 1.43, 1.28, 2.14` versus `0, 0, 0, 0, 0.02, 0.39, 0.95, 1.53, 0.78, 1.03` ms/frame. These are the diagnostic's aggregate acquisition times across all threads, not a critical-path timing or FPS gain. The intervals and loading artwork are not exactly scene-matched; this is one cold-cache pair, not a statistical performance conclusion. The result is consistent with lower range-lock acquisition cost in this startup workload. Both arms ended during the existing #628 loading failure, after visible artwork and black overlay. The final clock sent/completed and started/finished counters caught up respectively to 3761/3761 and 3686/3686, stationary for the last 28.05 and 16.03 sampled seconds. No device-removal/fence-error report, OOM delta, memory-guard stop or recorded kernel GPU fault in either run. Both created the previously refused compute pipeline and the two DXC fallbacks succeeded. No live-world correctness or performance established. The range-lock optimization is not sufficient to restore world entry on this configuration; useful to revisit once active gameplay can be measured. AI assistance: Hermes Agent, working on behalf of ArturoWolff. (GPT 6.2 Sol High).
CuteBooty commented 2026-11-28 04:42:08 +00:00 (Migrated from github.com)

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


Open-world numbers for this PR from an 8 GB NVIDIA card, to go with the startup A/B above.

  • 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; VICTORY_THIN=1, VICTORY_RELAY=2, VICTORY_SOFT_VIEWS=copies.
  • This is not an A/B inside one build. I compare my previous build without this PR (main 8fc22547c + local commits, one session of 19 minutes) with the next one with it (main 63b902fe1 + this PR's commit + #630 + the same local commits, one session of 16.7 minutes): same settings apart from one unrelated lighting switch, same part of the map, same evening.
  • In the second session VICTORY_FAULT_UNLOCKED was being flipped every 30 s by the in-run A/B, so the "ranges held" figures are given for both of its sides.
per frame without #697 with #697, fault lock as before with #697, VICTORY_FAULT_UNLOCKED on
"ranges held", all threads: median / p90 / worst 1.55 / 2.06 / 2.81 ms (206 lines) 0.97 / 1.38 / 2.36 ms (94 lines) 0.51 / 0.70 / 0.91 ms (88 lines)
submitting thread, "asking the write watch": median / p90 / worst 4.50 / 5.40 / 8.20 ms (1,031 lines) 3.90 / 4.70 / 6.90 ms (910 lines, both sides)
frame time at 5-7k draws 61 ms 64 ms (both sides)
frame time at 7-9k draws 68 ms 70 ms
frame time at 9-11k draws 78 ms 73 ms
  • So the hold time falls by about a third (by two thirds with the fault lock off as well) and the submitting thread's asking by about 0.6 ms a frame. The frame time is unchanged within run-to-run noise; these frames are 60-75 ms and bound by the submitting thread's other work.
  • No error lines. The player reported no stuck or flickering geometry in the 16.7 minutes (on foot in town and driving).
  • VICTORY_ASK_HOLD_ALL=1 on the same exe would be the cleaner comparison. I can run that if it is useful.

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

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7234204931 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/697#issuecomment-7234204931). Originally posted by [CuteBooty](https://github.com/CuteBooty) on 2026-11-28T04:42:08Z. --- Open-world numbers for this PR from an 8 GB NVIDIA card, to go with the startup A/B above. - 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; `VICTORY_THIN=1`, `VICTORY_RELAY=2`, `VICTORY_SOFT_VIEWS=copies`. - This is **not** an A/B inside one build. I compare my previous build without this PR (main `8fc22547c` + local commits, one session of 19 minutes) with the next one with it (main `63b902fe1` + this PR's commit + #630 + the same local commits, one session of 16.7 minutes): same settings apart from one unrelated lighting switch, same part of the map, same evening. - In the second session `VICTORY_FAULT_UNLOCKED` was being flipped every 30 s by the in-run A/B, so the "ranges held" figures are given for both of its sides. | per frame | without #697 | with #697, fault lock as before | with #697, `VICTORY_FAULT_UNLOCKED` on | |---|---|---|---| | "ranges held", all threads: median / p90 / worst | 1.55 / 2.06 / 2.81 ms (206 lines) | 0.97 / 1.38 / 2.36 ms (94 lines) | 0.51 / 0.70 / 0.91 ms (88 lines) | | submitting thread, "asking the write watch": median / p90 / worst | 4.50 / 5.40 / 8.20 ms (1,031 lines) | 3.90 / 4.70 / 6.90 ms (910 lines, both sides) | | | frame time at 5-7k draws | 61 ms | 64 ms (both sides) | | | frame time at 7-9k draws | 68 ms | 70 ms | | | frame time at 9-11k draws | 78 ms | 73 ms | | - So the hold time falls by about a third (by two thirds with the fault lock off as well) and the submitting thread's asking by about 0.6 ms a frame. The frame time is unchanged within run-to-run noise; these frames are 60-75 ms and bound by the submitting thread's other work. - No error lines. The player reported no stuck or flickering geometry in the 16.7 minutes (on foot in town and driving). - `VICTORY_ASK_HOLD_ALL=1` on the same exe would be the cleaner comparison. I can run that if it is useful. Measurements and this report were prepared with an AI assistant (Claude Code); the runs were played on my machine.
Dukestar69 commented 2026-11-28 04:47:11 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Dukestar69 on 2026-11-28T04:47:11Z.

Review: APPROVED


LGTM — verified on Windows:

  • cargo test -p victory-gpu --lib watch:: passed (49/49, including both new watch::ask_holds:: tests)
  • 0 new compiler warnings in touched files
  • cargo xtask policy passed (294 files ok)

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review:6095869203 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/697#pullrequestreview-6095869203). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-28T04:47:11Z. **Review:** APPROVED --- LGTM — verified on Windows: - `cargo test -p victory-gpu --lib watch::` passed (49/49, including both new `watch::ask_holds::` tests) - 0 new compiler warnings in touched files - `cargo xtask policy` passed (`294 files ok`) Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
urielbeaupre commented 2026-11-28 17:06:30 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by urielbeaupre on 2026-11-28T17:06:30Z.


An A/B on top of other copy-path work, for the record. RTX 4070 Ti 12 GB, Ryzen 9 7900X, Series S profile, DLSS off, same save, warm caches.

Base: main 63b902f with #1038 and #1184 (lazy landing/fetch on). That base already removes most per-frame refresh and copy-back work on the 21 MB buffer. #697 and #1133 merged cleanly on top; VICTORY_ASK_HOLD_ALL=1 gives #1133 alone. Cutscene = 60–110 s after input, after = 110–165 s. Warm runs only (the new build's first run built pipelines and isn't counted):

cutscene fps after scene change CPU preparing (cutscene) copying per frame
base (2 runs) 38.0 / 40.1 24.9 / 25.0 20.6 / 19.3 ms 12.0 / 11.3 ms
+ #1133 (1 run) 38.4 23.8 21.1 ms 12.8 ms
+ #1133 + #697 (2 runs) 37.8 / 37.4 26.0 / 22.9 20.8 / 21.1 ms 11.7 / 14.2 ms

On this setup neither shows a gain. Both are within about ±1.5 fps of the base, which is run-to-run noise here, and with both the copying is about 1.3 ms higher on average. No errors, and draw counts match.

This doesn't say the PRs are wrong. Where most refresh spans are already nothing_new and the big buffer no longer goes round the CPU, there's little left for them to save. In heavy scenes on this machine, the submit thread's biggest cost now is the refreshes themselves: about 23 ms a frame over ~6,500 spans, of which ~5,200 copy nothing.

🤖 Generated with Claude Code

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7242759629 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/697#issuecomment-7242759629). Originally posted by [urielbeaupre](https://github.com/urielbeaupre) on 2026-11-28T17:06:30Z. --- An A/B on top of other copy-path work, for the record. RTX 4070 Ti 12 GB, Ryzen 9 7900X, Series S profile, DLSS off, same save, warm caches. Base: main 63b902f with #1038 and #1184 (lazy landing/fetch on). That base already removes most per-frame refresh and copy-back work on the 21 MB buffer. #697 and #1133 merged cleanly on top; `VICTORY_ASK_HOLD_ALL=1` gives #1133 alone. Cutscene = 60–110 s after input, after = 110–165 s. Warm runs only (the new build's first run built pipelines and isn't counted): | | cutscene fps | after scene change | CPU preparing (cutscene) | copying per frame | |---|---|---|---|---| | base (2 runs) | 38.0 / 40.1 | 24.9 / 25.0 | 20.6 / 19.3 ms | 12.0 / 11.3 ms | | + #1133 (1 run) | 38.4 | 23.8 | 21.1 ms | 12.8 ms | | + #1133 + #697 (2 runs) | 37.8 / 37.4 | 26.0 / 22.9 | 20.8 / 21.1 ms | 11.7 / 14.2 ms | On this setup neither shows a gain. Both are within about ±1.5 fps of the base, which is run-to-run noise here, and with both the copying is about 1.3 ms higher on average. No errors, and draw counts match. This doesn't say the PRs are wrong. Where most refresh spans are already `nothing_new` and the big buffer no longer goes round the CPU, there's little left for them to save. In heavy scenes on this machine, the submit thread's biggest cost now is the refreshes themselves: about 23 ms a frame over ~6,500 spans, of which ~5,200 copy nothing. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!697
No description provided.