Skip to content

perf(gpu): lock-free no-op refreshes, chunked refresh claiming, and AVX2 copy diff - #614

Open
wike1701 wants to merge 2 commits into
trustno1-coder:mainfrom
wike1701:perf/cpu-refresh-and-copy-pipeline
Open

wike1701 wants to merge 2 commits into
trustno1-coder:mainfrom
wike1701:perf/cpu-refresh-and-copy-pipeline

Conversation

@wike1701

Copy link
Copy Markdown
Contributor

Summary

Pure CPU hot-path optimization targeting the preparing /
efreshes bottleneck (~48–68 ms/frame on open-world captures, where ~8,100 of ~8,600 refreshes/frame copy nothing). Leaves GPU output and ordering byte-for-byte identical.

1. Lock-free no-op refresh fast path (watch.rs, shadow.rs, host.rs)

  • Shadow::copied: Box<[AtomicU64]> + copy_lock: Mutex<()>: readers (
    othing_new_with, stale_under_writes, window_use) read page generations lock-free; writers (copy_stale, merge_under_writes, landed) serialize on copy_lock and publish
    ow with Ordering::Release only after ake_all finishes writing bytes.
  • watch::JournalRead::nothing_new_atomic + Shadow::pending_any /
    anged_any
    : eliminates Shadow.pending, Shadow.copied, and Shadow.ranged mutex locks on the common whole-page read-only no-op path, while holding one JournalRead guard per 32-item chunk in wide_chunks (always dropped before Self::update).
  • watch::is_kept() fast path: avoids building/sorting up to 8,600 �sk_ahead ranges and taking an exclusive journal_mut() write lock in �sk_ahead_done on every flush while VICTORY_ASK_ONCE=1 stands.

2. Offload refresh coalescing to VICTORY_THIN workers (host.rs)

  • Deferred::refreshed_span: merges contained, overlapping, and contiguous Step::Refresh entries for the same Shadow in-place during HostList::defer_refresh on the parallel VICTORY_THIN worker threads (cleared on itle_written, ake_coming, and per-shadow on defer_gpu_write), shrinking copies before the single submitting thread walks it.

3. Faster real copy hot path (shadow.rs)

  • Shadow::take: switches dword_runs(at, held, title, 0) to the existing AVX2-accelerated word_runs(at, held, title) and batches SEND[0..4] atomic updates once per ake() call instead of 4 atomics per 64 KiB page.

Verification

  • VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --lib -- shadow:: watch:: host:: list:: — 204 passed, 0 failed, 18 ignored
  • cargo check -p victory-gpu --features diagnostics — ok (0 new warnings)
  • cargo xtask policy — 292 files ok

@CuteBooty

Copy link
Copy Markdown
Contributor

A first in-game data point from an NVIDIA 8 GB card. The two runs are short, so please read it as "it runs", not as a verdict.

  • PC: RTX 3070 8 GB (driver 621.24), Ryzen 7 5800X3D, 32 GB, Windows 11. Series S, 1920x1080, no DLSS or frame generation in these two runs, started with victory.exe run, diag profile with diagnostics; VICTORY_THIN=1, VICTORY_RELAY=2, VICTORY_JOIN_PARTS=8, VICTORY_SOFT_VIEWS=copies.
  • Build A: main 8fc22547c + two unrelated local commits. Build B: the same + this PR's commit caf1a4ce5 cherry-picked. One session each (3.2 and 4.7 minutes), same save, not the same spot.
the submitting thread, per frame (frames of 3,000+ flushes) main main + #614
log lines 86 217
refreshes, median (mean) 17.9 (18.9) ms 19.4 (17.3) ms
flushes a frame / of them known to copy nothing 8,302 / 7,177 8,397 / 7,438
whole "preparing per frame, the submitting thread", median 54.7 ms 57.3 ms
  • No error lines, and the player reported no visual faults in the 4.7 minutes with the PR.
  • I cannot see a change in the refresh time outside the spread between two short runs on this PC. A longer pair on the same route is on my list. If one log line would show this PR's effect best, tell me which and I will report that one.

Measurements and this report were prepared with an AI assistant (Claude Code); the runs were played on my machine.

@POMXARK

POMXARK commented Nov 28, 2026

Copy link
Copy Markdown

Testing feedback on Windows 11, AMD Ryzen 7 5700X (8C/16T), NVIDIA RTX 5080 16 GB, 32 GB RAM, Series X 1440p + DLSS Quality + DLSS MFG 4× (4 MiB default windows, VICTORY_GPU_BCPACK=0, VICTORY_WAIT_RESIDENT=0, VICTORY_TEXTURE_ROOM_PERCENT=70, VICTORY_LAND_SKIP=1).

Full disclosure: tested on a fork branch based on v2026.11.27.7 (with local GPU patches, x86-64-v3/ThinLTO, PR #469 ahead_holds, PR #516, PR #340, and PR #81; resolved the single nothing_new conflict in watch.rs keeping ahead_holds binary search inside nothing_new_atomic).

Result

  • Unit tests: VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --lib -- shadow:: watch:: host:: list:: — 205 passed, 0 failed, 17 ignored (2.70 s).
  • 3D performance prior to failure (0..858 s, n=110 3D samples):
    • Frame pacing was notably smooth: 0 frames >=250 ms, 0 GPU stalls >=50 ms, max = 203.2 ms, tex refreshes p50 = 11.5 ms (down from 16.0 ms), write watch p50 = 1.7 ms (down from 2.6 ms).
    • High-draw 3D (7k–10k draws, p50=8,265): 11.30 FPS p50 / 12.60 mean (88.6 ms, Prep 70.5 ms, copies 41.8 ms).
    • Very-high-draw 3D (>=10k draws, p50=10,444): 13.50 FPS p50 (74.0 ms, Prep 57.1 ms, copies 31.1 ms).
  • Failure at 14m18s (frame=41453, heavy streaming transition 6.4k -> 9.7k refreshes/frame):

@Machad3x

Copy link
Copy Markdown

Test results for this PR on our fork. It is ported as 7a84d45a, in batch 9 together with refresh and asking cuts on the same path (only the pages a submission reads).

Setup: RTX 3080 Ti, driver 621.40, Windows 11 Pro build 26300, Ryzen 7 5700X. RT on. Each run is 240 s on the opening interior scene, with a valid (non-compile) rerun. Values are averages over the last 120 s.

Run Frame Preparing GPU
base 66.6 ms (max 81) 46.8 8.3
batch 9 67.0 ms (max 75) 41.7 14.0
  • Preparing: about 5 ms less per frame.
  • Frame time: steady state unchanged, because the GPU rose by about 6 ms (VRAM changes in the same batch).
  • Early loading: the first 80 s after the world starts average 148.5 ms per frame, down from 261.3.
  • Shaders and draws: 0 dropped draws, 0 refused shaders.

Unit tests (victory-gpu): 483 passed. Thanks!

henriazz10 added a commit to henriazz10/VIctory-NVIDIA that referenced this pull request Nov 28, 2026
whoalin1 added a commit to whoalin1/victory-altracing-prs that referenced this pull request Nov 28, 2026
…s, PRs trustno1-coder#697/trustno1-coder#614/trustno1-coder#700/trustno1-coder#666

- upload.rs: set default VICTORY_LOW_EARLY_MB=0 (restores bright bedroom & cuts stray faults while retaining explicit override + trustno1-coder#88 arena backoff)

- host/panel.rs & shadow::register: port Spaghetih/victory-sley-fork 6d813b4 (panel COPY_SOURCE->COPY_DEST barrier via uploaded flag; retire replaced shadow entry)

- descriptor.rs: port PR trustno1-coder#666 (FxHasher FastMap, split VIEW_SHAPES RwLock, forget early-out)

- watch.rs/host.rs/shadow.rs: port PR trustno1-coder#697 (per-range ask holds), PR trustno1-coder#614 (lock-free atomic shadow copied + ReadJournal + wide_chunks + word_runs + deferred coalescing), PR trustno1-coder#700 (keep 4 MiB chunk in scratch_any_size)

- shadow::land_tests: drop JournalRead before calling watch::nothing_new to prevent Windows SRWLock recursive read deadlock
@POMXARK

POMXARK commented Nov 28, 2026

Copy link
Copy Markdown

Follow-up isolation test on the 0x887A0006 (DXGI_ERROR_DEVICE_HUNG) reported earlier:

We isolated only the read-only lock-free refresh path and AVX2 copy diff from this PR — omitting Deferred::refreshed_span (host.rs) — and ran a full 20-minute 3D A/B on the exact same RTX 5080 + Ryzen 7 5700X Windows 11 setup:

  • Included: Shadow::take word_runs + batched SEND atomics, watch::JOURNAL_KEPT fast path, JournalRead::nothing_new_atomic (using ahead_holds), Shadow::copied: Box<[AtomicU64]> with copy_lock + pending_any/ranged_any, and shadow::wide_chunks(32) in Batch::refresh_front/refresh_ahead/flush_all.
  • Excluded: Deferred::refreshed_span in-place Step::Refresh coalescing/shrinking.

Isolation Result (20-Minute Run, 1200 s, 50,243 frames)

  • Stability: 0 errors, 0 DeviceRemoved/DEVICE_HUNG, 0 exceptions, 0 GPU>=50ms, 0 F>=250ms, 0 F>=500ms, worst 3D frame 191.1 ms, 327/327 (100%) Responding.
  • Performance (vs clean baseline before this subset):
    • ALL 3D (n=176 -> 167): 13.3 -> 13.9 FPS p50 (+4.5%), mean 13.35 -> 13.91 FPS (+4.2%), Prep 60.5 -> 58.1 ms.
    • 7k–10k draws/frame (n=37 -> 34): 10.90 -> 11.05 FPS p50 (mean 10.39 -> 11.06 FPS, +6.4%, copies 45.1 -> 40.2 ms).
    • submitting prep: ww 7.1 -> 6.0 ms, refreshes p90 47.5 -> 42.5 ms, 1s frame_times >100ms -19.7% (1,687 -> 1,354).

This strongly isolates the 0x887A0006 GPU hang to Deferred::refreshed_span (in-place Step::Refresh mutation/skipping across steps inside a submission), while the lock-free nothing_new_with + wide_chunks + word_runs portions are clean and stable across a full 20-minute workload.

@wike1701 wike1701 changed the title perf(gpu): lock-free no-op refreshes, thin-worker refresh coalescing, and AVX2 copy diff perf(gpu): lock-free no-op refreshes, chunked refresh claiming, and AVX2 copy diff Nov 28, 2026
@wike1701

Copy link
Copy Markdown
Contributor Author

Thank you @POMXARK for the thorough 20-minute A/B isolation run — that was super helpful! I have removed \Deferred::refreshed_span\ from this PR so it now contains only the clean, 20-minute-verified subset: lock-free \Shadow::copied\ + \copy_lock, \watch::JOURNAL_KEPT\ /
othing_new_atomic, \wide_chunks(32)\ claiming, and AVX2 \word_runs\ + batched \SEND\ atomics. Re-verified \cargo test -p victory-gpu --lib -- shadow:: watch:: host::\ (197 passed, 0 failed).

@RobertAndreiGit

Copy link
Copy Markdown

Tested the revised ee008d0 diff on stock 63b902f, on a Ryzen 5 5600 / RTX 3060 Ti 8 GB under CachyOS Proton. It built and reached Chapter 1 gameplay. This was one partial run, not a matched stock-vs-patch A/B.

  • Series S, DLSS Performance, FSR 3 2× configured; the stock and patched runs used copies of the same save/cache and the same VICTORY_CARD_AWAKE=turns setting. No other source patches in the candidate.
  • 8.33 rendered FPS from counter progress (208 → 996 in 94.6 s). Across 16 host reports with at least 2,000 draws/frame, the median was 9.9 FPS, with 4,502 draws and 264 draws skipped for lack of a host pipeline per frame (rounded). These are rendered rates, not measured display FPS.
  • For the CPU path this PR changes: in 60 complete one-second refresh reports inside high-draw host intervals, median refresh time was 62.0 ms/frame and the median share of spans already known to copy nothing was 73.3%. The timing includes refreshes that did copy; it does not measure the cost of no-op checks alone.

The opening tank view matched, but at three later capture marks (610, 720, 940) the candidate faced the balcony while stock faced the radio. The window closed and the title suspended at count 996, before the planned 2,220. So this confirms the revised subset runs on this Proton/8 GB setup and the refresh workload is present; it does not establish a speedup, regression, or long-run stability.

@wike1701
wike1701 force-pushed the perf/cpu-refresh-and-copy-pipeline branch from ee008d0 to f27bb04 Compare November 28, 2026 19:40
@wike1701
wike1701 force-pushed the perf/cpu-refresh-and-copy-pipeline branch from f27bb04 to 7382c36 Compare November 28, 2026 19:42
bigboss22869 added a commit to bigboss22869/VIctory-RTX5070Ti that referenced this pull request Nov 28, 2026
…ARLY=2) in this fork's defaults

Measured at the deck on the RTX 5070 Ti (native 1440p, no DLSS, 2026-11-28): the
memory stack cost about 2 ms a frame on 16 GB; ASK_EARLY=2 gave 47.0 ms against
48.4 (p90 48.5 against 51.3). GUARD_HOT=50 with FAULT_UNLOCKED=1 was slower (51.1),
more threads made no difference, PR trustno1-coder#614/trustno1-coder#697 with kibagami's direct constants
made none (48.2), and renderer port 5 was slower (53.6-58.8: the heap records'
thread made twice the records and the submissions waited for it).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants