perf(texture): single-query zero-alloc write-watch/guard check in refresh_timed #296

Closed
github-bot wants to merge 0 commits from github-bot/gh-296 into main AGit
Owner

@⁠leixner on GitHub · 2026-12-01 10:55 UTC · original
leixner:perf/texture-watch-single-query → main · +139 −18 · 2 files · 67 commits · closed without merging

Summary

Cuts texture refresh write-watch/guard overhead by ~78% (3.70 -> 0.80 ms med, 4.70 -> 1.30 ms p90) by replacing the double watch::writes(..., false) + watch::writes(..., true) sequence in texture::refresh_timed with a single zero-allocation watch::writes_since query.

Problem

On every refresh of a guarded view-memory texture, texture::refresh_timed previously:

  1. Called watch::writes(start, start + size, false) first — acquiring the global Asking::hold mutex across texture worker threads and issuing a doomed GetWriteWatch (kernel_written) syscall that always fails on view memory.
  2. Then called watch::writes(start, start + size, true) — hitting published(start, end) and heap-allocating a Vec<(usize, u64)> of written pages solely to check written.iter().all(|&(_, w)| w <= last.asked).

Changes

  • crates/victory-gpu/src/watch.rs:
    • Added Journal::any_written_after(first, last, since) to check for writes newer than since directly against written_fast / written without allocating a Vec.
    • Added watch::writes_since(start, end, since, allow_guarded) -> Option<(u64, bool, bool)> returning (now, any_written, was_guarded): checks ahead, then allow_guarded && published(start, end) before acquiring Asking::hold or calling kernel_written, and handles both write-watched (was_guarded = false) and guarded view-memory (was_guarded = true) paths in one call.
    • Added unit test watch::ask_holds::journal_any_written_after_matches_written_in.
  • crates/victory-gpu/src/texture.rs:
    • Updated Staging::refresh_timed to use watch::writes_since(start, start + size, last.asked, allow_guard) in place of the two sequential watch::writes calls, preserving identical behavior for both write-watched and guarded textures (including VICTORY_TEXTURE_GUARD=0).

Verification

  • cargo test -p victory-gpu --lib watch — 52 passed, 0 failed.
  • cargo test -p victory-gpu --lib texture — 32 passed, 0 failed.
  • cargo xtask policy — 293 files ok.
  • Gameplay A/B on Ryzen 7 5700X + RTX 3070 8 GB (Xbox Series X @ 1440p, VICTORY_WIDE_THREADS=8, 199 gameplay windows, 0 errors):
Metric (med / mean / p90) Baseline (main) This PR Delta
Texture watch (asking the write watch & guards) 3.70 / 3.50 / 4.70 ms 0.80 / 0.82 / 1.30 ms -78% med / -72% p90
Texture refreshes (all threads) 21.40 / 26.09 / 33.10 ms 17.00 / 25.64 / 29.30 ms -21% med / -11% p90
Submitting thread total 59.40 / 57.22 / 68.60 ms 53.40 / 52.76 / 64.00 ms -10% med / -7% p90
**@⁠leixner** on GitHub · 2026-12-01 10:55 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/296) `leixner:perf/texture-watch-single-query` → `main` · +139 −18 · 2 files · 67 commits · closed without merging ## Summary Cuts texture refresh write-watch/guard overhead by **~78%** (`3.70 -> 0.80 ms` med, `4.70 -> 1.30 ms` p90) by replacing the double `watch::writes(..., false)` + `watch::writes(..., true)` sequence in `texture::refresh_timed` with a single zero-allocation `watch::writes_since` query. ### Problem On every refresh of a guarded view-memory texture, `texture::refresh_timed` previously: 1. Called `watch::writes(start, start + size, false)` first — acquiring the global `Asking::hold` mutex across texture worker threads and issuing a doomed `GetWriteWatch` (`kernel_written`) syscall that always fails on view memory. 2. Then called `watch::writes(start, start + size, true)` — hitting `published(start, end)` and heap-allocating a `Vec<(usize, u64)>` of written pages solely to check `written.iter().all(|&(_, w)| w <= last.asked)`. ### Changes - **`crates/victory-gpu/src/watch.rs`**: - Added `Journal::any_written_after(first, last, since)` to check for writes newer than `since` directly against `written_fast` / `written` without allocating a `Vec`. - Added `watch::writes_since(start, end, since, allow_guarded) -> Option<(u64, bool, bool)>` returning `(now, any_written, was_guarded)`: checks `ahead`, then `allow_guarded && published(start, end)` *before* acquiring `Asking::hold` or calling `kernel_written`, and handles both write-watched (`was_guarded = false`) and guarded view-memory (`was_guarded = true`) paths in one call. - Added unit test `watch::ask_holds::journal_any_written_after_matches_written_in`. - **`crates/victory-gpu/src/texture.rs`**: - Updated `Staging::refresh_timed` to use `watch::writes_since(start, start + size, last.asked, allow_guard)` in place of the two sequential `watch::writes` calls, preserving identical behavior for both write-watched and guarded textures (including `VICTORY_TEXTURE_GUARD=0`). ## Verification - `cargo test -p victory-gpu --lib watch` — **52 passed, 0 failed**. - `cargo test -p victory-gpu --lib texture` — **32 passed, 0 failed**. - `cargo xtask policy` — **293 files ok**. - Gameplay A/B on Ryzen 7 5700X + RTX 3070 8 GB (Xbox Series X @ 1440p, `VICTORY_WIDE_THREADS=8`, 199 gameplay windows, 0 errors): | Metric (med / mean / p90) | Baseline (`main`) | This PR | Delta | | --- | --- | --- | --- | | Texture watch (`asking the write watch & guards`) | 3.70 / 3.50 / 4.70 ms | **0.80 / 0.82 / 1.30 ms** | **-78% med / -72% p90** | | Texture refreshes (all threads) | 21.40 / 26.09 / 33.10 ms | **17.00 / 25.64 / 29.30 ms** | **-21% med / -11% p90** | | Submitting thread total | 59.40 / 57.22 / 68.60 ms | **53.40 / 52.76 / 64.00 ms** | **-10% med / -7% p90** |
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 10:59:56 +00:00
Author
Owner

@⁠Aniseto on GitHub · 2026-12-01 11:18 UTC · original

Ran the watch and texture test groups at 6de8a3ca on an NVIDIA Blackwell desktop part with 16 GB of VRAM.

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.98.1 (48a229cea 2026-09-01), MSVC 14.44.35207, debug build, detached worktree at the exact PR head, own CARGO_TARGET_DIR, no local patches.

cargo test -q -p victory-gpu --lib watch -- --test-threads=1
52 passed; 0 failed; 0 ignored; 460 filtered out      (exit 0)

cargo test -q -p victory-gpu --lib texture -- --test-threads=1
32 passed; 0 failed; 6 ignored; 474 filtered out      (exit 0)

Both counts match the description, including watch::ask_holds::journal_any_written_after_matches_written_in. The six ignored tests in texture come from the wider filter. The description notes that watch fails randomly on its host with and without related changes; it passed here in one run, so no repeatability claim is made. No title run was done, so the cost of the write-watch query was not measured.

Not tested: the full workspace suite, a retail title, a paired frame-time A/B, Wine, AMD adapters, release profile, game data.

AI-assisted (OpenCode), model: MiMo-V2.6-Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

**@⁠Aniseto** on GitHub · 2026-12-01 11:18 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/296#issuecomment-7309469667) Ran the `watch` and `texture` test groups at `6de8a3ca` on an NVIDIA Blackwell desktop part with 16 GB of VRAM. Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.98.1 (48a229cea 2026-09-01), MSVC 14.44.35207, debug build, detached worktree at the exact PR head, own `CARGO_TARGET_DIR`, no local patches. ``` cargo test -q -p victory-gpu --lib watch -- --test-threads=1 52 passed; 0 failed; 0 ignored; 460 filtered out (exit 0) cargo test -q -p victory-gpu --lib texture -- --test-threads=1 32 passed; 0 failed; 6 ignored; 474 filtered out (exit 0) ``` Both counts match the description, including `watch::ask_holds::journal_any_written_after_matches_written_in`. The six ignored tests in `texture` come from the wider filter. The description notes that `watch` fails randomly on its host with and without related changes; it passed here in one run, so no repeatability claim is made. No title run was done, so the cost of the write-watch query was not measured. Not tested: the full workspace suite, a retail title, a paired frame-time A/B, Wine, AMD adapters, release profile, game data. AI-assisted (OpenCode), model: **MiMo-V2.6-Flash Free** - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.
Author
Owner

@⁠readmet3xt-lab on GitHub · 2026-12-01 12:16 UTC · original

Checked: nothing harmful in it, and it passes the lint check in both feature sets and the whole test suite (1,158 tests) on the batch branch. The release now in testing is frozen, so this is on the batch for the release after it, as one commit with you as its author. Nothing is needed from you now; the result of the run will be posted here.

**@⁠readmet3xt-lab** on GitHub · 2026-12-01 12:16 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/296#issuecomment-7310899240) Checked: nothing harmful in it, and it passes the lint check in both feature sets and the whole test suite (1,158 tests) on the batch branch. The release now in testing is frozen, so this is on the batch for the release after it, as one commit with you as its author. Nothing is needed from you now; the result of the run will be posted here.
github-bot closed this pull request 2026-12-02 07:54:49 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.