gpu: lock-free refresh checks, single-lock scoped pool, and zero-clone card_dirty (rebased #1094) #1442

Manually merged
github merged 1 commit from github-bot/gh-1442 into main 2026-11-29 08:21:41 +00:00 AGit
Owner

@⁠Bazovsky on GitHub · 2026-11-28 20:05 UTC · original
Bazovsky:pr/lockfree-refresh-pool-v2 → main · +723 −159 · 6 files · 1 commits · merged 2026-11-29 08:16 UTC

Clean rebase of #1094 onto current main (923e38c), per @⁠trustno1-coder's request in #1094.

Summary of changes

  1. Lock-free Shadow::nothing_new / watch::nothing_new_with (watch.rs, shadow.rs, host.rs):
    • Replaces global WRITTEN mutex reads on the no-op refresh fast path with lock-free per-page atomic epochs (PageEpochs) + an ahead snapshot (ahead_snapshot_into) reused across the submission's refresh batch.
    • Replaces Shadow::copied: Mutex<Vec<u64>> with Box<[AtomicU64]> (copy_lock serializes writers) and adds a SeqLock (ranged_seq) for Shadow::ranged.
    • Includes the Shadow::copy_stale post-take_all epoch publish fix (be4e568 from #1094, audited by @⁠POMXARK and @⁠hasekenmustafa-ctrl): copied[i].store(now, Ordering::Release) runs only after take_all(runs) joins all workers, ensuring Acquire readers never observe a refreshed epoch before worker writes are visible.
    • Reuses main's existing has_pending atomic and #1400's UnderSlots/batched card.dirty in merge_under_writes.
  2. Single-lock scoped refresh pool (land.rs, shadow.rs, host.rs):
    • wide_each_scoped runs parallel refresh batches without per-job Arc/Box allocations and claims work in chunks (MANY_CHUNK for large no-op sweeps, wide_chunk() otherwise so VICTORY_WIDE_CHUNK remains honored).
  3. Zero-clone card_dirty_ranges (shadow.rs, host.rs, host/send.rs, host/upcheck.rs):
    • Borrows &[(Arc<Shadow>, Vec<(usize, usize)>)] without redundant per-submission Vec clones.

Independent benchmark (from #1094)

Measured by @⁠Rafa7046 on Ryzen 9 9950X3D + RTX 5080 (Series X, 1440p DLSS Performance, FG off):

  • main (4 sessions): 35.6–37.8 median fps, 36.0–38.7 boat fps, 19.2–21.2 ms submit-thread preparing
  • #1094 (2 sessions): 38.3 / 38.4 median fps, 39.6 / 39.6 boat fps (+2.4 fps / +6%), 18.0 / 18.9 ms preparing

Verification

  • Native Windows victory-gpu unit tests: 552 passed, 0 failed (43 ignored).
  • cargo xwin clippy --no-deps -p victory-gpu --all-targets: 0 warnings in all modified files (watch.rs, land.rs, shadow.rs, host/upcheck.rs, touched host.rs regions).
**@⁠Bazovsky** on GitHub · 2026-11-28 20:05 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1442) `Bazovsky:pr/lockfree-refresh-pool-v2` → `main` · +723 −159 · 6 files · 1 commits · merged 2026-11-29 08:16 UTC Clean rebase of #1094 onto current `main` (`923e38c`), per @⁠trustno1-coder's request in #1094. ### Summary of changes 1. **Lock-free `Shadow::nothing_new` / `watch::nothing_new_with` (`watch.rs`, `shadow.rs`, `host.rs`)**: - Replaces global `WRITTEN` mutex reads on the no-op refresh fast path with lock-free per-page atomic epochs (`PageEpochs`) + an `ahead` snapshot (`ahead_snapshot_into`) reused across the submission's refresh batch. - Replaces `Shadow::copied: Mutex<Vec<u64>>` with `Box<[AtomicU64]>` (`copy_lock` serializes writers) and adds a SeqLock (`ranged_seq`) for `Shadow::ranged`. - Includes the `Shadow::copy_stale` post-`take_all` epoch publish fix (`be4e568` from #1094, audited by @⁠POMXARK and @⁠hasekenmustafa-ctrl): `copied[i].store(now, Ordering::Release)` runs only after `take_all(runs)` joins all workers, ensuring Acquire readers never observe a refreshed epoch before worker writes are visible. - Reuses `main`'s existing `has_pending` atomic and `#1400`'s `UnderSlots`/batched `card.dirty` in `merge_under_writes`. 2. **Single-lock scoped refresh pool (`land.rs`, `shadow.rs`, `host.rs`)**: - `wide_each_scoped` runs parallel refresh batches without per-job `Arc`/`Box` allocations and claims work in chunks (`MANY_CHUNK` for large no-op sweeps, `wide_chunk()` otherwise so `VICTORY_WIDE_CHUNK` remains honored). 3. **Zero-clone `card_dirty_ranges` (`shadow.rs`, `host.rs`, `host/send.rs`, `host/upcheck.rs`)**: - Borrows `&[(Arc<Shadow>, Vec<(usize, usize)>)]` without redundant per-submission `Vec` clones. ### Independent benchmark (from #1094) Measured by @⁠Rafa7046 on Ryzen 9 9950X3D + RTX 5080 (Series X, 1440p DLSS Performance, FG off): - `main` (4 sessions): `35.6–37.8` median fps, `36.0–38.7` boat fps, `19.2–21.2 ms` submit-thread preparing - `#1094` (2 sessions): **`38.3 / 38.4` median fps**, **`39.6 / 39.6` boat fps** (**+2.4 fps / +6%**), **`18.0 / 18.9 ms`** preparing ### Verification - Native Windows `victory-gpu` unit tests: **552 passed, 0 failed** (43 ignored). - `cargo xwin clippy --no-deps -p victory-gpu --all-targets`: **0 warnings** in all modified files (`watch.rs`, `land.rs`, `shadow.rs`, `host/upcheck.rs`, touched `host.rs` regions).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 20:06:07 +00:00
github-bot force-pushed github-bot/gh-1442 from 1935174664 to 27d312d38d 2026-11-29 01:46:52 +00:00 Compare
github manually merged commit 421613596f into main 2026-11-29 08:21:41 +00:00
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!1442
No description provided.