World load: send memory and preludes made ahead of the world's first frame, and a line saying what that frame made (VICTORY_SEND_AHEAD_MB, VICTORY_PRELUDES_AHEAD; off) #4335

Closed
github-bot wants to merge 11 commits from github-bot/gh-4334 into main AGit
Owner

@⁠kMagic142 on GitHub · 2026-11-30 18:59 UTC · original
kMagic142:pr-world-load → main · +1400 −841 · 34 files · 11 commits · closed without merging

What it changes

When the playable world first appears, one frame takes 750 to 1,900 ms. Before it, the loading screen runs for about a minute with 4 to 50 draws a frame, and the threads are mostly idle. That frame makes two kinds of objects where it needs them, on the threads it waits for:

  • Send memory (host/send.rs, VICTORY_SEND_OWN). A submission whose bytes no spare holds gets a new upload buffer, made, made resident and mapped on the thread that takes the bytes. The world's first frame sends far more than any frame before it, so the spares the loading screen left hold none of it. In our runs that frame made 4 to 9 such buffers (1,351 to 1,518 MB) in 127 to 568 ms. The largest was 1 GiB; in one run its MakeResident alone took 154 ms.
  • Preludes (Host::make_prelude: a command allocator and a closed list). A list takes one from the pool at its first submission that needs one, and the loading screen's small lists leave few in the pool. That frame made 63 to 75 of them in 82 to 117 ms.

This PR adds a thread, victory-worldahead, that makes both while the title loads: from the title's first present until the world's first frame. It also adds one log line for that frame. Both switches are off by default.

VICTORY_SEND_AHEAD_MB=<n> (unset or 0: nothing is made). The thread makes one buffer of n MiB for the frame's largest send. It also makes one buffer of each power of two below n, from 256 MiB down to 8 MiB, for the sends in the air beside it. For 1024 that is 1024, 256, 128, 64, 32, 16 and 8 MiB (1,528 MiB). n is capped at 4095, because one upload buffer of 4 GiB is refused (#3729). Each buffer is made by the same call and at the same size as send::memory would make it.

  • The buffers are kept apart from the spares (AHEAD), so neither give_back's cap nor trim's line (#3994) counts them.
  • send::memory takes a spare first, as before. Only when no spare holds the send does it take the least buffer made ahead that holds it. A send made at 256 MiB or less never takes one past 256 MiB: that buffer would be let go after this one use and would be missing for the large send it was made for.
  • Nothing is made while the PC's memory is pressed, nor when less than 8 GiB would be left free beside it. Under pressure, send::trim lets the buffers go at once.
  • At the world's first frame, what is left joins the spares and goes by their rules: up to 256 MiB within kept(), past it let go, as main lets go of large send memory after one use.
  • Nothing is made with VICTORY_SEND_OWN=0, which never takes it, or with VICTORY_SEND_BAR=1, whose memory is the card's.

VICTORY_PRELUDES_AHEAD=<n> (unset or 0: none; at most the pool's 256). The thread makes preludes until those it made and the pool together hold n, 32 at a time, under the same memory conditions. Each costs the driver about 3 MB.

  • HostList::record_prelude takes from the pool first, as before. If the pool is empty, it takes one made ahead before it makes one.
  • A prelude made ahead is stamped when it is taken, not when it was made. Its allocator has held nothing until then, so its age for VICTORY_ALLOCATOR_TRIM (on in victory play, a new allocator past 30 s) starts there. Otherwise a prelude made at the start of loading would get a new allocator in the very frame it was made for.
  • At the world's first frame, those not taken go to the pool, as a list gives its own back (give_prelude).

Nothing that reaches the card changes. A submission writes the bytes its copies read into its send memory, as into any spare, and a prelude is reset before it records.

The line of the world's first frame (always on, once a run). The meter counts each present's draws (crate::draw::drawn). The first frame with 2,000 draws or more gets one line at info: the world's first frame (the first of 2000 draws or more): <ms> ms; .... The loading screen draws 4 to 50 a frame and the world about 5,000. The line gives that frame's gains of:

  • the send memory made in it (how many, MiB, the largest, ms) and the preludes made in it (how many, ms; those made by the new thread are taken out);
  • MakeResident (times, ms) and waits until new memory is mapped (times, ms), on all threads;
  • waits until the sending thread sent what was published (wait_sent, with VICTORY_SUBMIT_SPLIT);
  • what it took of what was made ahead, what was left, and what was not made for want of room.

"The largest" is the value to set VICTORY_SEND_AHEAD_MB from. In our fork the largest single send in that frame was under 1 GiB. #3729 saw one world-load submission send from 1 GB to just past 2 GiB on main's code, on an RTX 5090.

The cost when nothing is made ahead, until the world's first frame: at each present, about 18 relaxed loads, one swap and an uncontended lock. After that frame: one relaxed load per present. make_prelude gains a clock read. send::memory gains one only where it makes memory, and wait_sent two atomic adds only where it waited.

Why off by default: this branch has not run in the game. The measurements below come from our fork. With n=1024 the memory made ahead is 1,528 MiB of the PC's memory during loading. A world-load send just past 2 GiB (#3729) would need n of about 2200, 2,704 MiB in all. On PCs that are short of memory, that conflicts with what #1520 and #3994 keep free.

How it was tested

  • GPU and profile: RTX 5090, Core Ultra 9 285K; Series X profile, DLSS Quality.

  • Where the numbers come from: all of them come from our fork, which is based on v2026.11.28.03 with many local changes. That tree is not main. This branch itself was not run in the game. The fork's versions of these two parts differ from this PR. The fork makes its send memory by doubles from 8 MiB; main makes it in 64 MiB steps up to 256 MiB and past that at its own size, and this PR follows main. The fork's reserve was 1024, 512, 256, 128, 64, 32, 16, 8 and 8 MiB, kept among the spares for good.

  • Before (six runs of our fork on 2026-11-30, nothing made ahead): the world's first frame took 1,254.9, 1,099.8, 754.8, 850.3, 754.2 and 716.8 ms. In it:

    • send memory made: 4 to 9 buffers, 1,350.6 to 1,518.3 MB, in 127.2 to 567.5 ms;
    • preludes and our lists' allocators made: 63 to 75, in 82.5 to 116.9 ms;
    • new memory made resident: 457 to 487 times, in 296.4 to 776.2 ms (the longest call 47.7 to 424.2 ms).
  • After (one run of our fork): 461.7 ms. That run had both parts on (send memory with a 1 GiB top, 2,048 MiB in all; 192 preludes), and with them other fork changes that this PR does not carry:

    • copies of title memory kept up to date ahead;
    • the indirect light stand-in's passes made ahead;
    • clamp scratch buffers made ahead;
    • EnqueueMakeResident on the thread that makes them.

    In that frame: send memory made 0, preludes made 10 (3.2 ms), new memory made resident 433 times in 204.5 ms (the longest 9.1 ms). Made ahead during loading: 9 buffers (2,147.5 MB) in 110.5 ms, 191 preludes in 79.5 ms.

  • Which part does the work: a confirmation job repeated these runs on our fork, same build and scene, no warm-up between runs. The world's first frame took:

    • nothing made ahead: 753.3 and 1,145.0 ms;
    • everything above: 440.9 and 449.4 ms;
    • only send memory (1 GiB top, 2,048 MiB in all) and 192 preludes made ahead, the two parts this PR carries: 536.7 and 531.2 ms;
    • only copies of title memory kept up to date ahead (not in this PR): 601.0 ms.

    So the two parts here take that frame from about 950 ms to about 534 ms in our fork. The rest of the gain comes from the copies kept up to date ahead, which this PR does not carry: main lacks the fork's first copies made ahead that they build on. Frame times after the world appears did not change (17.95 to 18.48 ms median across those runs, against 17.95 to 18.17 without).

  • For shader changes, the wave sizes tested: not a shader change.

  • cargo test passed for the crates it touches: yes, on main with this branch applied, for the Windows target. cargo check -p victory is clean, and cargo test -p victory-gpu --lib ahead passed 22 tests. Three of them are new:

    • send::tests::a_send_takes_the_least_memory_made_ahead_and_one_of_256_mib_or_less_never_one_past_it: which buffer a send takes, and that a 200 MiB send never takes the 1 GiB;
    • worldahead::tests::send_memory_made_ahead_is_the_largest_then_powers_of_two_from_256_mib_down: the sizes for 1024, 2112, 256, 100, 8 and under 8;
    • worldahead::tests::the_world_frames_gains_are_its_own_and_its_largest_send_is_not_a_gain.

    Clippy was not run.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches (world load, first frame, send memory, preludes, residency, made ahead). Related:
    • #3729 made send memory past what is kept at its own size. Main has that rule since 8b801739 (made_for), and this PR builds on it: memory made ahead past 256 MiB is used once and let go like any other. #3729's note that one world-load submission sends up to just past 2 GiB is why the largest size is a switch. #3729 no longer applies to main.
    • #3947 (send spares kept in order) and #3381 (spares in a pool type) change send::memory's spare lookup, next to this PR's change there. Neither applies to main as it is now.
    • #4138 (retirement and periodic sweeps on background threads) and #4227 (the pressed sweep interval) touch host.rs and send.rs. Each applies to main on top of this branch, and this branch on top of each (checked with git apply).
    • #3951 lets trimmed spares go on a thread of their own. Main does that already (let_go), and send memory made ahead that goes under pressure goes the same way.
    • #3703 adds a line for frames over 100 ms, with MakeResident and mapped waits among its parts. This PR's line comes once a run and names what this PR changes: the send memory and preludes the world's first frame made. #3703 does not apply to main as it is now.
    • #1397 (parallel prelude recording) is on main (9e8bb5b3) and still listed as open. This PR changes only which prelude record_prelude takes when the pool is empty, not how preludes are recorded.
    • #3138 (heap buffer views made while the title loads: no 1.6 s stall at world start) and #3486 (bindless buffer copies prepared during scene loading) make other parts of the world's start ahead of time, in other files.
    • #4256 is about the pipelines that frame makes at first use, in the pipeline code.
**@⁠kMagic142** on GitHub · 2026-11-30 18:59 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4334) `kMagic142:pr-world-load` → `main` · +1400 −841 · 34 files · 11 commits · closed without merging ## What it changes When the playable world first appears, one frame takes 750 to 1,900 ms. Before it, the loading screen runs for about a minute with 4 to 50 draws a frame, and the threads are mostly idle. That frame makes two kinds of objects where it needs them, on the threads it waits for: - Send memory (`host/send.rs`, `VICTORY_SEND_OWN`). A submission whose bytes no spare holds gets a new upload buffer, made, made resident and mapped on the thread that takes the bytes. The world's first frame sends far more than any frame before it, so the spares the loading screen left hold none of it. In our runs that frame made 4 to 9 such buffers (1,351 to 1,518 MB) in 127 to 568 ms. The largest was 1 GiB; in one run its `MakeResident` alone took 154 ms. - Preludes (`Host::make_prelude`: a command allocator and a closed list). A list takes one from the pool at its first submission that needs one, and the loading screen's small lists leave few in the pool. That frame made 63 to 75 of them in 82 to 117 ms. This PR adds a thread, `victory-worldahead`, that makes both while the title loads: from the title's first present until the world's first frame. It also adds one log line for that frame. Both switches are off by default. **`VICTORY_SEND_AHEAD_MB=<n>`** (unset or `0`: nothing is made). The thread makes one buffer of n MiB for the frame's largest send. It also makes one buffer of each power of two below n, from 256 MiB down to 8 MiB, for the sends in the air beside it. For 1024 that is 1024, 256, 128, 64, 32, 16 and 8 MiB (1,528 MiB). n is capped at 4095, because one upload buffer of 4 GiB is refused (#3729). Each buffer is made by the same call and at the same size as `send::memory` would make it. - The buffers are kept apart from the spares (`AHEAD`), so neither `give_back`'s cap nor `trim`'s line (#3994) counts them. - `send::memory` takes a spare first, as before. Only when no spare holds the send does it take the least buffer made ahead that holds it. A send made at 256 MiB or less never takes one past 256 MiB: that buffer would be let go after this one use and would be missing for the large send it was made for. - Nothing is made while the PC's memory is pressed, nor when less than 8 GiB would be left free beside it. Under pressure, `send::trim` lets the buffers go at once. - At the world's first frame, what is left joins the spares and goes by their rules: up to 256 MiB within `kept()`, past it let go, as main lets go of large send memory after one use. - Nothing is made with `VICTORY_SEND_OWN=0`, which never takes it, or with `VICTORY_SEND_BAR=1`, whose memory is the card's. **`VICTORY_PRELUDES_AHEAD=<n>`** (unset or `0`: none; at most the pool's 256). The thread makes preludes until those it made and the pool together hold n, 32 at a time, under the same memory conditions. Each costs the driver about 3 MB. - `HostList::record_prelude` takes from the pool first, as before. If the pool is empty, it takes one made ahead before it makes one. - A prelude made ahead is stamped when it is taken, not when it was made. Its allocator has held nothing until then, so its age for `VICTORY_ALLOCATOR_TRIM` (on in `victory play`, a new allocator past 30 s) starts there. Otherwise a prelude made at the start of loading would get a new allocator in the very frame it was made for. - At the world's first frame, those not taken go to the pool, as a list gives its own back (`give_prelude`). Nothing that reaches the card changes. A submission writes the bytes its copies read into its send memory, as into any spare, and a prelude is reset before it records. **The line of the world's first frame** (always on, once a run). The meter counts each present's draws (`crate::draw::drawn`). The first frame with 2,000 draws or more gets one line at info: `the world's first frame (the first of 2000 draws or more): <ms> ms; ...`. The loading screen draws 4 to 50 a frame and the world about 5,000. The line gives that frame's gains of: - the send memory made in it (how many, MiB, the largest, ms) and the preludes made in it (how many, ms; those made by the new thread are taken out); - `MakeResident` (times, ms) and waits until new memory is mapped (times, ms), on all threads; - waits until the sending thread sent what was published (`wait_sent`, with `VICTORY_SUBMIT_SPLIT`); - what it took of what was made ahead, what was left, and what was not made for want of room. "The largest" is the value to set `VICTORY_SEND_AHEAD_MB` from. In our fork the largest single send in that frame was under 1 GiB. #3729 saw one world-load submission send from 1 GB to just past 2 GiB on main's code, on an RTX 5090. The cost when nothing is made ahead, until the world's first frame: at each present, about 18 relaxed loads, one swap and an uncontended lock. After that frame: one relaxed load per present. `make_prelude` gains a clock read. `send::memory` gains one only where it makes memory, and `wait_sent` two atomic adds only where it waited. Why off by default: this branch has not run in the game. The measurements below come from our fork. With n=1024 the memory made ahead is 1,528 MiB of the PC's memory during loading. A world-load send just past 2 GiB (#3729) would need n of about 2200, 2,704 MiB in all. On PCs that are short of memory, that conflicts with what #1520 and #3994 keep free. ## How it was tested - GPU and profile: RTX 5090, Core Ultra 9 285K; Series X profile, DLSS Quality. - Where the numbers come from: all of them come from our fork, which is based on v2026.11.28.03 with many local changes. That tree is not main. This branch itself was not run in the game. The fork's versions of these two parts differ from this PR. The fork makes its send memory by doubles from 8 MiB; main makes it in 64 MiB steps up to 256 MiB and past that at its own size, and this PR follows main. The fork's reserve was 1024, 512, 256, 128, 64, 32, 16, 8 and 8 MiB, kept among the spares for good. - Before (six runs of our fork on 2026-11-30, nothing made ahead): the world's first frame took 1,254.9, 1,099.8, 754.8, 850.3, 754.2 and 716.8 ms. In it: - send memory made: 4 to 9 buffers, 1,350.6 to 1,518.3 MB, in 127.2 to 567.5 ms; - preludes and our lists' allocators made: 63 to 75, in 82.5 to 116.9 ms; - new memory made resident: 457 to 487 times, in 296.4 to 776.2 ms (the longest call 47.7 to 424.2 ms). - After (one run of our fork): 461.7 ms. That run had both parts on (send memory with a 1 GiB top, 2,048 MiB in all; 192 preludes), and with them other fork changes that this PR does not carry: - copies of title memory kept up to date ahead; - the indirect light stand-in's passes made ahead; - clamp scratch buffers made ahead; - `EnqueueMakeResident` on the thread that makes them. In that frame: send memory made 0, preludes made 10 (3.2 ms), new memory made resident 433 times in 204.5 ms (the longest 9.1 ms). Made ahead during loading: 9 buffers (2,147.5 MB) in 110.5 ms, 191 preludes in 79.5 ms. - Which part does the work: a confirmation job repeated these runs on our fork, same build and scene, no warm-up between runs. The world's first frame took: - nothing made ahead: 753.3 and 1,145.0 ms; - everything above: 440.9 and 449.4 ms; - only send memory (1 GiB top, 2,048 MiB in all) and 192 preludes made ahead, the two parts this PR carries: 536.7 and 531.2 ms; - only copies of title memory kept up to date ahead (not in this PR): 601.0 ms. So the two parts here take that frame from about 950 ms to about 534 ms in our fork. The rest of the gain comes from the copies kept up to date ahead, which this PR does not carry: main lacks the fork's first copies made ahead that they build on. Frame times after the world appears did not change (17.95 to 18.48 ms median across those runs, against 17.95 to 18.17 without). - For shader changes, the wave sizes tested: not a shader change. - `cargo test` passed for the crates it touches: yes, on main with this branch applied, for the Windows target. `cargo check -p victory` is clean, and `cargo test -p victory-gpu --lib ahead` passed 22 tests. Three of them are new: - `send::tests::a_send_takes_the_least_memory_made_ahead_and_one_of_256_mib_or_less_never_one_past_it`: which buffer a send takes, and that a 200 MiB send never takes the 1 GiB; - `worldahead::tests::send_memory_made_ahead_is_the_largest_then_powers_of_two_from_256_mib_down`: the sizes for 1024, 2112, 256, 100, 8 and under 8; - `worldahead::tests::the_world_frames_gains_are_its_own_and_its_largest_send_is_not_a_gain`. Clippy was not run. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches (world load, first frame, send memory, preludes, residency, made ahead). Related: - #3729 made send memory past what is kept at its own size. Main has that rule since 8b801739 (`made_for`), and this PR builds on it: memory made ahead past 256 MiB is used once and let go like any other. #3729's note that one world-load submission sends up to just past 2 GiB is why the largest size is a switch. #3729 no longer applies to main. - #3947 (send spares kept in order) and #3381 (spares in a pool type) change `send::memory`'s spare lookup, next to this PR's change there. Neither applies to main as it is now. - #4138 (retirement and periodic sweeps on background threads) and #4227 (the pressed sweep interval) touch `host.rs` and `send.rs`. Each applies to main on top of this branch, and this branch on top of each (checked with `git apply`). - #3951 lets trimmed spares go on a thread of their own. Main does that already (`let_go`), and send memory made ahead that goes under pressure goes the same way. - #3703 adds a line for frames over 100 ms, with `MakeResident` and mapped waits among its parts. This PR's line comes once a run and names what this PR changes: the send memory and preludes the world's first frame made. #3703 does not apply to main as it is now. - #1397 (parallel prelude recording) is on main (9e8bb5b3) and still listed as open. This PR changes only which prelude `record_prelude` takes when the pool is empty, not how preludes are recorded. - #3138 (heap buffer views made while the title loads: no 1.6 s stall at world start) and #3486 (bindless buffer copies prepared during scene loading) make other parts of the world's start ahead of time, in other files. - #4256 is about the pipelines that frame makes at first use, in the pipeline code.
The frame that first draws the world takes 750 to 1,900 ms (RTX 5090,
Core Ultra 9 285K; our fork on v2026.11.28.03, not main). In six runs
without anything made ahead, that frame made 4 to 9 buffers of send
memory (1,351 to 1,518 MB) in 127 to 568 ms, and 63 to 75 preludes in 82
to 117 ms, on the threads it waits for, after about a minute of loading
screen with the threads mostly idle.

A thread of its own (victory-worldahead) makes both from the title's
first present until that frame:
- VICTORY_SEND_AHEAD_MB=<n>: send memory of n MiB (at most 4095) and one
  buffer of each power of two below it from 256 MiB down to 8 MiB, kept
  apart from the spares. When no spare holds a send, send::memory takes
  the least of these that holds it; a send of 256 MiB or less never takes
  one past 256 MiB. Under pressure the buffers go at once; at the world's
  first frame what is left goes by the spares' rules.
- VICTORY_PRELUDES_AHEAD=<n>: preludes until those and the pool hold n.
  record_prelude takes one of them when the pool is empty, stamped at that
  moment for VICTORY_ALLOCATOR_TRIM.
Neither is made while the PC's memory is pressed, nor when less than
8 GiB would be left free. Both are off unless set.

The first frame of 2,000 draws or more gets one line. It gives the
frame's ms; the send memory (with the largest) and preludes made in it;
MakeResident and mapped waits; waits for the sending thread; and what it
took of what was made ahead.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 19:03:38 +00:00
github-bot closed this pull request 2026-12-01 18:43:52 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:42 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:42 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4334#issuecomment-7321390529) 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.
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:44 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:44 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4334#issuecomment-7321444804) 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!4335
No description provided.