GPU: let go of a placed texture's host copy as soon as its memory is … #550
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!550
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-550"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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) == 1andhost::references(&host.texture) == 1, the same two conditionslet_go_idlerequires, taken under the samemadelock and followed by the sametexture::unstage,host::retire,host.gonemarking andKINDS[2]/KINDS[3]counters.title_memory_remappedcalls 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_overflowpins 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=0still lets nothing go. The switch moved into onesweeping()so the two paths cannot disagree about it. The path is traced throughhost::traillike 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_remappedis defined (lib.rsre-exports it). No test drivesevict_placed_initself: it needs the host device, and the two conditions it acts on are the oneslet_go_idlealready had. What is new and testable is the range test.@Revens2 on GitHub · 2026-11-25 07:38 UTC · original
Duplicate of #432: @HailLucifer666 opened this patch 80 minutes earlier, and
gh pr diffreturns 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.
@Chipsraine on GitHub · 2026-11-25 18:04 UTC · original
Tested
e109ad1(same patch as #432) on top of465b94f: 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.465b94f+e109ad1465b94falone (control)e109ad1e109ad1revertedThe 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_inruns synchronously insidetitle_memory_remapped, i.e. on the title's thread for every map/unmap/move of title pages, and it:TEXTURESmutex for a walk over every texture (not a range lookup), so texture creation,let_go_idle, etc. wait on it;HOST_WRITTEN(texture::host_wrote) and computesfootprint();madeand 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 intitle_memory_remappedand drain them inlet_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=0turns it off but also turns off the old sweep, so it is not a clean A/B.I did not time the walk directly (
trailis off by default); happy to run an instrumented build if useful.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.Merge
Merge the changes and update on Forgejo.