Skip to content

Commit

Permalink
Use Khronos' OpenXR loader from Maven when supported
Browse files Browse the repository at this point in the history
Most of the platforms used to distribute their own
implementations/builds of the OpenXR loader. It was traditionally
part of the propietary SDKs distributed by vendors. As they were
under an EULA we had to keep them in a private repository only
available to core devs (obviously any other external dev could
download them on their own).

More recently, and driven by the AOSP flavor effort, we
started to build the Khronos OpenXR loader from sources.
Fortunatelly we got a well documented report explaining how
to use the loader directly from the central Maven repository.
This greatly simplifies the build process and also improves
the open-source feel of the project by reducing our deps with
the third-party repo.

So far this option is now available for the following flavors:
* Meta Quest2, Quest3, QuestPro (requires firmware v62+)
* Lynx R1
* Magic Leap 2

It does not work for neither HVR, nor SnapdragonSpaces based
devices nor Pico. For these ones we still need to rely on the
loader from the SDK.

This change BREAKS Meta builds for OS firmwares <v62 because
as mentioned, the Khronos loader is not available until v62.

Fixes #1394
  • Loading branch information
svillar committed Sep 13, 2024
1 parent 3066aa0 commit a3b942b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 50 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,12 @@ wolvic$ git clone [email protected]:Igalia/wolvic-third-parties.git third_party

This repo is only available to Igalia members. If you have access to the relevant SDK but not this repo, you can manually place them here:

- `third_party/ovr_mobile/` for Oculus (should contain a `VrApi` folder)
- ~`third_party/OVRPlatformSDK/` for Oculus (should contain a `Android` and `include` folders)~ (deprecated)
- `third_party/ovr_openxr_mobile_sdk/` for Oculus (should contain an `OpenXR` folder)
- `third_party/OVRPlatformSDK/` for Oculus (should contain a `Android` and `Include` folders)
- `third_party/hvr/` for Huawei (should contain `arm64-v8a`, `armeabi-v7a` and `include` folders)
- `third_party/wavesdk/` for Vive (should contain a `build` folder, among other things)
- `third_party/picoxr` [Pico OpenXR Mobile SDK](https://developer-global.pico-interactive.com/sdk?deviceId=1&platformId=3&itemId=11) (should contain `include` and `libs` folders, among other things that are not necessary for Wolvic)
- `third_party/lynx` [for Lynx](https://portal.lynx-r.com)(should contain a `loader-release.aar` file)
- `third_party/picoxr` [Pico OpenXR Mobile SDK](https://developer-global.pico-interactive.com/sdk?deviceId=1&platformId=3&itemId=11) (should contain `libs` folders, among other things that are not necessary for Wolvic)
- `third_party/spaces` [for Snapdragon Spaces](https://spaces.qualcomm.com/)(should contain `libopenxr_loader.aar`)
- `third_party/OpenXR-SDK/` [OpenXR-SDK](https://github.com/KhronosGroup/OpenXR-SDK) (should contain an `include` folder)
- `third_party/OpenXR-SDK/` [OpenXR-SDK](https://github.com/KhronosGroup/OpenXR-SDK) (should contain an `include` folder). This is used by HVR and PicoXR flavours. The other flavours using OpenXR use the include files provided by the Khronos OpenXR loader AAR from Maven.
- `third_party/aliceimu/` for [Huawei Vision Glass](https://consumer.huawei.com/cn/wearables/vision-glass/) (should contain an `.aar` file with the IMU library for the glasses)

The [repo in `third_party`](https://github.com/Igalia/wolvic-third-parties) can be updated like so:
Expand Down
54 changes: 14 additions & 40 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,41 +89,30 @@ target_sources(

include(AndroidNdkModules)
android_ndk_import_module_native_app_glue()
target_link_libraries(native-lib native_app_glue)
target_link_libraries(native-lib PRIVATE native_app_glue)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
endif()


if(OPENXR)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DXR_USE_PLATFORM_ANDROID -DXR_USE_GRAPHICS_API_OPENGL_ES")
include_directories(
${CMAKE_SOURCE_DIR}/../third_party/OpenXR-SDK/include
${CMAKE_SOURCE_DIR}/../app/src/openxr/cpp
)
if (OCULUSVR)
include_directories(
${CMAKE_SOURCE_DIR}/../third_party/OVRPlatformSDK/Include
)
add_custom_command(TARGET native-lib POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/../third_party/ovr_openxr_mobile_sdk/OpenXR/Libs/Android/${ANDROID_ABI}/Release/libopenxr_loader.so
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libopenxr_loader.so
)
elseif (HVR)
find_package(OpenXR REQUIRED CONFIG)
include_directories(${CMAKE_SOURCE_DIR}/../app/src/openxr/cpp)
if (HVR)
include_directories(${CMAKE_SOURCE_DIR}/../third_party/OpenXR-SDK/include)
add_custom_command(TARGET native-lib POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/../third_party/hvr/${ANDROID_ABI}/libxr_loader.so
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libxr_loader.so
)
elseif (PICOXR)
include_directories(
${CMAKE_SOURCE_DIR}/../third_party/picoxr/include
)
include_directories(${CMAKE_SOURCE_DIR}/../third_party/OpenXR-SDK/include)
add_custom_command(TARGET native-lib POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/../third_party/picoxr/libs/android.${ANDROID_ABI}/libopenxr_loader.so
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libopenxr_loader.so
)
else ()
target_link_libraries(native-lib PRIVATE OpenXR::openxr_loader)
endif ()
target_sources(
native-lib
Expand All @@ -141,6 +130,7 @@ if(OPENXR)
endif()

if(OCULUSVR)
include_directories(${CMAKE_SOURCE_DIR}/../third_party/OVRPlatformSDK/Include)
add_custom_command(TARGET native-lib POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/../third_party/OVRPlatformSDK/Android/libs/${ANDROID_ABI}/libovrplatformloader.so
Expand All @@ -162,10 +152,6 @@ find_library( # Sets the name of the path variable.
android-lib
android )

add_library(oculusvr-lib SHARED IMPORTED)
set_target_properties(oculusvr-lib PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/../third_party/ovr_openxr_mobile_sdk/OpenXR/Libs/Android/${ANDROID_ABI}/Release/libopenxr_loader.so )

add_library(ovrplatform-lib SHARED IMPORTED)
set_target_properties(ovrplatform-lib PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/../third_party/OVRPlatformSDK/Android/libs/${ANDROID_ABI}/libovrplatformloader.so )
Expand All @@ -182,22 +168,10 @@ add_library(picoxr-lib SHARED IMPORTED)
set_target_properties(picoxr-lib PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/../third_party/picoxr/libs/android.${ANDROID_ABI}/libopenxr_loader.so)

if (LYNX OR SPACES)
if(SPACES)
find_package(loader REQUIRED CONFIG)
target_link_libraries(native-lib loader::openxr_loader)
endif()

if (AOSP)
# Each module in an Android project can link to only one CMake or ndk-build script file. Given
# that we already have the native-lib, we need to add other the OpenXR loaded CMake project
#to the top level CMakeLists.txt file, i.e., this one.
set(lib_src_DIR ${CMAKE_SOURCE_DIR}/../third_party/OpenXR-SDK)
set(lib_build_DIR ${CMAKE_SOURCE_DIR}/../third_party/OpenXR-SDK/build)
file(MAKE_DIRECTORY ${lib_build_DIR})

add_subdirectory(${lib_src_DIR} ${lib_build_DIR})
target_link_libraries(native-lib openxr_loader)
endif()
target_link_libraries(native-lib PRIVATE loader::openxr_loader)
endif ()

# Add dependency on tinygltf library, which is used to load hand models
# from .glb assets. Since it is only a single C++ source and header,
Expand All @@ -210,15 +184,15 @@ include_directories(

# Add dependency on KTX-Software
add_subdirectory(${CMAKE_SOURCE_DIR}/src/main/cpp/KTX-Software)
target_link_libraries(native-lib ktx_read)
target_link_libraries(native-lib PRIVATE ktx_read)
target_include_directories(native-lib PRIVATE ${CMAKE_SOURCE_DIR}/src/main/cpp/KTX-Software/include)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
native-lib
native-lib PRIVATE
vrb

# Link VR_SDK_LIB exported from gradle flavors
Expand Down
7 changes: 3 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ android {
externalNativeBuild {
cmake {
cppFlags "-DOCULUSVR -DOPENXR"
arguments "-DVR_SDK_LIB=oculusvr-lib", "-DVR_SDK_EXTRA_LIB=ovrplatform-lib", "-DOCULUSVR=ON", "-DOPENXR=ON"
arguments "-DVR_SDK_EXTRA_LIB=ovrplatform-lib", "-DOCULUSVR=ON", "-DOPENXR=ON"
}
}
manifestPlaceholders = [ headtrackingRequired:"false", permissionToRemove:"android.permission.RECEIVE_BOOT_COMPLETED" ]
Expand Down Expand Up @@ -693,6 +693,8 @@ dependencies {
implementation deps.work.runtime
implementation deps.work.runtime_ktx

// OpenXR standard loader
implementation 'org.khronos.openxr:openxr_loader_for_android:1.0.34'

// Testing
androidTestImplementation deps.atsl.runner
Expand Down Expand Up @@ -723,9 +725,6 @@ dependencies {
hvrImplementation 'com.huawei.hms:location:6.2.0.300'
hvrImplementation 'com.huawei.hms:push:6.5.0.300'

// Lynx
lynxImplementation fileTree(dir: "${project.rootDir}/third_party/lynx", include: ['*.aar'])

// Snapdragon Spaces
spacesImplementation fileTree(dir: "${project.rootDir}/third_party/spaces", include: ['*.aar'])

Expand Down

0 comments on commit a3b942b

Please sign in to comment.