From ea45e9f91b895845913566ff55c243cdff5516e2 Mon Sep 17 00:00:00 2001 From: Vindicus999 <211831565+Vindicus999@users.noreply.github.com> Date: Sun, 24 Aug 2025 09:56:21 -0400 Subject: [PATCH] Revert "Merge branch 'master' of https://github.com/Vindicus999/WiVRn" This reverts commit 6212dccc2be7dddafb9454be17b3a8a7d222e3cd, reversing changes made to 80e31b642ac3fc6c313a4750687fadb6365b9c10. --- .github/ISSUE_TEMPLATE/bug_report.yml | 26 +- .github/workflows/APK-Release.yml | 7 - .github/workflows/Build.yml | 35 +- .github/workflows/Locales.yml | 12 +- CMakeLists.txt | 114 +- build.gradle | 1 - client/CMakeLists.txt | 29 +- client/application.cpp | 232 +- client/application.h | 95 +- client/configuration.cpp | 62 +- client/configuration.h | 2 - client/decoder/shard_accumulator.cpp | 16 +- client/decoder/shard_accumulator.h | 12 +- client/render/gpu_buffer.h | 5 +- client/render/imgui_impl.cpp | 15 +- client/render/scene_loader.cpp | 2 +- client/render/scene_renderer.cpp | 40 +- client/render/text_rasterizer.cpp | 68 +- client/scene.cpp | 4 +- client/scene.h | 1 + client/scenes/lobby.cpp | 234 +- client/scenes/lobby.h | 18 +- client/scenes/lobby_gui.cpp | 102 +- client/scenes/stream.cpp | 178 +- client/scenes/stream.h | 22 +- client/scenes/stream_gui.cpp | 38 +- client/scenes/stream_network.cpp | 20 +- client/scenes/stream_reprojection.cpp | 150 +- client/scenes/stream_reprojection.h | 14 +- client/scenes/stream_tracking.cpp | 144 +- client/shaders/reprojection.glsl | 51 +- client/shaders/reprojection_vsr.glsl | 5 - client/utils/contains.h | 14 +- client/utils/handle.h | 54 +- client/xr/body_tracker.cpp | 80 - client/xr/body_tracker.h | 43 - client/xr/error_category.cpp | 2 +- client/xr/face_tracker.cpp | 94 - client/xr/face_tracker.h | 40 - client/xr/fb_body_tracker.cpp | 59 +- client/xr/fb_body_tracker.h | 16 +- client/xr/fb_face_tracker2.cpp | 11 +- client/xr/fb_face_tracker2.h | 6 +- client/xr/hand_tracker.cpp | 13 +- client/xr/hand_tracker.h | 4 +- client/xr/htc_body_tracker.cpp | 85 +- client/xr/htc_body_tracker.h | 23 +- client/xr/htc_face_tracker.cpp | 52 +- client/xr/htc_face_tracker.h | 12 +- client/xr/instance.cpp | 17 +- client/xr/instance.h | 2 - client/xr/passthrough.cpp | 29 +- client/xr/passthrough.h | 10 +- client/xr/pico_body_tracker.cpp | 18 +- client/xr/pico_body_tracker.h | 6 +- client/xr/pico_face_tracker.cpp | 259 +- client/xr/pico_face_tracker.h | 15 +- client/xr/session.cpp | 17 +- client/xr/session.h | 4 +- client/xr/system.cpp | 35 +- client/xr/system.h | 38 +- .../reprojection.glsl.inc => xr/xr.h} | 45 +- cmake/AutoOption.cmake | 4 + cmake/GitVersion.cmake | 1 - common/CMakeLists.txt | 5 +- common/application.cpp | 74 +- common/application.h | 6 +- common/utils/load_icon.cpp | 398 +- common/utils/load_icon.h | 12 +- common/utils/steam_app_info.cpp | 3 - common/vk/allocation.h | 6 - common/vk/specialization_constants.h | 84 - common/vk/vk_allocator.cpp | 3 +- common/vk/vk_allocator.h | 3 +- common/wivrn_packets.h | 17 +- common/wivrn_sockets.cpp | 9 +- dashboard/apps.cpp | 2 +- dashboard/io.github.wivrn.wivrn.metainfo.xml | 14 - dashboard/qml/Main.qml | 17 +- dashboard/qml/WizardPage.qml | 1 - dashboard/wivrn_server.cpp | 20 +- docs/translating.md | 2 - external/CMakeLists.txt | 4 - external/imspinner/cimspinner.cpp | 1628 ------ external/imspinner/cimspinner.h | 415 -- external/imspinner/cimspinner_config.h | 11 - external/imspinner/imspinner.h | 4950 ----------------- flake.nix | 1 - flatpak/io.github.wivrn.wivrn.yml.in | 14 +- locale/es/wivrn.po | 6 +- locale/fr/wivrn.po | 224 +- locale/it/wivrn.po | 218 +- locale/pt_BR/wivrn-dashboard.po | 119 +- locale/pt_BR/wivrn.po | 436 +- locale/sk/wivrn-dashboard.po | 212 +- locale/sk/wivrn.po | 235 +- locale/tr/wivrn-dashboard.po | 943 ---- locale/tr/wivrn.po | 612 -- patches/apply.sh | 5 - ...001-c-multi-early-wake-of-compositor.patch | 8 +- ...02-ipc-server-Always-listen-to-stdin.patch | 4 +- .../monado/0003-Use-extern-socket-fd.patch | 4 +- ...Add-storage-usage-to-distortion-mesh.patch | 4 +- ...vironment-blend-mode-selection-logic.patch | 4 +- .../0006-Convert-to-YCbCr-in-Monado.patch | 10 +- .../0007-store-alpha-channel-in-layer-1.patch | 4 +- ...main-allow-custom-pacing-app-factory.patch | 4 +- .../0009-st-oxr-forward-0-refresh-rate.patch | 4 +- ...tortion-with-pixel-aligned-foveation.patch | 143 +- ...a-vk-Track-VK_KHR_video_maintenance1.patch | 64 - ...e-video_maintenance_1-device-feature.patch | 134 - ...-Request-video_maintenance_1-feature.patch | 26 - server/driver/wivrn_comp_target.cpp | 110 +- server/driver/wivrn_controller.cpp | 149 +- server/driver/wivrn_controller.h | 7 - server/driver/wivrn_foveation.cpp | 82 +- server/driver/wivrn_foveation.h | 7 +- server/driver/wivrn_generic_tracker.cpp | 8 +- server/driver/wivrn_generic_tracker.h | 8 +- server/driver/wivrn_hand_interaction.cpp | 109 +- server/driver/wivrn_session.cpp | 89 +- server/driver/wivrn_session.h | 12 +- server/encoder/video_encoder.cpp | 26 + server/encoder/video_encoder.h | 5 + server/encoder/video_encoder_vulkan.cpp | 22 +- server/encoder/video_encoder_vulkan.h | 3 +- server/encoder/video_encoder_vulkan_h264.cpp | 68 +- server/encoder/video_encoder_vulkan_h264.h | 3 +- server/encoder/video_encoder_x264.cpp | 8 +- server/main.cpp | 66 +- server/start_systemd_unit.cpp | 21 +- server/utils/wivrn_vk_bundle.cpp | 11 +- tools/check_messages.sh | 56 + tools/check_po.py | 153 +- tools/wireshark/CMakeLists.txt | 2 +- 135 files changed, 2784 insertions(+), 12225 deletions(-) delete mode 100644 client/shaders/reprojection_vsr.glsl delete mode 100644 client/xr/body_tracker.cpp delete mode 100644 client/xr/body_tracker.h delete mode 100644 client/xr/face_tracker.cpp delete mode 100644 client/xr/face_tracker.h rename client/{shaders/reprojection.glsl.inc => xr/xr.h} (57%) create mode 100644 cmake/AutoOption.cmake delete mode 100644 common/vk/specialization_constants.h delete mode 100644 external/imspinner/cimspinner.cpp delete mode 100644 external/imspinner/cimspinner.h delete mode 100644 external/imspinner/cimspinner_config.h delete mode 100644 external/imspinner/imspinner.h delete mode 100644 locale/tr/wivrn-dashboard.po delete mode 100644 locale/tr/wivrn.po delete mode 100644 patches/monado/0011-a-vk-Track-VK_KHR_video_maintenance1.patch delete mode 100644 patches/monado/0012-a-vk-Expose-video_maintenance_1-device-feature.patch delete mode 100644 patches/monado/0013-c-util-Request-video_maintenance_1-feature.patch create mode 100755 tools/check_messages.sh diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 098f36d2..b9417e68 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -36,33 +36,17 @@ 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. - 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"} - ] - } + description: Provide the content of `config.json` for the server. + placeholder: Add the content of config.json here... - type: textarea attributes: label: Server Logs description: Provide the `wivrn-server` output. - placeholder: | - Add the output of the wivrn-server here. - If more than a few lines, prefer file attachment. + placeholder: Add the output of the wivrn-server here... - type: dropdown id: gpu @@ -80,7 +64,7 @@ body: attributes: label: Vulkan Info description: Provide the output of `vulkaninfo --summary` command. - placeholder: Attach the output as a file here. + placeholder: Add the output of vulkaninfo command here... - type: dropdown id: hmd @@ -106,4 +90,4 @@ body: attributes: label: ADB Logs description: Provide the output of `adb logcat` command. - placeholder: Attach the output of adb logcat as a file. + placeholder: Add the output of adb logcat command here... diff --git a/.github/workflows/APK-Release.yml b/.github/workflows/APK-Release.yml index 8c5b374e..4eec207d 100644 --- a/.github/workflows/APK-Release.yml +++ b/.github/workflows/APK-Release.yml @@ -31,13 +31,6 @@ 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 a24f9a4e..cbc1e2af 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 libarchive-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 - name: Prepare Vulkan SDK uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 with: - vulkan-query-version: 1.3.296.0 - vulkan-components: Vulkan-Headers, Glslang, SPIRV-Tools + vulkan-query-version: 1.3.283.0 + vulkan-components: Vulkan-Headers vulkan-use-cache: true - name: Configure CMake @@ -87,8 +87,14 @@ 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 libarchive-dev libglm-dev glslang-tools + 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 # 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: > @@ -176,8 +182,8 @@ jobs: - name: Prepare Vulkan SDK uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 with: - vulkan-query-version: 1.3.296.0 - vulkan-components: Vulkan-Headers, Glslang, SPIRV-Tools + vulkan-query-version: 1.3.283.0 + vulkan-components: Vulkan-Headers vulkan-use-cache: true - name: Install dependencies @@ -186,14 +192,13 @@ 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 libarchive-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 - 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 @@ -288,8 +293,8 @@ jobs: - name: Prepare Vulkan SDK uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 with: - vulkan-query-version: 1.3.296.0 - vulkan-components: Vulkan-Headers, Glslang, SPIRV-Tools + vulkan-query-version: 1.3.268.0 + vulkan-components: Vulkan-Headers vulkan-use-cache: true - name: Install dependencies @@ -302,7 +307,6 @@ 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}} @@ -322,13 +326,6 @@ 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: @@ -470,7 +467,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 libarchive-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 - uses: actions/checkout@v4 with: diff --git a/.github/workflows/Locales.yml b/.github/workflows/Locales.yml index 722586f6..1cefef9b 100644 --- a/.github/workflows/Locales.yml +++ b/.github/workflows/Locales.yml @@ -9,14 +9,10 @@ jobs: - uses: actions/checkout@v4 - name: Install dependencies - run: | - sudo apt-get update && sudo apt-get install gettext - pip install polib PyGithub + run: sudo apt-get update && sudo apt-get install gettext qt6-base-dev qt6-tools-dev qt6-l10n-tools qtchooser python3-polib - name: Check that .po files are up to date run: | - 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 + qtchooser -install qt6 $(which qmake6) + export QT_SELECT=qt6 + tools/check_messages.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index b87c5bf0..e1f9b1aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,12 +17,13 @@ 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) -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}) +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_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) @@ -34,12 +35,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) -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_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_PIPEWIRE "Enable pipewire backend" ON) -option(WIVRN_USE_PULSEAUDIO "Enable pulseaudio backend" OFF) +auto_option(WIVRN_USE_PIPEWIRE "Enable pipewire backend" AUTO) +auto_option(WIVRN_USE_PULSEAUDIO "Enable pulseaudio backend" AUTO) 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 :") @@ -63,12 +64,6 @@ 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) @@ -80,13 +75,19 @@ endif() find_package(PkgConfig REQUIRED) find_package(Vulkan REQUIRED) find_package(Git) -if (NEED_COMMON AND NOT ANDROID) +if (NOT ANDROID) find_package(OpenSSL REQUIRED) endif() include(VulkanVersion) -if (WIVRN_USE_SYSTEM_BOOST AND NEED_COMMON) - if (WIVRN_BUILD_DISSECTOR) +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) find_package(Boost 1.84.0 REQUIRED COMPONENTS locale url) else() find_package(Boost 1.75.0 REQUIRED COMPONENTS locale url) @@ -103,30 +104,72 @@ 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) + 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) 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) + 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 (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) + 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) pkg_check_modules(X264 REQUIRED IMPORTED_TARGET x264) endif() - if (WIVRN_USE_SYSTEMD) + 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) pkg_check_modules(SYSTEMD REQUIRED IMPORTED_TARGET libsystemd) endif() - if (WIVRN_USE_PIPEWIRE) + 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) pkg_check_modules(libpipewire REQUIRED IMPORTED_TARGET libpipewire-0.3) endif() - if (WIVRN_USE_PULSEAUDIO) + 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) pkg_check_modules(libpulse REQUIRED IMPORTED_TARGET libpulse) endif() @@ -142,8 +185,7 @@ endif() if (WIVRN_BUILD_DASHBOARD OR WIVRN_BUILD_SERVER) pkg_check_modules(librsvg-2.0 REQUIRED IMPORTED_TARGET librsvg-2.0) - find_package(LibArchive REQUIRED) - find_package(PNG REQUIRED) + find_package(PNG) endif() if (WIVRN_BUILD_DASHBOARD) @@ -172,11 +214,23 @@ 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) + if (WIVRN_USE_SYSTEM_OPENXR STREQUAL "AUTO") + find_package(OpenXR 1.1.48) + elseif(WIVRN_USE_SYSTEM_OPENXR STREQUAL "ON") find_package(OpenXR 1.1.48 REQUIRED) endif() @@ -190,7 +244,9 @@ if(ANDROID) endif() if (WIVRN_BUILD_DISSECTOR) - if (WIVRN_USE_SYSTEM_OPENXR) + if (WIVRN_USE_SYSTEM_OPENXR STREQUAL "AUTO") + find_package(OpenXR 1.1.48) + elseif(WIVRN_USE_SYSTEM_OPENXR STREQUAL "ON") find_package(OpenXR 1.1.48 REQUIRED) endif() find_package(Wireshark REQUIRED) @@ -248,7 +304,7 @@ FetchContent_Declare(monado ) add_subdirectory(external) -if (NEED_COMMON) +if (WIVRN_BUILD_CLIENT OR WIVRN_BUILD_SERVER OR WIVRN_BUILD_DASHBOARD OR WIVRN_BUILD_DISSECTOR) add_subdirectory(common) endif() diff --git a/build.gradle b/build.gradle index f9474a0d..16d5e697 100644 --- a/build.gradle +++ b/build.gradle @@ -83,7 +83,6 @@ 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 1c11a214..7c903461 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -13,7 +13,7 @@ if (WIVRN_USE_LIBKTX) FetchContent_MakeAvailable(libktx) endif() -if (NOT WIVRN_USE_SYSTEM_BOOST) +if (NOT BOOST_FOUND) FetchContent_MakeAvailable(boost) endif() @@ -51,7 +51,7 @@ if(ANDROID) else() add_executable(wivrn) - if (WIVRN_USE_SYSTEM_OPENXR) + if (OpenXR_FOUND) target_link_libraries(wivrn OpenXR::openxr_loader OpenXR::headers) else() FetchContent_MakeAvailable(openxr_loader) @@ -91,22 +91,7 @@ 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 - Boost::locale - Boost::url - EnTT::EnTT - fastgltf - FreetypeHarfbuzz - glm::glm - imspinner - simdjson - spdlog::spdlog - stb - uni-algo - Vulkan::Vulkan - wivrn-common - wivrn-external -) +target_link_libraries(wivrn Vulkan::Vulkan spdlog::spdlog glm::glm fastgltf FreetypeHarfbuzz stb Boost::url Boost::locale) if (WIVRN_USE_LIBKTX) target_link_libraries(wivrn ktx_read) @@ -122,6 +107,10 @@ if(NOT ANDROID) install(TARGETS wivrn) endif() +target_link_libraries(wivrn simdjson uni-algo wivrn-common wivrn-external) + + + ############################################################################## # Dear ImGui # @@ -151,6 +140,10 @@ 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 2e612453..b0433274 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -28,20 +28,16 @@ #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/to_string.h" +#include "xr/xr.h" #include #include #include #include #include #include -#include #include #include #include @@ -138,7 +134,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/facebook/touch_controller_pro", - .required_extensions = {XR_FB_TOUCH_CONTROLLER_PRO_EXTENSION_NAME}, + .required_extensions = {"XR_FB_touch_controller_pro"}, .max_version = XR_MAKE_VERSION(1, 1, 0), .input_sources = { "/user/hand/left/output/haptic", @@ -251,7 +247,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/meta/touch_controller_plus", - .required_extensions = {XR_META_TOUCH_CONTROLLER_PLUS_EXTENSION_NAME}, + .required_extensions = {"XR_META_touch_controller_plus"}, .max_version = XR_MAKE_VERSION(1, 1, 0), .input_sources = { "/user/hand/left/output/haptic", @@ -352,7 +348,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/bytedance/pico_neo3_controller", - .required_extensions = {XR_BD_CONTROLLER_INTERACTION_EXTENSION_NAME}, + .required_extensions = {"XR_BD_controller_interaction"}, .input_sources = { "/user/hand/left/output/haptic", "/user/hand/right/output/haptic", @@ -395,7 +391,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/bytedance/pico4_controller", - .required_extensions = {XR_BD_CONTROLLER_INTERACTION_EXTENSION_NAME}, + .required_extensions = {"XR_BD_controller_interaction"}, .input_sources = { "/user/hand/left/output/haptic", "/user/hand/right/output/haptic", @@ -438,7 +434,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/bytedance/pico4s_controller", - .required_extensions = {XR_BD_CONTROLLER_INTERACTION_EXTENSION_NAME}, + .required_extensions = {"XR_BD_controller_interaction"}, .input_sources = { "/user/hand/left/output/haptic", "/user/hand/right/output/haptic", @@ -481,7 +477,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/htc/vive_focus3_controller", - .required_extensions = {XR_HTC_VIVE_FOCUS3_CONTROLLER_INTERACTION_EXTENSION_NAME}, + .required_extensions = {"XR_HTC_vive_focus3_controller_interaction"}, .input_sources = { "/user/hand/left/output/haptic", "/user/hand/right/output/haptic", @@ -523,7 +519,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/ext/hand_interaction_ext", - .required_extensions = {XR_EXT_HAND_INTERACTION_EXTENSION_NAME}, + .required_extensions = {"XR_EXT_hand_interaction"}, .input_sources = { "/user/hand/left/input/aim/pose", "/user/hand/left/input/grip/pose", @@ -552,14 +548,11 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/htc/vive_xr_tracker", - .required_extensions = { - XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME, - XR_HTC_PATH_ENUMERATION_EXTENSION_NAME, - }, + .required_extensions = {"XR_HTC_vive_xr_tracker_interaction", "XR_HTC_path_enumeration"}, }, interaction_profile{ .profile_name = "/interaction_profiles/ext/eye_gaze_interaction", - .required_extensions = {XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME}, + .required_extensions = {"XR_EXT_eye_gaze_interaction"}, .input_sources = { "/user/eyes_ext/input/gaze_ext/pose", }, @@ -724,13 +717,15 @@ 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)) @@ -739,27 +734,28 @@ 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) and - guess_model() != model::oculus_quest) // Quest 1 lies, the extension won't load - { + if (!strcmp(i.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME)) 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); @@ -878,7 +874,6 @@ void application::initialize_vulkan() .ppEnabledExtensionNames = vk_device_extensions.data(), .pEnabledFeatures = &device_features, }, - vk::PhysicalDeviceFragmentShadingRateFeaturesKHR{}, #ifdef __ANDROID__ vk::PhysicalDeviceSamplerYcbcrConversionFeaturesKHR{ .samplerYcbcrConversion = VK_TRUE, @@ -886,22 +881,6 @@ 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); @@ -923,16 +902,10 @@ 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, - }, -#ifndef NDEBUG - debug_utils_found -#else - false -#endif - ); + .physicalDevice = *vk_physical_device, + .device = *vk_device, + .instance = *vk_instance, + }); } void application::log_views() @@ -979,6 +952,8 @@ 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"); @@ -992,9 +967,7 @@ void application::initialize_actions() std::vector sources; for (auto & profile: interaction_profiles) { - 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; + profile.available = utils::contains_all(xr_extensions, profile.required_extensions) and profile.min_version <= api_version and profile.max_version > api_version; if (profile.profile_name.ends_with("khr/simple_controller")) { @@ -1035,15 +1008,15 @@ void application::initialize_actions() } if (add_palms) { - 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") // + 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") // 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 (xr_instance.has_extension(XR_EXT_PALM_POSE_EXTENSION_NAME) // + else if (utils::contains(xr_extensions, 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")) { @@ -1054,15 +1027,14 @@ void application::initialize_actions() } // Dynamically add VIVE XR Trackers to the profile if available - 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)) + if (htc_body && utils::contains(profile.required_extensions, XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME)) { - 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 & user_path: htc_body->get_paths()) { - 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)); + 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)); + } } } @@ -1110,14 +1082,8 @@ 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")) - { - for (auto & [path, action]: generic_trackers) - { - if (name.starts_with(xr_instance.path_to_string(path))) - action = 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)); } // Build an action set for each scene @@ -1154,7 +1120,7 @@ void application::initialize_actions() xr_bindings.push_back(XrActionSuggestedBinding{ .action = a, - .binding = xr_instance.string_to_path(k.input_source)}); + .binding = string_to_path(k.input_source)}); } } } @@ -1171,7 +1137,7 @@ void application::initialize_actions() for (const auto & name: profile.input_sources) { - xr_bindings.push_back({actions_by_name[name], xr_instance.string_to_path(name)}); + xr_bindings.push_back({actions_by_name[name], string_to_path(name)}); } try @@ -1191,7 +1157,7 @@ void application::initialize() { // LogLayersAndExtensions assert(!xr_instance); - std::vector xr_extensions; + xr_extensions.clear(); // Required extensions xr_extensions.push_back(XR_KHR_CONVERT_TIMESPEC_TIME_EXTENSION_NAME); @@ -1264,16 +1230,21 @@ void application::initialize() spdlog::info(" Orientation tracking: {}", (bool)properties.trackingProperties.orientationTracking); spdlog::info(" Position tracking: {}", (bool)properties.trackingProperties.positionTracking); - spdlog::info(" Hand tracking support: {}", xr_system_id.hand_tracking_supported()); + 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; + } - if (xr_instance.has_extension(XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME)) + if (utils::contains(xr_extensions, 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 (xr_instance.has_extension(XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME)) + if (utils::contains(xr_extensions, XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME)) { spdlog::info(" OpenXR post-processing extension support: true"); openxr_post_processing_supported = true; @@ -1281,39 +1252,23 @@ void application::initialize() switch (xr_system_id.passthrough_supported()) { - case xr::passthrough_type::none: + case xr::system::passthrough_type::no_passthrough: spdlog::info(" Passthrough: not supported"); break; - case xr::passthrough_type::bw: + case xr::system::passthrough_type::bw: spdlog::info(" Passthrough: black and white"); break; - case xr::passthrough_type::color: + case xr::system::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, 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); - - // 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) - { - auto props = xr_system_id.htc_face_tracking_properties(); - xr::htc_face_tracker(xr_instance, xr_session, props.supportEyeFacialTracking, props.supportLipFacialTracking); - } + 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(); @@ -1322,6 +1277,70 @@ void application::initialize() spdlog::info(" {}", xr::to_string(i)); } + 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) + { + left_hand = xr_session.create_hand_tracker(XR_HAND_LEFT_EXT); + right_hand = xr_session.create_hand_tracker(XR_HAND_RIGHT_EXT); + } + + 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); + } + vk::CommandPoolCreateInfo cmdpool_create_info; cmdpool_create_info.queueFamilyIndex = vk_queue_family_index; cmdpool_create_info.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer; @@ -1856,6 +1875,13 @@ 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 368983fa..cb17f87e 100644 --- a/client/application.h +++ b/client/application.h @@ -28,11 +28,14 @@ #include "utils/thread_safe.h" #include "vk/vk_allocator.h" #include "wifi_lock.h" -#include "xr/actionset.h" -#include "xr/instance.h" -#include "xr/session.h" -#include "xr/swapchain.h" -#include "xr/system.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 #include #include @@ -123,7 +126,12 @@ class application : public singleton xr::actionset xr_actionset; std::vector> actions; - std::vector> generic_trackers; + bool hand_tracking_supported = false; + xr::hand_tracker left_hand; + xr::hand_tracker right_hand; + + std::variant face_tracker; + std::variant body_tracker; bool eye_gaze_supported = false; @@ -133,6 +141,7 @@ 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; @@ -262,6 +271,16 @@ 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); @@ -332,6 +351,16 @@ 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; @@ -347,21 +376,26 @@ 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; @@ -382,6 +416,21 @@ 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; @@ -392,9 +441,29 @@ public: return instance().openxr_post_processing_supported; } - static auto & get_generic_trackers() + static xr::hand_tracker & get_left_hand() { - return instance().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; } static const std::vector & get_vk_device_extensions() diff --git a/client/configuration.cpp b/client/configuration.cpp index a8b2bf09..abe7f15e 100644 --- a/client/configuration.cpp +++ b/client/configuration.cpp @@ -82,8 +82,6 @@ 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; @@ -96,7 +94,7 @@ bool configuration::check_feature(feature f) const case feature::microphone: break; case feature::hand_tracking: - if (not system.hand_tracking_supported()) + if (not application::get_hand_tracking_supported()) return false; break; case feature::eye_gaze: @@ -104,12 +102,50 @@ bool configuration::check_feature(feature f) const return false; break; case feature::face_tracking: - if (system.face_tracker_supported() == xr::face_tracker_type::none) - return false; + 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; + } break; case feature::body_tracking: - if (system.body_tracker_supported() == xr::body_tracker_type::none) - return false; + 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; + } break; } } @@ -145,8 +181,8 @@ void configuration::set_feature(feature f, bool state) configuration::configuration(xr::system & system) { - passthrough_enabled = system.passthrough_supported() == xr::passthrough_type::color; - features[feature::hand_tracking] = system.hand_tracking_supported(); + passthrough_enabled = system.passthrough_supported() == xr::system::passthrough_type::color; + features[feature::hand_tracking] = application::get_hand_tracking_supported(); try { simdjson::dom::parser parser; @@ -178,9 +214,6 @@ 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()); @@ -207,7 +240,7 @@ configuration::configuration(xr::system & system) features[i] = val.get_bool(); } - if (system.passthrough_supported() == xr::passthrough_type::none) + if (system.passthrough_supported() == xr::system::passthrough_type::no_passthrough) passthrough_enabled = false; if (auto val = root["override_foveation_enable"]; val.is_bool()) @@ -233,7 +266,7 @@ configuration::configuration(xr::system & system) resolution_scale = 1.4; sgsr = {}; openxr_post_processing = {}; - passthrough_enabled = system.passthrough_supported() == xr::passthrough_type::color; + passthrough_enabled = system.passthrough_supported() == xr::system::passthrough_type::color; } } @@ -332,7 +365,6 @@ 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 a0f6ecad..8d34faae 100644 --- a/client/configuration.h +++ b/client/configuration.h @@ -56,8 +56,6 @@ 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 900c05ee..6b6106ce 100644 --- a/client/decoder/shard_accumulator.cpp +++ b/client/decoder/shard_accumulator.cpp @@ -18,9 +18,9 @@ */ #include "shard_accumulator.h" -#include "scenes/stream.h" // IWYU pragma: keep +#include "application.h" +#include "scenes/stream.h" #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, xr::instance & instance) +std::optional shard_set::insert(data_shard && shard) { if (empty()) - feedback.received_first_packet = instance.now(); + feedback.received_first_packet = application::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), instance); + auto shard_idx = current.insert(std::move(shard)); try_submit_frame(shard_idx); } else if (frame_diff == 1) { - next.insert(std::move(shard), instance); + next.insert(std::move(shard)); 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 = instance.now(); + current.feedback.received_last_packet = application::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 = instance.now(); + feedback.received_first_packet = application::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 406c0c49..4777de7f 100644 --- a/client/decoder/shard_accumulator.h +++ b/client/decoder/shard_accumulator.h @@ -34,11 +34,6 @@ using decoder_impl = ::wivrn::ffmpeg::decoder; #include #include -namespace xr -{ -class instance; -} - namespace wivrn { @@ -55,7 +50,7 @@ public: void reset(uint64_t frame_index); bool empty() const; - std::optional insert(data_shard &&, xr::instance & instance); + std::optional insert(data_shard &&); wivrn::from_headset::feedback feedback{}; @@ -75,13 +70,11 @@ 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, @@ -89,8 +82,7 @@ public: decoder(std::make_shared(device, physical_device, description, fps, stream_index, scene, this)), current(stream_index), next(stream_index), - weak_scene(scene), - instance(instance) + weak_scene(scene) { next.reset(1); } diff --git a/client/render/gpu_buffer.h b/client/render/gpu_buffer.h index 892dc3fb..7f03c03e 100644 --- a/client/render/gpu_buffer.h +++ b/client/render/gpu_buffer.h @@ -18,6 +18,7 @@ #pragma once +#include "application.h" #include "utils/alignment.h" #include "vk/allocation.h" #include @@ -114,10 +115,10 @@ public: } } - buffer_allocation copy_to_gpu(vk::raii::Device & device) + buffer_allocation copy_to_gpu() { buffer_allocation gpu_buffer{ - device, + application::get_device(), vk::BufferCreateInfo{ .size = bytes.size(), .usage = usage}, diff --git a/client/render/imgui_impl.cpp b/client/render/imgui_impl.cpp index 75556eca..53d59862 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 = *physical_device, - .Device = *device, - .QueueFamily = queue_family_index, + .PhysicalDevice = *application::get_physical_device(), + .Device = *application::get_device(), + .QueueFamily = application::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::clamp((display_time - last_display_time) * 1e-9f, 0.001f, 0.0166f); + io.DeltaTime = std::min((display_time - last_display_time) * 1e-9f, 0.0166f); last_display_time = display_time; // Uses the window list from last frame @@ -1099,13 +1099,6 @@ 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 07ceddfe..66ba86a4 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(device)); + auto buffer = std::make_shared(staging_buffer.copy_to_gpu()); for (auto & i: materials) i->buffer = buffer; diff --git a/client/render/scene_renderer.cpp b/client/render/scene_renderer.cpp index da28ec8f..d944c559 100644 --- a/client/render/scene_renderer.cpp +++ b/client/render/scene_renderer.cpp @@ -28,7 +28,6 @@ #include "vk/allocation.h" #include "vk/pipeline.h" #include "vk/shader.h" -#include "vk/specialization_constants.h" #include #include #include @@ -536,11 +535,34 @@ 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"); - auto specialization = make_specialization_constants( - int32_t(info.nb_texcoords), - VkBool32(info.dithering), - VkBool32(info.alpha_cutout), - VkBool32(info.skinning)); + 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, + }; return vk::raii::Pipeline{ device, @@ -551,14 +573,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, }, }, @@ -775,7 +797,7 @@ void scene_renderer::update_material_descriptor_set(renderer::material & materia device.updateDescriptorSets(write_ds, {}); } -[[maybe_unused]] static void print_scene_hierarchy(const entt::registry & scene, entt::entity root = entt::null, int level = 0) +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 ac0f7a83..d206aa15 100644 --- a/client/render/text_rasterizer.cpp +++ b/client/render/text_rasterizer.cpp @@ -139,42 +139,46 @@ text_rasterizer::text_rasterizer(vk::raii::Device & device, vk::raii::PhysicalDe image_allocation text_rasterizer::create_image(vk::Extent2D size) { - 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"}; + 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; } buffer_allocation text_rasterizer::create_buffer(size_t size) { - 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"}; + 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; } text_rasterizer::~text_rasterizer() diff --git a/client/scene.cpp b/client/scene.cpp index 684922ee..feeb29fe 100644 --- a/client/scene.cpp +++ b/client/scene.cpp @@ -51,6 +51,8 @@ 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:"); @@ -441,7 +443,7 @@ std::pair scene::load_gltf(const std::filesyst node.layer_mask = layer_mask; assert(renderer); - scene_loader loader(device, physical_device, queue, queue_family_index, renderer->get_default_material()); + scene_loader loader(device, physical_device, queue, application::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 9593100c..e84bbcea 100644 --- a/client/scene.h +++ b/client/scene.h @@ -103,6 +103,7 @@ 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 27fa5a17..cd328c19 100644 --- a/client/scenes/lobby.cpp +++ b/client/scenes/lobby.cpp @@ -383,18 +383,9 @@ void scenes::lobby::connect(const configuration::server_data & data) data.manual); } -std::optional scenes::lobby::check_recenter_gesture(xr::spaces space, const std::optional> & joints) +std::optional scenes::lobby::check_recenter_gesture(const std::array & joints) { - 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 & 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}; @@ -402,130 +393,102 @@ std::optional scenes::lobby::check_recenter_gesture(xr::spaces space, 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) { - xr::spaces controller; - glm::vec3 recenter_position; - float recenter_distance; + std::optional> aim; + glm::vec3 offset_position; + glm::quat offset_orientation; - if (recentering_context) + if (application::read_action_bool(recenter_left_action).value_or(std::pair{0, false}).second) { - controller = std::get<0>(*recentering_context); - bool state; - switch (controller) - { - case xr::spaces::aim_left: - state = application::read_action_bool(recenter_left_action).value_or(std::pair{0, false}).second; - break; - - case xr::spaces::aim_right: - state = application::read_action_bool(recenter_right_action).value_or(std::pair{0, false}).second; - break; - - default: - return std::nullopt; - } - - 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; - - 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; + 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]; } - // 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) + if (application::read_action_bool(recenter_right_action).value_or(std::pair{0, false}).second) { - // First frame of recentering - imgui_context::controller_state state{ - .active = true, - .aim_position = aim->first, - .aim_orientation = aim->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]; + } - imgui_ctx->compute_pointer_position(state); + 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 (state.pointer_position) // TODO: check that the pointer is inside an imgui window + if (not gui_recenter_position or not gui_recenter_distance) { - auto M = glm::mat3_cast(imgui_ctx->layers()[0].orientation); + // First frame where the recenter action is active + imgui_context::controller_state state{ + .active = true, + .aim_position = aim->first, + .aim_orientation = aim->second, + }; - // Pointer position in world - glm::vec3 world_pointer_position = imgui_ctx->rw_from_vp(*state.pointer_position); + imgui_ctx->compute_pointer_position(state); - // 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); + 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 + 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; + } } else { - // 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; - } + // 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; - recentering_context.emplace(controller, recenter_position, recenter_distance); - return std::nullopt; + // 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; + } } else { - // Subsequent frames: find the GUI position that gives the correct world pointer position - std::tie(controller, recenter_position, recenter_distance) = *recentering_context; - - 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; + gui_recenter_position.reset(); } + + return std::nullopt; } std::optional scenes::lobby::check_recenter_gui(glm::vec3 head_position, glm::quat head_orientation) @@ -649,24 +612,26 @@ 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 (left_hand and right_hand) + if (application::get_hand_tracking_supported()) { - auto left = left_hand->locate(world_space, frame_state.predictedDisplayTime); - auto right = right_hand->locate(world_space, frame_state.predictedDisplayTime); + auto left = application::get_left_hand().locate(world_space, frame_state.predictedDisplayTime); + auto right = application::get_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 (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 (!new_gui_position) + new_gui_position = check_recenter_gesture(*right); + } } if (head_position && new_gui_position) @@ -798,7 +763,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, queue_family_index, renderer->get_default_material()); + loader.emplace(device, physical_device, queue, application::queue_family_index(), renderer->get_default_material()); lobby_entity = load_gltf("ground.gltf", layer_lobby).first; @@ -835,6 +800,12 @@ 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; @@ -856,18 +827,20 @@ void scenes::lobby::on_focused() .haptic_output = get_action("right_haptic").first, }, }; - - if (system.hand_tracking_supported()) + if (auto & hand = application::get_left_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}); + imgui_inputs.push_back( + { + .hand = &hand, + }); + } + if (auto & hand = application::get_right_hand()) + { + imgui_inputs.push_back( + { + .hand = &hand, + }); } - - face_tracker = xr::make_face_tracker(instance, system, session); // 0.4mm / pixel std::vector vps{ @@ -969,9 +942,6 @@ 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 d527ec9c..1ef69eae 100644 --- a/client/scenes/lobby.h +++ b/client/scenes/lobby.h @@ -29,9 +29,7 @@ #include "wivrn_config.h" #include "wivrn_discover.h" #include "wivrn_packets.h" -#include "xr/face_tracker.h" #include -#include #include #include @@ -67,11 +65,6 @@ 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; @@ -101,10 +94,8 @@ 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; - // 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; + std::optional gui_recenter_position; + std::optional gui_recenter_distance; bool recenter_gui = true; void move_gui(glm::vec3 head_position, glm::vec3 new_gui_position); @@ -129,7 +120,6 @@ class lobby : public scene_impl ImTextureID about_picture; ImTextureID default_icon; std::unordered_map app_icons; - std::optional timestamp_start_application; virtual_keyboard keyboard; @@ -146,7 +136,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(XrTime predicted_display_time); + void gui_connected(); void gui_server_list(); void gui_new_server(); void gui_settings(); @@ -162,7 +152,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(xr::spaces space, const std::optional> & joints); + std::optional check_recenter_gesture(const std::array & 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 f25126be..b6137db1 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -34,13 +34,11 @@ #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 @@ -247,7 +245,6 @@ void scenes::lobby::gui_connecting(locked_notifiable & pin_req if (next_scene) { current_tab = tab::connected; - timestamp_start_application.reset(); ImGui::CloseCurrentPopup(); return; } @@ -378,7 +375,7 @@ void scenes::lobby::gui_enter_pin(locked_notifiable & pin_requ imgui_ctx->vibrate_on_hover(); } -void scenes::lobby::gui_connected(XrTime predicted_display_time) +void scenes::lobby::gui_connected() { if (not next_scene) { @@ -403,17 +400,14 @@ void scenes::lobby::gui_connected(XrTime predicted_display_time) auto apps = next_scene->get_applications(); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {20, 20}); - if (apps->empty()) + if (apps->applications.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::BeginDisabled(app_starting); - ImGui::BeginChild("Main", ImGui::GetWindowSize() - ImGui::GetCursorPos() - ImVec2(0, disconnect_size.y + 80), 0, app_starting ? ImGuiWindowFlags_NoScrollWithMouse : 0); + ImGui::BeginChild("Main", ImGui::GetWindowSize() - ImGui::GetCursorPos() - ImVec2(0, disconnect_size.y + 80), 0); ImGui::Indent(20); if (server_name.empty()) @@ -432,7 +426,7 @@ void scenes::lobby::gui_connected(XrTime predicted_display_time) ImGui::Indent((usable_window_width - icon_line_width) / 2); auto t0 = std::chrono::steady_clock::now(); - for (const auto [index, app]: utils::enumerate(*apps)) + for (const auto [index, app]: utils::enumerate(apps->applications)) { ImTextureID texture = [&]() -> ImTextureID { if (app.image.empty()) @@ -463,11 +457,8 @@ void scenes::lobby::gui_connected(XrTime predicted_display_time) }(); ImGui::PushStyleColor(ImGuiCol_Button, 0); - if (icon(app.name + "##" + app.id, texture, {256, 256}, ImGuiButtonFlags_PressedOnClickRelease, {icon_width, 0})) - { - timestamp_start_application = predicted_display_time; + if (icon(app.name + "##" + app.id, texture, {256, 256}, 0, {icon_width, 0})) next_scene->start_application(app.id); - } imgui_ctx->vibrate_on_hover(); ImGui::PopStyleColor(); // ImGuiCol_Button @@ -479,7 +470,7 @@ void scenes::lobby::gui_connected(XrTime predicted_display_time) std::vector> to_be_removed; for (const auto & [app_id, app_icon]: app_icons) { - if (not std::ranges::contains(*apps, app_id, &scenes::stream::app::id)) + if (not std::ranges::contains(apps->applications, app_id, &to_headset::application_list::application::id)) to_be_removed.emplace_back(app_id, app_icon); } for (const auto & [app_id, app_icon]: to_be_removed) @@ -490,26 +481,12 @@ void scenes::lobby::gui_connected(XrTime predicted_display_time) 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::SetCursorPos(ImGui::GetWindowSize() - disconnect_size - ImVec2{50, 50}); + ImGui::SetCursorPosX(ImGui::GetWindowSize().x - disconnect_size.x - 50); + ImGui::SetCursorPosY(ImGui::GetWindowSize().y - disconnect_size.y - 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)); @@ -890,7 +867,7 @@ void scenes::lobby::gui_settings() ImGui::EndDisabled(); } { - ImGui::BeginDisabled(not system.hand_tracking_supported()); + ImGui::BeginDisabled(not application::get_hand_tracking_supported()); bool enabled = config.check_feature(feature::hand_tracking); if (ImGui::Checkbox(_S("Enable hand tracking"), &enabled)) { @@ -914,7 +891,7 @@ void scenes::lobby::gui_settings() ImGui::EndDisabled(); } { - ImGui::BeginDisabled(std::holds_alternative(face_tracker)); + ImGui::BeginDisabled(not application::get_face_tracking_supported()); bool enabled = config.check_feature(feature::face_tracking); if (ImGui::Checkbox(_S("Enable face tracking"), &enabled)) { @@ -926,9 +903,8 @@ void scenes::lobby::gui_settings() imgui_ctx->vibrate_on_hover(); } - auto body_tracker = system.body_tracker_supported(); { - ImGui::BeginDisabled(body_tracker == xr::body_tracker_type::none); + ImGui::BeginDisabled(not application::get_body_tracking_supported()); bool enabled = config.check_feature(feature::body_tracking); if (ImGui::Checkbox(_S("Enable body tracking"), &enabled)) { @@ -943,14 +919,19 @@ void scenes::lobby::gui_settings() } else { - 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")); + 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()); } } imgui_ctx->vibrate_on_hover(); } - if (body_tracker == xr::body_tracker_type::fb) + if (std::holds_alternative(application::get_body_tracker())) { ImGui::BeginDisabled(not config.check_feature(feature::body_tracking)); ImGui::Indent(); @@ -976,7 +957,7 @@ void scenes::lobby::gui_settings() ImGui::EndDisabled(); } - ImGui::BeginDisabled(system.passthrough_supported() == xr::passthrough_type::none); + ImGui::BeginDisabled(passthrough_supported == xr::system::passthrough_type::no_passthrough); if (ImGui::Checkbox(_S("Enable video passthrough in lobby"), &config.passthrough_enabled)) { setup_passthrough(); @@ -987,13 +968,6 @@ 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 } @@ -1308,12 +1282,12 @@ void scenes::lobby::gui_first_run() item{ .f = feature::face_tracking, .text = _S("Enable face tracking?"), - .supported = not std::holds_alternative(face_tracker), + .supported = application::get_face_tracking_supported(), }, item{ .f = feature::body_tracking, .text = _S("Enable body tracking?"), - .supported = system.body_tracker_supported() != xr::body_tracker_type::none, + .supported = application::get_body_tracking_supported(), }, }; @@ -1643,22 +1617,11 @@ static auto face_weights() return res; } -static const char * get_face_icon(XrTime predicted_display_time, xr::face_tracker & face_tracker) +static const char * get_face_icon(XrTime predicted_display_time) { static const auto w = face_weights(); wivrn::from_headset::tracking::fb_face2 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; + std::get(application::get_face_tracker()).get_weights(predicted_display_time, expression); if (not expression.is_valid) return ICON_FA_FACE_MEH; @@ -1701,7 +1664,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time) .icon_disabled = ICON_FA_MICROPHONE_SLASH, }); - if (system.hand_tracking_supported()) + if (application::get_hand_tracking_supported()) { items.push_back({ .f = feature::hand_tracking, @@ -1722,18 +1685,21 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time) }); } - if (not std::holds_alternative(face_tracker)) + if (application::get_face_tracking_supported()) { + 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 = get_face_icon(predicted_display_time, face_tracker), + .icon_enabled = icon_enabled, .icon_disabled = ICON_FA_FACE_MEH_BLANK, }); } - if (system.body_tracker_supported() != xr::body_tracker_type::none) + if (application::get_body_tracking_supported()) { items.push_back({ .f = feature::body_tracking, @@ -1807,7 +1773,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time) if (*status.charge > 0.995) icon_nr = 5; else - icon_nr = instance.now() / 500'000'000 % 5; + icon_nr = application::now() / 500'000'000 % 5; } else icon_nr = std::round((*status.charge) * 4); @@ -1924,7 +1890,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(predicted_display_time); + gui_connected(); ImGui::End(); ImGui::PopStyleVar(3); // ImGuiStyleVar_WindowPadding, ImGuiStyleVar_FrameRounding, ImGuiStyleVar_FramePadding } @@ -2036,7 +2002,7 @@ std::vector> scenes::lobby::draw_gui(XrTi if (not is_gui_visible(*imgui_ctx, predicted_display_time)) { - if (system.hand_tracking_supported()) + if (application::get_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 63ab4a21..dc20f14e 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -17,9 +17,11 @@ * along with this program. If not, see . */ #include "constants.h" -#include "xr/body_tracker.h" -#include "xr/face_tracker.h" +#include "utils/overloaded.h" +#include "xr/fb_body_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 @@ -40,7 +42,6 @@ #include "utils/ranges.h" #include "vk/pipeline.h" #include "vk/shader.h" -#include "vk/specialization_constants.h" #include "wivrn_packets.h" #include #include @@ -188,11 +189,7 @@ 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{ - .language = application::get_messages_info().language, - .country = application::get_messages_info().country, - .variant = application::get_messages_info().variant, - }; + from_headset::headset_info_packet info{}; auto view = self->system.view_configuration_views(self->viewconfig)[0]; view = override_view(view, guess_model()); @@ -254,42 +251,39 @@ 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.face_tracking = std::visit(utils::overloaded{ + [](std::monostate &) { + return from_headset::face_type::none; + }, + [](xr::fb_face_tracker2 &) { + return from_headset::face_type::fb2; + }, + [](xr::htc_face_tracker &) { + return from_headset::face_type::htc; + }, + [](xr::pico_face_tracker &) { + return from_headset::face_type::fb2; + }, + }, + application::get_face_tracker()); } info.num_generic_trackers = 0; if (config.check_feature(feature::body_tracking)) { - 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.num_generic_trackers = std::visit(utils::overloaded{ + [&](std::monostate &) { + return size_t(0); + }, + [&](auto & b) { + return b.count(); + }, + }, + application::get_body_tracker()); } info.palm_pose = application::space(xr::spaces::palm_left) or application::space(xr::spaces::palm_right); - info.passthrough = self->system.passthrough_supported() != xr::passthrough_type::none; + info.passthrough = self->system.passthrough_supported() != xr::system::passthrough_type::no_passthrough; info.system_name = std::string(self->system.properties().systemName); audio::get_audio_description(info); @@ -317,6 +311,15 @@ 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; @@ -360,7 +363,7 @@ std::shared_ptr scenes::stream::create(std::unique_ptrhaptics_actions.emplace(id, haptics_action{ .action = action.first, - .path = self->instance.string_to_path(path), + .path = application::string_to_path(path), }); } } @@ -391,7 +394,7 @@ std::shared_ptr scenes::stream::create(std::unique_ptrget_default_material()); + loader.emplace(device, physical_device, queue, application::queue_family_index(), renderer->get_default_material()); std::string profile = controller_name(); input.emplace( @@ -467,11 +470,8 @@ void scenes::stream::on_focused() swapchain_imgui, std::vector{vp}); - 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; - } + 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,8 +494,6 @@ void scenes::stream::on_unfocused() loader.reset(); renderer.reset(); clear_swapchains(); - left_hand.reset(); - right_hand.reset(); imgui_ctx.reset(); swapchain_imgui = xr::swapchain(); @@ -526,16 +524,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 = instance.now(); + handle->feedback.received_from_decoder = application::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.empty(); + return i.alpha() or not i.frames().empty(); })) { state_ = state::streaming; - spdlog::info("Stream scene ready at t={}", instance.now()); + spdlog::info("Stream scene ready at t={}", application::now()); } } @@ -550,14 +548,15 @@ bool scenes::stream::accumulator_images::alpha() const return decoder->desc().channels == wivrn::to_headset::video_stream_description::channels_t::alpha; } -bool scenes::stream::accumulator_images::empty() const +std::vector scenes::stream::accumulator_images::frames() const { + std::vector result; for (const auto & frame: latest_frames) { if (frame) - return false; + result.push_back(frame->feedback.frame_index); } - return true; + return result; } std::vector> scenes::stream::common_frame(XrTime display_time) @@ -767,15 +766,7 @@ 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) @@ -808,19 +799,51 @@ 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); - auto vert_constants = make_specialization_constants( - float(description.width) / image_size.width, - float(description.height) / 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 frag_constants = make_specialization_constants( - VkBool32(need_srgb_conversion(guess_model())), - VkBool32(i.alpha())); + 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); // Create graphics pipeline vk::raii::ShaderModule vertex_shader = load_shader(device, "stream.vert"); @@ -838,13 +861,13 @@ void scenes::stream::render(const XrFrameState & frame_state) .stage = vk::ShaderStageFlagBits::eVertex, .module = *vertex_shader, .pName = "main", - .pSpecializationInfo = vert_constants, + .pSpecializationInfo = &vert_specialization_info, }, { .stage = vk::ShaderStageFlagBits::eFragment, .module = *fragment_shader, .pName = "main", - .pSpecializationInfo = frag_constants, + .pSpecializationInfo = &frag_specialization_info, }}, .VertexBindingDescriptions = {}, .VertexAttributeDescriptions = {}, @@ -930,7 +953,7 @@ void scenes::stream::render(const XrFrameState & frame_state) if (not blit_handle or not *i.blit_pipeline) continue; - blit_handle->feedback.blitted = instance.now(); + blit_handle->feedback.blitted = application::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; @@ -979,10 +1002,6 @@ 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, @@ -1291,7 +1310,10 @@ 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, @@ -1315,7 +1337,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 = image_info.format, + .format = vk::Format::eA8B8G8R8SrgbPack32, .components = {}, .subresourceRange = { .aspectMask = vk::ImageAspectFlagBits::eColor, @@ -1339,8 +1361,8 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript .renderPass = *blit_render_pass, .attachmentCount = 1, .pAttachments = &*output.image_view, - .width = image_info.extent.width, - .height = image_info.extent.height, + .width = decoder_out_size.width, + .height = decoder_out_size.height, .layers = 1, }); } @@ -1365,7 +1387,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, instance, item, description.fps, shared_from_this(), stream_index), + .decoder = std::make_unique(device, physical_device, item, description.fps, shared_from_this(), stream_index), }); } } @@ -1407,6 +1429,8 @@ 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 146b6752..6f506ab7 100644 --- a/client/scenes/stream.h +++ b/client/scenes/stream.h @@ -48,13 +48,6 @@ 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; @@ -67,12 +60,12 @@ private: vk::DescriptorSet descriptor_set = nullptr; vk::raii::PipelineLayout blit_pipeline_layout = nullptr; vk::raii::Pipeline blit_pipeline = nullptr; - // latest frames, rolling buffer + // latest frames from oldest to most recent std::array, image_buffer_size> latest_frames; std::shared_ptr frame(uint64_t id) const; bool alpha() const; - bool empty() const; + std::vector frames() const; }; wifi_lock::wifi wifi; @@ -84,9 +77,9 @@ private: std::unique_ptr network_session; std::atomic exiting = false; std::thread network_thread; - thread_safe tracking_control{}; + std::mutex tracking_control_mutex; + to_headset::tracking_control 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; @@ -100,6 +93,8 @@ 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 @@ -130,8 +125,6 @@ private: std::optional