Skip to content

Reduce CPU lock contention across shadow merges, refreshes, and card sync - #1561

Merged
trustno1-coder merged 1 commit into
trustno1-coder:mainfrom
mikael-jarvinen:pr-cpu-merging-stripes-and-batch
Nov 30, 2026
Merged

trustno1-coder merged 1 commit into
trustno1-coder:mainfrom
mikael-jarvinen:pr-cpu-merging-stripes-and-batch

Conversation

@mikael-jarvinen

Copy link
Copy Markdown
Contributor

Rebased replacement for #1157 onto main (923e38c), cleanly composed with upstream #1400 (UnderSlots + batched card.dirty) and VICTORY_FAULT_UNLOCKED (dropping already-merged hunks).

Summary of Changes

  • 64-stripe Shadow::merging ([RwLock<()>; 64], lazily allocated): replaces the single per-Shadow RwLock<()> so concurrent land_card_pieces and merge_under_writes on disjoint 64 KiB pages do not serialize each other; acquires only the touched stripe mask in ascending order and skips self.before.lock() on card-backed copies.
  • Unified CopyState (RwLock<CopyState>): replaces separate copied + ranged mutexes for concurrent lock-free reader sharing in nothing_new_with.
  • Batched JournalRead + Shadow::nothing_new_with: acquires JOURNAL read lock once per refresh/span batch instead of per copy, with binary-searched ahead_contains.
  • Batched descriptor::constant_slots_batch + HostHeap::constant_at_with_base: resolves SHADER_HEAPS once and reuses cached buffer_gpu across card_steps constant slots.
  • Submission Batch fast paths: Batch::note_gpu_write deduplicates repeated GPU writes and accumulates declared directly (avoiding declared_writes(runs) rescan); 1-entry last_ahead cache; Blocks::all_set word-level bitmap check in watch::guard; CARD_WORK locked after send::take.

Verification & Re-Measurement on main (923e38c)

  • Unit tests: 50/50 shadow + 51/51 watch tests pass; 0 new warnings.
  • Live benchmark (RTX 3080 10 GB, Ryzen 7 7800X3D, diag build, warm cache, 1440p DLSS Performance, FG off, 115 s scripted run):
Metric main (923e38c, ~7,650 draws) This PR (175c954, ~8,000–8,690 draws) Delta
Steady 3D FPS (med / peak) 15.7 / 17.3 16.3 / 17.8 +3.8% (at +5% draws)
GPU busy (%) / idle behind CPU (ms) 66.0% / 21.65 ms 94.5% / 3.35 ms +28.5 pp / −84.5% idle
Submit prep TOTAL (med / late) 58.50 ms 51.70 / 48.10 ms −6.80 ms (−11.6%)
lists' steps TOTAL (copies & fills) 24.15 ms (3.30 ms) 20.60 ms (1.70 ms) −14.7% (−48.5%)
planning card_steps 12.65 ms 10.40 ms −17.8%
asking write watch 5.10 ms 3.95 ms −22.5%
Title threads waited at presents 17.00 ms 4.35 ms −74.4%

@t90 t90 mentioned this pull request Nov 29, 2026
1 task done
edwardteach247 added a commit to edwardteach247/VIctory-NVIDIA that referenced this pull request Nov 29, 2026
…pe merge_stripe, CopyState RwLock, O(log N) ahead_contains, atomic Done, inline constant_slots_batch 2fbac6e, immediate CardPlan sync dc216b6)
@mikael-jarvinen mikael-jarvinen changed the title Reduce CPU lock contention across shadow merges, refreshes, and card sync [pr-performance][NVIDIA] Reduce CPU lock contention across shadow merges, refreshes, and card sync Nov 29, 2026
@github-actions github-actions Bot added NVIDIA pr-performance Pull request: makes it faster or use less memory labels Nov 29, 2026
@github-actions github-actions Bot changed the title [pr-performance][NVIDIA] Reduce CPU lock contention across shadow merges, refreshes, and card sync Reduce CPU lock contention across shadow merges, refreshes, and card sync Nov 29, 2026
@mikael-jarvinen
mikael-jarvinen force-pushed the pr-cpu-merging-stripes-and-batch branch from 175c954 to c2ed656 Compare November 29, 2026 08:30
Alxspb added a commit to Alxspb/VIctory-NVIDIA that referenced this pull request Nov 29, 2026
Held in the fork until upstream takes them; each switch keeps the old
behaviour by default:
- trustno1-coder#1937 the placed-texture span lock is skipped by default
  (VICTORY_SPANS_QUICK on), VICTORY_QUEUE_BATCH_MAX;
- trustno1-coder#1556 no-op refreshes batched, the lock-free ask_once fast path, a
  binary search in Journal::ahead;
- trustno1-coder#1561 less CPU lock contention in shadow merges, refreshes and card sync;
- trustno1-coder#2049 the sparse copy_stale fast path, the Batch/card_steps hot caches,
  the RT reserve's settle-decay, the depth plan;
- trustno1-coder#1971 the launcher's shader warm and preload runs apply what play applies;
- trustno1-coder#1911 Series S keeps 1,536 MB for render targets, not 3,072;
- trustno1-coder#1985 the XMA decoder thread runs at the helpers' priority
  (VICTORY_XMA_PRIORITY=-2..2);
- trustno1-coder#1912 flights in the air are settled before a bake reads title memory
  (VICTORY_BAKE_SETTLE);
- trustno1-coder#1274 room for a full-size 3840x2160 scene (VICTORY_NATIVE_4K,
  VICTORY_RT_HEAP_MB, VICTORY_SCENE_POOL).
@DoubleD17

DoubleD17 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

We ran a test of this PR on current main (it still merges cleanly), on a CPU-bound machine (about 66 ms of CPU preparation per frame).

CPU prep (ms/frame) controls at that point fps (mean) controls at that point
round 1 66.5 68.8 12.63 11.95
round 2 67.2 66.7 12.23 12.01
mean difference −0.9 ms +3.8 %

The difference is on the good side but inside the noise (the controls alone spread over 9 ms).

Picture: in round 1, one frame had the palms and the potted plants by the house missing. The game was at 8 fps at that moment, so that frame was on screen for about 140 ms. We saw none in the 320 control frames of this session nor in 800 earlier ones on this base, and we saw the same one-frame vegetation gap with #3502, #3476 and #3411. It may be a timing-sensitive problem in main rather than this PR alone.

Setup:

  • Ryzen 7 5800X (8 cores, 16 threads), RTX 5070 12 GB (DXGI budget 11,175 MB), 64 GB RAM, Windows 11;
  • Series X, 1440p with DLAA (DLSS at native resolution; corrected, this line said DLSS Performance at first), frame generation and ray tracing off;
  • the PR merged locally onto main 41adb55 (only its own commits on top), against 41adb55 itself;
  • a warm-up run per build, then 150 s runs in two rounds (the second in reverse order), with four control runs of 41adb55 spread through the session;
  • every run starts from the same save, restored before each run;
  • figures are medians of the 5 s host lines. The four controls measured 60.4–69.4 ms of CPU preparation per frame and drifted during the session, so each run is compared with the controls interpolated to its own start.

Picture check: a burst of 10 captures a second at the end of each run (80 frames), looked at frame by frame.

AI Assisted

PranThow added a commit to PranThow/VIctory-NVIDIA that referenced this pull request Nov 30, 2026
@trustno1-coder
trustno1-coder merged commit c17aacd into trustno1-coder:main Nov 30, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NVIDIA pr-performance Pull request: makes it faster or use less memory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants