native: optional top-mip drop for large sampled textures (#8) #348

Merged
Hayyan612 merged 1 commit from upstream-pr/348 into main 2026-11-27 16:14:20 +00:00
Hayyan612 commented 2026-11-27 13:29:46 +00:00 (Migrated from github.com)

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.

  • Which textures. Sampled-only 2D or array textures whose larger side is at least 1024 texels and that have a level below the top (dropped_levels). Render targets, UAV and 3D textures are left as they are.
  • Upload. detile takes the levels to skip: title level m becomes host level m - 1, and level 0 is never detiled. The background sync job carries the skip.
  • Views. host_mip_range maps each SRV's mip range onto the host texture (NativeHost::set_dropped_levels records what was dropped).
  • Docs. docs/native-host.md (with the other texture switches) and docs/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 GetDimensions see 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)

  • clippy gate (--workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -D warnings): clean
  • cargo test -p victory-gpu --lib (arm64): 350 passed
  • cargo test -p victory-shader -p victory-hle: passed, except native_probe (and native_list_imports in victory), which build the Windows probe with the cross tools I do not have installed; this change does not touch victory-hle or the loader
  • cargo xtask policy: clean

Not 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=1 for the copy sizes), would show whether it is worth making a default there.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5527461956 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/348). Originally posted by [Hayyan612](https://github.com/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. - **Which textures.** Sampled-only 2D or array textures whose larger side is at least 1024 texels and that have a level below the top (`dropped_levels`). Render targets, UAV and 3D textures are left as they are. - **Upload.** `detile` takes the levels to skip: title level `m` becomes host level `m - 1`, and level 0 is never detiled. The background sync job carries the skip. - **Views.** `host_mip_range` maps each SRV's mip range onto the host texture (`NativeHost::set_dropped_levels` records what was dropped). - **Docs.** `docs/native-host.md` (with the other texture switches) and `docs/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 `GetDimensions` see 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) - clippy gate (`--workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -D warnings`): clean - `cargo test -p victory-gpu --lib` (arm64): 350 passed - `cargo test -p victory-shader -p victory-hle`: passed, except `native_probe` (and `native_list_imports` in `victory`), which build the Windows probe with the cross tools I do not have installed; this change does not touch victory-hle or the loader - `cargo xtask policy`: clean ## Not 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=1` for the copy sizes), would show whether it is worth making a default there.
Sandile-0511 commented 2026-11-27 14:26:03 +00:00 (Migrated from github.com)

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, with VICTORY_METAL_RESIDENCY_SETS=heap and VICTORY_HOLD_BYTE=1471b6330:1; no build running alongside. One run per column, each build in a target directory of its own. Memory level is kern.memorystatus_level, sampled every 15 s.

main 905e7aad, switch unset this branch 5f18b1f2, switch on main 728845d1 with this diff applied, switch on
Failed command buffers 20, all kIOGPUCommandBufferCallbackErrorOutOfMemory, from 139 to 168 s 0 0
Frames from 120 s to the end of the run (frame=) 12 (2,558 to 2,570) 146 (2,558 to 2,704) 75 (2,482 to 2,557)
heap_set_mb at frame 2,432 (before the world; 11,479 to 11,846 draws recorded in all three) 16,002 11,899 12,403
heap_set_mb, highest in the run 18,046 13,374 13,285
Lowest memory level sampled 6% 15% 13%
Swap used, first sample to last 1,610 to 5,800 MB 3,146 to 3,090 MB 2,770 to 2,840 MB
work held for a wait that does not hold lines 14 2 2
Pipelines compiled during the run (render + compute) 301 + 389 29 + 30 318 + 382

Reading it.

  • The first and third columns are the like-for-like pair. Both compiled about 700 pipelines during the run (a cold cache), and they differ by the seven commits from 905e7aad to 728845d1 plus this diff. The second column had a warm cache (59 compiled), which is part of why it shows the most frames.
  • With the switch the heap set is 3.6 to 4.1 GB smaller at the same point before the world and about 4.7 GB smaller at its highest. The memory level stays at 13% or more where it fell to 6%, and swap stays flat where it grew by about 4.2 GB.
  • The diff applies to 728845d1 with git apply --3way and no conflict. On that tree cargo test -p victory-gpu --lib texture gives 59 passed and 1 ignored, among them this pull request's three tests.

Not checked.

  • 728845d1 without the switch: the third column has no control of its own.
  • More than one run per column. The table on #79 shows one build failing in one run and not in the next on a larger Mac.
  • Picture quality with the smaller textures: the world picture in the window is not far enough along here to judge blur.

After the third run nothing was left allocated in the sense of #357: In use system memory was 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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7220777012 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/348#issuecomment-7220777012). Originally posted by [Sandile-0511](https://github.com/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, with `VICTORY_METAL_RESIDENCY_SETS=heap` and `VICTORY_HOLD_BYTE=1471b6330:1`; no build running alongside. One run per column, each build in a target directory of its own. Memory level is `kern.memorystatus_level`, sampled every 15 s. | | main `905e7aad`, switch unset | this branch `5f18b1f2`, switch on | main `728845d1` with this diff applied, switch on | |---|---|---|---| | Failed command buffers | 20, all `kIOGPUCommandBufferCallbackErrorOutOfMemory`, from 139 to 168 s | 0 | 0 | | Frames from 120 s to the end of the run (`frame=`) | 12 (2,558 to 2,570) | 146 (2,558 to 2,704) | 75 (2,482 to 2,557) | | `heap_set_mb` at frame 2,432 (before the world; 11,479 to 11,846 draws recorded in all three) | 16,002 | 11,899 | 12,403 | | `heap_set_mb`, highest in the run | 18,046 | 13,374 | 13,285 | | Lowest memory level sampled | 6% | 15% | 13% | | Swap used, first sample to last | 1,610 to 5,800 MB | 3,146 to 3,090 MB | 2,770 to 2,840 MB | | `work held for a wait that does not hold` lines | 14 | 2 | 2 | | Pipelines compiled during the run (render + compute) | 301 + 389 | 29 + 30 | 318 + 382 | **Reading it.** - The first and third columns are the like-for-like pair. Both compiled about 700 pipelines during the run (a cold cache), and they differ by the seven commits from `905e7aad` to `728845d1` plus this diff. The second column had a warm cache (59 compiled), which is part of why it shows the most frames. - With the switch the heap set is 3.6 to 4.1 GB smaller at the same point before the world and about 4.7 GB smaller at its highest. The memory level stays at 13% or more where it fell to 6%, and swap stays flat where it grew by about 4.2 GB. - The diff applies to `728845d1` with `git apply --3way` and no conflict. On that tree `cargo test -p victory-gpu --lib texture` gives 59 passed and 1 ignored, among them this pull request's three tests. **Not checked.** - `728845d1` without the switch: the third column has no control of its own. - More than one run per column. The table on #79 shows one build failing in one run and not in the next on a larger Mac. - Picture quality with the smaller textures: the world picture in the window is not far enough along here to judge blur. After the third run nothing was left allocated in the sense of #357: `In use system memory` was 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.*
Hayyan612 commented 2026-11-27 15:29:12 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7222115697 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/348#issuecomment-7222115697). Originally posted by [Hayyan612](https://github.com/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.
ItsMariusBC commented 2026-11-27 16:15:05 +00:00 (Migrated from github.com)

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 728845d1 with this branch (5f18b1f2) merged, Series S, windowed, default residency (no VICTORY_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.

Without the switch Without, #301 and #359 merged (budget off) VICTORY_TEXTURE_DROP_TOP_MIP=1
Shader cache half cold (9,993 translated in the run) warm warm
Command buffers "never reported on by the GPU" 21 6 0
GPU errors (run-summary.sh) OutOfMemory 5, Other 5 OutOfMemory 2, Other 5 none
Free memory at its lowest (memory_pressure, every 15 s) 0 % 0 % 6 %
World frames in the run 3 3 28
Audio output fell back to silence once 7 times never
Window in the world black black grey scene with faint shapes, minimap and location panel drawn over it

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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7223037202 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/348#issuecomment-7223037202). Originally posted by [ItsMariusBC](https://github.com/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 `728845d1` with this branch (`5f18b1f2`) merged, Series S, windowed, default residency (no `VICTORY_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. | | Without the switch | Without, #301 and #359 merged (budget off) | `VICTORY_TEXTURE_DROP_TOP_MIP=1` | | --- | --- | --- | --- | | Shader cache | half cold (9,993 translated in the run) | warm | warm | | Command buffers "never reported on by the GPU" | 21 | 6 | 0 | | GPU errors (`run-summary.sh`) | OutOfMemory 5, Other 5 | OutOfMemory 2, Other 5 | none | | Free memory at its lowest (`memory_pressure`, every 15 s) | 0 % | 0 % | 6 % | | World frames in the run | 3 | 3 | 28 | | Audio output fell back to silence | once | 7 times | never | | Window in the world | black | black | grey scene with faint shapes, minimap and location panel drawn over it | 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.
LakshanSivakumar commented 2026-11-27 16:15:27 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7223044761 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/348#issuecomment-7223044761). Originally posted by [LakshanSivakumar](https://github.com/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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LakshanSivakumar/Native-Victory-macOS!348
No description provided.