Skip to content

Commit

Permalink
igl | cmake | OpenXR initial support
Browse files Browse the repository at this point in the history
  • Loading branch information
corporateshark committed Dec 24, 2023
1 parent a66b421 commit deca7ac
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 5 deletions.
22 changes: 22 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ option(IGL_WITH_SHELL "Enable Shell utils" ON)
option(IGL_WITH_TESTS "Enable IGL tests (gtest)" OFF)
option(IGL_WITH_TRACY "Enable Tracy profiler" OFF)
option(IGL_WITH_TRACY_GPU "Enable Tracy profiler for the GPU" OFF)
option(IGL_WITH_OPENXR "Enable OpenXR" OFF)
option(IGL_ENFORCE_LOGS "Enable logs in Release builds" ON)

option(IGL_DEPLOY_DEPS "Deploy dependencies via CMake" ON)
Expand Down Expand Up @@ -81,6 +82,7 @@ message(STATUS "IGL_WITH_SHELL = ${IGL_WITH_SHELL}")
message(STATUS "IGL_WITH_TESTS = ${IGL_WITH_TESTS}")
message(STATUS "IGL_WITH_TRACY = ${IGL_WITH_TRACY}")
message(STATUS "IGL_WITH_TRACY_GPU = ${IGL_WITH_TRACY_GPU}")
message(STATUS "IGL_WITH_OPENXR = ${IGL_WITH_OPENXR}")
message(STATUS "IGL_ENFORCE_LOGS = ${IGL_ENFORCE_LOGS}")

message(STATUS "IGL_DEPLOY_DEPS = ${IGL_DEPLOY_DEPS}")
Expand Down Expand Up @@ -145,6 +147,20 @@ if(IGL_WITH_TRACY)
igl_set_folder(TracyClient "third-party")
endif()

if(IGL_WITH_OPENXR)
if(IGL_WITH_VULKAN)
add_definitions("-DXR_USE_GRAPHICS_API_VULKAN")
elseif(IGL_WITH_OPENGLES)
add_definitions("-DXR_USE_GRAPHICS_API_OPENGL_ES")
elseif(IGL_WITH_OPENGL)
add_definitions("-DXR_USE_GRAPHICS_API_OPENGL")
else()
message(FATAL_ERROR "Unsupported OpenXR backend (Vulkan, OpenGL, OpenGL ES).")
endif()
add_subdirectory(third-party/deps/src/openxr-sdk)
igl_set_folder(openxr_loader "third-party/OpenXR")
endif()

add_subdirectory(src/igl)

if(IGL_WITH_TRACY)
Expand Down Expand Up @@ -286,3 +302,9 @@ endif()
if(IGL_WITH_TRACY)
target_link_libraries(IGLLibrary PUBLIC TracyClient)
endif()

if(IGL_WITH_OPENXR)
target_compile_definitions(IGLLibrary PUBLIC "IGL_WITH_OPENXR=1")
target_link_libraries(IGLLibrary PUBLIC OpenXR::openxr_loader)
target_include_directories(IGLLibrary PUBLIC "${IGL_ROOT_DIR}/third-party/deps/src/openxr-sdk/include")
endif()
5 changes: 5 additions & 0 deletions shell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ file(GLOB SHELL_SHARED_HEADER_FILES LIST_DIRECTORIES false RELATIVE ${CMAKE_CURR

add_library(IGLShellShared ${SHELL_SHARED_SRC_FILES} ${SHELL_SHARED_HEADER_FILES})

if(IGL_WITH_OPENXR)
add_subdirectory(openxr)
target_link_libraries(IGLShellShared PUBLIC IGLShellOpenXR)
endif()

target_include_directories(IGLShellShared PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/include_renderSessions")
target_include_directories(IGLShellShared PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/include_shared")

Expand Down
31 changes: 31 additions & 0 deletions shell/openxr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.16)

set(PROJECT_NAME "IGLShellOpenXR")

# emulate BUCK include paths
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include_shell_openxr/shell)
file(CREATE_LINK
"${IGL_ROOT_DIR}/shell/openxr/src"
"${CMAKE_CURRENT_BINARY_DIR}/include_shell_openxr/shell/openxr" COPY_ON_ERROR SYMBOLIC)
#

file(GLOB SHELL_OPENXR_SRC_FILES LIST_DIRECTORIES false RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
../openxr/desktop/*.cpp ../openxr/impl/*.cpp ../openxr/*.cpp)
file(GLOB SHELL_OPENXR_HEADER_FILES LIST_DIRECTORIES false RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
../openxr/desktop/*.h ../openxr/impl/*.h ../openxr/*.h)

add_library(IGLShellOpenXR ${SHELL_OPENXR_SRC_FILES} ${SHELL_OPENXR_HEADER_FILES})

target_link_libraries(IGLShellOpenXR PUBLIC IGLLibrary)
target_link_libraries(IGLShellOpenXR PUBLIC IGLLibrary)

target_include_directories(IGLShellOpenXR PUBLIC "${IGL_ROOT_DIR}/third-party/deps/src/openxr-sdk/src/common")
target_include_directories(IGLShellOpenXR PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/include_shell_openxr")

igl_set_folder(IGLShellOpenXR "IGL")
igl_set_cxxstd(IGLShellOpenXR 20)
23 changes: 21 additions & 2 deletions shell/openxr/desktop/XrApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
* LICENSE file in the root directory of this source tree.
*/

#include <igl/Common.h>

#if IGL_BACKEND_VULKAN
#include <igl/vulkan/Common.h>
#endif // IGL_BACKEND_VULKAN

#if IGL_BACKEND_OPENGL
#include <igl/opengl/GLIncludes.h>
#endif // IGL_BACKEND_OPENGL

#include <shell/openxr/XrApp.h>

#include <algorithm>
Expand All @@ -19,7 +29,12 @@

#include <glm/gtc/type_ptr.hpp>

#if IGL_PLATFORM_APPLE
#include <shell/shared/platform/mac/PlatformMac.h>
#elif IGL_PLATFORM_WIN
#include <shell/shared/platform/win/PlatformWin.h>
#endif

#include <shell/shared/renderSession/AppParams.h>
#include <shell/shared/renderSession/DefaultSession.h>
#include <shell/shared/renderSession/ShellParams.h>
Expand Down Expand Up @@ -255,8 +270,8 @@ void XrApp::enumerateReferenceSpaces() {
}

void XrApp::createSwapchainProviders(const std::unique_ptr<igl::IDevice>& device) {
const size_t numSwapchainProviders = useSinglePassStereo_ ? 1 : kNumViews;
const size_t numViewsPerSwapchain = useSinglePassStereo_ ? kNumViews : 1;
const uint32_t numSwapchainProviders = useSinglePassStereo_ ? 1 : kNumViews;
const uint32_t numViewsPerSwapchain = useSinglePassStereo_ ? kNumViews : 1;
swapchainProviders_.reserve(numSwapchainProviders);

for (size_t i = 0; i < numSwapchainProviders; i++) {
Expand Down Expand Up @@ -319,7 +334,11 @@ bool XrApp::initialize(const struct android_app* app) {
}

void XrApp::createShellSession(std::unique_ptr<igl::IDevice> device, AAssetManager* assetMgr) {
#if IGL_PLATFORM_APPLE
platform_ = std::make_shared<igl::shell::PlatformMac>(std::move(device));
#elif IGL_PLATFORM_WIN
platform_ = std::make_shared<igl::shell::PlatformWin>(std::move(device));
#endif
IGL_ASSERT(platform_ != nullptr);
renderSession_ = igl::shell::createDefaultRenderSession(platform_);
shellParams_->shellControlsViewParams = true;
Expand Down
4 changes: 2 additions & 2 deletions shell/openxr/desktop/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

using namespace igl::shell::openxr;

#if defined(USE_VULKAN_BACKEND)
#if IGL_BACKEND_VULKAN
#include "vulkan/XrAppImplVulkan.h"
// @fb-only
// @fb-only
Expand All @@ -25,7 +25,7 @@ XrInstance getXrInstance() {
}

int main(int argc, const char* argv[]) {
#if defined(USE_VULKAN_BACKEND)
#if IGL_BACKEND_VULKAN
auto xrApp = std::make_unique<XrApp>(std::make_unique<desktop::XrAppImplVulkan>());
// @fb-only
// @fb-only
Expand Down
2 changes: 2 additions & 0 deletions shell/openxr/desktop/vulkan/XrAppImplVulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include <array>
#include <igl/vulkan/Common.h>

#if !defined(XR_USE_GRAPHICS_API_VULKAN)
#define XR_USE_GRAPHICS_API_VULKAN
#endif // XR_USE_GRAPHICS_API_VULKAN
#include <openxr/openxr_platform.h>

#include <shell/openxr/impl/XrAppImpl.h>
Expand Down
2 changes: 1 addition & 1 deletion shell/openxr/src/XrApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class XrApp {
XrSession session_ = XR_NULL_HANDLE;

XrViewConfigurationProperties viewConfigProps_ = {.type = XR_TYPE_VIEW_CONFIGURATION_PROPERTIES};
static constexpr auto kNumViews = 2; // 2 for stereo
static constexpr uint32_t kNumViews = 2; // 2 for stereo
std::array<XrViewConfigurationView, kNumViews> viewports_;
std::array<XrView, kNumViews> views_;
std::array<XrPosef, kNumViews> viewStagePoses_;
Expand Down
8 changes: 8 additions & 0 deletions third-party/bootstrap-deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,13 @@
"url": "https://github.com/KhronosGroup/KTX-Software.git",
"revision": "84ee59dd27232ff60ea6ee135f67d46fde5c766b"
}
},
{
"name": "openxr-sdk",
"source": {
"type": "git",
"url": "https://github.com/KhronosGroup/OpenXR-SDK.git",
"sha1": "49e81bbd919af7c0cf513517a730d12253c28902"
}
}
]

0 comments on commit deca7ac

Please sign in to comment.