pool: reuse pieces the card is through with; rest staging 250 ms #393

Open
github-bot wants to merge 5 commits from github-bot/gh-393 into main AGit
Owner

@⁠cerealfordinner on GitHub · 2026-12-03 23:55 UTC · original
cerealfordinner:upstream/staging-rest-on-fence → main · +598 −105 · 1 files · 5 commits · open

Combines the texture-fence reuse from #364 with the 250 ms staging rest from
#279, rebased onto current main. Both touch the same piece bookkeeping, so
they ship as one change.

  • Retire what goes empty. take() and take_ripe() were test-only, and
    they dropped the blocks take_piece() freed instead of returning them to
    host::retire, so a 64 MiB block past the spares could be unmapped live.
    They return what went with the piece now; take_piece() returns its
    retired blocks instead of taking a seventh argument (the one clippy lint in
    pool.rs). No behaviour change.
  • Reuse texture pieces when the card is done with them. A texture piece
    rested 5 s by the clock alone, which under pressure loops: the sweep frees
    host copies, their pieces rest, the blocks can't go back, new textures take
    new blocks, and the card fills. On a 16 GB card (Boat and Prison) that was
    94 % of the budget, 1,325 passes without room, and 14,721 copies remade.
    A piece is free now once the card has finished FENCE_LAG (128, same as
    host::BURY_LAG) submissions after the newest one that may name it.
    Staging stays on the clock; REST is the fallback for a card that finishes
    nothing.
  • Rest staging 250 ms. Staging pieces come back finished with the last
    list that names them, so the upload heap can rest 250 ms instead of 5 s and
    be reused and retired sooner in streaming bursts. Texture pieces keep the
    fence path above.
**@⁠cerealfordinner** on GitHub · 2026-12-03 23:55 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/393) `cerealfordinner:upstream/staging-rest-on-fence` → `main` · +598 −105 · 1 files · 5 commits · open Combines the texture-fence reuse from #364 with the 250 ms staging rest from #279, rebased onto current `main`. Both touch the same piece bookkeeping, so they ship as one change. - **Retire what goes empty.** `take()` and `take_ripe()` were test-only, and they dropped the blocks `take_piece()` freed instead of returning them to `host::retire`, so a 64 MiB block past the spares could be unmapped live. They return what went with the piece now; `take_piece()` returns its retired blocks instead of taking a seventh argument (the one clippy lint in `pool.rs`). No behaviour change. - **Reuse texture pieces when the card is done with them.** A texture piece rested 5 s by the clock alone, which under pressure loops: the sweep frees host copies, their pieces rest, the blocks can't go back, new textures take new blocks, and the card fills. On a 16 GB card (Boat and Prison) that was 94 % of the budget, 1,325 passes without room, and 14,721 copies remade. A piece is free now once the card has finished `FENCE_LAG` (128, same as `host::BURY_LAG`) submissions after the newest one that may name it. Staging stays on the clock; `REST` is the fallback for a card that finishes nothing. - **Rest staging 250 ms.** Staging pieces come back finished with the last list that names them, so the upload heap can rest 250 ms instead of 5 s and be reused and retired sooner in streaming bursts. Texture pieces keep the fence path above.
take() and take_ripe() took the blocks take_piece() let go of and dropped
them where they stood: a 64 MiB heap block past the spares was unmapped
live instead of going back to the caller for host::retire (and never
counted in GOING/GONE). Both were dead code outside the tests, so they are
test-only now and return what went with the piece.

take_piece() returns what went instead of taking it as a seventh argument
(clippy::too_many_arguments, the one lint pool.rs had), and its two
searches (blocks that stay, blocks being emptied) are kept() and
emptying(). No behaviour change.
A texture's piece given back rested five seconds before it could be used
again (REST; the module doc said two), by the clock alone. Under pressure
that is a loop: the sweep lets host copies go to give blocks back, their
pieces rest, the blocks cannot go back, new textures go into new blocks,
the card fills, more is let go and made again (a 16 GB card on Boat and
Prison: 94 % of its budget, 1,325 passes without room, 14,721 copies made
again).

The pool of textures is fenced now: a piece is free once the card finished
FENCE_LAG (128, as host::BURY_LAG) submissions after the newest one that
may name what it held (STARTED + queued(), as host::retire counts it),
rested or not. Staging buffers are the PC's memory: they rest by the clock
alone. REST stays as the fallback for a card that finishes nothing.

When it is looked for: for want of room in take_piece(), before a block
being emptied is refilled or a new one made; and in the once-a-second
sweep of room(), so that a block the sweep emptied is back on the card two
frames on. The least free_from gates the walk of what rests: a look that
finds nothing costs nothing.

Tests: one short of FENCE_LAG a piece is not touched, at FENCE_LAG the same
piece is used again with no block made, a pool that is not fenced rests,
only what the card is through with goes, blocks made whole go back past
the spares at once (the sweep's look and for want of room), and 4,000
pseudo-random steps on a card of eight blocks check that pieces never
overlap and none is used again before it rested or the card is through
with it.
Port of PR #279 to the current pool: staging pieces come back with the
last list that names them (finished by then), so the upload heap can rest
250 ms instead of 5 s and be reused and retired sooner during streaming
bursts. Texture pieces keep the 5 s clock and the fence path (PR #364).

(cherry picked from commit 7cff9880a07bc70dc50f5c595c630c6e89f1a80a)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-03 23:57:21 +00:00
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-04 00:20 UTC · original

Checked this against #364 and #279 put together by hand.

The first two commits are #364 unchanged: git diff between #364's head and 1c75d6a..e3b2e00 on pool.rs is empty, so what I wrote on #364 still applies here. For the third commit I rebuilt the combination myself (cherry-picked #364's two commits, then #279's, on the same base 1152b9c, resolved the four conflicts the obvious way) and diffed pool.rs against this branch. The non-test code comes out the same:

  • new(most, fenced) just calls with_rest(most, fenced, REST) (pool.rs:296-300), so TEXTURES still gets 5000 ms as the clock fallback.
  • give_at sets rested_at = now + self.rest_ms (pool.rs:538). free_from is still computed the same way.
  • STAGING is with_rest(STAGING_KEPT, false, STAGING_REST) (pool.rs:672). It is unfenced, so by_fence returns straight away for it (pool.rs:600), and the tick passes finished = 0 for staging anyway (pool.rs:70). Staging goes by 250 ms on the clock and nothing else. Textures go by the fence, with 5 s as the fallback.
  • I grepped for REST outside the tests. The only code use is the default in new, so no other timer or retire path is still on 5 s for staging.

The differences are comments and tests:

  • STAGING_REST sits after REST and the doc is reworded (pool.rs:97-102). The new wording is a bit stronger than #279's: it says the piece's list "has finished by then". That's true when the wait succeeds. The caveat from my #279 comment still applies: the host sync path warns and carries on if Signal/SetEventOnCompletion fails, and the ahead path drops jobs after a failed wait. With 250 ms there's much less slack in those cases than with 5 s. That gap was already there and isn't something this PR needs to fix. I'd just soften the comment a little.
  • The module doc still says the clock means REST for staging buffers (pool.rs:18). It's 250 ms for staging now.
  • #279's two tests are replaced by a_staging_piece_rests_less_than_a_texture_piece (pool.rs:1328-1352). It checks the 249/250 ms edge for staging and the 5 s fallback for a fenced pool with no finished submissions, all through reclaim. Compared with #279's first test, it no longer checks reuse through take() at the edge or that the blocks past STAGING_KEPT get retired. Losing the concurrent test costs nothing, because it passed with rest 0 too (see my note on #279).

Tests on this branch, one NVIDIA desktop card:

  • cargo test -p victory-gpu --lib pool::: 16 tests, 20/20 debug, 20/20 release. The new test fails if give_at ignores rest_ms, so it does pin the wiring
  • full victory-gpu --lib run: 346 passed, 5 failed. Those are the same 5 that fail on main for me (two indirect::host_list_*, two pipeline::host, the flaky watch test)
  • cargo clippy -p victory-gpu --all-targets: nothing in pool.rs

So this matches #364 + #279 apart from the test swap and the two doc points above.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-04 00:20 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/393#issuecomment-7396664253) Checked this against #364 and #279 put together by hand. The first two commits are #364 unchanged: `git diff` between #364's head and 1c75d6a..e3b2e00 on pool.rs is empty, so what I wrote on #364 still applies here. For the third commit I rebuilt the combination myself (cherry-picked #364's two commits, then #279's, on the same base 1152b9c, resolved the four conflicts the obvious way) and diffed pool.rs against this branch. The non-test code comes out the same: - `new(most, fenced)` just calls `with_rest(most, fenced, REST)` (pool.rs:296-300), so TEXTURES still gets 5000 ms as the clock fallback. - `give_at` sets `rested_at = now + self.rest_ms` (pool.rs:538). `free_from` is still computed the same way. - STAGING is `with_rest(STAGING_KEPT, false, STAGING_REST)` (pool.rs:672). It is unfenced, so `by_fence` returns straight away for it (pool.rs:600), and the tick passes `finished = 0` for staging anyway (pool.rs:70). Staging goes by 250 ms on the clock and nothing else. Textures go by the fence, with 5 s as the fallback. - I grepped for `REST` outside the tests. The only code use is the default in `new`, so no other timer or retire path is still on 5 s for staging. The differences are comments and tests: - `STAGING_REST` sits after `REST` and the doc is reworded (pool.rs:97-102). The new wording is a bit stronger than #279's: it says the piece's list "has finished by then". That's true when the wait succeeds. The caveat from my #279 comment still applies: the host sync path warns and carries on if Signal/SetEventOnCompletion fails, and the ahead path drops jobs after a failed wait. With 250 ms there's much less slack in those cases than with 5 s. That gap was already there and isn't something this PR needs to fix. I'd just soften the comment a little. - The module doc still says the clock means `REST` for staging buffers (pool.rs:18). It's 250 ms for staging now. - #279's two tests are replaced by `a_staging_piece_rests_less_than_a_texture_piece` (pool.rs:1328-1352). It checks the 249/250 ms edge for staging and the 5 s fallback for a fenced pool with no finished submissions, all through `reclaim`. Compared with #279's first test, it no longer checks reuse through `take()` at the edge or that the blocks past `STAGING_KEPT` get retired. Losing the concurrent test costs nothing, because it passed with rest 0 too (see my note on #279). Tests on this branch, one NVIDIA desktop card: - `cargo test -p victory-gpu --lib pool::`: 16 tests, 20/20 debug, 20/20 release. The new test fails if `give_at` ignores `rest_ms`, so it does pin the wiring - full `victory-gpu --lib` run: 346 passed, 5 failed. Those are the same 5 that fail on main for me (two `indirect::host_list_*`, two `pipeline::host`, the flaky watch test) - `cargo clippy -p victory-gpu --all-targets`: nothing in pool.rs So this matches #364 + #279 apart from the test swap and the two doc points above. AI-assisted: yes
Author
Owner

@⁠deyvideguilherme on GitHub · 2026-12-04 01:58 UTC · original

Tested #393 (26b70f7, on top of main 1152b9c) on Linux/RADV in a ~5 min live gameplay session (Series S, 1920x1080, VICTORY_BVH_BUILDER=1, driving route), compared against main 1152b9c on the same machine and route:

  • Environment: Ryzen 7 5700X, RX 9060 XT 16 GiB (RDNA 4, Mesa RADV), 16 GiB RAM + zram, CachyOS Linux, GE-Proton11-16, release build (./build.sh, 0 warnings/errors in build; run exited with code 0 and 0 ERROR log entries).
Metric main (1152b9c, 299.5 s) #393 (26b70f7, 296.5 s)
pool::STAGING blocks — p50 / p90 / max (MiB) 896 / 1408 / 2048 384 / 435 / 512
GTT used — p50 / p90 / max (MiB) 7793 / 8197 / 8871 7203 / 7458 / 7538
Available RAM — min / p50 (MiB) 1402.6 / 2436.2 3076.9 / 3751.2
VRAM used — max (MiB) 12717.6 12395.7
Copy prep — p99 / max (ms) 6.43 / 8.19 5.61 / 6.18
FPS p50 29.86 28.39
  • Notes: single Linux/RADV 16 GiB host and manual driving routes; no FPS gain is claimed. On the #279 side, this matches the staging/GTT reduction seen with #279 alone on the same host (p50 320 MiB / max 576 MiB, GTT max 7437 MiB).
**@⁠deyvideguilherme** on GitHub · 2026-12-04 01:58 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/393#issuecomment-7398436145) Tested #393 (`26b70f7`, on top of `main` `1152b9c`) on Linux/RADV in a ~5 min live gameplay session (`Series S`, `1920x1080`, `VICTORY_BVH_BUILDER=1`, driving route), compared against `main` `1152b9c` on the same machine and route: - **Environment:** Ryzen 7 5700X, RX 9060 XT 16 GiB (RDNA 4, Mesa RADV), 16 GiB RAM + zram, CachyOS Linux, GE-Proton11-16, release build (`./build.sh`, 0 warnings/errors in build; run exited with code 0 and 0 `ERROR` log entries). | Metric | `main` (`1152b9c`, 299.5 s) | `#393` (`26b70f7`, 296.5 s) | | --- | --- | --- | | `pool::STAGING` blocks — p50 / p90 / max (MiB) | 896 / 1408 / 2048 | 384 / 435 / 512 | | GTT used — p50 / p90 / max (MiB) | 7793 / 8197 / 8871 | 7203 / 7458 / 7538 | | Available RAM — min / p50 (MiB) | 1402.6 / 2436.2 | 3076.9 / 3751.2 | | VRAM used — max (MiB) | 12717.6 | 12395.7 | | Copy prep — p99 / max (ms) | 6.43 / 8.19 | 5.61 / 6.18 | | `FPS` p50 | 29.86 | 28.39 | - **Notes:** single Linux/RADV 16 GiB host and manual driving routes; no FPS gain is claimed. On the `#279` side, this matches the staging/GTT reduction seen with #279 alone on the same host (`p50 320 MiB / max 576 MiB`, GTT max `7437 MiB`).
Author
Owner

@⁠fsrajner on GitHub · 2026-12-04 08:14 UTC · original

Tested on top of main together with the other PRs listed below. In this scene (the intro, about 2 minutes, 16 GB card) we see no measurable change. A longer run with more texture streaming might show it better.

Setup: RX 9070 XT 16 GB, Ryzen 7 7800X3D, CachyOS, RADV from this repo's setup.sh. Series X, 3840x2160 output, FSR 4 Quality (4.1.2), RT at defaults, headless gamescope. Same save (the intro); the game stops 120 s after the first press. The figures come from the 5 s stats: frame windows after loading. 2 runs per variant; main = 0fd7614. The PR build is main + #382 + #392 + #393 + #408 + #445 + #369 together. #398 was left out because it conflicts with #369 in the residency planning. The #369 merge conflicted only with local counters.

variant ms/frame (runs) 5 s windows > 40 ms worst 5% worst window long frames (longest)
main 47 (48, 45) 86.5% 59.3 ms 62.8 ms 1184 (275 ms)
PR build, defaults 46 (46, 46) 85.7% 61.3 ms 82.9 ms 1176 (254 ms)
PR build + VICTORY_TEXTURE_BARRIERS=1 46 (46, 46) 88.9% 59.0 ms 61.5 ms 1137 (172 ms)
PR build + VICTORY_CARD_KEPT_MB=9216 45 (44, 46) 83.8% 63.4 ms 65.1 ms 1171 (201 ms)

The first run of main and of the PR build each began by re-preparing shaders after a translator change. That is likely where the 48 ms run and the 82.9 ms worst window come from. Otherwise the spread between runs is about ±1 ms/frame, so all of these are within noise. In this scene the card is the limit (about 21-24 ms of GPU wait per frame).

**@⁠fsrajner** on GitHub · 2026-12-04 08:14 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/393#issuecomment-7405689673) Tested on top of main together with the other PRs listed below. In this scene (the intro, about 2 minutes, 16 GB card) we see no measurable change. A longer run with more texture streaming might show it better. **Setup:** RX 9070 XT 16 GB, Ryzen 7 7800X3D, CachyOS, RADV from this repo's `setup.sh`. Series X, 3840x2160 output, FSR 4 Quality (4.1.2), RT at defaults, headless gamescope. Same save (the intro); the game stops 120 s after the first press. The figures come from the 5 s `stats: frame` windows after loading. 2 runs per variant; main = 0fd7614. The PR build is main + #382 + #392 + #393 + #408 + #445 + #369 together. #398 was left out because it conflicts with #369 in the residency planning. The #369 merge conflicted only with local counters. | variant | ms/frame (runs) | 5 s windows > 40 ms | worst 5% | worst window | long frames (longest) | |---|---|---|---|---|---| | main | 47 (48, 45) | 86.5% | 59.3 ms | 62.8 ms | 1184 (275 ms) | | PR build, defaults | 46 (46, 46) | 85.7% | 61.3 ms | 82.9 ms | 1176 (254 ms) | | PR build + `VICTORY_TEXTURE_BARRIERS=1` | 46 (46, 46) | 88.9% | 59.0 ms | 61.5 ms | 1137 (172 ms) | | PR build + `VICTORY_CARD_KEPT_MB=9216` | 45 (44, 46) | 83.8% | 63.4 ms | 65.1 ms | 1171 (201 ms) | The first run of main and of the PR build each began by re-preparing shaders after a translator change. That is likely where the 48 ms run and the 82.9 ms worst window come from. Otherwise the spread between runs is about ±1 ms/frame, so all of these are within noise. In this scene the card is the limit (about 21-24 ms of GPU wait per frame).
Author
Owner

@⁠Luxuride on GitHub · 2026-12-04 11:28 UTC · original

The fence path reproduces host::bury exactly — submissions().0 + queue::queued() is newest_submission() (pool.rs:521-524 vs host.rs:384-386), and finished >= begun + 128 is the same test bury() applies (host.rs:388-392) — so reuse is at least as safe as what retirement already drops. The least/rested_now bookkeeping keeps the deque ordered, and the growth/fence arms now hand blocks back to host::retire instead of dropping them in place (pool.rs:345-352, the return (None, dropped) arms).

One ask: say where the 250 ms gets its safety. pool.rs:95-101 asserts "a staging piece comes back with the last list that names it, which has finished by then", and that is only true because Staging is dropped through host::retire with _piece (texture.rs:43-49, host.rs:364-367). A future path that drops a list before it finishes turns 250 ms into a use-after-read; naming the dependency (or pinning it with a test) is cheap.

Also worth a sentence: 5 s -> 250 ms is a 20x shortening with no switch back, and if you add one it needs both docs/SETTINGS.md and run.conf.default or it will not appear in the menu.

**@⁠Luxuride** on GitHub · 2026-12-04 11:28 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/393#issuecomment-7410143411) The fence path reproduces `host::bury` exactly — `submissions().0 + queue::queued()` is `newest_submission()` (`pool.rs:521-524` vs `host.rs:384-386`), and `finished >= begun + 128` is the same test `bury()` applies (`host.rs:388-392`) — so reuse is at least as safe as what retirement already drops. The `least`/`rested_now` bookkeeping keeps the deque ordered, and the growth/fence arms now hand blocks back to `host::retire` instead of dropping them in place (`pool.rs:345-352`, the `return (None, dropped)` arms). One ask: say where the 250 ms gets its safety. `pool.rs:95-101` asserts "a staging piece comes back with the last list that names it, which has finished by then", and that is only true because `Staging` is dropped through `host::retire` with `_piece` (`texture.rs:43-49`, `host.rs:364-367`). A future path that drops a list before it finishes turns 250 ms into a use-after-read; naming the dependency (or pinning it with a test) is cheap. Also worth a sentence: 5 s -> 250 ms is a 20x shortening with no switch back, and if you add one it needs both `docs/SETTINGS.md` and `run.conf.default` or it will not appear in the menu.
github-bot force-pushed github-bot/gh-393 from 26b70f7fad to 79ee1c2960 2026-12-04 22:42:04 +00:00 Compare
Author
Owner

@⁠cerealfordinner on GitHub · 2026-12-04 22:39 UTC · original

Rebased onto current main and applied the two doc tweaks from the review (softened "finished by then" wording and the module-doc staging reference). Branch is up to date.

**@⁠cerealfordinner** on GitHub · 2026-12-04 22:39 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/393#issuecomment-7426190825) Rebased onto current `main` and applied the two doc tweaks from the review (softened "finished by then" wording and the module-doc staging reference). Branch is up to date.
Per review: state that the short rest is only safe because a Staging is
dropped through host::retire with its _piece, so the last list naming the
piece has finished before the block is reused; a path that drops a list
early would turn 250 ms into a use-after-read.

Signed-off-by: cerealfordinner <[email protected]>
Author
Owner

@⁠cerealfordinner on GitHub · 2026-12-04 23:15 UTC · original

Added the dependency you asked for to the STAGING_REST doc: the 250 ms rest is only sound because a Staging is dropped through host::retire with its _piece (texture.rs:43-49, host.rs:364-367), so the last list naming the piece has finished before the block is reused — a path that drops a list before it finishes would turn 250 ms into a use-after-read.

cargo check -p victory-gpu --lib --target x86_64-pc-windows-gnu is clean (one pre-existing dead-code warning).

**@⁠cerealfordinner** on GitHub · 2026-12-04 23:15 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/393#issuecomment-7426879817) Added the dependency you asked for to the `STAGING_REST` doc: the 250 ms rest is only sound because a `Staging` is dropped through `host::retire` with its `_piece` (`texture.rs:43-49`, `host.rs:364-367`), so the last list naming the piece has finished before the block is reused — a path that drops a list before it finishes would turn 250 ms into a use-after-read. `cargo check -p victory-gpu --lib --target x86_64-pc-windows-gnu` is clean (one pre-existing dead-code warning).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/393/head:github-bot/gh-393'
git switch 'github-bot/gh-393'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-393'
git switch 'github-bot/gh-393'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-393'
git switch 'github-bot/gh-393'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-393'
git switch 'main'
git merge --squash 'github-bot/gh-393'
git switch 'main'
git merge --ff-only 'github-bot/gh-393'
git switch 'main'
git merge 'github-bot/gh-393'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.