perf(gpu/watch): skip exclusive GUARDS lock on unguarded title_memory_written and share lock in written_since_taken #25

Closed
github-bot wants to merge 1 commit from gh-pr/25/head into gh-pr/25/base
Owner

@⁠justadudeinbulgaria on GitHub · 2026-12-01 18:15 UTC · original
justadudeinbulgaria:pr/watch-lock-avoidance → main · +8 −5 · 1 files · 1 commits · closed without merging

Summary

Two surgical lock-avoidance wins in crates/victory-gpu/src/watch.rs that reduce GUARDS write-lock stalls against Renderer Port #6 (VICTORY_PORT_GUARD=1) without replacing Port #6's 64 KiB RwLock + Claims design (inspired by Androtim/MiniVI#287 audit):

  1. title_memory_written(): Add an atomic if PROTECTED.any(first, last) fast-path before acquiring exclusive guards() (mirroring the identical check views_mapped() already performs 20 lines below). DirectStorage/page writes into unguarded title memory no longer take an exclusive GUARDS write lock or block concurrent VEH fault handlers.
  2. written_since_taken(): Use guards_shared() instead of exclusive guards() when port_guard() is active, since it only reads g.clean, g.absent, and g.protected.

Verification

  • Zero shader-cache invalidation (crates/victory-shader/* and shader_cache.rs untouched).
  • Unit tests: cargo test -p victory-gpu --lib watch::tests:: -- --test-threads=1 — 31/31 passed on origin/main (48413c9).
  • Live gameplay (i5-10600K 6C/12T + RTX 2060 SUPER 8 GB, 1080p DLSS Perf + FSR 3 FG 2X): Steady-state PORT_GUARD shared-lock wait dropped from 2.93–3.47 ms to 0.45–0.52 ms (~6x lower), contributing to SUB dropping from 51.5 ms to 32.4–44.8 ms and live frametime dropping from 104.5 ms to 85.0–93.4 ms.
**@⁠justadudeinbulgaria** on GitHub · 2026-12-01 18:15 UTC · [original](https://github.com/ToLIManl/VIctory-Hydra/pull/25) `justadudeinbulgaria:pr/watch-lock-avoidance` → `main` · +8 −5 · 1 files · 1 commits · closed without merging ## Summary Two surgical lock-avoidance wins in `crates/victory-gpu/src/watch.rs` that reduce `GUARDS` write-lock stalls against Renderer Port #6 (`VICTORY_PORT_GUARD=1`) without replacing Port #6's 64 KiB `RwLock` + `Claims` design (inspired by `Androtim/MiniVI#287` audit): 1. **`title_memory_written()`**: Add an atomic `if PROTECTED.any(first, last)` fast-path before acquiring exclusive `guards()` (mirroring the identical check `views_mapped()` already performs 20 lines below). DirectStorage/page writes into unguarded title memory no longer take an exclusive `GUARDS` write lock or block concurrent VEH fault handlers. 2. **`written_since_taken()`**: Use `guards_shared()` instead of exclusive `guards()` when `port_guard()` is active, since it only reads `g.clean`, `g.absent`, and `g.protected`. ## Verification - **Zero shader-cache invalidation** (`crates/victory-shader/*` and `shader_cache.rs` untouched). - **Unit tests**: `cargo test -p victory-gpu --lib watch::tests:: -- --test-threads=1` — **31/31 passed** on `origin/main` (`48413c9`). - **Live gameplay (i5-10600K 6C/12T + RTX 2060 SUPER 8 GB, 1080p DLSS Perf + FSR 3 FG 2X)**: Steady-state `PORT_GUARD` shared-lock wait dropped from **`2.93–3.47 ms`** to **`0.45–0.52 ms`** (~6x lower), contributing to `SUB` dropping from `51.5 ms` to `32.4–44.8 ms` and live frametime dropping from `104.5 ms` to `85.0–93.4 ms`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 17:09:09 +00:00
github-bot closed this pull request 2026-12-02 17:09:09 +00:00
Author
Owner

@⁠ToLIManl on GitHub · 2026-12-02 12:54 UTC · original

Thank you @⁠justadudeinbulgaria! Integrated onto v2.0 main in commit 5d7f3ef with full Co-authored-by credit:

  • Ported the if PROTECTED.any(first, last) lock-avoidance fast path into watch.rs::title_memory_written (skipping the GUARDS mutex on unguarded memory writes).
  • (Note: the written_since_taken RwLock portion didn't apply directly because v2.0 watch.rs uses a Mutex for GUARDS rather than the older port_guard() RwLock.)

Included in the refreshed VIctory-Hydra-v2.0-Stage17.zip release. Closing since the branch targeted pre-v2.0 history and the change is now landed on main.

**@⁠ToLIManl** on GitHub · 2026-12-02 12:54 UTC · [original](https://github.com/ToLIManl/VIctory-Hydra/pull/25#issuecomment-7346061366) Thank you @⁠justadudeinbulgaria! Integrated onto v2.0 `main` in commit `5d7f3ef` with full `Co-authored-by` credit: - Ported the `if PROTECTED.any(first, last)` lock-avoidance fast path into `watch.rs::title_memory_written` (skipping the `GUARDS` mutex on unguarded memory writes). - *(Note: the `written_since_taken` `RwLock` portion didn't apply directly because v2.0 `watch.rs` uses a `Mutex` for `GUARDS` rather than the older `port_guard()` `RwLock`.)* Included in the refreshed `VIctory-Hydra-v2.0-Stage17.zip` release. Closing since the branch targeted pre-v2.0 history and the change is now landed on `main`.

Pull request closed

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