KhronosGroup / MoltenVK

MoltenVK is a Vulkan Portability implementation. It layers a subset of the high-performance, industry-standard Vulkan graphics and compute API over Apple's Metal graphics framework, enabling Vulkan applications to run on macOS, iOS and tvOS.
Apache License 2.0
4.76k stars 419 forks source link

Runtime dyld error on iOS 12 with MoltenVK xcframework #2240

Closed hrydgard closed 4 months ago

hrydgard commented 4 months ago

I'm linking the static xcframework into my app, which works great on newer iOS, but on iOS 12, I get the following:

dyld: Symbol not found: _OBJC_CLASS_$_MTLCaptureDescriptor

MTLCaptureDescriptor is an iOS 13 API.

The README.md clearly says that "At runtime, MoltenVK requires at least macOS 10.11, iOS 9.0, tvOS 9.0, or visionOS 1.0 (or iOS 11 or tvOS 11 if using IOSurfaces).".

This seems be a contradiction - you'd expect the precompiled binaries available in Releases to match what the README says.

I guess I'll have to go rebuild targeting iOS 12 and see if that helps?

hrydgard commented 4 months ago

image

I rebuilt MoltenVK with this setting, and linked to the newly produced binary.

Still the same - not working on iOS 12, working fine on newer iOS.

hrydgard commented 4 months ago

Dirty patch that fixes the issue, by simply commenting out the call:

        // Before macOS 10.15 and iOS 13.0, captureDesc will just be nil
        MTLCaptureDescriptor *captureDesc = nil; /* [[MTLCaptureDescriptor new] autorelease];
        captureDesc.captureObject = mtlCaptureObject;
        captureDesc.destination = MTLCaptureDestinationDeveloperTools;*/

The assertion in the comment clearly isn't right - it causes a linker error on iOS 12 rather than becoming nil.

Any ideas for a real patch? Also, it still doesn't actually work (aborts in VkCreateInstance), but my app launches and can stick with OpenGL on iOS 12 for now.

hrydgard commented 4 months ago

Seems I'll just disable Vulkan on iOS 12. Getting nonsensical crashes now:

bool mvkSupportsBCTextureCompression(id<MTLDevice> mtlDevice) {
#if MVK_XCODE_14_3 || (MVK_XCODE_12 && MVK_MACOS && !MVK_MACCAT)
    if ([mtlDevice respondsToSelector: @selector(supportsBCTextureCompression)]) { // << aborts here
        return mtlDevice.supportsBCTextureCompression;
    }
#endif
    return MVK_MACOS && !MVK_MACCAT;
}
billhollings commented 4 months ago

The README.md clearly says that "At runtime, MoltenVK requires at least macOS 10.11, iOS 9.0, tvOS 9.0, or visionOS 1.0 (or iOS 11 or tvOS 11 if using IOSurfaces).".

Yes. The documentation is definitely out of date. I'll update that.

In practice, we try to support as far back as current Xcode will build (currently macOS 10.15 & iOS 13), as marked in the target build settings (MoltenVK.xcodeproj).

To go back to iOS 12 and before, what version of Xcode are you using to build your app and MoltenVK?

And what is the error that occurs on the supportsBCTextureCompression crash. What feedback do you get?

hrydgard commented 4 months ago

I'm building with the very latest XCode. It doesn't seem to object to setting the target to 12.0 which is what I do from my CMakeLists.txt that I generate my XCode project from.

Though really, the only reason I'm setting it that far back is that I have an old iPad Air 2 which is interesting as an optimization target because it's so slow, and runs iOS 12 but nothing newer. But I should probably just bump my minimum up to 13.

As for the error, it was some obscure selector error. If it's really interesting I can try to reproduce it again. When I commented out supportsBCTextureCompression it crashed identically on the next thing, so I think it's an ABI mismatch of some sort, MoltenVK presumably being compiled for iOS 13 and something not being compatible. So now I don't even try to start up MoltenVK on iOS 12, I gated it on >= 13.

Anyway, I'll give up on MoltenVK on iOS 12.

billhollings commented 4 months ago

Yes. The documentation is definitely out of date. I'll update that.

In practice, we try to support as far back as current Xcode will build (currently macOS 10.15 & iOS 13), as marked in the target build settings (MoltenVK.xcodeproj).

PR #2242 includes these changes to the documentation.

billhollings commented 4 months ago

I'm building with the very latest XCode. It doesn't seem to object to setting the target to 12.0 which is what I do from my CMakeLists.txt that I generate my XCode project from.

Though really, the only reason I'm setting it that far back is that I have an old iPad Air 2 which is interesting as an optimization target because it's so slow, and runs iOS 12 but nothing newer. But I should probably just bump my minimum up to 13.

As for the error, it was some obscure selector error. If it's really interesting I can try to reproduce it again. When I commented out supportsBCTextureCompression it crashed identically on the next thing, so I think it's an ABI mismatch of some sort, MoltenVK presumably being compiled for iOS 13 and something not being compatible. So now I don't even try to start up MoltenVK on iOS 12, I gated it on >= 13.

Anyway, I'll give up on MoltenVK on iOS 12.

Okay. Thanks for the background explanation.

If it's really interesting I can try to reproduce it again.

No, that's definitely not needed. It would probably start a process of digging through an indefinite sequence of similar runtime errors. 😉