From 76d0d379418ecae43755a033b935bf457a61c6fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 22 Oct 2026 14:15:43 +0200 Subject: [PATCH] Outputs: Vulkan too, for --game-window and the iOS TV mode The SDL game window gets its Vulkan surface the same way the main window does, so it should work on Linux too. Windows and OpenGL aren't done. EmuScreen asks the draw context for the output's size, which follows a recreated Vulkan swapchain. Co-Authored-By: Claude Opus 5.5 (1M context) --- SDL/SDLMain.cpp | 42 ++++++++++++++++++----------- UI/EmuScreen.cpp | 3 +-- ios/ExternalDisplaySceneDelegate.mm | 6 ++--- ios/ViewController.mm | 5 ++-- 4 files changed, 33 insertions(+), 23 deletions(-) diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index b437fc78d1..594fcd34e0 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -1447,29 +1447,41 @@ static SDL_Window *g_gameWindow = nullptr; static int g_gameOutputId = 0; static void CreateGameWindow() { + Draw::SwapchainDesc desc{}; + desc.tag = "GameWindow"; + const GPUBackend backend = (GPUBackend)g_Config.iGPUBackend; + if (backend == GPUBackend::VULKAN) { + g_gameWindow = SDL_CreateWindow("PPSSPP game", 960, 544, SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY); + WindowDesc windowDesc{}; + std::string error; + if (g_gameWindow && !DetermineVulkanWindowSystem(g_gameWindow, &windowDesc, &error)) { + fprintf(stderr, "Can't use the game window: %s\n", error.c_str()); + SDL_DestroyWindow(g_gameWindow); + g_gameWindow = nullptr; + return; + } + desc.winsys = windowDesc.winsys; + desc.data1 = windowDesc.data1; + desc.data2 = windowDesc.data2; #if PPSSPP_PLATFORM(MAC) - if (g_Config.iGPUBackend != (int)GPUBackend::METAL) { - fprintf(stderr, "--game-window needs --graphics=metal\n"); + } else if (backend == GPUBackend::METAL) { + g_gameWindow = SDL_CreateWindow("PPSSPP game", 960, 544, SDL_WINDOW_METAL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY); + if (g_gameWindow) { + desc.winsys = WINDOWSYSTEM_METAL_EXT; + desc.data1 = SDL_Metal_GetLayer(SDL_Metal_CreateView(g_gameWindow)); + } +#endif + } else { + // TODO: Windows (D3D11) and OpenGL. + fprintf(stderr, "--game-window needs Vulkan, or Metal on Mac\n"); return; } - g_gameWindow = SDL_CreateWindow("PPSSPP game", 960, 544, SDL_WINDOW_METAL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY); if (!g_gameWindow) { fprintf(stderr, "Error creating the game window: %s\n", SDL_GetError()); return; } - SDL_MetalView metalView = SDL_Metal_CreateView(g_gameWindow); - int width = 0, height = 0; - SDL_GetWindowSizeInPixels(g_gameWindow, &width, &height); - Draw::SwapchainDesc desc{}; - desc.winsys = WINDOWSYSTEM_METAL_EXT; - desc.data1 = SDL_Metal_GetLayer(metalView); - desc.width = width; - desc.height = height; - desc.tag = "GameWindow"; + SDL_GetWindowSizeInPixels(g_gameWindow, &desc.width, &desc.height); g_gameOutputId = Native_AddOutput(OutputRole::Game, desc); -#else - fprintf(stderr, "--game-window is only implemented on Mac (Metal)\n"); -#endif } // Returns true if the event was for the game window, and has been handled. Keys still go to the emulator. diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index bde2586881..48b2db3857 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -1683,8 +1683,7 @@ void EmuScreen::UpdateGameOutput() { return; } OutputParams params; - params.pixelWidth = output->swapchain->Width(); - params.pixelHeight = output->swapchain->Height(); + screenManager()->getDrawContext()->GetFramebufferDimensions(output->swapchain, ¶ms.pixelWidth, ¶ms.pixelHeight); params.orientation = params.pixelHeight > params.pixelWidth * 1.1f ? DeviceOrientation::Portrait : DeviceOrientation::Landscape; gameOutputOrientation_ = params.orientation; gpu->SetPresentationOutput(¶ms); diff --git a/ios/ExternalDisplaySceneDelegate.mm b/ios/ExternalDisplaySceneDelegate.mm index 957e1097da..e9f07313b7 100644 --- a/ios/ExternalDisplaySceneDelegate.mm +++ b/ios/ExternalDisplaySceneDelegate.mm @@ -111,9 +111,9 @@ static bool g_launched = false; if (!self.windowScene || self.window) { return; } - // Only Metal can present to a second display so far. Without a window, iOS mirrors the phone. - if (g_Config.iGPUBackend != (int)GPUBackend::METAL) { - INFO_LOG(Log::G3D, "External display: mirroring, as the backend isn't Metal"); + // Without a window, iOS mirrors the phone. + if (g_Config.iGPUBackend != (int)GPUBackend::METAL && g_Config.iGPUBackend != (int)GPUBackend::VULKAN) { + INFO_LOG(Log::G3D, "External display: mirroring, as the backend can't present to it"); return; } #if !TARGET_OS_TV diff --git a/ios/ViewController.mm b/ios/ViewController.mm index facf2e65b6..d725277511 100644 --- a/ios/ViewController.mm +++ b/ios/ViewController.mm @@ -648,10 +648,9 @@ static int GetPickerRequestId(id picker) { #if !PPSSPP_PLATFORM(TVOS) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 270000 // From iOS 27, an external display scene only goes to apps that register for one like this. Earlier - // versions go by the Info.plist role instead. Only Metal can show the game there so far, and without - // the scene, iOS mirrors the phone. + // versions go by the Info.plist role instead. Without the scene, iOS mirrors the phone. if (@available(iOS 27.0, *)) { - if (g_Config.iGPUBackend == (int)GPUBackend::METAL) { + if (g_Config.iGPUBackend == (int)GPUBackend::METAL || g_Config.iGPUBackend == (int)GPUBackend::VULKAN) { UISceneConfiguration *sceneConfiguration = [UISceneConfiguration new]; sceneConfiguration.delegateClass = [ExternalDisplaySceneDelegate class]; self.externalDisplayRegistration = [self registerSceneAccessory:[UISceneAccessory externalNonInteractiveSceneAccessoryWithConfiguration:sceneConfiguration]];