From d3a3cab425b402b39e71751fa0b064a4d687a666 Mon Sep 17 00:00:00 2001 From: Eric Warmenhoven Date: Tue, 25 Apr 2023 21:35:56 -0400 Subject: [PATCH] Build iOS libretro core --- .gitlab-ci.yml | 15 +++++++++ CMakeLists.txt | 14 +++++++-- core/deps/libretro-common/include/libretro.h | 33 ++++++++++++++++++++ core/wsi/libretro.h | 4 +++ shell/libretro/libretro.cpp | 10 ++++++ 5 files changed, 73 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 55dc4fbd3..ec509441a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -28,6 +28,12 @@ CORE_ARGS: -DLIBRETRO=ON -G Xcode -DCMAKE_BUILD_TYPE=Release EXTRA_PATH: Release +.core-defs-ios-arm64: + extends: .core-defs + variables: + CORE_ARGS: -DLIBRETRO=ON -G Xcode -DCMAKE_BUILD_TYPE=Release + EXTRA_PATH: Release-iphoneos + .core-defs-android: extends: .core-defs script: @@ -62,6 +68,10 @@ include: - project: 'libretro-infrastructure/ci-templates' file: '/android-cmake.yml' + # iOS arm64 + - project: 'libretro-infrastructure/ci-templates' + file: '/ios-cmake.yml' + ################################## CONSOLES ################################ # Nintendo Switch # - project: 'libretro-infrastructure/ci-templates' @@ -139,6 +149,11 @@ android-x86: - .libretro-android-cmake-x86 - .core-defs-android +libretro-build-ios-arm64: + extends: + - .libretro-ios-cmake-arm64 + - .core-defs-ios-arm64 + ################################### CONSOLES ################################# # Nintendo Switch #libretro-build-libnx-aarch64: diff --git a/CMakeLists.txt b/CMakeLists.txt index b38094235..b9ccfc08c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,7 @@ option(ENABLE_GDB_SERVER "Build with GDB debugging support" OFF) option(ENABLE_DC_PROFILER "Build with support for target machine (SH4) profiler" OFF) option(ENABLE_FC_PROFILER "Build with support for host app (Flycast) profiler" OFF) -if(IOS) +if(IOS AND NOT LIBRETRO) set(USE_VULKAN OFF CACHE BOOL "Force vulkan off" FORCE) endif() @@ -122,7 +122,10 @@ elseif(LIBRETRO) else() set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined") endif() - set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "flycast_libretro") + set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "flycast_libretro" + XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO" + XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "" + ) set(CMAKE_SHARED_LIBRARY_PREFIX "") set(CMAKE_POSITION_INDEPENDENT_CODE ON) target_compile_definitions(${PROJECT_NAME} PRIVATE LIBRETRO) @@ -130,6 +133,11 @@ elseif(LIBRETRO) target_compile_definitions(${PROJECT_NAME} PRIVATE GLES GLES3 HAVE_OPENGLES HAVE_OPENGLES3) find_library(GLES3_LIBRARIES NAMES GLESv3 GLESv2 NO_CACHE REQUIRED) target_link_libraries(${PROJECT_NAME} PRIVATE ${GLES3_LIBRARIES}) + elseif(IOS) + target_compile_definitions(${PROJECT_NAME} PRIVATE GLES GLES3 HAVE_OPENGLES HAVE_OPENGLES3) + find_library(OPENGLES OpenGLES) + find_library(GLKIT GLKit) + target_link_libraries(${PROJECT_NAME} PRIVATE ${OPENGLES} ${GLKIT}) elseif(USE_GLES2) target_compile_definitions(${PROJECT_NAME} PRIVATE GLES GLES2 HAVE_OPENGLES HAVE_OPENGLES2) if(USE_VIDEOCORE) @@ -697,7 +705,7 @@ if(LIBRETRO) target_sources(${PROJECT_NAME} PRIVATE core/deps/libretro-common/glsm/glsm.c core/deps/libretro-common/glsym/rglgen.c) - if(ANDROID OR USE_GLES) + if(ANDROID OR IOS OR USE_GLES) target_sources(${PROJECT_NAME} PRIVATE core/deps/libretro-common/glsym/glsym_es3.c) elseif(USE_GLES2) target_sources(${PROJECT_NAME} PRIVATE core/deps/libretro-common/glsym/glsym_es2.c) diff --git a/core/deps/libretro-common/include/libretro.h b/core/deps/libretro-common/include/libretro.h index 4bd3f2f0c..983ebfc2c 100644 --- a/core/deps/libretro-common/include/libretro.h +++ b/core/deps/libretro-common/include/libretro.h @@ -1767,6 +1767,39 @@ enum retro_mod * (see enum retro_savestate_context) */ +#define RETRO_ENVIRONMENT_GET_HW_RENDER_CONTEXT_NEGOTIATION_INTERFACE_SUPPORT (73 | RETRO_ENVIRONMENT_EXPERIMENTAL) + /* struct retro_hw_render_context_negotiation_interface * -- + * Before calling SET_HW_RNEDER_CONTEXT_NEGOTIATION_INTERFACE, a core can query + * which version of the interface is supported. + * + * Frontend looks at interface_type and returns the maximum supported + * context negotiation interface version. + * If the interface_type is not supported or recognized by the frontend, a version of 0 + * must be returned in interface_version and true is returned by frontend. + * + * If this environment call returns true with interface_version greater than 0, + * a core can always use a negotiation interface version larger than what the frontend returns, but only + * earlier versions of the interface will be used by the frontend. + * A frontend must not reject a negotiation interface version that is larger than + * what the frontend supports. Instead, the frontend will use the older entry points that it recognizes. + * If this is incompatible with a particular core's requirements, it can error out early. + * + * Backwards compatibility note: + * This environment call was introduced after Vulkan v1 context negotiation. + * If this environment call is not supported by frontend - i.e. the environment call returns false - + * only Vulkan v1 context negotiation is supported (if Vulkan HW rendering is supported at all). + * If a core uses Vulkan negotiation interface with version > 1, negotiation may fail unexpectedly. + * All future updates to the context negotiation interface implies that frontend must support + * this environment call to query support. + */ + +#define RETRO_ENVIRONMENT_GET_JIT_CAPABLE 74 + /* bool * -- + * Result is set to true if the frontend has already verified JIT can be + * used, mainly for use iOS/tvOS. On other platforms the result is true. + */ + + /* VFS functionality */ /* File paths: diff --git a/core/wsi/libretro.h b/core/wsi/libretro.h index 1b4e25190..3b1c8f737 100644 --- a/core/wsi/libretro.h +++ b/core/wsi/libretro.h @@ -18,6 +18,10 @@ */ #pragma once #if defined(LIBRETRO) && (defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)) +#if defined(TARGET_IPHONE) //apple-specific ogles3 headers +#include +#include +#endif #include "gl_context.h" #include #include diff --git a/shell/libretro/libretro.cpp b/shell/libretro/libretro.cpp index 1c0d57fec..9e1f893c2 100644 --- a/shell/libretro/libretro.cpp +++ b/shell/libretro/libretro.cpp @@ -1793,6 +1793,16 @@ static bool set_dx11_hw_render() // Loading/unloading games bool retro_load_game(const struct retro_game_info *game) { +#if defined(IOS) + bool can_jit; + if (environ_cb(RETRO_ENVIRONMENT_GET_JIT_CAPABLE, &can_jit) && !can_jit) { + // jit is required both for performance and for audio. trying to run + // without the jit will cause a crash. + gui_display_notification("Cannot run without JIT", 5000); + return false; + } +#endif + NOTICE_LOG(BOOT, "retro_load_game: %s", game->path); extract_basename(g_base_name, game->path, sizeof(g_base_name));