-
Notifications
You must be signed in to change notification settings - Fork 12
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
vulkan-api on macOS should use libvulkan instead of libMoltenVK by default, and ideally the same lib as the one GLFW already loaded #24
Comments
Discovered related bsl/bindings-GLFW#61. So I was on the right track, though I'm still puzzled how the author of vulkan-api worked around that when testing with MoltenVK. I tried inserting current glfw C code from github into bindings-GLFW, but this doesn't compile. As suggested in bsl/bindings-GLFW#64 there is more work needed on this. |
See #20. The bindings were built and tested but binaries weren't run via GLFW. I think bsl/bindings-GLFW#64 was mostly done with the needed api updates to support a recent commit of GLFW. If you pick this work up, let me know how you fare. |
I'm on it. I finished the changes to GLFW.hsc that you already started, though I didn't check if there were more C functions to add. A small change to GLFW-b was necessary because of some removed functions. GLFW now finds MoltenVK, but I get another error:
I'm haven't figured out the cause yet, and am not sure which repos the fix to this will touch. To share my changes, should I fork your fork of bindings-GLFW to later address a pull request to you, or is it better to fork the original bindings-GLFW myself and pull your commits into that? |
Great job @cjay , thanks for moving this forward! Regarding the validation layers: Just to check if the whole thing working at all, you can disable them; for example, by switching off cabal flag To go deeper, check out this thread on reddit. |
The latter would be easiest, yes? Cool! |
Forks are at https://github.com/cjay/bindings-GLFW/tree/Upgrade-3.3 and https://github.com/cjay/GLFW-b/tree/Upgrade-3.3 After turning off the validation layer now I'm stuck with:
Interestingly the call Not sure I'm doing the whole linking thing right. Bindings-GLFW only seems to find MoltenVK when i put all the .dylib files from the SDK (including libMoltenVK.dylib and libvulkan.dylib) into the working directory. Edit: This is the error that seems to be happening, I don't know why the error message doesn't get displayed:
I hope you don't get spammed with notification mails because of my edits :) |
Correction: with
Edit: When I change "frameworks: MoltenVK" of |
Found out that the Vulkan loader searches for ICDs in OS-specific locations, and that MoltenVK is an ICD. Used the VK_ICD_FILENAMES env variable to get the loader to use MoltenVK. Now the expected extensions are present, including
So the loader can't find vkCreateMacOSSurfaceMVK despite the MoltenVK related extension being present. The symbol _vkCreateMacOSSurfaceMVK is present in the text sections of both libvulkan.dylib and libMoltenVK.dylib though. |
Hmm, can you check which extensions lists |
I’m on mobile, but there’s an issue on GLFW under mojave that throws a similar error. Check the issues on the repo — I remember there was a work around. |
I checked the glfw issues and found similar problems. This one "solved" it by avoiding static linking to the vulkan frameworks, but I already don't link statically. I removed the frameworks and .a files to be sure. Here someone had the analogue problem on Windows, also solved by dynamic linking. I also found a related issue in Vulkan-Docs. Haven't read every comment there, but what I read didn't help. This comment points out "All remaining functions will be loaded by a delegate VkCreateInstance function, which loads everything else using GetInstanceProcAddr and a valid, fresh and not NULL instance." but as far as I can tell this is already happening. The call I also tried using I also tried
This is absurd. And it can't even find the lib when it's in the working dir now. I think the options are now:
Please let me know if you can think of any other ideas, I think I'll take a look at the loader first 😕 |
That is rather unfortunate situation :( I may have messed up a bit cabal settings for the osx static linking; but the only thing you can specify there is the framework name (and then make sure the framework is visible in your build environment). I would try to go full dynamic: ask GLFW to link vulkan stuff dynamically, and disable all "useNativeFFI" flags and also disable all extension-related flags in vulkan-api/examples. This way, you are confident that all calls are done via I would suggest to try two things to know for sure if the error is on Vulkan/GLFW/vulkan-api side:
|
tl;dr: Making GLFW use libMoltenVK directly forgoes the Vulkan loader and displaying triangles works, but MVK alone is no full Vulkan implementation. The loader seems to mess it up despite finding the MoltenVK ICD. Finally some success. ve-01-CreateInstance worked as it should, and I saw that vulkan-api dlopens libMoltenVK.dylib instead of libvulkan.1.dylib. This gave me the idea to change the glfw code in vulkan.c to load libMoltenVK.dylib instead of libvulkan.1.dylib. With that change the vulkan-triangles example works. And vulkan-api doesn't even need the flag However this is only a workaround. As the SDK documentation states:
And the MoltenVK documentation states:
As I understand it, directly loading libMoltenVK.dylib forgoes the Vulkan loader, and because of that layers can't be used. As expected, I still need to comment out VK_LAYER_LUNARG_standard_validation in Instance.hs of vulkan-triangles for it to work. I still need to try C examples to narrow down the location of the problem. Other observations:
|
A sidenote: the purpose of So, do I understand correctly, that |
Yes, by changing this line of bindings-GLFW to use
I had not tested both cases with 01-CreateInstance, but yes it does work with both. Thanks to this question I found the solution though! GLFW loaded libvulkan and vulkan-api loaded libMoltenVK, and mixing both is bad. I had wrongly assumed that vulkan-api would just use whatever GLFW had loaded already. When both use libvulkan, everything works now, including the standard validation layer. Can you change vulkan-api to detect which lib has already been loaded? I'm not sure if this his feasible. Otherwise the documentation should warn about this problem. The default lib to load should definitely be libvulkan though. |
Aha, so this really is a Even though quick googling tells that the detection is possible, I think it's going to be more confusing. A user technically can make the first call to Vulkan earlier than to GLFW or other window manager (even though in our case we always call GLFW first to get the list of required extensions). Maybe, I should add something like an environment variable to override the name of the Vulkan-providing library?.. Anyway, it seems to be an universal agreement to load the Vulkan loader rather than ICD, so we definitely need to change the loader shim as you suggested. Could you please do that and also add some instructions how to render triangles on macOS to the readme? Maybe also add something like |
Linking to the Vulkan loader on macOS, fixes #24
I have tried a lot of things trying to get vulkan-examples (executable ve-06-Drawing) to work with MoltenVK on macOS, but always get the error "ve-06-Drawing: VulkanException {vkeCode = Nothing, vkeMessage = "GLFW reports that vulkan is not supported!"}". It would be awesome if the README had instructions on how to pull that off. I'm assuming this is possible because the README claims that vulkan-api is tested with MoltenVK.
System: macOS 10.14.3
cabal-install and Cabal version: 2.4.1.0
ghc: 8.6.4
Things I tried:
I think that static linking to the frameworks doesn't work because the C code is built without cmake which would define _GLFW_VULKAN_STATIC. This define is queried in vulkan.c. Interestingly this file only mentions .dll and .so files as parameters to dlopen, not .dylib. But I'm probably missing something.
The text was updated successfully, but these errors were encountered: