Lists' upload buffers are kept and used again, not made for each copy #923

Closed
0xkn0wh3r3 wants to merge 2 commits from upstream-pr/923 into main
0xkn0wh3r3 commented 2026-11-28 09:09:11 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by 0xkn0wh3r3 on 2026-11-28T09:09:11Z.


Why

The upload buffer of a list's copy (HostList::upload: the texels a title copy takes from a buffer, and the zeros of a texture's new levels) was memory of its own, made on the thread translating the list for every such copy and let go when the list was reset. Making one is a CreateCommittedResource with CREATE_NOT_RESIDENT and a MakeResident. With VICTORY_CARD_STEPS=2 (memory the card may write, so a shared buffer) it is also waited for until mapped, a copy queue's round trip.

In a play log on an RTX 5070 Ti (16 GB) with VICTORY_CARD_STEPS=2, new memory was waited for 28,000 times for 22.7 s (the longest 1.8 s, with the card's memory near its budget), and until mapped 25,000 times for 19.4 s. Those lines do not say which memory was waited for, and #630 adds the line that will. These buffers are among the few made that often. The scratch chunks next to them were pooled for the same reason (VICTORY_SCRATCH_POOL); these never were (the code said "shortcut: one buffer per copy; pool them once uploads are frequent").

What

  • A list's upload buffer is made at a power of two from 64 KiB to 32 MiB. It is kept when its list is reset or dropped, and handed to the next list that asks for one of that size. Larger ones are made at their size and let go, as before.
  • A buffer is taken again only by a list recorded after its own was reset, which is after every submission of it finished (HostList::reset), the same rule the scratch chunks rest on. Every caller writes the bytes it uses before the copy.
  • At most 64 MB are kept (256 MB with VICTORY_KEEP_FREED, unless the PC's memory is limited), apart for upload memory and shared memory. They are all let go when the PC's memory is pressured.
  • VICTORY_UPLOAD_POOL=0: one made for each copy, as before.

Before / after

cargo test --release -p victory-gpu --lib -- bench_list_upload_buffers --ignored --nocapture, RTX 5070 Ti, the time the recording thread spends getting the buffer:

200 buffers each. "Kept" takes a buffer from the pool and gives it back, so only its first take makes one; that first one is all of its mean.

Buffer made for each: mean / median / 99th kept: mean / median / 99th
64 KiB upload 1.28 ms / 1.08 / 3.82 6.6 µs / 0 / 0
64 KiB shared (CARD_STEPS=2) 0.98 ms / 0.72 / 3.70 3.8 µs / 0 / 0
1 MiB upload 2.09 ms / 1.77 / 5.44 5.7 µs / 0 / 0
1 MiB shared 0.85 ms / 0.73 / 3.68 3.4 µs / 0 / 0
8 MiB upload 6.69 ms / 5.66 / 13.98 26 µs / 0 / 0
8 MiB shared 1.14 ms / 0.97 / 4.14 7.0 µs / 0 / 0

With VICTORY_BENCH_BUSY=1 (a thread beside it making 64 MiB upload buffers all the time, so the system pages as it does while a scene loads), making one took 24–43 ms on average (99th percentile 39–95 ms), and a kept one 0 µs at the median. That thread makes far more memory than a title does, so take those numbers as an upper bound.

The machine was running another branch's test suite at the same time; both columns ran in the same process, one after the other, so they saw the same load.

Correctness

  • the_next_list_gets_the_upload_buffers_a_list_gave_back (needs a GPU): a buffer a dropped list gave back goes to the next list asking for that size class, mapped and writable, and a second request from the list holding it gets another buffer.
  • kept_upload_buffers_come_in_powers_of_two: the size classes.
  • Not yet tried in play.
  • cargo test -p victory-gpu --lib --locked: 455 passed, 0 failed. cargo clippy --workspace --all-targets --locked -- -D warnings stops at two findings that fail on main already (shadow.rs:1708, victory-shader/src/emit/mod.rs:2768; #630 fixes them) and reports nothing in host.rs.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5538598252 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/923). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-28T09:09:11Z. --- ## Why The upload buffer of a list's copy (`HostList::upload`: the texels a title copy takes from a buffer, and the zeros of a texture's new levels) was memory of its own, made on the thread translating the list for every such copy and let go when the list was reset. Making one is a `CreateCommittedResource` with `CREATE_NOT_RESIDENT` and a `MakeResident`. With `VICTORY_CARD_STEPS=2` (memory the card may write, so a shared buffer) it is also waited for until mapped, a copy queue's round trip. In a play log on an RTX 5070 Ti (16 GB) with `VICTORY_CARD_STEPS=2`, new memory was waited for 28,000 times for 22.7 s (the longest 1.8 s, with the card's memory near its budget), and until mapped 25,000 times for 19.4 s. Those lines do not say which memory was waited for, and #630 adds the line that will. These buffers are among the few made that often. The scratch chunks next to them were pooled for the same reason (`VICTORY_SCRATCH_POOL`); these never were (the code said "shortcut: one buffer per copy; pool them once uploads are frequent"). ## What - A list's upload buffer is made at a power of two from 64 KiB to 32 MiB. It is kept when its list is reset or dropped, and handed to the next list that asks for one of that size. Larger ones are made at their size and let go, as before. - A buffer is taken again only by a list recorded after its own was reset, which is after every submission of it finished (`HostList::reset`), the same rule the scratch chunks rest on. Every caller writes the bytes it uses before the copy. - At most 64 MB are kept (256 MB with `VICTORY_KEEP_FREED`, unless the PC's memory is limited), apart for upload memory and shared memory. They are all let go when the PC's memory is pressured. - `VICTORY_UPLOAD_POOL=0`: one made for each copy, as before. ## Before / after `cargo test --release -p victory-gpu --lib -- bench_list_upload_buffers --ignored --nocapture`, RTX 5070 Ti, the time the recording thread spends getting the buffer: 200 buffers each. "Kept" takes a buffer from the pool and gives it back, so only its first take makes one; that first one is all of its mean. | Buffer | made for each: mean / median / 99th | kept: mean / median / 99th | |---|---|---| | 64 KiB upload | 1.28 ms / 1.08 / 3.82 | 6.6 µs / 0 / 0 | | 64 KiB shared (`CARD_STEPS=2`) | 0.98 ms / 0.72 / 3.70 | 3.8 µs / 0 / 0 | | 1 MiB upload | 2.09 ms / 1.77 / 5.44 | 5.7 µs / 0 / 0 | | 1 MiB shared | 0.85 ms / 0.73 / 3.68 | 3.4 µs / 0 / 0 | | 8 MiB upload | 6.69 ms / 5.66 / 13.98 | 26 µs / 0 / 0 | | 8 MiB shared | 1.14 ms / 0.97 / 4.14 | 7.0 µs / 0 / 0 | With `VICTORY_BENCH_BUSY=1` (a thread beside it making 64 MiB upload buffers all the time, so the system pages as it does while a scene loads), making one took 24–43 ms on average (99th percentile 39–95 ms), and a kept one 0 µs at the median. That thread makes far more memory than a title does, so take those numbers as an upper bound. The machine was running another branch's test suite at the same time; both columns ran in the same process, one after the other, so they saw the same load. ## Correctness - `the_next_list_gets_the_upload_buffers_a_list_gave_back` (needs a GPU): a buffer a dropped list gave back goes to the next list asking for that size class, mapped and writable, and a second request from the list holding it gets another buffer. - `kept_upload_buffers_come_in_powers_of_two`: the size classes. - Not yet tried in play. - `cargo test -p victory-gpu --lib --locked`: 455 passed, 0 failed. `cargo clippy --workspace --all-targets --locked -- -D warnings` stops at two findings that fail on `main` already (`shadow.rs:1708`, `victory-shader/src/emit/mod.rs:2768`; #630 fixes them) and reports nothing in `host.rs`.
Dukestar69 commented 2026-11-28 09:19:58 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Dukestar69 on 2026-11-28T09:19:58Z.

Review: APPROVED


Tested locally merged onto main (63b902f).

  • Merge & Policy: Clean merge; cargo xtask policy passed (294 files ok).
  • Tests (RTX 5090):
    • cargo test -p victory-gpu --lib upload passed (10 passed; 0 failed; 1 ignored, including the new host::upload_pool_tests::kept_upload_buffers_come_in_powers_of_two and the_next_list_gets_the_upload_buffers_a_list_gave_back).
    • cargo test -p victory-gpu --lib list:: passed (7 passed; 0 failed).
    • cargo test -p victory-gpu --lib host::card_steps:: passed (9 passed; 0 failed; 1 ignored).
  • Compiled with 0 warnings.

Clean power-of-two upload-buffer pooling and reuse across command lists. LGTM.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review:6096939168 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/923#pullrequestreview-6096939168). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-28T09:19:58Z. **Review:** APPROVED --- Tested locally merged onto `main` (`63b902f`). - **Merge & Policy**: Clean merge; `cargo xtask policy` passed (`294 files ok`). - **Tests (RTX 5090)**: - `cargo test -p victory-gpu --lib upload` passed (`10 passed; 0 failed; 1 ignored`, including the new `host::upload_pool_tests::kept_upload_buffers_come_in_powers_of_two` and `the_next_list_gets_the_upload_buffers_a_list_gave_back`). - `cargo test -p victory-gpu --lib list::` passed (`7 passed; 0 failed`). - `cargo test -p victory-gpu --lib host::card_steps::` passed (`9 passed; 0 failed; 1 ignored`). - Compiled with 0 warnings. Clean power-of-two upload-buffer pooling and reuse across command lists. LGTM. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
trustno1-coder commented 2026-11-28 19:28:34 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-11-28T19:28:34Z.


Thanks for this. I'm closing it because main already pools list upload buffers by size class (take_upload / give_uploads in host.rs, with VICTORY_UPLOAD_POOL_MB), and the two conflict. If yours does something main's pool doesn't, please rebase it on the current main and open a new pull request with a comparison.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7244571989 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/923#issuecomment-7244571989). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-11-28T19:28:34Z. --- Thanks for this. I'm closing it because main already pools list upload buffers by size class (`take_upload` / `give_uploads` in host.rs, with `VICTORY_UPLOAD_POOL_MB`), and the two conflict. If yours does something main's pool doesn't, please rebase it on the current main and open a new pull request with a comparison.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
trustno1-coder/VIctory-NVIDIA!923
No description provided.