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 374031f
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 7 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()
14 changes: 14 additions & 0 deletions shell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,21 @@ if(ANDROID)
add_subdirectory(android)
endif()

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

macro(ADD_SHELL_SESSION target libs)
set(shell_srcs apps/SessionApp.cpp renderSessions/${target}.cpp renderSessions/${target}.h)
add_shell_session_with_srcs(${target} "${shell_srcs}" "${libs}")
endmacro()

macro(ADD_SHELL_SESSION_OPENXR target)
set(shell_srcs apps/SessionApp.cpp renderSessions/${target}.cpp renderSessions/${target}.h openxr/desktop/main.cpp)
add_shell_session_backend_openxr(${target} vulkan "${shell_srcs}" IGLShellOpenXR)
endmacro()

if(IGL_WITH_SAMPLES)
add_shell_session(BasicFramebufferSession "")
add_shell_session(ColorSession "")
Expand All @@ -67,4 +77,8 @@ if(IGL_WITH_SAMPLES)
add_shell_session(Textured3DCubeSession "")
add_shell_session(TQMultiRenderPassSession "")
add_shell_session(TQSession "")
if(IGL_WITH_OPENXR AND IGL_WITH_VULKAN)
add_shell_session_OpenXR(ColorSession "")
add_shell_session_OpenXR(Textured3DCubeSession)
endif()
endif()
37 changes: 37 additions & 0 deletions shell/openxr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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/desktop/vulkan/*.cpp
../openxr/impl/*.cpp
../openxr/src/*.cpp)
file(GLOB SHELL_OPENXR_HEADER_FILES LIST_DIRECTORIES false RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
../openxr/desktop/*.h
../openxr/desktop/vulkan/*.h
../openxr/impl/*.h
../openxr/src/*.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: 2 additions & 0 deletions shell/openxr/desktop/vulkan/XrSwapchainProviderImplVulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#include <igl/vulkan/VulkanTexture.h>
#include <vector>

#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/XrSwapchainProviderImpl.h>
Expand Down
16 changes: 14 additions & 2 deletions shell/openxr/src/XrApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@
#include <string>
#include <vector>

#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 <openxr/openxr.h>
#include <openxr/openxr_platform.h>

#include <glm/glm.hpp>

Expand Down Expand Up @@ -89,7 +98,10 @@ class XrApp {

std::vector<XrExtensionProperties> extensions_;
std::vector<const char*> requiredExtensions_ = {
#ifndef XR_USE_PLATFORM_MACOS
#if IGL_BACKEND_VULKAN
XR_KHR_VULKAN_ENABLE_EXTENSION_NAME,
#endif // IGL_BACKEND_VULKAN
#if !defined(XR_USE_PLATFORM_MACOS) && !defined(IGL_CMAKE_BUILD)
XR_FB_SWAPCHAIN_UPDATE_STATE_EXTENSION_NAME,
#endif
};
Expand All @@ -109,7 +121,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
2 changes: 1 addition & 1 deletion shell/openxr/src/XrLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace igl::shell::openxr {
#if IGL_DEBUG
void checkXRErrors(XrResult result, const char* function) {
if (XR_FAILED(result)) {
char errorBuffer[XR_MAX_RESULT_STRING_SIZE];
char errorBuffer[XR_MAX_RESULT_STRING_SIZE+1] = {};
xrResultToString(getXrInstance(), result, errorBuffer);
IGL_LOG_ERROR("OpenXR error: %s %s", function, errorBuffer);
}
Expand Down
13 changes: 13 additions & 0 deletions shell/windows/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,22 @@ function(ADD_SHELL_SESSION_BACKEND targetApp backend srcs libs)
target_link_libraries(${target} PUBLIC IGLShellApp_${backend})
endfunction()

function(ADD_SHELL_SESSION_BACKEND_OPENXR targetApp backend srcs libs)
set(target ${targetApp}_${backend}_openxr)
add_executable(${target} ${srcs})
igl_set_folder(${target} "IGL Shell Sessions/${backend}_OpenXR")
igl_set_cxxstd(${target} 20)
target_compile_definitions(${target} PRIVATE "IGL_SHELL_SESSION=${targetApp}")
target_link_libraries(${target} PUBLIC ${libs})
target_link_libraries(${target} PUBLIC IGLShellApp_${backend})
endfunction()

macro(ADD_SHELL_SESSION_WITH_SRCS target srcs libs)
if(IGL_WITH_VULKAN)
add_shell_session_backend(${target} vulkan "${srcs}" "${libs}")
# if(IGL_WITH_OPENXR)
# add_shell_session_backend_openxr(${target} vulkan "${srcs}" "${libs}")
# endif()
endif()
if(IGL_WITH_OPENGL)
add_shell_session_backend(${target} opengl "${srcs}" "${libs}")
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 374031f

Please sign in to comment.