GPU: a texture's levels on demand keep their tiles while anything names the texture (#776) #795

Open
LeonardoS11 wants to merge 2 commits from upstream-pr/795 into main
LeonardoS11 commented 2026-11-25 08:07:38 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by LeonardoS11 on 2026-11-25T08:07:38Z.


Fixes the device loss of #776.

The defect

  • With VICTORY_LEVELS_ON_DEMAND=1 a texture's memory is tiles in heaps of the pool (tiles.rs), not memory of the resource.
  • A list recorded or in the air keeps the ID3D12Resource it names (HostList::keep), not the host copy. For a committed texture that reference holds the memory. For a reserved one it holds nothing.
  • So when the host copy is let go — by the sweep, or by the title releasing the texture — Tiled's drop gives the tiles back at once. They are handed to other textures, and a heap whose tiles are all free goes back to the card, while a list still to run reads through the old texture's mappings.

This is still so on 9376fd6: the fixes that came with #747 are others.

The change

A host copy let go hands its texture and tiles to a list (tiles::let_go). The tiles go back to the pool when nothing but that list names the texture (tiles::give_back_let_go, at every sweep), and at once if nothing does already. 86 lines in tiles.rs, resource.rs, host.rs.

Tested

Windows 11, RTX 3080 Ti 12 GB, 64 GB RAM, diag build with diagnostics.

  • The levels-on-demand test with a new step 8 (a_texture_kept_by_a_list_keeps_its_tiles): a texture is given tiles, a clone of the resource is kept as a list would, the copy is let go; the tiles wait while the clone lives, also across a give_back_let_go, and go back when it is dropped; a texture nothing else names gives them back at once. Passes on the software adapter with the debug layer and on the card (VICTORY_TILES_TEST_CARD=1: "all steps passed ON THE CARD").
  • In game, one checkpoint in the prologue, 300 s a run, VICTORY_LEVELS_ON_DEMAND=1 VICTORY_CARD_ROOM_FOR_BUFFERS=1:
runs device removed heap given back to the card during the run
8dd30ab 3 1 (about 10 s into the world, 6.4 s after a sweep let go 610 copies) in the run that lost the device only
8dd30ab + this change 4 0 in 2 of the 4

Frame times with the change: 292, 274, 279, 272 ms (269 without it), so it costs nothing I can measure.

Caveats. The game runs were made with this change on 8dd30ab, before it was rebased onto 9376fd6 and before step 8 was added; the rebase had one conflict, in a doc comment. On the rebased commit I ran the test above, not the game yet. And 1 loss in 3 against 0 in 4 is few launches: two of the four had the condition of the loss (a heap given back) and went on, which is the stronger sign.

No title data in this PR.

🤖 Generated with Claude Code

<!-- greyfinch-sync:fxceless/victory-fork:issue:5487551708 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/795). Originally posted by [LeonardoS11](https://github.com/LeonardoS11) on 2026-11-25T08:07:38Z. --- Fixes the device loss of #776. ## The defect - With `VICTORY_LEVELS_ON_DEMAND=1` a texture's memory is tiles in heaps of the pool (`tiles.rs`), not memory of the resource. - A list recorded or in the air keeps the `ID3D12Resource` it names (`HostList::keep`), not the host copy. For a committed texture that reference holds the memory. For a reserved one it holds nothing. - So when the host copy is let go — by the sweep, or by the title releasing the texture — `Tiled`'s drop gives the tiles back at once. They are handed to other textures, and a heap whose tiles are all free goes back to the card, while a list still to run reads through the old texture's mappings. This is still so on 9376fd6: the fixes that came with #747 are others. ## The change A host copy let go hands its texture and tiles to a list (`tiles::let_go`). The tiles go back to the pool when nothing but that list names the texture (`tiles::give_back_let_go`, at every sweep), and at once if nothing does already. 86 lines in `tiles.rs`, `resource.rs`, `host.rs`. ## Tested Windows 11, RTX 3080 Ti 12 GB, 64 GB RAM, `diag` build with `diagnostics`. - The levels-on-demand test with a new step 8 (`a_texture_kept_by_a_list_keeps_its_tiles`): a texture is given tiles, a clone of the resource is kept as a list would, the copy is let go; the tiles wait while the clone lives, also across a `give_back_let_go`, and go back when it is dropped; a texture nothing else names gives them back at once. Passes on the software adapter with the debug layer and **on the card** (`VICTORY_TILES_TEST_CARD=1`: "all steps passed ON THE CARD"). - In game, one checkpoint in the prologue, 300 s a run, `VICTORY_LEVELS_ON_DEMAND=1 VICTORY_CARD_ROOM_FOR_BUFFERS=1`: | | runs | device removed | heap given back to the card during the run | |---|---|---|---| | 8dd30ab | 3 | 1 (about 10 s into the world, 6.4 s after a sweep let go 610 copies) | in the run that lost the device only | | 8dd30ab + this change | 4 | 0 | in 2 of the 4 | Frame times with the change: 292, 274, 279, 272 ms (269 without it), so it costs nothing I can measure. **Caveats.** The game runs were made with this change on 8dd30ab, before it was rebased onto 9376fd6 and before step 8 was added; the rebase had one conflict, in a doc comment. On the rebased commit I ran the test above, not the game yet. And 1 loss in 3 against 0 in 4 is few launches: two of the four had the condition of the loss (a heap given back) and went on, which is the stronger sign. No title data in this PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
LeonardoS11 commented 2026-11-25 09:08:51 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by LeonardoS11 on 2026-11-25T09:02:59Z.


Game runs of the rebased commit (32772d9 on 9376fd6), same scene and card, VICTORY_LEVELS_ON_DEMAND=1, 300 s each: 2 runs, no device loss, 326 and 322 ms a frame; the second ended with "the pool's heaps 576 MB (1 given back to the card so far)", so it went through the condition of the loss. That closes the first caveat above. (Runs by me; written with Claude Code.)

<!-- greyfinch-sync:fxceless/victory-fork:comment:7157805466 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/795#issuecomment-7157805466). Originally posted by [LeonardoS11](https://github.com/LeonardoS11) on 2026-11-25T09:02:59Z. --- Game runs of the rebased commit (32772d9 on 9376fd6), same scene and card, `VICTORY_LEVELS_ON_DEMAND=1`, 300 s each: 2 runs, no device loss, 326 and 322 ms a frame; the second ended with "the pool's heaps 576 MB (1 given back to the card so far)", so it went through the condition of the loss. That closes the first caveat above. (Runs by me; written with Claude Code.)
MamaLeVrai commented 2026-11-25 11:10:36 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by MamaLeVrai on 2026-11-25T10:20:24Z.


Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present. I merged this PR's head 32772d9 into main 9376fd6 in a throwaway tree (no conflict). cargo clippy --workspace --all-targets --locked -- -D warnings fails with exactly the errors main itself has on this machine (placed_filler_twins never used, depth_written never read, in victory-gpu); with --all-features it fails with the same number of errors as main (4). This PR adds none and removes none. cargo test --workspace --locked: 540 passed, 0 failed, 10 ignored, two runs (main alone: 540 passed, 0 failed, 10 ignored). The title was not run, so this says nothing about in-game effect. No game data.

AI-assisted (Claude Code); no game data.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7159559260 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/795#issuecomment-7159559260). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-25T10:20:24Z. --- Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present. I merged this PR's head `32772d9` into `main` `9376fd6` in a throwaway tree (no conflict). `cargo clippy --workspace --all-targets --locked -- -D warnings` fails with exactly the errors `main` itself has on this machine (`placed_filler_twins` never used, `depth_written` never read, in `victory-gpu`); with `--all-features` it fails with the same number of errors as `main` (4). This PR adds none and removes none. `cargo test --workspace --locked`: 540 passed, 0 failed, 10 ignored, two runs (`main` alone: 540 passed, 0 failed, 10 ignored). The title was not run, so this says nothing about in-game effect. No game data. AI-assisted (Claude Code); no game data.
LeonardoS11 commented 2026-11-27 03:59:08 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by LeonardoS11 on 2026-11-27T03:59:08Z.


Added one commit (6d2265a): a let-go texture's tiles now wait VICTORY_TILES_HOLD_FRAMES (default 3) frames after nothing names it, before they go back.

Why: in one run the device was lost about 0.7 s after a sweep that let go of 144 copies at once; the tiles were handed back while a frame still in flight could read them. Holding them a few frames removes that window. cargo check passes.

AI-assisted (Claude in Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:fxceless/victory-fork:comment:7209425919 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/795#issuecomment-7209425919). Originally posted by [LeonardoS11](https://github.com/LeonardoS11) on 2026-11-27T03:59:08Z. --- Added one commit (6d2265a): a let-go texture's tiles now wait `VICTORY_TILES_HOLD_FRAMES` (default 3) frames after nothing names it, before they go back. Why: in one run the device was lost about 0.7 s after a sweep that let go of 144 copies at once; the tiles were handed back while a frame still in flight could read them. Holding them a few frames removes that window. `cargo check` passes. *AI-assisted (Claude in Claude Code).* 🤖 Generated with [Claude Code](https://claude.com/claude-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/795:upstream-pr/795'
git switch 'upstream-pr/795'

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