gpu: evict covered placed textures under budget and trim unmapped mips #428
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/428"
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 froziiik on 2026-11-27T17:50:56Z.
Refs #8
Summary
On a 16 GB M2 Pro (
recommendedMaxWorkingSetSize= 12,124 MiB, Xbox Series Stitle_memory_mib= 7,776 MiB), headless runs past the menus withVICTORY_TEXTURE_DROP_TOP_MIP=1andVICTORY_METAL_TEXTURE_BUDGET_MB=4348hitkIOGPUCommandBufferCallbackErrorOutOfMemory(20 errors by frame 1899) due to:give_up_coveredwaited for!host.texture_in_use(k).give_up_overlapped.coveredmark and remaining resident alongside the newer placement.MTLTexturestorage for unmapped leading fine mips.Changes
crates/victory-gpu/src/native/{title.rs,textures.rs,memory.rs}):PoolTable::pool_rangesandTitle::placed_pools/placed_chunksto index placed textures by physical pool offsets across virtual address aliases.gpu_epoch,retired_epoch,pending_epochs,Title::retire_gpu_epochs) so under a texture budget (budget.limit > 0),give_up_coveredevicts heap-shown covered copies and clears their stale heap entries once prior GPU work has retired.Title::covered_evictedandhas_live_placed_overlapso re-realized covered copies are marked covered again while an overlapping placement is live.crates/victory-gpu/src/native/{memory.rs,textures.rs,host.rs,glue.rs}):PoolTable::any_mapped,unmapped_leading_mips, andTextureInfo::host_desc_withto omit unmapped leading fine mips on sampled 2D textures at creation.Title::upgrade_trimmed_texturesandNativeHost::upgrade_texture/dropped_countto upgrade trimmed textures in place and re-mirror their heap entries oncePoolTablemaps their fine mips.crates/victory-gpu/src/native/texture_tests.rs,docs/native-host.md):docs/native-host.md.Verification
cargo test -p victory-gpu -- --test-threads=1(arm64 native): passedcargo test -p victory-hle -p victory -p xtask: passedcargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings: passedcargo xtask policy: passed (asset policy: 398 files ok)VICTORY_TEXTURE_DROP_TOP_MIP=1 VICTORY_METAL_TEXTURE_BUDGET_MB=4348):OutOfMemory20 -> 0,Other5 -> 0,metal_mb11,033 MiB at frame 1792 (8,939 draws).Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-28T00:37:17Z.
Review: CHANGES_REQUESTED
Thanks for this PR! We're helping the maintainer clear the queue tonight, and main has moved a lot (the preview branch landed as
86cefd22, then a batch of PRs; main is nowa6a58361). This branch now conflicts with main incrates/victory-gpu/src/native/textures.rsandcrates/victory-gpu/src/native/title.rs.Could you merge current
maininto the branch (a merge commit is fine, no need to rebase) and resolve the conflict? These are in code main reworked tonight (covered placed textures and top-mip dropping), so please check your eviction and mip trim still apply on top of it. CI has not run on this PR yet (first-time contributor runs need approval); we'll approve the run once the branch is updated. Once GitHub shows it as mergeable and CI is green on the new head, we'll read it through and merge it if it holds up.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by ItsMariusBC on 2026-11-28T00:45:47Z.
A 24 GB data point for this, with one caveat first: it is on the old base. Main
b998bb65+ #405 at9706344f+ this PR ataa8f3a17, applied as a patch (it applied cleanly there). I have not tried it on current main, where the review above says it conflicts.Apple M5 Pro, 24 GB, macOS 27.2.1, Series S, windowed, warm shader cache (no translation in the runs), residency
useResource per encoder(the default here),VICTORY_HOLD_BYTE=1471b6330:1 VICTORY_TEXTURE_DROP_TOP_MIP=1,--seconds 480. The build also carried a local change that is off unless a switch is set.VICTORY_METAL_TEXTURE_BUDGET_MB=6144 VICTORY_TRACE_TEXTURE_SYNC=1kern.memorystatus_level, every 5 s)Host texture copies in the run with this PR, from the once-a-second line: 3,630 MiB at the most, and 3,538 MiB at the end, of which 2,989 shown by heap entries and 547 that could be given up; 3,785 MiB of distinct title memory under the copies, 1,691 MiB of copies outside the title's pools.
Still slow: 121 frames in the 315 s after the first world draw is about one frame every 2.6 s, and 5.9 GB of swap was in use late in the run.
On screen I have not checked for missing or flickering textures yet; I will add that when I have it.
I can attach the logs, or run the branch again once it is on current main.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by ItsMariusBC on 2026-11-28T01:29:44Z.
The figure without this PR that my comment above lacked: one run of current main, same Mac, same night.
Main
31a28830(so with #405 merged), no budget set,VICTORY_TEXTURE_DROP_TOP_MIP=2 VICTORY_TRACE_TEXTURE_SYNC=1 VICTORY_HOLD_BYTE=1471b6330:1, Series S, windowed,--seconds 480. The build carried the same local change that is off unless a switch is set.The last line of the main run also says 17 covered copies were given up in that second (3 MiB) and nothing was shared.
So on current main the copies are more than three times the title memory under them, and nearly all of that is held by covered copies that heap entries still show. With this PR on the old base they were about the size of the memory under them.
Three things that differ between the two runs, so the table is not a clean before and after:
=2on main and=1in the PR run. With the second level dropped as well, main still held 9.5 GB.I tried the patch on
31a28830: it conflicts intextures.rs(three places,give_up_coveredand aroundkeep_to_budget) andtitle.rs(two places, thecoveredfield and its initial value). I did not resolve them, since main's queue of covered copies and this PR's epochs are two answers to the same function.Once the branch is on current main I can run it here and post the same table.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by froziiik on 2026-11-28T13:03:12Z.
Merged
main(26817285) intofix/16gb-texture-oom(76533ce0) and resolved the conflicts:title.rs/textures.rs: Combinedmain's boundedcovered_queue(COVERED_CHECKS) round-robin sweep ingive_up_coveredwith retired-epoch eviction (covered: HashMap<usize, u64>,retire_gpu_epochs,covered_evicted), preservedSYNC_PHASEStiming aroundgive_up_covered/keep_to_budget/upgrade_trimmed_textures, and verifiedunmapped_leading_mipsworks on top ofVICTORY_TEXTURE_DROP_TOP_MIP=2.texture_tests.rs: Updateda_sync_checks_covered_copies_a_share_at_a_timefor theHashMap<usize, u64>type ofcovered.Local verification on
76533ce0:cargo test -p victory-gpu -- --test-threads=1— passedcargo test -p victory-hle -p victory -p xtask— passedcargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings— passedcargo xtask policy— passed (404 files ok)@Olima34 Could you please approve the CI run on the updated head?
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-28T13:04:57Z.
Come one the discord if you want to help us
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by froziiik on 2026-11-28T13:08:18Z.
My discord is
frozzyyy, would be glad to helpView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.