native: one host texture per range of title memory (share identical copies, give up covered placed copies) #359
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/359"
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?
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by m0rff on 2026-11-27T14:01:56Z.
Refs #356. Stacked on #301: the first five commits are #301's. This PR's own change is the last commit,
native: one host texture per range of title memory. I'll rebase it once #301 lands.Why. On a 24 GB M4 Pro (Series S, budget off), host texture copies grew to 8.5 GB over 1.7 GB of distinct title memory during the world load, and macOS ran out of memory (#301, alicans' third run). Each title key got its own copy, even when other keys covered the same memory.
What changes.
Identical copies share one texture (
Title::realize,identical_copy). A title texture can take a live copy's texture instead of making its own when the two:Both would be detiled from the same bytes into the same format, so draws sample the same texels. The shared copy is counted once. A GPU write through either key marks the shared copy, as the R9G9B9E5-over-R32_UINT case already does. When the owner's title texture goes, the first key that shared it takes the copy over. Its entries already show that texture, so nothing is cleared, made or uploaded again.
A placed copy goes when another placement covers its memory at another start, once nothing uses it (
Title::give_up_overlappedmarks it fromtexture_placed;give_up_coveredgives it up at a sync). Before, it went only when a description was placed at exactly its address, or with its pool.evictable): no heap entry shows it and no recorded or submitted list holds it. It also waits while a submission in flight names it. Giving up a copy an entry shows would clear the entry, and drop the Metal reference it holds, under work the GPU may still be running. So a copy that is still shown waits until the title writes another record over that entry.keep_named). A view written again at the copy's own address is not a new placement, so two placements in use don't keep covering each other.Trace. The
VICTORY_TRACE_TEXTURE_SYNC=1budget line now also gives, per second, how many textures shared an identical copy (and how many share one now) and how many placed copies were given up as covered (with MiB), and how many covered copies are still in use (waiting on an entry). Compare it with the distinct figure. If "made again" climbs with the covered count, the guess is wrong for this title.Not covered. Copies at other starts that stay live (separately placed mips or slices of one chain), and copies of one memory in another layout or format, still hold that memory once each. An object created over placed copies does not give them up; only placements do.
Tests (
texture_tests). Each fails with its part removed:an_identical_texture_over_the_same_memory_shares_its_copya_texture_sharing_a_released_copy_takes_it_overa_placed_copy_another_placement_covers_is_given_up_once_unused(includes a copy an entry still shows, kept until that entry shows another)The texture tests share one host and reuse pool addresses. Earlier tests' textures would now be shared by later identical ones, so
texture_tests::poolreleases what is left over its addresses first. That also stopped the probe-timing flakes in six runs out of six (they failed 2 runs in 5 before).Checks:
cargo test -p victory-hle -p victory -p victory-gpu -p xtaskpasses. victory-gpu was run natively on arm64: 363 passed, six runs in a row.-D warningsis clean, and native clippy finds nothing new in the changed lines.cargo xtask policyis ok.Needs world runs. This machine has no copy of the game. What would settle it: the copies and distinct figures at the world load on a 24 GB Mac with the budget off, against #301's head, plus how many "made again" there were.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by m0rff on 2026-11-27T14:32:56Z.
@alicans please don't run this head, nor #355: both are stacked on #301, which has a crash the maintainer found (comment on #301 at 14:25 UTC). I'll say here when they are rebased on a fix.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by m0rff on 2026-11-27T14:48:56Z.
@alicans #355 and #359 are now rebased on the crash fix in #301 (
a0fbd51a). The fix has not been run in the game, so it may still crash. If you try it, a world load of #359 with the budget off and VICTORY_TRACE_TEXTURE_SYNC=1 is the run that would help.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T16:23:31Z.
Merged in
582670f1, from the head before your rebase (55219dfa; the rebase only changed docs context, so the content is the same). I added one change on top: a submission takes the lists' snapshots for the budget only when the budget, an evicted texture or the trace needs them, instead of every submission (582670f1). Ran the tests, Windows clippy, policy and a release build, and a 170 s headless game run with the budget off: the world was entered and kept presenting to the end like the run without this PR, 0 GPU errors, no crash. I did not run with the budget on or with VICTORY_TRACE_TEXTURE_SYNC. Closing since it is on main. Thanks.Pull request closed