Repository navigation
Conversation
ba3fd99 to
3f64667
Compare
The iPhone / iPad app now translates shaders itself: maxmetal (Maxwell to Metal Shading Language, plain C) is built into the app and translates on the device every shader variant the startup shaders lack, as the game first asks for it. Before, such a variant was skipped until a Mac filled it in. maxmetal gives the same results as the Ryujinx + SPIRV-Cross route: 31,305 of the game's 31,307 variants produce bit-identical GPU output. Its heaviest fragment shaders take about 20% less GPU time (maxmetal docs/adr/0003). It has no C# translator, SPIR-V or SPIRV-Cross step, which is what lets it run on the device at all. build_app.py --no-startup-shaders builds an iPhone / iPad app with no startup shaders: the build skips about an hour of translating and compiling them, maxmetal translates every shader on the device and Metal compiles it there; the device keeps them for later starts. install_device.py makes the device stop using startup shaders an earlier install left. The shader box on the device gets a second line: the Metal libraries compiled on the device this run and the variants maxmetal translated, each with the seconds it took. The Mac keeps the Ryujinx translator. Tested: the shader compiler on the Mac, and on an iPhone 13 (iOS 26, TOTK 1.4.3) built with no startup shaders, so maxmetal translated every shader: the game started and rendered, and none of the 478 variants of the session failed.
… lack, with the Mac's own translator (not yet tested on a device) PR #1468 proposed a second translator (maxmetal) on the device. This links the one the Mac uses instead: totk_xlate (Ryujinx's translator, the project's patches, Service.cs, SPIRV-Cross in process) as a NativeAOT static library for ios-arm64 (prebuilt/ios-arm64/libtotk_xlate.a, tools/totk_xlate/publish_ios_lib.sh; Service.cs's request handling moved into HandleLine, which the command-line service and LibExports.cs both call). build_app.py builds SPIRV-Cross for the device from the pinned sources; build_ipa.py links both and defines TOTK_DEVICE_XLATE. totk_shader_rt.m then sets the library up and calls it where the Mac writes to the service's pipe, and the rest is the Mac's: background jobs (2 + 2 on the device), the Metal library, the variant index, contributions. nvn_mtl.m turns async shaders on there (TOTK_ASYNC_SHADERS=0 turns them off), so a missing variant's draws are skipped for a few frames instead of until the Mac fills it in. TOTK_SHADER_NO_TRANSLATE=1 keeps the old behaviour; visionOS is unchanged. Checked: the library form translates 551 Breath of the Wild variants to the same 2,204 files as the shipped totk_xlate, byte for byte, on the Mac and in the iOS simulator; the Mac's nvn_mtl.m and totk_shader_rt.m preprocess to the same code as before (line numbers aside); iOS syntax with and without the translator. Not yet: an iPhone build and play. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thank you for maxmetal and the careful comparison: 31,305 of 31,307 variants matching Ryujinx bit for bit, and the faster fragment shaders, are impressive work. It made us look again at the gap it fills: a variant the startup shaders lack is skipped on the device until the Mac fills it in. We closed that gap with the translator the Mac already uses instead of a second one (f04e947 on main): On an iPhone 14 (Breath of the Wild 1.6.0, startup shaders turned off to force it): 606 variants translated in 2 minutes, none failed, translation plus Metal library median 141 ms, p90 442 ms; every MSL, SPIR-V and reflection file equals what the Mac's translator makes from the same requests. Being the same translator, its output and caches cannot drift from the Mac's, and there is one translation chain to fix and maintain. So we will not merge this PR; closing it with thanks. The idea and your measurements were what led to this. |
Summary
The iPhone / iPad app now compiles shaders itself. maxmetal (Maxwell to Metal Shading Language, plain C, MIT) is built into the app. When the game first asks for a variant the startup shaders lack, maxmetal translates it on the device and Metal compiles it there; the device keeps both. Before, such a variant was skipped until a Mac filled it in (
fill_shaders.py).iPhone apps without startup shaders.
build_app.py --platform ios --no-startup-shadersbuilds an app with none: the build skips about an hour of translating and compiling them, and every shader is translated and compiled on the fly on the device.Overlay. The shader box on the device gets a second line:
Compiled shaders N (X s) maxmetal N (X s). These are the Metal libraries compiled from MSL on the device this run and the variants maxmetal translated, each with its total time.The Mac keeps the Ryujinx translator. maxmetal is pinned in
build_app.py(MAXMETAL,919805d).Evidence
The shader compiler was tested successfully on the Mac and on an iPhone 13 (A15, iOS 26) with TOTK 1.4.3. The iPhone build used
--no-startup-shaders, so maxmetal translated every shader the game used.After: the game starts and renders with no startup shaders at all. "Missing shaders" stays at 0, and none of maxmetal's translations failed.
Time per shader on the iPhone, first launch (478 variants):
On the second launch the device's caches serve almost everything:
maxmetal at
919805dbuilds for the Mac and iOS; its golden tests pass 22/22 and the Metal compiles 18/18.python -m unittest discover -s tests: 1,302 tests OK (169 skipped).Merge Danger
Door: two-way
A build without
--no-startup-shadersis unchanged, except that a variant its startup shaders lack is translated instead of skipped. Reverting brings the skipping back. Translations that maxmetal has already left in a device's cache stay there and remain valid MSL.Blast Radius: iOS
rt-totk-native-v8-unverified), because its output is meant to be bit-identical. A later maxmetal pin does not invalidate what devices have cached.--no-startup-shaders, which is opt-in.totk_msl_library; its overlay is unchanged.