Porting a Vulkan game engine to macOS in one day
The author ported the Vulkan game engine he wrote in Zig[1] for his roguelike deckbuilder Now You're Cooking! to aarch64 and x86_64 macOS. He got the game running on the first day with a borrowed MacBook, then spent two more days cleaning up the build process. Deploying from Linux, Windows or macOS now takes four steps, and running zig build deploy cross-compiles the game for all platforms and uploads it to Steam.
Apple does not support Vulkan, so the port relies on translation layers. MoltenVK[2] is a widely supported Vulkan implementation on top of Metal that is not fully conformant, while KosmicKrisp[3] is conformant but needs a newer Mac. The app bundle includes both, with the ICD paths changed to fit the bundle structure, and SDL is told where to find the bundled Vulkan library. Device selection first failed because non-conformant devices are hidden by default, so the author requested the portability enumeration extension and removed render features that were not guaranteed to work.
After shipping, the author found one bug. On x86_64 Macs with a discrete AMD GPU, MoltenVK's translation made 0xFF color components decode to about 0.99999970197 instead of 1, which broke one shader. The workaround compares the integer value before unpacking, and the author filed an issue upstream. He has not found the bug on newer Apple hardware with MoltenVK or on machines running KosmicKrisp.
Read the original gamesbymason.comDiscussion
Sources
-
Games by Mason
I ported my Vulkan game engine to macOS in one day







