Unified memory: copy back only the aliased sub-ranges of a write-combined piece (VICTORY_UNIFIED_ALIAS_RANGE) #4776

Closed
github-bot wants to merge 4 commits from github-bot/gh-4775 into main AGit
Owner

@⁠henriazz10 on GitHub · 2026-12-01 07:24 UTC · original
henriazz10:perf/copy-back-range1k → main · +677 −52 · 2 files · 4 commits · closed without merging

Refs #4426

What it changes

On the console the CPU and the GPU share one memory; on PC every write the title's shaders make to write-combined memory has to be copied back to system memory in case another copy reads it. Leaving copy-back out for whole classes was fast but broke faces and hair, because some of those pieces are aliased by another copy (#4426). Turning it back on for every piece that touches an alias copied back 9.5–35.8 GB per frame in our logs, because the decision was made per whole piece, and against the whole 4 MiB LOOSE window.

This decides it per sub-range:

  • VICTORY_UNIFIED_ALIAS_STRICT=1: records alias history (EVER_ALIASED) so a piece is never left on the card when another copy has ever overlapped it, also across evictions and re-creation.
  • VICTORY_UNIFIED_ALIAS_RANGE=1: splits each piece [a, b) into the exact sub-ranges that are aliased (copied back) and the rest (left on the card), using exact interval difference. Title buffers always use their full range; LOOSE windows use only the range actually asked for (asked[0..1]), unless a view without a size was made. Five unit tests check that copied back ∪ left == [a, b) and copied back ∩ left == ∅, byte for byte.
  • VICTORY_WC_NO_BACK_ALIAS_SAFE=1 and the play.rs defaults (UNIFIED_BACK=wc,coherent,cpu-only,unknown, WC_PIECES=1, WC_NO_BACK=1, WC_NO_BACK_PC=1, WC_NO_BACK_MIN_BYTES=1024, UNIFIED_STATS=1) put it to use. A piece whose alias appears only after the write is counted as late hits in the unified memory: line.

How it was tested

  • GPU and profile: RTX 5080 16 GB, Ryzen 9 5950X, 32 GB RAM, Windows 11; Series X profile, 1706×960 → 2560×1440, DLSS Quality, frame generation off, ray tracing off.
  • Bench: fixed in-game route, 120 s, 2 alternated runs per config, compared at matched load: submit-thread preparation −11.8 % against v2026.11.30.03 (62.9 ms vs 71.9 ms inside the load band). Copy-back fell from 9.5–35.8 GB/frame (whole-piece decision) to about 30 MB/frame, with late hits 0 in every bench run.
  • Real play (14 min, then 6.5 min and 23 min on later builds): no crash. Faces, hair, vehicles and the aircraft checked in the recordings at every moment the log showed late hits > 0: no stale or broken image. Those moments come only during scene loads and mission fades (up to 24 hits in one second), so this keeps the late hits counter on to show them.
  • Checks on Windows with the repo's toolchain (1.98.1), same commands as ci.yml: cargo build --release passes. cargo clippy --workspace --all-targets --locked -- -D warnings gives no new finding (it already fails on main, in the same 3 files). cargo test --workspace --locked: 2492 pass; modules::xmem::tests::a_read_by_range_waits_only_for_a_remapping_that_meets_it fails on every branch of this set and on none of the files they touch, and host::card_steps::tests::shared_scratch_eliminates_flight_settle_end_to_end once in the full parallel run, and each passes when run alone (--exact); main itself fails host::refresh_tests::chunked_nothing_new_with_matches_individual in the same run. cargo fmt --check already reports hundreds of hunks per file on main; the new code follows the style of the code around it.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related, not duplicates: #4675 (copy-back of listed render-target kinds), #4527 (lazy GPU_OWNED copy-back), #4528 (WC_BAR=3 for small read-only WC buffers), #4143.

AI-assisted. Neon (Gemini) wrote the change; Claude Code reviewed it, rebased it on main, built it, ran the checks, measured it and checked the image in the recordings.

🤖 Generated with Claude Code

**@⁠henriazz10** on GitHub · 2026-12-01 07:24 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4775) `henriazz10:perf/copy-back-range1k` → `main` · +677 −52 · 2 files · 4 commits · closed without merging <!-- Thanks for the pull request. Please label it (pr-fix, pr-feature, pr-performance, pr-diagnostics, pr-refactor, pr-docs or pr-tests, plus the area labels), or put the label in the title, like [pr-fix]. --> Refs #4426 ## What it changes On the console the CPU and the GPU share one memory; on PC every write the title's shaders make to write-combined memory has to be copied back to system memory in case another copy reads it. Leaving copy-back out for whole classes was fast but broke faces and hair, because some of those pieces are aliased by another copy (#4426). Turning it back on for every piece that touches an alias copied back **9.5–35.8 GB per frame** in our logs, because the decision was made per whole piece, and against the whole 4 MiB `LOOSE` window. This decides it **per sub-range**: - `VICTORY_UNIFIED_ALIAS_STRICT=1`: records alias history (`EVER_ALIASED`) so a piece is never left on the card when another copy has ever overlapped it, also across evictions and re-creation. - `VICTORY_UNIFIED_ALIAS_RANGE=1`: splits each piece `[a, b)` into the exact sub-ranges that are aliased (copied back) and the rest (left on the card), using exact interval difference. Title buffers always use their full range; `LOOSE` windows use only the range actually asked for (`asked[0..1]`), unless a view without a size was made. Five unit tests check that copied back ∪ left == `[a, b)` and copied back ∩ left == ∅, byte for byte. - `VICTORY_WC_NO_BACK_ALIAS_SAFE=1` and the `play.rs` defaults (`UNIFIED_BACK=wc,coherent,cpu-only,unknown`, `WC_PIECES=1`, `WC_NO_BACK=1`, `WC_NO_BACK_PC=1`, `WC_NO_BACK_MIN_BYTES=1024`, `UNIFIED_STATS=1`) put it to use. A piece whose alias appears only after the write is counted as `late hits` in the `unified memory:` line. ## How it was tested - GPU and profile: RTX 5080 16 GB, Ryzen 9 5950X, 32 GB RAM, Windows 11; Series X profile, 1706×960 → 2560×1440, DLSS Quality, frame generation off, ray tracing off. - Bench: fixed in-game route, 120 s, 2 alternated runs per config, compared at matched load: submit-thread preparation **−11.8 %** against `v2026.11.30.03` (62.9 ms vs 71.9 ms inside the load band). Copy-back fell from 9.5–35.8 GB/frame (whole-piece decision) to about 30 MB/frame, with `late hits 0` in every bench run. - Real play (14 min, then 6.5 min and 23 min on later builds): no crash. Faces, hair, vehicles and the aircraft checked in the recordings at every moment the log showed `late hits > 0`: no stale or broken image. Those moments come only during scene loads and mission fades (up to 24 hits in one second), so this keeps the `late hits` counter on to show them. - Checks on Windows with the repo's toolchain (1.98.1), same commands as `ci.yml`: `cargo build --release` passes. `cargo clippy --workspace --all-targets --locked -- -D warnings` gives no new finding (it already fails on `main`, in the same 3 files). `cargo test --workspace --locked`: 2492 pass; `modules::xmem::tests::a_read_by_range_waits_only_for_a_remapping_that_meets_it` fails on every branch of this set and on none of the files they touch, and `host::card_steps::tests::shared_scratch_eliminates_flight_settle_end_to_end` once in the full parallel run, and each passes when run alone (`--exact`); `main` itself fails `host::refresh_tests::chunked_nothing_new_with_matches_individual` in the same run. `cargo fmt --check` already reports hundreds of hunks per file on `main`; the new code follows the style of the code around it. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related, not duplicates: #4675 (copy-back of listed render-target kinds), #4527 (lazy GPU_OWNED copy-back), #4528 (`WC_BAR=3` for small read-only WC buffers), #4143. AI-assisted. Neon (Gemini) wrote the change; Claude Code reviewed it, rebased it on `main`, built it, ran the checks, measured it and checked the image in the recordings. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Fixes three correctness gaps in the #3838 unified copy-back path behind
VICTORY_UNIFIED_ALIAS_STRICT=1 (off by default, cached in OnceLock):
1. Removes the 1 MiB owner.len < unified_alias_max() blind spot so shader
   writes through >= 1 MiB pools or loose windows into ranges aliased by
   smaller buffers (e.g. skinned face/hair vertex buffers) are always
   copied back, recording exact overlapping sub-ranges in EVER_ALIASED.
2. Tracks merged aliased address intervals in EVER_ALIASED (trimmed in
   protection_freed after releasing PROTECTIONS) and hooks all Shadow
   creation paths after releasing BUFFERS/LOOSE locks (plus propagating
   card_left across grown windows).
3. Calls list.note_batch_write for pieces skipped by unified_pieces so
   indirect draw batch write tracking never misses skipped shader writes.

(cherry picked from commit 4e370b89be5ea1af629baa57c6b803a2056d5133)
Applies the same strict live-overlap and EVER_ALIASED check to the
standalone VICTORY_WC_NO_BACK=1 path (when VICTORY_UNIFIED_BACK is unset),
behind VICTORY_WC_NO_BACK_ALIAS_SAFE=1 (off by default, cached in OnceLock).
If a write-combined range is aliased by another copy, it falls through to
full copy-back instead of leaving stale bytes for the other copy.

(cherry picked from commit c05b86e1da50bfc35db2ba7c3c74d13d056ca660)
Recovers the copy-back speed of v2026.11.30.01 (-17% prep@50k) without
broken faces/hair and without copying 9.5-35 GB/frame of over-aliased
write-combined buffers, behind VICTORY_UNIFIED_ALIAS_RANGE=1 (off by default):
1. Splits each skipped piece [a, b) by exact interval difference against
   live overlaps and EVER_ALIASED so only the exact aliased sub-ranges go
   to copy-back while the unaliased bulk stays on the card.
2. Uses exact [asked[0], asked[1]) bounds for sized 4 MiB LOOSE windows
   (falling back to full bounds for BUFFERS and unsized_asks > 0) and
   updates EVER_ALIASED after releasing the LOOSE lock whenever asked
   expands or unsized_asks transitions from 0.
3. Honors VICTORY_WC_NO_BACK_PC=1 alongside VICTORY_WC_PIECES=1.

(cherry picked from commit f65c339255d8f30fe4b55b0e663c8c258e206b29)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 07:26:40 +00:00
github-bot closed this pull request 2026-12-01 18:36:34 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:32 UTC · original

Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

**@⁠trustno1-coder** on GitHub · 2026-12-01 18:32 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4775#issuecomment-7321107253) Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

Pull request closed

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!4776
No description provided.