native: optional top-mip drop for large sampled textures (#8) #348
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/348"
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 Hayyan612 on 2026-11-27T13:29:46Z.
Refs #347, a piece of #8 (and the "fewer top mips" lever named in #79 and #301).
What this changes
VICTORY_TEXTURE_DROP_TOP_MIP=1(off by default) makes large sampled-only 2D textures on the native host without their top level: half the width and height, one level fewer, about 75% of their memory. It complements #301 (a byte budget on how many copies are kept) by making each large copy smaller.dropped_levels). Render targets, UAV and 3D textures are left as they are.detiletakes the levels to skip: title levelmbecomes host levelm - 1, and level 0 is never detiled. The background sync job carries the skip.host_mip_rangemaps each SRV's mip range onto the host texture (NativeHost::set_dropped_levelsrecords what was dropped).docs/native-host.md(with the other texture switches) anddocs/metal-backend.md.Not console behaviour
Implicit-LOD sampling simply uses the next level (a little blurrier up close); explicit-LOD samples come out one level blurrier; integer texel loads and
GetDimensionssee the smaller texture. That is why it is opt-in.Tests
drop_top_mip_tests: which textures qualify, and the view mip mapping.a_texture_made_without_its_top_level_gets_the_lower_levels(Metal): a half-size host texture receives the title's level 1 as its level 0, and so on down.Checks run (MacBook Air M4, 16 GB)
--workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -D warnings): cleancargo test -p victory-gpu --lib(arm64): 350 passedcargo test -p victory-shader -p victory-hle: passed, exceptnative_probe(andnative_list_importsinvictory), which build the Windows probe with the cross tools I do not have installed; this change does not touch victory-hle or the loadercargo xtask policy: cleanNot measured
I have not run it in a game run. A footprint comparison from a 16 GB Mac at the world load, with and without the variable (
VICTORY_TRACE_TEXTURE_SYNC=1for the copy sizes), would show whether it is worth making a default there.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sandile-0511 on 2026-11-27T14:26:03Z.
A data point from a 24 GB Mac: here the world load runs out of GPU memory without this switch, and does not with it.
Setup. M5, 24 GB, macOS 26.5.1.
tools/macos/run-native.sh --seconds 240 --console series-s, windowed, withVICTORY_METAL_RESIDENCY_SETS=heapandVICTORY_HOLD_BYTE=1471b6330:1; no build running alongside. One run per column, each build in a target directory of its own. Memory level iskern.memorystatus_level, sampled every 15 s.905e7aad, switch unset5f18b1f2, switch on728845d1with this diff applied, switch onkIOGPUCommandBufferCallbackErrorOutOfMemory, from 139 to 168 sframe=)heap_set_mbat frame 2,432 (before the world; 11,479 to 11,846 draws recorded in all three)heap_set_mb, highest in the runwork held for a wait that does not holdlinesReading it.
905e7aadto728845d1plus this diff. The second column had a warm cache (59 compiled), which is part of why it shows the most frames.728845d1withgit apply --3wayand no conflict. On that treecargo test -p victory-gpu --lib texturegives 59 passed and 1 ignored, among them this pull request's three tests.Not checked.
728845d1without the switch: the third column has no control of its own.After the third run nothing was left allocated in the sense of #357:
In use system memorywas 0.7 GB with 2.9 GB wired once the process had gone. It was stopped by the timer, with no failed buffer in the run.AI-assisted: runs and summary done with Claude Code on my own machine; I reviewed the text.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Hayyan612 on 2026-11-27T15:29:12Z.
Thank you @Sandile-0511, this is exactly the measurement the PR was missing: 20 out-of-memory command buffers to 0 and the heap set 4 to 5 GB smaller on a 24 GB Mac, with the tests passing on
728845d1.With CI green I'm marking it ready for review. Picture quality stays open until the world draws far enough to judge blur; the switch stays off by default until then.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by ItsMariusBC on 2026-11-27T16:15:05Z.
A third 24 GB data point, after the merge, with one thing the others did not have: the run goes on into the world for 480 s, and here the switch is the difference between a black window and a picture.
Apple M5 Pro, 24 GB, macOS 27.2.1, main
728845d1with this branch (5f18b1f2) merged, Series S, windowed, default residency (noVICTORY_METAL_RESIDENCY_SETS),VICTORY_HOLD_BYTE=1471b6330:1,--seconds 480, nothing building alongside.title_memory_mib=7776 recommended_working_set_mib=18186. The builds also carry #327 (kept shader containers), which is not on the texture path.VICTORY_TEXTURE_DROP_TOP_MIP=1run-summary.sh)memory_pressure, every 15 s)One run per column, so the first column's cold shaders are a confound; the second column is the cleaner comparison.
With the switch the last frame's targets (
VICTORY_TRACE_TARGETS=1) show the two 1280x720 targets taking 179 and 177 draws with 1 and 4 dropped. The world still runs at about one frame every 15 s here, and the freeze still starts at the world load, about 70 s in.I cannot say anything about blur: the scene is the flat grey of current main, so there is no texture detail to judge yet.
I can attach the logs or run other switches on this Mac.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T16:15:27Z.
Merged in
4cf84c83. I fixed one thing on top: with the switch on, copies (CopyTextureRegion, CopyResource, copies to buffers) still used the title's mip numbers on a host texture one level short. They now use the host's level, and a copy to or from the dropped level is skipped (4b026d1e). Before pushing I ran the tests (native arm64), Windows clippy, the policy check, a release build, and one headless game run of the exact tree (170 s, Series S): menus at 30 fps, the world entered at about 81 s and kept presenting to the end at about 1 frame a second, 0 GPU errors, no crash. That run had the switch off; I did not run with it on. Thanks.