Skip to content

GPU: a title texture's host texture is made on its first use (the first-use half of #431) - #1969

Open
AgneyaK wants to merge 1 commit into
Marvisak:mainfrom
AgneyaK:gpu/host-textures-on-first-use
Open

AgneyaK wants to merge 1 commit into
Marvisak:mainfrom
AgneyaK:gpu/host-textures-on-first-use

Conversation

@AgneyaK

@AgneyaK AgneyaK commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Ports the first-use half of #431 (by @AntoninMichelq) onto current main. #431 and #1526 closed each other as duplicates (see #431), so nothing open covered it. The other half of #431, freeing host objects only after running submissions, is already in main (host::retire / release_retired).

What

A title texture's host copy was made when the title created the resource. Most are never used by a list, and on small cards the unused ones spill into system RAM. With #431 on the older base, a 6 GB / 16 GB laptop's story load went from 22.7 to 18.2 GB private and from 7.2 to 3.7 GB of GPU memory in RAM. 0xKaji measured ~7.85 → ~5.39 GiB of host textures on an 8 GB card with #1526.

  • Resource.host is a OnceLock. Resource::host makes the texture on first use, from the creation state and clear value kept with the resource (made_with), then registers it in TEXTURES_AT. Every host_resource / host_copy / host_transition is a first use: views, targets, copies, barriers.
  • Paths that must not create one read host_made instead: current, alias_source (it holds TEXTURES_AT), and Drop.
  • texture_at (placed views) still makes its texture at once, as before.
  • Lock order stays one way: the placed-texture map, then MEMORY (in shared_texture), then TEXTURES_AT. Nothing takes them the other way round.

Tested

Windows 11 26300, Rust 1.98.1, on main 940d32f:

Not tested yet: the title on this exact tree. On NVIDIA, main stops at boot without #1763 (#1754), so a title run needs that too. I'll post the numbers here once I have them.

AI use: Claude Code (Claude Opus 5.5) ported the change (from a local port made earlier in the same setup), wrote the test and ran the checks; the results are from the runs described.

🤖 Generated with Claude Code

Ports the first-use half of Marvisak#431 (AntoninMichelq) onto current main; the
other half (freeing host objects only after running submissions) is
already in main.

A title texture's host copy was made when the title created the
resource. Most are never used by a list, and on small cards the rest
spills into system RAM: with Marvisak#431 on the older base, a 6 GB / 16 GB
laptop's story load went from 22.7 to 18.2 GB private and from 7.2 to
3.7 GB of GPU memory in RAM.

`Resource::host` now makes it on first use (a view, a target, a copy, a
barrier: every `host_resource` / `host_copy` / `host_transition`), from
the creation state and clear value kept with the resource, and registers
the texture by memory then. Paths that must not create one (`current`,
`alias_source` while it holds `TEXTURES_AT`, `Drop`) read `host_made`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AgneyaK

AgneyaK commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

In-title result, and it's weaker than I hoped, so here it is plainly.

Setup: RTX 3050 6 GB Laptop, 16 GB RAM. main 940d32f + #1763 (NVIDIA stops at boot without it, #1754), with and without this PR. Diag build, a local NVIDIA-adapter patch (not in any PR), scripted Enter into the story. An outside guard killed the game when free RAM fell under 800 MB (this laptop blue-screened in the NVIDIA driver at ~24 GB private earlier tonight).

profile build stopped at host textures (MB) used by lists
Series X base 72 s, frame 1,024 1,556 (4,887 MB) 247 MB
Series X this PR 68 s, frame 1,024 1,516 (4,826 MB) 239 MB
Series S base 70 s, frame 1,331 1,559 (2,660 MB) 242 MB
Series S this PR 62 s, frame 1,028 1,542 (2,545 MB) 220 MB

So at boot it saves ~1–4%, not the 20% that #431 gave on the old base. The reason: descriptor::sync_heaps now mirrors every slot of the title's view heap before each submission, and making a slot's view (descriptor/host.rs make, View::Shader → host_copy) is a first use. So every texture that has a descriptor is made at once, used or not. By frame 256 this PR already has 1,515 host textures.

What it may still save: textures made after the heap is mirrored and never put in a slot. An earlier local run of the same change on 70564ae (another session on this laptop, not repeated tonight) had 4,852 instead of 8,777 MB of host textures at the same point of the story load. I could not get that far safely tonight: on both profiles free RAM drops by ~3 GB in a few seconds as the story starts, and the guard stopped every run there.

To get #431's old effect on current main, the mirror would have to stop making textures: a slot's view made only when a list or a heap-indexing draw can reach it. That's a bigger change than this PR. I'm happy to close this one if you'd rather not take it on its own.

AI use: Claude Code (Claude Opus 5.5) ran these builds and wrote this; the results are from the runs described.

@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.

Title texture's host texture made on first use: lazy texture creation — memory win; check first-use stall.

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026

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/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

On an RTX 3070, draw::tests::a_texture_written_in_one_format_reads_in_another_through_a_placed_view fails with this PR alone on 940d32f (round 0: one host texture); it passes on main.

AI-assisted.

@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown

Second RTX 3070 confirming Slay326's failure. 001c153 (as-is, on main 940d32f), driver 616.56, Windows 11, debug:

tree draw::tests::a_texture_written_in_one_format_reads_in_another_through_a_placed_view --exact, 3 runs cargo test -p victory-gpu --locked
main 940d32f 3 of 3 pass 141 passed, 2 failed
this PR 3 of 3 fail at draw.rs:2185, round 0: one host texture (left false, right true) 141 passed, 3 failed

The 2 failures on main are the same on both trees (dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views). The extra one with the PR is this test. No SKIPPED lines.

AI-assisted (Claude Code). Synthetic tests only.

juanfariasdev pushed a commit to juanfariasdev/VIctory that referenced this pull request Nov 25, 2026
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.
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 25, 2026
…exture's first use)

Taken in place of Marvisak#1969: with Marvisak#1969 a placed view used first made the
memory's host texture with its own (fewer) uses, and the title texture
the GPU writes then got another, so the placed view did not see the
GPU's writes (draw test a_texture_written_in_one_format_reads_in_another
_through_a_placed_view failed on WARP). Marvisak#2221's `lead` makes it as the
title texture of the memory with the most uses.

Conflicts in resource.rs:
- hand_out_resource: kept layer 4's read-only buffer registration
  (Marvisak#2120); textures are counted as waiting and listed by memory at
  creation (Marvisak#2221).
- alias_source: kept layer 4's order (cheap tests first, layouts last)
  with Marvisak#2221's made()/host_texture() in place of the host field.

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

5 participants