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

Open
AgneyaK wants to merge 1 commit from upstream-pr/1969 into main
AgneyaK commented 2026-11-25 01:56:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AgneyaK on 2026-11-25T01:56:14Z.


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:

  • New test a_texture_gets_its_host_copy_on_first_use: no host texture at creation, made on the first host_resource, made once, registered by memory once made.
  • cargo test -p victory-gpu --locked: 140 passed, 3 failed, the same 3 that fail on main here (the Intel Iris Xe the tests run on: the 2 heap-cap tests of #1744, and the castable test that #1765 fixes).
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean. cargo xtask policy: ok.

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

<!-- greyfinch-sync:Marvisak/VIctory:issue:6595358256 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1969). Originally posted by [AgneyaK](https://github.com/AgneyaK) on 2026-11-25T01:56:14Z. --- Ports the **first-use half of #431** (by @AntoninMichelq) onto current `main`. #431 and #1526 closed each other as duplicates (see [#431](https://github.com/Marvisak/VIctory/pull/431#issuecomment-7149904933)), 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`: - New test `a_texture_gets_its_host_copy_on_first_use`: no host texture at creation, made on the first `host_resource`, made once, registered by memory once made. - `cargo test -p victory-gpu --locked`: 140 passed, 3 failed, the same 3 that fail on `main` here (the Intel Iris Xe the tests run on: the 2 heap-cap tests of #1744, and the castable test that #1765 fixes). - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean. `cargo xtask policy`: ok. 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](https://claude.com/claude-code)
catminou4 commented 2026-11-25 03:03:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T02:10:33Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6050614002 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1969#pullrequestreview-6050614002). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T02:10:33Z. **Review:** COMMENTED --- 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.
AgneyaK commented 2026-11-25 03:03:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AgneyaK on 2026-11-25T02:06:34Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7150326907 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1969#issuecomment-7150326907). Originally posted by [AgneyaK](https://github.com/AgneyaK) on 2026-11-25T02:06:34Z. --- 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.
Marvisak commented 2026-11-25 09:06:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T08:24:53Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7156995721 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1969#issuecomment-7156995721). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T08:24:53Z. --- <!-- victory-triage v1 head=001c15336ac7f2c8be5f3869c8a5c65fa43fae9b verdict=needs-rebase at=2026-11-25T16:17:30Z --> 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](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:09Z.


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.

  • Cause: the test makes the placed view's texture before the resource object's first use. The placed texture is made at once without the unordered-access use, so the object's later first use cannot share it and replaces it: two host textures where main has one.
  • In the title the same order would split a GPU-written texture from its placed view (the R32_UINT writer and its R9G9B9E5 view); the alias copy bridges only same-start cases.
  • In a 480 s world run (merged with #1962, #2161, #2129, #2180, #1873) the image looked the same as without the PR. Host textures were 7.4 GB there against 10.35 GB without #1969 and #2161; I did not run the two apart.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7164938398 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1969#issuecomment-7164938398). Originally posted by [Slay326](https://github.com/Slay326) on 2026-11-25T14:13:09Z. --- 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`. - **Cause:** the test makes the placed view's texture before the resource object's first use. The placed texture is made at once without the unordered-access use, so the object's later first use cannot share it and replaces it: two host textures where `main` has one. - **In the title** the same order would split a GPU-written texture from its placed view (the R32_UINT writer and its R9G9B9E5 view); the alias copy bridges only same-start cases. - **In a 480 s world run** (merged with #1962, #2161, #2129, #2180, #1873) the image looked the same as without the PR. Host textures were 7.4 GB there against 10.35 GB without #1969 and #2161; I did not run the two apart. AI-assisted.
upipibi commented 2026-11-25 15:04:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-25T14:39:51Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7165621964 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1969#issuecomment-7165621964). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-25T14:39:51Z. --- 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.
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/1969:upstream-pr/1969'
git switch 'upstream-pr/1969'

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/1969'
git switch 'upstream-pr/1969'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1969'
git switch 'upstream-pr/1969'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1969'
git switch 'main'
git merge --squash 'upstream-pr/1969'
git switch 'main'
git merge --ff-only 'upstream-pr/1969'
git switch 'main'
git merge 'upstream-pr/1969'
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!1967
No description provided.