GPU: release idle placed textures, sooner past 90% of the VRAM budget #2159

Closed
0xkn0wh3r3 wants to merge 1 commit from upstream-pr/2161 into main
0xkn0wh3r3 commented 2026-11-25 06:41:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T06:41:19Z.


Problem

Textures the title places in its own memory get a resource and a host texture the first time a view reads one (texture_at), and are never released: one host texture per address and description ever viewed. On Zettrox/ztrx that was 18,639 of them, 2.5 GB, after nine minutes of Grand Theft Auto VI. Past the card's memory budget the system moved video memory into system RAM, which ended two of its runs.

Fix

  • texture_at notes each placed texture's last use (time and frame) under the table's lock, so a texture just handed out is never idle.
  • Once a second, at present, a placed texture is released with its host texture and staging when:
    • no view used it for 5 s and 4 frames (1 s and 2 frames while the process uses more than 90% of the card's memory budget, from QueryVideoMemoryInfo);
    • the title holds no reference, no list not yet reset names its host texture, and no title texture shares it;
    • no view heap slot keeps its host GPU texture (COM count of 1);
    • the host never wrote it (its contents are title memory's).
  • The host GPU texture is retired, so a submission running at that moment keeps it until it has run. The next view makes the texture again and uploads title memory.
  • Placed textures that a newer one replaced (their memory's host texture was replaced) are released the same way instead of being kept forever.
  • VICTORY_TEXTURE_SWEEP=0 keeps everything, as before. The host textures log line counts the placed textures released and their bytes.

Limit: a thread handed a resource by texture_at is protected by the idle time alone until its use makes a list or slot hold it. Every caller uses it at once, within the title's call.

Idea from Zettrox/ztrx (let_go_idle). ztrx makes host copies lazily (as #1969 proposes) and releases only the copy; here the whole placed resource goes, which needs no lazy host textures.

Testing

  • New (no game data): a placed texture in title memory stays while just used, while too little time or too few frames passed, while a list not yet reset names it, while another reference holds its host GPU texture, and while host-written; then it is released, leaves the table, and the next view makes it again. Also: past the budget, idle textures go sooner.
  • cargo test -p victory-gpu --lib on an RTX 5070 Ti: all pass except the two tests that already fail on main from the NVIDIA heap cap (#1835).
  • cargo clippy -p victory-gpu --all-targets, with and without --features diagnostics: clean.
  • Not run with a game (no game data here).
<!-- greyfinch-sync:Marvisak/VIctory:issue:6598833846 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2161). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-25T06:41:19Z. --- ### Problem Textures the title places in its own memory get a resource and a host texture the first time a view reads one (`texture_at`), and are never released: one host texture per address and description ever viewed. On Zettrox/ztrx that was 18,639 of them, 2.5 GB, after nine minutes of Grand Theft Auto VI. Past the card's memory budget the system moved video memory into system RAM, which ended two of its runs. ### Fix - `texture_at` notes each placed texture's last use (time and frame) under the table's lock, so a texture just handed out is never idle. - Once a second, at present, a placed texture is released with its host texture and staging when: - no view used it for 5 s and 4 frames (1 s and 2 frames while the process uses more than 90% of the card's memory budget, from `QueryVideoMemoryInfo`); - the title holds no reference, no list not yet reset names its host texture, and no title texture shares it; - no view heap slot keeps its host GPU texture (COM count of 1); - the host never wrote it (its contents are title memory's). - The host GPU texture is retired, so a submission running at that moment keeps it until it has run. The next view makes the texture again and uploads title memory. - Placed textures that a newer one replaced (their memory's host texture was replaced) are released the same way instead of being kept forever. - `VICTORY_TEXTURE_SWEEP=0` keeps everything, as before. The host textures log line counts the placed textures released and their bytes. Limit: a thread handed a resource by `texture_at` is protected by the idle time alone until its use makes a list or slot hold it. Every caller uses it at once, within the title's call. Idea from Zettrox/ztrx (`let_go_idle`). ztrx makes host copies lazily (as #1969 proposes) and releases only the copy; here the whole placed resource goes, which needs no lazy host textures. ### Testing - New (no game data): a placed texture in title memory stays while just used, while too little time or too few frames passed, while a list not yet reset names it, while another reference holds its host GPU texture, and while host-written; then it is released, leaves the table, and the next view makes it again. Also: past the budget, idle textures go sooner. - `cargo test -p victory-gpu --lib` on an RTX 5070 Ti: all pass except the two tests that already fail on `main` from the NVIDIA heap cap (#1835). - `cargo clippy -p victory-gpu --all-targets`, with and without `--features diagnostics`: clean. - Not run with a game (no game data here).
catminou4 commented 2026-11-25 08:06:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T07:17:29Z.

Review: COMMENTED


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

Idle placed textures released sooner past 90% VRAM — memory-pressure eviction tuning.

<!-- greyfinch-sync:Marvisak/VIctory:review:6053349779 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2161#pullrequestreview-6053349779). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T07:17:29Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Idle placed textures released sooner past 90% VRAM — memory-pressure eviction tuning.
Marvisak commented 2026-11-25 12:03:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T11:26:23Z.


Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-gpu/src/host.rs, crates/victory-gpu/src/object.rs, crates/victory-gpu/src/queue.rs, crates/victory-gpu/src/resource.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (needs-work) was for an older state of main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7161048577 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2161#issuecomment-7161048577). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T11:26:23Z. --- <!-- victory-triage v1 head=e04431f728c7b9a8bab52c7f553f70153f4a9a93 verdict=needs-rebase at=2026-11-25T16:06:30Z --> Automated triage for the maintainers. This pull request no longer merges cleanly into `main` (conflicts in `crates/victory-gpu/src/host.rs`, `crates/victory-gpu/src/object.rs`, `crates/victory-gpu/src/queue.rs`, `crates/victory-gpu/src/resource.rs`). It will be reviewed once it is rebased onto the current `main`. The earlier verdict (needs-work) was for an older state of `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Slay326 commented 2026-11-25 15:04:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Slay326 on 2026-11-25T14:13:07Z.


Hardware test on an RTX 3070 (8 GB), merged with #1962, #1969, #2129, #2180 and #1873 on a local test branch; 480 s into the world of Grand Theft Auto VI.

  • Without this PR: placed textures reached 7,650 / 4.2 GB in the first scene and 10,269 / 5.0 GB after the next scene change, and never went down.
  • With it: 4,150 / 2.9 GB, steady across the scene change; 6,577 placed textures (4,961 MB) were let go in the run. Dedicated GPU memory in use fell from 12.2 GB to 9.2 GB (budget 7.0 GB).
  • Merge note: on top of #1969 the sweep has to read host_made() instead of the host field (two places, unheld and let_go); texture_at keeps host().
  • Not checked: whether a texture let go and made again shows a frame late. In one capture the character's hair had a dark stripe; I could not tie that to the sweep.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7164937717 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2161#issuecomment-7164937717). Originally posted by [Slay326](https://github.com/Slay326) on 2026-11-25T14:13:07Z. --- Hardware test on an RTX 3070 (8 GB), merged with #1962, #1969, #2129, #2180 and #1873 on a local test branch; 480 s into the world of Grand Theft Auto VI. - **Without this PR:** placed textures reached 7,650 / 4.2 GB in the first scene and 10,269 / 5.0 GB after the next scene change, and never went down. - **With it:** 4,150 / 2.9 GB, steady across the scene change; 6,577 placed textures (4,961 MB) were let go in the run. Dedicated GPU memory in use fell from 12.2 GB to 9.2 GB (budget 7.0 GB). - **Merge note:** on top of #1969 the sweep has to read `host_made()` instead of the `host` field (two places, `unheld` and `let_go`); `texture_at` keeps `host()`. - **Not checked:** whether a texture let go and made again shows a frame late. In one capture the character's hair had a dark stripe; I could not tie that to the sweep. AI-assisted.
upstream-sync closed this pull request 2026-11-25 19:05:04 +00:00
0xkn0wh3r3 commented 2026-11-25 19:06:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T18:51:10Z.


Closing: upstream 69d1e8e covers this. Host textures fed from title memory are given up after 120 s and 300 presented frames unused, and past 90% of the card's budget the least recently used go until usage is back under 85%. Placed textures' host textures are included, and their heap slots are nulled and remade when read. Upstream measured that idle times as short as this PR's gave up textures that were read again within a minute. @Slay326, thanks for the 3070 run. It would be worth repeating it on current main.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7171491734 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2161#issuecomment-7171491734). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-25T18:51:10Z. --- Closing: upstream 69d1e8e covers this. Host textures fed from title memory are given up after 120 s and 300 presented frames unused, and past 90% of the card's budget the least recently used go until usage is back under 85%. Placed textures' host textures are included, and their heap slots are nulled and remade when read. Upstream measured that idle times as short as this PR's gave up textures that were read again within a minute. @Slay326, thanks for the 3070 run. It would be worth repeating it on current `main`.

Pull request closed

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!2159
No description provided.