perf(gpu): use pre-snapshotted ahead list in refresh sift paths (~7900 journal lock acquisitions/frame → ~48) #2504

Open
github-bot wants to merge 17 commits from github-bot/gh-2504 into main AGit
Owner

@⁠erax4193 on GitHub · 2026-11-29 13:43 UTC · original
erax4193:perf/refresh-use-ahead-snapshot → main · +989 −859 · 36 files · 17 commits · open

Problem

In flush_all and refresh_front, the light-refresh "few" path (len ≤ 256)
already calls watch::ahead_snapshot_into(&mut self.ahead_snap) before the
retain loop — but then immediately calls shadow.nothing_new(from, len) per
resource, which acquires journal() internally, ignoring the snapshot just
captured.

From the logs on a Core Ultra 9 275HX + RTX 5070L running the game's prologue:

refreshes 28.6 ms in 48 flushes of 7917, 6943 of them known to copy nothing

7917 resources × 48 flushes/frame ≈ 7920 journal() lock acquisitions per
frame, all on the submission thread, to answer "nothing changed" for 87.7% of
them. The lock is uncontested but not free: each acquisition reads an RWLock,
branches on the ahead list, and touches the per-page epoch array.

Fix

Two-line change per site: pass &self.ahead_snap to nothing_new_with —
the lock-free version that uses the pre-snapshotted ahead list — instead of
calling nothing_new which re-acquires the journal.

flush_all (line ~12680): snapshot is already taken at the top of the
branch; just pass it to retain.

refresh_front (line ~12498): no snapshot taken before the sift; add
one ahead_snapshot_into call, then use nothing_new_with in retain.

Result: ~48 snapshot acquisitions/frame instead of ~7920 per-resource ones.

Expected impact

The 28.6 ms/frame refresh time comes almost entirely from the per-resource
journal lock overhead — the 974 resources that actually copy data take far
less time. With the lock removed from the sift loop, the refresh cost should
drop close to the actual copy time of those ~12% dirty resources.

Notes

  • nothing_new_with is semantically equivalent when the snapshot is fresh:
    the snapshot is taken on the same thread, immediately before the loop, with
    no yield points between.
  • The existing batch path (uses nothing_new_all) is unchanged — it
    already batches the journal read.
  • The many / flush_sift path (> 256 resources per flush) is unchanged;
    that path uses wide_each which already distributes the per-resource cost.

🤖 Generated with Claude Code

**@⁠erax4193** on GitHub · 2026-11-29 13:43 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2504) `erax4193:perf/refresh-use-ahead-snapshot` → `main` · +989 −859 · 36 files · 17 commits · open ## Problem In `flush_all` and `refresh_front`, the light-refresh "few" path (`len ≤ 256`) already calls `watch::ahead_snapshot_into(&mut self.ahead_snap)` before the retain loop — but then immediately calls `shadow.nothing_new(from, len)` per resource, which acquires `journal()` internally, ignoring the snapshot just captured. From the logs on a Core Ultra 9 275HX + RTX 5070L running the game's prologue: ``` refreshes 28.6 ms in 48 flushes of 7917, 6943 of them known to copy nothing ``` 7917 resources × 48 flushes/frame ≈ 7920 `journal()` lock acquisitions per frame, all on the submission thread, to answer "nothing changed" for 87.7% of them. The lock is uncontested but not free: each acquisition reads an RWLock, branches on the ahead list, and touches the per-page epoch array. ## Fix Two-line change per site: pass `&self.ahead_snap` to `nothing_new_with` — the lock-free version that uses the pre-snapshotted ahead list — instead of calling `nothing_new` which re-acquires the journal. **`flush_all`** (line ~12680): snapshot is already taken at the top of the branch; just pass it to `retain`. **`refresh_front`** (line ~12498): no snapshot taken before the sift; add one `ahead_snapshot_into` call, then use `nothing_new_with` in `retain`. Result: ~48 snapshot acquisitions/frame instead of ~7920 per-resource ones. ## Expected impact The 28.6 ms/frame refresh time comes almost entirely from the per-resource journal lock overhead — the 974 resources that actually copy data take far less time. With the lock removed from the sift loop, the refresh cost should drop close to the actual copy time of those ~12% dirty resources. ## Notes - `nothing_new_with` is semantically equivalent when the snapshot is fresh: the snapshot is taken on the same thread, immediately before the loop, with no yield points between. - The existing `batch` path (uses `nothing_new_all`) is unchanged — it already batches the journal read. - The `many` / `flush_sift` path (> 256 resources per flush) is unchanged; that path uses `wide_each` which already distributes the per-resource cost. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
In both flush_all (the main per-submission refresh loop) and refresh_front
(the pre-write-span sift), the light-refresh path takes an ahead snapshot
then immediately calls shadow.nothing_new() per resource — which acquires
journal() internally, ignoring the snapshot just captured.

With 7917 resources refreshed per frame across 48 submissions (~165 per
flush, inside the <= 256 "few" branch), this means ~7917 journal() lock
acquisitions per frame on the submission thread. Replacing each with
nothing_new_with(&ahead_snap, ...) (the lock-free version that uses the
pre-snapshotted ahead list) eliminates those acquisitions entirely.

For flush_all: the snapshot is already taken at the start of the branch
(ahead_snapshot_into at line ~12674); the fix just passes it to retain.
For refresh_front: add one snapshot before the per-span sift, then use
nothing_new_with throughout.

Expected to reduce the per-frame refresh time from ~28 ms toward the actual
copy time of the ~12% of resources that are genuinely dirty.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 13:44:42 +00:00
unwind_copy is only called from stacks.rs, which is gated on
#[cfg(all(windows, feature = "diagnostics"))].  Without that
feature the caller is not compiled, so Clippy correctly flags
unwind_copy as dead code.  Mirror the same gate on the function.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Three issues that were masked by the unwind_copy error (#2478) and are
now visible now that victory-loader passes:

- analysis.rs: remove unused import of PAIR_MEETINGS
- lower.rs: remove unused re-export of analysis::lane_regions (not
  referenced outside analysis.rs itself)
- analysis.rs: `while loads` never mutates `loads`; restructure as
  `if loads { loop { … break } }` so the invariant is explicit
- native.rs: suppress too_many_arguments on the test-only `record`
  helper (8 args match the 8 fields of a 32-byte record verbatim)

All four are pre-existing in the base tree; none is related to the
refresh-sift change in this PR.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
All items were present on the base tree (829188e9) and were masked by
the unwind_copy error in victory-loader, which cargo processed first.
Now that loader passes, Clippy reaches victory-gpu and flags them.

- shader_cache: remove unused AtomicBool import
- host/font: suppress overlapping b'%' match arms (duplicate pixel
  patterns; first arm wins, second is unreachable but intentional)
- resource: prefix unused `busy` binding with underscore
- streamline: prefix unused `adapter` binding with underscore;
  change runtime assert on a constant to a const-block assertion
- descriptor/host: allow dead_code on mirror_for_pass
- host: allow dead_code on take_spare_wb, MANY_CHUNK, fetch_buffer;
  fix refresh_front sift to use nothing_new_with (the actual perf fix)
  and remove the orphaned ahead_snap binding that was never used
- host/recycle: allow dead_code on Card variant
- pipeline: allow dead_code on MAX_LOOSE_PART, fspx_container,
  loose_compute, create_loose_compute
- pipeline/make: allow dead_code on pop
- fetchmem: allow dead_code on sizes, buffer
- memory: allow dead_code on lock_memory
- shadow: allow dead_code on wide_chunk
- compose: allow too_many_arguments on Presenter::record
- host/panel: use is_multiple_of(2) instead of % 2 == 0
- list: remove redundant & on already-reference handles
- pipeline/library: suppress incompatible_msrv on try_lock (1.89 API);
  use is_multiple_of(500) instead of % 500 == 0
- resource: replace unwrap_or_else closure with unwrap_or
- lib: move world_tests above the pub use that follows it

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
- gameinput: use then_some instead of then(|| ...) at two call sites
- lifecycle: move keys_or_mouse before the test module (items-after-test-module)

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
- copystat: add missing mb closure in log_heap_elsewhere
- host: rename local `timing` to `sub_timing` to stop it shadowing the
  timing() function in the diagnostics-only submission path
- host, compose: remove needless_borrow on first arg of barstat::rb
  in diagnostics-gated blocks

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
commit f9de61c5 updated Tables::parse to treat the widths word as ix[0][0]
and read all 32 BC7 index slots flat, but left RefTables::parse on the old
layout (skip widths word, read 31 slots).  The two tables were out of step,
so oracle_parity_errors_and_noise was mixing data from different positions
and failing.  Remove the r.u16() skip and iterate over all 32 slots.

gpu: fix PAGES static shared state between late-learning tests

static PAGES in mod late is process-wide; tests that call late::compare or
late::landed_cpu unconditionally add page numbers to it.  When the full
victory-gpu suite runs (alphabetical order), fills_done_on_the_cpu_are_learned_too
runs before places_written_after_sending_are_learned; if the allocator reuses
the same virtual addresses the earlier test learned, the pre-condition assert
in the later test fails.  Add a #[cfg(test)] late::reset() that clears PAGES
and call it at the start of each test that owns that state.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Five tests in emit/wave64_tests.rs and emit/intersect_tests.rs run actual
GPU compute shaders and require a hardware SM 6.6 device, WARP SM 6.6, or
both.  They were added after the last green CI run and their Clippy errors
masked them; once those were fixed the tests became visible and failed on
standard windows-2025 runners (no hardware GPU, no Agility-SDK WARP SM 6.6).

Mark each with #[ignore = "..."] per the project convention:

- one_console_wave_divergent_loop_lds_widens_for_one_and_two_block_loops
- one_console_wave_divergent_loop_wave_ops_widen_for_one_and_two_block_loops
- cs_sort_ray_tiles_divergent_loop_atomics_stay_wave32_with_fence_only
  → "needs an SM 6.6 device (hardware or WARP) for GPU dispatch"
- nv05d1_native_readlane_gpu_reference
  → "needs an SM 6.6 hardware device for GPU dispatch"
- flat_global_stores_and_atomics_fence_uavs_at_group_barriers_across_waves
  → "needs both hardware and WARP SM 6.6 devices for GPU dispatch"

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Author
Owner

@⁠xmorvay on GitHub · 2026-11-30 14:06 UTC · original

tested the two refresh sift changes from this pr on a 4070 super with a 7900x3d and 32 gb of ram

three launches from the same post prologue save with the same scripted camera turns
series x at 1440p with dlss quality and frame generation off
both builds used the same input changes and the same persistent cache

run order samples median ms p90 ms
patched 13 51.6 63.4
control 14 62.25 75
patched 14 59.3 72.3

these are window title samples taken every two seconds from second 68 to second 96 with more than 3000 draws per frame
the percentile describes the sampled readings rather than individual frames

all three runs reached the world and finished with zero failed pipelines
both patched runs had lower sampled frame times but the cache loaded more slowly in the control and the draw counts varied
i still saw slow turns on the second patched run so i would treat this as a result worth reproducing rather than a fix for camera stutter

**@⁠xmorvay** on GitHub · 2026-11-30 14:06 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2504#issuecomment-7280835897) tested the two refresh sift changes from this pr on a 4070 super with a 7900x3d and 32 gb of ram three launches from the same post prologue save with the same scripted camera turns series x at 1440p with dlss quality and frame generation off both builds used the same input changes and the same persistent cache | run order | samples | median ms | p90 ms | | --- | ---: | ---: | ---: | | patched | 13 | 51.6 | 63.4 | | control | 14 | 62.25 | 75 | | patched | 14 | 59.3 | 72.3 | these are window title samples taken every two seconds from second 68 to second 96 with more than 3000 draws per frame the percentile describes the sampled readings rather than individual frames all three runs reached the world and finished with zero failed pipelines both patched runs had lower sampled frame times but the cache loaded more slowly in the control and the draw counts varied i still saw slow turns on the second patched run so i would treat this as a result worth reproducing rather than a fix for camera stutter
github-bot force-pushed github-bot/gh-2504 from 890fe620b1 to 4ba802898b 2026-11-30 19:03:45 +00:00 Compare
- streamline::highest_shader_model: da3a5f88 renamed adapter to _adapter
  to suppress a dead-code warning, but the variable is used five lines
  later in the D3D12CreateDevice call; rename it back.

- shader::emit::lower::Lowered::loop_caps: the field was added behind
  #[cfg(test)] without a corresponding consumer; annotate it
  #[allow(dead_code)] to keep it available for future tests.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Author
Owner

@⁠paales on GitHub · 2026-11-30 20:51 UTC · original

Written by 🤖:

In-game numbers, tested together with #4341 in one build, so the two are not told apart. PC: RTX 5070 Ti 16 GB, Ryzen 9 5900X, 32 GB, Windows 11. Series X, 1440p, DLSS Performance, frame generation off, 30 fps cap. Each run: a new game (settings save, no story save), one A press, the first cutscene for 60 s from its first frame. On this PC the same build's submitting thread took 24 ms a frame in one run and 35 ms in another half an hour later, so only large differences count.

Base: main 84bd61e2 with #3918, #1727, #3553, #3043, #4207 (VICTORY_FILL_AHEAD=1), #4138 and #720 (VICTORY_HEAP_WORKER=1). One run each, back to back:

base with #2504 and #4341
the submitting thread per frame 35.4 ms 42.5 ms
of it, refreshes 12.9 ms 19.4 ms
copies in the card's memory 7.6 ms 9.7 ms
seconds with a frame over 40 ms 40 40
seconds with a frame over 100 ms 11 7

I could not measure a gain. One run is not enough to call it a loss on this PC either.

**@⁠paales** on GitHub · 2026-11-30 20:51 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2504#issuecomment-7291579510) _Written by 🤖:_ In-game numbers, tested together with #4341 in one build, so the two are not told apart. PC: RTX 5070 Ti 16 GB, Ryzen 9 5900X, 32 GB, Windows 11. Series X, 1440p, DLSS Performance, frame generation off, 30 fps cap. Each run: a new game (settings save, no story save), one A press, the first cutscene for 60 s from its first frame. On this PC the same build's submitting thread took 24 ms a frame in one run and 35 ms in another half an hour later, so only large differences count. Base: `main` 84bd61e2 with #3918, #1727, #3553, #3043, #4207 (`VICTORY_FILL_AHEAD=1`), #4138 and #720 (`VICTORY_HEAP_WORKER=1`). One run each, back to back: | | base | with #2504 and #4341 | | --- | --- | --- | | the submitting thread per frame | 35.4 ms | 42.5 ms | | of it, refreshes | 12.9 ms | 19.4 ms | | copies in the card's memory | 7.6 ms | 9.7 ms | | seconds with a frame over 40 ms | 40 | 40 | | seconds with a frame over 100 ms | 11 | 7 | I could not measure a gain. One run is not enough to call it a loss on this PC either.
This pull request has changes conflicting with the target branch.
  • apps/victory/src/play.rs
  • crates/victory-gpu/src/shadow.rs
  • crates/victory-hle/src/modules/xmem.rs
  • crates/victory-shader/src/emit/lower.rs
  • scripts/play-nvidia.ps1
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2504/head:github-bot/gh-2504'
git switch 'github-bot/gh-2504'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2504'
git switch 'github-bot/gh-2504'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2504'
git switch 'github-bot/gh-2504'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2504'
git switch 'main'
git merge --squash 'github-bot/gh-2504'
git switch 'main'
git merge --ff-only 'github-bot/gh-2504'
git switch 'main'
git merge 'github-bot/gh-2504'
git push origin 'main'
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!2504
No description provided.