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

Manually merged
github merged 1 commit from github-bot/gh-700 into main 2026-11-29 08:21:49 +00:00 AGit
Owner

@⁠kibagami-nc on GitHub · 2026-11-28 03:46 UTC · original
kibagami-nc:perf/scratch-small-chunk-takes-a-kept-one → main · +65 −15 · 1 files · 1 commits · merged 2026-11-29 08:16 UTC

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.

**@⁠kibagami-nc** on GitHub · 2026-11-28 03:46 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/700) `kibagami-nc:perf/scratch-small-chunk-takes-a-kept-one` → `main` · +65 −15 · 1 files · 1 commits · merged 2026-11-29 08:16 UTC **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.
A list's first scratch chunk is a small one (SCRATCH_FIRST, 256 KiB), and
Spare::take 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 (a
committed upload buffer), and as many came back past the bound and were
freed; on an RTX 5080 (Series S, a balcony scene) some 35 a frame, about
1 ms each to free.

take_chunk now gives a kept 4 MiB chunk for a small first one when none of
the small size is kept, and says so by the size it returns, so the list
uses the whole chunk and gives it back as 4 MiB (take_kept). A kept small
one still comes first. VICTORY_SCRATCH_ANY_SIZE=0 keeps the exact sizes.

Port of the first part of Ym1r1710's change (fxceless/victory-fork#1367).
Its second part, a bound of 512 MiB on the kept spares, is left out: this
tree already raises the bound to 1 GiB where the PC's memory is not
limited (SPARE_KEPT, keep_freed), and keeps 128 MiB elsewhere.

Test a_small_first_chunk_takes_a_kept_4_mib_one (the spare module).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 03:49:09 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-28 04:30 UTC · original · approved these changes

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).

**@⁠Dukestar69** on GitHub · 2026-11-28 04:30 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/700#pullrequestreview-6095814764) · **approved these changes** 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).
github-bot force-pushed github-bot/gh-700 from 7d981e5382 to 889c85928b 2026-11-28 20:00:45 +00:00 Compare
github-bot force-pushed github-bot/gh-700 from 889c85928b to ffc33ebd96 2026-11-29 00:39:37 +00:00 Compare
github manually merged commit e32d481e00 into main 2026-11-29 08:21:49 +00:00
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!700
No description provided.