Skip to content

Memory by address: the arenas' writes are told, the kernel is not asked about them - #1062

Merged
trustno1-coder merged 1 commit into
trustno1-coder:mainfrom
MrSquirrel489:rt/arena-writes-told
Nov 29, 2026
Merged

trustno1-coder merged 1 commit into
trustno1-coder:mainfrom
MrSquirrel489:rt/arena-writes-told

Conversation

@MrSquirrel489

Copy link
Copy Markdown
Contributor

What

With the title's ray tracing on (VICTORY_BVH_BUILDER=1, F1: RAY TRACING), memory.rs now
tells the write journal of its own writes into the arenas and the directory
(watch::own, watch::owner_wrote), and the kernel is no longer asked what was written there.
VICTORY_MEMORY_OWNED=0 asks the kernel as before.

Why

Every list that reaches memory by address refreshes every arena whole (Memory::bring_up), and
each submission asked the kernel (GetWriteWatch) which pages of all of them were written:
18-21 arenas of 64 MiB and the 128 MB directory. That is 5-9 GB of page tables walked a frame
to find the few pages memory.rs itself had just written (bring, take, fill). The time
follows the megabytes, not the number of askings (5.3 GB: 6.6 ms, 6.6 GB: 7.9 ms, 9.0 GB:
10.8 ms; upload.rs already notes the same of one 3.2 GB reservation).

Stack samples of victory-submit on the boat, 60 s: GetWriteWatch is 27.1 % of the thread
with the builder on and 9.5 % with it off; 16.2 % straight from watch::ask_once (off: 2.1 %).

Nothing else writes that memory: the arenas' copies (shadow::by_address) only read it, and
what shaders store there stays on the card. A write is told after its bytes are in, so a copy
that began before it has an older asking's number and takes the pages again.

Measured

i7-13700K, RTX 4080 16 GB, Windows 11, 3840x2160, DLSS Performance, Series X profile, release
build. One game at a time, runs alternated with main. The boat of the opening, 175-255 s after
the window, medians of the log's 5-second lines.

Kernel askings a frame, diagnostics build, builder on, the office and the cut to outdoors:

main this branch
asked 5,300-9,000 MB 1,720-2,050 MB
time 6.5-11.9 ms 2.8-4.1 ms

Boat, builder on (each column one run):

main main main main branch, switch off branch branch branch
fps 24.5 23.9 21.8 23.1 25.4 27.9 26.8 24.2
frame, ms 40.9 42.0 46.0 43.3 39.4 35.8 37.3 41.4
preparing, ms 24.8 24.9 23.5 24.3 26.3 19.2 19.2 19.4
on the GPU, ms 8.0 9.7 14.6 10.7 4.6 7.6 9.5 13.5

"preparing" falls by about 5 ms in every run. Frames a second follow it only as far as the
card's time allows: that varies from run to run by itself (4.6-14.6 ms, with the state of the
dynamic structures, see "Known gaps" in docs/fork-ray-tracing.md), so single runs overlap.

Boat, builder off (launcher's settings), five runs of main and four of the branch, alternated:
main 30.95, 30.43, 31.10, 30.87, 30.87 fps; branch 30.29, 30.54, 31.39, 30.98 fps. No difference
beyond the spread of runs (about 1.5 fps).

Pictures, builder on, the opening unskipped, screenshots every 5 s: the office is lit as on main
(walls, shelf, the shadowed side of faces), outdoors and the boat look the same. The glitter on
faces that main shows now and then with the builder on is still there now and then: it is not
this change's subject. No device removal or crash in 9 runs of the branch.

Tests: cargo test --locked --workspace --no-fail-fast: 1,127 pass, 0 fail, 49 ignored (one new:
watch::tests::memory_its_owner_tells_of_is_answered_without_the_kernel). In an earlier run
victory-loader's console_insn::tests::a_clzero_loop_becomes_plain_stores failed once and
passed when run again; that crate does not depend on victory-gpu. cargo clippy -p victory-gpu:
no new warning.

Not measured

  • Other cards and CPUs; AMD; more than 16 GB of the card's memory in use.
  • Longer play than the first 4.5 minutes of the title; free roam.
  • The first minutes while packed structures stream in were looked at only as 5-second lines
    (branch: 10 s under 5 fps, 25 s at 5-15 fps in one run; main: 50 s and 15 s in one run). One
    run each: not a claim.
  • VICTORY_RELAY=0, VICTORY_ASK_ONCE=0 and other non-default paths of the write watch.

🤖 Generated with Claude Code

…ed about them

With the title's ray tracing on (VICTORY_BVH_BUILDER=1), every list that
reaches memory by address refreshes every arena whole, and each submission
asked the kernel which pages of them were written: 18-21 arenas of 64 MiB
and the directory, 5-9 GB of page tables walked a frame, 6.5-11.9 ms of the
submitting thread (i7-13700K, diagnostics build), to find the few pages
memory.rs itself had just written.

Only memory.rs writes the arenas and the directory. It now tells the journal
of each write (watch::owner_wrote), and ranges that are owned this way are
answered from the journal alone: 1.7-2.0 GB asked a frame, 2.8-4.1 ms.
On the boat of the opening, 4K, RTX 4080: "preparing" 23.5-24.9 ms -> 19.2-19.4
ms a frame with the builder on. Without the builder nothing measurable changes.

VICTORY_MEMORY_OWNED=0 asks the kernel as before.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@jptorres96

Copy link
Copy Markdown

Checked this on Windows at 59e7a01 (base 63b902f), without the game. Ryzen 5 5600X, RTX 4080 SUPER, Windows build 26300, rustc 1.98.1.

  • cargo test --locked -p victory-gpu --lib -- --test-threads=1: 454 passed, 0 failed, 38 ignored, including memory_its_owner_tells_of_is_answered_without_the_kernel.
  • cargo clippy -p victory-gpu --all-targets [--all-features] -- -D warnings: clean in both builds once the manual_is_multiple_of already on main (descriptor.rs:1234) is allowed.

The saving, synthetically. I wrote an ignored test on my fork, probe-1062, on top of this branch. It sets up 20 write-watched arenas of 64 MiB, every page touched once. Each frame it writes 40 random 8-byte spots per arena and then calls writes() over every arena whole. It also checks that every page written that frame comes back with a newer write than the frame's start.

20 x 64 MiB (1.28 GB) per frame written pages missed
asked of the kernel 1.40-1.44 ms 0
own + owner_wrote 0.08 ms 0
VICTORY_MEMORY_OWNED=0 1.34 ms 0

That is about 1.1 ms per GB asked, so your 5.3-9 GB would come to 6-10 ms here. That is in line with your 6.5-11.9 ms, and with the time following the megabytes.

Cost elsewhere. owned() adds a read of OWNED to writes, asked, nothing_new and ask_rest. I ran the #795 probe from my comment there on this branch: per-range writes on memory that isn't owned, 1, 4 and 8 threads. It shows nothing above main (8 threads: 22 us a range write-watched and 84 us guarded, against 25 and 92 on main).

Read through. In memory.rs, every write into the arenas and the directory goes through owner_wrote: fill, gone's cleared entry, take's merge and the piece copy. The one other write_volatile is to the faults buffer, which isn't owned. The watch::wrote dropped from place is covered by hold, which calls fill. The only VirtualFree of an arena is the failure path, which calls disown first, so a stale OWNED range can't later cover a reservation that something else writes. What the probe can't check is your statement that nothing else writes there, i.e. that what shaders store stays on the card.

Conflict with #1094. That PR replaces nothing_new with lock-free nothing_new_with / nothing_new_single, so the two don't merge cleanly in watch.rs. Whichever lands second should add || owned(first, last) to known in both new functions. Leaving it out isn't unsafe: they answer false and the refresh falls through to writes(), which does handle owned memory. But the arenas would then lose the shortcut. #1094 also mirrors Journal::note into its epoch table, and owner_wrote goes through note, so that part combines without changes.

Synthetic only: no game files.

@Bj0rnis

Bj0rnis commented Nov 28, 2026

Copy link
Copy Markdown

Independent live RT-on (VICTORY_BVH_BUILDER=1) verification on RTX 5070 Ti 16 GB + Ryzen 7 9800X3D (Windows 11, 32 GB RAM, driver 621.24, Rust 1.98.1, --release build from source at 59e7a01, Series X profile, 2560×1440, DLSS Quality, Frame Generation off; opening → prison cell → prison break room, ~27 RT arenas / 1,484 MB, ~412–419 BVH build dispatches/frame).

Targeted asking the write watch A/B (same binary, VICTORY_BVH_BUILDER=1):

Metric (submitting-thread 1 s log samples) VICTORY_MEMORY_OWNED=0 (n=269) VICTORY_MEMORY_OWNED=1 (default, n=306) Delta
Median asking the write watch 9.1 ms 4.7 ms −4.4 ms (−48.4%)
p90 asking the write watch 10.8 ms 6.4 ms −4.4 ms (−40.7%)
Max asking the write watch 13.6 ms 12.9 ms −0.7 ms
Device removed / OOM 0 / 0 0 / 0 Clean

Visuals & caveats:

  • RT indirect lighting, soft shadows, and floor reflections worked cleanly in both passes with no new regressions from VICTORY_MEMORY_OWNED=1. (Observed normal run-to-run variance under high VRAM pressure [13.7–13.9 / 14.5 GB VRAM, 7.0–7.4 GB shared]: Run 1 [OWNED=1] rendered the phone screen and showed the known waitress face glitter; Run 2 [OWNED=0] had a clean waitress face and a black phone screen.)
  • FPS caveat: The OWNED=1 run was our first cold RT launch (compiling RT/BVH pipelines on the fly, 6.7 fps median / 22.4 fps peak), whereas the OWNED=0 run had warm RT pipelines (14.6 fps median / 18.5 fps in the 9.3k-draw prison break room / 24.3 fps peak), so raw FPS is not apples-to-apples between the two passes — only the isolated asking the write watch saving above.

Automated checks: Clean merge-tree on main (63b902f); cargo test --locked -p victory-gpu --features diagnostics --lib -- watch:: memory:: 53 passed, 0 failed (including watch::tests::memory_its_owner_tells_of_is_answered_without_the_kernel); cargo xtask policy 294 files ok.

Not tested: boat / free-roam scenes or VICTORY_BVH_BUILDER=0 regression check. No game data, logs, or captures attached.

AI-assisted test run and summary.

@Rafa7046

Copy link
Copy Markdown
Contributor

Here is a data point from a different implementation of the same idea, plus the boat, which is listed as not tested.

Setup: RTX 5080, 9950X3D, Series X, 1440p, DLSS Performance, VICTORY_BVH_BUILDER=1, main at 8fc2254. A script plays the prologue cutscenes, then stands one minute on Jason's boat.

Before I saw this PR, I wrote a local variant:

  • every write we make into an arena (fill, take's merge, the piece copy) pushes a mark;
  • at the front of each submission, where refresh_front does its refreshes, the marks go into the copies' CPU side;
  • the arenas are left out of the per-list refresh, so nothing asks the kernel about them, and a new arena goes up whole once.

I ran alternating sessions on the same exe, with the variant on a switch:

Kernel asking a frame Cutscenes fps Preparing, cutscenes Boat fps Device removed
off (4) 8.9–9.6 GB 42.9 / 41.4 / 42.3 / 23.1 ~19.6 ms 27.1 / 30.5 / 31.4 / 28.8 0 of 4 (a 5th ended in a 0x119 bugcheck)
marks (5) 1.9–2.3 GB 46.2 / 47.4 / 47.5 / 37.8 / 47.8 ~16.9 ms 26.1* / 15.4 / 36.0 / 22.2* / 3.0 2 of 5

* The device was removed; the boat figure is partial.

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

@Lancito01

Copy link
Copy Markdown

Data point (RTX 3080 10 GB, 32 GB RAM, Series S profile, warm cache, prison window scene ~4.1k draws/frame), on main 9ce3cf9 + #938, one change at a time:

ms/frame median write-watch per frame
without #1062 66.5 346 watches, 29.4 ms, 8.9 GB checked
with #1062 (default on) 67.9 358 watches, 37.5 ms, 9.6 GB checked

So on this title the owned arenas don't seem to take memory out of the GetWriteWatch scan; almost all of the ~9 GB checked is still unchanged each frame. Happy to rerun with extra logging if you want to see which ranges stay watched.

AI-assisted (Claude).

@Lancito01

Copy link
Copy Markdown

Follow-up to my data point above: comparing screenshots, the run with this PR drew the prison jumpsuits (Lucia's and the inmates' outside) dark red instead of orange; the runs before and after it on the same base, cache and settings drew them orange. So beside no speed change here, it looks like something written into owned memory is not being seen (stale colour data). One run only, same scene (prison window, ~4.1k draws).

AI-assisted (Claude).

@trustno1-coder
trustno1-coder merged commit e74eb4b into trustno1-coder:main Nov 29, 2026
krolyxon added a commit to krolyxon/VIctory-NVIDIA-proton that referenced this pull request Nov 29, 2026
Conflicts:
- shadow.rs: upstream's Copied { pages, ranges } replaces trustno1-coder#1298's tuple;
  trustno1-coder#1298's batched nothing_new_with keeps its shape on it (Copied::ranged
  replaces ranged_in); trustno1-coder#1184's lazy landing and its tests follow (pages,
  arena). An unused copy_all of trustno1-coder#1298's and the VICTORY_WIDE_CHUNK tests
  (helpers dropped earlier) are left out.
- watch.rs: trustno1-coder#1062's owned memory is told in asked() beside trustno1-coder#1298's binary
  search, and counted as known by is_published() (so the batched
  nothing_new sees it too, sampled before the journal's lock).
- structure.rs: upstream's trustno1-coder#1103 (ours came adapted through trustno1-coder#1226).
- lib.rs: both modules.
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.

6 participants