GPU/watch: skip the kernel write-watch asking for known guarded view memory (~3,600 failing kernel calls and ~6-8 ms of submitting-thread CPU per frame) #670

Open
Jonirulah wants to merge 1 commit from upstream-pr/670 into main
Jonirulah commented 2026-11-25 04:20:11 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Jonirulah on 2026-11-25T04:20:11Z.


watch::writes asks GetWriteWatch first for every range that the submission's single asking did not cover, and goes to the guards only after that call fails. View memory, meaning the guards' protected or absent blocks, can never be write-watched. So every flush of a copy over view memory paid one failing kernel call before the guards answered.

This change checks the guards' sets first and skips the kernel call for those ranges. The guards' answer is the same as before. VICTORY_VIEW_ASK=1 (or the existing VICTORY_GUARD_ASK=1) brings the old behaviour back for A/B runs.

Diagnostics builds get two new per-frame counters, printed before the barrier-waits line: askings that failed in the kernel, and askings skipped for known view memory.

Measurements

Setup:

  • RTX 3070 Laptop 8 GB, Ryzen 7 5800H, Windows 11 26100, --console series-s.
  • Diag build of this change on top of c96b4f2 plus a few local patches (#188 is needed for Series S).
  • Env: VICTORY_PIPELINE_WAIT_MS=24 VICTORY_LEAN_WINDOWS=1 VICTORY_WINDOW_KB=1024 VICTORY_WINDOW_TAILS=1 VICTORY_INPLACE=1.
  • Same executable for both runs, with a warm shader cache (hits=3000, misses=0 in both).

Medians once the world draws (≥1000 draws/frame):

VICTORY_VIEW_ASK=1 (old) this change
write-watch askings failing in the kernel, per frame 3879 264
askings skipped (known view memory), per frame 0 3269
write-watch time per frame (steady part, t ≥ 150 s) 36.7 ms 29.9 ms
"preparing" per frame (steady part) 226.7 ms 220.9 ms
ms/frame (steady part) 355 367

About 3,600 failing kernel calls and about 6–7 ms of submitting-thread CPU are gone per frame. Frame time does not change measurably: the ±12 ms difference is within run-to-run noise with 11–13 reports per run, and copying back (~230 ms/frame) dominates the frame in this scene.

This saving is on the submitting thread. With #648 (VICTORY_CARD_FETCH_INFLIGHT=1), the relay's ~140 ms/frame wait for fetches is gone and that thread's preparing now sets the frame. Measured together with #648 (same diag build and config plus VICTORY_CARD_FETCH_INFLIGHT=1, steady part ≥ 120 s after the world appears, one run each):

#648 alone #648 + this change
ms/frame 312 295
write-watch time per frame 37.7 ms 29.4 ms
submitting thread inside submissions 138.3 user + 93.0 kernel ms 127.3 user + 86.7 kernel ms
kernel askings that failed, per frame — 242

About 17 ms of submitting-thread CPU per frame is gone. Frame time drops by 17 ms here, but with one run each that cannot all be attributed to this change.

Tests (this branch, on 310c6eb)

  • cargo test -p victory-gpu: 118 passed, 0 failed.
  • cargo test --workspace --no-fail-fast --exclude victory-shader: all passed.
  • cargo test -p victory-shader --lib: 4 failures (emit::valu_tests::ds_min_max_f32_order_floats_and_return_the_old_value, v_permlane16_and_x16_read_the_lanes_their_selectors_pick, whole_wave_f64_sum_and_cvt_f32_f64, emit::waterfall_tests::lanes_load_from_the_buffer_their_nested_arms_chose). These come from main: this change does not touch victory-shader, and that crate does not depend on victory-gpu.
  • cargo clippy --workspace --all-targets -- -D warnings fails on main's own code, in files this change does not touch: resource.rs:2257 (placed_filler_twins unused), draw.rs:2339 (sort_unstable_by_key) and indirect.rs:1322 (depth_written never read). Neither changed file adds a warning.
  • cargo xtask policy: 169 files ok.

🤖 Generated with Claude Code

<!-- greyfinch-sync:fxceless/victory-fork:issue:6597127150 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/670). Originally posted by [Jonirulah](https://github.com/Jonirulah) on 2026-11-25T04:20:11Z. --- `watch::writes` asks `GetWriteWatch` first for every range that the submission's single asking did not cover, and goes to the guards only after that call fails. View memory, meaning the guards' protected or absent blocks, can never be write-watched. So every flush of a copy over view memory paid one failing kernel call before the guards answered. This change checks the guards' sets first and skips the kernel call for those ranges. The guards' answer is the same as before. `VICTORY_VIEW_ASK=1` (or the existing `VICTORY_GUARD_ASK=1`) brings the old behaviour back for A/B runs. Diagnostics builds get two new per-frame counters, printed before the barrier-waits line: askings that failed in the kernel, and askings skipped for known view memory. ### Measurements Setup: - RTX 3070 Laptop 8 GB, Ryzen 7 5800H, Windows 11 26100, `--console series-s`. - Diag build of this change on top of c96b4f2 plus a few local patches (#188 is needed for Series S). - Env: `VICTORY_PIPELINE_WAIT_MS=24 VICTORY_LEAN_WINDOWS=1 VICTORY_WINDOW_KB=1024 VICTORY_WINDOW_TAILS=1 VICTORY_INPLACE=1`. - Same executable for both runs, with a warm shader cache (hits=3000, misses=0 in both). Medians once the world draws (≥1000 draws/frame): | | `VICTORY_VIEW_ASK=1` (old) | this change | |---|---|---| | write-watch askings failing in the kernel, per frame | 3879 | 264 | | askings skipped (known view memory), per frame | 0 | 3269 | | write-watch time per frame (steady part, t ≥ 150 s) | 36.7 ms | 29.9 ms | | "preparing" per frame (steady part) | 226.7 ms | 220.9 ms | | ms/frame (steady part) | 355 | 367 | About 3,600 failing kernel calls and about 6–7 ms of submitting-thread CPU are gone per frame. Frame time does not change measurably: the ±12 ms difference is within run-to-run noise with 11–13 reports per run, and copying back (~230 ms/frame) dominates the frame in this scene. This saving is on the submitting thread. With #648 (`VICTORY_CARD_FETCH_INFLIGHT=1`), the relay's ~140 ms/frame wait for fetches is gone and that thread's preparing now sets the frame. Measured together with #648 (same diag build and config plus `VICTORY_CARD_FETCH_INFLIGHT=1`, steady part ≥ 120 s after the world appears, one run each): | | #648 alone | #648 + this change | |---|---|---| | ms/frame | 312 | 295 | | write-watch time per frame | 37.7 ms | 29.4 ms | | submitting thread inside submissions | 138.3 user + 93.0 kernel ms | 127.3 user + 86.7 kernel ms | | kernel askings that failed, per frame | — | 242 | About 17 ms of submitting-thread CPU per frame is gone. Frame time drops by 17 ms here, but with one run each that cannot all be attributed to this change. ### Tests (this branch, on 310c6eb) - `cargo test -p victory-gpu`: 118 passed, 0 failed. - `cargo test --workspace --no-fail-fast --exclude victory-shader`: all passed. - `cargo test -p victory-shader --lib`: 4 failures (`emit::valu_tests::ds_min_max_f32_order_floats_and_return_the_old_value`, `v_permlane16_and_x16_read_the_lanes_their_selectors_pick`, `whole_wave_f64_sum_and_cvt_f32_f64`, `emit::waterfall_tests::lanes_load_from_the_buffer_their_nested_arms_chose`). These come from `main`: this change does not touch `victory-shader`, and that crate does not depend on `victory-gpu`. - `cargo clippy --workspace --all-targets -- -D warnings` fails on `main`'s own code, in files this change does not touch: `resource.rs:2257` (`placed_filler_twins` unused), `draw.rs:2339` (`sort_unstable_by_key`) and `indirect.rs:1322` (`depth_written` never read). Neither changed file adds a warning. - `cargo xtask policy`: 169 files ok. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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/670:upstream-pr/670'
git switch 'upstream-pr/670'

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/670'
git switch 'upstream-pr/670'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/670'
git switch 'upstream-pr/670'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/670'
git switch 'main'
git merge --squash 'upstream-pr/670'
git switch 'main'
git merge --ff-only 'upstream-pr/670'
git switch 'main'
git merge 'upstream-pr/670'
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
fxceless/victory-fork!670
No description provided.