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

Open
github-bot wants to merge 1 commit from github-bot/gh-795 into main AGit
Owner

@⁠LeonardoS11 on GitHub · 2026-11-25 08:07 UTC · original
LeonardoS11:fix/levels-heap-release → main · +86 −0 · 3 files · 1 commits · open

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

**@⁠LeonardoS11** on GitHub · 2026-11-25 08:07 UTC · [original](https://github.com/fxceless/victory-fork/pull/795) `LeonardoS11:fix/levels-heap-release` → `main` · +86 −0 · 3 files · 1 commits · open 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)
The tiles of a texture made level by level (VICTORY_LEVELS_ON_DEMAND=1) are
in heaps of ours, not in the texture. A list recorded or in the air keeps
the texture it names (`HostList::keep`), not its host copy, so the host
copy could be let go (the sweep, the title's release) while a list still to
run read through the texture's mappings: the tiles went back to the pool,
were given to other textures, and a heap with all of its tiles free went
back to the card.

On an RTX 3080 Ti, Series X, levels on demand with room for buffers: the
device was removed (0x887A0006) in 1 run of 3, about ten seconds into the
world, 6.4 s after a sweep let go 610 host copies of textures, with one
heap given back to the card; in the runs that went on none was. With this
change: 0 removals in 4 runs (292, 274, 279 and 272 ms a frame), two of
them with a heap given back.

A host copy let go now hands its texture and tiles to a list
(`tiles::let_go`); the tiles go back when nothing but that list names the
texture (`tiles::give_back_let_go`, at every sweep), at once if nothing
does already. Step 8 of the levels-on-demand test lets go of a texture a
list still keeps and checks that its tiles wait until the list is reset.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:51:19 +00:00
Author
Owner

@⁠LeonardoS11 on GitHub · 2026-11-25 09:02 UTC · original

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

**@⁠LeonardoS11** on GitHub · 2026-11-25 09:02 UTC · [original](https://github.com/fxceless/victory-fork/pull/795#issuecomment-7157805466) 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.)
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-25 10:20 UTC · original

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.

**@⁠MamaLeVrai** on GitHub · 2026-11-25 10:20 UTC · [original](https://github.com/fxceless/victory-fork/pull/795#issuecomment-7159559260) 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.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/tiles.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/795/head:github-bot/gh-795'
git switch 'github-bot/gh-795'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-795'
git switch 'github-bot/gh-795'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-795'
git switch 'github-bot/gh-795'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-795'
git switch 'main'
git merge --squash 'github-bot/gh-795'
git switch 'main'
git merge --ff-only 'github-bot/gh-795'
git switch 'main'
git merge 'github-bot/gh-795'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.