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

MacOS support progress/discussion #31

Open
johanhenriksson opened this issue Mar 10, 2023 · 6 comments
Open

MacOS support progress/discussion #31

johanhenriksson opened this issue Mar 10, 2023 · 6 comments

Comments

@johanhenriksson
Copy link

So I managed to get a bit further on MacOS support tonight.

  • Modified sample 01 to use GLFW for cross-platform window management
  • Successfully created a VkSurfaceKHR handle from the GLFW window

To get it working I had to change the default library name from libMoltenVK.dylib to the standard libvulkan.1.dylib. I havent looked into it, but i seem to recall that being correct for newer versions of MVK.

I'm currently stuck at a crash in vk.GetPhysicalDeviceSurfaceSupportKHR, with the output

libc++abi: terminating with uncaught exception of type std::__1::system_error: mutex lock failed: Invalid argument
SIGABRT: abort

I'm not sure what's causing it, but I'm a little bit suspicious towards the use of dlsym for loading function pointers. As far as I can tell the recommended way is to use vkGetInstanceProcAdd and vkGetDeviceProcAddr, and other platform-specific methods are not supported except as a way to locate those two methods.

@bbredesen
Copy link
Owner

Do you have a public fork of the samples w/ your changes? I just generated (locally) on mac against 1.2.177. Sample 0 runs successfully for me, but I would like to duplicate the error what you are seeing.

@johanhenriksson
Copy link
Author

johanhenriksson commented Mar 12, 2023

@bbredesen I pushed a draft PR in the samples repo. Haven't had a chance to keep working on it.

Sample 00 works fine for me too without any changes (besides removing the error strings), the problems occur in sample 01. Would be cool if you can test the GLFW version on windows too, at least some of that code could be useful for cross platform support :)

@bbredesen
Copy link
Owner

I ran into a ton of issues trying to use GLFW too. GLFW is taking the instance parameter as an interface{} and then using reflection to determine if the handle is a pointer, so I'm wondering if GLFW is doing something weird with Vulkan handles. Dispatchable handles are pointers to a function dispatch table in Vulkan, but intended to be opaque to the programmer, so I don't know why GLFW wants the handle to be a pointer type.

I didn't want to dig too deeply into GLFW so I've adapted the "shared" win32 code to also work with Cocoa, calling out to Objective-C. The good news is that go-vk seems to work just fine on Mac:

Screen Shot 2023-03-16 at 12 57 44 PM

I ended up refactoring the whole shared window message model, with impact on how the individual samples setup and start the window. I'm going to push a new branch to [go-vk-samples] shortly, with the caveat that only the basic triangle sample will compile at the moment, so I haven't done much testing yet.

Solving GLFW+go-vk may end up being a requirement though...it is a well-known and commonly used library, and probably a lot of people's first choice to quickly open a opengl or vulkan window on their platform.

@bbredesen
Copy link
Owner

bbredesen commented Mar 16, 2023

And also note that I generated a local copy of vk-go against 1.2.203 (last 1.2 revision of vk.xml), with -platform="win32,macos,metal". I'll also push a branch of go-vk for 1.2.

Branch: https://github.com/bbredesen/go-vk/tree/1.2.203-darwin

@johanhenriksson
Copy link
Author

Really cool, nice work!

And yeah, this is pretty much the exact use case for GLFW and avoiding it will involve basically re-implementing it, so its probably worth the effort. If it turns out to be too annoying, another idea is to try using SDL2 for cross platform windowing first.

Anyway, CreateWindowSurface seems to be the only (Go) GLFW function that deals with VkInstance handles, so I don't think there can be too much weird things going on in the background. Im guessing the code

(C.VkInstance)(unsafe.Pointer(reflect.ValueOf(instance).Pointer()))

is just a trick to allow any Go object to be cast to a VkInstance, and in order for that to work, we have to pass a pointer to the function. Also, since I managed to get it to create a surface successfully this way, I don't think theres anything sketchy going on here.

@bbredesen
Copy link
Owner

The rest of the samples have been updated on the shared-framework-update branch and now run on (my) mac.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants