Skip to content
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

Fix Vulkan/MoltenVK on macOS yet again #8666

Merged
merged 5 commits into from Mar 12, 2020

Conversation

stenzek
Copy link
Contributor

@stenzek stenzek commented Mar 11, 2020

Well, this was a fun debugging experience. At least it wasn't as borked as the last time.

Basically, the auto-fill-background stuff changing out paint engines broke on Qt 5.14. I'm swapping this out with a better method - letting the graphics backend take care of clearing the screen instead. The downside is there will be a slightly longer delay before it is cleared as the graphics API needs to initialize, but it's much cleaner code-wise.

It also now passes the layer to MoltenVK instead of the view, which prevents [NSView layer] from being called off the main thread. Which currently is just a warning, but with the way Apple seems to be going at some point in the future it'll probably become an error, and cause Dolphin to crash, so better safe than sorry.

... hopefully this stays working for a while this time. I don't like debugging Mac issues :(

We need this because we need to pass the layer to MoltenVK, not
the view handle. But the input subsystem still needs the window.
Gets rid of the warning for calling [NSView layer] off the main thread.
This is related to https://bugs.dolphin-emu.org/issues/10958 which
uses Qt to clear out the window so the game list isn't displayed
while the core is booting. Instead, we use the video backend to
render a black screen, which means Qt doesn't have to flip between
paint engines.
We no longer need this since the video backend handles clearing the
window, and it fixes MoltenVK with Qt 5.14.
Copy link
Contributor

@spycrab spycrab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM

@pizuz
Copy link

pizuz commented Mar 11, 2020

Working as advertised. The delay is barely noticeable. Thank you.

@gilcel
Copy link

gilcel commented Mar 12, 2020

Well done! I confirm that it fixes issue #12002.
Thanks for this!

@JMC47 JMC47 merged commit 15acce8 into dolphin-emu:master Mar 12, 2020
kemenaran added a commit to kemenaran/dolphin that referenced this pull request Apr 5, 2020
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants