From 3923b82efaea4b9de12517f892633b2c8be37e06 Mon Sep 17 00:00:00 2001 From: Jelly10086 Date: Sat, 14 Nov 2026 18:25:57 +0900 Subject: [PATCH] fix(metal): Distinguish missing library functions from specialization errors --- NativeBridgeMetalFrontend.mm | 22 ++++++++++++++++++++-- README.md | 2 ++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/NativeBridgeMetalFrontend.mm b/NativeBridgeMetalFrontend.mm index c955d67..1632143 100644 --- a/NativeBridgeMetalFrontend.mm +++ b/NativeBridgeMetalFrontend.mm @@ -1661,6 +1661,20 @@ static std::string quartzCoreCallers(); // no runtime handle: it is stitched from its bitcode (functionBitcode) and refused as a pipeline's own function. static NBFunction *ciKernelFunction(NBLibrary *library,NSString *name); static bool forEachLibraryEntry(NBLibrary *library,const std::function &visit); +static NSError *functionLookupError(NBLibrary *library, NSString *name, NSString *detail) { + const char *wanted = name.UTF8String; + bool found = false; + // Core Image can search several libraries for the same kernel. Keep a missing + // function distinguishable from a failure to specialize a function that exists. + if(wanted && forEachLibraryEntry(library,[&](const std::string &entry,int) { + found = entry == wanted; + return !found; + }) && !found) { + return [NSError errorWithDomain:MTLLibraryErrorDomain code:MTLLibraryErrorFunctionNotFound + userInfo:@{NSLocalizedDescriptionKey:detail}]; + } + return nbError(detail); +} @implementation NBLibrary - (void)dealloc {DetailSpan timing(9,(uintptr_t)_handle);nmb_library_release(_handle);} - (id)newFunctionWithName:(NSString *)name constantValues:(MTLFunctionConstantValues *)values error:(NSError **)error { @@ -1706,7 +1720,8 @@ static bool forEachLibraryEntry(NBLibrary *library,const std::function)function; @@ -1720,7 +1735,10 @@ static bool forEachLibraryEntry(NBLibrary *library,const std::function)newFunctionWithDescriptor:(MTLFunctionDescriptor *)d error:(NSError **)error { if(!d.name){if(error)*error=nbError(@"a function name is required");return nil;} NBFunction *function=(NBFunction *)(d.constantValues?[self newFunctionWithName:d.name constantValues:d.constantValues error:error]:[self newFunctionWithName:d.name]); - if(!function){if(error && !d.constantValues)*error=nbError([NSString stringWithFormat:@"function %@: %@",d.name,lastError()]);return nil;} + if(!function){ + if(error && !d.constantValues)*error=functionLookupError(self,d.name,[NSString stringWithFormat:@"function %@: %@",d.name,lastError()]); + return nil; + } if(d.specializedName) { if(function.handle && !nmb_function_set_specialized_name(function.handle,d.specializedName.UTF8String)) { if(error)*error=nbError(lastError());return nil; diff --git a/README.md b/README.md index ffd2bca..9f17e3e 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ The frontend uses metal2vulkan and Turnip with the kernel GPU interface and sele All clients use single-sample rendering by default. `NATIVE_METAL_SINGLE_SAMPLE=0` preserves a process's requested sample counts; `1` forces single-sample rendering. Texture types, pipeline sample counts and resolve outputs follow the selected policy. Same-user clients share writable shader caches. Resource aliasing, swizzles, range copies, function constants, specialized link names and allocation queries reach the runtime. Queue priorities aggregate current live requests without a process-name policy. +Function lookup returns `MTLLibraryErrorFunctionNotFound` when the requested name is absent from the library. + Build and interface details: [documentation](https://unixnu.com/drivers/adreno-metal). Component sources and dependencies: [catalog](https://unixnu.com/reference/components). ## Memory reuse