Skip to content

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

Closed
0xkn0wh3r3 wants to merge 1 commit into
Marvisak:mainfrom
0xkn0wh3r3:gpu/free-idle-placed-textures
Closed

0xkn0wh3r3 wants to merge 1 commit into
Marvisak:mainfrom
0xkn0wh3r3:gpu/free-idle-placed-textures

Conversation

@0xkn0wh3r3

Copy link
Copy Markdown
Contributor

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 (NVIDIA D3D12 (70564ae): stride_tests & synthetic_tests fail due to HEAP_VIEWS (2M > 1M NVIDIA limit) and Stride::Structured with rawBufferLoad #1835).
  • cargo clippy -p victory-gpu --all-targets, with and without --features diagnostics: clean.
  • Not run with a game (no game data here).

Textures the title places in its own memory and views without a resource
object get a resource and a host texture on first use (`texture_at`),
and were 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 the PC's, which ended two of its runs.

Each placed texture now notes its last use (time and frame) under the
table's lock when `texture_at` hands it out. Once a second, at present,
those that are idle and held by nothing else are let go with their host
texture and staging. One goes when:
- no view named it for 5 seconds and 4 frames (1 second and 2 frames
  while the process uses more than nine tenths of the card's memory
  budget, from DXGI's QueryVideoMemoryInfo);
- the title holds no reference, no list not yet reset names its host
  texture, and no title texture shares that host texture;
- the host GPU texture has no other COM reference: no view heap slot
  keeps it and none was retired;
- the host never wrote it (its contents are title memory's).
Its host GPU texture is retired (`crate::host::retire`), so a submission
running at that moment still has it until it has run. The next view
makes it again and uploads title memory again. Placed
textures replaced by a newer one (their memory's host texture was
replaced) are no longer kept forever either; they go the same way. Dead
entries of the memory-to-host-texture map are dropped after a sweep.

shortcut: 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.

`VICTORY_TEXTURE_SWEEP=0` keeps them all, as before. The fps companion
line counts the placed textures let go and their bytes.

Tests (no game data):
- `idle_placed_textures_go_unless_something_holds_them`: a placed texture
  in title memory stays while just used, while too few frames or too
  little time passed, while a list not yet reset names it, while another
  reference holds its host GPU texture, and while host-written; then it
  goes, leaves the table, and the next view makes it again.
- `past_the_budget_idle_textures_go_sooner`.

Idea from Zettrox/ztrx (`let_go_idle`), written for upstream's placed
texture table: ztrx makes host copies lazily (as Marvisak#1969 proposes) and lets
go of the copy only; here the whole placed resource goes.

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

@Slay326

Slay326 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

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 GPU: a title texture's host texture is made on its first use (the first-use half of #431) #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.

r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 25, 2026
Conflicts:
- resource.rs texture_at: layer 4 (with Marvisak#2221) kept placed textures in a
  plain map; Marvisak#2161's table (by_view, replaced, last use) is taken, and
  Marvisak#2221's host_texture() makes the host texture on hand-out (a draw
  reads it). Marvisak#2161's unheld and let_go read the host texture with
  Marvisak#2221's made() (they must not make one).
- host.rs: the host textures line keeps Marvisak#2221's "waiting for a first
  use" and adds Marvisak#2161's "let go while idle".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 25, 2026
A host texture's staging buffer (its uploads from title memory, the size
of the texture, in the upload heap: the PC's memory) was kept as long as
the host texture. With Marvisak#1962's placed-texture views, which heap slots
keep, that was one per texture the title ever placed and a shader read;
Marvisak#2161 cannot let those go while a slot views them.

A staging buffer is now stamped with the time and frame whenever it is
needed: a list copies from it (upload), or, for textures the heaps view
(upload_changed, every submission), only when the memory changed. Once a
second at present, one not needed for 5 seconds and 4 frames, and that
no list not yet reset holds, goes; its buffer is retired so a running
submission keeps it. The host texture keeps what was uploaded, and the
memory's tracker (or, untracked, the last hash) stays with it: while the
memory is unchanged, heap uploads make no new buffer. Once it changes,
or a list copies from it, a new one is made and the whole memory
detiled into it (forced: the buffer is new). One made but never
refreshed keeps no tracker, so the next starts anew.

VICTORY_STAGING_SWEEP=0 keeps them all, as before. The host textures
line counts staging buffers alive and let go, with their bytes.

Test (no game data): idle_staging_goes_and_its_host_texture_stays.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
r4tedx pushed a commit to r4tedx/VIctory that referenced this pull request Nov 25, 2026
…arvisak#1873, Marvisak#2221, Marvisak#2161, idle staging buffers released)

Marvisak#1873 81ebd7c: one shared scratch buffer for texture detiling.
Marvisak#2221 df15bd1 (in place of Marvisak#1969): host textures made on a title texture's
first use.
Marvisak#2161 e04431f: idle placed textures are let go.
47bb09c: idle staging buffers are let go, their host textures kept.
For A/B: VICTORY_STAGING_SWEEP=0, VICTORY_TEXTURE_SWEEP=0. Runtime only.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@0xkn0wh3r3

Copy link
Copy Markdown
Contributor Author

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.

@0xkn0wh3r3 0xkn0wh3r3 closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants