translate --cache on a Mac: translate the containers earlier runs kept #327

Merged
ItsMariusBC merged 4 commits from upstream-pr/327 into main 2026-11-27 16:14:20 +00:00
ItsMariusBC commented 2026-11-27 11:43:56 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by ItsMariusBC on 2026-11-27T11:43:56Z.


What this changes

On a Mac, victory translate --cache now warms the native host's shader cache. Before, it stopped with "translate needs a Windows host for now".

There is no issue for this yet, so it is a draft: I can open one and claim it if you want the change.

Why not from the game's files, as on Windows. The title hands the native host pieces (code, metadata; graphics_containers, compute_container) and the container is put together in the host, so a container found in the shader archive is other bytes with another cache key. I tried the Windows walk first: of 25,985 distinct containers found in the files, 58 were ones a run had cached.

What it does instead.

  • Each container a run translates is kept as the title passed it, once, under its short hash in <cache>/native-shaders/containers (prewarm::keep, called from Shader::native). It sits beside first-binds.txt, outside the build folders, so it outlives a changed translator.
  • victory translate --cache (no paths) translates the kept containers on every core, through native::shaders::translate, the call a run's prewarm makes. A file whose bytes are not its name's is counted and skipped.

Cost, and a question. A run to the world keeps 21,596 containers, 322 MB, for every user. There is no switch of its own; VICTORY_NO_SHADER_CACHE turns it off with the cache. Say if you would rather have it opt-in.

Not covered: the translations a run asks for by how a shader is drawn (rectangle lists, extra parameters, thread counts), and Metal libraries and pipelines. --pipelines stays Windows-only. shader_cache.rs, victory-shader and Cargo.lock are untouched, so no cache is invalidated.

How it was tested

  • cargo test -p victory-hle -p victory -p victory-gpu -p xtask (arm64 host), and -p victory with --target x86_64-apple-darwin. Not run: -p victory-loader.
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings, and cargo xtask policy
  • Ran the game: see below

All of that was on main c1b9587. Main has moved since; the branch merges without conflict, and I have not rerun the gates on the merge.

New tests: warm::tests::the_warm_up_translates_what_a_run_kept (it fails with the translation taken out) and prewarm::tests::kept_containers_read_back_and_damaged_ones_do_not.

Game, Apple M5 Pro, 24 GB, Series S:

  1. A run to the world kept 21,596 containers.
  2. With four open pull requests merged that change the translator (#253, #263, #267, #278: a new, empty build folder), the warm-up took 67.9 s: 17,469 translated, 4,127 refused, 0 damaged. A cold run's prewarm took about 100 s for this, with the title loading beside it.
  3. The run after it logged shaders_cached=21564 shaders_translated=2 at frame 1920 (VICTORY_TRACE_SHADER_CACHE=1), and its prewarm was done 19 s in.

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md (none made)
  • New diagnostics are behind a VICTORY_* variable and documented (none added; the warm-up is documented in docs/native-host.md)
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5526047157 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/327). Originally posted by [ItsMariusBC](https://github.com/ItsMariusBC) on 2026-11-27T11:43:56Z. --- ## What this changes On a Mac, `victory translate --cache` now warms the native host's shader cache. Before, it stopped with "translate needs a Windows host for now". There is no issue for this yet, so it is a draft: I can open one and claim it if you want the change. **Why not from the game's files, as on Windows.** The title hands the native host pieces (code, metadata; `graphics_containers`, `compute_container`) and the container is put together in the host, so a container found in the shader archive is other bytes with another cache key. I tried the Windows walk first: of 25,985 distinct containers found in the files, 58 were ones a run had cached. **What it does instead.** - Each container a run translates is kept as the title passed it, once, under its short hash in `<cache>/native-shaders/containers` (`prewarm::keep`, called from `Shader::native`). It sits beside `first-binds.txt`, outside the build folders, so it outlives a changed translator. - `victory translate --cache` (no paths) translates the kept containers on every core, through `native::shaders::translate`, the call a run's prewarm makes. A file whose bytes are not its name's is counted and skipped. **Cost, and a question.** A run to the world keeps 21,596 containers, 322 MB, for every user. There is no switch of its own; `VICTORY_NO_SHADER_CACHE` turns it off with the cache. Say if you would rather have it opt-in. Not covered: the translations a run asks for by how a shader is drawn (rectangle lists, extra parameters, thread counts), and Metal libraries and pipelines. `--pipelines` stays Windows-only. `shader_cache.rs`, `victory-shader` and `Cargo.lock` are untouched, so no cache is invalidated. ## How it was tested - [x] `cargo test -p victory-hle -p victory -p victory-gpu -p xtask` (arm64 host), and `-p victory` with `--target x86_64-apple-darwin`. Not run: `-p victory-loader`. - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings`, and `cargo xtask policy` - [x] Ran the game: see below All of that was on main `c1b9587`. Main has moved since; the branch merges without conflict, and I have not rerun the gates on the merge. New tests: `warm::tests::the_warm_up_translates_what_a_run_kept` (it fails with the translation taken out) and `prewarm::tests::kept_containers_read_back_and_damaged_ones_do_not`. Game, Apple M5 Pro, 24 GB, Series S: 1. A run to the world kept 21,596 containers. 2. With four open pull requests merged that change the translator (#253, #263, #267, #278: a new, empty build folder), the warm-up took 67.9 s: 17,469 translated, 4,127 refused, 0 damaged. A cold run's prewarm took about 100 s for this, with the title loading beside it. 3. The run after it logged `shaders_cached=21564 shaders_translated=2` at frame 1920 (`VICTORY_TRACE_SHADER_CACHE=1`), and its prewarm was done 19 s in. ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md (none made) - [x] New diagnostics are behind a `VICTORY_*` variable and documented (none added; the warm-up is documented in docs/native-host.md)
reefbluesky commented 2026-11-27 13:15:07 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by reefbluesky on 2026-11-27T13:15:07Z.


A tester's data point for this, from an M2 Pro (10 cores: 6 performance, 4 efficiency), 32 GB, macOS 27.2, series-x.

Why keeping the containers outside the build folders helps. I rebuild after each merge to main. This morning that made four build folders under native-shaders/ (6909d8c1, dbde7124, d09afb17, 714755fc: three main commits up to c5d7f4d and one local build of main + #250 #296 #318 #335), each about 580 MB and each filled from nothing by a run to the world. With this PR, victory translate --cache after each rebuild would refill them before the first run.

A question about finding the code ahead of any run. nxnative (the Switch port, MIT) translates every shader before the first run: it scans every file of the game, finds each shader by a hash of its control section and its code, and looks it up by that key at run time (docs/agents/04-graphics.md). Your finding that only 58 of 25,985 file containers match what a run caches says the assembled container cannot be the key here. Could the key be the code part alone? If the code bytes the title passes (graphics_containers, compute_container) can be found as they are in the shader pack, a first run could start with most translations done, and only the metadata the title builds at run time would be missing. I have not checked whether the code is stored unchanged in the pack.

I can run this branch here and report the kept container count and the time translate --cache takes on an M2 Pro if that helps.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7219245272 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/327#issuecomment-7219245272). Originally posted by [reefbluesky](https://github.com/reefbluesky) on 2026-11-27T13:15:07Z. --- A tester's data point for this, from an M2 Pro (10 cores: 6 performance, 4 efficiency), 32 GB, macOS 27.2, series-x. **Why keeping the containers outside the build folders helps.** I rebuild after each merge to main. This morning that made four build folders under `native-shaders/` (6909d8c1, dbde7124, d09afb17, 714755fc: three main commits up to c5d7f4d and one local build of main + #250 #296 #318 #335), each about 580 MB and each filled from nothing by a run to the world. With this PR, `victory translate --cache` after each rebuild would refill them before the first run. **A question about finding the code ahead of any run.** nxnative (the Switch port, MIT) translates every shader before the first run: it scans every file of the game, finds each shader by a hash of its control section and its code, and looks it up by that key at run time ([docs/agents/04-graphics.md](https://github.com/seedds/nxnative/blob/main/docs/agents/04-graphics.md)). Your finding that only 58 of 25,985 file containers match what a run caches says the assembled container cannot be the key here. Could the key be the code part alone? If the code bytes the title passes (`graphics_containers`, `compute_container`) can be found as they are in the shader pack, a first run could start with most translations done, and only the metadata the title builds at run time would be missing. I have not checked whether the code is stored unchanged in the pack. I can run this branch here and report the kept container count and the time `translate --cache` takes on an M2 Pro if that helps.
LakshanSivakumar commented 2026-11-27 16:15:24 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T16:15:24Z.


Merged in 4cf84c83. The containers stay on by default with the cache, as you have it. 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. I did not run translate --cache myself. Thanks.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7223043652 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/327#issuecomment-7223043652). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T16:15:24Z. --- Merged in 4cf84c83. The containers stay on by default with the cache, as you have it. 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. I did not run translate --cache myself. Thanks.
reefbluesky commented 2026-11-27 18:35:09 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by reefbluesky on 2026-11-27T18:35:09Z.


Ran victory translate --cache on an M2 Pro (10 cores, 32 GB, macOS 27.2), main b998bb65.

  • A windowed run into the world kept 21,572 containers (321 MB).
  • With them already translated, translate --cache took 0.5 s (all cached).
  • Cold, as after a translator change (a fresh VICTORY_CACHE_DIR holding only those containers): 106.6 s wall, 835 s CPU, 1.16 GB peak RSS; 19,306 translated, 2,266 refused, 0 damaged, 712 MB of translations.

In the run itself the same translations came at about 1,000 a minute with the world at about 0.9 fps, so two minutes ahead of the first run replace about twenty minutes of stalls. Not measured yet: a run right after the warm-up.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7225643836 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/327#issuecomment-7225643836). Originally posted by [reefbluesky](https://github.com/reefbluesky) on 2026-11-27T18:35:09Z. --- Ran `victory translate --cache` on an M2 Pro (10 cores, 32 GB, macOS 27.2), main `b998bb65`. - A windowed run into the world kept 21,572 containers (321 MB). - With them already translated, `translate --cache` took 0.5 s (all cached). - Cold, as after a translator change (a fresh `VICTORY_CACHE_DIR` holding only those containers): 106.6 s wall, 835 s CPU, 1.16 GB peak RSS; 19,306 translated, 2,266 refused, 0 damaged, 712 MB of translations. In the run itself the same translations came at about 1,000 a minute with the world at about 0.9 fps, so two minutes ahead of the first run replace about twenty minutes of stalls. Not measured yet: a run right after the warm-up.
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!327
No description provided.