-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
macOS: fix initializing Vulkan surface when using gfx-portability #8724
macOS: fix initializing Vulkan surface when using gfx-portability #8724
Conversation
Since dolphin-emu#8666, when running Dolphin using gfx-portability instead of MoltenVK, it crashes with an exception: ``` $ LIBVULKAN_PATH=/usr/local/lib/libportability.dylib /Applications/Dolphin.app/Contents/MacOS/Dolphin 2020-04-05 21:05:53.416 Dolphin[73210:890862] -[CAMetalLayer layer]: unrecognized selector sent to instance 0x7fa0be67a710 2020-04-05 21:05:53.436 Dolphin[73210:890862] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CAMetalLayer layer]: unrecognized selector sent to instance 0x7fa0be67a710' *** First throw call stack: ( 0 CoreFoundation 0x00007fff30a16acd __exceptionPreprocess + 256 1 libobjc.A.dylib 0x00007fff5b11aa17 objc_exception_throw + 48 2 CoreFoundation 0x00007fff30a908d6 -[NSObject(NSObject) __retain_OA] + 0 3 CoreFoundation 0x00007fff309b893f ___forwarding___ + 1485 4 CoreFoundation 0x00007fff309b82e8 _CF_forwarding_prep_0 + 120 5 libportability.dylib 0x000000010c315758 _ZN17gfx_backend_metal8Instance26create_surface_from_nsview17h127760c1704de68dE + 72 6 libportability.dylib 0x000000010c284cff _ZN15portability_gfx5impls24gfxCreateMacOSSurfaceMVK17h9f931ad376c6842eE + 207 7 Dolphin 0x00000001009c8fd1 _ZN6Vulkan9SwapChain19CreateVulkanSurfaceEP12VkInstance_TRK16WindowSystemInfo + 65 ) libc++abi.dylib: terminating with uncaught exception of type NSException ``` This seems to be because `vkCreateWin32SurfaceKHR` expects an NSView (per the documentation), but after dolphin-emu#8666 it receives a CAMetalLayer. This PR fixes the crash by passing the CAMetalLayer-backed NSView instead.
Interesting! But how do you add gfx-portability to Dolphin.app ? |
For now gfx-portability dynamically replaces MoltenVK at runtime. You have to download a compiled release of gfx-portability, then run Dolphin with |
Wow! Amazing! Thanks! |
-1 for this. This was a deliberate choice, portability is in the wrong here. The swap chain is created on the video thread, which is not the UI thread. Calling any methods on the Portability should accept a layer pointer unless they are only interested in people creating swap chains on the UI thread. |
There is a new non MoltenVK specific extension to pass the CALayer: VK_EXT_metal_surface. I think the right fix would be to switch to that (and update Dolphin built-in MoltenVK). |
@galad87 I feel like that doesn't help the underlying issue, which is altering the view off the UI thread. You're still going to need to create a layer at some point, so unless portability is queusing it on the main/UI thread, it's not safe. While it might work in the current version, Apple has a history of restricting these sorts of things with OS updates, so what works now might not work in 6 months time. I'd rather just "do it properly". |
Of course, NSView is main-thread only, but the new VK_EXT_metal_surface extension defines a common way to pass a CALayer to Vulkan, and hopefully both MoltenVK and gfx-portability implements this extension correctly. Altering the NSView will continue to be a main-thread only operation anyway. |
Okay, great, we're on the same page then. I'll switch dolphin over to the extension then, it's due to update mvk anyway. |
If the performance improves significantly when gfx-portability is used instead of MoltenVK as the comments above suggest, perhaps the former should be included in Dolphin by default instead? |
@Zirro I'd rather use the Khronos-recommended/supported translation layer. It's not just about performance, compatibility matters too. But users should have the choice. |
I see, though I have a feeling that @kvark would be quite interested in sorting out any compatibility issues which may be uncovered. |
Well I just tested 2 games. My mac mini has a (crappy) Intel HD 4000 integrated GPU so not sure if everyone get the same results...it should be thorougly tested by other Mac users as well. |
You should test the latest version of MoltenVK too. |
Of course - and Dolphin has helped fix issues for both projects in the past. That's why the command-line override exists ;) I'd just prefer to stick with what is supported by the vendor as it's the lowest-risk option, considering none of our team actively develops for macOS and Dolphin's support for it is basically on life support at the moment. Unless someone wants to take on the platform maintainer role :) |
See #8728 |
We can and will work around this in gfx-portability-0.8 release. |
(a more detailed answer as I caught up to the discussion) Passing We made In the meantime, we are changing our implementation of |
No, I've been testing a lot of stuff recently in gfx-rs/portability#210 (comment) and didn't find any other case that would need that. It's still a relatively harmless hack, and I'm ok to have it given that the whole |
Okay, fair enough. I wish someone told me about the extension earlier, since I'm not following any MVK/Portability changes, and I would have already switched it over with the fixes for Qt 5.14 last month! :) |
Could yuzu's recent macOS pull request benefit from your code ? Would be great ;-) |
Superseded by #8728. |
Since #8666, when running Dolphin using gfx-portability instead of MoltenVK, it crashes with an exception:
This seems to be because
vkCreateWin32SurfaceKHR
expects an NSView (per the documentation), but after #8666 it receives a CAMetalLayer.This PR fixes the crash by passing the CAMetalLayer-backed NSView instead. Running Dolphin with gfx-portability runs fine after this.
Note of gfx-portability
On a 2013 Macbook / Iris 5100, gfx-portability gives a substantially better framerate than MoltenVK (around ~10 FPS). At some point I remember it also had better frame pacing. So I'm quite eager to keep Dophin working with gfx-portability :)