Title memory by address: make a rehydration's inputs ready before it runs #87

Open
github-bot wants to merge 2 commits from github-bot/gh-86 into main AGit
Owner

@⁠Mbappinho on GitHub · 2026-12-05 05:00 UTC · original
Mbappinho:sw-rehydrate-ready → main · +146 −13 · 3 files · 2 commits · open

What this changes

With -RayTracing (the software walk, the default), the builder's rehydration stages read each geometry's vertices, indices and transform through pointers that none of their dispatch arguments show. Title memory by address gives a page a copy on the card only after a shader has touched it without one, and that access reads 0. Draws and per-frame builds recover on the next frame. A structure is rehydrated once, though, so it kept those zeros for the rest of the run.

The probe's rehydrate wrapper already reads the geometry descriptions the title passes, for its counts. It now also hands their ranges to title memory by address before it calls the DLL (memory::ready_ahead, exported as victory_gpu::title_memory_ready_ahead). The ranges are the vertices (with the 32 bytes before the first vertex, where the title's quantized positions keep their header), the indices and the transform.

  • The change is on unless VICTORY_BVH_REHYDRATE_PREPARE=0.
  • The probe's log line now also counts the pages made ready (about 40 a frame while the world loads, then a few).
  • The probe is on with -RayTracing unless VICTORY_BVH_PROBE=0; turning the probe off also turns this off.
  • One unit test covers the ranges.

How it was found

I took memory dumps (VICTORY_MEMORY_DUMP, diagnostics build) 110 s into the world, read the rehydrated structures back from the arenas and decoded their leaves. I first checked the reader on the structures the title's builder built itself in the same dumps.

leaves of the rehydrated structures positions inside the box all zero outside the box
VICTORY_BVH_REHYDRATE_PREPARE=0 (as main) 43.4 % 49.7 % 7.0 %
this change 92.6 % 1.9 % 5.5 %
built by the title's builder, same dumps (check of the reader) 85-90 % 3.4-4.8 % 5.3-10.3 %

The first two rows come from two back-to-back runs of one exe with the switch flipped. I measured the second row again with this branch's exe and got the same figures. With the change, 1,302 of 1,701 rehydrated structures are whole, against 738 of 1,707 without it.

Before the change, 80 % of the structures with at least 70 % zero leaves had vertex or index pages missing from the card's copy at dump time, against 9 % of the structures with under 10 % zero leaves. The runtime's own warning ("shaders touched pages that had no copy (those accesses read 0 ...)") fires while the world loads.

Measured

RX 9070 XT, Ryzen 7 9800X3D, 32 GB, Windows 11. Release build of this branch. Series X, -RayTracing -NoPcQuality, no other switch. Same save, standing still outdoors, 60 s to settle, then 150 s measured, nobody at the controls; runs alternated (on, off, off, on).

fps median fps p10 frame ms card ms prep ms
VICTORY_BVH_REHYDRATE_PREPARE=0 25 / 26 24 / 26 39.3 / 38.0 12.5 / 11.3 21.9 / 21.9
this change 30 / 30 29 / 29 33.0 / 33.1 6.2 / 5.9 22.4 / 22.6
  • The card's time is about halved. The probe rays also hit sooner (below): with the geometry back, they stop at it instead of walking on.
  • The CPU pays about 0.5-0.7 ms of preparation per frame for the copies made ahead. An earlier pair of the same kind on my diagnostics branch showed the same pattern: 31 / 31 against 28 / 26.
  • Light, measured on my diagnostics branch (966f7e7c + #81 + this change, software walk): GI pass output (mean red of its target) 3.90 and 3.96 with this change, 4.99 without (one run), 3.82 with #81's hardware walk. Probe hit distance 3,074 and 3,143 with this change, 4,236 without, 2,475 with hardware rays. With this change the software walk's GI pass output comes close to the hardware walk's (the light gap I reported in #81 mostly closes); the probe hit distance still differs, and I have no console reference to say which is right.
  • Device removed: 0 in 13 runs (5 of this branch, 8 of the diagnostics branch).

Checks

  • cargo clippy --workspace --all-targets --locked -- -D warnings, and with --all-features: clean.
  • cargo test --workspace --locked --no-fail-fast: everything that ran passed except host::stamps::tests::a_submissions_times_are_the_pcs, which fails on main on this PC too. victory-loader's unit tests hang here when run in parallel, as noted in #81, and I stopped the run there.
  • cargo test --workspace --all-features --locked -- --test-threads=1: the same host::stamps failure. In one full run, descriptor::host::tests::slots_gray_for_long_are_named also failed (it times slots in seconds); it then passed in 3 of 3 runs of the victory-gpu tests on this branch and 2 of 2 on main.
  • cargo xtask policy: ok.

Made with Claude Code.

**@⁠Mbappinho** on GitHub · 2026-12-05 05:00 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/86) `Mbappinho:sw-rehydrate-ready` → `main` · +146 −13 · 3 files · 2 commits · open ## What this changes With `-RayTracing` (the software walk, the default), the builder's rehydration stages read each geometry's vertices, indices and transform through pointers that none of their dispatch arguments show. Title memory by address gives a page a copy on the card only after a shader has touched it without one, and that access reads 0. Draws and per-frame builds recover on the next frame. A structure is rehydrated once, though, so it kept those zeros for the rest of the run. The probe's rehydrate wrapper already reads the geometry descriptions the title passes, for its counts. It now also hands their ranges to title memory by address before it calls the DLL (`memory::ready_ahead`, exported as `victory_gpu::title_memory_ready_ahead`). The ranges are the vertices (with the 32 bytes before the first vertex, where the title's quantized positions keep their header), the indices and the transform. - The change is on unless `VICTORY_BVH_REHYDRATE_PREPARE=0`. - The probe's log line now also counts the pages made ready (about 40 a frame while the world loads, then a few). - The probe is on with `-RayTracing` unless `VICTORY_BVH_PROBE=0`; turning the probe off also turns this off. - One unit test covers the ranges. ## How it was found I took memory dumps (`VICTORY_MEMORY_DUMP`, diagnostics build) 110 s into the world, read the rehydrated structures back from the arenas and decoded their leaves. I first checked the reader on the structures the title's builder built itself in the same dumps. | leaves of the rehydrated structures | positions inside the box | all zero | outside the box | |---|---|---|---| | `VICTORY_BVH_REHYDRATE_PREPARE=0` (as `main`) | 43.4 % | 49.7 % | 7.0 % | | this change | 92.6 % | 1.9 % | 5.5 % | | built by the title's builder, same dumps (check of the reader) | 85-90 % | 3.4-4.8 % | 5.3-10.3 % | The first two rows come from two back-to-back runs of one exe with the switch flipped. I measured the second row again with this branch's exe and got the same figures. With the change, 1,302 of 1,701 rehydrated structures are whole, against 738 of 1,707 without it. Before the change, 80 % of the structures with at least 70 % zero leaves had vertex or index pages missing from the card's copy at dump time, against 9 % of the structures with under 10 % zero leaves. The runtime's own warning ("shaders touched pages that had no copy (those accesses read 0 ...)") fires while the world loads. ## Measured RX 9070 XT, Ryzen 7 9800X3D, 32 GB, Windows 11. Release build of this branch. Series X, `-RayTracing -NoPcQuality`, no other switch. Same save, standing still outdoors, 60 s to settle, then 150 s measured, nobody at the controls; runs alternated (on, off, off, on). | | fps median | fps p10 | frame ms | card ms | prep ms | |---|---|---|---|---|---| | `VICTORY_BVH_REHYDRATE_PREPARE=0` | 25 / 26 | 24 / 26 | 39.3 / 38.0 | 12.5 / 11.3 | 21.9 / 21.9 | | this change | 30 / 30 | 29 / 29 | 33.0 / 33.1 | 6.2 / 5.9 | 22.4 / 22.6 | - The card's time is about halved. The probe rays also hit sooner (below): with the geometry back, they stop at it instead of walking on. - The CPU pays about 0.5-0.7 ms of preparation per frame for the copies made ahead. An earlier pair of the same kind on my diagnostics branch showed the same pattern: 31 / 31 against 28 / 26. - Light, measured on my diagnostics branch (`966f7e7c` + #81 + this change, software walk): GI pass output (mean red of its target) 3.90 and 3.96 with this change, 4.99 without (one run), 3.82 with #81's hardware walk. Probe hit distance 3,074 and 3,143 with this change, 4,236 without, 2,475 with hardware rays. With this change the software walk's GI pass output comes close to the hardware walk's (the light gap I reported in #81 mostly closes); the probe hit distance still differs, and I have no console reference to say which is right. - Device removed: 0 in 13 runs (5 of this branch, 8 of the diagnostics branch). ## Checks - `cargo clippy --workspace --all-targets --locked -- -D warnings`, and with `--all-features`: clean. - `cargo test --workspace --locked --no-fail-fast`: everything that ran passed except `host::stamps::tests::a_submissions_times_are_the_pcs`, which fails on `main` on this PC too. `victory-loader`'s unit tests hang here when run in parallel, as noted in #81, and I stopped the run there. - `cargo test --workspace --all-features --locked -- --test-threads=1`: the same `host::stamps` failure. In one full run, `descriptor::host::tests::slots_gray_for_long_are_named` also failed (it times slots in seconds); it then passed in 3 of 3 runs of the `victory-gpu` tests on this branch and 2 of 2 on `main`. - `cargo xtask policy`: ok. Made with Claude Code.
The builder's rehydration stages read each geometry's vertices, indices and
transform through pointers none of their arguments show. A page with no copy
on the card reads 0, and since a structure is rehydrated once, the zeros
stayed in it for the rest of the run (about half of the rehydrated triangles
in a test run). The probe's rehydrate wrapper now hands those ranges to
title memory by address first (`title_memory_ready_ahead`). On unless
VICTORY_BVH_REHYDRATE_PREPARE=0.

Made with Claude Code.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-05 05:02:22 +00:00
Author
Owner

@⁠ReTerryDavis on GitHub · 2026-12-05 09:44 UTC · original

Awesome improvement for software -RayTracing! Just a few small fixes in crates/victory-gpu/src/memory.rs before merging:

  1. Doc comment placement: pub fn ready_ahead was inserted between pub(crate) fn ready's doc comment (/// Before a draw...) and fn ready(...), attaching ready's docs to ready_ahead.
  2. Overflow & page-span clamping in ready_ahead: address + len - 1 can overflow u64 on malformed inputs—use address.saturating_add(len - 1) and clamp the end page to u64::from(MEMORY_PAGES) - 1 before iterating pages.clone().filter(...).
  3. Sync m.frame: Sync m.frame to crate::frame::current() (for compatibility with 627da77's DIRTY_WINDOW / dirty_epoch tracking if ready_ahead runs before memory::ready() on a new frame). Optional nice-to-have: mark newly mapped read-only input arena pages held.loose = true to match memory::ready.

(The Default tests CI failure was just an unrelated pre-existing descriptor.rs flake.) Once those small items in memory.rs are tidied up, this is ready to merge!

**@⁠ReTerryDavis** on GitHub · 2026-12-05 09:44 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/86#issuecomment-7435888755) Awesome improvement for software `-RayTracing`! Just a few small fixes in `crates/victory-gpu/src/memory.rs` before merging: 1. **Doc comment placement:** `pub fn ready_ahead` was inserted between `pub(crate) fn ready`'s doc comment (`/// Before a draw...`) and `fn ready(...)`, attaching `ready`'s docs to `ready_ahead`. 2. **Overflow & page-span clamping in `ready_ahead`:** `address + len - 1` can overflow `u64` on malformed inputs—use `address.saturating_add(len - 1)` and clamp the end page to `u64::from(MEMORY_PAGES) - 1` before iterating `pages.clone().filter(...)`. 3. **Sync `m.frame`:** Sync `m.frame` to `crate::frame::current()` (for compatibility with `627da77`'s `DIRTY_WINDOW` / `dirty_epoch` tracking if `ready_ahead` runs before `memory::ready()` on a new frame). Optional nice-to-have: mark newly mapped read-only input arena pages `held.loose = true` to match `memory::ready`. (The `Default tests` CI failure was just an unrelated pre-existing `descriptor.rs` flake.) Once those small items in `memory.rs` are tidied up, this is ready to merge!
github-bot force-pushed github-bot/gh-86 from 6f9374a257 to 3aa85624cb 2026-12-05 18:01:35 +00:00 Compare
Author
Owner

@⁠Mbappinho on GitHub · 2026-12-05 17:57 UTC · original

Thanks for the review. All three are in 3aa85624, with the branch rebased on main at a6b5a998 (it merges cleanly with today's 8bff52be):

  1. ready_ahead now comes after ready, with its own doc comment; ready's doc comment is back on ready.
  2. The page span is clamped: the last page is address.saturating_add(len - 1) / PAGE, capped at MEMORY_PAGES - 1, and a range that is empty or starts past the directory is skipped.
  3. The frame's start that ready did inline (set m.frame, clear refused, take_faults, look_again, report, and the diagnostics' per-frame work) is now Memory::begin_frame, called by both. A rehydration that comes first in a frame starts that frame as ready would, so ready does not skip the start and what ready_ahead dirties carries the current frame. The pages given a copy here are marked loose, as a read-only view's.

Checked on this exact build: clippy with and without --all-features (with main's own lint failures allowed), the workspace tests but victory-gpu, whose test target does not build on main (overlay/shots.rs, Tab::Lighting), on one thread since victory-loader's hang with the default count (see #81): 1076 passed, 0 failed; and a memory dump: of the rehydrated structures' leaves, 86 of 1.65 M read zero (about half without the fix, in the earlier dumps). On 8f78f14a the fix gave 30.3 / 30.2 fps against 25.4 / 26.3 without; on current main the frame is bound by a slowdown that I will detail on #81 (19.5 / 19.8 against 19.9 / 20.2), so the gain on the card does not show there.

Made with Claude Code.

**@⁠Mbappinho** on GitHub · 2026-12-05 17:57 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/86#issuecomment-7442671651) Thanks for the review. All three are in 3aa85624, with the branch rebased on `main` at a6b5a998 (it merges cleanly with today's 8bff52be): 1. `ready_ahead` now comes after `ready`, with its own doc comment; `ready`'s doc comment is back on `ready`. 2. The page span is clamped: the last page is `address.saturating_add(len - 1) / PAGE`, capped at `MEMORY_PAGES - 1`, and a range that is empty or starts past the directory is skipped. 3. The frame's start that `ready` did inline (set `m.frame`, clear `refused`, `take_faults`, `look_again`, `report`, and the diagnostics' per-frame work) is now `Memory::begin_frame`, called by both. A rehydration that comes first in a frame starts that frame as `ready` would, so `ready` does not skip the start and what `ready_ahead` dirties carries the current frame. The pages given a copy here are marked `loose`, as a read-only view's. Checked on this exact build: clippy with and without `--all-features` (with `main`'s own lint failures allowed), the workspace tests but `victory-gpu`, whose test target does not build on `main` (`overlay/shots.rs`, `Tab::Lighting`), on one thread since `victory-loader`'s hang with the default count (see #81): 1076 passed, 0 failed; and a memory dump: of the rehydrated structures' leaves, 86 of 1.65 M read zero (about half without the fix, in the earlier dumps). On `8f78f14a` the fix gave 30.3 / 30.2 fps against 25.4 / 26.3 without; on current `main` the frame is bound by a slowdown that I will detail on #81 (19.5 / 19.8 against 19.9 / 20.2), so the gain on the card does not show there. Made with Claude Code.
Author
Owner

@⁠Saksukella on GitHub · 2026-12-05 18:01 UTC · original

Tested this independently on **AMD Radeon RX 9070 XT (

**@⁠Saksukella** on GitHub · 2026-12-05 18:01 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/86#issuecomment-7442746026) Tested this independently on **AMD Radeon RX 9070 XT (
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-86'
git switch 'github-bot/gh-86'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-86'
git switch 'github-bot/gh-86'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-86'
git switch 'main'
git merge --squash 'github-bot/gh-86'
git switch 'main'
git merge --ff-only 'github-bot/gh-86'
git switch 'main'
git merge 'github-bot/gh-86'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.