Skip to content

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 into
fxceless:mainfrom
Jonirulah:view-ask-skip
Open

Jonirulah wants to merge 1 commit into
fxceless:mainfrom
Jonirulah:view-ask-skip

Conversation

@Jonirulah

Copy link
Copy Markdown

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 (Series S: the second present plane, and a plain stretch for the upscale dispatch #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

…memory

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 <noreply@anthropic.com>
triippywhale pushed a commit to triippywhale/victory-fork that referenced this pull request Nov 25, 2026
Ported from fxceless#670 (05d3775), onto the guards'
bitmaps, and taken one step further.

View memory cannot be write-watched, so `GetWriteWatch` can only fail
there; the guards answer afterwards. `writes` asked the kernel first for
every range not covered by the submission's ahead asking, and paid that
failed call each time. It now asks the guards first (by the range's first
block, as `guard` itself takes a range) and skips the kernel for view
memory they hold.

The same held for `ask_ahead`, which the fork's PR does not touch: a run
of view-memory ranges failed in the kernel, was asked again by halves
down to single ranges, failing each time, and then each range failed
once more in `writes`, about twice as many failed calls as ranges. Those
ranges are now left out of the ahead asking and go straight to `writes`.

The failed askings were never counted (`watches` counts the ones that
answer). A new stats line counts both: askings that failed in the kernel
and askings not made for memory the guards hold. `VICTORY_VIEW_ASK=1` (or
`VICTORY_GUARD_ASK=1`) asks the kernel as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017V7WBB9Mgcxkr8YRW4LAzi
fxceless added a commit that referenced this pull request Nov 25, 2026
…c, draw-table slots left to their draws, no failing write-watch calls; card fetches inside their flights (off by default)

- Descriptor sync: a multiply-and-fold fingerprint of a record in place of
  BLAKE3 (35 to 42 ms a frame over 250,000 to 300,000 records), and slots
  that draws read through tables lately are left to their draws
  (VICTORY_HEAP_SYNC_TABLES=1 mirrors them too): the pass over the heap
  went from 70-220 ms a frame to about 3.
- Write watch: no kernel asking for memory the guards already hold as view
  memory (pull request #670 by Jonirulah).
- Card copies' flagged pieces can come down inside their own flights
  (pull request #648 by Jonirulah; VICTORY_CARD_FETCH_INFLIGHT=1, off by
  default). One game run with it on: no device loss, the copy-back
  thread's fetch wait 181 -> 0 ms a frame, the card busier; no frame-time
  gain claimed.
- Logging: the heap pass's texture part and buffer slots; indirect compute
  dispatches over 65,535 groups.
- README: what was measured, and that pull request #220 with
  VICTORY_INDIRECT_WINDOW=1 lost the device twice here and is not in.

One five-minute game run of this tree's source on an RTX 4070: no device
loss; the frame is still 250 to 380 ms (the card is the limit). This
merged tree was built; its test suites were not run.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
triippywhale pushed a commit to triippywhale/victory-fork that referenced this pull request Nov 25, 2026
ask_once asks the kernel's write watch, once per copy, about the ranges
a submission refreshes. ask_ahead already left guarded view memory out,
but the per-range loop after it did not. Every copy of view memory was
therefore one failed GetWriteWatch at each submission, on the submitting
thread: the 5adccfe run counted 4,050 failed askings a frame, about one
per guarded copy over 30 submissions. writes() already answers such
memory from the guards (known_view, from fxceless#670), so
the loop now skips it the same way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017V7WBB9Mgcxkr8YRW4LAzi
HelmXGaming added a commit to HelmXGaming/victory-fork that referenced this pull request Nov 25, 2026
…copy queue, indirect windows, profiler; all behind switches)

Brings in 9376fd6 too. On this NVIDIA laptop 9376fd6 hung the device
twice by default (its write-watch shortcut, fxceless#670); VICTORY_VIEW_ASK=1
avoided it. Test with that set.

Conflict in indirect.rs, kept from both sides:
- The clamp shader keeps upstream's per-group budget charge and its
  MOST_DRAW guard, and this side's dispatch in parts (SPLIT records for
  one compute dispatch past 65,535 groups in x, the prologue's indirect
  light gather). This side's wide-dispatch counters in budget words 3-4
  are dropped: upstream no longer reads or zeroes them.
- clamp_into (upstream's state-tracked scratch) takes this side's `how`
  bits (AHEAD, IN_PARTS) instead of a bool; bound_split goes through it.
- The split test reads back like upstream's tests (INDIRECT_ARGUMENT ->
  COPY_SOURCE).

cargo test -p victory-gpu --lib indirect:: texture:: watch:: : 30 passed,
1 failed (warp_budget_saturates_..., the upstream race between two groups
that fxceless#847 describes; not this merge), 2 ignored.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant