From 9e651a52c721b2b460270a34470dfd26fee20376 Mon Sep 17 00:00:00 2001 From: bluseliu50 <265648257+bluseliu50@users.noreply.github.com> Date: Tue, 10 Nov 2026 15:51:45 +0800 Subject: [PATCH] fix: keep the shader cache inside Metal's cache directory In the user cache directory the pipeline cache now sits in com.apple.metal/m2v. A sandboxed process may write there whenever its profile lets Metal cache shaders. macOS's iconservicesagent could not write /m2v (thousands of denials), compiled every pipeline again at each launch and was killed at its memory limit within seconds, over and over. Not run on hardware yet. --- NativeAdrenoMetalPlugin.mm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/NativeAdrenoMetalPlugin.mm b/NativeAdrenoMetalPlugin.mm index 47d9348..f19bab8 100644 --- a/NativeAdrenoMetalPlugin.mm +++ b/NativeAdrenoMetalPlugin.mm @@ -198,6 +198,11 @@ static id clientDevice(unsigned port) { for (unsigned i : {2u, 0u, 1u}) { if (device) break; if (!candidates[i][0]) continue; + // In the user cache directory the cache sits inside Metal's own shader cache directory (com.apple.metal): a sandboxed process may + // write there whenever its profile lets Metal cache shaders at all (macOS iconservicesagent: its profile allows METAL_CACHE_PATH + // and denied every write to /m2v, so each of its launches compiled every pipeline again and it was killed at its memory + // limit within seconds). + if (i == 0) {strlcat(candidates[i], "com.apple.metal", sizeof candidates[i]); mkdir(candidates[i], 0700); strlcat(candidates[i], "/", sizeof candidates[i]);} if (i != 2) strlcat(candidates[i], "m2v", sizeof candidates[i]); mkdir(candidates[i], 0700); if (access(candidates[i], W_OK) != 0) continue; @@ -458,6 +463,7 @@ static id deviceForPort(unsigned port) { for (unsigned i : order) { if (device) break; if (!candidates[i][0]) continue; + if (i == 0) {strlcat(candidates[i], "com.apple.metal", sizeof candidates[i]); mkdir(candidates[i], 0700); strlcat(candidates[i], "/", sizeof candidates[i]);} // as for the clients below if (i != 5) strlcat(candidates[i], "m2v", sizeof candidates[i]); mkdir(candidates[i], 0700); if (access(candidates[i], W_OK) != 0) continue;