diff --git a/SDL/SDLCocoaMetalLayer.mm b/SDL/SDLCocoaMetalLayer.mm index ce1b9cd206..d0df82716b 100644 --- a/SDL/SDLCocoaMetalLayer.mm +++ b/SDL/SDLCocoaMetalLayer.mm @@ -1,10 +1,16 @@ +#if defined(PPSSPP_PLATFORM_MAC) #import +#else +#import +#endif #import #include "base/logging.h" #include "SDLCocoaMetalLayer.h" void *makeWindowMetalCompatible(void *window) { + // https://github.com/KhronosGroup/MoltenVK/issues/78#issuecomment-371118536 +#if defined(PPSSPP_PLATFORM_MAC) NSView *view = ((NSWindow *)window).contentView; assert([view isKindOfClass:[NSView class]]); @@ -13,4 +19,19 @@ void *makeWindowMetalCompatible(void *window) { [view setLayer:[CAMetalLayer layer]]; } return view.layer; +#else + UIView *view = (UIView *)window; + assert([view isKindOfClass:[UIView class]]); + + CAMetalLayer *metalLayer = [CAMetalLayer new]; + + CGSize viewSize = view.frame.size; + metalLayer.frame = view.frame; + metalLayer.opaque = true; + metalLayer.framebufferOnly = true; + metalLayer.drawableSize = viewSize; + metalLayer.pixelFormat = (MTLPixelFormat)80;//BGRA8Unorm==80 + [view.layer addSublayer:metalLayer]; + return metalLayer; +#endif } diff --git a/SDL/SDLVulkanGraphicsContext.cpp b/SDL/SDLVulkanGraphicsContext.cpp index 29d68ffc04..02123b105d 100644 --- a/SDL/SDLVulkanGraphicsContext.cpp +++ b/SDL/SDLVulkanGraphicsContext.cpp @@ -75,9 +75,15 @@ bool SDLVulkanGraphicsContext::Init(SDL_Window *&window, int x, int y, int mode, break; #endif #if defined(VK_USE_PLATFORM_METAL_EXT) +#if defined(PPSSPP_PLATFORM_MAC) case SDL_SYSWM_COCOA: vulkan_->InitSurface(WINDOWSYSTEM_METAL_EXT, makeWindowMetalCompatible(sys_info.info.cocoa.window), nullptr); break; +#else + case SDL_SYSWM_UIKIT: + vulkan_->InitSurface(WINDOWSYSTEM_METAL_EXT, makeWindowMetalCompatible(sys_info.info.uikit.window), nullptr); + break; +#endif #endif default: fprintf(stderr, "Vulkan subsystem %d not supported\n", sys_info.subsystem);