ryanmyers: Improve logging for Metallib function lookup failures (#7836)
If a .metallib was compiled with a target iOS version that's newer than the current device, loading the .metallib may succeed, but finding main0 (or any other function in it) will fail. Currently, this causes a crash due to an assert. Logging the error and returning MetalFunctionBundle::error() makes the crash slightly easier to diagnose. (Note that in practice, this will probably be a useless "Compiler encountered an internal error" message -- the GPU backend is crashing, and the Metal stub library sees XPC_ERROR_CONNECTION_INTERRUPTED. It retries up to 3 times (crashing each time) and then gives up.)
This commit is contained in:
@@ -169,6 +169,23 @@ bool MetalShaderCompiler::isParallelShaderCompileSupported() const noexcept {
|
||||
id<MTLFunction> function = [library newFunctionWithName:@"main0"
|
||||
constantValues:constants
|
||||
error:&error];
|
||||
if (function == nil) {
|
||||
// If the library loads but functions within it fail to load, it usually means the
|
||||
// GPU backend crashed. (This can happen if it's a Metallib shader that was compiled
|
||||
// with a minimum iOS version that's newer than this device.)
|
||||
NSString* errorMessage = @"unknown error";
|
||||
if (error) {
|
||||
auto description =
|
||||
[error.localizedDescription cStringUsingEncoding:NSUTF8StringEncoding];
|
||||
utils::slog.w << description << utils::io::endl;
|
||||
errorMessage = error.localizedDescription;
|
||||
}
|
||||
PANIC_LOG("Failed to load main0 in Metal program.");
|
||||
NSString* programName =
|
||||
[NSString stringWithFormat:@"%s::main0", program.getName().c_str_safe()];
|
||||
return MetalFunctionBundle::error(errorMessage, programName);
|
||||
}
|
||||
|
||||
if (!program.getName().empty()) {
|
||||
function.label = @(program.getName().c_str());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user