diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 5c847e25..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,8 +64,7 @@ body: attributes: label: Vulkan Info description: Provide the output of `vulkaninfo --summary` command. - render: text - placeholder: Attach the output as a file here. + placeholder: Add the output of vulkaninfo command here... - type: dropdown id: hmd @@ -107,5 +90,4 @@ body: attributes: label: ADB Logs description: Provide the output of `adb logcat` command. - render: plain - 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 04c1921c..c57d944f 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 247e9165..16aded6c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,12 +18,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) @@ -36,12 +37,12 @@ option(WIVRN_WERROR "Treat warnings as errors" OFF) option(WIVRN_OPTIMIZE_SHADERS "Run siprv-opt on compiled shaders" ON) 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 :") @@ -65,12 +66,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) @@ -82,13 +77,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) @@ -105,30 +106,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() @@ -144,8 +187,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) @@ -174,11 +216,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() @@ -192,7 +246,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) @@ -249,7 +305,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 f4512f7a..b0dd3325 100644 --- a/build.gradle +++ b/build.gradle @@ -124,7 +124,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 8090ae81..d2c1770e 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 SHADERS ${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 24082765..b0433274 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -18,7 +18,7 @@ */ #include "application.h" - +#include "asset.h" #include "hardware.h" #include "openxr/openxr.h" #include "scene.h" @@ -26,23 +26,18 @@ #include "spdlog/spdlog.h" #include "utils/contains.h" #include "utils/files.h" -#include "utils/i18n.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 @@ -72,6 +67,7 @@ struct interaction_profile std::string profile_name; std::vector required_extensions; XrVersion min_version = XR_MAKE_VERSION(1, 0, 0); + XrVersion max_version = XR_MAKE_VERSION(2, 0, 0); // exclusive std::vector input_sources; bool available; }; @@ -138,7 +134,8 @@ 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", "/user/hand/left/output/haptic_trigger_fb", @@ -250,7 +247,8 @@ 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", "/user/hand/right/output/haptic", @@ -350,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", @@ -393,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", @@ -436,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", @@ -479,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", @@ -521,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", @@ -550,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", }, @@ -654,7 +649,6 @@ VkBool32 application::vulkan_debug_report_callback( } #ifndef NDEBUG - bool my_error = true; if (level >= spdlog::level::warn) { bool validation_layer_found = false; @@ -665,13 +659,10 @@ VkBool32 application::vulkan_debug_report_callback( if (validation_layer_found && i.library != "libVkLayer_khronos_validation.so") spdlog::log(level, "{:#016x}: {} + {:#x}", i.pc, i.library, i.pc - i.library_base); - - if (i.library == "libopenxr_loader.so") - my_error = false; } } - if (level >= spdlog::level::err and my_error) + if (level >= spdlog::level::err) abort(); #endif @@ -726,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)) @@ -741,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); @@ -880,7 +874,6 @@ void application::initialize_vulkan() .ppEnabledExtensionNames = vk_device_extensions.data(), .pEnabledFeatures = &device_features, }, - vk::PhysicalDeviceFragmentShadingRateFeaturesKHR{}, #ifdef __ANDROID__ vk::PhysicalDeviceSamplerYcbcrConversionFeaturesKHR{ .samplerYcbcrConversion = VK_TRUE, @@ -888,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); @@ -925,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() @@ -981,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"); @@ -994,8 +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; + 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")) { @@ -1036,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")) { @@ -1055,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)); + } } } @@ -1111,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 @@ -1155,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)}); } } } @@ -1172,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 @@ -1192,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); @@ -1265,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; @@ -1282,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(); @@ -1323,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; @@ -1330,47 +1348,50 @@ void application::initialize() vk_cmdpool = vk::raii::CommandPool{vk_device, cmdpool_create_info}; initialize_actions(); - load_locale(); -} -void application::load_locale() -{ gen.add_messages_domain("wivrn"); std::locale loc = gen(""); - messages_info.encoding = "UTF-8"; - if (config->locale.empty()) - { #ifdef __ANDROID__ - jni::klass java_util_Locale("java/util/Locale"); - auto default_locale = java_util_Locale.call>("getDefault"); + jni::klass java_util_Locale("java/util/Locale"); + auto default_locale = java_util_Locale.call>("getDefault"); - // if (auto language = default_locale.call("toString")) - if (auto language = default_locale.call("getLanguage")) - messages_info.language = language; + // if (auto language = default_locale.call("toString")) + if (auto language = default_locale.call("getLanguage")) + messages_info.language = language; + + if (auto country = default_locale.call("getCountry")) + messages_info.country = country; + + messages_info.encoding = "UTF-8"; - if (auto country = default_locale.call("getCountry")) - messages_info.country = country; #else - auto & facet = std::use_facet(loc); - messages_info.language = facet.language(); - messages_info.country = facet.country(); + auto & facet = std::use_facet(loc); + messages_info.language = facet.language(); + messages_info.country = facet.country(); + messages_info.encoding = "UTF-8"; #endif - } - else - { - auto pos = config->locale.find("_"); - messages_info.language = config->locale.substr(0, pos); - if (pos != std::string::npos) - messages_info.country = config->locale.substr(pos + 1); - } spdlog::info("Current locale: language {}, country {}, encoding {}", messages_info.language, messages_info.country, messages_info.encoding); messages_info.paths.push_back("locale"); messages_info.domains.push_back(boost::locale::gnu_gettext::messages_info::domain("wivrn")); - messages_info.callback = open_locale_file; + messages_info.callback = [](const std::string & file_name, const std::string & encoding) { + std::vector buffer; + try + { + asset file(file_name); + buffer.resize(file.size()); + memcpy(buffer.data(), file.data(), file.size()); + } + catch (...) + { + } + + return buffer; + }; + loc = std::locale(loc, boost::locale::gnu_gettext::create_messages_facet(messages_info)); std::locale::global(loc); @@ -1854,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 365ebcf6..69327ae2 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 dbea9cf2..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,8 +214,8 @@ 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()); if (auto val = root["openxr_post_processing"]; val.is_object()) parse_openxr_post_processing_options(val.get_object()); @@ -204,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()) @@ -218,9 +254,6 @@ configuration::configuration(xr::system & system) if (auto val = root["first_run"]; val.is_bool()) first_run = val.get_bool(); - - if (auto val = root["locale"]; val.is_string()) - locale = val.get_string().value(); } catch (std::exception & e) { @@ -231,11 +264,31 @@ configuration::configuration(xr::system & system) preferred_refresh_rate.reset(); minimum_refresh_rate.reset(); 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; } } +void configuration::parse_sgsr_options(simdjson::simdjson_result sgsr_root) +{ + sgsr = {}; + if (auto val = sgsr_root["enabled"]; val.is_bool()) + sgsr.enabled = val.get_bool(); + + if (auto val = sgsr_root["upscaling_factor"]; val.is_double()) + sgsr.upscaling_factor = val.get_double(); + + if (auto val = sgsr_root["use_edge_direction"]; val.is_bool()) + sgsr.use_edge_direction = val.get_bool(); + + if (auto val = sgsr_root["edge_threshold"]; val.is_double()) + sgsr.edge_threshold = val.get_double(); + + if (auto val = sgsr_root["edge_sharpness"]; val.is_double()) + sgsr.edge_sharpness = val.get_double(); +} + void configuration::parse_openxr_post_processing_options(simdjson::simdjson_result openxr_post_processing_root) { openxr_post_processing = {}; @@ -251,6 +304,17 @@ static std::ostream & operator<<(std::ostream & stream, feature f) return stream << "\"" << magic_enum::enum_name(f) << "\""; } +static std::ostream & write_sgsr(std::ofstream & stream, const configuration::sgsr_settings & sgsr) +{ + stream << "{\"enabled\":" << std::boolalpha << sgsr.enabled; + stream << ",\"upscaling_factor\":" << sgsr.upscaling_factor; + stream << ",\"use_edge_direction\":" << std::boolalpha << sgsr.use_edge_direction; + stream << ",\"edge_threshold\":" << sgsr.edge_threshold; + stream << ",\"edge_sharpness\":" << sgsr.edge_sharpness; + stream << "}"; + return stream; +} + static std::ostream & write_openxr_post_processing(std::ofstream & stream, const configuration::openxr_post_processing_settings & openxr_post_processing) { stream << "{\"super_sampling\":" << openxr_post_processing.super_sampling; @@ -293,13 +357,14 @@ void configuration::save() if (minimum_refresh_rate) json << ",\"minimum_refresh_rate\":" << *minimum_refresh_rate; json << ",\"resolution_scale\":" << resolution_scale; + json << ",\"sgsr\":"; + write_sgsr(json, sgsr); json << ",\"openxr_post_processing\":"; write_openxr_post_processing(json, openxr_post_processing); json << ",\"passthrough_enabled\":" << std::boolalpha << passthrough_enabled; 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); @@ -307,6 +372,5 @@ void configuration::save() json << ",\"override_foveation_pitch\":" << override_foveation_pitch; json << ",\"override_foveation_distance\":" << override_foveation_distance; json << ",\"first_run\":" << std::boolalpha << first_run; - json << ",\"locale\":" << json_string(locale); json << "}"; } diff --git a/client/configuration.h b/client/configuration.h index d8dfbf6f..8d34faae 100644 --- a/client/configuration.h +++ b/client/configuration.h @@ -56,7 +56,16 @@ public: bool fb_lower_body = false; bool fb_hip = true; - bool enable_stream_gui = true; + // Snapdragon Game Super Resolution + struct sgsr_settings + { + bool enabled = false; + float upscaling_factor = 1.5; + bool use_edge_direction = true; + float edge_threshold = 4.0; + float edge_sharpness = 2.0; + }; + sgsr_settings sgsr{}; // XR_FB_composition_layer_settings extension flags struct openxr_post_processing_settings @@ -74,8 +83,6 @@ public: bool first_run = true; - std::string locale; - bool check_feature(feature f) const; void set_feature(feature f, bool state); @@ -83,6 +90,7 @@ private: mutable std::mutex mutex; std::map features; + void parse_sgsr_options(simdjson::simdjson_result root); void parse_openxr_post_processing_options(simdjson::simdjson_result root); public: diff --git a/client/decoder/shard_accumulator.cpp b/client/decoder/shard_accumulator.cpp index a7ec0636..c570fa93 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 a0145e22..4777de7f 100644 --- a/client/decoder/shard_accumulator.h +++ b/client/decoder/shard_accumulator.h @@ -19,30 +19,27 @@ #pragma once -#include "decoder.h" -#include "wivrn_packets.h" - #include +#include + +#ifdef __ANDROID__ +#include "decoder/android/android_decoder.h" +using decoder_impl = ::wivrn::android::decoder; +#else +#include "decoder/ffmpeg/ffmpeg_decoder.h" +using decoder_impl = ::wivrn::ffmpeg::decoder; +#endif + +#include "wivrn_packets.h" #include #include -#include - -namespace xr -{ -class instance; -} - -namespace scenes -{ -class stream; -} namespace wivrn { class shard_accumulator { - std::shared_ptr decoder_; + std::shared_ptr decoder; public: using data_shard = wivrn::to_headset::video_stream_data_shard; @@ -53,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{}; @@ -73,22 +70,19 @@ 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, uint8_t stream_index) : - decoder_(decoder::make(device, physical_device, description, fps, stream_index, scene, this)), + 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); } @@ -97,20 +91,20 @@ public: auto & desc() const { - return decoder_->description; + return decoder->desc(); } vk::Sampler sampler() { - return decoder_->sampler(); + return decoder->sampler(); } - const vk::Extent2D extent() + vk::Extent2D image_size() { - return decoder_->extent(); + return decoder->image_size(); } - using blit_handle = decoder::blit_handle; + using blit_handle = decoder_impl::blit_handle; private: void try_submit_frame(std::optional shard_idx); 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 888e4865..7a2daabb 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 2074e5aa..e67831ce 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 @@ -533,11 +532,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, @@ -548,14 +570,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, }, }, @@ -772,7 +794,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 fa7222cc..5ff2efa0 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -35,13 +35,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 @@ -248,7 +246,6 @@ void scenes::lobby::gui_connecting(locked_notifiable & pin_req if (next_scene) { current_tab = tab::connected; - timestamp_start_application.reset(); ImGui::CloseCurrentPopup(); return; } @@ -379,7 +376,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) { @@ -404,17 +401,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()) @@ -433,7 +427,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()) @@ -464,11 +458,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 @@ -480,7 +471,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) @@ -491,26 +482,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)); @@ -928,7 +905,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)) { @@ -952,7 +929,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)) { @@ -964,9 +941,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)) { @@ -981,14 +957,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(); @@ -1014,7 +995,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(); @@ -1025,13 +1006,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 } @@ -1263,12 +1237,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(), }, }; @@ -1598,22 +1572,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; @@ -1656,7 +1619,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, @@ -1677,18 +1640,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, @@ -1762,7 +1728,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); @@ -1879,7 +1845,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 } @@ -1991,7 +1957,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 e79c1305..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 @@ -38,6 +40,8 @@ #include "utils/contains.h" #include "utils/named_thread.h" #include "utils/ranges.h" +#include "vk/pipeline.h" +#include "vk/shader.h" #include "wivrn_packets.h" #include #include @@ -45,11 +49,6 @@ #include #include -#include "wivrn_config.h" -#if WIVRN_FEATURE_RENDERDOC -#include "vk/renderdoc.h" -#endif - using namespace wivrn; // clang-format off @@ -152,8 +151,7 @@ static const std::array supported_depth_formats{ }; scenes::stream::stream() : - scene_impl(supported_color_formats, supported_depth_formats), - blitters{blitter(device, 0), blitter(device, 1)} + scene_impl(supported_color_formats, supported_depth_formats) { } @@ -191,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()); @@ -257,49 +251,46 @@ 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); if (not(config.check_feature(feature::microphone))) info.microphone = {}; - info.supported_codecs = decoder::supported_codecs(); + info.supported_codecs = decoder_impl::supported_codecs(); return info; }()); @@ -320,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; @@ -363,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), }); } } @@ -394,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( @@ -470,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; @@ -497,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(); @@ -529,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()); } } @@ -553,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) @@ -770,17 +766,138 @@ 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) + { + if (auto sampler = i.decoder->sampler(); sampler and not *i.blit_pipeline) + { + // Create blit pipeline + // Create VkDescriptorSetLayout with an immutable sampler + vk::DescriptorSetLayoutBinding sampler_layout_binding{ + .binding = 0, + .descriptorType = vk::DescriptorType::eCombinedImageSampler, + .descriptorCount = 1, + .stageFlags = vk::ShaderStageFlagBits::eFragment, + .pImmutableSamplers = &sampler, + }; + + vk::DescriptorSetLayoutCreateInfo layout_info{ + .bindingCount = 1, + .pBindings = &sampler_layout_binding, + }; + + i.descriptor_set_layout = vk::raii::DescriptorSetLayout(device, layout_info); + i.descriptor_set = device.allocateDescriptorSets( + vk::DescriptorSetAllocateInfo{ + .descriptorPool = *blit_descriptor_pool, + .descriptorSetCount = 1, + .pSetLayouts = &*i.descriptor_set_layout, + })[0] + .release(); + + const auto & description = i.decoder->desc(); + vk::Extent2D image_size = i.decoder->image_size(); + std::array useful_size{ + float(description.width) / image_size.width, + float(description.height) / image_size.height, + }; + spdlog::info("useful size: {}x{} with buffer {}x{}", + description.width, + description.height, + image_size.width, + image_size.height); + + std::array specialization_constants_desc{ + vk::SpecializationMapEntry{ + .constantID = 0, + .offset = 0, + .size = sizeof(float), + }, + vk::SpecializationMapEntry{ + .constantID = 1, + .offset = sizeof(float), + .size = sizeof(float), + }}; + + 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"); + vk::raii::ShaderModule fragment_shader = load_shader(device, "stream.frag"); + + vk::PipelineLayoutCreateInfo pipeline_layout_info{ + .setLayoutCount = 1, + .pSetLayouts = &*i.descriptor_set_layout, + }; + + i.blit_pipeline_layout = vk::raii::PipelineLayout(device, pipeline_layout_info); + + vk::pipeline_builder pipeline_info{ + .Stages = {{ + .stage = vk::ShaderStageFlagBits::eVertex, + .module = *vertex_shader, + .pName = "main", + .pSpecializationInfo = &vert_specialization_info, + }, + { + .stage = vk::ShaderStageFlagBits::eFragment, + .module = *fragment_shader, + .pName = "main", + .pSpecializationInfo = &frag_specialization_info, + }}, + .VertexBindingDescriptions = {}, + .VertexAttributeDescriptions = {}, + .InputAssemblyState = {{ + .topology = vk::PrimitiveTopology::eTriangleStrip, + }}, + // With vk::DynamicState::eViewport, vk::DynamicState::eScissor the number of viewports + // and scissors is still used, put a vector with one element + .Viewports = {{}}, + .Scissors = {{}}, + .RasterizationState = {{ + .polygonMode = vk::PolygonMode::eFill, + .lineWidth = 1, + }}, + .MultisampleState = {{ + .rasterizationSamples = vk::SampleCountFlagBits::e1, + }}, + .ColorBlendAttachments = { + {.colorWriteMask = i.alpha() ? vk::ColorComponentFlagBits::eA + : vk::ColorComponentFlagBits::eA | vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB}}, + .DynamicStates = {vk::DynamicState::eViewport, vk::DynamicState::eScissor}, + .layout = *i.blit_pipeline_layout, + .renderPass = *blit_render_pass, + .subpass = 0, + }; + + i.blit_pipeline = vk::raii::Pipeline(device, application::get_pipeline_cache(), pipeline_info); + } + } + if (device.waitForFences(*fence, VK_TRUE, UINT64_MAX) == vk::Result::eTimeout) throw std::runtime_error("Vulkan fence timeout"); @@ -811,13 +928,11 @@ void scenes::stream::render(const XrFrameState & frame_state) std::array image_indices; -#if WIVRN_FEATURE_RENDERDOC - renderdoc_begin(*vk_instance); -#endif command_buffer.reset(); - command_buffer.begin(vk::CommandBufferBeginInfo{ - .flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit, - }); + + vk::CommandBufferBeginInfo begin_info; + begin_info.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit; + command_buffer.begin(begin_info); // Keep a reference to the resources needed to blit the images until vkWaitForFences @@ -832,12 +947,13 @@ void scenes::stream::render(const XrFrameState & frame_state) std::array foveation{}; bool use_alpha = false; - for (auto & blit_handle: current_blit_handles) + // Blit images from the decoders + for (auto [i, blit_handle]: std::views::zip(decoders, current_blit_handles)) { - if (not blit_handle) + 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; @@ -848,12 +964,27 @@ void scenes::stream::render(const XrFrameState & frame_state) foveation = blit_handle->view_info.foveation; use_alpha = blit_handle->view_info.alpha; - if (blit_handle->current_layout == vk::ImageLayout::eUndefined) + vk::DescriptorImageInfo image_info{ + .imageView = *blit_handle->image_view, + .imageLayout = vk::ImageLayout::eGeneral, + }; + + vk::WriteDescriptorSet descriptor_write{ + .dstSet = i.descriptor_set, + .dstBinding = 0, + .dstArrayElement = 0, + .descriptorCount = 1, + .descriptorType = vk::DescriptorType::eCombinedImageSampler, + .pImageInfo = &image_info, + }; + + device.updateDescriptorSets(descriptor_write, {}); + if (*blit_handle->current_layout != vk::ImageLayout::eGeneral) { vk::ImageMemoryBarrier barrier{ .srcAccessMask = vk::AccessFlagBits::eNone, .dstAccessMask = vk::AccessFlagBits::eMemoryRead, - .oldLayout = vk::ImageLayout::eUndefined, + .oldLayout = *blit_handle->current_layout, .newLayout = vk::ImageLayout::eGeneral, .image = blit_handle->image, .subresourceRange = { @@ -864,22 +995,72 @@ void scenes::stream::render(const XrFrameState & frame_state) }; command_buffer.pipelineBarrier(vk::PipelineStageFlagBits::eAllCommands, vk::PipelineStageFlagBits::eAllCommands, {}, {}, {}, barrier); - blit_handle->current_layout = vk::ImageLayout::eGeneral; + *blit_handle->current_layout = vk::ImageLayout::eGeneral; } } - // Blit images from the decoders - std::array blitted; - for (auto [i, b]: utils::enumerate(blitters)) + uint16_t x_offset = 0; + for (auto & out: decoder_output) { - b.begin(command_buffer); - for (auto [j, blit_handle]: utils::enumerate(current_blit_handles)) + command_buffer.beginRenderPass( + { + .renderPass = *blit_render_pass, + .framebuffer = *out.frame_buffer, + .renderArea = { + .offset = {0, 0}, + .extent = decoder_out_size, + }, + .clearValueCount = 0, + }, + vk::SubpassContents::eInline); + + for (const auto & decoder: decoders) { - if (not blit_handle) + if (not *decoder.blit_pipeline) continue; - b.push_image(command_buffer, j, decoders[j].decoder->sampler(), decoders[j].decoder->extent(), blit_handle->image_view, blit_handle->current_layout); + if (decoder.alpha() and not use_alpha) + continue; + + command_buffer.bindPipeline(vk::PipelineBindPoint::eGraphics, *decoder.blit_pipeline); + + const auto & description = decoder.decoder->desc(); + int x0 = description.offset_x - x_offset; + int y0 = description.offset_y; + int x1 = x0 + description.width * description.subsampling; + int y1 = y0 + description.height * description.subsampling; + + vk::Viewport viewport{ + .x = (float)x0, + .y = (float)y0, + .width = float(description.width * description.subsampling), + .height = float(description.height * description.subsampling), + .minDepth = 0, + .maxDepth = 1, + }; + + x0 = std::clamp(x0, 0, decoder_out_size.width); + x1 = std::clamp(x1, 0, decoder_out_size.width); + y0 = std::clamp(y0, 0, decoder_out_size.height); + y1 = std::clamp(y1, 0, decoder_out_size.height); + + vk::Rect2D scissor{ + .offset = {.x = x0, .y = y0}, + .extent = {.width = (uint32_t)(x1 - x0), .height = (uint32_t)(y1 - y0)}, + }; + + command_buffer.setViewport(0, viewport); + command_buffer.setScissor(0, scissor); + + command_buffer.bindDescriptorSets( + vk::PipelineBindPoint::eGraphics, + *decoder.blit_pipeline_layout, + 0, + decoder.descriptor_set, + nullptr); + command_buffer.draw(3, 1, 0, 0); } - blitted[i] = b.end(command_buffer); + command_buffer.endRenderPass(); + x_offset += decoder_out_size.width; } command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 1); @@ -890,7 +1071,7 @@ void scenes::stream::render(const XrFrameState & frame_state) int32_t max_height = 0; for (size_t i = 0; i < view_count; ++i) { - extents[i] = defoveator->defoveated_size(foveation[i]); + extents[i] = reprojector->defoveated_size(foveation[i]); max_width = std::max(max_width, extents[i].width); max_height = std::max(max_height, extents[i].height); } @@ -920,7 +1101,7 @@ void scenes::stream::render(const XrFrameState & frame_state) // defoveate the image int image_index = swapchain.acquire(); swapchain.wait(); - defoveator->defoveate(command_buffer, foveation, blitted, image_index); + reprojector->reproject(command_buffer, foveation, image_index); command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 2); @@ -928,9 +1109,6 @@ void scenes::stream::render(const XrFrameState & frame_state) vk::SubmitInfo submit_info; submit_info.setCommandBuffers(*command_buffer); queue.lock()->submit(submit_info, *fence); -#if WIVRN_FEATURE_RENDERDOC - renderdoc_end(*vk_instance); -#endif swapchain.release(); std::vector layer_view(view_count); @@ -1097,15 +1275,119 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript } video_stream_description = description; - for (auto & b: blitters) - b.reset(description); + + const uint32_t video_width = description.width / view_count; + const uint32_t video_height = description.height; + + // Create renderpass + { + vk::AttachmentDescription color_desc{ + .format = vk::Format::eA8B8G8R8SrgbPack32, + .samples = vk::SampleCountFlagBits::e1, + .loadOp = vk::AttachmentLoadOp::eDontCare, + .storeOp = vk::AttachmentStoreOp::eStore, + .initialLayout = vk::ImageLayout::eUndefined, + .finalLayout = vk::ImageLayout::eShaderReadOnlyOptimal, + }; + + vk::AttachmentReference color_ref{ + .attachment = 0, + .layout = vk::ImageLayout::eColorAttachmentOptimal, + }; + + vk::SubpassDescription subpass{ + .pipelineBindPoint = vk::PipelineBindPoint::eGraphics, + }; + subpass.setColorAttachments(color_ref); + + vk::RenderPassCreateInfo renderpass_info{ + .flags = {}, + }; + renderpass_info.setAttachments(color_desc); + renderpass_info.setSubpasses(subpass); + + blit_render_pass = vk::raii::RenderPass(device, renderpass_info); + } + + // 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, + .format = vk::Format::eA8B8G8R8SrgbPack32, + .extent = {video_width, video_height, 1}, + .mipLevels = 1, + .arrayLayers = view_count, + .samples = vk::SampleCountFlagBits::e1, + .tiling = vk::ImageTiling::eOptimal, + .usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eColorAttachment, + .sharingMode = vk::SharingMode::eExclusive, + .initialLayout = vk::ImageLayout::eUndefined, + }; + + VmaAllocationCreateInfo alloc_info{ + .requiredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, + }; + + decoder_out_image = image_allocation{device, image_info, alloc_info}; + + vk::ImageViewCreateInfo image_view_info{ + .image = vk::Image{decoder_out_image}, + .viewType = vk::ImageViewType::e2D, + .format = vk::Format::eA8B8G8R8SrgbPack32, + .components = {}, + .subresourceRange = { + .aspectMask = vk::ImageAspectFlagBits::eColor, + .baseMipLevel = 0, + .levelCount = 1, + .baseArrayLayer = 0, + .layerCount = 1, + }, + }; + + for (uint32_t view = 0; view < view_count; ++view) + { + auto & output = decoder_output[view]; + + image_view_info.subresourceRange.baseArrayLayer = view; + output.image_view = vk::raii::ImageView(device, image_view_info); + + output.frame_buffer = vk::raii::Framebuffer( + device, + vk::FramebufferCreateInfo{ + .renderPass = *blit_render_pass, + .attachmentCount = 1, + .pAttachments = &*output.image_view, + .width = decoder_out_size.width, + .height = decoder_out_size.height, + .layers = 1, + }); + } + } + + { + vk::DescriptorPoolSize pool_size{ + .type = vk::DescriptorType::eCombinedImageSampler, + .descriptorCount = uint32_t(2 * description.items.size()), + }; + blit_descriptor_pool = vk::raii::DescriptorPool( + device, + vk::DescriptorPoolCreateInfo{ + .maxSets = uint32_t(2 * description.items.size()), + .poolSizeCount = 1, + .pPoolSizes = &pool_size, + }); + } for (const auto & [stream_index, item]: utils::enumerate(description.items)) { 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), }); } } @@ -1118,6 +1400,15 @@ void scenes::stream::setup_reprojection_swapchain(uint32_t swapchain_width, uint const uint32_t video_width = video_stream_description->width / view_count; const uint32_t video_height = video_stream_description->height; + const configuration::sgsr_settings sgsr = application::get_config().sgsr; + if (sgsr.enabled) + { + const float upscaling_factor = sgsr.upscaling_factor; + spdlog::info("Using SGSR with an upscale factor of {}", upscaling_factor); + swapchain_width *= upscaling_factor; + swapchain_height *= upscaling_factor; + } + auto views = system.view_configuration_views(viewconfig); swapchain = xr::swapchain(session, device, swapchain_format, swapchain_width, swapchain_height, 1, views.size()); @@ -1134,9 +1425,12 @@ void scenes::stream::setup_reprojection_swapchain(uint32_t swapchain_width, uint for (auto & image: swapchain.images()) swapchain_images.push_back(image.image); - defoveator.emplace( + reprojector.emplace( 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 64cafea0..6f506ab7 100644 --- a/client/scenes/stream.h +++ b/client/scenes/stream.h @@ -23,9 +23,8 @@ #include "decoder/shard_accumulator.h" #include "render/imgui_impl.h" #include "scene.h" -#include "scenes/blitter.h" #include "scenes/input_profile.h" -#include "stream_defoveator.h" +#include "stream_reprojection.h" #include "utils/thread_safe.h" #include "wifi_lock.h" #include "wivrn_client.h" @@ -49,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; @@ -64,12 +56,16 @@ private: struct accumulator_images { std::unique_ptr decoder; - // latest frames, rolling buffer + vk::raii::DescriptorSetLayout descriptor_set_layout = nullptr; + vk::DescriptorSet descriptor_set = nullptr; + vk::raii::PipelineLayout blit_pipeline_layout = nullptr; + vk::raii::Pipeline blit_pipeline = nullptr; + // latest frames from oldest to most recent 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; @@ -81,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; @@ -94,10 +90,21 @@ private: std::shared_mutex decoder_mutex; std::optional video_stream_description; std::vector decoders; // Locked by decoder_mutex + vk::raii::DescriptorPool blit_descriptor_pool = nullptr; + vk::raii::RenderPass blit_render_pass = nullptr; - std::array blitters; + vk::Extent2D decoder_out_size; + vk::Format decoder_out_format; + image_allocation decoder_out_image; - std::optional defoveator; + struct renderpass_output + { + vk::raii::ImageView image_view = nullptr; + vk::raii::Framebuffer frame_buffer = nullptr; + }; + std::array decoder_output; + + std::optional reprojector; vk::raii::Fence fence = nullptr; vk::raii::CommandBuffer command_buffer = nullptr; @@ -118,8 +125,6 @@ private: std::optional