Reuse fenced GPU upload scratch across command lists #1525

Closed
github-bot wants to merge 1 commit from gh-pr/1525/head into gh-pr/1525/base
Owner

@⁠franticfrostin on GitHub · 2026-11-24 18:45 UTC · original
franticfrostin:gpu/upload-scratch-reuse → main · +202 −34 · 1 files · 1 commits · closed without merging

Summary

Recycle idle D3D12 upload scratch across command lists after the GPU has finished using it. The shared pool holds up to 4 MiB. If the fence wait fails, the submission stops through VIctory’s existing GPU failure reporter before the buffers can be recycled.

Testing

On an RTX 4060 Laptop GPU, two 170-second Series S runs compared pooling on and off in the same build. New scratch allocations dropped from 1,669 to 118, while peak scratch capacity rose from 27.5 to 28.5 MiB. A 150-second Series X run also reached world rendering with the pool enabled.

The earlier live runs used 256 KiB chunks and PR #431. The current patch is rebased onto 940d32f and preserves upstream’s on-demand chunk sizing from 64 KiB to 4 MiB. The shared idle pool is capped at 4 MiB in total and reuses chunks of the requested capacity.

On the rebased patch, four scratch tests passed on hardware and WARP. Workspace Clippy with all features, the default-feature GPU Clippy check, and the asset-policy check also passed. Frame rate and long-session stability remain unverified.

Related work includes dedicated upload pooling in #982 and scratch chunk sizing in #1246. Codex helped write and test this patch.

**@⁠franticfrostin** on GitHub · 2026-11-24 18:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/1525) `franticfrostin:gpu/upload-scratch-reuse` → `main` · +202 −34 · 1 files · 1 commits · closed without merging ## Summary Recycle idle D3D12 upload scratch across command lists after the GPU has finished using it. The shared pool holds up to 4 MiB. If the fence wait fails, the submission stops through VIctory’s existing GPU failure reporter before the buffers can be recycled. ## Testing On an RTX 4060 Laptop GPU, two 170-second Series S runs compared pooling on and off in the same build. New scratch allocations dropped from 1,669 to 118, while peak scratch capacity rose from 27.5 to 28.5 MiB. A 150-second Series X run also reached world rendering with the pool enabled. The earlier live runs used 256 KiB chunks and PR #431. The current patch is rebased onto `940d32f` and preserves upstream’s on-demand chunk sizing from 64 KiB to 4 MiB. The shared idle pool is capped at 4 MiB in total and reuses chunks of the requested capacity. On the rebased patch, four scratch tests passed on hardware and WARP. Workspace Clippy with all features, the default-feature GPU Clippy check, and the asset-policy check also passed. Frame rate and long-session stability remain unverified. Related work includes dedicated upload pooling in #982 and scratch chunk sizing in #1246. Codex helped write and test this patch.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:35:11 +00:00
github-bot closed this pull request 2026-11-26 04:35:11 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:30 UTC · original · edited 2026-11-25 06:32 UTC

Automated triage for the maintainers.

Merge candidate. It merges cleanly. In crates/victory-gpu/src/host.rs, HostList::reset now trims each list's scratch to the peak of its last two recordings, and hands the rest to a process-wide idle pool (IDLE_SCRATCH, at most 4 MiB, reused by exact capacity). Scratch::reserve keeps the old growth policy, and it no longer moves the cursor when an allocation fails. This is only safe if no list is reset while its work is still running. I checked that: Host::execute has the only ExecuteCommandLists in the crate, and it waits on the fence for every group. The PR makes a failed fence wait fatal (fail(..) with the removal report) instead of a warning, which closes the one path where a chunk could be recycled while still in use. That behaviour change is deliberate and worth a maintainer's glance. The measured drop from 1,669 to 118 new scratch allocations in a 170 s run is in the description. Overlap with #982 (dedicated uploads) and #1246 (chunk sizing) is noted there.

CI: passing (check).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/1525#issuecomment-7149619235) · edited 2026-11-25 06:32 UTC <!-- victory-triage v1 head=dff5a3bc56e1c91759b1429d3798863ef5421e12 verdict=merge-candidate at=2026-11-25T06:32:08Z --> Automated triage for the maintainers. **Merge candidate.** It merges cleanly. In `crates/victory-gpu/src/host.rs`, `HostList::reset` now trims each list's scratch to the peak of its last two recordings, and hands the rest to a process-wide idle pool (`IDLE_SCRATCH`, at most 4 MiB, reused by exact capacity). `Scratch::reserve` keeps the old growth policy, and it no longer moves the cursor when an allocation fails. This is only safe if no list is reset while its work is still running. I checked that: `Host::execute` has the only `ExecuteCommandLists` in the crate, and it waits on the fence for every group. The PR makes a failed fence wait fatal (`fail(..)` with the removal report) instead of a warning, which closes the one path where a chunk could be recycled while still in use. That behaviour change is deliberate and worth a maintainer's glance. The measured drop from 1,669 to 118 new scratch allocations in a 170 s run is in the description. Overlap with #982 (dedicated uploads) and #1246 (chunk sizing) is noted there. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:01 UTC · original

Automated triage for the maintainers, second look (a review against current main, with builds and tests where they could change the verdict).

Closing because the gain is not shown on main. The measurement (new scratch allocations 1,669 to 118) was taken on an older base with fixed 256 KiB chunks plus another PR. On main each host list already keeps its scratch chunks across resets, and since 9cc37c5f host lists themselves are recycled with their chunks, so the churn the pool removes is not known to exist; the trimming can add some, because a list whose use alternates would free chunks main keeps. The fatal fence-wait change is unrelated and should be its own PR.

If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

**@⁠Marvisak** on GitHub · 2026-11-25 22:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/1525#issuecomment-7175839672) Automated triage for the maintainers, second look (a review against current `main`, with builds and tests where they could change the verdict). Closing because the gain is not shown on `main`. The measurement (new scratch allocations 1,669 to 118) was taken on an older base with fixed 256 KiB chunks plus another PR. On `main` each host list already keeps its scratch chunks across resets, and since 9cc37c5f host lists themselves are recycled with their chunks, so the churn the pool removes is not known to exist; the trimming can add some, because a list whose use alternates would free chunks `main` keeps. The fatal fence-wait change is unrelated and should be its own PR. If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

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/Marvisak--VIctory!1525
No description provided.