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
github-bot wants to merge 1 commit from github-bot/gh-670 into main AGit
Owner

@⁠Jonirulah on GitHub · 2026-11-25 04:20 UTC · original
Jonirulah:view-ask-skip → main · +55 −10 · 2 files · 1 commits · open

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

**@⁠Jonirulah** on GitHub · 2026-11-25 04:20 UTC · [original](https://github.com/fxceless/victory-fork/pull/670) `Jonirulah:view-ask-skip` → `main` · +55 −10 · 2 files · 1 commits · open `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)
watch::writes asked GetWriteWatch first for every range not covered by the
submission's single asking, and only went to the guards after the call
failed. View memory (the guards' protected or absent blocks) cannot be
write-watched, so every flush of a copy over it paid one failing kernel
call before the guards answered. Ask the guards' sets first and skip the
call for such ranges. VICTORY_VIEW_ASK=1 (or VICTORY_GUARD_ASK=1) restores
the old behaviour for A/B runs.

Diagnostics: two counters, printed before the barrier-waits line: askings
that failed in the kernel, and askings not made for known view memory.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:48:38 +00:00
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/copystat.rs
  • crates/victory-gpu/src/watch.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/670/head:github-bot/gh-670'
git switch 'github-bot/gh-670'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-670'
git switch 'github-bot/gh-670'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-670'
git switch 'github-bot/gh-670'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-670'
git switch 'main'
git merge --squash 'github-bot/gh-670'
git switch 'main'
git merge --ff-only 'github-bot/gh-670'
git switch 'main'
git merge 'github-bot/gh-670'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.