GPU: let go of a placed texture's host copy as soon as its memory is … #550

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

@⁠pug205gti6 on GitHub · 2026-11-25 02:07 UTC · original
pug205gti6:pr/432-shaders-dxil-p10 → main · +126 −2 · 2 files · 1 commits · open

…unmapped

A placed texture's host copy waited for the idle sweep: five seconds and four frames of nothing asking for it (resource::let_go_idle). Nothing is asking while the title streams its next set of textures in, so a texture the title had already finished with kept its card memory through the whole stream -- and the run paged. Unmapping the title memory is how the title says it is done with a texture; that is the moment to act on, and it was already a call (watch::title_memory_remapped) with the range in hand.

WHAT GOES, AND WHEN.
resource::evict_placed_in(base, len) walks the placed textures the title fills whose bytes meet [base, base + len), and lets a host copy go when only its title resource holds it: Arc::strong_count(host) == 1 and host::references(&host.texture) == 1, the same two conditions let_go_idle requires, taken under the same made lock and followed by the same texture::unstage, host::retire, host.gone marking and KINDS[2]/KINDS[3] counters. title_memory_remapped calls it after the views and placements there are forgotten. Nothing waits on a fence, so no submission is held up, and no list or slot that still names the copy is touched: it stays, as before, until they let it go. The next use makes the host copy anew from the memory the runtime has just mapped, which is exactly what the idle sweep relied on.

Overlap is answered by a new resource::ranges_overlap(a_start, a_len, b_start, b_len): half-open, zero-length ranges share nothing, and the ends saturate, so a range cannot wrap into a false hit. It is the one piece of this that can be tested without a card, so it is:
ranges_overlap_handles_boundaries_zero_len_and_overflow pins adjacency in both orders, a single shared byte on either side, containment both ways, empty ranges, and the top of the address space. Mutation-probed: < to <= in the first comparison makes the adjacent case report an overlap and the test fails on it.

VICTORY_TEXTURE_SWEEP=0 still lets nothing go. The switch moved into one sweeping() so the two paths cannot disagree about it. The path is traced through host::trail like the idle sweep's, naming how many went and their KiB.

SCOPE.
resource.rs and the call in watch.rs, which is where title_memory_remapped is defined (lib.rs re-exports it). No test drives evict_placed_in itself: it needs the host device, and the two conditions it acts on are the ones let_go_idle already had. What is new and testable is the range test.

**@⁠pug205gti6** on GitHub · 2026-11-25 02:07 UTC · [original](https://github.com/fxceless/victory-fork/pull/550) `pug205gti6:pr/432-shaders-dxil-p10` → `main` · +126 −2 · 2 files · 1 commits · open …unmapped A placed texture's host copy waited for the idle sweep: five seconds and four frames of nothing asking for it (`resource::let_go_idle`). Nothing is asking while the title streams its next set of textures in, so a texture the title had already finished with kept its card memory through the whole stream -- and the run paged. Unmapping the title memory is how the title says it is done with a texture; that is the moment to act on, and it was already a call (`watch::title_memory_remapped`) with the range in hand. WHAT GOES, AND WHEN. `resource::evict_placed_in(base, len)` walks the placed textures the title fills whose bytes meet `[base, base + len)`, and lets a host copy go when only its title resource holds it: `Arc::strong_count(host) == 1` and `host::references(&host.texture) == 1`, the same two conditions `let_go_idle` requires, taken under the same `made` lock and followed by the same `texture::unstage`, `host::retire`, `host.gone` marking and `KINDS[2]`/`KINDS[3]` counters. `title_memory_remapped` calls it after the views and placements there are forgotten. Nothing waits on a fence, so no submission is held up, and no list or slot that still names the copy is touched: it stays, as before, until they let it go. The next use makes the host copy anew from the memory the runtime has just mapped, which is exactly what the idle sweep relied on. Overlap is answered by a new `resource::ranges_overlap(a_start, a_len, b_start, b_len)`: half-open, zero-length ranges share nothing, and the ends saturate, so a range cannot wrap into a false hit. It is the one piece of this that can be tested without a card, so it is: `ranges_overlap_handles_boundaries_zero_len_and_overflow` pins adjacency in both orders, a single shared byte on either side, containment both ways, empty ranges, and the top of the address space. Mutation-probed: `<` to `<=` in the first comparison makes the adjacent case report an overlap and the test fails on it. `VICTORY_TEXTURE_SWEEP=0` still lets nothing go. The switch moved into one `sweeping()` so the two paths cannot disagree about it. The path is traced through `host::trail` like the idle sweep's, naming how many went and their KiB. SCOPE. resource.rs and the call in watch.rs, which is where `title_memory_remapped` is defined (`lib.rs` re-exports it). No test drives `evict_placed_in` itself: it needs the host device, and the two conditions it acts on are the ones `let_go_idle` already had. What is new and testable is the range test.
A placed texture's host copy waited for the idle sweep: five seconds and four
frames of nothing asking for it (`resource::let_go_idle`). Nothing is asking
while the title streams its next set of textures in, so a texture the title
had already finished with kept its card memory through the whole stream -- and
the run paged. Unmapping the title memory is how the title says it is done
with a texture; that is the moment to act on, and it was already a call
(`watch::title_memory_remapped`) with the range in hand.

WHAT GOES, AND WHEN.
`resource::evict_placed_in(base, len)` walks the placed textures the title
fills whose bytes meet `[base, base + len)`, and lets a host copy go when only
its title resource holds it: `Arc::strong_count(host) == 1` and
`host::references(&host.texture) == 1`, the same two conditions `let_go_idle`
requires, taken under the same `made` lock and followed by the same
`texture::unstage`, `host::retire`, `host.gone` marking and `KINDS[2]`/`KINDS[3]`
counters. `title_memory_remapped` calls it after the views and placements there
are forgotten. Nothing waits on a fence, so no submission is held up, and no
list or slot that still names the copy is touched: it stays, as before, until
they let it go. The next use makes the host copy anew from the memory the
runtime has just mapped, which is exactly what the idle sweep relied on.

Overlap is answered by a new `resource::ranges_overlap(a_start, a_len, b_start,
b_len)`: half-open, zero-length ranges share nothing, and the ends saturate, so
a range cannot wrap into a false hit. It is the one piece of this that can be
tested without a card, so it is:
`ranges_overlap_handles_boundaries_zero_len_and_overflow` pins adjacency in
both orders, a single shared byte on either side, containment both ways, empty
ranges, and the top of the address space. Mutation-probed: `<` to `<=` in the
first comparison makes the adjacent case report an overlap and the test fails
on it.

`VICTORY_TEXTURE_SWEEP=0` still lets nothing go. The switch moved into one
`sweeping()` so the two paths cannot disagree about it. The path is traced
through `host::trail` like the idle sweep's, naming how many went and their
KiB.

SCOPE.
resource.rs and the call in watch.rs, which is where `title_memory_remapped`
is defined (`lib.rs` re-exports it). No test drives `evict_placed_in` itself:
it needs the host device, and the two conditions it acts on are the ones
`let_go_idle` already had. What is new and testable is the range test.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:46:08 +00:00
Author
Owner

@⁠Revens2 on GitHub · 2026-11-25 07:38 UTC · original

Duplicate of #432: @⁠HailLucifer666 opened this patch 80 minutes earlier, and gh pr diff returns the same bytes for both (+126/-2 on 2 file(s), same title).

Both PRs are CONFLICTING, so this copy does not resolve the conflict it was probably made for.

Please continue in #432 so the review history and any test data stay in one place.
Thanks.

**@⁠Revens2** on GitHub · 2026-11-25 07:38 UTC · [original](https://github.com/fxceless/victory-fork/pull/550#issuecomment-7156080629) Duplicate of #432: @⁠HailLucifer666 opened this patch 80 minutes earlier, and `gh pr diff` returns the same bytes for both (+126/-2 on 2 file(s), same title). Both PRs are CONFLICTING, so this copy does not resolve the conflict it was probably made for. Please continue in #432 so the review history and any test data stay in one place. Thanks.
Author
Owner

@⁠Chipsraine on GitHub · 2026-11-25 18:04 UTC · original

Tested e109ad1 (same patch as #432) on top of 465b94f: on a new game it breaks the opening cutscene. Without it the same tree plays it.

Setup: RTX 5080 16 GB / Ryzen 5 5600, Series X profile, warm shader cache, ASYNC_SUBMIT QUEUE2 INDIRECT_WINDOW TEXTURE_NO_WAIT COPY_PLAIN, TEXTURE_CATCHUP=0, fresh save data (no story save) before every run.

Build Load screen until the world draws Indexed textures uploaded ~75 s in Result
465b94f + e109ad1 ~236 s 3,486 (746 MB) the opening cutscene does not play: player left standing in the night forest, then a frozen frame
465b94f alone (control) ~72 s 28,170 (10,040 MB) the cutscene plays, then the next one
larger stack (#927 #795 #643 #916 #911) + e109ad1 ~250 s 3,501 same as the first row (4 runs)
same stack, e109ad1 reverted ~68 s 19,188 by 68 s the cutscene plays

The forest is the cutscene's first shot. With the patch the load runs ~4× longer, the cutscene's clock runs out while the world is still loading, and the script skips past it.

Likely cause: evict_placed_in runs synchronously inside title_memory_remapped, i.e. on the title's thread for every map/unmap/move of title pages, and it:

  • holds the global TEXTURES mutex for a walk over every texture (not a range lookup), so texture creation, let_go_idle, etc. wait on it;
  • per texture takes HOST_WRITTEN (texture::host_wrote) and computes footprint();
  • for overlapping ones takes made and does a COM AddRef/Release.

During loading the title remaps pages constantly while the table grows to tens of thousands of textures, so the cost is roughly O(remaps × textures) on the streaming path. It fits the numbers: in the first ~2 minutes the title asks for far fewer textures (the "waiting" count stays low too), so the title itself is held up rather than re-uploading what was evicted.

Possible fixes: queue the (base, len) ranges in title_memory_remapped and drain them in let_go_idle (or another place off the title's thread), and/or keep placed textures in a map by address so only the overlapping ones are visited. VICTORY_TEXTURE_SWEEP=0 turns it off but also turns off the old sweep, so it is not a clean A/B.

I did not time the walk directly (trail is off by default); happy to run an instrumented build if useful.

**@⁠Chipsraine** on GitHub · 2026-11-25 18:04 UTC · [original](https://github.com/fxceless/victory-fork/pull/550#issuecomment-7170408459) Tested `e109ad1` (same patch as #432) on top of `465b94f`: **on a new game it breaks the opening cutscene.** Without it the same tree plays it. Setup: RTX 5080 16 GB / Ryzen 5 5600, Series X profile, warm shader cache, `ASYNC_SUBMIT QUEUE2 INDIRECT_WINDOW TEXTURE_NO_WAIT COPY_PLAIN`, `TEXTURE_CATCHUP=0`, fresh save data (no story save) before every run. | Build | Load screen until the world draws | Indexed textures uploaded ~75 s in | Result | |---|---|---|---| | `465b94f` + `e109ad1` | ~236 s | 3,486 (746 MB) | the opening cutscene does not play: player left standing in the night forest, then a frozen frame | | `465b94f` alone (control) | ~72 s | 28,170 (10,040 MB) | the cutscene plays, then the next one | | larger stack (#927 #795 #643 #916 #911) + `e109ad1` | ~250 s | 3,501 | same as the first row (4 runs) | | same stack, `e109ad1` reverted | ~68 s | 19,188 by 68 s | the cutscene plays | The forest is the cutscene's first shot. With the patch the load runs ~4× longer, the cutscene's clock runs out while the world is still loading, and the script skips past it. **Likely cause:** `evict_placed_in` runs synchronously inside `title_memory_remapped`, i.e. on the title's thread for every map/unmap/move of title pages, and it: - holds the global `TEXTURES` mutex for a walk over **every** texture (not a range lookup), so texture creation, `let_go_idle`, etc. wait on it; - per texture takes `HOST_WRITTEN` (`texture::host_wrote`) and computes `footprint()`; - for overlapping ones takes `made` and does a COM AddRef/Release. During loading the title remaps pages constantly while the table grows to tens of thousands of textures, so the cost is roughly O(remaps × textures) on the streaming path. It fits the numbers: in the first ~2 minutes the title asks for far fewer textures (the "waiting" count stays low too), so the title itself is held up rather than re-uploading what was evicted. Possible fixes: queue the `(base, len)` ranges in `title_memory_remapped` and drain them in `let_go_idle` (or another place off the title's thread), and/or keep placed textures in a map by address so only the overlapping ones are visited. `VICTORY_TEXTURE_SWEEP=0` turns it off but also turns off the old sweep, so it is not a clean A/B. I did not time the walk directly (`trail` is off by default); happy to run an instrumented build if useful.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/resource.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/550/head:github-bot/gh-550'
git switch 'github-bot/gh-550'

Merge

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