feat(metal4): add GPU-ready model buffer cache via Metal IO #414

Manually merged
github merged 1 commit from gh-pr/414/head into gh-pr/414/base 2026-11-27 00:39:25 +00:00
Owner

@⁠maple-quartz18 on GitHub · 2026-11-26 21:38 UTC · original
maple-quartz18:p1-model-buffer-cache → master · +254 −2 · 2 files · 1 commits · merged 2026-11-26 22:06 UTC

What

Adds a versioned GPU-ready model buffer cache (SXMTLIO2), mirroring the existing texture cache design:

  • On hit: load_buffer DMAs cached vertex/index bytes straight into PRIVATE buffers (staging=None), with commit().wait() so the buffers are ready before the first draw.
  • On miss: falls back to the existing staging path and writes the cache in a background thread (max 2 writers, 4 GiB cap, LRU trim).
  • Identity: model file name + source version + CRC of vertex/index bytes, so content changes invalidate the cache automatically.

Why

Model upload currently re-uploads the same vertex/index data from CPU staging on every launch. Caching the GPU-ready bytes lets Metal IO load them directly, avoiding the CPU staging copy.

build_vertex_index_bytes() from the already-merged P0 is the single source of truth for the byte layout, so cached payloads are byte-identical to what runtime upload expects.

Safety

  • Every cache operation is best-effort: any open/validate/load failure degrades silently to the existing staging path and never blocks rendering.
  • The cache dir is enabled in configure_renderer() next to the texture cache, sharing the same work root.

Verification

  • Header CRC fields: [36..40] = identity CRC, [28..32] vertex CRC, [32..36] index CRC.
  • New code parses cleanly under rustfmt; type-checked against the audited metal-rust load_buffer / new_io_file_handle signatures.
  • Note: PRIVATE-buffer load_buffer on real macOS GPU needs a hardware smoke test (binding layer does not restrict storageMode).
**@⁠maple-quartz18** on GitHub · 2026-11-26 21:38 UTC · [original](https://github.com/holdmysocks/SixNG/pull/414) `maple-quartz18:p1-model-buffer-cache` → `master` · +254 −2 · 2 files · 1 commits · merged 2026-11-26 22:06 UTC ## What Adds a versioned GPU-ready model buffer cache (`SXMTLIO2`), mirroring the existing texture cache design: - **On hit**: `load_buffer` DMAs cached vertex/index bytes straight into PRIVATE buffers (`staging=None`), with `commit().wait()` so the buffers are ready before the first draw. - **On miss**: falls back to the existing staging path and writes the cache in a background thread (max 2 writers, 4 GiB cap, LRU trim). - **Identity**: model file name + source version + CRC of vertex/index bytes, so content changes invalidate the cache automatically. ## Why Model upload currently re-uploads the same vertex/index data from CPU staging on every launch. Caching the GPU-ready bytes lets Metal IO load them directly, avoiding the CPU staging copy. `build_vertex_index_bytes()` from the already-merged P0 is the single source of truth for the byte layout, so cached payloads are byte-identical to what runtime upload expects. ## Safety - Every cache operation is best-effort: any open/validate/load failure degrades silently to the existing staging path and never blocks rendering. - The cache dir is enabled in `configure_renderer()` next to the texture cache, sharing the same work root. ## Verification - Header CRC fields: `[36..40]` = identity CRC, `[28..32]` vertex CRC, `[32..36]` index CRC. - New code parses cleanly under rustfmt; type-checked against the audited metal-rust `load_buffer` / `new_io_file_handle` signatures. - **Note**: PRIVATE-buffer `load_buffer` on real macOS GPU needs a hardware smoke test (binding layer does not restrict storageMode).
Cache vertex/index buffers as versioned SXMTLIO2 files. On hit, load_buffer
DMAs them straight into PRIVATE buffers (staging=None); on miss, fall back to
the existing staging path and write the cache in a background thread.
Reuses build_vertex_index_bytes() from P0 so cached bytes match runtime exactly.

The cache dir is enabled from configure_renderer() alongside the texture cache,
sharing the same work root. Any cache failure degrades silently to staging.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 00:39:24 +00:00
github manually merged commit 683f3a3bc3 into gh-pr/414/base 2026-11-27 00:39:25 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-26 21:39 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-26 21:39 UTC · [original](https://github.com/holdmysocks/SixNG/pull/414#pullrequestreview-6080747210) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
This discussion has been locked. Commenting is limited to contributors.
No description provided.