diff --git a/common/Vulkan/SwapChain.cpp b/common/Vulkan/SwapChain.cpp index 5f303cde88..fc0d6834d0 100644 --- a/common/Vulkan/SwapChain.cpp +++ b/common/Vulkan/SwapChain.cpp @@ -29,6 +29,27 @@ #if defined(__APPLE__) #include +#ifdef __i386__ +typedef float CGFloat; +#else +typedef double CGFloat; +#endif + +template +Ret msgsend(Self self, const char* sel, Args... args) +{ + void (*fn)(void) = objc_msgSend; +#ifdef __i386__ + if (std::is_same::value || std::is_same::value || std::is_same::value) + fn = objc_msgSend_fpret; +#endif +#ifdef __x86_64__ + if (std::is_same::value) + fn = objc_msgSend_fpret; +#endif + return reinterpret_cast(fn)(self, sel_getUid(sel), args...); +} + static bool CreateMetalLayer(WindowInfo* wi) { id view = reinterpret_cast(wi->window_handle); @@ -41,7 +62,7 @@ static bool CreateMetalLayer(WindowInfo* wi) } // [CAMetalLayer layer] - id layer = reinterpret_cast(objc_msgSend)(objc_getClass("CAMetalLayer"), sel_getUid("layer")); + id layer = msgsend(clsCAMetalLayer, "layer"); if (!layer) { Console.Error("Failed to create Metal layer."); @@ -49,19 +70,19 @@ static bool CreateMetalLayer(WindowInfo* wi) } // [view setWantsLayer:YES] - reinterpret_cast(objc_msgSend)(view, sel_getUid("setWantsLayer:"), YES); + msgsend(view, "setWantsLayer:", YES); // [view setLayer:layer] - reinterpret_cast(objc_msgSend)(view, sel_getUid("setLayer:"), layer); + msgsend(view, "setLayer:", layer); // NSScreen* screen = [NSScreen mainScreen] - id screen = reinterpret_cast(objc_msgSend)(objc_getClass("NSScreen"), sel_getUid("mainScreen")); + id screen = msgsend(objc_getClass("NSScreen"), "mainScreen"); // CGFloat factor = [screen backingScaleFactor] - double factor = reinterpret_cast(objc_msgSend)(screen, sel_getUid("backingScaleFactor")); + CGFloat factor = msgsend(screen, "backingScaleFactor"); // layer.contentsScale = factor - reinterpret_cast(objc_msgSend)(layer, sel_getUid("setContentsScale:"), factor); + msgsend(layer, "setContentsScale:", factor); // Store the layer pointer, that way MoltenVK doesn't call [NSView layer] outside the main thread. wi->surface_handle = layer;