GPU: a list's small first scratch chunk may be a kept 4 MiB one (port of fxceless#1367, first part) #700

Merged
kibagami-nc merged 1 commit from upstream-pr/700 into main 2026-11-29 08:16:58 +00:00
kibagami-nc commented 2026-11-28 03:46:56 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by kibagami-nc on 2026-11-28T03:46:56Z.


Rebased on main (f9dfb76f). Main has since given scratch chunks a memory kind (Chunk::wb: write-back or write-combined) and takes a kept one only of the kind asked (Spare::take_if). take_kept follows it: a small first chunk takes a kept 4 MiB one of the same memory only, and the test checks that one of the other memory is not taken. cargo test -p victory-gpu --lib --locked: 590 passed, 44 ignored. Clippy: nothing new against main's own findings.

The problem

A list's first scratch chunk is a small one (SCRATCH_FIRST, 256 KiB). Spare::take (crates/victory-gpu/src/host.rs) gives back only a chunk of the exact size asked for.

When the kept spares were all 4 MiB ones, every small first chunk was made new, as a committed upload buffer. As many came back past the bound and were freed. fxceless measured about 35 a frame on an RTX 5080 (Series S, a balcony scene), about 1 ms each to free.

The change

take_chunk gives a kept 4 MiB chunk for a small first one when no chunk of the small size is kept.

  • The real size goes with it: the size it returns is 4 MiB, so the list uses the whole chunk and gives it back as 4 MiB (take_kept).
  • A kept small chunk still comes first.
  • Exact sizes only: VICTORY_SCRATCH_ANY_SIZE=0 turns this off.
  • The other caller: plane_upload, the other user of take_chunk, keeps the size it is given back too.

This is a port of the first part of Ym1r1710's change (fxceless/victory-fork#1367).

Its second part, a 512 MiB bound on the kept spares, is left out. This tree already raises that bound to 1 GiB where the PC's memory is not limited (SPARE_KEPT with keep_freed), and keeps 128 MiB elsewhere. Several reports here are about commit charge on 16 GB PCs, so I did not raise it further for everyone.

fxceless measured both parts together: 63-84 ms a frame before, 52-56 ms after, and 0 chunk drops a frame instead of 30-52. I have not measured this part alone in the game. A run with VICTORY_SCRATCH_ANY_SIZE=0, and one without it, would show its share.

Tests

  • New host::spare::a_small_first_chunk_takes_a_kept_4_mib_one. It covers the switch, sizes other than the small first one, a kept small chunk taken before a 4 MiB one, and the size given back.
  • cargo test -p victory-gpu --locked --lib: 453 passed, 0 failed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings, with and without --all-features: nothing in the changed lines. main's own findings are fixed by #665.

No game files, dumps or extracted data are included.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5536366860 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/700). Originally posted by [kibagami-nc](https://github.com/kibagami-nc) on 2026-11-28T03:46:56Z. --- **Rebased on main (f9dfb76f).** Main has since given scratch chunks a memory kind (`Chunk::wb`: write-back or write-combined) and takes a kept one only of the kind asked (`Spare::take_if`). `take_kept` follows it: a small first chunk takes a kept 4 MiB one of the **same** memory only, and the test checks that one of the other memory is not taken. `cargo test -p victory-gpu --lib --locked`: 590 passed, 44 ignored. Clippy: nothing new against main's own findings. ## The problem A list's first scratch chunk is a small one (`SCRATCH_FIRST`, 256 KiB). `Spare::take` (`crates/victory-gpu/src/host.rs`) gives back only a chunk of the exact size asked for. When the kept spares were all 4 MiB ones, every small first chunk was made new, as a committed upload buffer. As many came back past the bound and were freed. fxceless measured about 35 a frame on an RTX 5080 (Series S, a balcony scene), about 1 ms each to free. ## The change `take_chunk` gives a kept 4 MiB chunk for a small first one when no chunk of the small size is kept. - **The real size goes with it:** the size it returns is 4 MiB, so the list uses the whole chunk and gives it back as 4 MiB (`take_kept`). - **A kept small chunk still comes first.** - **Exact sizes only:** `VICTORY_SCRATCH_ANY_SIZE=0` turns this off. - **The other caller:** `plane_upload`, the other user of `take_chunk`, keeps the size it is given back too. This is a port of the first part of Ym1r1710's change ([fxceless/victory-fork#1367](https://github.com/fxceless/victory-fork/pull/1367)). Its second part, a 512 MiB bound on the kept spares, is left out. This tree already raises that bound to 1 GiB where the PC's memory is not limited (`SPARE_KEPT` with `keep_freed`), and keeps 128 MiB elsewhere. Several reports here are about commit charge on 16 GB PCs, so I did not raise it further for everyone. fxceless measured both parts together: 63-84 ms a frame before, 52-56 ms after, and 0 chunk drops a frame instead of 30-52. I have not measured this part alone in the game. A run with `VICTORY_SCRATCH_ANY_SIZE=0`, and one without it, would show its share. ## Tests - New `host::spare::a_small_first_chunk_takes_a_kept_4_mib_one`. It covers the switch, sizes other than the small first one, a kept small chunk taken before a 4 MiB one, and the size given back. - `cargo test -p victory-gpu --locked --lib`: 453 passed, 0 failed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`, with and without `--all-features`: nothing in the changed lines. `main`'s own findings are fixed by #665. No game files, dumps or extracted data are included.
Dukestar69 commented 2026-11-28 04:30:06 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Dukestar69 on 2026-11-28T04:30:06Z.

Review: APPROVED


LGTM — verified on Windows (RTX 5090):

  • cargo test -p victory-gpu --lib host:: passed (121/121)
  • 0 new compiler warnings in touched files
  • cargo xtask policy passed (294 files ok)

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

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review:6095814764 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/700#pullrequestreview-6095814764). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-28T04:30:06Z. **Review:** APPROVED --- LGTM — verified on Windows (RTX 5090): - `cargo test -p victory-gpu --lib host::` passed (121/121) - 0 new compiler warnings in touched files - `cargo xtask policy` passed (`294 files ok`) Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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!700
No description provided.