GPU: small first scratch chunk per list; log host memory against budget #1665

Open
cyudev wants to merge 2 commits from upstream-pr/1666 into main
cyudev commented 2026-11-24 20:35:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cyudev on 2026-11-24T20:35:26Z.


GPU: small first scratch chunk per list; log host memory against budget

HostList::scratch hands out upload memory in 4 MiB chunks, and a list keeps every chunk across resets. In the world the title records with hundreds of host lists, most of which need a few KiB per recording. So each list that ever touched scratch pinned a full 4 MiB upload buffer.

On an RTX 3060 Ti (8 GB) with 16 GB RAM, running r4tedx's integration/testers update 10, this went as follows:

  1. Upload buffers failed with E_OUTOFMEMORY (no upload buffer … size=4194304, confirmed with the debug layer).
  2. Either the device was removed (DXGI_ERROR_DEVICE_REMOVED), or the title's own crash handler fired with memory.load_percent: 97.

This happened a few minutes into the world. Report on #71: https://github.com/Marvisak/VIctory/issues/71#issuecomment-7142982328

Change

  • A list's first chunk is now 256 KiB. A request that does not fit gets 4 MiB chunks after it, as before. Requests over 4 MiB still get their own buffer, freed at reset.

  • On reset, a list keeps only its first chunk.

  • Every 5 s, next to the frame-rate line:

    host memory: video <used>/<budget> MB, system <used>/<budget> MB; list scratch <n> MB in <lists> lists
    

    The figures come from IDXGIAdapter3::QueryVideoMemoryInfo, so testers can see memory pressure without the debug layer.

Measured

Same machine and tree, VICTORY_SHADER_LOOP_LIMIT=32, one run each:

before after
list scratch held, a minute into the world 1,476-1,588 MB (369 lists × 4 MiB; the most chunks in any one list was 1) 130-170 MB
time in the world before the end ~2.5-3.5 min (two runs) ~6 min

A first attempt that only trimmed chunks past the first on reset changed nothing. No list ever held more than one chunk; the cost was the size of that one chunk.

Not fixed here

The run after the change still ended with a device removal. System memory the GPU uses kept climbing to ~5.6 GB of a 7.4 GB budget from other sources. Video memory sat above budget (~9.2 GB of 7.2 GB) from world entry on. Those are separate problems.

Testing

  • cargo clippy -p victory-gpu --all-targets --all-features -- -D warnings: clean.
  • cargo test -p victory-gpu: 52 passed on the RTX 3060 Ti, 55 with --features diagnostics on WARP. Two new tests cover the scratch scheme: a small first chunk; requests packed and 256-byte aligned; growth by 4 MiB chunks without overlap; a request over the small chunk taking a big first chunk; a request over 4 MiB getting its own buffer; a reset keeping and reusing only the first chunk.
  • In the title on the RTX 3060 Ti as above. The in-game runs were on integration/testers with this change applied; this PR is the same change on main.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6590895534 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1666). Originally posted by [cyudev](https://github.com/cyudev) on 2026-11-24T20:35:26Z. --- ## GPU: small first scratch chunk per list; log host memory against budget `HostList::scratch` hands out upload memory in 4 MiB chunks, and a list keeps every chunk across resets. In the world the title records with hundreds of host lists, most of which need a few KiB per recording. So each list that ever touched scratch pinned a full 4 MiB upload buffer. On an RTX 3060 Ti (8 GB) with 16 GB RAM, running r4tedx's `integration/testers` update 10, this went as follows: 1. Upload buffers failed with `E_OUTOFMEMORY` (`no upload buffer … size=4194304`, confirmed with the debug layer). 2. Either the device was removed (`DXGI_ERROR_DEVICE_REMOVED`), or the title's own crash handler fired with `memory.load_percent: 97`. This happened a few minutes into the world. Report on #71: https://github.com/Marvisak/VIctory/issues/71#issuecomment-7142982328 ### Change - A list's first chunk is now 256 KiB. A request that does not fit gets 4 MiB chunks after it, as before. Requests over 4 MiB still get their own buffer, freed at reset. - On reset, a list keeps only its first chunk. - Every 5 s, next to the frame-rate line: ``` host memory: video <used>/<budget> MB, system <used>/<budget> MB; list scratch <n> MB in <lists> lists ``` The figures come from `IDXGIAdapter3::QueryVideoMemoryInfo`, so testers can see memory pressure without the debug layer. ### Measured Same machine and tree, `VICTORY_SHADER_LOOP_LIMIT=32`, one run each: | | before | after | |---|---|---| | list scratch held, a minute into the world | 1,476-1,588 MB (369 lists × 4 MiB; the most chunks in any one list was **1**) | 130-170 MB | | time in the world before the end | ~2.5-3.5 min (two runs) | ~6 min | A first attempt that only trimmed chunks past the first on reset changed nothing. No list ever held more than one chunk; the cost was the size of that one chunk. ### Not fixed here The run after the change still ended with a device removal. System memory the GPU uses kept climbing to ~5.6 GB of a 7.4 GB budget from other sources. Video memory sat above budget (~9.2 GB of 7.2 GB) from world entry on. Those are separate problems. ### Testing - `cargo clippy -p victory-gpu --all-targets --all-features -- -D warnings`: clean. - `cargo test -p victory-gpu`: 52 passed on the RTX 3060 Ti, 55 with `--features diagnostics` on WARP. Two new tests cover the scratch scheme: a small first chunk; requests packed and 256-byte aligned; growth by 4 MiB chunks without overlap; a request over the small chunk taking a big first chunk; a request over 4 MiB getting its own buffer; a reset keeping and reusing only the first chunk. - In the title on the RTX 3060 Ti as above. The in-game runs were on `integration/testers` with this change applied; this PR is the same change on `main`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
catminou4 commented 2026-11-24 23:04:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T22:19:49Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Small first scratch chunk per list with big-chunk growth and first-chunk retention: chunk_sizes() exposes the layout, scratch_starts_small_grows_by_big_chunks_and_keeps_its_first + a_first_request_bigger_than_the_small_chunk_takes_a_big_one cover both paths. 2 tests.

<!-- greyfinch-sync:Marvisak/VIctory:review:6048310796 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1666#pullrequestreview-6048310796). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T22:19:49Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Small first scratch chunk per list with big-chunk growth and first-chunk retention: chunk_sizes() exposes the layout, scratch_starts_small_grows_by_big_chunks_and_keeps_its_first + a_first_request_bigger_than_the_small_chunk_takes_a_big_one cover both paths. 2 tests.
Marvisak commented 2026-11-25 02:06:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:34:02Z.


Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-gpu/src/host.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149695199 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1666#issuecomment-7149695199). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:34:02Z. --- <!-- victory-triage v1 head=a67255631622f04eed3d9a7d65b9422ceda66815 verdict=needs-rebase at=2026-11-25T01:34:01Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-gpu/src/host.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1666:upstream-pr/1666'
git switch 'upstream-pr/1666'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1666'
git switch 'upstream-pr/1666'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1666'
git switch 'upstream-pr/1666'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1666'
git switch 'main'
git merge --squash 'upstream-pr/1666'
git switch 'main'
git merge --ff-only 'upstream-pr/1666'
git switch 'main'
git merge 'upstream-pr/1666'
git push origin 'main'
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
Marvisak/VIctory!1665
No description provided.