From b2fc4a80fe797bdaa62e683e4baae2488cf0f164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 19 Oct 2026 12:05:14 +0200 Subject: [PATCH] Metal: Leave the backend out of the libretro cores They get their graphics context from the frontend, so they compiled and linked the Metal backend without being able to use it. Adds PPSSPP_API_METAL, like PPSSPP_API_D3D11, for the code that only exists with it. Co-Authored-By: Claude Opus 5.5 (1M context) --- CMakeLists.txt | 3 ++- Common/CMakeLists.txt | 4 ++-- Core/Config.cpp | 2 +- GPU/CMakeLists.txt | 2 +- GPU/GPU.cpp | 4 ++-- headless/Headless.cpp | 4 ++-- ppsspp_config.h | 5 +++++ 7 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 92b7fb7ab3..c7421bd0bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1135,7 +1135,8 @@ if(WIN32) list(APPEND GlslangLibs spirv-cross-hlsl) endif() -if(APPLE) +# The Metal backend. Not in the libretro cores, which get their graphics context from the frontend. +if(APPLE AND NOT LIBRETRO) list(APPEND GlslangLibs spirv-cross-msl) endif() diff --git a/Common/CMakeLists.txt b/Common/CMakeLists.txt index bacc0e4ddc..36880b070a 100644 --- a/Common/CMakeLists.txt +++ b/Common/CMakeLists.txt @@ -34,7 +34,7 @@ if(NOT NO_OPENGL) ) endif() -if(APPLE) +if(APPLE AND NOT LIBRETRO) set(CommonMetal GPU/Metal/MetalGraphicsContext.h GPU/Metal/MetalGraphicsContext.mm @@ -420,7 +420,7 @@ if(TARGET Ext::GLEW) target_link_libraries(Common Ext::GLEW) endif() -if(APPLE) +if(APPLE AND NOT LIBRETRO) target_link_libraries(Common "-framework Metal" "-framework QuartzCore") endif() diff --git a/Core/Config.cpp b/Core/Config.cpp index 04955b36c0..7edd3af46f 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -609,7 +609,7 @@ bool Config::IsBackendEnabled(GPUBackend backend) { return false; #endif -#if !PPSSPP_PLATFORM(MAC) && !PPSSPP_PLATFORM(IOS) +#if !PPSSPP_API(METAL) if (backend == GPUBackend::METAL) return false; #endif diff --git a/GPU/CMakeLists.txt b/GPU/CMakeLists.txt index 9df9e1ea89..111b4f2503 100644 --- a/GPU/CMakeLists.txt +++ b/GPU/CMakeLists.txt @@ -71,7 +71,7 @@ endif() if(WIN32) list(APPEND GPU_IMPLS ${GPU_D3D11}) endif() -if(APPLE) +if(APPLE AND NOT LIBRETRO) set(GPU_METAL Metal/DrawEngineMetal.h Metal/DrawEngineMetal.mm diff --git a/GPU/GPU.cpp b/GPU/GPU.cpp index 4e6d4e9dea..ddd41211a9 100644 --- a/GPU/GPU.cpp +++ b/GPU/GPU.cpp @@ -37,7 +37,7 @@ #include "GPU/D3D11/GPU_D3D11.h" #endif -#if PPSSPP_PLATFORM(MAC) || PPSSPP_PLATFORM(IOS) +#if PPSSPP_API(METAL) #include "GPU/Metal/GPU_Metal.h" #endif @@ -75,7 +75,7 @@ static GPUCommon *CreateGPUCore(GPUCore gpuCore, GraphicsContext *ctx, Draw::Dra return new GPU_Vulkan(ctx, draw); #endif case GPUCORE_METAL: -#if PPSSPP_PLATFORM(MAC) || PPSSPP_PLATFORM(IOS) +#if PPSSPP_API(METAL) return new GPU_Metal(ctx, draw); #else return nullptr; diff --git a/headless/Headless.cpp b/headless/Headless.cpp index e3e515f4f3..e5588c146f 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -49,7 +49,7 @@ #include "Common/StringUtils.h" #include "Common/Thread/ThreadManager.h" #include "Common/GPU/Vulkan/VulkanGraphicsContext.h" -#if PPSSPP_PLATFORM(MAC) || PPSSPP_PLATFORM(IOS) +#if PPSSPP_API(METAL) #include "Common/GPU/Metal/MetalGraphicsContext.h" #endif #include "Core/CmdLine.h" @@ -1112,7 +1112,7 @@ int main(int argc, const char* argv[]) { vulkanContext->SetOffscreen(480, 272); graphicsContext = vulkanContext; deviceSetting = &g_Config.sVulkanDevice; -#if PPSSPP_PLATFORM(MAC) || PPSSPP_PLATFORM(IOS) +#if PPSSPP_API(METAL) } else if (gpuCore == GPUCORE_METAL) { MetalGraphicsContext *metalContext = new MetalGraphicsContext(); metalContext->SetOffscreen(480, 272); diff --git a/ppsspp_config.h b/ppsspp_config.h index 4ce8d5eeb4..61b733c160 100644 --- a/ppsspp_config.h +++ b/ppsspp_config.h @@ -143,3 +143,8 @@ #if PPSSPP_PLATFORM(WINDOWS) #define PPSSPP_API_D3D11 1 #endif + +// Not in the libretro cores, which get their graphics context from the frontend. +#if (PPSSPP_PLATFORM(MAC) || PPSSPP_PLATFORM(IOS)) && !defined(__LIBRETRO__) +#define PPSSPP_API_METAL 1 +#endif