perf(gpu): single-pass ask_once, sorted ahead lookup, ask_once_active skip, and merged Shadow copied/ranged lock #1676

Closed
github-bot wants to merge 1 commit from github-bot/gh-1676 into main AGit
Owner

@⁠qlfu on GitHub · 2026-11-28 23:21 UTC · original
qlfu:pr/watch-and-refresh-perf → main · +280 −99 · 3 files · 1 commits · closed without merging

What it changes

Removes redundant submitting-thread write-watch work and lock/atomic contention across watch, shadow, and host refresh flushes:

  • crates/victory-gpu/src/watch.rs:
    • Tracks ASK_ONCE_ACTIVE (AtomicBool mirror of Journal::kept) and exposes ask_once_active() so ask_ahead() / ask_ahead_done() and Batch::refresh_front / Batch::flush_all skip building, filtering (published), sorting, and discarding thousands of ranges on every flush while ask_once is already active.
    • Consolidates ask_once into a single pass over ranges (one published() filter, one sort, one Askings::hold_or_all, one journal_mut() lock) instead of running ask_ahead followed by a second full scan and ahead.clone() in ask_rest.
    • Keeps Journal::ahead sorted and merged into disjoint intervals and replaces linear j.ahead.iter().any(...) scans in nothing_new, writes, asked, ask_more, and ask_rest with O(log N) ahead_contains (partition_point).
    • Checks copied page bounds / zero-marks in nothing_new before taking JOURNAL.read().
    • Adds unit tests for ahead_contains parity and ask_once active-flag / sorted-ahead invariants.
  • crates/victory-gpu/src/shadow.rs:
    • Merges Shadow::ranged into CopiedPages under Shadow::copied (all callers already held copied's lock), removing a second mutex per buffer check/update.
    • Guards Shadow::update's self.pending.lock() and Vec allocation behind the existing lock-free self.has_pending.load(Acquire) check.
    • Skips watch::parts_written(&again_at) (and its JOURNAL.read()) in Shadow::copy_stale when again_at is empty.
    • Adds wide_each_chunks so parallel flush workers receive (from, to) ranges directly.
  • crates/victory-gpu/src/host.rs:
    • Skips building ranges: Vec<(usize, usize)> before watch::ask_ahead in Batch::refresh_front and Batch::flush_all when watch::ask_once_active() is true.
    • Uses wide_each_chunks in Batch::refresh_front and Batch::flush_all to flush FLUSHES[2] (nothing_new count) once per worker chunk instead of per buffer.

How it was tested

  • GPU and profile: RTX 4070 Ti 12 GB + Ryzen 7 5700X, Series X (game_scarlett_master.exe), 1440p DLSS Balanced, -NoFrameGenReady, VICTORY_PORT_CONSTANTS=1, VICTORY_WAIT_RESIDENT=textures, clean 90s gameplay runs (0 WARNs / 0 ERRORs).
  • Before (stack8v2 without this PR):
    • FPS: median 22.00 / mean 23.15 (p10 18.0, max 31.2), frame_times med 43.7 ms / mean 43.5 ms, >50 ms: 24.9%
    • Submitting thread sub_all: median 36.25 ms / mean 37.35 ms (watch 5.00 ms, refreshes 10.75 ms, ASYNC_SUBMIT worked 39.4 ms)
  • After (stack9 with this PR):
    • FPS: median 22.80 / mean 23.64 (p10 19.2, max 32.2), frame_times med 42.7 ms / mean 42.7 ms, >50 ms: 24.0%
    • Submitting thread sub_all: median 35.30 ms / mean 36.12 ms (-1.23 ms mean; watch 4.65 ms -7%, refreshes 10.55 ms, ASYNC_SUBMIT worked 37.05 ms -2.35 ms)
  • cargo clippy -p victory-gpu --lib --tests --locked (default & --all-features): 0 new warnings.
  • cargo test passed for the crates it touches: yes (551 passed; 0 failed in cargo test -p victory-gpu --lib --locked -- --test-threads=1).

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #1637 (also introduces sorted Journal::ahead; this PR additionally adds the ask_once_active() skip in watch/host, single-pass ask_once, Shadow::update has_pending guard, Shadow::ranged merged into Shadow::copied, and chunk-batched FLUSHES[2] updates).
**@⁠qlfu** on GitHub · 2026-11-28 23:21 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1676) `qlfu:pr/watch-and-refresh-perf` → `main` · +280 −99 · 3 files · 1 commits · closed without merging ## What it changes Removes redundant submitting-thread write-watch work and lock/atomic contention across `watch`, `shadow`, and `host` refresh flushes: - **`crates/victory-gpu/src/watch.rs`**: - Tracks `ASK_ONCE_ACTIVE` (`AtomicBool` mirror of `Journal::kept`) and exposes `ask_once_active()` so `ask_ahead()` / `ask_ahead_done()` and `Batch::refresh_front` / `Batch::flush_all` skip building, filtering (`published`), sorting, and discarding thousands of ranges on every flush while `ask_once` is already active. - Consolidates `ask_once` into a single pass over `ranges` (one `published()` filter, one sort, one `Askings::hold_or_all`, one `journal_mut()` lock) instead of running `ask_ahead` followed by a second full scan and `ahead.clone()` in `ask_rest`. - Keeps `Journal::ahead` sorted and merged into disjoint intervals and replaces linear `j.ahead.iter().any(...)` scans in `nothing_new`, `writes`, `asked`, `ask_more`, and `ask_rest` with O(log N) `ahead_contains` (`partition_point`). - Checks `copied` page bounds / zero-marks in `nothing_new` before taking `JOURNAL.read()`. - Adds unit tests for `ahead_contains` parity and `ask_once` active-flag / sorted-`ahead` invariants. - **`crates/victory-gpu/src/shadow.rs`**: - Merges `Shadow::ranged` into `CopiedPages` under `Shadow::copied` (all callers already held `copied`'s lock), removing a second mutex per buffer check/update. - Guards `Shadow::update`'s `self.pending.lock()` and `Vec` allocation behind the existing lock-free `self.has_pending.load(Acquire)` check. - Skips `watch::parts_written(&again_at)` (and its `JOURNAL.read()`) in `Shadow::copy_stale` when `again_at` is empty. - Adds `wide_each_chunks` so parallel flush workers receive `(from, to)` ranges directly. - **`crates/victory-gpu/src/host.rs`**: - Skips building `ranges: Vec<(usize, usize)>` before `watch::ask_ahead` in `Batch::refresh_front` and `Batch::flush_all` when `watch::ask_once_active()` is true. - Uses `wide_each_chunks` in `Batch::refresh_front` and `Batch::flush_all` to flush `FLUSHES[2]` (`nothing_new` count) once per worker chunk instead of per buffer. ## How it was tested - GPU and profile: RTX 4070 Ti 12 GB + Ryzen 7 5700X, Series X (`game_scarlett_master.exe`), 1440p DLSS Balanced, `-NoFrameGenReady`, `VICTORY_PORT_CONSTANTS=1`, `VICTORY_WAIT_RESIDENT=textures`, clean 90s gameplay runs (`0 WARNs / 0 ERRORs`). - Before (`stack8v2` without this PR): - FPS: median `22.00` / mean `23.15` (`p10 18.0`, max `31.2`), `frame_times` med `43.7 ms` / mean `43.5 ms`, `>50 ms: 24.9%` - Submitting thread `sub_all`: median `36.25 ms` / mean `37.35 ms` (`watch 5.00 ms`, `refreshes 10.75 ms`, `ASYNC_SUBMIT worked 39.4 ms`) - After (`stack9` with this PR): - FPS: median `22.80` / mean `23.64` (`p10 19.2`, max `32.2`), `frame_times` med `42.7 ms` / mean `42.7 ms`, `>50 ms: 24.0%` - Submitting thread `sub_all`: median `35.30 ms` / mean `36.12 ms` (**-1.23 ms mean**; `watch 4.65 ms` **-7%**, `refreshes 10.55 ms`, `ASYNC_SUBMIT worked 37.05 ms` **-2.35 ms**) - `cargo clippy -p victory-gpu --lib --tests --locked` (default & `--all-features`): 0 new warnings. - `cargo test` passed for the crates it touches: yes (`551 passed; 0 failed` in `cargo test -p victory-gpu --lib --locked -- --test-threads=1`). ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #1637 (also introduces sorted `Journal::ahead`; this PR additionally adds the `ask_once_active()` skip in `watch`/`host`, single-pass `ask_once`, `Shadow::update` `has_pending` guard, `Shadow::ranged` merged into `Shadow::copied`, and chunk-batched `FLUSHES[2]` updates).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 23:24:40 +00:00
github-bot closed this pull request 2026-11-29 10:17:33 +00:00
Author
Owner

@⁠qlfu on GitHub · 2026-11-29 10:14 UTC · original

Closing in favor of the focused lock-free refresh rewiring PR on \main\ (\829188e9), since \head_contains, lock-free \Shadow::copied/
anged_lockfree, and \watch::is_kept\ have already landed on \main.

**@⁠qlfu** on GitHub · 2026-11-29 10:14 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1676#issuecomment-7254302071) Closing in favor of the focused lock-free refresh rewiring PR on \main\ (\829188e9\), since \head_contains\, lock-free \Shadow::copied\/\ anged_lockfree\, and \watch::is_kept\ have already landed on \main\.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!1676
No description provided.