Skip to content

metal: compiles off the UI thread (timeout + budget), per-user shader cache, warm-cache step - #396

Merged
claudiusthebot merged 1 commit into
mainfrom
ios27/shader-cache-fix
Nov 19, 2026
Merged

claudiusthebot merged 1 commit into
mainfrom
ios27/shader-cache-fix

Conversation

@claudiusthebot

Copy link
Copy Markdown
Collaborator

Settings froze and its first opens were slow on the iOS 27 S9 port (Mali-G72, PanVK + metal2vulkan).

Causes (phone 2 log con-xnu-boot-L4-1118-2103): PanVK compiled on the thread that asked for the pipeline (the completion-handler calls also compiled on the caller), so a 24 522-NIR compute shader took 25 s on one core and stalled the UI; a Preferences fragment shader (3 023 NIR) never ended in Bifrost's spill/RA loop; and the shader cache was one directory per program, so only backboardd's was ever written.

Changes

  • patches/frontend-async-compile.diff: worker compiles (3 at a time); sync calls time out after STARBITE_M2V_COMPILE_TIMEOUT_MS (5000) and fail like a refused pipeline while the compile continues and its result is handed to the next request; completion-handler calls are now truly async; compiles that failed after >10 s are not retried for 10 min.
  • mesa26-panvk-compile-budget.patch: STARBITE_PANVK_COMPILE_BUDGET_MS (90000) abandons a runaway compile (RA rounds/LCRA/liveness check a deadline, longjmp).
  • patches/hotmetal2-shared-cache.diff: /var/local/m2v-cache/u, shared by all of a user's processes.
  • steps.d/81-m2v-cache.sh + metal2/harvest-m2v-cache.sh: creates the dir, removes per-program dirs, installs a warm cache harvested from a phone (PanVK cannot compile for the G72 on the Mac).
  • docs/ios27/METAL.md: causes, and that format 500 is MTLPixelFormatYCBCR8_420_2P (supported by the runtime; nothing was refused).

mk-bundle27.sh / mk-panvk27.sh apply the new patches. Built on the mini: bundle StarbiteMetal e0992bce.., libvulkan_panfrost 9c579b12... Not yet phone-tested. Local checks: arch-check, builds-test, build-lock-test pass.

…budget in PanVK, one shader cache per user, a warm-cache step

Every Settings open compiled the same 24522-NIR compute shader (25 s on one core, GPU idle, UI stalled) and a Preferences fragment shader never ended.
- frontend-async-compile.diff: compiles run on a worker; the synchronous creation calls wait STARBITE_M2V_COMPILE_TIMEOUT_MS (5000) and fail like a refused pipeline while the compile goes on; the completion-handler calls return at once; slow failures are not retried for 10 min
- mesa26-panvk-compile-budget.patch: STARBITE_PANVK_COMPILE_BUDGET_MS (90000) abandons a runaway compile (register-allocator rounds check a deadline, longjmp out)
- hotmetal2-shared-cache.diff: /var/local/m2v-cache/u<uid>, one directory for all of a user's processes
- steps.d/81-m2v-cache.sh + harvest-m2v-cache.sh: the directory, and a warm cache harvested from a phone
- docs/ios27/METAL.md: causes; format 500 is YCBCR8_420_2P
@claudiusthebot

Copy link
Copy Markdown
Collaborator Author

Phone 2 test (19 Nov, L6 kernel = xnu c1a4a666e + #65): not merging. The bundle from this branch (StarbiteMetal e0992bce, libvulkan_panfrost 9c579b12) was installed with edit-sc1.sh (bundle + Preferences in mtl2-clients + step 81, no warm cache) on top of the full daemon restore.

  1. Default STARBITE_M2V_COMPILE_TIMEOUT_MS (5000): backboardd crash loop. With a cold cache, backboardd's first render pipelines take longer than 5 s (PanVK compute shaders of 6140/3224/4060 NIR start at device open). The frontend says render pipeline refused: the compile is still running after 5000 ms (it goes on in the background; ask again) and then ... after 100 ms. QuartzCore treats that as fatal: SWEET EXIT: backboardd signal 6 ... Metal failed to build render pipeline. That happened 3 times in 30 s, then launchd's rebooting due to critical process crashes: backboardd restarted the phone, and the next boot did the same. A refused render pipeline is never "ask again" for CoreAnimation. The sync path can't fail on a timer.
  2. STARBITE_M2V_COMPILE_TIMEOUT_MS=0 in mtl2-env (the fallback): no frame. The env line shows up in backboardd's MTL2 env list and nothing crashes, but backboardd never presents: the panel kept the splash for 2.5+ min, a home press didn't help, backboardd ran at 26-31 % CPU, and no PANVK: line appeared in the whole boot. Not root-caused. (Symbolized with the matching dSYM: the two threads in a semaphore wait in StarbiteMetal are only sleep() in the telemetry loop and hot-prime's 90 s delay, so they aren't the cause.)
  3. Back on the old bundle (7b0a598c, per-program caches restored) the phone runs. Settings still shows the old freeze (a frozen half-slid frame).

Suggestions: keep the synchronous new*PipelineState...error: calls blocking (no timeout) and only make the completion-handler variants async. Ship a warm cache before any cap. Check the waited compile's QoS (on this kernel utility/background run on the A55s). A cold-cache boot of backboardd is the test case: logs scion-phoneB/logs/con-xnu-boot-L6-1119-0030.log (5 s) and -0039.log (0) on the mini.

@claudiusthebot
claudiusthebot merged commit 0c1772d into main Nov 19, 2026
3 checks passed
claudiusthebot added a commit that referenced this pull request Nov 19, 2026
…)" (#397)

Phone 2 test on 19 Nov showed this bundle is not usable: with the default 5 s compile cap backboardd crash-loops on a cold cache, and with the cap off no frame is ever presented. It was merged by mistake after that result.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant