feat(metal4): add offline model cache baking tool #472

Open
github-bot wants to merge 2 commits from github-bot/gh-472 into master AGit
Owner

@⁠maple-quartz18 on GitHub · 2026-11-27 07:07 UTC · original
maple-quartz18:p2-offline-model-cache-bake → master · +524 −0 · 4 files · 2 commits · open

What

Adds a --bake-model-cache CLI subcommand that scans .glb files under the work folder and pre-generates SXMTLIO2 caches, enabling batch pre-baking for large asset sets.

  • Reuses the already-merged P0 build_vertex_index_bytes() and the P1 cache writers (model_identity / write_model_cache_entry), so cached bytes are byte-identical to what runtime upload expects — no second byte-layout source of truth.
  • Full streaming CRC verification: after baking, every emitted .buf is re-read in 64 KiB chunks and its vertex/index payload CRCs are checked against the header, catching bit-rot from a partial write. Memory stays bounded regardless of model size.
  • Scanning skips cache directories (metal_io_models_v2, gui_cache_v4, cache) so generated artifacts are never fed back as inputs.
  • Reports found / baked / skipped / failed / verified counts; per-file failures are logged and skipped, never aborting the batch.

Why

Model upload previously only cached on first render (per launch). For very large asset sets it is useful to pre-generate the GPU-ready buffers ahead of time. This is the third and final step of the model-cache plan (P0 refactor → P1 runtime cache → P2 offline baking).

Design note

The tool is added as a CLI subcommand in main.rs (gated macOS + metal4-poc, alongside the renderer), not as a standalone #[path] bin. glb.rs / render3d.rs reference many crate::* modules (atmo, GUI_CACHE, …); a standalone bin would have to re-import the whole module closure and is easy to get wrong. The subcommand reuses main.rs's already-complete module graph, needs no pub(crate) visibility changes, and touches no Cargo.toml.

Verification

  • 6 unit tests (model_bake_tests) covering header round-trip, idempotent write, identity change / bad magic / bad version rejection, vertex+index payload corruption detection, cache-dir skipping, and buf-only verification — all passing.
  • Core functions and tests were compiled and executed in an isolated harness on Linux (the real file is macOS-gated, so it cannot be cargo checked there).
  • rustfmt parse check clean. Real macOS GPU smoke test of the cache-hit path remains tracked from P1.

Cache writes remain best-effort; a failed or corrupt cache never blocks rendering.

**@⁠maple-quartz18** on GitHub · 2026-11-27 07:07 UTC · [original](https://github.com/holdmysocks/SixNG/pull/472) `maple-quartz18:p2-offline-model-cache-bake` → `master` · +524 −0 · 4 files · 2 commits · open ## What Adds a `--bake-model-cache` CLI subcommand that scans `.glb` files under the work folder and pre-generates `SXMTLIO2` caches, enabling batch pre-baking for large asset sets. - Reuses the already-merged P0 `build_vertex_index_bytes()` and the P1 cache writers (`model_identity` / `write_model_cache_entry`), so cached bytes are **byte-identical** to what runtime upload expects — no second byte-layout source of truth. - **Full streaming CRC verification**: after baking, every emitted `.buf` is re-read in 64 KiB chunks and its vertex/index payload CRCs are checked against the header, catching bit-rot from a partial write. Memory stays bounded regardless of model size. - Scanning skips cache directories (`metal_io_models_v2`, `gui_cache_v4`, `cache`) so generated artifacts are never fed back as inputs. - Reports `found / baked / skipped / failed / verified` counts; per-file failures are logged and skipped, never aborting the batch. ## Why Model upload previously only cached on first render (per launch). For very large asset sets it is useful to pre-generate the GPU-ready buffers ahead of time. This is the third and final step of the model-cache plan (P0 refactor → P1 runtime cache → P2 offline baking). ## Design note The tool is added as a CLI subcommand in `main.rs` (gated `macOS + metal4-poc`, alongside the renderer), **not** as a standalone `#[path]` bin. `glb.rs` / `render3d.rs` reference many `crate::*` modules (`atmo`, `GUI_CACHE`, …); a standalone bin would have to re-import the whole module closure and is easy to get wrong. The subcommand reuses `main.rs`'s already-complete module graph, needs no `pub(crate)` visibility changes, and touches no `Cargo.toml`. ## Verification - 6 unit tests (`model_bake_tests`) covering header round-trip, idempotent write, identity change / bad magic / bad version rejection, vertex+index payload corruption detection, cache-dir skipping, and buf-only verification — all passing. - Core functions and tests were compiled and executed in an isolated harness on Linux (the real file is macOS-gated, so it cannot be `cargo check`ed there). - `rustfmt` parse check clean. Real macOS GPU smoke test of the cache-hit path remains tracked from P1. Cache writes remain best-effort; a failed or corrupt cache never blocks rendering.
Add a --bake-model-cache CLI subcommand that scans .glb files under the
work folder and pre-generates SXMTLIO2 caches using the same
build_vertex_index_bytes() and cache writers as runtime upload, so cached
bytes are byte-identical to what the renderer expects. Enables batch
pre-baking for large asset sets.

Adds full streaming CRC verification (chunked, bounded memory) to detect
bit-rot, skips cache directories during scanning, and reports found/baked/
skipped/failed/verified counts. Includes 6 unit tests covering header
round-trip, identity/magic/version rejection, payload corruption detection,
cache-dir skipping and buf-only verification.

All cache operations are best-effort per file; one bad model never aborts
the batch. Gated behind macOS + metal4-poc alongside the renderer.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 07:16:07 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-27 07:07 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-27 07:07 UTC · [original](https://github.com/holdmysocks/SixNG/pull/472#pullrequestreview-6084652301) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
Add a Settings page section (macOS + metal4-poc) with a 'Bake model cache'
button, live progress (spinner, elapsed time, current file from the child's
log), cancel, and a result line. Follows the existing --bake-map BakeJob
pattern: the bake runs in a child process so a failure or OOM cannot take
down the app, and Drop kills orphaned bakes on close.

Adds a progress callback variant bake_model_cache_dir_with_progress() so the
CLI can stream per-file progress into <work>/model_cache_bake.log via the new
--bake-log flag; the original bake_model_cache_dir() signature is unchanged.
The 6 bake tests pass with the new signature.
Author
Owner

@⁠maple-quartz18 on GitHub · 2026-11-27 16:03 UTC · original

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

where are you from?

**@⁠maple-quartz18** on GitHub · 2026-11-27 16:03 UTC · [original](https://github.com/holdmysocks/SixNG/pull/472#issuecomment-7222806602) > Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. where are you from?
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/472/head:github-bot/gh-472'
git switch 'github-bot/gh-472'

Merge

Merge the changes and update on Forgejo.
git switch 'master'
git merge --no-ff 'github-bot/gh-472'
git switch 'github-bot/gh-472'
git rebase 'master'
git switch 'master'
git merge --ff-only 'github-bot/gh-472'
git switch 'github-bot/gh-472'
git rebase 'master'
git switch 'master'
git merge --no-ff 'github-bot/gh-472'
git switch 'master'
git merge --squash 'github-bot/gh-472'
git switch 'master'
git merge --ff-only 'github-bot/gh-472'
git switch 'master'
git merge 'github-bot/gh-472'
git push origin 'master'
This discussion has been locked. Commenting is limited to contributors.
No description provided.