From 42817287d7c24fca889a2781eb340c2fa72152ac Mon Sep 17 00:00:00 2001 From: bluseliu50 <265648257+bluseliu50@users.noreply.github.com> Date: Thu, 22 Oct 2026 21:54:39 +0800 Subject: [PATCH] feat(plugin): report a client process's first Metal problem --- NativeAdrenoMetalPlugin.mm | 12 ++++++++++++ NativeBridgeMetalFrontend.h | 2 ++ NativeBridgeMetalFrontend.mm | 8 ++++++++ 3 files changed, 22 insertions(+) diff --git a/NativeAdrenoMetalPlugin.mm b/NativeAdrenoMetalPlugin.mm index 94da850..13260c9 100644 --- a/NativeAdrenoMetalPlugin.mm +++ b/NativeAdrenoMetalPlugin.mm @@ -194,6 +194,18 @@ static id clientDevice(unsigned port) { if (!device && !lastError[0]) lastError = nmb_last_error(); } if (!device) clientFailure(port, usable ? "no-device" : "no-cachedir", lastError); + // The client's first problem, once, on the same text line: WidgetRenderer crashed on a nil render encoder with no reason anywhere readable + // (its own log lines need the plugin's format strings, which the device does not keep). Checked every second for ten minutes. + if (device) { + dispatch_async(dispatch_get_global_queue(QOS_CLASS_UTILITY, 0), ^{ + for (unsigned second = 0; second < 600; ++second) { + char problem[200] = {}; + const uint64_t count = native_bridge_metal_first_problem(problem, sizeof problem); + if (count) {clientFailure(port, "problem", problem); return;} + sleep(1); + } + }); + } return device; } static id deviceForPort(unsigned port) { diff --git a/NativeBridgeMetalFrontend.h b/NativeBridgeMetalFrontend.h index 5c0c7ca..d7dabfc 100644 --- a/NativeBridgeMetalFrontend.h +++ b/NativeBridgeMetalFrontend.h @@ -15,6 +15,8 @@ id native_bridge_metal_library_with_air(const void *bytes, size_t length); size_t native_bridge_metal_status(char *out, size_t size); // The pixel formats of the textures asked for (first eight distinct) and how many texture requests the runtime refused. size_t native_bridge_metal_formats(char *out, size_t size); +// The process's first problem (a refusal or a missing call) into out, and how many problems there were. +uint64_t native_bridge_metal_first_problem(char *out, size_t size); size_t native_bridge_metal_telemetry(char *out, size_t size); // Structured cumulative artifact/driver-cache counters for offline qualification. struct NmbShaderCacheStats; diff --git a/NativeBridgeMetalFrontend.mm b/NativeBridgeMetalFrontend.mm index ad7f7a4..d275298 100644 --- a/NativeBridgeMetalFrontend.mm +++ b/NativeBridgeMetalFrontend.mm @@ -63,9 +63,12 @@ extern "C" unsigned native_bridge_metal_recent_commits(uint64_t windowUs) { } static std::mutex gProblemLock; static char gLastProblems[2][200]; +// The process's first problem, kept: a client process has no telemetry table, and its first refusal is usually the cause of the rest. +static char gFirstProblem[200]; static void noteProblem(NSString *what) { gProblems++; std::lock_guard lock(gProblemLock); + if(!gFirstProblem[0])strlcpy(gFirstProblem,what.UTF8String?:"?",sizeof gFirstProblem); memcpy(gLastProblems[1],gLastProblems[0],sizeof gLastProblems[0]); strlcpy(gLastProblems[0],what.UTF8String?:"?",sizeof gLastProblems[0]); } @@ -1781,6 +1784,11 @@ extern "C" size_t native_bridge_metal_telemetry(char *out,size_t size) { return at; } +extern "C" uint64_t native_bridge_metal_first_problem(char *out,size_t size) { + std::lock_guard lock(gProblemLock); + if(size)strlcpy(out,gFirstProblem,size); + return gProblems.load(); +} extern "C" size_t native_bridge_metal_formats(char *out,size_t size) { std::lock_guard lock(gProblemLock); return native_bridge_metal_formats_locked(out,size);