perf(gpu): batch no-op buffer refresh checks and reduce lock contention #318

Open
wike1701 wants to merge 1 commit from upstream-pr/318 into main
wike1701 commented 2026-11-27 20:58:22 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by wike1701 on 2026-11-27T20:58:22Z.


Summary

Reduces CPU overhead in the open-world buffer refresh hot path (Batch::refresh_front and Batch::flush_all), where real open-world captures spend ~28–32 ms/frame checking ~10,000 buffer refreshes of which ~85–90% are unchanged no-ops.

Changes

  • watch::JournalRead +
    ead_journal()
    (crates/victory-gpu/src/watch.rs): allows holding one JOURNAL read guard across a chunk of
    othing_new checks instead of acquiring/releasing the global RwLock ~10,000 times per frame.
  • Shadow::pending_any / Shadow::ranged_any atomic fast paths + Shadow::nothing_new_with (crates/victory-gpu/src/shadow.rs): skips pending and
    anged mutex locks on read-only / non-ranged buffers in
    othing_new_with, writes_pending, writes_pending_in, and
    anged.
  • shadow::wide_chunks (crates/victory-gpu/src/shadow.rs + crates/victory-gpu/src/host.rs): processes
    efresh_front and lush_all in 32-item chunks per worker claim (1 atomic increment + 1 JournalRead + 1 FLUSHES[2] atomic increment per chunk instead of per item). JournalRead is always dropped before calling Self::update, preventing any RwLock upgrade deadlock.

Verification

  • cargo test -p victory-gpu --lib -- shadow:: watch:: host:: — 193 passed, 0 failed, 17 ignored (including new tests wide_chunks_visits_every_index_once and journal_read_matches_watch_nothing_new)
  • cargo check -p victory-gpu --features diagnostics — ok (0 new warnings)
  • cargo xtask policy — 287 files ok
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5533012147 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/318). Originally posted by [wike1701](https://github.com/wike1701) on 2026-11-27T20:58:22Z. --- ## Summary Reduces CPU overhead in the open-world buffer refresh hot path (Batch::refresh_front and Batch::flush_all), where real open-world captures spend ~28–32 ms/frame checking ~10,000 buffer refreshes of which ~85–90% are unchanged no-ops. ### Changes - **watch::JournalRead + ead_journal()** (crates/victory-gpu/src/watch.rs): allows holding one JOURNAL read guard across a chunk of othing_new checks instead of acquiring/releasing the global RwLock ~10,000 times per frame. - **Shadow::pending_any / Shadow::ranged_any atomic fast paths + Shadow::nothing_new_with** (crates/victory-gpu/src/shadow.rs): skips pending and anged mutex locks on read-only / non-ranged buffers in othing_new_with, writes_pending, writes_pending_in, and anged. - **shadow::wide_chunks** (crates/victory-gpu/src/shadow.rs + crates/victory-gpu/src/host.rs): processes efresh_front and lush_all in 32-item chunks per worker claim (1 atomic increment + 1 JournalRead + 1 FLUSHES[2] atomic increment per chunk instead of per item). JournalRead is always dropped before calling Self::update, preventing any RwLock upgrade deadlock. ## Verification - cargo test -p victory-gpu --lib -- shadow:: watch:: host:: — **193 passed, 0 failed, 17 ignored** (including new tests wide_chunks_visits_every_index_once and journal_read_matches_watch_nothing_new) - cargo check -p victory-gpu --features diagnostics — **ok** (0 new warnings) - cargo xtask policy — **287 files ok**
cloph-dsp commented 2026-11-28 03:06:54 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by cloph-dsp on 2026-11-28T03:06:54Z.


Independent local verification (Windows, Rust 1.100.0/MSVC, no game data):

  • PR #318 at head 66dfa778b9145a5eb86650e5c7fd7862f4c54882, base (single-commit parent) 0cef07e9d766df48f0e95f13ce3bbbe2290fe9d3.
  • cargo test --locked -p victory-gpu --lib -- shadow::land_tests::wide_chunks_visits_every_index_once --exact --test-threads=1 --quiet → 1 passed, 0 failed, 456 filtered, exit 0.
  • cargo test --locked -p victory-gpu --lib -- shadow::land_tests::journal_read_matches_watch_nothing_new --exact --test-threads=1 --quiet → 1 passed, 0 failed, 456 filtered, exit 0.
  • git grep -F for both test names on the base returned no hits (tests are new on this PR); git diff --check 0cef07e9 HEAD clean (3 files, +168/-28).
  • Used a per-worktree CARGO_TARGET_DIR (never shared) with CARGO_BUILD_JOBS=2.
  • Only the two named synthetic tests were replayed; full workspace suite and clippy were not run locally (no clippy component on this toolchain).
  • GPU/driver: N/A (CPU-only shadow bookkeeping tests). No game data, assets, extracted shaders, DRM or decrypt involved.

AI-assisted (Hy4 flash).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7232803476 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/318#issuecomment-7232803476). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-28T03:06:54Z. --- Independent local verification (Windows, Rust 1.100.0/MSVC, no game data): - PR #318 at head `66dfa778b9145a5eb86650e5c7fd7862f4c54882`, base (single-commit parent) `0cef07e9d766df48f0e95f13ce3bbbe2290fe9d3`. - `cargo test --locked -p victory-gpu --lib -- shadow::land_tests::wide_chunks_visits_every_index_once --exact --test-threads=1 --quiet` → 1 passed, 0 failed, 456 filtered, exit 0. - `cargo test --locked -p victory-gpu --lib -- shadow::land_tests::journal_read_matches_watch_nothing_new --exact --test-threads=1 --quiet` → 1 passed, 0 failed, 456 filtered, exit 0. - `git grep -F` for both test names on the base returned no hits (tests are new on this PR); `git diff --check 0cef07e9 HEAD` clean (3 files, +168/-28). - Used a per-worktree `CARGO_TARGET_DIR` (never shared) with `CARGO_BUILD_JOBS=2`. - Only the two named synthetic tests were replayed; full workspace suite and clippy were not run locally (no clippy component on this toolchain). - GPU/driver: N/A (CPU-only shadow bookkeeping tests). No game data, assets, extracted shaders, DRM or decrypt involved. AI-assisted (Hy4 flash).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/318:upstream-pr/318'
git switch 'upstream-pr/318'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/318'
git switch 'upstream-pr/318'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/318'
git switch 'upstream-pr/318'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/318'
git switch 'main'
git merge --squash 'upstream-pr/318'
git switch 'main'
git merge --ff-only 'upstream-pr/318'
git switch 'main'
git merge 'upstream-pr/318'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

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