diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index b9417e68..098f36d2 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -36,17 +36,33 @@ body: validations: required: true + - type: input + attributes: + label: Installation method + description: Describe how WiVRn and OpenComposite/xrizer were installed + placeholder: flatpak --user, flatpak, AUR, Gentoo/Guru, built from sources... + - type: textarea attributes: label: Server Config - description: Provide the content of `config.json` for the server. - placeholder: Add the content of config.json here... + description: | + Provide the content of `config.json` for the server. + Located in `${XDG_CONFIG_HOME-${HOME}/.config}/wivrn/config.json` + or `~/.var/app/io.github.wivrn.wivrn/config/wivrn/config.json` for the flatpak version + placeholder: | + { + "encoders": [ + {"codec": "h264"} + ] + } - type: textarea attributes: label: Server Logs description: Provide the `wivrn-server` output. - placeholder: Add the output of the wivrn-server here... + placeholder: | + Add the output of the wivrn-server here. + If more than a few lines, prefer file attachment. - type: dropdown id: gpu @@ -64,7 +80,7 @@ body: attributes: label: Vulkan Info description: Provide the output of `vulkaninfo --summary` command. - placeholder: Add the output of vulkaninfo command here... + placeholder: Attach the output as a file here. - type: dropdown id: hmd @@ -90,4 +106,4 @@ body: attributes: label: ADB Logs description: Provide the output of `adb logcat` command. - placeholder: Add the output of adb logcat command here... + placeholder: Attach the output of adb logcat as a file. diff --git a/.github/workflows/APK-Release.yml b/.github/workflows/APK-Release.yml index 4eec207d..8c5b374e 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -31,6 +31,13 @@ jobs: # repository: 'Vindicus999/WiVRn' # ref: sneed + - name: Prepare Vulkan SDK + uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 + with: + vulkan-query-version: 1.3.296.0 + vulkan-components: Glslang, SPIRV-Tools + vulkan-use-cache: true + - name: set up JDK uses: actions/setup-java@v4 with: diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index cbc1e2af..a24f9a4e 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -33,12 +33,12 @@ jobs: - name: Install dependencies run: > - sudo apt-get update && sudo apt-get install libvulkan-dev libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libavahi-client-dev libavahi-glib-dev libeigen3-dev glslang-tools libudev-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev nlohmann-json3-dev libpulse-dev xz-utils libpipewire-0.3-dev libcli11-dev libboost-all-dev librsvg2-bin libssl-dev libnotify-dev librsvg2-dev + sudo apt-get update && sudo apt-get install libvulkan-dev libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libavahi-client-dev libavahi-glib-dev libeigen3-dev glslang-tools libudev-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev nlohmann-json3-dev libpulse-dev xz-utils libpipewire-0.3-dev libcli11-dev libboost-all-dev librsvg2-bin libssl-dev libnotify-dev librsvg2-dev libarchive-dev - name: Prepare Vulkan SDK uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 with: - vulkan-query-version: 1.3.283.0 - vulkan-components: Vulkan-Headers + vulkan-query-version: 1.3.296.0 + vulkan-components: Vulkan-Headers, Glslang, SPIRV-Tools vulkan-use-cache: true - name: Configure CMake @@ -87,14 +87,8 @@ jobs: - name: Install dependencies run: > - apt-get update && apt-get install --yes libvulkan-dev libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev nlohmann-json3-dev qt6-base-dev qt6-tools-dev libcap-dev pkexec libboost-all-dev librsvg2-bin libssl-dev libnotify-dev qt6-declarative-dev extra-cmake-modules libkirigami-dev libkf6i18n-dev libkf6coreaddons-dev libkf6qqc2desktopstyle-dev libkf6iconthemes-dev jq sudo cmake gcc g++ git qcoro-qt6-dev librsvg2-dev + apt-get update && apt-get install --yes libvulkan-dev libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev nlohmann-json3-dev qt6-base-dev qt6-tools-dev libcap-dev pkexec libboost-all-dev librsvg2-bin libssl-dev libnotify-dev qt6-declarative-dev extra-cmake-modules libkirigami-dev libkf6i18n-dev libkf6coreaddons-dev libkf6qqc2desktopstyle-dev libkf6iconthemes-dev jq sudo cmake gcc g++ git qcoro-qt6-dev librsvg2-dev libarchive-dev libglm-dev glslang-tools # runtime: qml6-module-qtqml-workerscript qml6-module-qtquick-dialogs - - name: Prepare Vulkan SDK - uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 - with: - vulkan-query-version: 1.3.283.0 - vulkan-components: Vulkan-Headers - vulkan-use-cache: true - name: Configure CMake run: > @@ -182,8 +176,8 @@ jobs: - name: Prepare Vulkan SDK uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 with: - vulkan-query-version: 1.3.283.0 - vulkan-components: Vulkan-Headers + vulkan-query-version: 1.3.296.0 + vulkan-components: Vulkan-Headers, Glslang, SPIRV-Tools vulkan-use-cache: true - name: Install dependencies @@ -192,13 +186,14 @@ jobs: - name: install server dependencies run: > - sudo apt-get update && sudo apt-get install libavahi-glib-dev nlohmann-json3-dev libpulse-dev xz-utils libpipewire-0.3-dev libcli11-dev qt6-base-dev qt6-tools-dev libcap-dev pkexec libnotify-dev librsvg2-dev + sudo apt-get update && sudo apt-get install libavahi-glib-dev nlohmann-json3-dev libpulse-dev xz-utils libpipewire-0.3-dev libcli11-dev qt6-base-dev qt6-tools-dev libcap-dev pkexec libnotify-dev librsvg2-dev libarchive-dev - name: Configure CMake run: > cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_INSTALL_PREFIX=/usr + -DWIVRN_USE_SYSTEM_OPENXR=OFF --preset everything -DWIVRN_BUILD_DASHBOARD=OFF -DWIVRN_BUILD_DISSECTOR=OFF @@ -293,8 +288,8 @@ jobs: - name: Prepare Vulkan SDK uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 with: - vulkan-query-version: 1.3.268.0 - vulkan-components: Vulkan-Headers + vulkan-query-version: 1.3.296.0 + vulkan-components: Vulkan-Headers, Glslang, SPIRV-Tools vulkan-use-cache: true - name: Install dependencies @@ -307,6 +302,7 @@ jobs: -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_INSTALL_PREFIX=/usr --preset ${{ matrix.cmake_preset }} + -DWIVRN_USE_SYSTEM_OPENXR=OFF - name: Build run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} @@ -326,6 +322,13 @@ jobs: with: fetch-depth: 0 + - name: Prepare Vulkan SDK + uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 + with: + vulkan-query-version: 1.3.296.0 + vulkan-components: Glslang, SPIRV-Tools + vulkan-use-cache: true + - name: set up JDK uses: actions/setup-java@v4 with: @@ -467,7 +470,7 @@ jobs: - name: Install dependencies run: | apt update - apt install --yes libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libavahi-client-dev libavahi-glib-dev libeigen3-dev glslang-tools libudev-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev nlohmann-json3-dev libpulse-dev xz-utils libpipewire-0.3-dev libcli11-dev qt6-base-dev qt6-tools-dev libcap-dev pkexec libboost-all-dev librsvg2-bin dpkg-dev pkg-config debhelper-compat build-essential lintian cmake libnotify-dev qt6-declarative-dev extra-cmake-modules libkirigami-dev libkf6i18n-dev libkf6coreaddons-dev libkf6qqc2desktopstyle-dev libkf6iconthemes-dev jq sudo cmake gcc g++ git wget libssl-dev qcoro-qt6-dev librsvg2-dev + apt install --yes libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libavahi-client-dev libavahi-glib-dev libeigen3-dev glslang-tools libudev-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev nlohmann-json3-dev libpulse-dev xz-utils libpipewire-0.3-dev libcli11-dev qt6-base-dev qt6-tools-dev libcap-dev pkexec libboost-all-dev librsvg2-bin dpkg-dev pkg-config debhelper-compat build-essential lintian cmake libnotify-dev qt6-declarative-dev extra-cmake-modules libkirigami-dev libkf6i18n-dev libkf6coreaddons-dev libkf6qqc2desktopstyle-dev libkf6iconthemes-dev jq sudo cmake gcc g++ git wget libssl-dev qcoro-qt6-dev librsvg2-dev libarchive-dev - uses: actions/checkout@v4 with: diff --git a/.github/workflows/Locales.yml b/.github/workflows/Locales.yml index 1cefef9b..722586f6 100644 --- a/.github/workflows/Locales.yml +++ b/.github/workflows/Locales.yml @@ -9,10 +9,14 @@ jobs: - uses: actions/checkout@v4 - name: Install dependencies - run: sudo apt-get update && sudo apt-get install gettext qt6-base-dev qt6-tools-dev qt6-l10n-tools qtchooser python3-polib + run: | + sudo apt-get update && sudo apt-get install gettext + pip install polib PyGithub - name: Check that .po files are up to date run: | - qtchooser -install qt6 $(which qmake6) - export QT_SELECT=qt6 - tools/check_messages.sh + if [[ "${{github.ref}}" == 'refs/heads/master' ]] ; then + tools/check_po.py --manage-issues --github-repository "${{ github.repository }}" --github-token "${{ github.token }}" + else + tools/check_po.py + fi diff --git a/CMakeLists.txt b/CMakeLists.txt index e1f9b1aa..b87c5bf0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,13 +17,12 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) include(FetchContent) include(ExternalProject) include(GNUInstallDirs) -include("cmake/AutoOption.cmake") option(WIVRN_USE_SYSTEM_FREETYPE "Use system FreeType" ON) -auto_option(WIVRN_USE_SYSTEM_BOOST "Use system Boost headers" AUTO) -auto_option(WIVRN_USE_SYSTEM_OPENXR "Use system OpenXR headers" AUTO) -auto_option(WIVRN_USE_SYSTEMD "Use libsystemd" AUTO) -auto_option(WIVRN_USE_LIBKTX "Use libktx" AUTO) +option(WIVRN_USE_SYSTEM_BOOST "Use system Boost headers" ON) +option(WIVRN_USE_SYSTEM_OPENXR "Use system OpenXR headers" ON) +option(WIVRN_USE_SYSTEMD "Use libsystemd" ON) +option(WIVRN_USE_LIBKTX "Use libktx" ${ANDROID}) option(WIVRN_USE_ANDROID_VALIDATION_LAYER "Download the android version of the Vulkan validation layer" OFF) option(WIVRN_BUILD_CLIENT "Build WiVRn client" OFF) option(WIVRN_BUILD_SERVER "Build WiVRn server" ON) @@ -35,12 +34,12 @@ option(WIVRN_BUILD_TEST "Build test binaries" OFF) option(WIVRN_WERROR "Treat warnings as errors" OFF) option(WIVRN_USE_NVENC "Enable nvenc (Nvidia) hardware encoder" ON) -auto_option(WIVRN_USE_VAAPI "Enable vaapi (AMD/Intel) hardware encoder" AUTO) -auto_option(WIVRN_USE_VULKAN_ENCODE "Enable vulkan video encoder" AUTO) -auto_option(WIVRN_USE_X264 "Enable x264 software encoder" AUTO) +option(WIVRN_USE_VAAPI "Enable vaapi (AMD/Intel) hardware encoder" ON) +option(WIVRN_USE_VULKAN_ENCODE "Enable vulkan video encoder" ON) +option(WIVRN_USE_X264 "Enable x264 software encoder" ON) -auto_option(WIVRN_USE_PIPEWIRE "Enable pipewire backend" AUTO) -auto_option(WIVRN_USE_PULSEAUDIO "Enable pulseaudio backend" AUTO) +option(WIVRN_USE_PIPEWIRE "Enable pipewire backend" ON) +option(WIVRN_USE_PULSEAUDIO "Enable pulseaudio backend" OFF) set(OVR_COMPAT_SEARCH_PATH "/opt/xrizer:/usr/local/lib/OpenComposite:/usr/lib/OpenComposite:/opt/OpenComposite:/opt/opencomposite" CACHE STRING "List of places to search for the OpenVR compatibility layer, separated by :") @@ -64,6 +63,12 @@ endif() option(ENABLE_COLOURED_OUTPUT "Always produce ANSI-coloured output (GNU/Clang only)." ON) +if (WIVRN_BUILD_CLIENT OR WIVRN_BUILD_SERVER OR WIVRN_BUILD_DASHBOARD OR WIVRN_BUILD_DISSECTOR) + set(NEED_COMMON TRUE) +else() + set(NEED_COMMON FALSE) +endif() + if(ENABLE_COLOURED_OUTPUT) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") add_compile_options(-fdiagnostics-color=always) @@ -75,19 +80,13 @@ endif() find_package(PkgConfig REQUIRED) find_package(Vulkan REQUIRED) find_package(Git) -if (NOT ANDROID) +if (NEED_COMMON AND NOT ANDROID) find_package(OpenSSL REQUIRED) endif() include(VulkanVersion) -if (WIVRN_USE_SYSTEM_BOOST STREQUAL "AUTO") - if(WIVRN_BUILD_DISSECTOR) - find_package(Boost 1.84.0 COMPONENTS locale url) - else() - find_package(Boost 1.75.0 COMPONENTS locale url) - endif() -elseif(WIVRN_USE_SYSTEM_BOOST STREQUAL "ON") - if(WIVRN_BUILD_DISSECTOR) +if (WIVRN_USE_SYSTEM_BOOST AND NEED_COMMON) + if (WIVRN_BUILD_DISSECTOR) find_package(Boost 1.84.0 REQUIRED COMPONENTS locale url) else() find_package(Boost 1.75.0 REQUIRED COMPONENTS locale url) @@ -104,72 +103,30 @@ if (WIVRN_BUILD_SERVER) message(FATAL_ERROR "No encoder selected, use at least one of WIVRN_USE_NVENC, WIVRN_USE_VAAPI, WIVRN_USE_VULKAN_ENCODE or WIVRN_USE_X264") endif() - if (WIVRN_USE_VAAPI STREQUAL "AUTO") - pkg_check_modules(LIBAV IMPORTED_TARGET libavcodec libavutil libswscale libavfilter) - pkg_check_modules(LIBDRM IMPORTED_TARGET libdrm) - if (LIBAV_FOUND AND LIBDRM_FOUND) - set(WIVRN_USE_VAAPI ON) - else() - set(WIVRN_USE_VAAPI OFF) - endif() - elseif (WIVRN_USE_VAAPI) + if (WIVRN_USE_VAAPI) pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET libavcodec libavutil libswscale libavfilter) pkg_check_modules(LIBDRM REQUIRED IMPORTED_TARGET libdrm) endif() - if (WIVRN_USE_VULKAN_ENCODE STREQUAL "AUTO") - if (Vulkan_VERSION VERSION_GREATER_EQUAL 1.3.283) - set(WIVRN_USE_VULKAN_ENCODE ON) - else() - set(WIVRN_USE_VULKAN_ENCODE OFF) - endif() - elseif(WIVRN_USE_VULKAN_ENCODE) + if (WIVRN_USE_VULKAN_ENCODE) if (Vulkan_VERSION VERSION_LESS 1.3.283) message(FATAL_ERROR "Vulkan video encode requires 1.3.283, found ${Vulkan_VERSION}") endif() endif() - if (WIVRN_USE_X264 STREQUAL "AUTO") - pkg_check_modules(X264 IMPORTED_TARGET x264) - if (X264_FOUND) - set(WIVRN_USE_X264 ON) - else() - set(WIVRN_USE_X264 OFF) - endif() - elseif (WIVRN_USE_X264) + if (WIVRN_USE_X264) pkg_check_modules(X264 REQUIRED IMPORTED_TARGET x264) endif() - if (WIVRN_USE_SYSTEMD STREQUAL "AUTO") - pkg_check_modules(SYSTEMD IMPORTED_TARGET libsystemd) - if (SYSTEMD_FOUND) - set(WIVRN_USE_SYSTEMD ON) - else() - set(WIVRN_USE_SYSTEMD OFF) - endif() - elseif (WIVRN_USE_SYSTEMD) + if (WIVRN_USE_SYSTEMD) pkg_check_modules(SYSTEMD REQUIRED IMPORTED_TARGET libsystemd) endif() - if (WIVRN_USE_PIPEWIRE STREQUAL "AUTO") - pkg_check_modules(libpipewire IMPORTED_TARGET libpipewire-0.3) - if (libpipewire_FOUND) - set(WIVRN_USE_PIPEWIRE ON) - else() - set(WIVRN_USE_PIPEWIRE OFF) - endif() - elseif (WIVRN_USE_PIPEWIRE) + if (WIVRN_USE_PIPEWIRE) pkg_check_modules(libpipewire REQUIRED IMPORTED_TARGET libpipewire-0.3) endif() - if (WIVRN_USE_PULSEAUDIO STREQUAL "AUTO") - pkg_check_modules(libpulse IMPORTED_TARGET libpulse) - if (libpulse_FOUND) - set(WIVRN_USE_PULSEAUDIO ON) - else() - set(WIVRN_USE_PULSEAUDIO OFF) - endif() - elseif (WIVRN_USE_PULSEAUDIO) + if (WIVRN_USE_PULSEAUDIO) pkg_check_modules(libpulse REQUIRED IMPORTED_TARGET libpulse) endif() @@ -185,7 +142,8 @@ endif() if (WIVRN_BUILD_DASHBOARD OR WIVRN_BUILD_SERVER) pkg_check_modules(librsvg-2.0 REQUIRED IMPORTED_TARGET librsvg-2.0) - find_package(PNG) + find_package(LibArchive REQUIRED) + find_package(PNG REQUIRED) endif() if (WIVRN_BUILD_DASHBOARD) @@ -214,23 +172,11 @@ if (WIVRN_BUILD_CLIENT OR WIVRN_BUILD_DASHBOARD) find_package(Gettext REQUIRED) endif() -if (WIVRN_BUILD_CLIENT) - if (WIVRN_USE_LIBKTX STREQUAL "AUTO") - if (ANDROID) - set(WIVRN_USE_LIBKTX ON) - else() - set(WIVRN_USE_LIBKTX OFF) - endif() - endif() -endif() - if (WIVRN_BUILD_CLIENT AND NOT ANDROID) pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET libavcodec libavutil libswscale libavfilter) find_package(Fontconfig REQUIRED) - if (WIVRN_USE_SYSTEM_OPENXR STREQUAL "AUTO") - find_package(OpenXR 1.1.48) - elseif(WIVRN_USE_SYSTEM_OPENXR STREQUAL "ON") + if (WIVRN_USE_SYSTEM_OPENXR) find_package(OpenXR 1.1.48 REQUIRED) endif() @@ -244,9 +190,7 @@ if(ANDROID) endif() if (WIVRN_BUILD_DISSECTOR) - if (WIVRN_USE_SYSTEM_OPENXR STREQUAL "AUTO") - find_package(OpenXR 1.1.48) - elseif(WIVRN_USE_SYSTEM_OPENXR STREQUAL "ON") + if (WIVRN_USE_SYSTEM_OPENXR) find_package(OpenXR 1.1.48 REQUIRED) endif() find_package(Wireshark REQUIRED) @@ -304,7 +248,7 @@ FetchContent_Declare(monado ) add_subdirectory(external) -if (WIVRN_BUILD_CLIENT OR WIVRN_BUILD_SERVER OR WIVRN_BUILD_DASHBOARD OR WIVRN_BUILD_DISSECTOR) +if (NEED_COMMON) add_subdirectory(common) endif() diff --git a/build.gradle b/build.gradle index 16d5e697..f9474a0d 100644 --- a/build.gradle +++ b/build.gradle @@ -83,6 +83,7 @@ android { '-DCMAKE_ANDROID_NDK_VERSION=' + ndkVersion, '-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON', '-DCMAKE_EXPORT_COMPILE_COMMANDS=ON', + '-DWIVRN_USE_SYSTEM_BOOST=OFF', '-DWIVRN_USE_SYSTEM_FREETYPE=OFF', '-DWIVRN_BUILD_CLIENT=ON', '-DWIVRN_BUILD_SERVER=OFF', diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 7c903461..1c11a214 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -13,7 +13,7 @@ if (WIVRN_USE_LIBKTX) FetchContent_MakeAvailable(libktx) endif() -if (NOT BOOST_FOUND) +if (NOT WIVRN_USE_SYSTEM_BOOST) FetchContent_MakeAvailable(boost) endif() @@ -51,7 +51,7 @@ if(ANDROID) else() add_executable(wivrn) - if (OpenXR_FOUND) + if (WIVRN_USE_SYSTEM_OPENXR) target_link_libraries(wivrn OpenXR::openxr_loader OpenXR::headers) else() FetchContent_MakeAvailable(openxr_loader) @@ -91,7 +91,22 @@ file(GLOB_RECURSE VULKAN_SHADERS CONFIGURE_DEPENDS "*.glsl") target_sources(wivrn PRIVATE ${LOCAL_SOURCE} ${VULKAN_SHADERS}) wivrn_compile_glsl(wivrn ${VULKAN_SHADERS}) -target_link_libraries(wivrn Vulkan::Vulkan spdlog::spdlog glm::glm fastgltf FreetypeHarfbuzz stb Boost::url Boost::locale) +target_link_libraries(wivrn + Boost::locale + Boost::url + EnTT::EnTT + fastgltf + FreetypeHarfbuzz + glm::glm + imspinner + simdjson + spdlog::spdlog + stb + uni-algo + Vulkan::Vulkan + wivrn-common + wivrn-external +) if (WIVRN_USE_LIBKTX) target_link_libraries(wivrn ktx_read) @@ -107,10 +122,6 @@ if(NOT ANDROID) install(TARGETS wivrn) endif() -target_link_libraries(wivrn simdjson uni-algo wivrn-common wivrn-external) - - - ############################################################################## # Dear ImGui # @@ -140,10 +151,6 @@ target_link_libraries(wivrn-imgui FreetypeHarfbuzz) target_link_libraries(wivrn wivrn-imgui) -############################################################################## -# EnTT -# -target_link_libraries(wivrn EnTT::EnTT) ############################################################################## # Vulkan Validation Layer diff --git a/client/application.cpp b/client/application.cpp index b0433274..2e612453 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -28,16 +28,20 @@ #include "utils/files.h" #include "vk/check.h" #include "wifi_lock.h" +#include "wivrn_packets.h" #include "xr/actionset.h" #include "xr/check.h" +#include "xr/htc_exts.h" +#include "xr/htc_face_tracker.h" #include "xr/meta_body_tracking_fidelity.h" -#include "xr/xr.h" +#include "xr/to_string.h" #include #include #include #include #include #include +#include #include #include #include @@ -134,7 +138,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/facebook/touch_controller_pro", - .required_extensions = {"XR_FB_touch_controller_pro"}, + .required_extensions = {XR_FB_TOUCH_CONTROLLER_PRO_EXTENSION_NAME}, .max_version = XR_MAKE_VERSION(1, 1, 0), .input_sources = { "/user/hand/left/output/haptic", @@ -247,7 +251,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/meta/touch_controller_plus", - .required_extensions = {"XR_META_touch_controller_plus"}, + .required_extensions = {XR_META_TOUCH_CONTROLLER_PLUS_EXTENSION_NAME}, .max_version = XR_MAKE_VERSION(1, 1, 0), .input_sources = { "/user/hand/left/output/haptic", @@ -348,7 +352,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/bytedance/pico_neo3_controller", - .required_extensions = {"XR_BD_controller_interaction"}, + .required_extensions = {XR_BD_CONTROLLER_INTERACTION_EXTENSION_NAME}, .input_sources = { "/user/hand/left/output/haptic", "/user/hand/right/output/haptic", @@ -391,7 +395,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/bytedance/pico4_controller", - .required_extensions = {"XR_BD_controller_interaction"}, + .required_extensions = {XR_BD_CONTROLLER_INTERACTION_EXTENSION_NAME}, .input_sources = { "/user/hand/left/output/haptic", "/user/hand/right/output/haptic", @@ -434,7 +438,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/bytedance/pico4s_controller", - .required_extensions = {"XR_BD_controller_interaction"}, + .required_extensions = {XR_BD_CONTROLLER_INTERACTION_EXTENSION_NAME}, .input_sources = { "/user/hand/left/output/haptic", "/user/hand/right/output/haptic", @@ -477,7 +481,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/htc/vive_focus3_controller", - .required_extensions = {"XR_HTC_vive_focus3_controller_interaction"}, + .required_extensions = {XR_HTC_VIVE_FOCUS3_CONTROLLER_INTERACTION_EXTENSION_NAME}, .input_sources = { "/user/hand/left/output/haptic", "/user/hand/right/output/haptic", @@ -519,7 +523,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/ext/hand_interaction_ext", - .required_extensions = {"XR_EXT_hand_interaction"}, + .required_extensions = {XR_EXT_HAND_INTERACTION_EXTENSION_NAME}, .input_sources = { "/user/hand/left/input/aim/pose", "/user/hand/left/input/grip/pose", @@ -548,11 +552,14 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/htc/vive_xr_tracker", - .required_extensions = {"XR_HTC_vive_xr_tracker_interaction", "XR_HTC_path_enumeration"}, + .required_extensions = { + XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME, + XR_HTC_PATH_ENUMERATION_EXTENSION_NAME, + }, }, interaction_profile{ .profile_name = "/interaction_profiles/ext/eye_gaze_interaction", - .required_extensions = {"XR_EXT_eye_gaze_interaction"}, + .required_extensions = {XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME}, .input_sources = { "/user/eyes_ext/input/gaze_ext/pose", }, @@ -717,15 +724,13 @@ void application::initialize_vulkan() spdlog::info("Using Vulkan validation layer"); layers.push_back("VK_LAYER_KHRONOS_validation"); } + bool debug_report_found = false; + bool debug_utils_found = false; #endif std::vector instance_extensions{}; std::unordered_set optional_device_extensions{}; -#ifndef NDEBUG - bool debug_report_found = false; - bool debug_utils_found = false; -#endif spdlog::info("Available Vulkan instance extensions:"); std::vector> extensions; for (vk::ExtensionProperties & i: vk_context.enumerateInstanceExtensionProperties(nullptr)) @@ -734,28 +739,27 @@ void application::initialize_vulkan() #ifndef NDEBUG if (!strcmp(i.extensionName, VK_EXT_DEBUG_REPORT_EXTENSION_NAME)) + { debug_report_found = true; + instance_extensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); + } - if (!strcmp(i.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME)) + if (!strcmp(i.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) and + guess_model() != model::oculus_quest) // Quest 1 lies, the extension won't load + { debug_utils_found = true; + instance_extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); + } #endif } std::ranges::sort(extensions); for (const auto & [extension_name, spec_version]: extensions) spdlog::info(" {} (version {})", extension_name, spec_version); -#ifndef NDEBUG - if (debug_utils_found && debug_report_found) - { - // debug_extensions_found = true; - // spdlog::info("Using debug extensions"); - instance_extensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); - // instance_extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); - } -#endif - vk_device_extensions.push_back(VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME); optional_device_extensions.emplace(VK_IMG_FILTER_CUBIC_EXTENSION_NAME); + optional_device_extensions.emplace(VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME); + optional_device_extensions.emplace(VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME); #ifdef __ANDROID__ vk_device_extensions.push_back(VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME); @@ -874,6 +878,7 @@ void application::initialize_vulkan() .ppEnabledExtensionNames = vk_device_extensions.data(), .pEnabledFeatures = &device_features, }, + vk::PhysicalDeviceFragmentShadingRateFeaturesKHR{}, #ifdef __ANDROID__ vk::PhysicalDeviceSamplerYcbcrConversionFeaturesKHR{ .samplerYcbcrConversion = VK_TRUE, @@ -881,6 +886,22 @@ void application::initialize_vulkan() #endif }; + if (utils::contains(vk_device_extensions, VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME) and + utils::contains(vk_device_extensions, VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME)) + { + auto [feat, fragment_feat] = vk_physical_device.getFeatures2(); + auto & create_feat = device_create_info.get(); + create_feat.primitiveFragmentShadingRate = fragment_feat.primitiveFragmentShadingRate; + create_feat.attachmentFragmentShadingRate = fragment_feat.attachmentFragmentShadingRate; + spdlog::info("Fragment shading rate features: primitive={} attachment={}", + create_feat.primitiveFragmentShadingRate, + create_feat.attachmentFragmentShadingRate); + } + else + { + device_create_info.unlink(); + } + vk_device = xr_system_id.create_device(vk_physical_device, device_create_info.get()); *vk_queue.lock() = vk_device.getQueue(vk_queue_family_index, 0); @@ -902,10 +923,16 @@ void application::initialize_vulkan() pipeline_cache = vk::raii::PipelineCache(vk_device, pipeline_cache_info); allocator.emplace(VmaAllocatorCreateInfo{ - .physicalDevice = *vk_physical_device, - .device = *vk_device, - .instance = *vk_instance, - }); + .physicalDevice = *vk_physical_device, + .device = *vk_device, + .instance = *vk_instance, + }, +#ifndef NDEBUG + debug_utils_found +#else + false +#endif + ); } void application::log_views() @@ -952,8 +979,6 @@ void application::initialize_actions() { spdlog::debug("Initializing actions"); - auto * htc_body = std::get_if(&body_tracker); - // Build an action set with all possible input sources std::vector action_sets; xr_actionset = xr::actionset(xr_instance, "all_actions", "All actions"); @@ -967,7 +992,9 @@ void application::initialize_actions() std::vector sources; for (auto & profile: interaction_profiles) { - profile.available = utils::contains_all(xr_extensions, profile.required_extensions) and profile.min_version <= api_version and profile.max_version > api_version; + profile.available = std::ranges::all_of(profile.required_extensions, [&](auto & ext) { return xr_instance.has_extension(ext); }) and + profile.min_version <= api_version and + profile.max_version > api_version; if (profile.profile_name.ends_with("khr/simple_controller")) { @@ -1008,15 +1035,15 @@ void application::initialize_actions() } if (add_palms) { - if ((api_version >= XR_MAKE_VERSION(1, 1, 0) or utils::contains(xr_extensions, XR_KHR_MAINTENANCE1_EXTENSION_NAME)) // - and utils::contains(profile.input_sources, "/user/hand/left/input/grip/pose") // + if ((api_version >= XR_MAKE_VERSION(1, 1, 0) or xr_instance.has_extension(XR_KHR_MAINTENANCE1_EXTENSION_NAME)) // + and utils::contains(profile.input_sources, "/user/hand/left/input/grip/pose") // and not utils::contains(profile.input_sources, "/user/hand/left/input/grip_surface/pose")) { spdlog::info("Adding grip_surface/pose for interaction profile {}", profile.profile_name); profile.input_sources.push_back("/user/hand/left/input/grip_surface/pose"); profile.input_sources.push_back("/user/hand/right/input/grip_surface/pose"); } - else if (utils::contains(xr_extensions, XR_EXT_PALM_POSE_EXTENSION_NAME) // + else if (xr_instance.has_extension(XR_EXT_PALM_POSE_EXTENSION_NAME) // and utils::contains(profile.input_sources, "/user/hand/left/input/grip/pose") // and not utils::contains(profile.input_sources, "/user/hand/left/input/palm_ext/pose")) { @@ -1027,14 +1054,15 @@ void application::initialize_actions() } // Dynamically add VIVE XR Trackers to the profile if available - if (htc_body && utils::contains(profile.required_extensions, XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME)) + if (utils::contains(profile.required_extensions, XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME) and + xr_instance.has_extension(XR_HTC_PATH_ENUMERATION_EXTENSION_NAME)) { - for (const auto & user_path: htc_body->get_paths()) + XrPath tracker_profile = xr_instance.string_to_path("/interaction_profiles/htc/vive_xr_tracker"); + for (const auto & user_path: xr_instance.enumerate_paths_for_interaction_profile(tracker_profile)) { - for (const auto & input_path: htc_body->get_paths(user_path)) - { - profile.input_sources.push_back(path_to_string(user_path) + path_to_string(input_path)); - } + generic_trackers.emplace_back(user_path, nullptr); + for (const auto & input_path: xr_instance.enumerate_paths_for_interaction_profile(tracker_profile, user_path)) + profile.input_sources.push_back(xr_instance.path_to_string(user_path) + xr_instance.path_to_string(input_path)); } } @@ -1082,8 +1110,14 @@ void application::initialize_actions() spaces[size_t(xr::spaces::poke_right)] = xr_session.create_action_space(a); else if (name == "/user/eyes_ext/input/gaze_ext/pose") spaces[size_t(xr::spaces::eye_gaze)] = xr_session.create_action_space(a); - else if (name.contains("/input/entity_htc/pose") && htc_body) - htc_body->add(xr_session.create_action_space(a)); + else if (name.contains("/input/entity_htc/pose")) + { + for (auto & [path, action]: generic_trackers) + { + if (name.starts_with(xr_instance.path_to_string(path))) + action = xr_session.create_action_space(a); + } + } } // Build an action set for each scene @@ -1120,7 +1154,7 @@ void application::initialize_actions() xr_bindings.push_back(XrActionSuggestedBinding{ .action = a, - .binding = string_to_path(k.input_source)}); + .binding = xr_instance.string_to_path(k.input_source)}); } } } @@ -1137,7 +1171,7 @@ void application::initialize_actions() for (const auto & name: profile.input_sources) { - xr_bindings.push_back({actions_by_name[name], string_to_path(name)}); + xr_bindings.push_back({actions_by_name[name], xr_instance.string_to_path(name)}); } try @@ -1157,7 +1191,7 @@ void application::initialize() { // LogLayersAndExtensions assert(!xr_instance); - xr_extensions.clear(); + std::vector xr_extensions; // Required extensions xr_extensions.push_back(XR_KHR_CONVERT_TIMESPEC_TIME_EXTENSION_NAME); @@ -1230,21 +1264,16 @@ void application::initialize() spdlog::info(" Orientation tracking: {}", (bool)properties.trackingProperties.orientationTracking); spdlog::info(" Position tracking: {}", (bool)properties.trackingProperties.positionTracking); - if (utils::contains(xr_extensions, XR_EXT_HAND_TRACKING_EXTENSION_NAME)) - { - XrSystemHandTrackingPropertiesEXT hand_tracking_properties = xr_system_id.hand_tracking_properties(); - spdlog::info(" Hand tracking support: {}", (bool)hand_tracking_properties.supportsHandTracking); - hand_tracking_supported = hand_tracking_properties.supportsHandTracking; - } + spdlog::info(" Hand tracking support: {}", xr_system_id.hand_tracking_supported()); - if (utils::contains(xr_extensions, XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME)) + if (xr_instance.has_extension(XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME)) { XrSystemEyeGazeInteractionPropertiesEXT eye_gaze_properties = xr_system_id.eye_gaze_interaction_properties(); spdlog::info(" Eye gaze support: {}", (bool)eye_gaze_properties.supportsEyeGazeInteraction); eye_gaze_supported = eye_gaze_properties.supportsEyeGazeInteraction; } - if (utils::contains(xr_extensions, XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME)) + if (xr_instance.has_extension(XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME)) { spdlog::info(" OpenXR post-processing extension support: true"); openxr_post_processing_supported = true; @@ -1252,93 +1281,45 @@ void application::initialize() switch (xr_system_id.passthrough_supported()) { - case xr::system::passthrough_type::no_passthrough: + case xr::passthrough_type::none: spdlog::info(" Passthrough: not supported"); break; - case xr::system::passthrough_type::bw: + case xr::passthrough_type::bw: spdlog::info(" Passthrough: black and white"); break; - case xr::system::passthrough_type::color: + case xr::passthrough_type::color: spdlog::info(" Passthrough: color"); break; } + spdlog::info(" Face tracker: {}", magic_enum::enum_name(xr_system_id.face_tracker_supported())); + spdlog::info(" Body tracker: {}", magic_enum::enum_name(xr_system_id.body_tracker_supported())); + // Log view configurations and blend modes log_views(); initialize_vulkan(); - xr_session = xr::session(xr_instance, xr_system_id, vk_instance, vk_physical_device, vk_device, vk_queue_family_index); - - { - auto spaces = xr_session.get_reference_spaces(); - spdlog::info("{} reference spaces", spaces.size()); - for (XrReferenceSpaceType i: spaces) - spdlog::info(" {}", xr::to_string(i)); - } + xr_session = xr::session(xr_instance, xr_system_id, vk_instance, vk_physical_device, vk_device, vk_queue, vk_queue_family_index); spaces[size_t(xr::spaces::view)] = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_VIEW); spaces[size_t(xr::spaces::world)] = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_STAGE); config.emplace(xr_system_id); - if (hand_tracking_supported) + // HTC face tracker fails if created later + // we can destroy it right away, it actually stores static handles + if (xr_system_id.face_tracker_supported() == xr::face_tracker_type::htc) { - left_hand = xr_session.create_hand_tracker(XR_HAND_LEFT_EXT); - right_hand = xr_session.create_hand_tracker(XR_HAND_RIGHT_EXT); + auto props = xr_system_id.htc_face_tracking_properties(); + xr::htc_face_tracker(xr_instance, xr_session, props.supportEyeFacialTracking, props.supportLipFacialTracking); } - if (utils::contains(xr_extensions, XR_FB_FACE_TRACKING2_EXTENSION_NAME)) { - XrSystemFaceTrackingProperties2FB fb_face2_properties = xr_system_id.fb_face_tracking2_properties(); - spdlog::info(" FB face tracking support: {}", (bool)fb_face2_properties.supportsVisualFaceTracking); - if (fb_face2_properties.supportsVisualFaceTracking) - face_tracker.emplace(xr_instance, xr_session); - } - - if (std::holds_alternative(face_tracker) && utils::contains(xr_extensions, XR_HTC_FACIAL_TRACKING_EXTENSION_NAME)) - { - XrSystemFacialTrackingPropertiesHTC htc_face_properties = xr_system_id.htc_face_tracking_properties(); - spdlog::info(" HTC eye tracking support: {}", (bool)htc_face_properties.supportEyeFacialTracking); - spdlog::info(" HTC lip tracking support: {}", (bool)htc_face_properties.supportLipFacialTracking); - if (htc_face_properties.supportEyeFacialTracking || htc_face_properties.supportLipFacialTracking) - face_tracker.emplace(xr_instance, xr_session, htc_face_properties.supportEyeFacialTracking, htc_face_properties.supportLipFacialTracking); - } - - if (std::holds_alternative(face_tracker) && eye_gaze_supported) - { - switch (guess_model()) - { - case model::pico_4_pro: - case model::pico_4_enterprise: - spdlog::info(" PICO face tracking support: true"); - face_tracker.emplace(xr_instance, xr_session); - break; - default: - break; - } - } - - if (utils::contains_all(xr_extensions, std::array{XR_FB_BODY_TRACKING_EXTENSION_NAME, XR_META_BODY_TRACKING_FULL_BODY_EXTENSION_NAME, XR_META_BODY_TRACKING_FIDELITY_EXTENSION_NAME})) - { - XrSystemBodyTrackingPropertiesFB fb_body_properties = xr_system_id.fb_body_tracking_properties(); - spdlog::info(" FB body tracking support: {}", (bool)fb_body_properties.supportsBodyTracking); - if (fb_body_properties.supportsBodyTracking) - body_tracker.emplace(xr_instance, xr_session); - } - - if (std::holds_alternative(body_tracker) && utils::contains_all(xr_extensions, std::array{XR_HTC_PATH_ENUMERATION_EXTENSION_NAME, XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME})) - { - spdlog::info(" HTC body tracking support: true"); - body_tracker.emplace(xr_instance, xr_session); - } - - if (std::holds_alternative(body_tracker) && utils::contains(xr_extensions, XR_BD_BODY_TRACKING_EXTENSION_NAME)) - { - XrSystemBodyTrackingPropertiesBD bd_body_properties = xr_system_id.bd_body_tracking_properties(); - spdlog::info(" PICO body tracking support: {}", (bool)bd_body_properties.supportsBodyTracking); - if (bd_body_properties.supportsBodyTracking) - body_tracker.emplace(xr_instance, xr_session); + auto spaces = xr_session.get_reference_spaces(); + spdlog::info("{} reference spaces", spaces.size()); + for (XrReferenceSpaceType i: spaces) + spdlog::info(" {}", xr::to_string(i)); } vk::CommandPoolCreateInfo cmdpool_create_info; @@ -1875,13 +1856,6 @@ void application::poll_events() exit_requested = true; } break; - case XR_TYPE_EVENT_DATA_INTERACTION_PROFILE_CHANGED: { - if (auto * htc_body = std::get_if(&body_tracker)) - { - htc_body->update_active(); - } - } - break; case XR_TYPE_EVENT_DATA_REFERENCE_SPACE_CHANGE_PENDING: break; case XR_TYPE_EVENT_DATA_SESSION_STATE_CHANGED: { diff --git a/client/application.h b/client/application.h index cb17f87e..368983fa 100644 --- a/client/application.h +++ b/client/application.h @@ -28,14 +28,11 @@ #include "utils/thread_safe.h" #include "vk/vk_allocator.h" #include "wifi_lock.h" -#include "xr/fb_body_tracker.h" -#include "xr/fb_face_tracker2.h" -#include "xr/hand_tracker.h" -#include "xr/htc_body_tracker.h" -#include "xr/htc_face_tracker.h" -#include "xr/pico_body_tracker.h" -#include "xr/pico_face_tracker.h" -#include "xr/xr.h" +#include "xr/actionset.h" +#include "xr/instance.h" +#include "xr/session.h" +#include "xr/swapchain.h" +#include "xr/system.h" #include #include #include @@ -126,12 +123,7 @@ class application : public singleton xr::actionset xr_actionset; std::vector> actions; - bool hand_tracking_supported = false; - xr::hand_tracker left_hand; - xr::hand_tracker right_hand; - - std::variant face_tracker; - std::variant body_tracker; + std::vector> generic_trackers; bool eye_gaze_supported = false; @@ -141,7 +133,6 @@ class application : public singleton bool session_focused = false; bool session_visible = false; bool debug_extensions_found = false; - std::vector xr_extensions; std::vector vk_device_extensions; std::atomic exit_requested = false; std::filesystem::path config_path; @@ -271,16 +262,6 @@ public: return std::make_pair(position, orientation); } - static XrPath string_to_path(const std::string & s) - { - return instance().xr_instance.string_to_path(s); - } - - static std::string path_to_string(XrPath p) - { - return instance().xr_instance.path_to_string(p); - } - void run(); static void push_scene(std::shared_ptr); @@ -351,16 +332,6 @@ public: // #endif } - static XrTime now() - { - return instance().xr_instance.now(); - } - - static uint32_t queue_family_index() - { - return instance().vk_queue_family_index; - } - static thread_safe & get_queue() { return instance().vk_queue; @@ -376,26 +347,21 @@ public: return intent; } - static vk::raii::PhysicalDevice & get_physical_device() - { - return instance().vk_physical_device; - } - static const vk::PhysicalDeviceProperties & get_physical_device_properties() { return instance().physical_device_properties; } - static vk::raii::Device & get_device() - { - return instance().vk_device; - } - static vk::raii::Instance & get_vulkan_instance() { return instance().vk_instance; } + static xr::system & get_system() + { + return instance().xr_system_id; + } + static vk::raii::PipelineCache & get_pipeline_cache() { return instance().pipeline_cache; @@ -416,21 +382,6 @@ public: return instance().last_scene_cpu_time; } - static bool get_hand_tracking_supported() - { - return instance().hand_tracking_supported; - } - - static bool get_face_tracking_supported() - { - return !std::holds_alternative(instance().face_tracker); - } - - static bool get_body_tracking_supported() - { - return !std::holds_alternative(instance().body_tracker); - } - static bool get_eye_gaze_supported() { return instance().eye_gaze_supported; @@ -441,29 +392,9 @@ public: return instance().openxr_post_processing_supported; } - static xr::hand_tracker & get_left_hand() + static auto & get_generic_trackers() { - return instance().left_hand; - } - - static xr::hand_tracker & get_right_hand() - { - return instance().right_hand; - } - - static auto & get_face_tracker() - { - return instance().face_tracker; - } - - static auto & get_body_tracker() - { - return instance().body_tracker; - } - - static const std::vector & get_xr_extensions() - { - return instance().xr_extensions; + return instance().generic_trackers; } static const std::vector & get_vk_device_extensions() diff --git a/client/configuration.cpp b/client/configuration.cpp index abe7f15e..a8b2bf09 100644 --- a/client/configuration.cpp +++ b/client/configuration.cpp @@ -82,6 +82,8 @@ bool configuration::check_feature(feature f) const { std::lock_guard lock(mutex); + auto & system = application::get_system(); + auto it = features.find(f); if (it == features.end()) return false; @@ -94,7 +96,7 @@ bool configuration::check_feature(feature f) const case feature::microphone: break; case feature::hand_tracking: - if (not application::get_hand_tracking_supported()) + if (not system.hand_tracking_supported()) return false; break; case feature::eye_gaze: @@ -102,50 +104,12 @@ bool configuration::check_feature(feature f) const return false; break; case feature::face_tracking: - switch (guess_model()) - { - case model::htc_vive_focus_3: - case model::htc_vive_focus_vision: - case model::htc_vive_xr_elite: - if (not std::holds_alternative(application::get_face_tracker())) - return false; - break; - case model::pico_4_pro: - case model::pico_4_enterprise: - if (not std::holds_alternative(application::get_face_tracker())) - return false; - break; - default: - if (not std::holds_alternative(application::get_face_tracker())) - return false; - break; - } + if (system.face_tracker_supported() == xr::face_tracker_type::none) + return false; break; case feature::body_tracking: - switch (guess_model()) - { - case model::meta_quest_3: - case model::meta_quest_3s: - if (not std::holds_alternative(application::get_body_tracker())) - return false; - break; - case model::htc_vive_focus_3: - case model::htc_vive_xr_elite: - case model::htc_vive_focus_vision: - if (not std::holds_alternative(application::get_body_tracker())) - return false; - break; - case model::pico_neo_3: - case model::pico_4: - case model::pico_4s: - case model::pico_4_pro: - case model::pico_4_enterprise: - if (not std::holds_alternative(application::get_body_tracker())) - return false; - break; - default: - break; - } + if (system.body_tracker_supported() == xr::body_tracker_type::none) + return false; break; } } @@ -181,8 +145,8 @@ void configuration::set_feature(feature f, bool state) configuration::configuration(xr::system & system) { - passthrough_enabled = system.passthrough_supported() == xr::system::passthrough_type::color; - features[feature::hand_tracking] = application::get_hand_tracking_supported(); + passthrough_enabled = system.passthrough_supported() == xr::passthrough_type::color; + features[feature::hand_tracking] = system.hand_tracking_supported(); try { simdjson::dom::parser parser; @@ -214,6 +178,9 @@ configuration::configuration(xr::system & system) if (auto val = root["resolution_scale"]; val.is_double()) resolution_scale = val.get_double(); + if (auto val = root["enable_stream_gui"]; val.is_bool()) + enable_stream_gui = val.get_bool(); + if (auto val = root["sgsr"]; val.is_object()) parse_sgsr_options(val.get_object()); @@ -240,7 +207,7 @@ configuration::configuration(xr::system & system) features[i] = val.get_bool(); } - if (system.passthrough_supported() == xr::system::passthrough_type::no_passthrough) + if (system.passthrough_supported() == xr::passthrough_type::none) passthrough_enabled = false; if (auto val = root["override_foveation_enable"]; val.is_bool()) @@ -266,7 +233,7 @@ configuration::configuration(xr::system & system) resolution_scale = 1.4; sgsr = {}; openxr_post_processing = {}; - passthrough_enabled = system.passthrough_supported() == xr::system::passthrough_type::color; + passthrough_enabled = system.passthrough_supported() == xr::passthrough_type::color; } } @@ -365,6 +332,7 @@ void configuration::save() json << ",\"mic_unprocessed_audio\":" << std::boolalpha << mic_unprocessed_audio; json << ",\"fb_lower_body\":" << std::boolalpha << fb_lower_body; json << ",\"fb_hip\":" << std::boolalpha << fb_hip; + json << ",\"enable_stream_gui\":" << std::boolalpha << enable_stream_gui; for (auto & [key, value]: features) json << "," << key << ":" << std::boolalpha << value; json << ",\"virtual_keyboard_layout\":" << json_string(virtual_keyboard_layout); diff --git a/client/configuration.h b/client/configuration.h index 8d34faae..a0f6ecad 100644 --- a/client/configuration.h +++ b/client/configuration.h @@ -56,6 +56,8 @@ public: bool fb_lower_body = false; bool fb_hip = true; + bool enable_stream_gui = true; + // Snapdragon Game Super Resolution struct sgsr_settings { diff --git a/client/decoder/shard_accumulator.cpp b/client/decoder/shard_accumulator.cpp index 6b6106ce..900c05ee 100644 --- a/client/decoder/shard_accumulator.cpp +++ b/client/decoder/shard_accumulator.cpp @@ -18,9 +18,9 @@ */ #include "shard_accumulator.h" -#include "application.h" -#include "scenes/stream.h" +#include "scenes/stream.h" // IWYU pragma: keep #include "spdlog/spdlog.h" +#include "xr/instance.h" namespace wivrn { @@ -63,10 +63,10 @@ static bool is_complete(const shard_set & shards) return true; } -std::optional shard_set::insert(data_shard && shard) +std::optional shard_set::insert(data_shard && shard, xr::instance & instance) { if (empty()) - feedback.received_first_packet = application::now(); + feedback.received_first_packet = instance.now(); auto idx = shard.shard_idx; if (idx >= data.size()) @@ -121,12 +121,12 @@ void shard_accumulator::push_shard(video_stream_data_shard && shard) } else if (frame_diff == 0) { - auto shard_idx = current.insert(std::move(shard)); + auto shard_idx = current.insert(std::move(shard), instance); try_submit_frame(shard_idx); } else if (frame_diff == 1) { - next.insert(std::move(shard)); + next.insert(std::move(shard), instance); if (is_complete(next)) { debug_why_not_sent(current); @@ -191,7 +191,7 @@ void shard_accumulator::try_submit_frame(uint16_t shard_idx) if (not frame_complete) return; - current.feedback.received_last_packet = application::now(); + current.feedback.received_last_packet = instance.now(); current.feedback.sent_to_decoder = current.feedback.received_last_packet; data_shard::timing_info_t timing_info = data_shards.back()->timing_info.value_or(data_shard::timing_info_t{}); current.feedback.encode_begin = timing_info.encode_begin; @@ -216,7 +216,7 @@ void shard_accumulator::try_submit_frame(uint16_t shard_idx) void shard_accumulator::send_feedback(wivrn::from_headset::feedback & feedback) { if (not feedback.received_last_packet) - feedback.received_first_packet = application::now(); + feedback.received_first_packet = instance.now(); auto scene = weak_scene.lock(); if (scene) scene->send_feedback(feedback); diff --git a/client/decoder/shard_accumulator.h b/client/decoder/shard_accumulator.h index 4777de7f..406c0c49 100644 --- a/client/decoder/shard_accumulator.h +++ b/client/decoder/shard_accumulator.h @@ -34,6 +34,11 @@ using decoder_impl = ::wivrn::ffmpeg::decoder; #include #include +namespace xr +{ +class instance; +} + namespace wivrn { @@ -50,7 +55,7 @@ public: void reset(uint64_t frame_index); bool empty() const; - std::optional insert(data_shard &&); + std::optional insert(data_shard &&, xr::instance & instance); wivrn::from_headset::feedback feedback{}; @@ -70,11 +75,13 @@ private: shard_set current; shard_set next; std::weak_ptr weak_scene; + xr::instance & instance; public: explicit shard_accumulator( vk::raii::Device & device, vk::raii::PhysicalDevice & physical_device, + xr::instance & instance, const wivrn::to_headset::video_stream_description::item & description, float fps, std::weak_ptr scene, @@ -82,7 +89,8 @@ public: decoder(std::make_shared(device, physical_device, description, fps, stream_index, scene, this)), current(stream_index), next(stream_index), - weak_scene(scene) + weak_scene(scene), + instance(instance) { next.reset(1); } diff --git a/client/render/gpu_buffer.h b/client/render/gpu_buffer.h index 7f03c03e..892dc3fb 100644 --- a/client/render/gpu_buffer.h +++ b/client/render/gpu_buffer.h @@ -18,7 +18,6 @@ #pragma once -#include "application.h" #include "utils/alignment.h" #include "vk/allocation.h" #include @@ -115,10 +114,10 @@ public: } } - buffer_allocation copy_to_gpu() + buffer_allocation copy_to_gpu(vk::raii::Device & device) { buffer_allocation gpu_buffer{ - application::get_device(), + device, vk::BufferCreateInfo{ .size = bytes.size(), .usage = usage}, diff --git a/client/render/imgui_impl.cpp b/client/render/imgui_impl.cpp index 53d59862..75556eca 100644 --- a/client/render/imgui_impl.cpp +++ b/client/render/imgui_impl.cpp @@ -345,9 +345,9 @@ imgui_context::imgui_context( ImGui_ImplVulkan_InitInfo init_info = { .Instance = *application::get_vulkan_instance(), - .PhysicalDevice = *application::get_physical_device(), - .Device = *application::get_device(), - .QueueFamily = application::queue_family_index(), + .PhysicalDevice = *physical_device, + .Device = *device, + .QueueFamily = queue_family_index, .Queue = *queue.get_unsafe(), .RenderPass = *renderpass, .MinImageCount = 2, @@ -718,7 +718,7 @@ void imgui_context::new_frame(XrTime display_time) ImPlot::SetCurrentContext(plot_context); if (last_display_time) - io.DeltaTime = std::min((display_time - last_display_time) * 1e-9f, 0.0166f); + io.DeltaTime = std::clamp((display_time - last_display_time) * 1e-9f, 0.001f, 0.0166f); last_display_time = display_time; // Uses the window list from last frame @@ -1099,6 +1099,13 @@ ImTextureID imgui_context::load_texture(const std::string & filename) void imgui_context::free_texture(ImTextureID texture) { + // Make sure we are done using the texture + std::vector fences; + for (auto & f: command_buffers) + fences.push_back(*f.fence); + if (auto result = device.waitForFences(fences, true, 1'000'000'000); result != vk::Result::eSuccess) + spdlog::error("vkWaitForfences: {}", vk::to_string(result)); + textures.erase(texture); } diff --git a/client/render/scene_loader.cpp b/client/render/scene_loader.cpp index 66ba86a4..07ceddfe 100644 --- a/client/render/scene_loader.cpp +++ b/client/render/scene_loader.cpp @@ -785,7 +785,7 @@ entt::registry scene_loader::operator()(const std::filesystem::path & gltf_path) // Copy the staging buffer to the GPU spdlog::debug("Uploading scene data ({} bytes) to GPU memory", staging_buffer.size()); - auto buffer = std::make_shared(staging_buffer.copy_to_gpu()); + auto buffer = std::make_shared(staging_buffer.copy_to_gpu(device)); for (auto & i: materials) i->buffer = buffer; diff --git a/client/render/scene_renderer.cpp b/client/render/scene_renderer.cpp index d944c559..da28ec8f 100644 --- a/client/render/scene_renderer.cpp +++ b/client/render/scene_renderer.cpp @@ -28,6 +28,7 @@ #include "vk/allocation.h" #include "vk/pipeline.h" #include "vk/shader.h" +#include "vk/specialization_constants.h" #include #include #include @@ -535,34 +536,11 @@ vk::raii::Pipeline scene_renderer::create_pipeline(const pipeline_info & info) auto vertex_shader = load_shader(device, info.shader_name + ".vert"); auto fragment_shader = load_shader(device, info.shader_name + ".frag"); - std::array specialization_constants_desc{ - vk::SpecializationMapEntry{ - .constantID = 0, - .offset = offsetof(pipeline_info, nb_texcoords), - .size = sizeof(int32_t), - }, - vk::SpecializationMapEntry{ - .constantID = 1, - .offset = offsetof(pipeline_info, dithering), - .size = sizeof(VkBool32), - }, - vk::SpecializationMapEntry{ - .constantID = 2, - .offset = offsetof(pipeline_info, alpha_cutout), - .size = sizeof(VkBool32), - }, - vk::SpecializationMapEntry{ - .constantID = 3, - .offset = offsetof(pipeline_info, skinning), - .size = sizeof(VkBool32), - }}; - - vk::SpecializationInfo specialization{ - .mapEntryCount = specialization_constants_desc.size(), - .pMapEntries = specialization_constants_desc.data(), - .dataSize = sizeof(pipeline_info), - .pData = &info, - }; + auto specialization = make_specialization_constants( + int32_t(info.nb_texcoords), + VkBool32(info.dithering), + VkBool32(info.alpha_cutout), + VkBool32(info.skinning)); return vk::raii::Pipeline{ device, @@ -573,14 +551,14 @@ vk::raii::Pipeline scene_renderer::create_pipeline(const pipeline_info & info) .stage = vk::ShaderStageFlagBits::eVertex, .module = *vertex_shader, .pName = "main", - .pSpecializationInfo = &specialization, + .pSpecializationInfo = specialization, }, vk::PipelineShaderStageCreateInfo{ .stage = vk::ShaderStageFlagBits::eFragment, .module = *fragment_shader, .pName = "main", - .pSpecializationInfo = &specialization, + .pSpecializationInfo = specialization, }, }, @@ -797,7 +775,7 @@ void scene_renderer::update_material_descriptor_set(renderer::material & materia device.updateDescriptorSets(write_ds, {}); } -static void print_scene_hierarchy(const entt::registry & scene, entt::entity root = entt::null, int level = 0) +[[maybe_unused]] static void print_scene_hierarchy(const entt::registry & scene, entt::entity root = entt::null, int level = 0) { if (level == 0) spdlog::info("Node hierarchy:"); diff --git a/client/render/text_rasterizer.cpp b/client/render/text_rasterizer.cpp index d206aa15..ac0f7a83 100644 --- a/client/render/text_rasterizer.cpp +++ b/client/render/text_rasterizer.cpp @@ -139,46 +139,42 @@ text_rasterizer::text_rasterizer(vk::raii::Device & device, vk::raii::PhysicalDe image_allocation text_rasterizer::create_image(vk::Extent2D size) { - image_allocation alloc{device, - vk::ImageCreateInfo{ - .imageType = vk::ImageType::e2D, - .format = text::format, - .extent = { - .width = size.width, - .height = size.height, - .depth = 1, - }, - .mipLevels = 1, - .arrayLayers = 1, - .samples = vk::SampleCountFlagBits::e1, - .tiling = vk::ImageTiling::eOptimal, - .usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst, - .sharingMode = vk::SharingMode::eExclusive, - .initialLayout = vk::ImageLayout::eUndefined, - }, - VmaAllocationCreateInfo{ - .flags = 0, - .usage = VMA_MEMORY_USAGE_AUTO, - }}; - - application::set_debug_reports_name(alloc, "text_rasterizer image"); - return alloc; + return {device, + vk::ImageCreateInfo{ + .imageType = vk::ImageType::e2D, + .format = text::format, + .extent = { + .width = size.width, + .height = size.height, + .depth = 1, + }, + .mipLevels = 1, + .arrayLayers = 1, + .samples = vk::SampleCountFlagBits::e1, + .tiling = vk::ImageTiling::eOptimal, + .usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst, + .sharingMode = vk::SharingMode::eExclusive, + .initialLayout = vk::ImageLayout::eUndefined, + }, + VmaAllocationCreateInfo{ + .flags = 0, + .usage = VMA_MEMORY_USAGE_AUTO, + }, + "text_rasterizer image"}; } buffer_allocation text_rasterizer::create_buffer(size_t size) { - buffer_allocation alloc{device, - vk::BufferCreateInfo{ - .size = size, - .usage = vk::BufferUsageFlagBits::eTransferSrc, - }, - VmaAllocationCreateInfo{ - .flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT, - .usage = VMA_MEMORY_USAGE_AUTO, - }}; - application::set_debug_reports_name(alloc, "text_rasterizer buffer"); - - return alloc; + return {device, + vk::BufferCreateInfo{ + .size = size, + .usage = vk::BufferUsageFlagBits::eTransferSrc, + }, + VmaAllocationCreateInfo{ + .flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT, + .usage = VMA_MEMORY_USAGE_AUTO, + }, + "text_rasterizer buffer"}; } text_rasterizer::~text_rasterizer() diff --git a/client/scene.cpp b/client/scene.cpp index feeb29fe..684922ee 100644 --- a/client/scene.cpp +++ b/client/scene.cpp @@ -51,8 +51,6 @@ scene::scene(key, const meta & current_meta, std::span support queue_family_index(application::instance().vk_queue_family_index), current_meta(current_meta) { - passthrough_supported = system.passthrough_supported(); - swapchain_format = vk::Format::eUndefined; spdlog::info("Supported swapchain formats:"); @@ -443,7 +441,7 @@ std::pair scene::load_gltf(const std::filesyst node.layer_mask = layer_mask; assert(renderer); - scene_loader loader(device, physical_device, queue, application::queue_family_index(), renderer->get_default_material()); + scene_loader loader(device, physical_device, queue, queue_family_index, renderer->get_default_material()); loader.add_prefab(world, loader(path), entity); diff --git a/client/scene.h b/client/scene.h index e84bbcea..9593100c 100644 --- a/client/scene.h +++ b/client/scene.h @@ -103,7 +103,6 @@ public: protected: vk::Format swapchain_format; vk::Format depth_format; - xr::system::passthrough_type passthrough_supported; bool composition_layer_depth_test_supported; bool composition_layer_color_scale_bias_supported; diff --git a/client/scenes/lobby.cpp b/client/scenes/lobby.cpp index cd328c19..27fa5a17 100644 --- a/client/scenes/lobby.cpp +++ b/client/scenes/lobby.cpp @@ -383,9 +383,18 @@ void scenes::lobby::connect(const configuration::server_data & data) data.manual); } -std::optional scenes::lobby::check_recenter_gesture(const std::array & joints) +std::optional scenes::lobby::check_recenter_gesture(xr::spaces space, const std::optional> & joints) { - const auto & palm = joints[XR_HAND_JOINT_PALM_EXT].first; + if (recentering_context and std::get<0>(*recentering_context) != space) + return std::nullopt; + + if (not joints) + { + recentering_context.reset(); + return std::nullopt; + } + + const auto & palm = (*joints)[XR_HAND_JOINT_PALM_EXT].first; const auto & o = palm.pose.orientation; const auto & p = palm.pose.position; glm::quat q{o.w, o.x, o.y, o.z}; @@ -393,102 +402,130 @@ std::optional scenes::lobby::check_recenter_gesture(const std::array< if (glm::dot(q * glm::vec3(0, 1, 0), glm::vec3(0, -1, 0)) > constants::lobby::recenter_cosangle_min) { + recentering_context.emplace(space, glm::vec3{}, 0); return v + glm::vec3(0, constants::lobby::recenter_distance_up, 0) + q * glm::vec3(0, 0, -constants::lobby::recenter_distance_front); } + recentering_context.reset(); return std::nullopt; } std::optional scenes::lobby::check_recenter_action(XrTime predicted_display_time, glm::vec3 head_position) { - std::optional> aim; - glm::vec3 offset_position; - glm::quat offset_orientation; + xr::spaces controller; + glm::vec3 recenter_position; + float recenter_distance; - if (application::read_action_bool(recenter_left_action).value_or(std::pair{0, false}).second) + if (recentering_context) { - aim = application::locate_controller(application::space(xr::spaces::aim_left), application::space(xr::spaces::world), predicted_display_time); - std::tie(offset_position, offset_orientation) = input->offset[xr::spaces::aim_left]; - } - - if (application::read_action_bool(recenter_right_action).value_or(std::pair{0, false}).second) - { - aim = application::locate_controller(application::space(xr::spaces::aim_right), application::space(xr::spaces::world), predicted_display_time); - std::tie(offset_position, offset_orientation) = input->offset[xr::spaces::aim_right]; - } - - if (aim) - { - // Handle controller offset - aim->first = aim->first + glm::mat3_cast(aim->second * offset_orientation) * offset_position; - aim->second = aim->second * offset_orientation; - - if (not gui_recenter_position or not gui_recenter_distance) + controller = std::get<0>(*recentering_context); + bool state; + switch (controller) { - // First frame where the recenter action is active - imgui_context::controller_state state{ - .active = true, - .aim_position = aim->first, - .aim_orientation = aim->second, - }; + case xr::spaces::aim_left: + state = application::read_action_bool(recenter_left_action).value_or(std::pair{0, false}).second; + break; - imgui_ctx->compute_pointer_position(state); + case xr::spaces::aim_right: + state = application::read_action_bool(recenter_right_action).value_or(std::pair{0, false}).second; + break; - if (state.pointer_position) // TODO: check that the pointer is inside an imgui window - { - auto M = glm::mat3_cast(imgui_ctx->layers()[0].orientation); + default: + return std::nullopt; + } - // Pointer position in world - glm::vec3 world_pointer_position = imgui_ctx->rw_from_vp(*state.pointer_position); + if (not state) + { + recentering_context.reset(); + return std::nullopt; + } + } + else if (auto state = application::read_action_bool(recenter_left_action); state and state->second) + controller = xr::spaces::aim_left; + else if (auto state = application::read_action_bool(recenter_right_action); state and state->second) + controller = xr::spaces::aim_right; + else + return std::nullopt; - // Pointer position in GUI - gui_recenter_position = glm::transpose(M) * (world_pointer_position - imgui_ctx->layers()[0].position); - gui_recenter_distance = glm::length(state.aim_position - world_pointer_position); - } - else - { - gui_recenter_position = glm::vec3(0, 0, 0); - gui_recenter_distance = constants::lobby::recenter_action_distance; - } + auto aim = application::locate_controller(application::space(controller), application::space(xr::spaces::world), predicted_display_time); + + if (not aim) + { + // The controller cannot be located + recentering_context.reset(); + return std::nullopt; + } + + // Handle controller offset + auto [offset_position, offset_orientation] = input->offset[controller]; + aim->first = aim->first + glm::mat3_cast(aim->second * offset_orientation) * offset_position; + aim->second = aim->second * offset_orientation; + + if (not recentering_context) + { + // First frame of recentering + imgui_context::controller_state state{ + .active = true, + .aim_position = aim->first, + .aim_orientation = aim->second, + }; + + imgui_ctx->compute_pointer_position(state); + + if (state.pointer_position) // TODO: check that the pointer is inside an imgui window + { + auto M = glm::mat3_cast(imgui_ctx->layers()[0].orientation); + + // Pointer position in world + glm::vec3 world_pointer_position = imgui_ctx->rw_from_vp(*state.pointer_position); + + // Pointer position in GUI + recenter_position = glm::transpose(M) * (world_pointer_position - imgui_ctx->layers()[0].position); + recenter_distance = glm::length(state.aim_position - world_pointer_position); } else { - // Subsequent frames: find the GUI position that gives the correct world pointer position - glm::vec3 controller_direction = -glm::column(glm::mat3_cast(aim->second), 2); - glm::vec3 wanted_world_pointer_position = aim->first + controller_direction * *gui_recenter_distance; - - // I'm sure there's an analytical solution but I can't be bothered to write it so - // let's use a gradient descent instead - auto f = [&](glm::vec3 new_gui_position) { - auto q = compute_gui_orientation(head_position, new_gui_position); - auto M = glm::mat3_cast(q); // plane-to-world transform - - glm::vec3 world_pointer_position = new_gui_position + M * *gui_recenter_position; - - return world_pointer_position - wanted_world_pointer_position; - }; - - // One step is usually enough, the solution will continuously improve in the next frames - glm::vec3 gui_position = imgui_ctx->layers()[0].position; - float eps = 0.01; - glm::vec3 obj = f(gui_position); - glm::vec3 obj_dx = (f(gui_position + glm::vec3(eps, 0, 0)) - obj) / eps; - glm::vec3 obj_dy = (f(gui_position + glm::vec3(0, eps, 0)) - obj) / eps; - glm::vec3 obj_dz = (f(gui_position + glm::vec3(0, 0, eps)) - obj) / eps; - - glm::mat3 jacobian{obj_dx, obj_dy, obj_dz}; - - gui_position -= glm::inverse(jacobian) * obj; - - return gui_position; + // Use the center of the GUI if the controller points outside of the GUI + recenter_position = glm::vec3(0, 0, 0); + recenter_distance = constants::lobby::recenter_action_distance; } + + recentering_context.emplace(controller, recenter_position, recenter_distance); + return std::nullopt; } else { - gui_recenter_position.reset(); - } + // Subsequent frames: find the GUI position that gives the correct world pointer position + std::tie(controller, recenter_position, recenter_distance) = *recentering_context; - return std::nullopt; + glm::vec3 controller_direction = -glm::column(glm::mat3_cast(aim->second), 2); + glm::vec3 wanted_world_pointer_position = aim->first + controller_direction * recenter_distance; + + // I'm sure there's an analytical solution but I can't be bothered to write it so + // let's use a gradient descent instead + auto f = [&](glm::vec3 new_gui_position) { + auto q = compute_gui_orientation(head_position, new_gui_position); + auto M = glm::mat3_cast(q); // plane-to-world transform + + glm::vec3 world_pointer_position = new_gui_position + M * recenter_position; + + return world_pointer_position - wanted_world_pointer_position; + }; + + // One step is usually enough, the solution will continuously improve in the next frames + glm::vec3 gui_position = imgui_ctx->layers()[0].position; + float eps = 0.01; + glm::vec3 obj = f(gui_position); + glm::vec3 obj_dx = (f(gui_position + glm::vec3(eps, 0, 0)) - obj) / eps; + glm::vec3 obj_dy = (f(gui_position + glm::vec3(0, eps, 0)) - obj) / eps; + glm::vec3 obj_dz = (f(gui_position + glm::vec3(0, 0, eps)) - obj) / eps; + + glm::mat3 jacobian{obj_dx, obj_dy, obj_dz}; + + gui_position -= glm::inverse(jacobian) * obj; + + return gui_position; + } } std::optional scenes::lobby::check_recenter_gui(glm::vec3 head_position, glm::quat head_orientation) @@ -612,26 +649,24 @@ void scenes::lobby::render(const XrFrameState & frame_state) if (!new_gui_position and head_position) new_gui_position = check_recenter_action(frame_state.predictedDisplayTime, head_position->first); - if (application::get_hand_tracking_supported()) + if (left_hand and right_hand) { - auto left = application::get_left_hand().locate(world_space, frame_state.predictedDisplayTime); - auto right = application::get_right_hand().locate(world_space, frame_state.predictedDisplayTime); + auto left = left_hand->locate(world_space, frame_state.predictedDisplayTime); + auto right = right_hand->locate(world_space, frame_state.predictedDisplayTime); hand_model::apply(world, left, right); if (left and xr::hand_tracker::check_flags(*left, XR_SPACE_LOCATION_POSITION_TRACKED_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT, 0)) - { hide_left_controller = true; - if (!new_gui_position) - new_gui_position = check_recenter_gesture(*left); - } if (right and xr::hand_tracker::check_flags(*right, XR_SPACE_LOCATION_POSITION_TRACKED_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT, 0)) - { hide_right_controller = true; - if (!new_gui_position) - new_gui_position = check_recenter_gesture(*right); - } + + if (not new_gui_position) + new_gui_position = check_recenter_gesture(xr::spaces::palm_left, left); + + if (not new_gui_position) + new_gui_position = check_recenter_gesture(xr::spaces::palm_right, right); } if (head_position && new_gui_position) @@ -763,7 +798,7 @@ void scenes::lobby::on_focused() // assert(std::ranges::all_of(views, [height](const XrViewConfigurationView & view) { return view.recommendedImageRectHeight == height; })); renderer.emplace(device, physical_device, queue, commandpool); - loader.emplace(device, physical_device, queue, application::queue_family_index(), renderer->get_default_material()); + loader.emplace(device, physical_device, queue, queue_family_index, renderer->get_default_material()); lobby_entity = load_gltf("ground.gltf", layer_lobby).first; @@ -800,12 +835,6 @@ void scenes::lobby::on_focused() xyz_axes_right_controller = load_gltf("xyz-arrows.glb", layer_controllers).first; #endif - if (application::get_hand_tracking_supported()) - { - hand_model::add_hand(*this, XR_HAND_LEFT_EXT, "left-hand.glb", layer_controllers); - hand_model::add_hand(*this, XR_HAND_RIGHT_EXT, "right-hand.glb", layer_controllers); - } - recenter_left_action = get_action("recenter_left").first; recenter_right_action = get_action("recenter_right").first; @@ -827,21 +856,19 @@ void scenes::lobby::on_focused() .haptic_output = get_action("right_haptic").first, }, }; - if (auto & hand = application::get_left_hand()) + + if (system.hand_tracking_supported()) { - imgui_inputs.push_back( - { - .hand = &hand, - }); - } - if (auto & hand = application::get_right_hand()) - { - imgui_inputs.push_back( - { - .hand = &hand, - }); + left_hand = session.create_hand_tracker(XR_HAND_LEFT_EXT); + right_hand = session.create_hand_tracker(XR_HAND_RIGHT_EXT); + hand_model::add_hand(*this, XR_HAND_LEFT_EXT, "left-hand.glb", layer_controllers); + hand_model::add_hand(*this, XR_HAND_RIGHT_EXT, "right-hand.glb", layer_controllers); + imgui_inputs.push_back({.hand = &*left_hand}); + imgui_inputs.push_back({.hand = &*right_hand}); } + face_tracker = xr::make_face_tracker(instance, system, session); + // 0.4mm / pixel std::vector vps{ { @@ -942,6 +969,9 @@ void scenes::lobby::on_unfocused() world.clear(); // Must be cleared before the renderer so that the descriptor sets are freed before their pools input.reset(); + left_hand.reset(); + right_hand.reset(); + face_tracker.emplace(); loader.reset(); renderer.reset(); diff --git a/client/scenes/lobby.h b/client/scenes/lobby.h index 1ef69eae..d527ec9c 100644 --- a/client/scenes/lobby.h +++ b/client/scenes/lobby.h @@ -29,7 +29,9 @@ #include "wivrn_config.h" #include "wivrn_discover.h" #include "wivrn_packets.h" +#include "xr/face_tracker.h" #include +#include #include #include @@ -65,6 +67,11 @@ class lobby : public scene_impl std::optional imgui_ctx; + std::optional left_hand; + std::optional right_hand; + + xr::face_tracker face_tracker; + std::string selected_item; std::unique_ptr license; @@ -94,8 +101,10 @@ class lobby : public scene_impl XrAction recenter_left_action = XR_NULL_HANDLE; XrAction recenter_right_action = XR_NULL_HANDLE; - std::optional gui_recenter_position; - std::optional gui_recenter_distance; + // std::optional gui_recenter_position; + // std::optional gui_recenter_distance; + // Which controller is used for recentering, position of the pointed point in the GUI, in GUI axes, and distance between the controller and the pointed point during recentering + std::optional> recentering_context; bool recenter_gui = true; void move_gui(glm::vec3 head_position, glm::vec3 new_gui_position); @@ -120,6 +129,7 @@ class lobby : public scene_impl ImTextureID about_picture; ImTextureID default_icon; std::unordered_map app_icons; + std::optional timestamp_start_application; virtual_keyboard keyboard; @@ -136,7 +146,7 @@ class lobby : public scene_impl void draw_features_status(XrTime predicted_display_time); void gui_connecting(locked_notifiable & request); void gui_enter_pin(locked_notifiable & request); - void gui_connected(); + void gui_connected(XrTime predicted_display_time); void gui_server_list(); void gui_new_server(); void gui_settings(); @@ -152,7 +162,7 @@ class lobby : public scene_impl void connect(const configuration::server_data & data); std::unique_ptr connect_to_session(wivrn_discover::service service, bool manual_connection); - std::optional check_recenter_gesture(const std::array & joints); + std::optional check_recenter_gesture(xr::spaces space, const std::optional> & joints); std::optional check_recenter_action(XrTime predicted_display_time, glm::vec3 head_position); std::optional check_recenter_gui(glm::vec3 head_position, glm::quat head_orientation); diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index b6137db1..f25126be 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -34,11 +34,13 @@ #include "utils/overloaded.h" #include "utils/ranges.h" #include "version.h" +#include "xr/body_tracker.h" #include #include #include #include #include +#include #include #include #include @@ -245,6 +247,7 @@ void scenes::lobby::gui_connecting(locked_notifiable & pin_req if (next_scene) { current_tab = tab::connected; + timestamp_start_application.reset(); ImGui::CloseCurrentPopup(); return; } @@ -375,7 +378,7 @@ void scenes::lobby::gui_enter_pin(locked_notifiable & pin_requ imgui_ctx->vibrate_on_hover(); } -void scenes::lobby::gui_connected() +void scenes::lobby::gui_connected(XrTime predicted_display_time) { if (not next_scene) { @@ -400,14 +403,17 @@ void scenes::lobby::gui_connected() auto apps = next_scene->get_applications(); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {20, 20}); - if (apps->applications.empty()) + if (apps->empty()) { CenterTextHV(_("Start an application on the server to start streaming.")); } else { + bool app_starting = timestamp_start_application and (predicted_display_time - *timestamp_start_application < 10'000'000'000); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {20, 0}); - ImGui::BeginChild("Main", ImGui::GetWindowSize() - ImGui::GetCursorPos() - ImVec2(0, disconnect_size.y + 80), 0); + ImGui::BeginDisabled(app_starting); + ImGui::BeginChild("Main", ImGui::GetWindowSize() - ImGui::GetCursorPos() - ImVec2(0, disconnect_size.y + 80), 0, app_starting ? ImGuiWindowFlags_NoScrollWithMouse : 0); ImGui::Indent(20); if (server_name.empty()) @@ -426,7 +432,7 @@ void scenes::lobby::gui_connected() ImGui::Indent((usable_window_width - icon_line_width) / 2); auto t0 = std::chrono::steady_clock::now(); - for (const auto [index, app]: utils::enumerate(apps->applications)) + for (const auto [index, app]: utils::enumerate(*apps)) { ImTextureID texture = [&]() -> ImTextureID { if (app.image.empty()) @@ -457,8 +463,11 @@ void scenes::lobby::gui_connected() }(); ImGui::PushStyleColor(ImGuiCol_Button, 0); - if (icon(app.name + "##" + app.id, texture, {256, 256}, 0, {icon_width, 0})) + if (icon(app.name + "##" + app.id, texture, {256, 256}, ImGuiButtonFlags_PressedOnClickRelease, {icon_width, 0})) + { + timestamp_start_application = predicted_display_time; next_scene->start_application(app.id); + } imgui_ctx->vibrate_on_hover(); ImGui::PopStyleColor(); // ImGuiCol_Button @@ -470,7 +479,7 @@ void scenes::lobby::gui_connected() std::vector> to_be_removed; for (const auto & [app_id, app_icon]: app_icons) { - if (not std::ranges::contains(apps->applications, app_id, &to_headset::application_list::application::id)) + if (not std::ranges::contains(*apps, app_id, &scenes::stream::app::id)) to_be_removed.emplace_back(app_id, app_icon); } for (const auto & [app_id, app_icon]: to_be_removed) @@ -481,12 +490,26 @@ void scenes::lobby::gui_connected() ScrollWhenDragging(); ImGui::EndChild(); + ImGui::EndDisabled(); + + if (app_starting) + { + ImGui::SetCursorPos(ImGui::GetWindowSize() / 2 - ImVec2{200, 200} - ImGui::GetStyle().FramePadding); + ImSpinner::SpinnerAng("App starting spinner", + 200, // Radius + 40, // Thickness + ImColor{1.f, 1.f, 1.f, 1.f}, // Colour + ImColor{1.f, 1.f, 1.f, 0.f}, // Background + 6, // Velocity + 0.75f * 2 * M_PI // Angle + ); + } + ImGui::PopStyleVar(); // ImGuiStyleVar_WindowPadding } ImGui::PopStyleVar(); - ImGui::SetCursorPosX(ImGui::GetWindowSize().x - disconnect_size.x - 50); - ImGui::SetCursorPosY(ImGui::GetWindowSize().y - disconnect_size.y - 50); + ImGui::SetCursorPos(ImGui::GetWindowSize() - disconnect_size - ImVec2{50, 50}); ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.2f, 0.2f, 0.40f)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.8f, 0.2f, 0.2f, 1.00f)); @@ -867,7 +890,7 @@ void scenes::lobby::gui_settings() ImGui::EndDisabled(); } { - ImGui::BeginDisabled(not application::get_hand_tracking_supported()); + ImGui::BeginDisabled(not system.hand_tracking_supported()); bool enabled = config.check_feature(feature::hand_tracking); if (ImGui::Checkbox(_S("Enable hand tracking"), &enabled)) { @@ -891,7 +914,7 @@ void scenes::lobby::gui_settings() ImGui::EndDisabled(); } { - ImGui::BeginDisabled(not application::get_face_tracking_supported()); + ImGui::BeginDisabled(std::holds_alternative(face_tracker)); bool enabled = config.check_feature(feature::face_tracking); if (ImGui::Checkbox(_S("Enable face tracking"), &enabled)) { @@ -903,8 +926,9 @@ void scenes::lobby::gui_settings() imgui_ctx->vibrate_on_hover(); } + auto body_tracker = system.body_tracker_supported(); { - ImGui::BeginDisabled(not application::get_body_tracking_supported()); + ImGui::BeginDisabled(body_tracker == xr::body_tracker_type::none); bool enabled = config.check_feature(feature::body_tracking); if (ImGui::Checkbox(_S("Enable body tracking"), &enabled)) { @@ -919,19 +943,14 @@ void scenes::lobby::gui_settings() } else { - std::visit(utils::overloaded{ - [](auto &) {}, - [this](xr::fb_body_tracker &) { - imgui_ctx->tooltip(_("Requires 'Hand and body tracking' to be enabled in the Quest movement tracking settings,\notherwise body data will be guessed from controller and headset positions")); - }, - }, - application::get_body_tracker()); + if (body_tracker == xr::body_tracker_type::fb) + imgui_ctx->tooltip(_("Requires 'Hand and body tracking' to be enabled in the Quest movement tracking settings,\notherwise body data will be guessed from controller and headset positions")); } } imgui_ctx->vibrate_on_hover(); } - if (std::holds_alternative(application::get_body_tracker())) + if (body_tracker == xr::body_tracker_type::fb) { ImGui::BeginDisabled(not config.check_feature(feature::body_tracking)); ImGui::Indent(); @@ -957,7 +976,7 @@ void scenes::lobby::gui_settings() ImGui::EndDisabled(); } - ImGui::BeginDisabled(passthrough_supported == xr::system::passthrough_type::no_passthrough); + ImGui::BeginDisabled(system.passthrough_supported() == xr::passthrough_type::none); if (ImGui::Checkbox(_S("Enable video passthrough in lobby"), &config.passthrough_enabled)) { setup_passthrough(); @@ -968,6 +987,13 @@ void scenes::lobby::gui_settings() imgui_ctx->tooltip(_("This feature is not supported by your headset")); ImGui::EndDisabled(); + { + ImGui::Checkbox(_S("Enable in-stream window"), &config.enable_stream_gui); + imgui_ctx->vibrate_on_hover(); + if (ImGui::IsItemHovered()) + imgui_ctx->tooltip(_("Enables the configuration window to be shown while the game is streaming.\nIf enabled, the window is activated by pressing both thumbsticks.")); + } + ImGui::PopStyleVar(); // ImGuiStyleVar_ItemSpacing } @@ -1282,12 +1308,12 @@ void scenes::lobby::gui_first_run() item{ .f = feature::face_tracking, .text = _S("Enable face tracking?"), - .supported = application::get_face_tracking_supported(), + .supported = not std::holds_alternative(face_tracker), }, item{ .f = feature::body_tracking, .text = _S("Enable body tracking?"), - .supported = application::get_body_tracking_supported(), + .supported = system.body_tracker_supported() != xr::body_tracker_type::none, }, }; @@ -1617,11 +1643,22 @@ static auto face_weights() return res; } -static const char * get_face_icon(XrTime predicted_display_time) +static const char * get_face_icon(XrTime predicted_display_time, xr::face_tracker & face_tracker) { static const auto w = face_weights(); wivrn::from_headset::tracking::fb_face2 expression; - std::get(application::get_face_tracker()).get_weights(predicted_display_time, expression); + const char * result = nullptr; + std::visit(utils::overloaded{ + [](std::monostate &) {}, + [&](xr::htc_face_tracker &) { result = ICON_FA_FACE_SMILE_WINK; }, + [&](auto & ft) { + ft.get_weights(predicted_display_time, expression); + }, + }, + face_tracker); + + if (result) + return result; if (not expression.is_valid) return ICON_FA_FACE_MEH; @@ -1664,7 +1701,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time) .icon_disabled = ICON_FA_MICROPHONE_SLASH, }); - if (application::get_hand_tracking_supported()) + if (system.hand_tracking_supported()) { items.push_back({ .f = feature::hand_tracking, @@ -1685,21 +1722,18 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time) }); } - if (application::get_face_tracking_supported()) + if (not std::holds_alternative(face_tracker)) { - const char * icon_enabled = std::holds_alternative(application::get_face_tracker()) - ? get_face_icon(predicted_display_time) - : ICON_FA_FACE_KISS_WINK_HEART; items.push_back({ .f = feature::face_tracking, .tooltip_enabled = _("Face tracking is enabled"), .tooltip_disabled = _("Face tracking is disabled"), - .icon_enabled = icon_enabled, + .icon_enabled = get_face_icon(predicted_display_time, face_tracker), .icon_disabled = ICON_FA_FACE_MEH_BLANK, }); } - if (application::get_body_tracking_supported()) + if (system.body_tracker_supported() != xr::body_tracker_type::none) { items.push_back({ .f = feature::body_tracking, @@ -1773,7 +1807,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time) if (*status.charge > 0.995) icon_nr = 5; else - icon_nr = application::now() / 500'000'000 % 5; + icon_nr = instance.now() / 500'000'000 % 5; } else icon_nr = std::round((*status.charge) * 4); @@ -1890,7 +1924,7 @@ std::vector> scenes::lobby::draw_gui(XrTi ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 10); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {10, 10}); ImGui::Begin("WiVRn", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove); - gui_connected(); + gui_connected(predicted_display_time); ImGui::End(); ImGui::PopStyleVar(3); // ImGuiStyleVar_WindowPadding, ImGuiStyleVar_FrameRounding, ImGuiStyleVar_FramePadding } @@ -2002,7 +2036,7 @@ std::vector> scenes::lobby::draw_gui(XrTi if (not is_gui_visible(*imgui_ctx, predicted_display_time)) { - if (application::get_hand_tracking_supported()) + if (system.hand_tracking_supported()) display_recentering_tip(*imgui_ctx, _("Press the grip button or put your palm up\nto move the main window")); else display_recentering_tip(*imgui_ctx, _("Press the grip button to move the main window")); diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index dc20f14e..63ab4a21 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -17,11 +17,9 @@ * along with this program. If not, see . */ #include "constants.h" -#include "utils/overloaded.h" -#include "xr/fb_body_tracker.h" +#include "xr/body_tracker.h" +#include "xr/face_tracker.h" #include "xr/fb_face_tracker2.h" -#include "xr/htc_body_tracker.h" -#include "xr/pico_body_tracker.h" #include "xr/space.h" #include #include @@ -42,6 +40,7 @@ #include "utils/ranges.h" #include "vk/pipeline.h" #include "vk/shader.h" +#include "vk/specialization_constants.h" #include "wivrn_packets.h" #include #include @@ -189,7 +188,11 @@ std::shared_ptr scenes::stream::create(std::unique_ptrnetwork_session = std::move(network_session); self->network_session->send_control([&]() { - from_headset::headset_info_packet info{}; + from_headset::headset_info_packet info{ + .language = application::get_messages_info().language, + .country = application::get_messages_info().country, + .variant = application::get_messages_info().variant, + }; auto view = self->system.view_configuration_views(self->viewconfig)[0]; view = override_view(view, guess_model()); @@ -251,39 +254,42 @@ std::shared_ptr scenes::stream::create(std::unique_ptrsystem.face_tracker_supported()) + { + case xr::face_tracker_type::none: + info.face_tracking = from_headset::face_type::none; + break; + case xr::face_tracker_type::fb: + case xr::face_tracker_type::pico: + info.face_tracking = from_headset::face_type::fb2; + break; + case xr::face_tracker_type::htc: + info.face_tracking = from_headset::face_type::htc; + break; + } } info.num_generic_trackers = 0; if (config.check_feature(feature::body_tracking)) { - info.num_generic_trackers = std::visit(utils::overloaded{ - [&](std::monostate &) { - return size_t(0); - }, - [&](auto & b) { - return b.count(); - }, - }, - application::get_body_tracker()); + switch (self->system.body_tracker_supported()) + { + case xr::body_tracker_type::none: + break; + case xr::body_tracker_type::fb: + info.num_generic_trackers = xr::fb_body_tracker::get_whitelisted_joints(config.fb_lower_body, config.fb_hip).size(); + break; + case xr::body_tracker_type::htc: + info.num_generic_trackers = application::get_generic_trackers().size(); + break; + case xr::body_tracker_type::pico: + info.num_generic_trackers = xr::pico_body_tracker::joint_whitelist.size(); + break; + } } info.palm_pose = application::space(xr::spaces::palm_left) or application::space(xr::spaces::palm_right); - info.passthrough = self->system.passthrough_supported() != xr::system::passthrough_type::no_passthrough; + info.passthrough = self->system.passthrough_supported() != xr::passthrough_type::none; info.system_name = std::string(self->system.properties().systemName); audio::get_audio_description(info); @@ -311,15 +317,6 @@ std::shared_ptr scenes::stream::create(std::unique_ptrnetwork_session->send_control(from_headset::get_application_list{ - .language = info.language, - .country = info.country, - .variant = info.variant, - }); - } - { const auto & config = application::get_config(); self->override_foveation_enable = config.override_foveation_enable; @@ -363,7 +360,7 @@ std::shared_ptr scenes::stream::create(std::unique_ptrhaptics_actions.emplace(id, haptics_action{ .action = action.first, - .path = application::string_to_path(path), + .path = self->instance.string_to_path(path), }); } } @@ -394,7 +391,7 @@ std::shared_ptr scenes::stream::create(std::unique_ptrget_default_material()); + loader.emplace(device, physical_device, queue, queue_family_index, renderer->get_default_material()); std::string profile = controller_name(); input.emplace( @@ -470,8 +467,11 @@ void scenes::stream::on_focused() swapchain_imgui, std::vector{vp}); - plots_toggle_1 = get_action("plots_toggle_1").first; - plots_toggle_2 = get_action("plots_toggle_2").first; + if (application::get_config().enable_stream_gui) + { + plots_toggle_1 = get_action("plots_toggle_1").first; + plots_toggle_2 = get_action("plots_toggle_2").first; + } recenter_left = get_action("recenter_left").first; recenter_right = get_action("recenter_right").first; foveation_pitch = get_action("foveation_pitch").first; @@ -494,6 +494,8 @@ void scenes::stream::on_unfocused() loader.reset(); renderer.reset(); clear_swapchains(); + left_hand.reset(); + right_hand.reset(); imgui_ctx.reset(); swapchain_imgui = xr::swapchain(); @@ -524,16 +526,16 @@ void scenes::stream::push_blit_handle(shard_accumulator * decoder, std::shared_p { if (decoder != decoders[stream].decoder.get()) return; - handle->feedback.received_from_decoder = application::now(); + handle->feedback.received_from_decoder = instance.now(); std::swap(handle, decoders[stream].latest_frames[handle->feedback.frame_index % decoders[stream].latest_frames.size()]); } if (state_ != state::streaming and std::ranges::all_of(decoders, [](accumulator_images & i) { - return i.alpha() or not i.frames().empty(); + return i.alpha() or not i.empty(); })) { state_ = state::streaming; - spdlog::info("Stream scene ready at t={}", application::now()); + spdlog::info("Stream scene ready at t={}", instance.now()); } } @@ -548,15 +550,14 @@ bool scenes::stream::accumulator_images::alpha() const return decoder->desc().channels == wivrn::to_headset::video_stream_description::channels_t::alpha; } -std::vector scenes::stream::accumulator_images::frames() const +bool scenes::stream::accumulator_images::empty() const { - std::vector result; for (const auto & frame: latest_frames) { if (frame) - result.push_back(frame->feedback.frame_index); + return false; } - return result; + return true; } std::vector> scenes::stream::common_frame(XrTime display_time) @@ -766,7 +767,15 @@ void scenes::stream::render(const XrFrameState & frame_state) } if (state_ == state::stalled) + { + network_session->send_control(from_headset::get_application_list{ + .language = application::get_messages_info().language, + .country = application::get_messages_info().country, + .variant = application::get_messages_info().variant, + }); + application::pop_scene(); + } assert(swapchain); for (auto & i: decoders) @@ -799,51 +808,19 @@ void scenes::stream::render(const XrFrameState & frame_state) const auto & description = i.decoder->desc(); vk::Extent2D image_size = i.decoder->image_size(); - std::array useful_size{ - float(description.width) / image_size.width, - float(description.height) / image_size.height, - }; spdlog::info("useful size: {}x{} with buffer {}x{}", description.width, description.height, image_size.width, image_size.height); - std::array specialization_constants_desc{ - vk::SpecializationMapEntry{ - .constantID = 0, - .offset = 0, - .size = sizeof(float), - }, - vk::SpecializationMapEntry{ - .constantID = 1, - .offset = sizeof(float), - .size = sizeof(float), - }}; + auto vert_constants = make_specialization_constants( + float(description.width) / image_size.width, + float(description.height) / image_size.height); - vk::SpecializationInfo vert_specialization_info; - vert_specialization_info.setMapEntries(specialization_constants_desc); - vert_specialization_info.setData(useful_size); - - std::array constants = { - need_srgb_conversion(guess_model()), - i.alpha(), - }; - std::array frag_specialization_constant_desc = { - vk::SpecializationMapEntry{ - .constantID = 0, - .offset = 0, - .size = sizeof(constants[0]), - }, - vk::SpecializationMapEntry{ - .constantID = 1, - .offset = sizeof(constants[0]), - .size = sizeof(constants[1]), - }, - }; - vk::SpecializationInfo frag_specialization_info; - frag_specialization_info.setMapEntries(frag_specialization_constant_desc); - frag_specialization_info.setData(constants); + auto frag_constants = make_specialization_constants( + VkBool32(need_srgb_conversion(guess_model())), + VkBool32(i.alpha())); // Create graphics pipeline vk::raii::ShaderModule vertex_shader = load_shader(device, "stream.vert"); @@ -861,13 +838,13 @@ void scenes::stream::render(const XrFrameState & frame_state) .stage = vk::ShaderStageFlagBits::eVertex, .module = *vertex_shader, .pName = "main", - .pSpecializationInfo = &vert_specialization_info, + .pSpecializationInfo = vert_constants, }, { .stage = vk::ShaderStageFlagBits::eFragment, .module = *fragment_shader, .pName = "main", - .pSpecializationInfo = &frag_specialization_info, + .pSpecializationInfo = frag_constants, }}, .VertexBindingDescriptions = {}, .VertexAttributeDescriptions = {}, @@ -953,7 +930,7 @@ void scenes::stream::render(const XrFrameState & frame_state) if (not blit_handle or not *i.blit_pipeline) continue; - blit_handle->feedback.blitted = application::now(); + blit_handle->feedback.blitted = instance.now(); if (blit_handle->feedback.blitted - blit_handle->feedback.received_from_decoder > 1'000'000'000) state_ = stream::state::stalled; ++blit_handle->feedback.times_displayed; @@ -1002,6 +979,10 @@ void scenes::stream::render(const XrFrameState & frame_state) uint16_t x_offset = 0; for (auto & out: decoder_output) { + vk::Extent2D decoder_out_size{ + .width = decoder_out_image.info().extent.width, + .height = decoder_out_image.info().extent.height, + }; command_buffer.beginRenderPass( { .renderPass = *blit_render_pass, @@ -1310,10 +1291,7 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript } // Create outputs for the decoders - decoder_out_size = vk::Extent2D{video_width, video_height}; { - decoder_out_format = vk::Format::eA8B8G8R8SrgbPack32; - vk::ImageCreateInfo image_info{ .flags = vk::ImageCreateFlags{}, .imageType = vk::ImageType::e2D, @@ -1337,7 +1315,7 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript vk::ImageViewCreateInfo image_view_info{ .image = vk::Image{decoder_out_image}, .viewType = vk::ImageViewType::e2D, - .format = vk::Format::eA8B8G8R8SrgbPack32, + .format = image_info.format, .components = {}, .subresourceRange = { .aspectMask = vk::ImageAspectFlagBits::eColor, @@ -1361,8 +1339,8 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript .renderPass = *blit_render_pass, .attachmentCount = 1, .pAttachments = &*output.image_view, - .width = decoder_out_size.width, - .height = decoder_out_size.height, + .width = image_info.extent.width, + .height = image_info.extent.height, .layers = 1, }); } @@ -1387,7 +1365,7 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript spdlog::info("Creating decoder size {}x{} offset {},{}", item.width, item.height, item.offset_x, item.offset_y); decoders.push_back(accumulator_images{ - .decoder = std::make_unique(device, physical_device, item, description.fps, shared_from_this(), stream_index), + .decoder = std::make_unique(device, physical_device, instance, item, description.fps, shared_from_this(), stream_index), }); } } @@ -1429,8 +1407,6 @@ void scenes::stream::setup_reprojection_swapchain(uint32_t swapchain_width, uint device, physical_device, decoder_out_image, - vk::Extent2D{.width = video_width, .height = video_height}, - 2, swapchain_images, extent, swapchain.format()); diff --git a/client/scenes/stream.h b/client/scenes/stream.h index 6f506ab7..146b6752 100644 --- a/client/scenes/stream.h +++ b/client/scenes/stream.h @@ -48,6 +48,13 @@ public: }; static const size_t image_buffer_size = 3; + struct app + { + std::string id; + std::string name; + std::vector image; + }; + private: static const size_t view_count = 2; @@ -60,12 +67,12 @@ private: vk::DescriptorSet descriptor_set = nullptr; vk::raii::PipelineLayout blit_pipeline_layout = nullptr; vk::raii::Pipeline blit_pipeline = nullptr; - // latest frames from oldest to most recent + // latest frames, rolling buffer std::array, image_buffer_size> latest_frames; std::shared_ptr frame(uint64_t id) const; bool alpha() const; - std::vector frames() const; + bool empty() const; }; wifi_lock::wifi wifi; @@ -77,9 +84,9 @@ private: std::unique_ptr network_session; std::atomic exiting = false; std::thread network_thread; - std::mutex tracking_control_mutex; - to_headset::tracking_control tracking_control{}; + thread_safe tracking_control{}; std::array, 2> interaction_profiles; // left and right hand + std::atomic interaction_profile_changed = false; std::atomic recenter_requested = false; std::atomic display_time_phase = 0; std::atomic display_time_period = 0; @@ -93,8 +100,6 @@ private: vk::raii::DescriptorPool blit_descriptor_pool = nullptr; vk::raii::RenderPass blit_render_pass = nullptr; - vk::Extent2D decoder_out_size; - vk::Format decoder_out_format; image_allocation decoder_out_image; struct renderpass_output @@ -125,6 +130,8 @@ private: std::optional