Download hosted FEX code caches before launch
Description
Second app half of the FEX code cache pipeline, stacked on #2358. A launch dependency, FexCodeCacheDependency, runs for containers on a FEX series build with the cache fixes (2611-gn-6 or newer): it asks GET /api/code-caches for the caches compiled for this game, FEX build and SoC, and streams any that are missing or changed into the prefix's AppData/Local/fex-emu/cache/, verified by size and sha256 through a temp file. FEX then loads translated code at launch instead of compiling it; it only picks a cache whose name carries the loaded image's file id, so files left from an older game build are ignored. The list is re-checked at most every six hours per FEX version and any failure logs and lets the launch continue.
The server side is utkarshdalal/gamenative-cloudflare-workers#91. Caches are served per SoC until FEX stamps them with a CPU-feature fingerprint.
Recording
Loading screen shows "Checking FEX code cache" and "Downloading FEX code cache (n/m)"; logcat tag FexCodeCache.
Type of Change
- Bug fix
- Performance / stability improvement
- Compatibility improvements
- Other (requires prior approval)
Checklist
- If I have access to
#code-changes, I have discussed this change there and it has been green-lighted. If I do not have access, I have still provided clear context in this PR. If I skip both, I accept that this change may face delays in review, may not be reviewed at all, or may be closed. - This change aligns with the current project scope (core functionality, stability, or performance). If not, it has been explicitly approved beforehand.
- I have attached a recording of the change.
- I have read and agree to the contribution guidelines in
CONTRIBUTING.md.
Summary by cubic
Adds a launch dependency that downloads hosted FEX code caches before launch so FEX loads precompiled translation instead of compiling at launch. It runs only when the FEX code cache toggle is on, the container is on a FEX series build with the cache fixes (2611-gn-6+), and the pack includes the offline compiler; otherwise it skips silently.
The dependency asks GET /api/code-caches for caches matching the game, FEX version and SoC, and streams missing or changed files into the prefix's AppData/Local/fex-emu/cache/. When the device already holds the previous cache version, only a zstd patch is fetched and applied with the old file as dictionary; otherwise the full gzip is streamed. Either way the result is inflated through a temp file and renamed into place only when size and sha256 match. A 200 reply without a cache list counts as a failure rather than an empty list, since an unrouted path on the API host is answered by another worker. The list is re-checked at most every six hours per FEX version, and a failure logs and lets the launch continue.