From ca053be9a7ec54f09d64227e5f67a728fd2b8a09 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sun, 18 May 2025 14:19:03 +0200 Subject: [PATCH 01/85] Prepare v0.25 release --- dashboard/io.github.wivrn.wivrn.metainfo.xml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/dashboard/io.github.wivrn.wivrn.metainfo.xml b/dashboard/io.github.wivrn.wivrn.metainfo.xml index 87681212..c687b86c 100644 --- a/dashboard/io.github.wivrn.wivrn.metainfo.xml +++ b/dashboard/io.github.wivrn.wivrn.metainfo.xml @@ -69,6 +69,16 @@ + + https://github.com/WiVRn/WiVRn/releases/tag/v0.25 + +
    +
  • Client-side post-processing (sharpening)
  • +
  • Configurable OpenVR compatibility library and path to adb
  • +
  • Include xrizer in flatpak release
  • +
+
+
https://github.com/WiVRn/WiVRn/releases/tag/v0.24.1 From a0f6a2247db4cc00b9fa62ad2c7630fdedbce753 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sun, 18 May 2025 17:06:54 +0200 Subject: [PATCH 02/85] fix apt usage in CI --- .github/workflows/Build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 0ae7d70b..d7b97df9 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -547,7 +547,7 @@ jobs: git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" git config --global user.name "github-actions[bot]" - apt install python-toml python-aiohttp + sudo apt-get install python-toml python-aiohttp cd flathub git remote add upstream https://github.com/flathub/io.github.wivrn.wivrn.git From f59015654c1ea488ffbbefd164c9e7c77a0d6578 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sun, 18 May 2025 20:57:11 +0200 Subject: [PATCH 03/85] fix build with older vulkan.hpp --- server/encoder/ffmpeg/video_encoder_va.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/encoder/ffmpeg/video_encoder_va.cpp b/server/encoder/ffmpeg/video_encoder_va.cpp index aec6d8c5..cbf2f9c5 100644 --- a/server/encoder/ffmpeg/video_encoder_va.cpp +++ b/server/encoder/ffmpeg/video_encoder_va.cpp @@ -312,7 +312,7 @@ video_encoder_va::video_encoder_va(wivrn_vk_bundle & vk, auto & image = (i == 0 ? luma : chroma); image = vk.device.createImage(image_create_info.get()); - auto [req, ded_req] = vk.device.getImageMemoryRequirements2({.image = image}); + auto [req, ded_req] = vk.device.getImageMemoryRequirements2({.image = *image}); const auto & object = desc->objects[desc->layers[i].planes[0].object_index]; auto memory_props = vk.device.getMemoryFdPropertiesKHR(vk::ExternalMemoryHandleTypeFlagBits::eDmaBufEXT, object.fd); @@ -327,7 +327,7 @@ video_encoder_va::video_encoder_va(wivrn_vk_bundle & vk, .fd = dup(object.fd), }, vk::MemoryDedicatedAllocateInfo{ - .image = image, + .image = *image, }, }; if (not(ded_req.prefersDedicatedAllocation or ded_req.requiresDedicatedAllocation)) From d90baecfef6866a41fdd3e55b6ff7e4ea288b1ed Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sun, 18 May 2025 21:40:02 +0200 Subject: [PATCH 04/85] don't fail on repos with no tags --- tools/gen_debian_changelog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/gen_debian_changelog.py b/tools/gen_debian_changelog.py index 6ab41130..30a72059 100755 --- a/tools/gen_debian_changelog.py +++ b/tools/gen_debian_changelog.py @@ -51,7 +51,7 @@ def main(): tree = ET.parse(args.metainfo) if args.nightly: - version = subprocess.check_output(["git", "describe", "--tags"]).decode().strip() + version = subprocess.check_output(["git", "describe", "--tags", "--always"]).decode().strip() version = version[1:] # remove the initial "v" write_entry( out=args.out, From bb0c847b92e8c2f912cf9303a4b7a703f3c8f526 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sun, 18 May 2025 21:52:22 +0200 Subject: [PATCH 05/85] don't fail release on forks --- .github/workflows/Build.yml | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index d7b97df9..90e7f0fb 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -510,10 +510,21 @@ jobs: fetch-depth: 0 path: wivrn + - name: Check for FLATHUB_TOKEN + id: flathub-token-check + shell: bash + run: | + if [[ "${{ secrets.FLATHUB_TOKEN}}" != '' ]]; then + echo "available=true" >> $GITHUB_OUTPUT; + else + echo "available=false" >> $GITHUB_OUTPUT; + fi + - uses: actions/checkout@v4 + if: ${{ steps.flathub-token-check.outputs.available == 'true' }} with: fetch-depth: 0 - repository: WiVRn/io.github.wivrn.wivrn + repository: ${{ github.repository_owner }}/io.github.wivrn.wivrn path: flathub token: ${{ secrets.FLATHUB_TOKEN }} @@ -541,6 +552,7 @@ jobs: flatpak/*.flatpak - name: Update flatpak manifest for flathub + if: ${{ steps.flathub-token-check.outputs.available == 'true' }} run: | WIVRN_TAG=$(echo $GITHUB_REF | sed -E -e "s,refs/[^/]*/v?,,") @@ -568,8 +580,9 @@ jobs: - name: Update release branch run: | cd wivrn - git fetch origin release - git push origin HEAD:release + if git fetch origin release; then + git push origin HEAD:release + fi sync_fork_downstream: name: Sync fork downstream From bc7d0ad6e00d7c03fdfd8145fa54645462b46e43 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Tue, 20 May 2025 23:30:18 +0200 Subject: [PATCH 06/85] Fix jdk package in Arch build instructions --- docs/building.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/building.md b/docs/building.md index 89115497..d5f0caf7 100644 --- a/docs/building.md +++ b/docs/building.md @@ -60,7 +60,7 @@ See [Server](#server-pc) for the server compile options. # Client (headset) #### Build dependencies -As Arch package names: git pkgconf glslang cmake jdk17-temurin librsvg cli11 ktx_software-git ([AUR](https://aur.archlinux.org/packages/ktx_software-git)) +As Arch package names: git pkgconf glslang cmake jdk17-openjdk librsvg cli11 ktx_software-git ([AUR](https://aur.archlinux.org/packages/ktx_software-git)) OpenSSL build dependencies are also needed, as described [here](https://github.com/openssl/openssl/blob/master/INSTALL.md#prerequisites), in particular perl 5. @@ -93,7 +93,7 @@ Once you have generated the keys, the apk will be automatically signed at build From the main directory. ```bash export ANDROID_HOME=~/Android -export JAVA_HOME=/usr/lib/jvm/java-17-temurin/ +export JAVA_HOME=/usr/lib/jvm/java-17-openjdk/ ./gradlew assembleStandardRelease ``` From b29abf073ed7eb94fb34210328d395d670aec7bb Mon Sep 17 00:00:00 2001 From: Sapphire Date: Tue, 20 May 2025 15:37:23 -0500 Subject: [PATCH 07/85] Fix call to ipc_server_main, add config options for debug GUI and steamvr_lh * Add config option for SteamVR lighthouse device support * Add dashboard toggles for debug window and steamvr_lh * clang-format * Hide advanced toggles if not enabled during build --- dashboard/gui_config.h.in | 3 +++ dashboard/qml/SettingsPage.qml | 23 ++++++++++++++++++ dashboard/settings.cpp | 42 +++++++++++++++++++++++++++++++++ dashboard/settings.h | 8 +++++++ server/driver/configuration.cpp | 6 +++++ server/driver/configuration.h | 2 ++ server/driver/wivrn_session.cpp | 3 ++- server/main.cpp | 21 ++++++++++++----- 8 files changed, 101 insertions(+), 7 deletions(-) diff --git a/dashboard/gui_config.h.in b/dashboard/gui_config.h.in index 7b087278..64c52003 100644 --- a/dashboard/gui_config.h.in +++ b/dashboard/gui_config.h.in @@ -21,6 +21,9 @@ #cmakedefine01 WIVRN_CHECK_CAPSYSNICE +#cmakedefine01 WIVRN_FEATURE_DEBUG_GUI +#cmakedefine01 WIVRN_FEATURE_STEAMVR_LIGHTHOUSE + #cmakedefine01 WIVRN_USE_NVENC #cmakedefine01 WIVRN_USE_VAAPI #cmakedefine01 WIVRN_USE_VULKAN_ENCODE diff --git a/dashboard/qml/SettingsPage.qml b/dashboard/qml/SettingsPage.qml index edeb59fa..78c87ac8 100644 --- a/dashboard/qml/SettingsPage.qml +++ b/dashboard/qml/SettingsPage.qml @@ -316,6 +316,22 @@ Kirigami.ScrollablePage { Kirigami.FormData.isSection: true } + Kirigami.Heading { + text: i18n("Advanced options") + level: 1 + type: Kirigami.Heading.Type.Primary + } + Controls.CheckBox { + id: debug_gui + text: i18n("Enable debug window") + visible: config.debug_gui_supported + } + Controls.CheckBox { + id: steamvr_lh + text: i18n("Enable SteamVR tracked devices support") + visible: config.steamvr_lh_supported + } + Controls.CheckBox { id: adb_custom Layout.row: 0 @@ -452,6 +468,9 @@ Kirigami.ScrollablePage { settings.adb_custom = adb_custom.checked; settings.adb_location = adb_location.text; Adb.setPath(adb_custom.checked ? adb_location.text : "adb"); + + config.debugGui = debug_gui.checked; + config.steamVrLh = steamvr_lh.checked; } function load() { @@ -471,6 +490,10 @@ Kirigami.ScrollablePage { // auto_encoders.checked = true; encoder_layout.currentIndex = 0; } + + debug_gui.checked = config.debugGui; + steamvr_lh.checked = config.steamVrLh; + openvr_combobox.load() adb_custom.checked = settings.adb_custom; diff --git a/dashboard/settings.cpp b/dashboard/settings.cpp index 7dbecc50..b0e59d1b 100644 --- a/dashboard/settings.cpp +++ b/dashboard/settings.cpp @@ -19,6 +19,7 @@ #include "settings.h" #include "escape_string.h" +#include "gui_config.h" #include "utils/flatpak.h" #include "wivrn_server.h" #include @@ -213,6 +214,25 @@ void Settings::load(const wivrn_server * server) set_application(""); } + // Advanced options (debug window, steamvr_lh) + try + { + set_debugGui(json_doc.value("debug-gui", false)); + } + catch (...) + { + set_debugGui(false); + } + + try + { + set_steamVrLh(json_doc.value("use-steamvr-lh", false)); + } + catch (...) + { + set_steamVrLh(false); + } + // OpenVR compat library try { @@ -298,6 +318,9 @@ void Settings::save(wivrn_server * server) if (application() != "") json_doc["application"] = unescape_string(application()); + json_doc["debug-gui"] = debugGui(); + json_doc["use-steamvr-lh"] = steamVrLh(); + if (openvr() == "-") json_doc["openvr-compat-path"] = nullptr; else if (openvr() == "") @@ -315,6 +338,8 @@ void Settings::restore_defaults() set_bitrate(50'000'000); set_scale(-1); set_application(""); + set_debugGui(false); + set_steamVrLh(false); set_tcpOnly(false); } @@ -347,4 +372,21 @@ bool Settings::flatpak() const return wivrn::is_flatpak(); } +bool Settings::debug_gui() const +{ +#if WIVRN_FEATURE_DEBUG_GUI + return true; +#else + return false; +#endif +} +bool Settings::steamvr_lh() const +{ +#if WIVRN_FEATURE_STEAMVR_LIGHTHOUSE + return true; +#else + return false; +#endif +} + #include "moc_settings.cpp" diff --git a/dashboard/settings.h b/dashboard/settings.h index 11948896..9a5e667c 100644 --- a/dashboard/settings.h +++ b/dashboard/settings.h @@ -122,10 +122,14 @@ class Settings : public QObject Q_PROPERTY(int bitrate READ bitrate WRITE set_bitrate NOTIFY bitrateChanged) Q_PROPERTY(float scale READ scale WRITE set_scale NOTIFY scaleChanged) Q_PROPERTY(QString application READ application WRITE set_application NOTIFY applicationChanged) + Q_PROPERTY(bool debugGui READ debugGui WRITE set_debugGui NOTIFY debugGuiChanged) + Q_PROPERTY(bool steamVrLh READ steamVrLh WRITE set_steamVrLh NOTIFY steamVrLhChanged) Q_PROPERTY(bool tcpOnly READ tcpOnly WRITE set_tcpOnly NOTIFY tcpOnlyChanged) Q_PROPERTY(QString openvr READ openvr WRITE set_openvr NOTIFY openvrChanged) Q_PROPERTY(bool flatpak READ flatpak CONSTANT) + Q_PROPERTY(bool debug_gui_supported READ debug_gui CONSTANT) + Q_PROPERTY(bool steamvr_lh_supported READ steamvr_lh CONSTANT) SETTER_GETTER_NOTIFY(bool, manualEncoders) SETTER_GETTER_NOTIFY(std::vector, encoders) @@ -133,6 +137,8 @@ class Settings : public QObject SETTER_GETTER_NOTIFY(int, bitrate) SETTER_GETTER_NOTIFY(float, scale) SETTER_GETTER_NOTIFY(QString, application) + SETTER_GETTER_NOTIFY(bool, debugGui) + SETTER_GETTER_NOTIFY(bool, steamVrLh) SETTER_GETTER_NOTIFY(bool, tcpOnly) SETTER_GETTER_NOTIFY(QString, openvr) @@ -146,6 +152,8 @@ public: Q_INVOKABLE void set_encoder_preset(QJSValue preset); bool flatpak() const; + bool debug_gui() const; + bool steamvr_lh() const; static std::optional encoder_id_from_string(std::string_view s); static std::optional codec_id_from_string(std::string_view s); diff --git a/server/driver/configuration.cpp b/server/driver/configuration.cpp index 7839b28d..2f7fc4b6 100644 --- a/server/driver/configuration.cpp +++ b/server/driver/configuration.cpp @@ -140,6 +140,12 @@ configuration configuration::read_user_configuration() } } + if (auto it = json.find("debug-gui"); it != json.end()) + result.debug_gui = *it; + + if (auto it = json.find("use-steamvr-lh"); it != json.end()) + result.use_steamvr_lh = *it; + if (auto it = json.find("tcp-only"); it != json.end()) result.tcp_only = *it; else if (auto it = json.find("tcp_only"); it != json.end()) diff --git a/server/driver/configuration.h b/server/driver/configuration.h index d3363b60..86eea9de 100644 --- a/server/driver/configuration.h +++ b/server/driver/configuration.h @@ -59,6 +59,8 @@ struct configuration std::optional> scale; std::optional> grip_surface; std::vector application; + bool debug_gui = false; + bool use_steamvr_lh = false; bool tcp_only = false; service_publication publication = service_publication::avahi; diff --git a/server/driver/wivrn_session.cpp b/server/driver/wivrn_session.cpp index 65833517..e884ff02 100644 --- a/server/driver/wivrn_session.cpp +++ b/server/driver/wivrn_session.cpp @@ -20,6 +20,7 @@ #include "wivrn_session.h" #include "accept_connection.h" +#include "configuration.h" #include "driver/app_pacer.h" #include "main/comp_compositor.h" #include "main/comp_main_interface.h" @@ -169,7 +170,7 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr connection static_roles.hand_tracking.right = xdevs[xdev_count++] = &right_hand; #if WIVRN_FEATURE_STEAMVR_LIGHTHOUSE - auto use_steamvr_lh = std::getenv("WIVRN_USE_STEAMVR_LH"); + auto use_steamvr_lh = configuration::read_user_configuration().use_steamvr_lh || std::getenv("WIVRN_USE_STEAMVR_LH"); xrt_system_devices * lhdevs = NULL; if (use_steamvr_lh && steamvr_lh_create_devices(&lhdevs) == XRT_SUCCESS) diff --git a/server/main.cpp b/server/main.cpp index 410afbd2..22e90386 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -49,6 +49,7 @@ #include #include +#include #include #include @@ -57,9 +58,6 @@ U_TRACE_TARGET_SETUP(U_TRACE_WHICH_SERVICE) extern "C" { - int - ipc_server_main(int argc, char * argv[]); - int listen_socket = -1; } @@ -267,7 +265,7 @@ void start_app() } } -void start_server() +void start_server(configuration config) { server_pid = do_fork ? fork() : 0; @@ -298,9 +296,20 @@ void start_server() setenv("AMD_DEBUG", "lowlatencyenc", false); + ipc_server_main_info server_info{ + .udgci = { + .window_title = "WiVRn", +#if WIVRN_FEATURE_DEBUG_GUI + .open = config.debug_gui ? U_DEBUG_GUI_OPEN_ALWAYS : U_DEBUG_GUI_OPEN_AUTO, +#else + .open = U_DEBUG_GUI_OPEN_NEVER, +#endif + }, + }; + try { - exit(ipc_server_main(0, 0 /*argc, argv*/)); + exit(ipc_server_main(0, 0, &server_info /*argc, argv, ismi*/)); } catch (std::exception & e) { @@ -472,7 +481,7 @@ gboolean headset_connected_success(void *) expose_known_keys_on_dbus(); - start_server(); + start_server(configuration::read_user_configuration()); start_app(); delay_next_try = default_delay_next_try; From 8b1de4ab719737700433224388f11c5b7dcfb083 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Wed, 21 May 2025 16:58:27 +0200 Subject: [PATCH 08/85] Catch patch errors in debian CI --- .github/workflows/Build.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 90e7f0fb..af74da05 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -470,7 +470,10 @@ jobs: - name: Patch monado working-directory: wivrn/monado-src - run: ../patches/apply.sh ../patches/monado/* + run: > + for p in ../patches/monado/*; do + patch -p1 --fuzz=0 --forward < "$p" + done - name: Edit changelog working-directory: wivrn From 309bd92fbbf828c81d98a2b6da5b1de9a4d9be04 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Wed, 21 May 2025 17:02:34 +0200 Subject: [PATCH 09/85] Regenerate monado patches --- ...001-c-multi-early-wake-of-compositor.patch | 8 +++---- ...02-ipc-server-Always-listen-to-stdin.patch | 6 +++--- .../monado/0003-Use-extern-socket-fd.patch | 6 +++--- ...Add-storage-usage-to-distortion-mesh.patch | 6 +++--- ...vironment-blend-mode-selection-logic.patch | 8 +++---- ...06-Use-mipmaps-for-distortion-shader.patch | 21 ++++++++++--------- .../0007-Convert-to-YCbCr-in-Monado.patch | 8 +++---- ...0008-store-alpha-channel-in-layer-1.patch} | 6 +++--- ...-oxr-bind-to-dynamic-role-s-profile.patch} | 8 +++---- ...ain-allow-custom-pacing-app-factory.patch} | 6 +++--- ... 0011-st-oxr-forward-0-refresh-rate.patch} | 10 ++++----- 11 files changed, 47 insertions(+), 46 deletions(-) rename patches/monado/{0010-store-alpha-channel-in-layer-1.patch => 0008-store-alpha-channel-in-layer-1.patch} (96%) rename patches/monado/{0011-st-oxr-bind-to-dynamic-role-s-profile.patch => 0009-st-oxr-bind-to-dynamic-role-s-profile.patch} (91%) rename patches/monado/{0013-c-main-allow-custom-pacing-app-factory.patch => 0010-c-main-allow-custom-pacing-app-factory.patch} (95%) rename patches/monado/{0014-st-oxr-forward-0-refresh-rate.patch => 0011-st-oxr-forward-0-refresh-rate.patch} (82%) diff --git a/patches/monado/0001-c-multi-early-wake-of-compositor.patch b/patches/monado/0001-c-multi-early-wake-of-compositor.patch index 173b1247..89e1a5ab 100644 --- a/patches/monado/0001-c-multi-early-wake-of-compositor.patch +++ b/patches/monado/0001-c-multi-early-wake-of-compositor.patch @@ -1,7 +1,7 @@ -From a0e439f723394452ab79a09c04df5135c3613d11 Mon Sep 17 00:00:00 2001 +From e18311e2b207f784cdd48ab6faf3834f912a1f8d Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Tue, 22 Oct 2024 15:23:19 +0200 -Subject: [PATCH 01/13] c/multi: early wake of compositor +Subject: [PATCH 01/11] c/multi: early wake of compositor --- .../compositor/multi/comp_multi_compositor.c | 14 +++++++++ @@ -10,7 +10,7 @@ Subject: [PATCH 01/13] c/multi: early wake of compositor 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/xrt/compositor/multi/comp_multi_compositor.c b/src/xrt/compositor/multi/comp_multi_compositor.c -index 2895ccb0f..0c940cb3a 100644 +index d19eda4ff..b9fcd0ca6 100644 --- a/src/xrt/compositor/multi/comp_multi_compositor.c +++ b/src/xrt/compositor/multi/comp_multi_compositor.c @@ -231,7 +231,21 @@ wait_for_scheduled_free(struct multi_compositor *mc) @@ -128,5 +128,5 @@ index b06b03a58..249e07d7d 100644 //! @todo Make the clients not go from IDLE to READY before we have completed a first frame. // Make sure there is at least some sort of valid frame data here. -- -2.48.1 +2.49.0 diff --git a/patches/monado/0002-ipc-server-Always-listen-to-stdin.patch b/patches/monado/0002-ipc-server-Always-listen-to-stdin.patch index 7908f3c4..2e600dae 100644 --- a/patches/monado/0002-ipc-server-Always-listen-to-stdin.patch +++ b/patches/monado/0002-ipc-server-Always-listen-to-stdin.patch @@ -1,7 +1,7 @@ -From 6e5926f76f8a7ee66eff164ebe630c65d024237f Mon Sep 17 00:00:00 2001 +From 0b802694d3a46668acbb7962cb6cc9e7634fa519 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Tue, 2 Apr 2024 17:14:42 +0200 -Subject: [PATCH 02/10] ipc/server: Always listen to stdin +Subject: [PATCH 02/11] ipc/server: Always listen to stdin --- src/xrt/ipc/server/ipc_server_mainloop_linux.c | 2 +- @@ -21,5 +21,5 @@ index d364fbed3..ad6b473b7 100644 // default. // This polls stdin. -- -2.48.0 +2.49.0 diff --git a/patches/monado/0003-Use-extern-socket-fd.patch b/patches/monado/0003-Use-extern-socket-fd.patch index db26adc3..80746d17 100644 --- a/patches/monado/0003-Use-extern-socket-fd.patch +++ b/patches/monado/0003-Use-extern-socket-fd.patch @@ -1,7 +1,7 @@ -From 95631921f2dd8f422281d5d94bca167bcb773471 Mon Sep 17 00:00:00 2001 +From 7a53f4a771a8386d659ad03a025447e8193c284c Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Tue, 8 Oct 2024 22:13:15 +0200 -Subject: [PATCH 03/10] Use extern socket fd +Subject: [PATCH 03/11] Use extern socket fd --- src/xrt/ipc/server/ipc_server_mainloop_linux.c | 8 ++++++++ @@ -34,5 +34,5 @@ index ad6b473b7..ea6fad65b 100644 // We may have been launched with socket activation int num_fds = sd_listen_fds(0); -- -2.48.0 +2.49.0 diff --git a/patches/monado/0004-c-render-Add-storage-usage-to-distortion-mesh.patch b/patches/monado/0004-c-render-Add-storage-usage-to-distortion-mesh.patch index bea92966..7079f123 100644 --- a/patches/monado/0004-c-render-Add-storage-usage-to-distortion-mesh.patch +++ b/patches/monado/0004-c-render-Add-storage-usage-to-distortion-mesh.patch @@ -1,7 +1,7 @@ -From c95362727746c19ff039168ebec3e6e21e6bcc3c Mon Sep 17 00:00:00 2001 +From 018341025bf1ddd2a59e063e7dd972b914ebfbb5 Mon Sep 17 00:00:00 2001 From: galister <3123227-galister@users.noreply.gitlab.com> Date: Mon, 19 Aug 2024 18:51:45 +0900 -Subject: [PATCH 04/10] c/render: Add storage usage to distortion mesh +Subject: [PATCH 04/11] c/render: Add storage usage to distortion mesh --- src/xrt/compositor/render/render_distortion.c | 2 +- @@ -21,5 +21,5 @@ index 8ac24db8e..5a7e400c3 100644 &image); // out_image VK_CHK_AND_RET(ret, "vk_create_image_simple"); -- -2.48.0 +2.49.0 diff --git a/patches/monado/0005-change-environment-blend-mode-selection-logic.patch b/patches/monado/0005-change-environment-blend-mode-selection-logic.patch index 13bab638..759e6467 100644 --- a/patches/monado/0005-change-environment-blend-mode-selection-logic.patch +++ b/patches/monado/0005-change-environment-blend-mode-selection-logic.patch @@ -1,14 +1,14 @@ -From 9a3e2f9bdc3149aaa6db1c54c95b0b4f9ab379ff Mon Sep 17 00:00:00 2001 +From e7159c1bb460909c7c8fe4d54f2a1513462e24b0 Mon Sep 17 00:00:00 2001 From: galister <85970-galister@users.noreply.gitlab.freedesktop.org> Date: Sat, 23 Nov 2024 02:42:12 +0900 -Subject: [PATCH 05/10] change environment blend mode selection logic +Subject: [PATCH 05/11] change environment blend mode selection logic --- src/xrt/compositor/multi/comp_multi_system.c | 26 +++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/xrt/compositor/multi/comp_multi_system.c b/src/xrt/compositor/multi/comp_multi_system.c -index b7d2c2174..62a5a0c27 100644 +index 249e07d7d..12c8fc455 100644 --- a/src/xrt/compositor/multi/comp_multi_system.c +++ b/src/xrt/compositor/multi/comp_multi_system.c @@ -232,23 +232,31 @@ find_active_blend_mode(struct multi_compositor **overlay_sorted_clients, size_t @@ -53,5 +53,5 @@ index b7d2c2174..62a5a0c27 100644 } -- -2.48.0 +2.49.0 diff --git a/patches/monado/0006-Use-mipmaps-for-distortion-shader.patch b/patches/monado/0006-Use-mipmaps-for-distortion-shader.patch index bd8a0ffd..a59214d1 100644 --- a/patches/monado/0006-Use-mipmaps-for-distortion-shader.patch +++ b/patches/monado/0006-Use-mipmaps-for-distortion-shader.patch @@ -1,7 +1,7 @@ -From 3f6883949ac235cc1e3f1ef8480ad08bd25da503 Mon Sep 17 00:00:00 2001 +From 5f506fb48a7dc284bb64598617bed6d8d481b662 Mon Sep 17 00:00:00 2001 From: galister <3123227-galister@users.noreply.gitlab.com> Date: Thu, 31 Oct 2024 04:37:27 +0900 -Subject: [PATCH 06/10] Use mipmaps for distortion shader +Subject: [PATCH 06/11] Use mipmaps for distortion shader --- src/external/CMakeLists.txt | 23 + @@ -42,10 +42,10 @@ Subject: [PATCH 06/10] Use mipmaps for distortion shader create mode 100644 src/xrt/compositor/util/comp_mipmap.h diff --git a/src/external/CMakeLists.txt b/src/external/CMakeLists.txt -index 0705627ae..51f89714f 100644 +index 6b1566e42..570d1a30f 100644 --- a/src/external/CMakeLists.txt +++ b/src/external/CMakeLists.txt -@@ -211,3 +211,26 @@ add_library(xrt-external-vdf INTERFACE) +@@ -215,3 +215,26 @@ add_library(xrt-external-vdf INTERFACE) target_include_directories( xrt-external-vdf SYSTEM INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/valve-file-vdf ) @@ -1673,7 +1673,7 @@ index 000000000..524a74120 + srgbFromLinear(arg.b), alpha); +} diff --git a/src/xrt/auxiliary/vk/vk_helpers.c b/src/xrt/auxiliary/vk/vk_helpers.c -index 62f505391..80193f1ab 100644 +index 3aebad12a..7e6630d4d 100644 --- a/src/xrt/auxiliary/vk/vk_helpers.c +++ b/src/xrt/auxiliary/vk/vk_helpers.c @@ -1382,6 +1382,7 @@ vk_create_sampler(struct vk_bundle *vk, VkSamplerAddressMode clamp_mode, VkSampl @@ -1716,7 +1716,7 @@ index f1c54ed4d..3bc9302f7 100644 target_include_directories(comp_util PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) endif() diff --git a/src/xrt/compositor/main/comp_renderer.c b/src/xrt/compositor/main/comp_renderer.c -index bd07a7744..112d14e32 100644 +index 6df4d2b29..89982e654 100644 --- a/src/xrt/compositor/main/comp_renderer.c +++ b/src/xrt/compositor/main/comp_renderer.c @@ -366,6 +366,9 @@ renderer_build_rendering_target_resources(struct comp_renderer *r, @@ -2499,10 +2499,10 @@ index dbc2fec7e..fc11a0521 100644 * Layer squashing. */ diff --git a/src/xrt/compositor/util/comp_render_helpers.h b/src/xrt/compositor/util/comp_render_helpers.h -index aa5de56c2..bbf295c0a 100644 +index 8fa3af8f0..4e525be5a 100644 --- a/src/xrt/compositor/util/comp_render_helpers.h +++ b/src/xrt/compositor/util/comp_render_helpers.h -@@ -145,10 +145,10 @@ cmd_barrier_view_images(struct vk_bundle *vk, +@@ -149,10 +149,10 @@ cmd_barrier_view_images(struct vk_bundle *vk, VkPipelineStageFlags src_stage_mask, VkPipelineStageFlags dst_stage_mask) { @@ -2515,7 +2515,7 @@ index aa5de56c2..bbf295c0a 100644 .baseArrayLayer = 0, .layerCount = 1, }; -@@ -172,16 +172,16 @@ cmd_barrier_view_images(struct vk_bundle *vk, +@@ -176,17 +176,17 @@ cmd_barrier_view_images(struct vk_bundle *vk, continue; } @@ -2543,6 +2543,7 @@ index aa5de56c2..bbf295c0a 100644 + all_color_level_subresource_range); // subresource_range } } + diff --git a/src/xrt/compositor/util/comp_scratch.c b/src/xrt/compositor/util/comp_scratch.c index 48bfda7c7..1d892a31b 100644 --- a/src/xrt/compositor/util/comp_scratch.c @@ -2759,5 +2760,5 @@ index 44849c20e..f8c891e49 100644 void comp_scratch_stereo_images_free(struct comp_scratch_stereo_images *cssi, struct vk_bundle *vk); -- -2.48.0 +2.49.0 diff --git a/patches/monado/0007-Convert-to-YCbCr-in-Monado.patch b/patches/monado/0007-Convert-to-YCbCr-in-Monado.patch index f1c9ad38..e26f6bc2 100644 --- a/patches/monado/0007-Convert-to-YCbCr-in-Monado.patch +++ b/patches/monado/0007-Convert-to-YCbCr-in-Monado.patch @@ -1,7 +1,7 @@ -From cf75548500d8aff912f2e63d68e0ea3628941bf8 Mon Sep 17 00:00:00 2001 +From 30eb60e3716c0bb0df118f4b36eb1820c567ee5b Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Wed, 11 Sep 2024 22:56:29 +0200 -Subject: [PATCH 07/10] Convert to YCbCr in Monado +Subject: [PATCH 07/11] Convert to YCbCr in Monado --- src/xrt/compositor/main/comp_renderer.c | 6 +- @@ -15,7 +15,7 @@ Subject: [PATCH 07/10] Convert to YCbCr in Monado 8 files changed, 186 insertions(+), 85 deletions(-) diff --git a/src/xrt/compositor/main/comp_renderer.c b/src/xrt/compositor/main/comp_renderer.c -index 104f761bf..3b3439d5a 100644 +index 89982e654..55aaed69e 100644 --- a/src/xrt/compositor/main/comp_renderer.c +++ b/src/xrt/compositor/main/comp_renderer.c @@ -1009,7 +1009,8 @@ dispatch_compute(struct comp_renderer *r, @@ -715,5 +715,5 @@ index fc11a0521..3db6c8d2e 100644 d->do_timewarp); // } -- -2.48.0 +2.49.0 diff --git a/patches/monado/0010-store-alpha-channel-in-layer-1.patch b/patches/monado/0008-store-alpha-channel-in-layer-1.patch similarity index 96% rename from patches/monado/0010-store-alpha-channel-in-layer-1.patch rename to patches/monado/0008-store-alpha-channel-in-layer-1.patch index eb04c298..450d45f0 100644 --- a/patches/monado/0010-store-alpha-channel-in-layer-1.patch +++ b/patches/monado/0008-store-alpha-channel-in-layer-1.patch @@ -1,7 +1,7 @@ -From e17739a88a15ac26dfe9ccb9ffc97ff029fa7764 Mon Sep 17 00:00:00 2001 +From d5337b1e4811aef804057e26d67aace90adc36e8 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sun, 3 Nov 2024 13:40:00 +0100 -Subject: [PATCH 10/10] store alpha channel in layer 1 +Subject: [PATCH 08/11] store alpha channel in layer 1 --- src/xrt/compositor/shaders/clear.comp | 4 ++-- @@ -90,5 +90,5 @@ index 461aeb4ec..237221a54 100644 + imageStore(luma, ivec3(offset.xy/2 + gl_GlobalInvocationID.xy, 1), alpha); } -- -2.48.0 +2.49.0 diff --git a/patches/monado/0011-st-oxr-bind-to-dynamic-role-s-profile.patch b/patches/monado/0009-st-oxr-bind-to-dynamic-role-s-profile.patch similarity index 91% rename from patches/monado/0011-st-oxr-bind-to-dynamic-role-s-profile.patch rename to patches/monado/0009-st-oxr-bind-to-dynamic-role-s-profile.patch index 32aaad95..c2566ed7 100644 --- a/patches/monado/0011-st-oxr-bind-to-dynamic-role-s-profile.patch +++ b/patches/monado/0009-st-oxr-bind-to-dynamic-role-s-profile.patch @@ -1,14 +1,14 @@ -From 6321ad3eee7d4a8b304a36de008d8fb8359f3dfe Mon Sep 17 00:00:00 2001 +From dffeb683c92b6ab2fbbf240817e4087a134d997f Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Wed, 19 Feb 2025 10:13:36 +0100 -Subject: [PATCH] st/oxr: bind to dynamic role's profile +Subject: [PATCH 09/11] st/oxr: bind to dynamic role's profile --- src/xrt/state_trackers/oxr/oxr_binding.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/xrt/state_trackers/oxr/oxr_binding.c b/src/xrt/state_trackers/oxr/oxr_binding.c -index eb8bb5489..b04977a8b 100644 +index 07378d7b3..83a7b241d 100644 --- a/src/xrt/state_trackers/oxr/oxr_binding.c +++ b/src/xrt/state_trackers/oxr/oxr_binding.c @@ -380,6 +380,23 @@ oxr_find_profile_for_device(struct oxr_logger *log, @@ -36,5 +36,5 @@ index eb8bb5489..b04977a8b 100644 oxr_get_profile_for_device_name(log, sess, xdev->name, out_p); if (*out_p != NULL) { -- -2.48.1 +2.49.0 diff --git a/patches/monado/0013-c-main-allow-custom-pacing-app-factory.patch b/patches/monado/0010-c-main-allow-custom-pacing-app-factory.patch similarity index 95% rename from patches/monado/0013-c-main-allow-custom-pacing-app-factory.patch rename to patches/monado/0010-c-main-allow-custom-pacing-app-factory.patch index a30f8edd..91f9d340 100644 --- a/patches/monado/0013-c-main-allow-custom-pacing-app-factory.patch +++ b/patches/monado/0010-c-main-allow-custom-pacing-app-factory.patch @@ -1,7 +1,7 @@ -From edd3447b25387908acbe005f1cbee5f17bae0260 Mon Sep 17 00:00:00 2001 +From 644f84e916d40d6341de91687a3dc9b0eecd13a4 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Thu, 27 Feb 2025 22:45:36 +0100 -Subject: [PATCH] c/main: allow custom pacing app factory +Subject: [PATCH 10/11] c/main: allow custom pacing app factory --- src/xrt/compositor/main/comp_compositor.c | 10 ++++++---- @@ -78,5 +78,5 @@ index 617561c37..e10ba8358 100644 #else if (!use_null) { -- -2.48.1 +2.49.0 diff --git a/patches/monado/0014-st-oxr-forward-0-refresh-rate.patch b/patches/monado/0011-st-oxr-forward-0-refresh-rate.patch similarity index 82% rename from patches/monado/0014-st-oxr-forward-0-refresh-rate.patch rename to patches/monado/0011-st-oxr-forward-0-refresh-rate.patch index a2318f5f..f1b0dbfe 100644 --- a/patches/monado/0014-st-oxr-forward-0-refresh-rate.patch +++ b/patches/monado/0011-st-oxr-forward-0-refresh-rate.patch @@ -1,17 +1,17 @@ -From b9bef34f0362677d2a58c0b2b331c98e2f74f9b2 Mon Sep 17 00:00:00 2001 +From f3dbf64ec2a45ac0e44a5d017b66d12fd8d63e77 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sat, 15 Mar 2025 22:19:48 +0100 -Subject: [PATCH] st/oxr: forward 0 refresh rate +Subject: [PATCH 11/11] st/oxr: forward 0 refresh rate --- src/xrt/state_trackers/oxr/oxr_api_session.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/xrt/state_trackers/oxr/oxr_api_session.c b/src/xrt/state_trackers/oxr/oxr_api_session.c -index c84806bde..955019957 100644 +index df8ec96b7..cbc542130 100644 --- a/src/xrt/state_trackers/oxr/oxr_api_session.c +++ b/src/xrt/state_trackers/oxr/oxr_api_session.c -@@ -644,15 +644,11 @@ oxr_xrRequestDisplayRefreshRateFB(XrSession session, float displayRefreshRate) +@@ -645,15 +645,11 @@ oxr_xrRequestDisplayRefreshRateFB(XrSession session, float displayRefreshRate) OXR_VERIFY_SESSION_AND_INIT_LOG(&log, session, sess, "xrRequestDisplayRefreshRateFB"); OXR_VERIFY_SESSION_NOT_LOST(&log, sess); @@ -29,5 +29,5 @@ index c84806bde..955019957 100644 if ((int)(displayRefreshRate * 100.0f) == (int)(sess->sys->xsysc->info.refresh_rates_hz[i] * 100.0f)) { found = true; -- -2.48.1 +2.49.0 From d3e7201774e86e2d931497d044aebe6f5e8775d6 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Wed, 21 May 2025 19:56:00 +0200 Subject: [PATCH 10/85] Document debug-gui and use-steamvr-lh --- docs/configuration.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/configuration.md b/docs/configuration.md index 79f5ef14..5e52937f 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -190,3 +190,17 @@ Provides the path to the directory of an OpenVR compatibility tool (such as Open If unset, WiVRn will autodetect the path of such a tool as usual (see [the SteamVR guide](./steamvr.md)). If set to an null, WiVRn will not manage the OpenVR configuration. + +## `debug-gui` +Default value: `false` + +Only available when built with `WIVRN_FEATURE_DEBUG_GUI`. + +Enables the Monado debug gui. + +## `use-steamvr-lh` +Default value: `false` + +Only available when built with `WIVRN_FEATURE_STEAMVR_LIGHTHOUSE` + +Enables the driver to load SteamVR Lighthouse devices. From d9dc4fb8df83d72ff91dbbbdf0b25593bd7c2b96 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Wed, 21 May 2025 20:11:51 +0200 Subject: [PATCH 11/85] Add tooltip for lighthouse button --- dashboard/qml/SettingsPage.qml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/dashboard/qml/SettingsPage.qml b/dashboard/qml/SettingsPage.qml index 78c87ac8..f0b573bd 100644 --- a/dashboard/qml/SettingsPage.qml +++ b/dashboard/qml/SettingsPage.qml @@ -326,10 +326,15 @@ Kirigami.ScrollablePage { text: i18n("Enable debug window") visible: config.debug_gui_supported } - Controls.CheckBox { - id: steamvr_lh - text: i18n("Enable SteamVR tracked devices support") + RowLayout { visible: config.steamvr_lh_supported + Controls.CheckBox { + id: steamvr_lh + text: i18n("Enable SteamVR tracked devices support") + } + Kirigami.ContextualHelpButton { + toolTipText: i18n("Load Lighthouse based controllers and trackers, requires SteamVR to be installed and devices to be powered on when connecting to WiVRn.") + } } Controls.CheckBox { From 4a0a5818ae92cfb33567bb1fad875da749a6b011 Mon Sep 17 00:00:00 2001 From: Sapphire Date: Tue, 13 May 2025 17:51:45 -0500 Subject: [PATCH 12/85] Add nix devshell --- flake.lock | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..51376c93 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1743550720, + "narHash": "sha256-hIshGgKZCgWh6AYJpJmRgFdR3WUbkY04o82X05xqQiY=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "c621e8422220273271f52058f618c94e405bb0f5", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1747744144, + "narHash": "sha256-W7lqHp0qZiENCDwUZ5EX/lNhxjMdNapFnbErcbnP11Q=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "2795c506fe8fb7b03c36ccb51f75b6df0ab2553f", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1743296961, + "narHash": "sha256-b1EdN3cULCqtorQ4QeWgLMrd5ZGOjLSLemfa00heasc=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "e4822aea2a6d1cdd36653c134cacfd64c97ff4fa", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..5c33ce92 --- /dev/null +++ b/flake.nix @@ -0,0 +1,57 @@ +{ + inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + inputs.flake-parts.url = "github:hercules-ci/flake-parts"; + + outputs = inputs@{ nixpkgs, flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ "x86_64-linux" ]; + perSystem = { pkgs, ... }: let + # Tools used for development work (clangd, clang-format) + devTools = with pkgs; [ + clang-tools + ]; + # Extra build inputs not yet in the nixpkgs recipe. + # Should be submitted to nixpkgs on release + extraBuildInputs = with pkgs; [ + # XRT_FEATURE_DEBUG_GUI requires SDL2 + sdl2-compat + ]; + + package = pkgs.wivrn.overrideAttrs (finalAttrs: oldAttrs: { + src = ./.; + version = "next"; + + # Because src is just a folder path and not a set from a fetcher, it doesn't need to be unpacked, so having a postUnpack throws an error. + postUnpack = null; + prePatch = '' + ourMonadoRev="${finalAttrs.monado.src.rev}" + theirMonadoRev=$(sed -n '/FetchContent_Declare(monado/,/)/p' CMakeLists.txt | grep "GIT_TAG" | awk '{print $2}') + if [ ! "$theirMonadoRev" == "$ourMonadoRev" ]; then + echo "Our Monado source revision doesn't match CMakeLists.txt." >&2 + echo " theirs: $theirMonadoRev" >&2 + echo " ours: $ourMonadoRev" >&2 + return 1 + fi + ''; + + monado = pkgs.applyPatches { + inherit (oldAttrs.monado) patches postPatch; + src = pkgs.fetchFromGitLab { + inherit (oldAttrs.monado.src) owner repo; + domain = "gitlab.freedesktop.org"; + # Keep in sync with CMakeLists.txt monado rev + rev = "2a6932d46dad9aa957205e8a47ec2baa33041076"; + hash = "sha256-Bus9GTNC4+nOSwN8pUsMaFsiXjlpHYioQfBLxbQEF+0="; + }; + }; + + buildInputs = oldAttrs.buildInputs ++ extraBuildInputs; + }); + in { + packages.default = package; + devShells.default = package.overrideAttrs (oldAttrs: { + nativeBuildInputs = oldAttrs.nativeBuildInputs ++ devTools; + }); + }; + }; +} \ No newline at end of file From ac3003ef54186a4bc44069e1663b0bfc6f4ab59d Mon Sep 17 00:00:00 2001 From: Sapphire Date: Wed, 21 May 2025 04:00:27 -0500 Subject: [PATCH 13/85] Add Nix CI step --- .github/workflows/Build.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index af74da05..1537c5b3 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -150,6 +150,18 @@ jobs: include-hidden-files: true retention-days: 1 + nix-test: + name: Test Nix package and devshell + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: cachix/install-nix-action@v31 + - run: nix flake check + - run: nix build + build-test-client: name: Linux client runs-on: ubuntu-24.04 From aa86ee72121ae133bd0f7b84c070c73bc5a9685f Mon Sep 17 00:00:00 2001 From: Sapphire Date: Wed, 21 May 2025 05:41:49 -0500 Subject: [PATCH 14/85] Read monado rev from file --- .github/workflows/Build.yml | 2 +- CMakeLists.txt | 3 ++- flake.nix | 14 +++----------- monado-rev | 1 + tools/gen_flatpak_manifest.py | 2 +- 5 files changed, 8 insertions(+), 14 deletions(-) create mode 100644 monado-rev diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 1537c5b3..e61a4874 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -474,7 +474,7 @@ jobs: - name: Download monado run: | - MONADO_COMMIT=$(grep -zo "FetchContent_Declare(monado[^)]*)" wivrn/CMakeLists.txt | sed -ze "s/^.*GIT_TAG *\([^ )]*\).*$/\1/" | tr -d '\0') + MONADO_COMMIT=$(cat wivrn/monado-rev) wget https://gitlab.freedesktop.org/monado/monado/-/archive/$MONADO_COMMIT/monado-$MONADO_COMMIT.tar.gz mkdir wivrn/monado-src diff --git a/CMakeLists.txt b/CMakeLists.txt index 98678d01..3e213697 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -284,11 +284,12 @@ FetchContent_Declare(uni-algo EXCLUDE_FROM_ALL SYSTEM URL https://github.co URL_HASH SHA256=f2a1539cd8635bc6088d05144a73ecfe7b4d74ee0361fabed6f87f9f19e74ca9) file(GLOB MONADO_PATCHES CONFIGURE_DEPENDS patches/monado/*) +file(READ monado-rev MONADO_REV) # Server dependencies FetchContent_Declare(monado GIT_REPOSITORY https://gitlab.freedesktop.org/monado/monado # The flatpak manifest is updated automatically - GIT_TAG 2a6932d46dad9aa957205e8a47ec2baa33041076 + GIT_TAG ${MONADO_REV} PATCH_COMMAND ${CMAKE_CURRENT_LIST_DIR}/patches/apply.sh ${MONADO_PATCHES} EXCLUDE_FROM_ALL ) diff --git a/flake.nix b/flake.nix index 5c33ce92..df94fe73 100644 --- a/flake.nix +++ b/flake.nix @@ -22,17 +22,8 @@ version = "next"; # Because src is just a folder path and not a set from a fetcher, it doesn't need to be unpacked, so having a postUnpack throws an error. + # We also don't need the check since we read the revision from the monado-rev file. postUnpack = null; - prePatch = '' - ourMonadoRev="${finalAttrs.monado.src.rev}" - theirMonadoRev=$(sed -n '/FetchContent_Declare(monado/,/)/p' CMakeLists.txt | grep "GIT_TAG" | awk '{print $2}') - if [ ! "$theirMonadoRev" == "$ourMonadoRev" ]; then - echo "Our Monado source revision doesn't match CMakeLists.txt." >&2 - echo " theirs: $theirMonadoRev" >&2 - echo " ours: $ourMonadoRev" >&2 - return 1 - fi - ''; monado = pkgs.applyPatches { inherit (oldAttrs.monado) patches postPatch; @@ -40,7 +31,8 @@ inherit (oldAttrs.monado.src) owner repo; domain = "gitlab.freedesktop.org"; # Keep in sync with CMakeLists.txt monado rev - rev = "2a6932d46dad9aa957205e8a47ec2baa33041076"; + rev = builtins.readFile ./monado-rev; + # Nix will output the correct hash when it doesn't match hash = "sha256-Bus9GTNC4+nOSwN8pUsMaFsiXjlpHYioQfBLxbQEF+0="; }; }; diff --git a/monado-rev b/monado-rev new file mode 100644 index 00000000..f4e7a1ab --- /dev/null +++ b/monado-rev @@ -0,0 +1 @@ +2a6932d46dad9aa957205e8a47ec2baa33041076 \ No newline at end of file diff --git a/tools/gen_flatpak_manifest.py b/tools/gen_flatpak_manifest.py index 5c82d1c5..7715416b 100755 --- a/tools/gen_flatpak_manifest.py +++ b/tools/gen_flatpak_manifest.py @@ -58,7 +58,7 @@ if __name__ == "__main__": json.dump(gen_src, f, indent=4, sort_keys=False) - monado_commit = cmake.get("monado", "GIT_TAG") + monado_commit = open(os.path.join(root, "monado-rev")).read() boostpfr_url = cmake.get("boostpfr", "URL") boostpfr_sha256 = cmake.get("boostpfr", "URL_HASH").split("=")[-1] From 4b103ef6b00d18cbc02f9184b97b67e5dcf97097 Mon Sep 17 00:00:00 2001 From: Sapphire Date: Wed, 21 May 2025 07:54:34 -0500 Subject: [PATCH 15/85] Force a refetch when the revision changes --- flake.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index df94fe73..1121315e 100644 --- a/flake.nix +++ b/flake.nix @@ -27,7 +27,8 @@ monado = pkgs.applyPatches { inherit (oldAttrs.monado) patches postPatch; - src = pkgs.fetchFromGitLab { + # Force a refetch when the monado rev changes. + src = pkgs.invalidateFetcherByDrvHash pkgs.fetchFromGitLab { inherit (oldAttrs.monado.src) owner repo; domain = "gitlab.freedesktop.org"; # Keep in sync with CMakeLists.txt monado rev From 61152d95a0e0d0a4c3ba253c787b814bd7114e79 Mon Sep 17 00:00:00 2001 From: mitsuami-megane <173323057+mitsuami-megane@users.noreply.github.com> Date: Thu, 22 May 2025 03:31:42 +0900 Subject: [PATCH 16/85] update steamvr_lh tooltip --- dashboard/qml/SettingsPage.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dashboard/qml/SettingsPage.qml b/dashboard/qml/SettingsPage.qml index f0b573bd..d4c9ed59 100644 --- a/dashboard/qml/SettingsPage.qml +++ b/dashboard/qml/SettingsPage.qml @@ -333,7 +333,7 @@ Kirigami.ScrollablePage { text: i18n("Enable SteamVR tracked devices support") } Kirigami.ContextualHelpButton { - toolTipText: i18n("Load Lighthouse based controllers and trackers, requires SteamVR to be installed and devices to be powered on when connecting to WiVRn.") + toolTipText: i18n("Allows the use of lighthouse-based controllers and trackers.\nRequires SteamVR to be installed.\nDevices must be be powered on before connecting to WiVRn.\nAn external tool such as motoc is needed for calibration.") } } From 77560028963bedc28f088d349d45be2524588e1a Mon Sep 17 00:00:00 2001 From: mitsuami-megane <173323057+mitsuami-megane@users.noreply.github.com> Date: Thu, 22 May 2025 03:47:58 +0900 Subject: [PATCH 17/85] update ja-JP locale --- locale/ja/wivrn-dashboard.po | 66 +++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 19 deletions(-) diff --git a/locale/ja/wivrn-dashboard.po b/locale/ja/wivrn-dashboard.po index 3d7fcafb..32e15228 100644 --- a/locale/ja/wivrn-dashboard.po +++ b/locale/ja/wivrn-dashboard.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: WiVRn-dashboard\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-05-05 23:41+0900\n" +"POT-Creation-Date: 2025-05-22 03:31+0900\n" "PO-Revision-Date: 2025-04-10 07:14+0900\n" "Last-Translator: Mitsuami Megane \n" "Language-Team: Japanese <>\n" @@ -517,54 +517,72 @@ msgstr "H.265" msgid "AV1" msgstr "AV1" -#: dashboard/qml/SettingsPage.qml:323 +#: dashboard/qml/SettingsPage.qml:320 +#, kde-format +msgid "Advanced options" +msgstr "詳細設定" + +#: dashboard/qml/SettingsPage.qml:326 +#, kde-format +msgid "Enable debug window" +msgstr "デバッグ・ウィンドウを表示する" + +#: dashboard/qml/SettingsPage.qml:333 +#, kde-format +msgid "Enable SteamVR tracked devices support" +msgstr "SteamVR・ライトハウス・トラッキング" + +#: dashboard/qml/SettingsPage.qml:336 +#, kde-format +msgid "" +"Allows the use of lighthouse-based controllers and trackers.\n" +"Requires SteamVR to be installed.\n" +"Devices must be be powered on before connecting to WiVRn.\n" +"An external tool such as motoc is needed for calibration." +msgstr "" +"ライトハウスのコントローラーやトラッカーなどの使用します。\n" +"SteamVRをインストールする必要があります。\n" +"すべてのデバイスの電源が入ってからHMDを接続しましょう。\n" +"キャリブレーションはmotocなどのソフトウェアで行います。" + +#: dashboard/qml/SettingsPage.qml:344 #, kde-format msgid "Custom adb location" msgstr "特定なADBの場所" -#: dashboard/qml/SettingsPage.qml:334 +#: dashboard/qml/SettingsPage.qml:355 #, kde-format msgid "Adb location:" msgstr "ADBの場所:" -#: dashboard/qml/SettingsPage.qml:343 +#: dashboard/qml/SettingsPage.qml:364 #, kde-format msgctxt "browse a file to choose the adb binary" msgid "Browse" msgstr "検索する" -#: dashboard/qml/SettingsPage.qml:353 +#: dashboard/qml/SettingsPage.qml:374 #, kde-format msgid "Default" msgstr "デフォルト" -#: dashboard/qml/SettingsPage.qml:360 -#, kde-format -msgid "xrizer" -msgstr "xrizer" - -#: dashboard/qml/SettingsPage.qml:365 -#, kde-format -msgid "Open Composite" -msgstr "OpenComposite" - -#: dashboard/qml/SettingsPage.qml:372 +#: dashboard/qml/SettingsPage.qml:388 #, kde-format msgctxt "set a custom OpenVR compatibility library" msgid "Custom" msgstr "カスタム" -#: dashboard/qml/SettingsPage.qml:377 +#: dashboard/qml/SettingsPage.qml:393 #, kde-format msgid "Disabled" msgstr "無し" -#: dashboard/qml/SettingsPage.qml:385 +#: dashboard/qml/SettingsPage.qml:401 #, kde-format msgid "OpenVR compatibility library:" msgstr "OpenVR実装ライブラリー" -#: dashboard/qml/SettingsPage.qml:411 +#: dashboard/qml/SettingsPage.qml:427 #, kde-format msgid "Library path, excluding bin/linux64/vrclient.so" msgstr "ライブラリーの場所(bin/linux64/vrclient.so 無し)" @@ -862,3 +880,13 @@ msgstr "完了" #, kde-format msgid "Finished" msgstr "完了しました" + +#: dashboard/wivrn_server.cpp:584 +#, kde-format +msgid "xrizer" +msgstr "xrizer" + +#: dashboard/wivrn_server.cpp:585 +#, kde-format +msgid "Open Composite" +msgstr "OpenComposite" From d6fb4d6f36a9ec59be701ee7cfc824381147de96 Mon Sep 17 00:00:00 2001 From: mitsuami-megane <173323057+mitsuami-megane@users.noreply.github.com> Date: Thu, 22 May 2025 04:14:20 +0900 Subject: [PATCH 18/85] Fix ja locale typo --- locale/ja/wivrn-dashboard.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locale/ja/wivrn-dashboard.po b/locale/ja/wivrn-dashboard.po index 32e15228..40f425ba 100644 --- a/locale/ja/wivrn-dashboard.po +++ b/locale/ja/wivrn-dashboard.po @@ -540,7 +540,7 @@ msgid "" "Devices must be be powered on before connecting to WiVRn.\n" "An external tool such as motoc is needed for calibration." msgstr "" -"ライトハウスのコントローラーやトラッカーなどの使用します。\n" +"ライトハウスのコントローラーやトラッカーなどを使用します。\n" "SteamVRをインストールする必要があります。\n" "すべてのデバイスの電源が入ってからHMDを接続しましょう。\n" "キャリブレーションはmotocなどのソフトウェアで行います。" From a33fae434ef49110dc520c8828072a5ad3e39a3b Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Wed, 21 May 2025 11:24:21 +0200 Subject: [PATCH 19/85] Destroy cuda context in encoder destructor --- server/encoder/video_encoder_nvenc.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/encoder/video_encoder_nvenc.cpp b/server/encoder/video_encoder_nvenc.cpp index b6d976a0..b07ed634 100644 --- a/server/encoder/video_encoder_nvenc.cpp +++ b/server/encoder/video_encoder_nvenc.cpp @@ -310,6 +310,8 @@ video_encoder_nvenc::~video_encoder_nvenc() { if (session_handle) fn.nvEncDestroyEncoder(session_handle); + if (cuda) + cuda_fn->cuCtxDestroy(cuda); } std::pair video_encoder_nvenc::present_image(vk::Image y_cbcr, vk::raii::CommandBuffer & cmd_buf, uint8_t slot, uint64_t) From d88d8230d4bd096cf37bd19927d8accb385f8849 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Thu, 22 May 2025 18:27:39 +0200 Subject: [PATCH 20/85] update fr locale --- locale/fr/wivrn-dashboard.po | 69 +++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 20 deletions(-) diff --git a/locale/fr/wivrn-dashboard.po b/locale/fr/wivrn-dashboard.po index 2f3efab6..ce67fd84 100644 --- a/locale/fr/wivrn-dashboard.po +++ b/locale/fr/wivrn-dashboard.po @@ -5,8 +5,8 @@ msgid "" msgstr "" "Project-Id-Version: WiVRn-dashboard\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-04-27 16:16+0200\n" -"PO-Revision-Date: 2025-04-27 16:20+0200\n" +"POT-Creation-Date: 2025-05-22 18:25+0200\n" +"PO-Revision-Date: 2025-05-22 18:33+0200\n" "Last-Translator: Guillaume Meunier \n" "Language-Team: French <>\n" "Language: French\n" @@ -530,54 +530,73 @@ msgstr "H.265" msgid "AV1" msgstr "AV1" -#: dashboard/qml/SettingsPage.qml:323 +#: dashboard/qml/SettingsPage.qml:320 +#, kde-format +msgid "Advanced options" +msgstr "Paramètres avancés" + +#: dashboard/qml/SettingsPage.qml:326 +#, kde-format +msgid "Enable debug window" +msgstr "Activer la fenêtre de débogage" + +#: dashboard/qml/SettingsPage.qml:333 +#, kde-format +msgid "Enable SteamVR tracked devices support" +msgstr "Activer le support des manettes SteamVR" + +#: dashboard/qml/SettingsPage.qml:336 +#, kde-format +msgid "" +"Allows the use of lighthouse-based controllers and trackers.\n" +"Requires SteamVR to be installed.\n" +"Devices must be be powered on before connecting to WiVRn.\n" +"An external tool such as motoc is needed for calibration." +msgstr "" +"Permet d'utiliser les manettes et trackers utilisant Lighthouse.\n" +"Nécessite SteamVR installé.\n" +"Les manettes et trackers doivent être allumés avant de connecter le casque à " +"WiVRn.\n" +"Un utilitaire tiers tel que motoc est nécessaire pour la calibration." + +#: dashboard/qml/SettingsPage.qml:344 #, kde-format msgid "Custom adb location" msgstr "Spécifier l'emplacement d'adb" -#: dashboard/qml/SettingsPage.qml:334 +#: dashboard/qml/SettingsPage.qml:355 #, kde-format msgid "Adb location:" msgstr "Emplacement d'adb" -#: dashboard/qml/SettingsPage.qml:343 +#: dashboard/qml/SettingsPage.qml:364 #, kde-format msgctxt "browse a file to choose the adb binary" msgid "Browse" msgstr "Parcourir" -#: dashboard/qml/SettingsPage.qml:353 +#: dashboard/qml/SettingsPage.qml:374 #, kde-format msgid "Default" msgstr "Par défaut" -#: dashboard/qml/SettingsPage.qml:360 -#, kde-format -msgid "xrizer" -msgstr "xrizer" - -#: dashboard/qml/SettingsPage.qml:365 -#, kde-format -msgid "Open Composite" -msgstr "Open Composite" - -#: dashboard/qml/SettingsPage.qml:372 +#: dashboard/qml/SettingsPage.qml:388 #, kde-format msgctxt "set a custom OpenVR compatibility library" msgid "Custom" msgstr "Personnalisé" -#: dashboard/qml/SettingsPage.qml:377 +#: dashboard/qml/SettingsPage.qml:393 #, kde-format msgid "Disabled" msgstr "Désactivé" -#: dashboard/qml/SettingsPage.qml:385 +#: dashboard/qml/SettingsPage.qml:401 #, kde-format msgid "OpenVR compatibility library:" msgstr "Compatibilité OpenVR :" -#: dashboard/qml/SettingsPage.qml:411 +#: dashboard/qml/SettingsPage.qml:427 #, kde-format msgid "Library path, excluding bin/linux64/vrclient.so" msgstr "Chemin de la bibliothèque, en enlevant bin/linux64/vrclient.so" @@ -887,3 +906,13 @@ msgstr "Finir" #, kde-format msgid "Finished" msgstr "Terminé" + +#: dashboard/wivrn_server.cpp:584 +#, kde-format +msgid "xrizer" +msgstr "xrizer" + +#: dashboard/wivrn_server.cpp:585 +#, kde-format +msgid "Open Composite" +msgstr "Open Composite" From 8297c38d7f4296394faab20fdb735904503406d9 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Mon, 26 May 2025 11:29:06 +0200 Subject: [PATCH 21/85] Fix crash on non-Android --- client/application.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/client/application.cpp b/client/application.cpp index 060777b3..bacde863 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -1356,11 +1356,7 @@ application::application(application_info info) : } }; -#ifdef __ANDROID__ wifi = wifi_lock::make_wifi_lock(app_info.native_app->activity->clazz); -#else - wifi = std::make_shared(); -#endif // Initialize the loader for this platform PFN_xrInitializeLoaderKHR initializeLoader = nullptr; @@ -1376,6 +1372,7 @@ application::application(application_info info) : } #else + wifi = std::make_shared(); config_path = xdg_config_home() / "wivrn"; cache_path = xdg_cache_home() / "wivrn"; #endif From f97cac0b85dc60fbfcc03763d4fdc03f2e045945 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Mon, 26 May 2025 11:40:05 +0200 Subject: [PATCH 22/85] Fix incorrect image type --- client/scenes/stream_reprojection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/scenes/stream_reprojection.cpp b/client/scenes/stream_reprojection.cpp index 563b7ea2..fc701634 100644 --- a/client/scenes/stream_reprojection.cpp +++ b/client/scenes/stream_reprojection.cpp @@ -153,7 +153,7 @@ stream_reprojection::stream_reprojection( { vk::ImageViewCreateInfo iv_info{ .image = input_image, - .viewType = vk::ImageViewType::e2DArray, + .viewType = vk::ImageViewType::e2D, .format = vk::Format::eA8B8G8R8SrgbPack32, .components = { .r = vk::ComponentSwizzle::eIdentity, From 38b64fe09c27757109f126d91b9a5f4244e01f78 Mon Sep 17 00:00:00 2001 From: Kitlith Date: Mon, 26 May 2025 20:46:41 -0700 Subject: [PATCH 23/85] Make patch commit timestamps reproducible. This forces commit timestamps to match authorship timestamps, meaning that the only remaining avenue of variability is the committing person. --- patches/apply.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patches/apply.sh b/patches/apply.sh index cd1cb078..0aae3c60 100755 --- a/patches/apply.sh +++ b/patches/apply.sh @@ -6,7 +6,7 @@ if [ -d ".git" ] ; then git config --local commit.gpgsign false git am --abort 2> /dev/null git checkout . - exec git am "$@" + exec git am --committer-date-is-author-date "$@" fi # There is no reliable way to apply a patch and succeed if it was From 5130bdeda51c52137f11e0536273f3bfbb2f7f71 Mon Sep 17 00:00:00 2001 From: Kitlith Date: Mon, 26 May 2025 20:58:00 -0700 Subject: [PATCH 24/85] Make patch commit committer reproducible. Just makes setting the git config unconditional. We should probably drop this commit if this script is also intended to be used with repositories outside of the build deps. --- patches/apply.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/patches/apply.sh b/patches/apply.sh index 0aae3c60..272a2e54 100755 --- a/patches/apply.sh +++ b/patches/apply.sh @@ -1,9 +1,9 @@ #!/bin/sh if [ -d ".git" ] ; then - git config user.email > /dev/null || git config user.email "git-am@invalid" - git config user.name > /dev/null || git config user.name "no name" - git config --local commit.gpgsign false + git config --worktree user.email "git-am@invalid" + git config --worktree user.name "no name" + git config --worktree commit.gpgsign false git am --abort 2> /dev/null git checkout . exec git am --committer-date-is-author-date "$@" From 908d21ffecc57eb2e569d6ebb09cdd99c898421f Mon Sep 17 00:00:00 2001 From: Sapphire Date: Mon, 12 May 2025 11:44:51 -0500 Subject: [PATCH 25/85] WIP: Pico 4 Pro face tracking --- .github/ISSUE_TEMPLATE/bug_report.yml | 1 + AndroidManifest.xml | 2 + client/application.cpp | 13 ++ client/application.h | 14 ++ client/configuration.cpp | 4 + client/hardware.cpp | 9 + client/hardware.h | 1 + client/scenes/lobby_gui.cpp | 4 +- client/scenes/stream.cpp | 2 + client/scenes/stream_tracking.cpp | 8 +- client/xr/pico_face_tracker.cpp | 69 +++++++ client/xr/pico_face_tracker.h | 49 +++++ client/xr/session.cpp | 6 + client/xr/session.h | 2 + client/xr/xr.h | 4 + common/wivrn_packets.h | 9 + common/xr/pico_eye_types.h | 147 ++++++++++++++ common/xr/pico_eye_types_reflection.h | 31 +++ server/CMakeLists.txt | 1 + server/driver/wivrn_pico_face_tracker.cpp | 223 ++++++++++++++++++++++ server/driver/wivrn_pico_face_tracker.h | 48 +++++ server/driver/wivrn_session.cpp | 9 + server/driver/wivrn_session.h | 2 + 23 files changed, 655 insertions(+), 3 deletions(-) create mode 100644 client/xr/pico_face_tracker.cpp create mode 100644 client/xr/pico_face_tracker.h create mode 100644 common/xr/pico_eye_types.h create mode 100644 common/xr/pico_eye_types_reflection.h create mode 100644 server/driver/wivrn_pico_face_tracker.cpp create mode 100644 server/driver/wivrn_pico_face_tracker.h diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 26fdca1e..b9417e68 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -77,6 +77,7 @@ body: - Quest 3 - Quest 3S - Pico 4 + - Pico 4 Pro/Enterprise - Pico Neo 3 - HTC Vive Focus 3 - HTC Vive XR Elite diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 9914169e..9df29233 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -44,6 +44,7 @@ + @@ -70,6 +71,7 @@ + diff --git a/client/application.cpp b/client/application.cpp index bacde863..66249e7a 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -30,6 +30,7 @@ #include "wifi_lock.h" #include "xr/actionset.h" #include "xr/check.h" +#include "xr/pico_eye_types.h" #include "xr/xr.h" #include #include @@ -1039,6 +1040,7 @@ void application::initialize() opt_extensions.push_back(XR_HTC_PASSTHROUGH_EXTENSION_NAME); opt_extensions.push_back(XR_HTC_FACIAL_TRACKING_EXTENSION_NAME); opt_extensions.push_back(XR_FB_FACE_TRACKING2_EXTENSION_NAME); + opt_extensions.push_back(XR_PICO_EYE_TRACKING_EXTENSION_NAME); opt_extensions.push_back(XR_EXT_PALM_POSE_EXTENSION_NAME); opt_extensions.push_back(XR_KHR_COMPOSITION_LAYER_DEPTH_EXTENSION_NAME); opt_extensions.push_back(XR_FB_COMPOSITION_LAYER_DEPTH_TEST_EXTENSION_NAME); @@ -1121,6 +1123,12 @@ void application::initialize() htc_face_tracking_lip_supported = htc_face_properties.supportLipFacialTracking; } + if (utils::contains(xr_extensions, XR_PICO_EYE_TRACKING_EXTENSION_NAME)) + { + spdlog::info(" PICO face tracking support: true"); + pico_face_tracking_supported = true; + } + if (utils::contains(xr_extensions, XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME)) { spdlog::info(" OpenXR post-processing extension support: true"); @@ -1180,6 +1188,11 @@ void application::initialize() htc_face_tracker_lip = xr_session.create_htc_face_tracker(XR_FACIAL_TRACKING_TYPE_LIP_DEFAULT_HTC); } + if (pico_face_tracking_supported) + { + pico_face_tracker = xr_session.create_pico_face_tracker(); + } + vk::CommandPoolCreateInfo cmdpool_create_info; cmdpool_create_info.queueFamilyIndex = vk_queue_family_index; cmdpool_create_info.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer; diff --git a/client/application.h b/client/application.h index 2a5e44d0..67758507 100644 --- a/client/application.h +++ b/client/application.h @@ -24,6 +24,7 @@ #include "xr/fb_face_tracker2.h" #include "xr/hand_tracker.h" #include "xr/htc_face_tracker.h" +#include "xr/pico_face_tracker.h" #ifdef __ANDROID__ #include #endif @@ -133,6 +134,9 @@ class application : public singleton bool htc_face_tracking_lip_supported = false; xr::htc_face_tracker htc_face_tracker_lip; + bool pico_face_tracking_supported = false; + xr::pico_face_tracker pico_face_tracker; + bool eye_gaze_supported = false; bool openxr_post_processing_supported = false; @@ -436,6 +440,11 @@ public: return instance().htc_face_tracking_lip_supported; } + static bool get_pico_face_tracking_supported() + { + return instance().pico_face_tracking_supported; + } + static bool get_eye_gaze_supported() { return instance().eye_gaze_supported; @@ -471,6 +480,11 @@ public: return instance().htc_face_tracker_lip; } + static xr::pico_face_tracker & get_pico_face_tracker() + { + return instance().pico_face_tracker; + } + static const std::vector & get_xr_extensions() { return instance().xr_extensions; diff --git a/client/configuration.cpp b/client/configuration.cpp index 0be20d8a..be7bab39 100644 --- a/client/configuration.cpp +++ b/client/configuration.cpp @@ -111,6 +111,10 @@ bool configuration::check_feature(feature f) const if (not(application::get_htc_face_tracking_eye_supported() or application::get_htc_face_tracking_lip_supported())) return false; break; + case model::pico_4_pro: + if (not application::get_pico_face_tracking_supported()) + return false; + break; default: if (not application::get_fb_face_tracking2_supported()) return false; diff --git a/client/hardware.cpp b/client/hardware.cpp index ddf051b4..6a4362ab 100644 --- a/client/hardware.cpp +++ b/client/hardware.cpp @@ -77,6 +77,9 @@ static model guess_model_() if (model == "A9210") return model::pico_4s; + if (model == "A8110") + return model::pico_4_pro; + spdlog::info("manufacturer={}, model={}, device={} assuming Pico 4", manufacturer, model, device); return model::pico_4; } @@ -145,6 +148,7 @@ XrViewConfigurationView override_view(XrViewConfigurationView view, model m) return scale_view(view, 1832); case model::pico_4: case model::pico_4s: + case model::pico_4_pro: return scale_view(view, 2160); case model::htc_vive_focus_3: case model::htc_vive_focus_vision: @@ -172,6 +176,7 @@ bool need_srgb_conversion(model m) case model::pico_neo_3: case model::pico_4: case model::pico_4s: + case model::pico_4_pro: case model::htc_vive_focus_3: case model::htc_vive_focus_vision: case model::htc_vive_xr_elite: @@ -201,6 +206,7 @@ const char * permission_name(feature f) case model::pico_neo_3: case model::pico_4: case model::pico_4s: + case model::pico_4_pro: return "com.picovr.permission.EYE_TRACKING"; case model::htc_vive_focus_3: case model::htc_vive_focus_vision: @@ -222,6 +228,8 @@ const char * permission_name(feature f) case model::pico_neo_3: case model::pico_4: case model::pico_4s: + case model::pico_4_pro: + return "com.picovr.permission.FACE_TRACKING"; case model::htc_vive_focus_3: case model::htc_vive_focus_vision: case model::htc_vive_xr_elite: @@ -257,6 +265,7 @@ std::string controller_name() return "pico-neo3"; case model::pico_4: case model::pico_4s: // TODO: split when we have the pico-4s 3d model + case model::pico_4_pro: return "pico-4"; case model::htc_vive_focus_3: case model::htc_vive_focus_vision: diff --git a/client/hardware.h b/client/hardware.h index e74cb1cf..f3daf059 100644 --- a/client/hardware.h +++ b/client/hardware.h @@ -35,6 +35,7 @@ enum class model pico_neo_3, pico_4, pico_4s, + pico_4_pro, htc_vive_focus_3, htc_vive_xr_elite, htc_vive_focus_vision, diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index 94c14797..c8bf6fd8 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -727,7 +727,7 @@ void scenes::lobby::gui_settings() ImGui::EndDisabled(); } { - ImGui::BeginDisabled(not(application::get_fb_face_tracking2_supported() or application::get_htc_face_tracking_eye_supported() or application::get_htc_face_tracking_lip_supported())); + ImGui::BeginDisabled(not(application::get_fb_face_tracking2_supported() or application::get_htc_face_tracking_eye_supported() or application::get_htc_face_tracking_lip_supported() or application::get_pico_face_tracking_supported())); bool enabled = config.check_feature(feature::face_tracking); if (ImGui::Checkbox(_S("Enable face tracking"), &enabled)) { @@ -1419,7 +1419,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time) }); } - if (application::get_htc_face_tracking_eye_supported() or application::get_htc_face_tracking_lip_supported()) + if (application::get_htc_face_tracking_eye_supported() or application::get_htc_face_tracking_lip_supported() or application::get_pico_face_tracking_supported()) { items.push_back({ .f = feature::face_tracking, diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index 6c49de63..eb03c4eb 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -220,6 +220,8 @@ std::shared_ptr scenes::stream::create(std::unique_ptr + * Copyright (C) 2025 Sapphire + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "pico_face_tracker.h" +#include "spdlog/common.h" +#include "spdlog/spdlog.h" +#include "wivrn_packets.h" +#include "xr/instance.h" +#include "xr/session.h" +#include "xr/xr.h" +#include + +xr::pico_face_tracker::pico_face_tracker(instance & inst, session & s_) : + s(s_) +{ + xrStartEyeTrackingPICO = inst.get_proc("xrStartEyeTrackingPICO"); + xrStopEyeTrackingPICO = inst.get_proc("xrStopEyeTrackingPICO"); + xrSetTrackingModePICO = inst.get_proc("xrSetTrackingModePICO"); + xrGetFaceTrackingStatePICO = inst.get_proc("xrGetFaceTrackingStatePICO"); + xrGetFaceTrackingDataPICO = inst.get_proc("xrGetFaceTrackingDataPICO"); + + CHECK_XR(xrStartEyeTrackingPICO(s)); + CHECK_XR(xrSetTrackingModePICO(s, XR_TRACKING_MODE_FACE_BIT_PICO)); +} +xr::pico_face_tracker::~pico_face_tracker() +{ + if (auto res = xrStopEyeTrackingPICO(s, XR_TRACKING_MODE_FACE_BIT_PICO); res != XR_SUCCESS) + spdlog::warn("Failed to deactivate face tracking: {}", xr::to_string(res)); +} + +void xr::pico_face_tracker::get_weights(XrTime time, wivrn::from_headset::tracking::pico_face & out_expressions) +{ + if (!xrGetFaceTrackingDataPICO) + return; + + XrFaceTrackingDataPICO face_tracking{.time = 0}; + + if (auto res = xrGetFaceTrackingDataPICO(s, time, XR_GET_FACE_DATA_DEFAULT_PICO, &face_tracking); res != XR_SUCCESS) + { + XrTrackingModeFlagsPICO mode; + XrTrackingStateCodePICO code; + + if (xrGetFaceTrackingStatePICO(s, &mode, &code) == XR_SUCCESS) + spdlog::warn("Unable to get face tracking data: xrGetFaceTrackingDataPICO returned {}, tracking mode state {}, flags {}", xr::to_string(res), xr::to_string(code), mode); + else + spdlog::warn("Unable to get face tracking data: xrGetFaceTrackingDataPICO returned {}", xr::to_string(res)); + out_expressions.is_valid = false; + return; + } + + std::copy_n(face_tracking.blendShapeWeight, std::size(face_tracking.blendShapeWeight), out_expressions.weights.data()); + out_expressions.is_valid = face_tracking.time != 0; +} diff --git a/client/xr/pico_face_tracker.h b/client/xr/pico_face_tracker.h new file mode 100644 index 00000000..aa95e0c9 --- /dev/null +++ b/client/xr/pico_face_tracker.h @@ -0,0 +1,49 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2024 galister + * Copyright (C) 2025 Sapphire + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include "wivrn_packets.h" +#include "xr/pico_eye_types.h" +#include "xr/pico_eye_types_reflection.h" +#include + +namespace xr +{ +class instance; +class session; + +class pico_face_tracker +{ + PFN_xrStartEyeTrackingPICO xrStartEyeTrackingPICO{}; + PFN_xrStopEyeTrackingPICO xrStopEyeTrackingPICO{}; + PFN_xrSetTrackingModePICO xrSetTrackingModePICO{}; + PFN_xrGetFaceTrackingStatePICO xrGetFaceTrackingStatePICO{}; + PFN_xrGetFaceTrackingDataPICO xrGetFaceTrackingDataPICO{}; + + XrSession s; + +public: + pico_face_tracker() = default; + pico_face_tracker(instance & inst, session & s); + ~pico_face_tracker(); + + void get_weights(XrTime time, struct wivrn::from_headset::tracking::pico_face & out_expressions); +}; +} // namespace xr diff --git a/client/xr/session.cpp b/client/xr/session.cpp index 2b51405f..ab6e6978 100644 --- a/client/xr/session.cpp +++ b/client/xr/session.cpp @@ -136,6 +136,12 @@ xr::htc_face_tracker xr::session::create_htc_face_tracker(XrFacialTrackingTypeHT CHECK_XR(xrCreateFacialTrackerHTC(id, &create_info, &ft)); return {*inst, ft, facialTrackingType}; } + +xr::pico_face_tracker xr::session::create_pico_face_tracker() +{ + return {*inst, *this}; +} + std::vector xr::session::get_swapchain_formats() const { std::vector formats; diff --git a/client/xr/session.h b/client/xr/session.h index fc86c8c2..bd43147f 100644 --- a/client/xr/session.h +++ b/client/xr/session.h @@ -30,6 +30,7 @@ #include "hand_tracker.h" #include "htc_face_tracker.h" #include "passthrough.h" +#include "pico_face_tracker.h" #include "space.h" namespace xr @@ -52,6 +53,7 @@ public: hand_tracker create_hand_tracker(XrHandEXT hand, XrHandJointSetEXT hand_joint_set = XR_HAND_JOINT_SET_DEFAULT_EXT); fb_face_tracker2 create_fb_face_tracker2(); htc_face_tracker create_htc_face_tracker(XrFacialTrackingTypeHTC); + pico_face_tracker create_pico_face_tracker(); std::vector get_swapchain_formats() const; diff --git a/client/xr/xr.h b/client/xr/xr.h index 2ca95f22..2d3234d2 100644 --- a/client/xr/xr.h +++ b/client/xr/xr.h @@ -26,6 +26,8 @@ #include "swapchain.h" #include "system.h" #include "xr/check.h" +#include "xr/pico_eye_types.h" +#include "xr/pico_eye_types_reflection.h" #include #include @@ -56,6 +58,8 @@ XR_ENUM_STR(XrSessionState); XR_ENUM_STR(XrObjectType); XR_ENUM_STR(XrStructureType); +XR_ENUM_STR(XrTrackingStateCodePICO); + std::string to_string(XrVersion version); } // namespace xr diff --git a/common/wivrn_packets.h b/common/wivrn_packets.h index b31f09ea..2e87294b 100644 --- a/common/wivrn_packets.h +++ b/common/wivrn_packets.h @@ -34,6 +34,7 @@ #include "smp.h" #include "wivrn_serialization_types.h" +#include "xr/pico_eye_types.h" namespace wivrn { @@ -197,6 +198,7 @@ enum face_type : uint8_t none, fb2, htc, + pico, }; struct headset_info_packet @@ -286,6 +288,13 @@ struct tracking bool lip_active; }; std::optional face_htc; + + struct pico_face + { + std::array weights; + bool is_valid; + }; + std::optional face_pico; }; struct trackings diff --git a/common/xr/pico_eye_types.h b/common/xr/pico_eye_types.h new file mode 100644 index 00000000..8e5bc826 --- /dev/null +++ b/common/xr/pico_eye_types.h @@ -0,0 +1,147 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2025 Sapphire + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +// See https://pico.crx.moe/docs/pico-openxr/eye-gaze-interaction and https://pico.crx.moe/docs/pico-openxr/eye-tracking. + +#pragma once + +#include + +#define XR_PICO_EYE_TRACKING_EXTENSION_NAME "XR_PICO_eye_tracking" + +typedef XrFlags64 XrTrackingModeFlagsPICO; + +static const XrTrackingModeFlagsPICO XR_TRACKING_MODE_EYE_BIT_PICO = 0x00000004; +static const XrTrackingModeFlagsPICO XR_TRACKING_MODE_FACE_BIT_PICO = 0x00000008; +static const XrTrackingModeFlagsPICO XR_TRACKING_MODE_FACE_LIPSYNC_PICO = 0x00002000; +static const XrTrackingModeFlagsPICO XR_TRACKING_MODE_FACE_LIPSYNC_BLEND_SHAPES_PICO = 0x00000100; + +typedef enum XrTrackingStateCodePICO +{ + XR_MT_SUCCESS_PICO = 0, + XR_MT_FAILURE_PICO = -1, + XR_MT_MODE_NONE_PICO = -2, + XR_MT_DEVICE_NOT_SUPPORT_PICO = -3, + XR_MT_SERVICE_NEED_START_PICO = -4, + XR_MT_ET_PERMISSION_DENIED_PICO = -5, + XR_MT_FT_PERMISSION_DENIED_PICO = -6, + XR_MT_MIC_PERMISSION_DENIED_PICO = -7, + XR_MT_SYSTEM_DENIED_PICO = -8, + XR_MT_UNKNOWN_ERROR_PICO = -9, +} XrTrackingStateCodePICO; + +typedef enum XrFaceTrackingDataTypePICO +{ + XR_GET_FACE_DATA_DEFAULT_PICO = 0, + XR_GET_FACE_DATA_PICO = 3, + XR_GET_LIP_DATA_PICO = 4, + XR_GET_FACELIP_DATA_PICO = 5, +} XrFaceTrackingDataTypePICO; + +typedef struct XrFaceTrackingDataPICO +{ + XrTime time; + float blendShapeWeight[72]; + float isVideoInputValid[10]; + float laughingProbability; + float emotionProbability[10]; + float reserved[128]; +} XrFaceTrackingDataPICO; + +typedef enum XrBlendShapeIndexPICO +{ + XR_BS_EYELOOKDOWN_L_PICO = 0, + XR_BS_NOSESNEER_L_PICO = 1, + XR_BS_EYELOOKIN_L_PICO = 2, + XR_BS_BROWINNERUP_PICO = 3, + XR_BS_BROWDOWN_R_PICO = 4, + XR_BS_MOUTHCLOSE_PICO = 5, + XR_BS_MOUTHLOWERDOWN_R_PICO = 6, + XR_BS_JAWOPEN_PICO = 7, + XR_BS_MOUTHUPPERUP_R_PICO = 8, + XR_BS_MOUTHSHRUGUPPER_PICO = 9, + XR_BS_MOUTHFUNNEL_PICO = 10, + XR_BS_EYELOOKIN_R_PICO = 11, + XR_BS_EYELOOKDOWN_R_PICO = 12, + XR_BS_NOSESNEER_R_PICO = 13, + XR_BS_MOUTHROLLUPPER_PICO = 14, + XR_BS_JAWRIGHT_PICO = 15, + XR_BS_BROWDOWN_L_PICO = 16, + XR_BS_MOUTHSHRUGLOWER_PICO = 17, + XR_BS_MOUTHROLLLOWER_PICO = 18, + XR_BS_MOUTHSMILE_L_PICO = 19, + XR_BS_MOUTHPRESS_L_PICO = 20, + XR_BS_MOUTHSMILE_R_PICO = 21, + XR_BS_MOUTHPRESS_R_PICO = 22, + XR_BS_MOUTHDIMPLE_R_PICO = 23, + XR_BS_MOUTHLEFT_PICO = 24, + XR_BS_JAWFORWARD_PICO = 25, + XR_BS_EYESQUINT_L_PICO = 26, + XR_BS_MOUTHFROWN_L_PICO = 27, + XR_BS_EYEBLINK_L_PICO = 28, + XR_BS_CHEEKSQUINT_L_PICO = 29, + XR_BS_BROWOUTERUP_L_PICO = 30, + XR_BS_EYELOOKUP_L_PICO = 31, + XR_BS_JAWLEFT_PICO = 32, + XR_BS_MOUTHSTRETCH_L_PICO = 33, + XR_BS_MOUTHPUCKER_PICO = 34, + XR_BS_EYELOOKUP_R_PICO = 35, + XR_BS_BROWOUTERUP_R_PICO = 36, + XR_BS_CHEEKSQUINT_R_PICO = 37, + XR_BS_EYEBLINK_R_PICO = 38, + XR_BS_MOUTHUPPERUP_L_PICO = 39, + XR_BS_MOUTHFROWN_R_PICO = 40, + XR_BS_EYESQUINT_R_PICO = 41, + XR_BS_MOUTHSTRETCH_R_PICO = 42, + XR_BS_CHEEKPUFF_PICO = 43, + XR_BS_EYELOOKOUT_L_PICO = 44, + XR_BS_EYELOOKOUT_R_PICO = 45, + XR_BS_EYEWIDE_R_PICO = 46, + XR_BS_EYEWIDE_L_PICO = 47, + XR_BS_MOUTHRIGHT_PICO = 48, + XR_BS_MOUTHDIMPLE_L_PICO = 49, + XR_BS_MOUTHLOWERDOWN_L_PICO = 50, + XR_BS_TONGUEOUT_PICO = 51, + XR_VISEME_PP_PICO = 52, + XR_VISEME_CH_PICO = 53, + XR_VISEME_O_PICO = 54, + XR_VISEME_OU_PICO = 55, + XR_VISEME_I_BACK_PICO = 56, + XR_VISEME_U_PICO = 57, + XR_VISEME_RR_PICO = 58, + XR_VISEME_XX_PICO = 59, + XR_VISEME_AA_PICO = 60, + XR_VISEME_I_FRONT_PICO = 61, + XR_VISEME_FF_PICO = 62, + XR_VISEME_UW_PICO = 63, + XR_VISEME_TH_PICO = 64, + XR_VISEME_KK_PICO = 65, + XR_VISEME_SS_PICO = 66, + XR_VISEME_E_PICO = 67, + XR_VISEME_DD_PICO = 68, + XR_VISEME_EI_PICO = 69, + XR_VISEME_NN_PICO = 70, + XR_VISEME_SIL_PICO = 71, + XR_BLEND_SHAPE_COUNT_PICO = 72, +} XrBlendShapeIndexPICO; + +typedef XrResult(XRAPI_PTR * PFN_xrStartEyeTrackingPICO)(XrSession session); +typedef XrResult(XRAPI_PTR * PFN_xrStopEyeTrackingPICO)(XrSession session, XrTrackingModeFlagsPICO mode); +typedef XrResult(XRAPI_PTR * PFN_xrSetTrackingModePICO)(XrSession session, XrTrackingModeFlagsPICO flags); +typedef XrResult(XRAPI_PTR * PFN_xrGetFaceTrackingStatePICO)(XrSession session, XrTrackingModeFlagsPICO * mode, XrTrackingStateCodePICO * code); +typedef XrResult(XRAPI_PTR * PFN_xrGetFaceTrackingDataPICO)(XrSession session, XrTime time, XrFaceTrackingDataTypePICO type, XrFaceTrackingDataPICO * data); diff --git a/common/xr/pico_eye_types_reflection.h b/common/xr/pico_eye_types_reflection.h new file mode 100644 index 00000000..3d9995c7 --- /dev/null +++ b/common/xr/pico_eye_types_reflection.h @@ -0,0 +1,31 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2025 Sapphire + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +// See https://pico.crx.moe/docs/pico-openxr/eye-gaze-interaction and https://pico.crx.moe/docs/pico-openxr/eye-tracking. + +#define XR_LIST_ENUM_XrTrackingStateCodePICO(_) \ + _(XR_MT_SUCCESS_PICO, 0) \ + _(XR_MT_FAILURE_PICO, -1) \ + _(XR_MT_MODE_NONE_PICO, -2) \ + _(XR_MT_DEVICE_NOT_SUPPORT_PICO, -3) \ + _(XR_MT_SERVICE_NEED_START_PICO, -4) \ + _(XR_MT_ET_PERMISSION_DENIED_PICO, -5) \ + _(XR_MT_FT_PERMISSION_DENIED_PICO, -6) \ + _(XR_MT_MIC_PERMISSION_DENIED_PICO, -7) \ + _(XR_MT_SYSTEM_DENIED_PICO, -8) \ + _(XR_MT_UNKNOWN_ERROR_PICO, -9) diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index f0dfcc78..e853c146 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -96,6 +96,7 @@ if (WIVRN_BUILD_SERVER) driver/wivrn_eye_tracker.cpp driver/wivrn_fb_face2_tracker.cpp driver/wivrn_htc_face_tracker.cpp + driver/wivrn_pico_face_tracker.cpp driver/wivrn_foveation.cpp driver/pose_list.cpp driver/view_list.cpp diff --git a/server/driver/wivrn_pico_face_tracker.cpp b/server/driver/wivrn_pico_face_tracker.cpp new file mode 100644 index 00000000..8e5cb4ee --- /dev/null +++ b/server/driver/wivrn_pico_face_tracker.cpp @@ -0,0 +1,223 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2024 Guillaume Meunier + * Copyright (C) 2024 Patrick Nicolas + * Copyright (C) 2024 galister + * Copyright (C) 2025 Sapphire + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "wivrn_pico_face_tracker.h" + +#include "wivrn_packets.h" +#include "wivrn_session.h" + +#include "util/u_logging.h" +#include "xr/pico_eye_types.h" +#include "xrt/xrt_defines.h" +#include "xrt/xrt_device.h" +#include "xrt/xrt_results.h" + +#include +#include +#include +#include +#include + +namespace wivrn +{ + +static void wivrn_pico_face_tracker_destroy(xrt_device * xdev); + +static xrt_result_t wivrn_pico_face_tracker_update_inputs(xrt_device * xdev) +{ + static_cast(xdev)->update_inputs(); + return XRT_SUCCESS; +} + +static xrt_result_t wivrn_pico_face_tracker_get_face_tracking(struct xrt_device * xdev, + enum xrt_input_name facial_expression_type, + int64_t at_timestamp_ns, + struct xrt_facial_expression_set * out_value); + +wivrn_pico_face_tracker::wivrn_pico_face_tracker(xrt_device * hmd, + wivrn::wivrn_session & cnx) : + xrt_device{}, cnx(cnx) +{ + xrt_device * base = this; + base->tracking_origin = hmd->tracking_origin; + base->get_face_tracking = wivrn_pico_face_tracker_get_face_tracking; + base->update_inputs = wivrn_pico_face_tracker_update_inputs; + base->destroy = wivrn_pico_face_tracker_destroy; + name = XRT_DEVICE_FB_FACE_TRACKING2; + device_type = XRT_DEVICE_TYPE_FACE_TRACKER; + face_tracking_supported = true; + + // Print name. + strcpy(str, "WiVRn Pico Face Tracker (as FB v2)"); + strcpy(serial, "WiVRn Pico Face Tracker"); + + // Setup input. + face_input.name = XRT_INPUT_FB_FACE_TRACKING2_VISUAL; + face_input.active = true; + inputs = &face_input; + input_count = 1; +} + +void wivrn_pico_face_tracker::update_inputs() +{ + // Empty +} + +void wivrn_pico_face_tracker::update_tracking(const from_headset::tracking & tracking, const clock_offset & offset) +{ + static std::array confidences{1.0, 1.0}; + if (not(tracking.face_pico and tracking.face_pico->is_valid)) + return; + const auto & face = *tracking.face_pico; + + std::array weights{}; + +#define MAP_EXPRESSION(fb, pico) \ + weights[fb] = face.weights[pico]; + + // Map the blendshapes. + MAP_EXPRESSION(XR_FACE_EXPRESSION2_BROW_LOWERER_L_FB, XR_BS_BROWDOWN_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_BROW_LOWERER_R_FB, XR_BS_BROWDOWN_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_CHEEK_PUFF_L_FB, XR_BS_CHEEKPUFF_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_CHEEK_PUFF_R_FB, XR_BS_CHEEKPUFF_PICO); + // XR_FACE_EXPRESSION2_CHEEK_RAISER_L_FB + // XR_FACE_EXPRESSION2_CHEEK_RAISER_R_FB + // XR_FACE_EXPRESSION2_CHEEK_SUCK_L_FB + // XR_FACE_EXPRESSION2_CHEEK_SUCK_R_FB + MAP_EXPRESSION(XR_FACE_EXPRESSION2_CHIN_RAISER_B_FB, XR_BS_MOUTHSHRUGLOWER_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_CHIN_RAISER_T_FB, XR_BS_MOUTHSHRUGUPPER_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_DIMPLER_L_FB, XR_BS_MOUTHDIMPLE_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_DIMPLER_R_FB, XR_BS_MOUTHDIMPLE_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_CLOSED_L_FB, XR_BS_EYEBLINK_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_CLOSED_R_FB, XR_BS_EYEBLINK_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_DOWN_L_FB, XR_BS_EYELOOKDOWN_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_DOWN_R_FB, XR_BS_EYELOOKDOWN_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_LEFT_L_FB, XR_BS_EYELOOKIN_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_LEFT_R_FB, XR_BS_EYELOOKIN_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_RIGHT_L_FB, XR_BS_EYELOOKOUT_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_RIGHT_R_FB, XR_BS_EYELOOKOUT_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_UP_L_FB, XR_BS_EYELOOKUP_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_UP_R_FB, XR_BS_EYELOOKUP_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_INNER_BROW_RAISER_L_FB, XR_BS_BROWINNERUP_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_INNER_BROW_RAISER_R_FB, XR_BS_BROWINNERUP_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_JAW_DROP_FB, XR_BS_JAWOPEN_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_JAW_SIDEWAYS_LEFT_FB, XR_BS_JAWLEFT_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_JAW_SIDEWAYS_RIGHT_FB, XR_BS_JAWRIGHT_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_JAW_THRUST_FB, XR_BS_JAWFORWARD_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LID_TIGHTENER_L_FB, XR_BS_EYESQUINT_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LID_TIGHTENER_R_FB, XR_BS_EYESQUINT_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_CORNER_DEPRESSOR_L_FB, XR_BS_MOUTHFROWN_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_CORNER_DEPRESSOR_R_FB, XR_BS_MOUTHFROWN_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_CORNER_PULLER_L_FB, XR_BS_MOUTHSMILE_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_CORNER_PULLER_R_FB, XR_BS_MOUTHSMILE_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_FUNNELER_LB_FB, XR_BS_MOUTHFUNNEL_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_FUNNELER_LT_FB, XR_BS_MOUTHFUNNEL_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_FUNNELER_RB_FB, XR_BS_MOUTHFUNNEL_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_FUNNELER_RT_FB, XR_BS_MOUTHFUNNEL_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_PRESSOR_L_FB, XR_BS_MOUTHPRESS_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_PRESSOR_R_FB, XR_BS_MOUTHPRESS_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_PUCKER_L_FB, XR_BS_MOUTHPUCKER_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_PUCKER_R_FB, XR_BS_MOUTHPUCKER_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_STRETCHER_L_FB, XR_BS_MOUTHSTRETCH_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_STRETCHER_R_FB, XR_BS_MOUTHSTRETCH_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_SUCK_LB_FB, XR_BS_MOUTHROLLLOWER_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_SUCK_LT_FB, XR_BS_MOUTHROLLLOWER_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_SUCK_RT_FB, XR_BS_MOUTHROLLUPPER_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_SUCK_RB_FB, XR_BS_MOUTHROLLUPPER_PICO); + // XR_FACE_EXPRESSION2_LIP_TIGHTENER_L_FB + // XR_FACE_EXPRESSION2_LIP_TIGHTENER_R_FB + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIPS_TOWARD_FB, XR_BS_MOUTHCLOSE_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LOWER_LIP_DEPRESSOR_L_FB, XR_BS_MOUTHLOWERDOWN_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LOWER_LIP_DEPRESSOR_R_FB, XR_BS_MOUTHLOWERDOWN_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_MOUTH_LEFT_FB, XR_BS_MOUTHLEFT_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_MOUTH_RIGHT_FB, XR_BS_MOUTHRIGHT_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_NOSE_WRINKLER_L_FB, XR_BS_NOSESNEER_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_NOSE_WRINKLER_R_FB, XR_BS_NOSESNEER_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_OUTER_BROW_RAISER_L_FB, XR_BS_BROWOUTERUP_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_OUTER_BROW_RAISER_R_FB, XR_BS_BROWOUTERUP_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_UPPER_LID_RAISER_L_FB, XR_BS_EYEWIDE_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_UPPER_LID_RAISER_R_FB, XR_BS_EYEWIDE_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_UPPER_LIP_RAISER_L_FB, XR_BS_MOUTHUPPERUP_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_UPPER_LIP_RAISER_R_FB, XR_BS_MOUTHUPPERUP_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_TONGUE_OUT_FB, XR_BS_TONGUEOUT_PICO); + // XR_FACE_EXPRESSION2_TONGUE_TIP_INTERDENTAL_FB + // XR_FACE_EXPRESSION2_TONGUE_TIP_ALVEOLAR_FB + // XR_FACE_EXPRESSION2_TONGUE_FRONT_DORSAL_PALATE_FB + // XR_FACE_EXPRESSION2_TONGUE_MID_DORSAL_PALATE_FB + // XR_FACE_EXPRESSION2_TONGUE_BACK_DORSAL_VELAR_FB + // XR_FACE_EXPRESSION2_TONGUE_RETREAT_FB + +#undef MAP_EXPRESSION + + wivrn_fb_face2_data data{ + .weights = weights, + .confidences = confidences, + .is_valid = face.is_valid, + .is_eye_following_blendshapes_valid = face.is_valid, + }; + + if (not face_list.update_tracking(tracking.production_timestamp, tracking.timestamp, data, offset)) + cnx.set_enabled(to_headset::tracking_control::id::face, false); +} + +xrt_result_t wivrn_pico_face_tracker::get_face_tracking(enum xrt_input_name facial_expression_type, int64_t at_timestamp_ns, struct xrt_facial_expression_set * inout_value) +{ + if (facial_expression_type == XRT_INPUT_FB_FACE_TRACKING2_VISUAL) + { + cnx.set_enabled(to_headset::tracking_control::id::face, true); + auto [_, data] = face_list.get_at(at_timestamp_ns); + + inout_value->face_expression_set2_fb.is_valid = data.is_valid; + + if (not data.is_valid) + return XRT_SUCCESS; + + inout_value->face_expression_set2_fb.is_eye_following_blendshapes_valid = data.is_eye_following_blendshapes_valid; + + memcpy(&inout_value->face_expression_set2_fb.weights, data.weights.data(), sizeof(float) * data.weights.size()); + memcpy(&inout_value->face_expression_set2_fb.confidences, data.confidences.data(), sizeof(float) * data.confidences.size()); + + inout_value->face_expression_set2_fb.data_source = XRT_FACE_TRACKING_DATA_SOURCE2_VISUAL_FB; + + return XRT_SUCCESS; + } + + return XRT_ERROR_NOT_IMPLEMENTED; +} + +/* + * + * Functions + * + */ + +static void wivrn_pico_face_tracker_destroy(xrt_device * xdev) +{ +} + +static xrt_result_t wivrn_pico_face_tracker_get_face_tracking(struct xrt_device * xdev, + enum xrt_input_name facial_expression_type, + int64_t at_timestamp_ns, + struct xrt_facial_expression_set * inout_value) +{ + return static_cast(xdev)->get_face_tracking(facial_expression_type, at_timestamp_ns, inout_value); +} +} // namespace wivrn diff --git a/server/driver/wivrn_pico_face_tracker.h b/server/driver/wivrn_pico_face_tracker.h new file mode 100644 index 00000000..b85f74dd --- /dev/null +++ b/server/driver/wivrn_pico_face_tracker.h @@ -0,0 +1,48 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2024 Guillaume Meunier + * Copyright (C) 2024 Patrick Nicolas + * Copyright (C) 2024 galister + * Copyright (C) 2025 Sapphire + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include "wivrn_fb_face2_tracker.h" +#include "wivrn_packets.h" +#include "xrt/xrt_defines.h" +#include "xrt/xrt_device.h" + +namespace wivrn +{ + +class wivrn_session; + +class wivrn_pico_face_tracker : public xrt_device +{ + fb_face2_list face_list; + xrt_input face_input; + + wivrn::wivrn_session & cnx; + +public: + wivrn_pico_face_tracker(xrt_device * hmd, wivrn::wivrn_session & cnx); + + void update_inputs(); + void update_tracking(const from_headset::tracking &, const clock_offset &); + xrt_result_t get_face_tracking(enum xrt_input_name facial_expression_type, int64_t at_timestamp_ns, struct xrt_facial_expression_set * out_value); +}; +} // namespace wivrn diff --git a/server/driver/wivrn_session.cpp b/server/driver/wivrn_session.cpp index e884ff02..3b14df2f 100644 --- a/server/driver/wivrn_session.cpp +++ b/server/driver/wivrn_session.cpp @@ -38,6 +38,7 @@ #include "wivrn_foveation.h" #include "wivrn_htc_face_tracker.h" #include "wivrn_ipc.h" +#include "wivrn_pico_face_tracker.h" #include "wivrn_packets.h" #include "xrt/xrt_device.h" @@ -214,6 +215,12 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr connection static_roles.face = htc_face_tracker.get(); xdevs[xdev_count++] = htc_face_tracker.get(); } + if (get_info().face_tracking == wivrn::from_headset::face_type::pico || is_forced_extension("PICO_eye_tracking")) + { + pico_face_tracker = std::make_unique(&hmd, *this); + static_roles.face = pico_face_tracker.get(); + xdevs[xdev_count++] = pico_face_tracker.get(); + } #if WIVRN_FEATURE_SOLARXR xrt_device * solar_devs[XRT_SYSTEM_MAX_DEVICES]; @@ -411,6 +418,8 @@ void wivrn_session::operator()(const from_headset::tracking & tracking) fb_face2_tracker->update_tracking(tracking, offset); else if (htc_face_tracker) htc_face_tracker->update_tracking(tracking, offset); + else if (pico_face_tracker) + pico_face_tracker->update_tracking(tracking, offset); } void wivrn_session::operator()(from_headset::derived_pose && derived) diff --git a/server/driver/wivrn_session.h b/server/driver/wivrn_session.h index 95584f23..b7004778 100644 --- a/server/driver/wivrn_session.h +++ b/server/driver/wivrn_session.h @@ -44,6 +44,7 @@ namespace wivrn class wivrn_eye_tracker; class wivrn_fb_face2_tracker; class wivrn_htc_face_tracker; +class wivrn_pico_face_tracker; class wivrn_foveation; class wivrn_foveation_renderer; struct audio_device; @@ -109,6 +110,7 @@ class wivrn_session : public xrt_system_devices std::unique_ptr eye_tracker; std::unique_ptr fb_face2_tracker; std::unique_ptr htc_face_tracker; + std::unique_ptr pico_face_tracker; std::unique_ptr foveation; wivrn_comp_target * comp_target; From c2c94a57bb68844c613ec49bb968032634d36da2 Mon Sep 17 00:00:00 2001 From: Sapphire Date: Tue, 13 May 2025 19:45:46 -0500 Subject: [PATCH 26/85] Change face tracking packet members to a variant --- client/scenes/stream_tracking.cpp | 6 +++--- common/wivrn_packets.h | 5 ++--- server/driver/wivrn_fb_face2_tracker.cpp | 12 ++++++------ server/driver/wivrn_htc_face_tracker.cpp | 12 ++++++------ server/driver/wivrn_pico_face_tracker.cpp | 11 ++++++----- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/client/scenes/stream_tracking.cpp b/client/scenes/stream_tracking.cpp index bcc24dd0..79cb5358 100644 --- a/client/scenes/stream_tracking.cpp +++ b/client/scenes/stream_tracking.cpp @@ -336,10 +336,10 @@ void scenes::stream::tracking() case wivrn::from_headset::face_type::none: break; case wivrn::from_headset::face_type::fb2: - application::get_fb_face_tracker2().get_weights(t0 + Δt, packet.face.emplace()); + application::get_fb_face_tracker2().get_weights(t0 + Δt, packet.face.emplace()); break; case wivrn::from_headset::face_type::htc: { - auto & face_htc = packet.face_htc.emplace(); + auto & face_htc = packet.face.emplace(); face_htc.eye_active = false; face_htc.lip_active = false; if (application::get_htc_face_tracking_eye_supported()) @@ -349,7 +349,7 @@ void scenes::stream::tracking() break; } case wivrn::from_headset::face_type::pico: - application::get_pico_face_tracker().get_weights(t0 + Δt, packet.face_pico.emplace()); + application::get_pico_face_tracker().get_weights(t0 + Δt, packet.face.emplace()); break; } } diff --git a/common/wivrn_packets.h b/common/wivrn_packets.h index 2e87294b..9f35c4b1 100644 --- a/common/wivrn_packets.h +++ b/common/wivrn_packets.h @@ -278,7 +278,6 @@ struct tracking bool is_valid; bool is_eye_following_blendshapes_valid; }; - std::optional face; struct htc_face { @@ -287,14 +286,14 @@ struct tracking bool eye_active; bool lip_active; }; - std::optional face_htc; struct pico_face { std::array weights; bool is_valid; }; - std::optional face_pico; + + std::variant face; }; struct trackings diff --git a/server/driver/wivrn_fb_face2_tracker.cpp b/server/driver/wivrn_fb_face2_tracker.cpp index ecf33636..09f912f4 100644 --- a/server/driver/wivrn_fb_face2_tracker.cpp +++ b/server/driver/wivrn_fb_face2_tracker.cpp @@ -80,15 +80,15 @@ void wivrn_fb_face2_tracker::update_inputs() void wivrn_fb_face2_tracker::update_tracking(const from_headset::tracking & tracking, const clock_offset & offset) { - if (not(tracking.face and tracking.face->is_valid)) + auto * face = std::get_if(&tracking.face); + if (not(face and face->is_valid)) return; - const auto & face = *tracking.face; wivrn_fb_face2_data data{ - .weights = face.weights, - .confidences = face.confidences, - .is_valid = face.is_valid, - .is_eye_following_blendshapes_valid = face.is_eye_following_blendshapes_valid, + .weights = face->weights, + .confidences = face->confidences, + .is_valid = face->is_valid, + .is_eye_following_blendshapes_valid = face->is_eye_following_blendshapes_valid, }; if (not face_list.update_tracking(tracking.production_timestamp, tracking.timestamp, data, offset)) diff --git a/server/driver/wivrn_htc_face_tracker.cpp b/server/driver/wivrn_htc_face_tracker.cpp index 9fd92c32..89ad06f6 100644 --- a/server/driver/wivrn_htc_face_tracker.cpp +++ b/server/driver/wivrn_htc_face_tracker.cpp @@ -84,15 +84,15 @@ void wivrn_htc_face_tracker::update_inputs() void wivrn_htc_face_tracker::update_tracking(const from_headset::tracking & tracking, const clock_offset & offset) { - if (not(tracking.face_htc)) + auto * face = std::get_if(&tracking.face); + if (not face) return; - const auto & face = *tracking.face_htc; wivrn_htc_face_data data{ - .eye = face.eye, - .lip = face.lip, - .eye_active = face.eye_active, - .lip_active = face.lip_active}; + .eye = face->eye, + .lip = face->lip, + .eye_active = face->eye_active, + .lip_active = face->lip_active}; if (not face_list.update_tracking(tracking.production_timestamp, tracking.timestamp, data, offset)) cnx.set_enabled(to_headset::tracking_control::id::face, false); diff --git a/server/driver/wivrn_pico_face_tracker.cpp b/server/driver/wivrn_pico_face_tracker.cpp index 8e5cb4ee..75e671dd 100644 --- a/server/driver/wivrn_pico_face_tracker.cpp +++ b/server/driver/wivrn_pico_face_tracker.cpp @@ -84,14 +84,15 @@ void wivrn_pico_face_tracker::update_inputs() void wivrn_pico_face_tracker::update_tracking(const from_headset::tracking & tracking, const clock_offset & offset) { static std::array confidences{1.0, 1.0}; - if (not(tracking.face_pico and tracking.face_pico->is_valid)) + + auto * face = std::get_if(&tracking.face); + if (not(face and face->is_valid)) return; - const auto & face = *tracking.face_pico; std::array weights{}; #define MAP_EXPRESSION(fb, pico) \ - weights[fb] = face.weights[pico]; + weights[fb] = face->weights[pico]; // Map the blendshapes. MAP_EXPRESSION(XR_FACE_EXPRESSION2_BROW_LOWERER_L_FB, XR_BS_BROWDOWN_L_PICO); @@ -170,8 +171,8 @@ void wivrn_pico_face_tracker::update_tracking(const from_headset::tracking & tra wivrn_fb_face2_data data{ .weights = weights, .confidences = confidences, - .is_valid = face.is_valid, - .is_eye_following_blendshapes_valid = face.is_valid, + .is_valid = face->is_valid, + .is_eye_following_blendshapes_valid = face->is_valid, }; if (not face_list.update_tracking(tracking.production_timestamp, tracking.timestamp, data, offset)) From 774702007d2eed1e885ec5de1879ff7f66b34321 Mon Sep 17 00:00:00 2001 From: Sapphire Date: Tue, 13 May 2025 20:33:43 -0500 Subject: [PATCH 27/85] Initialize base members in member initialiser list for server face tracker classes --- server/driver/wivrn_fb_face2_tracker.cpp | 62 ++++++----------------- server/driver/wivrn_fb_face2_tracker.h | 3 +- server/driver/wivrn_htc_face_tracker.cpp | 62 ++++++----------------- server/driver/wivrn_htc_face_tracker.h | 3 +- server/driver/wivrn_pico_face_tracker.cpp | 62 ++++++----------------- server/driver/wivrn_pico_face_tracker.h | 3 +- 6 files changed, 51 insertions(+), 144 deletions(-) diff --git a/server/driver/wivrn_fb_face2_tracker.cpp b/server/driver/wivrn_fb_face2_tracker.cpp index 09f912f4..3b51f28f 100644 --- a/server/driver/wivrn_fb_face2_tracker.cpp +++ b/server/driver/wivrn_fb_face2_tracker.cpp @@ -24,6 +24,7 @@ #include "wivrn_session.h" #include "util/u_logging.h" +#include "utils/method.h" #include "xrt/xrt_defines.h" #include "xrt/xrt_device.h" #include "xrt/xrt_results.h" @@ -36,36 +37,21 @@ namespace wivrn { -static void wivrn_fb_face2_tracker_destroy(xrt_device * xdev); - -static xrt_result_t wivrn_fb_face2_tracker_update_inputs(xrt_device * xdev) -{ - static_cast(xdev)->update_inputs(); - return XRT_SUCCESS; -} - -static xrt_result_t wivrn_fb_face2_tracker_get_face_tracking(struct xrt_device * xdev, - enum xrt_input_name facial_expression_type, - int64_t at_timestamp_ns, - struct xrt_facial_expression_set * out_value); - wivrn_fb_face2_tracker::wivrn_fb_face2_tracker(xrt_device * hmd, wivrn::wivrn_session & cnx) : - xrt_device{}, cnx(cnx) + xrt_device{ + .name = XRT_DEVICE_FB_FACE_TRACKING2, + .device_type = XRT_DEVICE_TYPE_FACE_TRACKER, + .str = "WiVRn FB v2 Face Tracker", + .serial = "WiVRn FB v2 Face Tracker", + .tracking_origin = hmd->tracking_origin, + .face_tracking_supported = true, + .update_inputs = method_pointer<&wivrn_fb_face2_tracker::update_inputs>, + .get_face_tracking = method_pointer<&wivrn_fb_face2_tracker::get_face_tracking>, + .destroy = [](xrt_device *) {}, + }, + cnx(cnx) { - xrt_device * base = this; - base->tracking_origin = hmd->tracking_origin; - base->get_face_tracking = wivrn_fb_face2_tracker_get_face_tracking; - base->update_inputs = wivrn_fb_face2_tracker_update_inputs; - base->destroy = wivrn_fb_face2_tracker_destroy; - name = XRT_DEVICE_FB_FACE_TRACKING2; - device_type = XRT_DEVICE_TYPE_FACE_TRACKER; - face_tracking_supported = true; - - // Print name. - strcpy(str, "WiVRn FB v2 Face Tracker"); - strcpy(serial, "WiVRn FB v2 Face Tracker"); - // Setup input. face_input.name = XRT_INPUT_FB_FACE_TRACKING2_VISUAL; face_input.active = true; @@ -73,9 +59,9 @@ wivrn_fb_face2_tracker::wivrn_fb_face2_tracker(xrt_device * hmd, input_count = 1; } -void wivrn_fb_face2_tracker::update_inputs() +xrt_result_t wivrn_fb_face2_tracker::update_inputs() { - // Empty + return XRT_SUCCESS; } void wivrn_fb_face2_tracker::update_tracking(const from_headset::tracking & tracking, const clock_offset & offset) @@ -119,22 +105,4 @@ xrt_result_t wivrn_fb_face2_tracker::get_face_tracking(enum xrt_input_name facia return XRT_ERROR_NOT_IMPLEMENTED; } - -/* - * - * Functions - * - */ - -static void wivrn_fb_face2_tracker_destroy(xrt_device * xdev) -{ -} - -static xrt_result_t wivrn_fb_face2_tracker_get_face_tracking(struct xrt_device * xdev, - enum xrt_input_name facial_expression_type, - int64_t at_timestamp_ns, - struct xrt_facial_expression_set * inout_value) -{ - return static_cast(xdev)->get_face_tracking(facial_expression_type, at_timestamp_ns, inout_value); -} } // namespace wivrn diff --git a/server/driver/wivrn_fb_face2_tracker.h b/server/driver/wivrn_fb_face2_tracker.h index dd75f97b..02f138c2 100644 --- a/server/driver/wivrn_fb_face2_tracker.h +++ b/server/driver/wivrn_fb_face2_tracker.h @@ -92,9 +92,10 @@ class wivrn_fb_face2_tracker : public xrt_device wivrn::wivrn_session & cnx; public: + using base = xrt_device; wivrn_fb_face2_tracker(xrt_device * hmd, wivrn::wivrn_session & cnx); - void update_inputs(); + xrt_result_t update_inputs(); void update_tracking(const from_headset::tracking &, const clock_offset &); xrt_result_t get_face_tracking(enum xrt_input_name facial_expression_type, int64_t at_timestamp_ns, struct xrt_facial_expression_set * out_value); }; diff --git a/server/driver/wivrn_htc_face_tracker.cpp b/server/driver/wivrn_htc_face_tracker.cpp index 89ad06f6..c5b018f0 100644 --- a/server/driver/wivrn_htc_face_tracker.cpp +++ b/server/driver/wivrn_htc_face_tracker.cpp @@ -24,6 +24,7 @@ #include "wivrn_session.h" #include "util/u_logging.h" +#include "utils/method.h" #include "xrt/xrt_defines.h" #include "xrt/xrt_device.h" #include "xrt/xrt_results.h" @@ -36,36 +37,21 @@ namespace wivrn { -static void wivrn_htc_face_tracker_destroy(xrt_device * xdev); - -static xrt_result_t wivrn_htc_face_tracker_update_inputs(xrt_device * xdev) -{ - static_cast(xdev)->update_inputs(); - return XRT_SUCCESS; -} - -static xrt_result_t wivrn_htc_face_tracker_get_face_tracking(struct xrt_device * xdev, - enum xrt_input_name facial_expression_type, - int64_t at_timestamp_ns, - struct xrt_facial_expression_set * out_value); - wivrn_htc_face_tracker::wivrn_htc_face_tracker(xrt_device * hmd, wivrn::wivrn_session & cnx) : - xrt_device{}, cnx(cnx) + xrt_device{ + .name = XRT_DEVICE_HTC_FACE_TRACKING, + .device_type = XRT_DEVICE_TYPE_FACE_TRACKER, + .str = "WiVRn HTC Face Tracker", + .serial = "WiVRn HTC Face Tracker", + .tracking_origin = hmd->tracking_origin, + .face_tracking_supported = true, + .update_inputs = method_pointer<&wivrn_htc_face_tracker::update_inputs>, + .get_face_tracking = method_pointer<&wivrn_htc_face_tracker::get_face_tracking>, + .destroy = [](xrt_device *) {}, + }, + cnx(cnx) { - xrt_device * base = this; - base->tracking_origin = hmd->tracking_origin; - base->get_face_tracking = wivrn_htc_face_tracker_get_face_tracking; - base->update_inputs = wivrn_htc_face_tracker_update_inputs; - base->destroy = wivrn_htc_face_tracker_destroy; - name = XRT_DEVICE_HTC_FACE_TRACKING; - device_type = XRT_DEVICE_TYPE_FACE_TRACKER; - face_tracking_supported = true; - - // Print name. - strcpy(str, "WiVRn HTC Face Tracker"); - strcpy(serial, "WiVRn HTC Face Tracker"); - // Setup input. inputs_array[0].name = XRT_INPUT_HTC_EYE_FACE_TRACKING; inputs_array[0].active = true; @@ -77,9 +63,9 @@ wivrn_htc_face_tracker::wivrn_htc_face_tracker(xrt_device * hmd, input_count = inputs_array.size(); } -void wivrn_htc_face_tracker::update_inputs() +xrt_result_t wivrn_htc_face_tracker::update_inputs() { - // Empty + return XRT_SUCCESS; } void wivrn_htc_face_tracker::update_tracking(const from_headset::tracking & tracking, const clock_offset & offset) @@ -133,22 +119,4 @@ xrt_result_t wivrn_htc_face_tracker::get_face_tracking(enum xrt_input_name facia return XRT_ERROR_NOT_IMPLEMENTED; } - -/* - * - * Functions - * - */ - -static void wivrn_htc_face_tracker_destroy(xrt_device * xdev) -{ -} - -static xrt_result_t wivrn_htc_face_tracker_get_face_tracking(struct xrt_device * xdev, - enum xrt_input_name facial_expression_type, - int64_t at_timestamp_ns, - struct xrt_facial_expression_set * inout_value) -{ - return static_cast(xdev)->get_face_tracking(facial_expression_type, at_timestamp_ns, inout_value); -} } // namespace wivrn diff --git a/server/driver/wivrn_htc_face_tracker.h b/server/driver/wivrn_htc_face_tracker.h index 84c6de23..37659d70 100644 --- a/server/driver/wivrn_htc_face_tracker.h +++ b/server/driver/wivrn_htc_face_tracker.h @@ -105,9 +105,10 @@ class wivrn_htc_face_tracker : public xrt_device wivrn::wivrn_session & cnx; public: + using base = xrt_device; wivrn_htc_face_tracker(xrt_device * hmd, wivrn::wivrn_session & cnx); - void update_inputs(); + xrt_result_t update_inputs(); void update_tracking(const from_headset::tracking &, const clock_offset &); xrt_result_t get_face_tracking(enum xrt_input_name facial_expression_type, int64_t at_timestamp_ns, struct xrt_facial_expression_set * out_value); }; diff --git a/server/driver/wivrn_pico_face_tracker.cpp b/server/driver/wivrn_pico_face_tracker.cpp index 75e671dd..b527cb64 100644 --- a/server/driver/wivrn_pico_face_tracker.cpp +++ b/server/driver/wivrn_pico_face_tracker.cpp @@ -25,6 +25,7 @@ #include "wivrn_session.h" #include "util/u_logging.h" +#include "utils/method.h" #include "xr/pico_eye_types.h" #include "xrt/xrt_defines.h" #include "xrt/xrt_device.h" @@ -39,36 +40,21 @@ namespace wivrn { -static void wivrn_pico_face_tracker_destroy(xrt_device * xdev); - -static xrt_result_t wivrn_pico_face_tracker_update_inputs(xrt_device * xdev) -{ - static_cast(xdev)->update_inputs(); - return XRT_SUCCESS; -} - -static xrt_result_t wivrn_pico_face_tracker_get_face_tracking(struct xrt_device * xdev, - enum xrt_input_name facial_expression_type, - int64_t at_timestamp_ns, - struct xrt_facial_expression_set * out_value); - wivrn_pico_face_tracker::wivrn_pico_face_tracker(xrt_device * hmd, wivrn::wivrn_session & cnx) : - xrt_device{}, cnx(cnx) + xrt_device{ + .name = XRT_DEVICE_FB_FACE_TRACKING2, + .device_type = XRT_DEVICE_TYPE_FACE_TRACKER, + .str = "WiVRn Pico Face Tracker (as FB v2)", + .serial = "WiVRn Pico Face Tracker", + .tracking_origin = hmd->tracking_origin, + .face_tracking_supported = true, + .update_inputs = method_pointer<&wivrn_pico_face_tracker::update_inputs>, + .get_face_tracking = method_pointer<&wivrn_pico_face_tracker::get_face_tracking>, + .destroy = [](xrt_device *) {}, + }, + cnx(cnx) { - xrt_device * base = this; - base->tracking_origin = hmd->tracking_origin; - base->get_face_tracking = wivrn_pico_face_tracker_get_face_tracking; - base->update_inputs = wivrn_pico_face_tracker_update_inputs; - base->destroy = wivrn_pico_face_tracker_destroy; - name = XRT_DEVICE_FB_FACE_TRACKING2; - device_type = XRT_DEVICE_TYPE_FACE_TRACKER; - face_tracking_supported = true; - - // Print name. - strcpy(str, "WiVRn Pico Face Tracker (as FB v2)"); - strcpy(serial, "WiVRn Pico Face Tracker"); - // Setup input. face_input.name = XRT_INPUT_FB_FACE_TRACKING2_VISUAL; face_input.active = true; @@ -76,9 +62,9 @@ wivrn_pico_face_tracker::wivrn_pico_face_tracker(xrt_device * hmd, input_count = 1; } -void wivrn_pico_face_tracker::update_inputs() +xrt_result_t wivrn_pico_face_tracker::update_inputs() { - // Empty + return XRT_SUCCESS; } void wivrn_pico_face_tracker::update_tracking(const from_headset::tracking & tracking, const clock_offset & offset) @@ -203,22 +189,4 @@ xrt_result_t wivrn_pico_face_tracker::get_face_tracking(enum xrt_input_name faci return XRT_ERROR_NOT_IMPLEMENTED; } - -/* - * - * Functions - * - */ - -static void wivrn_pico_face_tracker_destroy(xrt_device * xdev) -{ -} - -static xrt_result_t wivrn_pico_face_tracker_get_face_tracking(struct xrt_device * xdev, - enum xrt_input_name facial_expression_type, - int64_t at_timestamp_ns, - struct xrt_facial_expression_set * inout_value) -{ - return static_cast(xdev)->get_face_tracking(facial_expression_type, at_timestamp_ns, inout_value); -} } // namespace wivrn diff --git a/server/driver/wivrn_pico_face_tracker.h b/server/driver/wivrn_pico_face_tracker.h index b85f74dd..85b5b86f 100644 --- a/server/driver/wivrn_pico_face_tracker.h +++ b/server/driver/wivrn_pico_face_tracker.h @@ -39,9 +39,10 @@ class wivrn_pico_face_tracker : public xrt_device wivrn::wivrn_session & cnx; public: + using base = xrt_device; wivrn_pico_face_tracker(xrt_device * hmd, wivrn::wivrn_session & cnx); - void update_inputs(); + xrt_result_t update_inputs(); void update_tracking(const from_headset::tracking &, const clock_offset &); xrt_result_t get_face_tracking(enum xrt_input_name facial_expression_type, int64_t at_timestamp_ns, struct xrt_facial_expression_set * out_value); }; From 512eb5a45b0e5381f14992d1d469d869a933dd58 Mon Sep 17 00:00:00 2001 From: Sapphire Date: Thu, 15 May 2025 12:38:28 -0500 Subject: [PATCH 28/85] Improve Pico face tracking logs --- client/xr/pico_face_tracker.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/client/xr/pico_face_tracker.cpp b/client/xr/pico_face_tracker.cpp index 2b0b43d6..aab0f2ca 100644 --- a/client/xr/pico_face_tracker.cpp +++ b/client/xr/pico_face_tracker.cpp @@ -40,7 +40,7 @@ xr::pico_face_tracker::pico_face_tracker(instance & inst, session & s_) : } xr::pico_face_tracker::~pico_face_tracker() { - if (auto res = xrStopEyeTrackingPICO(s, XR_TRACKING_MODE_FACE_BIT_PICO); res != XR_SUCCESS) + if (auto res = xrStopEyeTrackingPICO(s, XR_TRACKING_MODE_FACE_BIT_PICO); !XR_SUCCEEDED(res)) spdlog::warn("Failed to deactivate face tracking: {}", xr::to_string(res)); } @@ -56,10 +56,11 @@ void xr::pico_face_tracker::get_weights(XrTime time, wivrn::from_headset::tracki XrTrackingModeFlagsPICO mode; XrTrackingStateCodePICO code; - if (xrGetFaceTrackingStatePICO(s, &mode, &code) == XR_SUCCESS) + auto state_res = xrGetFaceTrackingStatePICO(s, &mode, &code); + if (XR_SUCCEEDED(state_res)) spdlog::warn("Unable to get face tracking data: xrGetFaceTrackingDataPICO returned {}, tracking mode state {}, flags {}", xr::to_string(res), xr::to_string(code), mode); else - spdlog::warn("Unable to get face tracking data: xrGetFaceTrackingDataPICO returned {}", xr::to_string(res)); + spdlog::warn("Unable to get face tracking data: xrGetFaceTrackingDataPICO returned {}, unable to get face tracking state: {}", xr::to_string(res), xr::to_string(state_res)); out_expressions.is_valid = false; return; } From 5bf4da0c5076c3fd9d4357b19d7d54137e1e46f2 Mon Sep 17 00:00:00 2001 From: Sapphire Date: Thu, 15 May 2025 14:16:16 -0500 Subject: [PATCH 29/85] Fix Pico model detection --- client/configuration.cpp | 1 + client/hardware.cpp | 22 ++++++++++++++++++---- client/hardware.h | 1 + 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/client/configuration.cpp b/client/configuration.cpp index be7bab39..cf52494d 100644 --- a/client/configuration.cpp +++ b/client/configuration.cpp @@ -112,6 +112,7 @@ bool configuration::check_feature(feature f) const return false; break; case model::pico_4_pro: + case model::pico_4_enterprise: if (not application::get_pico_face_tracking_supported()) return false; break; diff --git a/client/hardware.cpp b/client/hardware.cpp index 6a4362ab..0e7cccb0 100644 --- a/client/hardware.cpp +++ b/client/hardware.cpp @@ -71,16 +71,25 @@ static model guess_model_() if (manufacturer == "Pico") { - if (model == "Pico Neo 3") + const auto pico_model = get_property("pxr.vendorhw.product.model"); + spdlog::info(" pxr.vendorhw.product.model = \"{}\":", pico_model); + + if (pico_model == "Pico Neo 3") return model::pico_neo_3; - if (model == "A9210") + if (pico_model == "PICO 4") + return model::pico_4; + + if (pico_model == "PICO 4 Ultra") return model::pico_4s; - if (model == "A8110") + if (pico_model == "PICO 4 Pro") return model::pico_4_pro; - spdlog::info("manufacturer={}, model={}, device={} assuming Pico 4", manufacturer, model, device); + if (pico_model == "PICO 4 Enterprise") + return model::pico_4_enterprise; + + spdlog::info("manufacturer={}, model={}, device={}, pico_model={} assuming Pico 4", manufacturer, model, device, pico_model); return model::pico_4; } if (manufacturer == "HTC") @@ -149,6 +158,7 @@ XrViewConfigurationView override_view(XrViewConfigurationView view, model m) case model::pico_4: case model::pico_4s: case model::pico_4_pro: + case model::pico_4_enterprise: return scale_view(view, 2160); case model::htc_vive_focus_3: case model::htc_vive_focus_vision: @@ -177,6 +187,7 @@ bool need_srgb_conversion(model m) case model::pico_4: case model::pico_4s: case model::pico_4_pro: + case model::pico_4_enterprise: case model::htc_vive_focus_3: case model::htc_vive_focus_vision: case model::htc_vive_xr_elite: @@ -207,6 +218,7 @@ const char * permission_name(feature f) case model::pico_4: case model::pico_4s: case model::pico_4_pro: + case model::pico_4_enterprise: return "com.picovr.permission.EYE_TRACKING"; case model::htc_vive_focus_3: case model::htc_vive_focus_vision: @@ -229,6 +241,7 @@ const char * permission_name(feature f) case model::pico_4: case model::pico_4s: case model::pico_4_pro: + case model::pico_4_enterprise: return "com.picovr.permission.FACE_TRACKING"; case model::htc_vive_focus_3: case model::htc_vive_focus_vision: @@ -266,6 +279,7 @@ std::string controller_name() case model::pico_4: case model::pico_4s: // TODO: split when we have the pico-4s 3d model case model::pico_4_pro: + case model::pico_4_enterprise: return "pico-4"; case model::htc_vive_focus_3: case model::htc_vive_focus_vision: diff --git a/client/hardware.h b/client/hardware.h index f3daf059..608aa644 100644 --- a/client/hardware.h +++ b/client/hardware.h @@ -36,6 +36,7 @@ enum class model pico_4, pico_4s, pico_4_pro, + pico_4_enterprise, htc_vive_focus_3, htc_vive_xr_elite, htc_vive_focus_vision, From f7b77d21b832de4facc43b60db7213762921da4f Mon Sep 17 00:00:00 2001 From: Sapphire Date: Wed, 21 May 2025 02:50:43 -0500 Subject: [PATCH 30/85] Try to initialize face tracking again on xrGetFaceTrackingDataPICO failure --- client/xr/pico_face_tracker.cpp | 13 +++++++++++++ common/xr/pico_eye_types.h | 18 +++++++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/client/xr/pico_face_tracker.cpp b/client/xr/pico_face_tracker.cpp index aab0f2ca..e0fa91a3 100644 --- a/client/xr/pico_face_tracker.cpp +++ b/client/xr/pico_face_tracker.cpp @@ -22,6 +22,7 @@ #include "spdlog/spdlog.h" #include "wivrn_packets.h" #include "xr/instance.h" +#include "xr/pico_eye_types.h" #include "xr/session.h" #include "xr/xr.h" #include @@ -61,6 +62,18 @@ void xr::pico_face_tracker::get_weights(XrTime time, wivrn::from_headset::tracki spdlog::warn("Unable to get face tracking data: xrGetFaceTrackingDataPICO returned {}, tracking mode state {}, flags {}", xr::to_string(res), xr::to_string(code), mode); else spdlog::warn("Unable to get face tracking data: xrGetFaceTrackingDataPICO returned {}, unable to get face tracking state: {}", xr::to_string(res), xr::to_string(state_res)); + + if (auto res = xrStartEyeTrackingPICO(s); !XR_SUCCEEDED(res)) + { + spdlog::warn("Failed to start eye tracking: {}", xr::to_string(res)); + goto exit; + } + if (auto res = xrSetTrackingModePICO(s, XR_TRACKING_MODE_FACE_BIT_PICO); !XR_SUCCEEDED(res)) + { + spdlog::warn("Failed to set tracking mode: {}", xr::to_string(res)); + } + +exit: out_expressions.is_valid = false; return; } diff --git a/common/xr/pico_eye_types.h b/common/xr/pico_eye_types.h index 8e5bc826..94773d41 100644 --- a/common/xr/pico_eye_types.h +++ b/common/xr/pico_eye_types.h @@ -33,16 +33,16 @@ static const XrTrackingModeFlagsPICO XR_TRACKING_MODE_FACE_LIPSYNC_BLEND_SHAPES_ typedef enum XrTrackingStateCodePICO { - XR_MT_SUCCESS_PICO = 0, - XR_MT_FAILURE_PICO = -1, - XR_MT_MODE_NONE_PICO = -2, - XR_MT_DEVICE_NOT_SUPPORT_PICO = -3, - XR_MT_SERVICE_NEED_START_PICO = -4, - XR_MT_ET_PERMISSION_DENIED_PICO = -5, - XR_MT_FT_PERMISSION_DENIED_PICO = -6, + XR_MT_SUCCESS_PICO = 0, + XR_MT_FAILURE_PICO = -1, + XR_MT_MODE_NONE_PICO = -2, + XR_MT_DEVICE_NOT_SUPPORT_PICO = -3, + XR_MT_SERVICE_NEED_START_PICO = -4, + XR_MT_ET_PERMISSION_DENIED_PICO = -5, + XR_MT_FT_PERMISSION_DENIED_PICO = -6, XR_MT_MIC_PERMISSION_DENIED_PICO = -7, - XR_MT_SYSTEM_DENIED_PICO = -8, - XR_MT_UNKNOWN_ERROR_PICO = -9, + XR_MT_SYSTEM_DENIED_PICO = -8, + XR_MT_UNKNOWN_ERROR_PICO = -9, } XrTrackingStateCodePICO; typedef enum XrFaceTrackingDataTypePICO From cd72cf68b05a47b2ba4f47e01f855d4edbb9030f Mon Sep 17 00:00:00 2001 From: Sapphire Date: Thu, 22 May 2025 16:37:00 -0500 Subject: [PATCH 31/85] Add debug log when receiving pico face tracking info --- client/xr/pico_face_tracker.cpp | 2 +- client/xr/xr.cpp | 27 -------- client/xr/xr.h | 38 +----------- common/xr/pico_eye_types_reflection.h | 75 +++++++++++++++++++++++ common/xr/to_string.h | 62 +++++++++++++++++++ server/driver/wivrn_pico_face_tracker.cpp | 9 +++ 6 files changed, 148 insertions(+), 65 deletions(-) delete mode 100644 client/xr/xr.cpp create mode 100644 common/xr/to_string.h diff --git a/client/xr/pico_face_tracker.cpp b/client/xr/pico_face_tracker.cpp index e0fa91a3..43eb6875 100644 --- a/client/xr/pico_face_tracker.cpp +++ b/client/xr/pico_face_tracker.cpp @@ -73,7 +73,7 @@ void xr::pico_face_tracker::get_weights(XrTime time, wivrn::from_headset::tracki spdlog::warn("Failed to set tracking mode: {}", xr::to_string(res)); } -exit: + exit: out_expressions.is_valid = false; return; } diff --git a/client/xr/xr.cpp b/client/xr/xr.cpp deleted file mode 100644 index fa4133f5..00000000 --- a/client/xr/xr.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * WiVRn VR streaming - * Copyright (C) 2022 Guillaume Meunier - * Copyright (C) 2022 Patrick Nicolas - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "xr.h" - -#include "spdlog/fmt/fmt.h" - -std::string xr::to_string(XrVersion version) -{ - return fmt::format("{}.{}.{}", XR_VERSION_MAJOR(version), XR_VERSION_MINOR(version), XR_VERSION_PATCH(version)); -} diff --git a/client/xr/xr.h b/client/xr/xr.h index 2d3234d2..314c6b5f 100644 --- a/client/xr/xr.h +++ b/client/xr/xr.h @@ -26,40 +26,4 @@ #include "swapchain.h" #include "system.h" #include "xr/check.h" -#include "xr/pico_eye_types.h" -#include "xr/pico_eye_types_reflection.h" - -#include -#include -#include - -namespace xr -{ -#define XR_ENUM_CASE_STR(name, val) \ - case name: \ - return #name; -#define XR_ENUM_STR(enumType) \ - constexpr const char * to_string(enumType e) \ - { \ - switch (e) \ - { \ - XR_LIST_ENUM_##enumType(XR_ENUM_CASE_STR) default : return "Unknown"; \ - } \ - } - -XR_ENUM_STR(XrResult); -XR_ENUM_STR(XrFormFactor); -XR_ENUM_STR(XrViewConfigurationType); -XR_ENUM_STR(XrEnvironmentBlendMode); -XR_ENUM_STR(XrReferenceSpaceType); -XR_ENUM_STR(XrActionType); -XR_ENUM_STR(XrEyeVisibility); -XR_ENUM_STR(XrSessionState); -XR_ENUM_STR(XrObjectType); -XR_ENUM_STR(XrStructureType); - -XR_ENUM_STR(XrTrackingStateCodePICO); - -std::string to_string(XrVersion version); - -} // namespace xr +#include "xr/to_string.h" \ No newline at end of file diff --git a/common/xr/pico_eye_types_reflection.h b/common/xr/pico_eye_types_reflection.h index 3d9995c7..3a2e6fea 100644 --- a/common/xr/pico_eye_types_reflection.h +++ b/common/xr/pico_eye_types_reflection.h @@ -29,3 +29,78 @@ _(XR_MT_MIC_PERMISSION_DENIED_PICO, -7) \ _(XR_MT_SYSTEM_DENIED_PICO, -8) \ _(XR_MT_UNKNOWN_ERROR_PICO, -9) + +#define XR_LIST_ENUM_XrBlendShapeIndexPICO(_) \ + _(XR_BS_EYELOOKDOWN_L_PICO, 0) \ + _(XR_BS_NOSESNEER_L_PICO, 1) \ + _(XR_BS_EYELOOKIN_L_PICO, 2) \ + _(XR_BS_BROWINNERUP_PICO, 3) \ + _(XR_BS_BROWDOWN_R_PICO, 4) \ + _(XR_BS_MOUTHCLOSE_PICO, 5) \ + _(XR_BS_MOUTHLOWERDOWN_R_PICO, 6) \ + _(XR_BS_JAWOPEN_PICO, 7) \ + _(XR_BS_MOUTHUPPERUP_R_PICO, 8) \ + _(XR_BS_MOUTHSHRUGUPPER_PICO, 9) \ + _(XR_BS_MOUTHFUNNEL_PICO, 10) \ + _(XR_BS_EYELOOKIN_R_PICO, 11) \ + _(XR_BS_EYELOOKDOWN_R_PICO, 12) \ + _(XR_BS_NOSESNEER_R_PICO, 13) \ + _(XR_BS_MOUTHROLLUPPER_PICO, 14) \ + _(XR_BS_JAWRIGHT_PICO, 15) \ + _(XR_BS_BROWDOWN_L_PICO, 16) \ + _(XR_BS_MOUTHSHRUGLOWER_PICO, 17) \ + _(XR_BS_MOUTHROLLLOWER_PICO, 18) \ + _(XR_BS_MOUTHSMILE_L_PICO, 19) \ + _(XR_BS_MOUTHPRESS_L_PICO, 20) \ + _(XR_BS_MOUTHSMILE_R_PICO, 21) \ + _(XR_BS_MOUTHPRESS_R_PICO, 22) \ + _(XR_BS_MOUTHDIMPLE_R_PICO, 23) \ + _(XR_BS_MOUTHLEFT_PICO, 24) \ + _(XR_BS_JAWFORWARD_PICO, 25) \ + _(XR_BS_EYESQUINT_L_PICO, 26) \ + _(XR_BS_MOUTHFROWN_L_PICO, 27) \ + _(XR_BS_EYEBLINK_L_PICO, 28) \ + _(XR_BS_CHEEKSQUINT_L_PICO, 29) \ + _(XR_BS_BROWOUTERUP_L_PICO, 30) \ + _(XR_BS_EYELOOKUP_L_PICO, 31) \ + _(XR_BS_JAWLEFT_PICO, 32) \ + _(XR_BS_MOUTHSTRETCH_L_PICO, 33) \ + _(XR_BS_MOUTHPUCKER_PICO, 34) \ + _(XR_BS_EYELOOKUP_R_PICO, 35) \ + _(XR_BS_BROWOUTERUP_R_PICO, 36) \ + _(XR_BS_CHEEKSQUINT_R_PICO, 37) \ + _(XR_BS_EYEBLINK_R_PICO, 38) \ + _(XR_BS_MOUTHUPPERUP_L_PICO, 39) \ + _(XR_BS_MOUTHFROWN_R_PICO, 40) \ + _(XR_BS_EYESQUINT_R_PICO, 41) \ + _(XR_BS_MOUTHSTRETCH_R_PICO, 42) \ + _(XR_BS_CHEEKPUFF_PICO, 43) \ + _(XR_BS_EYELOOKOUT_L_PICO, 44) \ + _(XR_BS_EYELOOKOUT_R_PICO, 45) \ + _(XR_BS_EYEWIDE_R_PICO, 46) \ + _(XR_BS_EYEWIDE_L_PICO, 47) \ + _(XR_BS_MOUTHRIGHT_PICO, 48) \ + _(XR_BS_MOUTHDIMPLE_L_PICO, 49) \ + _(XR_BS_MOUTHLOWERDOWN_L_PICO, 50) \ + _(XR_BS_TONGUEOUT_PICO, 51) \ + _(XR_VISEME_PP_PICO, 52) \ + _(XR_VISEME_CH_PICO, 53) \ + _(XR_VISEME_O_PICO, 54) \ + _(XR_VISEME_OU_PICO, 55) \ + _(XR_VISEME_I_BACK_PICO, 56) \ + _(XR_VISEME_U_PICO, 57) \ + _(XR_VISEME_RR_PICO, 58) \ + _(XR_VISEME_XX_PICO, 59) \ + _(XR_VISEME_AA_PICO, 60) \ + _(XR_VISEME_I_FRONT_PICO, 61) \ + _(XR_VISEME_FF_PICO, 62) \ + _(XR_VISEME_UW_PICO, 63) \ + _(XR_VISEME_TH_PICO, 64) \ + _(XR_VISEME_KK_PICO, 65) \ + _(XR_VISEME_SS_PICO, 66) \ + _(XR_VISEME_E_PICO, 67) \ + _(XR_VISEME_DD_PICO, 68) \ + _(XR_VISEME_EI_PICO, 69) \ + _(XR_VISEME_NN_PICO, 70) \ + _(XR_VISEME_SIL_PICO, 71) \ + _(XR_BLEND_SHAPE_COUNT_PICO, 72) diff --git a/common/xr/to_string.h b/common/xr/to_string.h new file mode 100644 index 00000000..4ad2a89d --- /dev/null +++ b/common/xr/to_string.h @@ -0,0 +1,62 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2022 Guillaume Meunier + * Copyright (C) 2022 Patrick Nicolas + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include "xr/pico_eye_types.h" +#include "xr/pico_eye_types_reflection.h" + +#include +#include +#include + +namespace xr +{ +#define XR_ENUM_CASE_STR(name, val) \ + case name: \ + return #name; +#define XR_ENUM_STR(enumType) \ + constexpr const char * to_string(enumType e) \ + { \ + switch (e) \ + { \ + XR_LIST_ENUM_##enumType(XR_ENUM_CASE_STR) default : return "Unknown"; \ + } \ + } + +XR_ENUM_STR(XrResult); +XR_ENUM_STR(XrFormFactor); +XR_ENUM_STR(XrViewConfigurationType); +XR_ENUM_STR(XrEnvironmentBlendMode); +XR_ENUM_STR(XrReferenceSpaceType); +XR_ENUM_STR(XrActionType); +XR_ENUM_STR(XrEyeVisibility); +XR_ENUM_STR(XrSessionState); +XR_ENUM_STR(XrObjectType); +XR_ENUM_STR(XrStructureType); + +XR_ENUM_STR(XrTrackingStateCodePICO); +XR_ENUM_STR(XrBlendShapeIndexPICO); + +inline std::string to_string(XrVersion version) +{ + return std::format("{}.{}.{}", XR_VERSION_MAJOR(version), XR_VERSION_MINOR(version), XR_VERSION_PATCH(version)); +} + +} // namespace xr diff --git a/server/driver/wivrn_pico_face_tracker.cpp b/server/driver/wivrn_pico_face_tracker.cpp index b527cb64..14e2bdfb 100644 --- a/server/driver/wivrn_pico_face_tracker.cpp +++ b/server/driver/wivrn_pico_face_tracker.cpp @@ -27,6 +27,8 @@ #include "util/u_logging.h" #include "utils/method.h" #include "xr/pico_eye_types.h" +#include "xr/pico_eye_types_reflection.h" +#include "xr/to_string.h" #include "xrt/xrt_defines.h" #include "xrt/xrt_device.h" #include "xrt/xrt_results.h" @@ -75,6 +77,13 @@ void wivrn_pico_face_tracker::update_tracking(const from_headset::tracking & tra if (not(face and face->is_valid)) return; + // for debugging purposes + U_LOG_D("pico face tracking blendshapes:"); + for (auto i = 0; i <= XR_BS_TONGUEOUT_PICO; i++) + { + U_LOG_D(" %s: %f", xr::to_string(static_cast(i)), face->weights[i]); + } + std::array weights{}; #define MAP_EXPRESSION(fb, pico) \ From b24c6e5ea1c4ab8c6b615bd5dd9503cb0992dbd7 Mon Sep 17 00:00:00 2001 From: Sapphire Date: Sat, 24 May 2025 17:21:07 -0500 Subject: [PATCH 32/85] Move pico->fb2 mapping to client --- client/scenes/lobby_gui.cpp | 11 +- client/scenes/stream_tracking.cpp | 2 +- client/xr/pico_face_tracker.cpp | 96 ++++++++++- client/xr/pico_face_tracker.h | 2 +- common/wivrn_packets.h | 8 +- server/CMakeLists.txt | 1 - server/driver/wivrn_pico_face_tracker.cpp | 201 ---------------------- server/driver/wivrn_pico_face_tracker.h | 49 ------ server/driver/wivrn_session.cpp | 15 +- server/driver/wivrn_session.h | 2 - 10 files changed, 107 insertions(+), 280 deletions(-) delete mode 100644 server/driver/wivrn_pico_face_tracker.cpp delete mode 100644 server/driver/wivrn_pico_face_tracker.h diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index c8bf6fd8..191a59ea 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -1344,7 +1344,12 @@ static const char * get_face_icon(XrTime predicted_display_time) { static const auto w = face_weights(); wivrn::from_headset::tracking::fb_face2 expression; - application::get_fb_face_tracker2().get_weights(predicted_display_time, expression); + if (application::get_fb_face_tracking2_supported()) + application::get_fb_face_tracker2().get_weights(predicted_display_time, expression); + else if (application::get_pico_face_tracking_supported()) + application::get_pico_face_tracker().get_weights(predicted_display_time, expression); + else + __builtin_unreachable(); if (not expression.is_valid) return ICON_FA_FACE_MEH; @@ -1408,7 +1413,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time) }); } - if (application::get_fb_face_tracking2_supported()) + if (application::get_fb_face_tracking2_supported() or application::get_pico_face_tracking_supported()) { items.push_back({ .f = feature::face_tracking, @@ -1419,7 +1424,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time) }); } - if (application::get_htc_face_tracking_eye_supported() or application::get_htc_face_tracking_lip_supported() or application::get_pico_face_tracking_supported()) + if (application::get_htc_face_tracking_eye_supported() or application::get_htc_face_tracking_lip_supported()) { items.push_back({ .f = feature::face_tracking, diff --git a/client/scenes/stream_tracking.cpp b/client/scenes/stream_tracking.cpp index 79cb5358..cdc9f3b8 100644 --- a/client/scenes/stream_tracking.cpp +++ b/client/scenes/stream_tracking.cpp @@ -349,7 +349,7 @@ void scenes::stream::tracking() break; } case wivrn::from_headset::face_type::pico: - application::get_pico_face_tracker().get_weights(t0 + Δt, packet.face.emplace()); + application::get_pico_face_tracker().get_weights(t0 + Δt, packet.face.emplace()); break; } } diff --git a/client/xr/pico_face_tracker.cpp b/client/xr/pico_face_tracker.cpp index 43eb6875..8243735a 100644 --- a/client/xr/pico_face_tracker.cpp +++ b/client/xr/pico_face_tracker.cpp @@ -24,7 +24,8 @@ #include "xr/instance.h" #include "xr/pico_eye_types.h" #include "xr/session.h" -#include "xr/xr.h" +#include "xr/to_string.h" +#include #include xr::pico_face_tracker::pico_face_tracker(instance & inst, session & s_) : @@ -45,7 +46,7 @@ xr::pico_face_tracker::~pico_face_tracker() spdlog::warn("Failed to deactivate face tracking: {}", xr::to_string(res)); } -void xr::pico_face_tracker::get_weights(XrTime time, wivrn::from_headset::tracking::pico_face & out_expressions) +void xr::pico_face_tracker::get_weights(XrTime time, wivrn::from_headset::tracking::fb_face2 & out_expressions) { if (!xrGetFaceTrackingDataPICO) return; @@ -75,9 +76,96 @@ void xr::pico_face_tracker::get_weights(XrTime time, wivrn::from_headset::tracki exit: out_expressions.is_valid = false; + out_expressions.is_eye_following_blendshapes_valid = false; return; } - std::copy_n(face_tracking.blendShapeWeight, std::size(face_tracking.blendShapeWeight), out_expressions.weights.data()); - out_expressions.is_valid = face_tracking.time != 0; + if (face_tracking.time == 0) + { + out_expressions.is_valid = false; + out_expressions.is_eye_following_blendshapes_valid = false; + return; + } + +#define MAP_EXPRESSION(fb, pico) \ + out_expressions.weights[fb] = face_tracking.blendShapeWeight[pico]; + + // Map the blendshapes. + out_expressions.weights.fill(0.f); + out_expressions.confidences.fill(1.f); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_BROW_LOWERER_L_FB, XR_BS_BROWDOWN_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_BROW_LOWERER_R_FB, XR_BS_BROWDOWN_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_CHEEK_PUFF_L_FB, XR_BS_CHEEKPUFF_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_CHEEK_PUFF_R_FB, XR_BS_CHEEKPUFF_PICO); + // XR_FACE_EXPRESSION2_CHEEK_RAISER_L_FB + // XR_FACE_EXPRESSION2_CHEEK_RAISER_R_FB + // XR_FACE_EXPRESSION2_CHEEK_SUCK_L_FB + // XR_FACE_EXPRESSION2_CHEEK_SUCK_R_FB + MAP_EXPRESSION(XR_FACE_EXPRESSION2_CHIN_RAISER_B_FB, XR_BS_MOUTHSHRUGLOWER_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_CHIN_RAISER_T_FB, XR_BS_MOUTHSHRUGUPPER_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_DIMPLER_L_FB, XR_BS_MOUTHDIMPLE_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_DIMPLER_R_FB, XR_BS_MOUTHDIMPLE_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_CLOSED_L_FB, XR_BS_EYEBLINK_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_CLOSED_R_FB, XR_BS_EYEBLINK_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_DOWN_L_FB, XR_BS_EYELOOKDOWN_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_DOWN_R_FB, XR_BS_EYELOOKDOWN_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_LEFT_L_FB, XR_BS_EYELOOKIN_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_LEFT_R_FB, XR_BS_EYELOOKIN_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_RIGHT_L_FB, XR_BS_EYELOOKOUT_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_RIGHT_R_FB, XR_BS_EYELOOKOUT_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_UP_L_FB, XR_BS_EYELOOKUP_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_UP_R_FB, XR_BS_EYELOOKUP_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_INNER_BROW_RAISER_L_FB, XR_BS_BROWINNERUP_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_INNER_BROW_RAISER_R_FB, XR_BS_BROWINNERUP_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_JAW_DROP_FB, XR_BS_JAWOPEN_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_JAW_SIDEWAYS_LEFT_FB, XR_BS_JAWLEFT_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_JAW_SIDEWAYS_RIGHT_FB, XR_BS_JAWRIGHT_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_JAW_THRUST_FB, XR_BS_JAWFORWARD_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LID_TIGHTENER_L_FB, XR_BS_EYESQUINT_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LID_TIGHTENER_R_FB, XR_BS_EYESQUINT_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_CORNER_DEPRESSOR_L_FB, XR_BS_MOUTHFROWN_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_CORNER_DEPRESSOR_R_FB, XR_BS_MOUTHFROWN_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_CORNER_PULLER_L_FB, XR_BS_MOUTHSMILE_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_CORNER_PULLER_R_FB, XR_BS_MOUTHSMILE_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_FUNNELER_LB_FB, XR_BS_MOUTHFUNNEL_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_FUNNELER_LT_FB, XR_BS_MOUTHFUNNEL_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_FUNNELER_RB_FB, XR_BS_MOUTHFUNNEL_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_FUNNELER_RT_FB, XR_BS_MOUTHFUNNEL_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_PRESSOR_L_FB, XR_BS_MOUTHPRESS_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_PRESSOR_R_FB, XR_BS_MOUTHPRESS_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_PUCKER_L_FB, XR_BS_MOUTHPUCKER_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_PUCKER_R_FB, XR_BS_MOUTHPUCKER_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_STRETCHER_L_FB, XR_BS_MOUTHSTRETCH_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_STRETCHER_R_FB, XR_BS_MOUTHSTRETCH_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_SUCK_LB_FB, XR_BS_MOUTHROLLLOWER_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_SUCK_LT_FB, XR_BS_MOUTHROLLLOWER_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_SUCK_RT_FB, XR_BS_MOUTHROLLUPPER_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_SUCK_RB_FB, XR_BS_MOUTHROLLUPPER_PICO); + // XR_FACE_EXPRESSION2_LIP_TIGHTENER_L_FB + // XR_FACE_EXPRESSION2_LIP_TIGHTENER_R_FB + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIPS_TOWARD_FB, XR_BS_MOUTHCLOSE_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LOWER_LIP_DEPRESSOR_L_FB, XR_BS_MOUTHLOWERDOWN_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_LOWER_LIP_DEPRESSOR_R_FB, XR_BS_MOUTHLOWERDOWN_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_MOUTH_LEFT_FB, XR_BS_MOUTHLEFT_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_MOUTH_RIGHT_FB, XR_BS_MOUTHRIGHT_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_NOSE_WRINKLER_L_FB, XR_BS_NOSESNEER_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_NOSE_WRINKLER_R_FB, XR_BS_NOSESNEER_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_OUTER_BROW_RAISER_L_FB, XR_BS_BROWOUTERUP_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_OUTER_BROW_RAISER_R_FB, XR_BS_BROWOUTERUP_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_UPPER_LID_RAISER_L_FB, XR_BS_EYEWIDE_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_UPPER_LID_RAISER_R_FB, XR_BS_EYEWIDE_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_UPPER_LIP_RAISER_L_FB, XR_BS_MOUTHUPPERUP_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_UPPER_LIP_RAISER_R_FB, XR_BS_MOUTHUPPERUP_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_TONGUE_OUT_FB, XR_BS_TONGUEOUT_PICO); + // XR_FACE_EXPRESSION2_TONGUE_TIP_INTERDENTAL_FB + // XR_FACE_EXPRESSION2_TONGUE_TIP_ALVEOLAR_FB + // XR_FACE_EXPRESSION2_TONGUE_FRONT_DORSAL_PALATE_FB + // XR_FACE_EXPRESSION2_TONGUE_MID_DORSAL_PALATE_FB + // XR_FACE_EXPRESSION2_TONGUE_BACK_DORSAL_VELAR_FB + // XR_FACE_EXPRESSION2_TONGUE_RETREAT_FB + +#undef MAP_EXPRESSION + + out_expressions.is_valid = true; + out_expressions.is_eye_following_blendshapes_valid = true; } diff --git a/client/xr/pico_face_tracker.h b/client/xr/pico_face_tracker.h index aa95e0c9..89c229d0 100644 --- a/client/xr/pico_face_tracker.h +++ b/client/xr/pico_face_tracker.h @@ -44,6 +44,6 @@ public: pico_face_tracker(instance & inst, session & s); ~pico_face_tracker(); - void get_weights(XrTime time, struct wivrn::from_headset::tracking::pico_face & out_expressions); + void get_weights(XrTime time, struct wivrn::from_headset::tracking::fb_face2 & out_expressions); }; } // namespace xr diff --git a/common/wivrn_packets.h b/common/wivrn_packets.h index 9f35c4b1..26fb076f 100644 --- a/common/wivrn_packets.h +++ b/common/wivrn_packets.h @@ -287,13 +287,7 @@ struct tracking bool lip_active; }; - struct pico_face - { - std::array weights; - bool is_valid; - }; - - std::variant face; + std::variant face; }; struct trackings diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index e853c146..f0dfcc78 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -96,7 +96,6 @@ if (WIVRN_BUILD_SERVER) driver/wivrn_eye_tracker.cpp driver/wivrn_fb_face2_tracker.cpp driver/wivrn_htc_face_tracker.cpp - driver/wivrn_pico_face_tracker.cpp driver/wivrn_foveation.cpp driver/pose_list.cpp driver/view_list.cpp diff --git a/server/driver/wivrn_pico_face_tracker.cpp b/server/driver/wivrn_pico_face_tracker.cpp deleted file mode 100644 index 14e2bdfb..00000000 --- a/server/driver/wivrn_pico_face_tracker.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/* - * WiVRn VR streaming - * Copyright (C) 2024 Guillaume Meunier - * Copyright (C) 2024 Patrick Nicolas - * Copyright (C) 2024 galister - * Copyright (C) 2025 Sapphire - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "wivrn_pico_face_tracker.h" - -#include "wivrn_packets.h" -#include "wivrn_session.h" - -#include "util/u_logging.h" -#include "utils/method.h" -#include "xr/pico_eye_types.h" -#include "xr/pico_eye_types_reflection.h" -#include "xr/to_string.h" -#include "xrt/xrt_defines.h" -#include "xrt/xrt_device.h" -#include "xrt/xrt_results.h" - -#include -#include -#include -#include -#include - -namespace wivrn -{ - -wivrn_pico_face_tracker::wivrn_pico_face_tracker(xrt_device * hmd, - wivrn::wivrn_session & cnx) : - xrt_device{ - .name = XRT_DEVICE_FB_FACE_TRACKING2, - .device_type = XRT_DEVICE_TYPE_FACE_TRACKER, - .str = "WiVRn Pico Face Tracker (as FB v2)", - .serial = "WiVRn Pico Face Tracker", - .tracking_origin = hmd->tracking_origin, - .face_tracking_supported = true, - .update_inputs = method_pointer<&wivrn_pico_face_tracker::update_inputs>, - .get_face_tracking = method_pointer<&wivrn_pico_face_tracker::get_face_tracking>, - .destroy = [](xrt_device *) {}, - }, - cnx(cnx) -{ - // Setup input. - face_input.name = XRT_INPUT_FB_FACE_TRACKING2_VISUAL; - face_input.active = true; - inputs = &face_input; - input_count = 1; -} - -xrt_result_t wivrn_pico_face_tracker::update_inputs() -{ - return XRT_SUCCESS; -} - -void wivrn_pico_face_tracker::update_tracking(const from_headset::tracking & tracking, const clock_offset & offset) -{ - static std::array confidences{1.0, 1.0}; - - auto * face = std::get_if(&tracking.face); - if (not(face and face->is_valid)) - return; - - // for debugging purposes - U_LOG_D("pico face tracking blendshapes:"); - for (auto i = 0; i <= XR_BS_TONGUEOUT_PICO; i++) - { - U_LOG_D(" %s: %f", xr::to_string(static_cast(i)), face->weights[i]); - } - - std::array weights{}; - -#define MAP_EXPRESSION(fb, pico) \ - weights[fb] = face->weights[pico]; - - // Map the blendshapes. - MAP_EXPRESSION(XR_FACE_EXPRESSION2_BROW_LOWERER_L_FB, XR_BS_BROWDOWN_L_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_BROW_LOWERER_R_FB, XR_BS_BROWDOWN_R_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_CHEEK_PUFF_L_FB, XR_BS_CHEEKPUFF_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_CHEEK_PUFF_R_FB, XR_BS_CHEEKPUFF_PICO); - // XR_FACE_EXPRESSION2_CHEEK_RAISER_L_FB - // XR_FACE_EXPRESSION2_CHEEK_RAISER_R_FB - // XR_FACE_EXPRESSION2_CHEEK_SUCK_L_FB - // XR_FACE_EXPRESSION2_CHEEK_SUCK_R_FB - MAP_EXPRESSION(XR_FACE_EXPRESSION2_CHIN_RAISER_B_FB, XR_BS_MOUTHSHRUGLOWER_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_CHIN_RAISER_T_FB, XR_BS_MOUTHSHRUGUPPER_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_DIMPLER_L_FB, XR_BS_MOUTHDIMPLE_L_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_DIMPLER_R_FB, XR_BS_MOUTHDIMPLE_R_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_CLOSED_L_FB, XR_BS_EYEBLINK_L_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_CLOSED_R_FB, XR_BS_EYEBLINK_R_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_DOWN_L_FB, XR_BS_EYELOOKDOWN_L_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_DOWN_R_FB, XR_BS_EYELOOKDOWN_R_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_LEFT_L_FB, XR_BS_EYELOOKIN_L_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_LEFT_R_FB, XR_BS_EYELOOKIN_R_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_RIGHT_L_FB, XR_BS_EYELOOKOUT_L_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_RIGHT_R_FB, XR_BS_EYELOOKOUT_R_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_UP_L_FB, XR_BS_EYELOOKUP_L_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_UP_R_FB, XR_BS_EYELOOKUP_R_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_INNER_BROW_RAISER_L_FB, XR_BS_BROWINNERUP_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_INNER_BROW_RAISER_R_FB, XR_BS_BROWINNERUP_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_JAW_DROP_FB, XR_BS_JAWOPEN_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_JAW_SIDEWAYS_LEFT_FB, XR_BS_JAWLEFT_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_JAW_SIDEWAYS_RIGHT_FB, XR_BS_JAWRIGHT_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_JAW_THRUST_FB, XR_BS_JAWFORWARD_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_LID_TIGHTENER_L_FB, XR_BS_EYESQUINT_L_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_LID_TIGHTENER_R_FB, XR_BS_EYESQUINT_R_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_CORNER_DEPRESSOR_L_FB, XR_BS_MOUTHFROWN_L_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_CORNER_DEPRESSOR_R_FB, XR_BS_MOUTHFROWN_R_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_CORNER_PULLER_L_FB, XR_BS_MOUTHSMILE_L_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_CORNER_PULLER_R_FB, XR_BS_MOUTHSMILE_R_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_FUNNELER_LB_FB, XR_BS_MOUTHFUNNEL_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_FUNNELER_LT_FB, XR_BS_MOUTHFUNNEL_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_FUNNELER_RB_FB, XR_BS_MOUTHFUNNEL_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_FUNNELER_RT_FB, XR_BS_MOUTHFUNNEL_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_PRESSOR_L_FB, XR_BS_MOUTHPRESS_L_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_PRESSOR_R_FB, XR_BS_MOUTHPRESS_R_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_PUCKER_L_FB, XR_BS_MOUTHPUCKER_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_PUCKER_R_FB, XR_BS_MOUTHPUCKER_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_STRETCHER_L_FB, XR_BS_MOUTHSTRETCH_L_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_STRETCHER_R_FB, XR_BS_MOUTHSTRETCH_R_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_SUCK_LB_FB, XR_BS_MOUTHROLLLOWER_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_SUCK_LT_FB, XR_BS_MOUTHROLLLOWER_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_SUCK_RT_FB, XR_BS_MOUTHROLLUPPER_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_SUCK_RB_FB, XR_BS_MOUTHROLLUPPER_PICO); - // XR_FACE_EXPRESSION2_LIP_TIGHTENER_L_FB - // XR_FACE_EXPRESSION2_LIP_TIGHTENER_R_FB - MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIPS_TOWARD_FB, XR_BS_MOUTHCLOSE_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_LOWER_LIP_DEPRESSOR_L_FB, XR_BS_MOUTHLOWERDOWN_L_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_LOWER_LIP_DEPRESSOR_R_FB, XR_BS_MOUTHLOWERDOWN_R_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_MOUTH_LEFT_FB, XR_BS_MOUTHLEFT_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_MOUTH_RIGHT_FB, XR_BS_MOUTHRIGHT_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_NOSE_WRINKLER_L_FB, XR_BS_NOSESNEER_L_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_NOSE_WRINKLER_R_FB, XR_BS_NOSESNEER_R_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_OUTER_BROW_RAISER_L_FB, XR_BS_BROWOUTERUP_L_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_OUTER_BROW_RAISER_R_FB, XR_BS_BROWOUTERUP_R_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_UPPER_LID_RAISER_L_FB, XR_BS_EYEWIDE_L_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_UPPER_LID_RAISER_R_FB, XR_BS_EYEWIDE_R_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_UPPER_LIP_RAISER_L_FB, XR_BS_MOUTHUPPERUP_L_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_UPPER_LIP_RAISER_R_FB, XR_BS_MOUTHUPPERUP_R_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_TONGUE_OUT_FB, XR_BS_TONGUEOUT_PICO); - // XR_FACE_EXPRESSION2_TONGUE_TIP_INTERDENTAL_FB - // XR_FACE_EXPRESSION2_TONGUE_TIP_ALVEOLAR_FB - // XR_FACE_EXPRESSION2_TONGUE_FRONT_DORSAL_PALATE_FB - // XR_FACE_EXPRESSION2_TONGUE_MID_DORSAL_PALATE_FB - // XR_FACE_EXPRESSION2_TONGUE_BACK_DORSAL_VELAR_FB - // XR_FACE_EXPRESSION2_TONGUE_RETREAT_FB - -#undef MAP_EXPRESSION - - wivrn_fb_face2_data data{ - .weights = weights, - .confidences = confidences, - .is_valid = face->is_valid, - .is_eye_following_blendshapes_valid = face->is_valid, - }; - - if (not face_list.update_tracking(tracking.production_timestamp, tracking.timestamp, data, offset)) - cnx.set_enabled(to_headset::tracking_control::id::face, false); -} - -xrt_result_t wivrn_pico_face_tracker::get_face_tracking(enum xrt_input_name facial_expression_type, int64_t at_timestamp_ns, struct xrt_facial_expression_set * inout_value) -{ - if (facial_expression_type == XRT_INPUT_FB_FACE_TRACKING2_VISUAL) - { - cnx.set_enabled(to_headset::tracking_control::id::face, true); - auto [_, data] = face_list.get_at(at_timestamp_ns); - - inout_value->face_expression_set2_fb.is_valid = data.is_valid; - - if (not data.is_valid) - return XRT_SUCCESS; - - inout_value->face_expression_set2_fb.is_eye_following_blendshapes_valid = data.is_eye_following_blendshapes_valid; - - memcpy(&inout_value->face_expression_set2_fb.weights, data.weights.data(), sizeof(float) * data.weights.size()); - memcpy(&inout_value->face_expression_set2_fb.confidences, data.confidences.data(), sizeof(float) * data.confidences.size()); - - inout_value->face_expression_set2_fb.data_source = XRT_FACE_TRACKING_DATA_SOURCE2_VISUAL_FB; - - return XRT_SUCCESS; - } - - return XRT_ERROR_NOT_IMPLEMENTED; -} -} // namespace wivrn diff --git a/server/driver/wivrn_pico_face_tracker.h b/server/driver/wivrn_pico_face_tracker.h deleted file mode 100644 index 85b5b86f..00000000 --- a/server/driver/wivrn_pico_face_tracker.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * WiVRn VR streaming - * Copyright (C) 2024 Guillaume Meunier - * Copyright (C) 2024 Patrick Nicolas - * Copyright (C) 2024 galister - * Copyright (C) 2025 Sapphire - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include "wivrn_fb_face2_tracker.h" -#include "wivrn_packets.h" -#include "xrt/xrt_defines.h" -#include "xrt/xrt_device.h" - -namespace wivrn -{ - -class wivrn_session; - -class wivrn_pico_face_tracker : public xrt_device -{ - fb_face2_list face_list; - xrt_input face_input; - - wivrn::wivrn_session & cnx; - -public: - using base = xrt_device; - wivrn_pico_face_tracker(xrt_device * hmd, wivrn::wivrn_session & cnx); - - xrt_result_t update_inputs(); - void update_tracking(const from_headset::tracking &, const clock_offset &); - xrt_result_t get_face_tracking(enum xrt_input_name facial_expression_type, int64_t at_timestamp_ns, struct xrt_facial_expression_set * out_value); -}; -} // namespace wivrn diff --git a/server/driver/wivrn_session.cpp b/server/driver/wivrn_session.cpp index 3b14df2f..6ed67c81 100644 --- a/server/driver/wivrn_session.cpp +++ b/server/driver/wivrn_session.cpp @@ -38,7 +38,6 @@ #include "wivrn_foveation.h" #include "wivrn_htc_face_tracker.h" #include "wivrn_ipc.h" -#include "wivrn_pico_face_tracker.h" #include "wivrn_packets.h" #include "xrt/xrt_device.h" @@ -203,24 +202,20 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr connection static_roles.eyes = eye_tracker.get(); xdevs[xdev_count++] = eye_tracker.get(); } - if (get_info().face_tracking == wivrn::from_headset::face_type::fb2 || is_forced_extension("FB_face_tracking2")) + + auto face = get_info().face_tracking; + if (face == from_headset::face_type::fb2 || face == from_headset::face_type::pico || is_forced_extension("FB_face_tracking2")) { fb_face2_tracker = std::make_unique(&hmd, *this); static_roles.face = fb_face2_tracker.get(); xdevs[xdev_count++] = fb_face2_tracker.get(); } - if (get_info().face_tracking == wivrn::from_headset::face_type::htc || is_forced_extension("HTC_facial_tracking")) + if (face == wivrn::from_headset::face_type::htc || is_forced_extension("HTC_facial_tracking")) { htc_face_tracker = std::make_unique(&hmd, *this); static_roles.face = htc_face_tracker.get(); xdevs[xdev_count++] = htc_face_tracker.get(); } - if (get_info().face_tracking == wivrn::from_headset::face_type::pico || is_forced_extension("PICO_eye_tracking")) - { - pico_face_tracker = std::make_unique(&hmd, *this); - static_roles.face = pico_face_tracker.get(); - xdevs[xdev_count++] = pico_face_tracker.get(); - } #if WIVRN_FEATURE_SOLARXR xrt_device * solar_devs[XRT_SYSTEM_MAX_DEVICES]; @@ -418,8 +413,6 @@ void wivrn_session::operator()(const from_headset::tracking & tracking) fb_face2_tracker->update_tracking(tracking, offset); else if (htc_face_tracker) htc_face_tracker->update_tracking(tracking, offset); - else if (pico_face_tracker) - pico_face_tracker->update_tracking(tracking, offset); } void wivrn_session::operator()(from_headset::derived_pose && derived) diff --git a/server/driver/wivrn_session.h b/server/driver/wivrn_session.h index b7004778..95584f23 100644 --- a/server/driver/wivrn_session.h +++ b/server/driver/wivrn_session.h @@ -44,7 +44,6 @@ namespace wivrn class wivrn_eye_tracker; class wivrn_fb_face2_tracker; class wivrn_htc_face_tracker; -class wivrn_pico_face_tracker; class wivrn_foveation; class wivrn_foveation_renderer; struct audio_device; @@ -110,7 +109,6 @@ class wivrn_session : public xrt_system_devices std::unique_ptr eye_tracker; std::unique_ptr fb_face2_tracker; std::unique_ptr htc_face_tracker; - std::unique_ptr pico_face_tracker; std::unique_ptr foveation; wivrn_comp_target * comp_target; From e2d964101908d2960cf1875742d366b9c4bb7537 Mon Sep 17 00:00:00 2001 From: Sapphire Date: Wed, 28 May 2025 22:45:13 -0500 Subject: [PATCH 33/85] Fix eye look blendshapes --- client/xr/pico_face_tracker.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/client/xr/pico_face_tracker.cpp b/client/xr/pico_face_tracker.cpp index 8243735a..e3d01d82 100644 --- a/client/xr/pico_face_tracker.cpp +++ b/client/xr/pico_face_tracker.cpp @@ -109,10 +109,13 @@ void xr::pico_face_tracker::get_weights(XrTime time, wivrn::from_headset::tracki MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_CLOSED_R_FB, XR_BS_EYEBLINK_R_PICO); MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_DOWN_L_FB, XR_BS_EYELOOKDOWN_L_PICO); MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_DOWN_R_FB, XR_BS_EYELOOKDOWN_R_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_LEFT_L_FB, XR_BS_EYELOOKIN_L_PICO); + + // "out" is left for the left eye, right for the right eye + MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_LEFT_L_FB, XR_BS_EYELOOKOUT_L_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_RIGHT_L_FB, XR_BS_EYELOOKIN_L_PICO); MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_LEFT_R_FB, XR_BS_EYELOOKIN_R_PICO); - MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_RIGHT_L_FB, XR_BS_EYELOOKOUT_L_PICO); MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_RIGHT_R_FB, XR_BS_EYELOOKOUT_R_PICO); + MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_UP_L_FB, XR_BS_EYELOOKUP_L_PICO); MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_UP_R_FB, XR_BS_EYELOOKUP_R_PICO); MAP_EXPRESSION(XR_FACE_EXPRESSION2_INNER_BROW_RAISER_L_FB, XR_BS_BROWINNERUP_PICO); From bd2f6a632e7a3accf90787773f2171f953eb0b95 Mon Sep 17 00:00:00 2001 From: Sapphire Date: Fri, 30 May 2025 12:15:36 -0500 Subject: [PATCH 34/85] Defer pico face tracking start until stream begins --- client/scenes/lobby_gui.cpp | 11 +++-------- client/scenes/stream_tracking.cpp | 9 +++++++++ client/xr/pico_face_tracker.cpp | 25 ++++++++++++++++++++++--- client/xr/pico_face_tracker.h | 3 +++ 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index 191a59ea..c8bf6fd8 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -1344,12 +1344,7 @@ static const char * get_face_icon(XrTime predicted_display_time) { static const auto w = face_weights(); wivrn::from_headset::tracking::fb_face2 expression; - if (application::get_fb_face_tracking2_supported()) - application::get_fb_face_tracker2().get_weights(predicted_display_time, expression); - else if (application::get_pico_face_tracking_supported()) - application::get_pico_face_tracker().get_weights(predicted_display_time, expression); - else - __builtin_unreachable(); + application::get_fb_face_tracker2().get_weights(predicted_display_time, expression); if (not expression.is_valid) return ICON_FA_FACE_MEH; @@ -1413,7 +1408,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time) }); } - if (application::get_fb_face_tracking2_supported() or application::get_pico_face_tracking_supported()) + if (application::get_fb_face_tracking2_supported()) { items.push_back({ .f = feature::face_tracking, @@ -1424,7 +1419,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time) }); } - if (application::get_htc_face_tracking_eye_supported() or application::get_htc_face_tracking_lip_supported()) + if (application::get_htc_face_tracking_eye_supported() or application::get_htc_face_tracking_lip_supported() or application::get_pico_face_tracking_supported()) { items.push_back({ .f = feature::face_tracking, diff --git a/client/scenes/stream_tracking.cpp b/client/scenes/stream_tracking.cpp index cdc9f3b8..aa6a76bc 100644 --- a/client/scenes/stream_tracking.cpp +++ b/client/scenes/stream_tracking.cpp @@ -249,7 +249,13 @@ void scenes::stream::tracking() else if (application::get_htc_face_tracking_eye_supported() or application::get_htc_face_tracking_lip_supported()) face_tracking = from_headset::face_type::htc; else if (application::get_pico_face_tracking_supported()) + { face_tracking = from_headset::face_type::pico; + // We can't start the face tracking on application initialisation like we do for + // other face trackers due to a Pico runtime bug where face tracking freezes when + // the headset is taken off or the application is quit. + application::get_pico_face_tracker().start(); + } } on_interaction_profile_changed({}); @@ -444,6 +450,9 @@ void scenes::stream::tracking() exit(); } } + + if (face_tracking == from_headset::face_type::pico) + application::get_pico_face_tracker().stop(); } void scenes::stream::operator()(to_headset::tracking_control && packet) diff --git a/client/xr/pico_face_tracker.cpp b/client/xr/pico_face_tracker.cpp index e3d01d82..506e2fe4 100644 --- a/client/xr/pico_face_tracker.cpp +++ b/client/xr/pico_face_tracker.cpp @@ -25,7 +25,9 @@ #include "xr/pico_eye_types.h" #include "xr/session.h" #include "xr/to_string.h" + #include +#include #include xr::pico_face_tracker::pico_face_tracker(instance & inst, session & s_) : @@ -36,14 +38,31 @@ xr::pico_face_tracker::pico_face_tracker(instance & inst, session & s_) : xrSetTrackingModePICO = inst.get_proc("xrSetTrackingModePICO"); xrGetFaceTrackingStatePICO = inst.get_proc("xrGetFaceTrackingStatePICO"); xrGetFaceTrackingDataPICO = inst.get_proc("xrGetFaceTrackingDataPICO"); - - CHECK_XR(xrStartEyeTrackingPICO(s)); - CHECK_XR(xrSetTrackingModePICO(s, XR_TRACKING_MODE_FACE_BIT_PICO)); } xr::pico_face_tracker::~pico_face_tracker() { + if (started) + stop(); +} + +void xr::pico_face_tracker::start() +{ + if (started) + throw std::invalid_argument("face tracking already started"); + + CHECK_XR(xrStartEyeTrackingPICO(s)); + CHECK_XR(xrSetTrackingModePICO(s, XR_TRACKING_MODE_FACE_BIT_PICO)); + started = true; +} +void xr::pico_face_tracker::stop() +{ + if (!started) + throw std::invalid_argument("face tracking not started"); + if (auto res = xrStopEyeTrackingPICO(s, XR_TRACKING_MODE_FACE_BIT_PICO); !XR_SUCCEEDED(res)) spdlog::warn("Failed to deactivate face tracking: {}", xr::to_string(res)); + + started = false; } void xr::pico_face_tracker::get_weights(XrTime time, wivrn::from_headset::tracking::fb_face2 & out_expressions) diff --git a/client/xr/pico_face_tracker.h b/client/xr/pico_face_tracker.h index 89c229d0..c3d1ff2b 100644 --- a/client/xr/pico_face_tracker.h +++ b/client/xr/pico_face_tracker.h @@ -38,12 +38,15 @@ class pico_face_tracker PFN_xrGetFaceTrackingDataPICO xrGetFaceTrackingDataPICO{}; XrSession s; + bool started{}; public: pico_face_tracker() = default; pico_face_tracker(instance & inst, session & s); ~pico_face_tracker(); + void start(); + void stop(); void get_weights(XrTime time, struct wivrn::from_headset::tracking::fb_face2 & out_expressions); }; } // namespace xr From 248a533d0ee761863267fb1e3940ad0022b64774 Mon Sep 17 00:00:00 2001 From: Sapphire Date: Sat, 31 May 2025 22:09:34 -0500 Subject: [PATCH 35/85] Assume ft is available on pico when XR_EXT_eye_gaze_interaction is supported --- client/application.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/client/application.cpp b/client/application.cpp index 66249e7a..404d4c22 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -19,6 +19,7 @@ #include "application.h" #include "asset.h" +#include "hardware.h" #include "openxr/openxr.h" #include "scene.h" #include "spdlog/common.h" @@ -1040,7 +1041,6 @@ void application::initialize() opt_extensions.push_back(XR_HTC_PASSTHROUGH_EXTENSION_NAME); opt_extensions.push_back(XR_HTC_FACIAL_TRACKING_EXTENSION_NAME); opt_extensions.push_back(XR_FB_FACE_TRACKING2_EXTENSION_NAME); - opt_extensions.push_back(XR_PICO_EYE_TRACKING_EXTENSION_NAME); opt_extensions.push_back(XR_EXT_PALM_POSE_EXTENSION_NAME); opt_extensions.push_back(XR_KHR_COMPOSITION_LAYER_DEPTH_EXTENSION_NAME); opt_extensions.push_back(XR_FB_COMPOSITION_LAYER_DEPTH_TEST_EXTENSION_NAME); @@ -1105,6 +1105,24 @@ void application::initialize() 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 (eye_gaze_supported) + { + switch (guess_model()) + { + case model::pico_4_pro: + case model::pico_4_enterprise: + pico_face_tracking_supported = true; + break; + default: + pico_face_tracking_supported = false; + break; + } + } + else + pico_face_tracking_supported = false; + + spdlog::info(" PICO face tracking support: {}", (bool)pico_face_tracking_supported); } if (utils::contains(xr_extensions, XR_FB_FACE_TRACKING2_EXTENSION_NAME)) @@ -1123,12 +1141,6 @@ void application::initialize() htc_face_tracking_lip_supported = htc_face_properties.supportLipFacialTracking; } - if (utils::contains(xr_extensions, XR_PICO_EYE_TRACKING_EXTENSION_NAME)) - { - spdlog::info(" PICO face tracking support: true"); - pico_face_tracking_supported = true; - } - if (utils::contains(xr_extensions, XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME)) { spdlog::info(" OpenXR post-processing extension support: true"); From 53a6efe27a7b7c811d8220e6e43480a21e4e97ea Mon Sep 17 00:00:00 2001 From: Sapphire Date: Sat, 31 May 2025 23:41:21 -0500 Subject: [PATCH 36/85] Cleanup pico face error handling, remove stale workaround --- client/xr/pico_face_tracker.cpp | 40 +++++++-------------------------- client/xr/pico_face_tracker.h | 1 - 2 files changed, 8 insertions(+), 33 deletions(-) diff --git a/client/xr/pico_face_tracker.cpp b/client/xr/pico_face_tracker.cpp index 506e2fe4..bf224be4 100644 --- a/client/xr/pico_face_tracker.cpp +++ b/client/xr/pico_face_tracker.cpp @@ -36,13 +36,11 @@ xr::pico_face_tracker::pico_face_tracker(instance & inst, session & s_) : xrStartEyeTrackingPICO = inst.get_proc("xrStartEyeTrackingPICO"); xrStopEyeTrackingPICO = inst.get_proc("xrStopEyeTrackingPICO"); xrSetTrackingModePICO = inst.get_proc("xrSetTrackingModePICO"); - xrGetFaceTrackingStatePICO = inst.get_proc("xrGetFaceTrackingStatePICO"); xrGetFaceTrackingDataPICO = inst.get_proc("xrGetFaceTrackingDataPICO"); } xr::pico_face_tracker::~pico_face_tracker() { - if (started) - stop(); + stop(); } void xr::pico_face_tracker::start() @@ -57,7 +55,7 @@ void xr::pico_face_tracker::start() void xr::pico_face_tracker::stop() { if (!started) - throw std::invalid_argument("face tracking not started"); + return; if (auto res = xrStopEyeTrackingPICO(s, XR_TRACKING_MODE_FACE_BIT_PICO); !XR_SUCCEEDED(res)) spdlog::warn("Failed to deactivate face tracking: {}", xr::to_string(res)); @@ -67,44 +65,22 @@ void xr::pico_face_tracker::stop() void xr::pico_face_tracker::get_weights(XrTime time, wivrn::from_headset::tracking::fb_face2 & out_expressions) { - if (!xrGetFaceTrackingDataPICO) + out_expressions.is_valid = false; + out_expressions.is_eye_following_blendshapes_valid = false; + + if (!started or !xrGetFaceTrackingDataPICO) return; XrFaceTrackingDataPICO face_tracking{.time = 0}; - if (auto res = xrGetFaceTrackingDataPICO(s, time, XR_GET_FACE_DATA_DEFAULT_PICO, &face_tracking); res != XR_SUCCESS) + if (auto res = xrGetFaceTrackingDataPICO(s, time, XR_GET_FACE_DATA_DEFAULT_PICO, &face_tracking); !XR_SUCCEEDED(res)) { - XrTrackingModeFlagsPICO mode; - XrTrackingStateCodePICO code; - - auto state_res = xrGetFaceTrackingStatePICO(s, &mode, &code); - if (XR_SUCCEEDED(state_res)) - spdlog::warn("Unable to get face tracking data: xrGetFaceTrackingDataPICO returned {}, tracking mode state {}, flags {}", xr::to_string(res), xr::to_string(code), mode); - else - spdlog::warn("Unable to get face tracking data: xrGetFaceTrackingDataPICO returned {}, unable to get face tracking state: {}", xr::to_string(res), xr::to_string(state_res)); - - if (auto res = xrStartEyeTrackingPICO(s); !XR_SUCCEEDED(res)) - { - spdlog::warn("Failed to start eye tracking: {}", xr::to_string(res)); - goto exit; - } - if (auto res = xrSetTrackingModePICO(s, XR_TRACKING_MODE_FACE_BIT_PICO); !XR_SUCCEEDED(res)) - { - spdlog::warn("Failed to set tracking mode: {}", xr::to_string(res)); - } - - exit: - out_expressions.is_valid = false; - out_expressions.is_eye_following_blendshapes_valid = false; + spdlog::warn("Unable to get face tracking data: xrGetFaceTrackingDataPICO returned {}", xr::to_string(res)); return; } if (face_tracking.time == 0) - { - out_expressions.is_valid = false; - out_expressions.is_eye_following_blendshapes_valid = false; return; - } #define MAP_EXPRESSION(fb, pico) \ out_expressions.weights[fb] = face_tracking.blendShapeWeight[pico]; diff --git a/client/xr/pico_face_tracker.h b/client/xr/pico_face_tracker.h index c3d1ff2b..bd006568 100644 --- a/client/xr/pico_face_tracker.h +++ b/client/xr/pico_face_tracker.h @@ -34,7 +34,6 @@ class pico_face_tracker PFN_xrStartEyeTrackingPICO xrStartEyeTrackingPICO{}; PFN_xrStopEyeTrackingPICO xrStopEyeTrackingPICO{}; PFN_xrSetTrackingModePICO xrSetTrackingModePICO{}; - PFN_xrGetFaceTrackingStatePICO xrGetFaceTrackingStatePICO{}; PFN_xrGetFaceTrackingDataPICO xrGetFaceTrackingDataPICO{}; XrSession s; From d392d30d1c79cf6f6ca59a6484315c3a1544be77 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Fri, 6 Jun 2025 13:15:15 +0200 Subject: [PATCH 37/85] fix qtdeclarative-6.9.1 crash --- dashboard/qml/SettingsPage.qml | 1 - 1 file changed, 1 deletion(-) diff --git a/dashboard/qml/SettingsPage.qml b/dashboard/qml/SettingsPage.qml index d4c9ed59..ca9dcc49 100644 --- a/dashboard/qml/SettingsPage.qml +++ b/dashboard/qml/SettingsPage.qml @@ -301,7 +301,6 @@ Kirigami.ScrollablePage { onCurrentIndexChanged: partitionner.codec = model[currentIndex].name delegate: Controls.ItemDelegate { - required property int index required property string label required property string name From 2f2192f292ef3372ef4d9fdf34b25fdf6e6bc039 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Fri, 6 Jun 2025 13:21:21 +0200 Subject: [PATCH 38/85] Fix qml naming warning --- dashboard/wivrn_server.cpp | 10 +++++----- dashboard/wivrn_server.h | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dashboard/wivrn_server.cpp b/dashboard/wivrn_server.cpp index 7a520dae..816387a7 100644 --- a/dashboard/wivrn_server.cpp +++ b/dashboard/wivrn_server.cpp @@ -577,19 +577,19 @@ QString wivrn_server::host_path(QString path) return path; } -QList wivrn_server::openVRCompat() const +QList wivrn_server::openVRCompat() const { if (wivrn::is_flatpak()) return { - OpenVRCompat(i18n("xrizer"), "xrizer"), - OpenVRCompat(i18n("Open Composite"), "OpenComposite"), + openVRCompatLib(i18n("xrizer"), "xrizer"), + openVRCompatLib(i18n("Open Composite"), "OpenComposite"), }; - QList result; + QList result; for (auto path: std::ranges::split_view(std::string_view(OVR_COMPAT_SEARCH_PATH), std::string_view(":"))) { if (std::filesystem::path fs = std::string_view(path); std::filesystem::exists(fs)) - result.push_back(OpenVRCompat(QString::fromStdString(fs.string()), QString::fromStdString(fs.string()))); + result.push_back(openVRCompatLib(QString::fromStdString(fs.string()), QString::fromStdString(fs.string()))); } return result; } diff --git a/dashboard/wivrn_server.h b/dashboard/wivrn_server.h index 5a38a997..bc61dc6f 100644 --- a/dashboard/wivrn_server.h +++ b/dashboard/wivrn_server.h @@ -95,7 +95,7 @@ public: } }; -class OpenVRCompat +class openVRCompatLib { Q_GADGET QML_VALUE_TYPE(openVRCompat) @@ -107,8 +107,8 @@ class OpenVRCompat QString m_path; public: - OpenVRCompat() = default; - OpenVRCompat(QString name, QString path) : + openVRCompatLib() = default; + openVRCompatLib(QString name, QString path) : m_name(name), m_path(path) {} // localized name of the compat layer (can be the path) @@ -199,7 +199,7 @@ public: Q_INVOKABLE QString host_path(QString path); // System information - Q_PROPERTY(QList openVRCompat READ openVRCompat CONSTANT) + Q_PROPERTY(QList openVRCompat READ openVRCompat CONSTANT) Status serverStatus() const { @@ -315,7 +315,7 @@ public: return server_output.join(""); } - QList openVRCompat() const; + QList openVRCompat() const; Q_INVOKABLE void disconnect_headset(); Q_INVOKABLE void copy_steam_command(); From 8233ab052b296df366d241c58362d1fa1ff62b46 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Fri, 6 Jun 2025 13:24:22 +0200 Subject: [PATCH 39/85] fix qml registered multiple times warnings --- dashboard/steam_apps.h | 1 - dashboard/wivrn_server.h | 1 - 2 files changed, 2 deletions(-) diff --git a/dashboard/steam_apps.h b/dashboard/steam_apps.h index d76a8b39..91e6b9ee 100644 --- a/dashboard/steam_apps.h +++ b/dashboard/steam_apps.h @@ -25,7 +25,6 @@ class steamApp { Q_GADGET QML_VALUE_TYPE(steamApp) - QML_ELEMENT Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(QString imagePath READ imagePath WRITE setImagePath) Q_PROPERTY(QString command READ command WRITE setCommand) diff --git a/dashboard/wivrn_server.h b/dashboard/wivrn_server.h index bc61dc6f..7e4a1154 100644 --- a/dashboard/wivrn_server.h +++ b/dashboard/wivrn_server.h @@ -37,7 +37,6 @@ class headset { Q_GADGET QML_VALUE_TYPE(headset) - QML_ELEMENT Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(QString publicKey READ publicKey WRITE setPublicKey) Q_PROPERTY(bool hasLastConnection READ hasLastConnection) From 5cebea6eda9c92ca0ced7b67d70172daf753fa15 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Fri, 6 Jun 2025 13:31:05 +0200 Subject: [PATCH 40/85] Remove PrivateTmp for wivrn-application This may break some applications and does not provide useful sandboxing --- server/dist/wivrn-application.service.in | 1 - 1 file changed, 1 deletion(-) diff --git a/server/dist/wivrn-application.service.in b/server/dist/wivrn-application.service.in index d783dad4..ea994347 100644 --- a/server/dist/wivrn-application.service.in +++ b/server/dist/wivrn-application.service.in @@ -6,4 +6,3 @@ Type=simple ExecStart=@CMAKE_INSTALL_PREFIX@/bin/wivrn-server --application Restart=on-failure RestartSec=0 -PrivateTmp=true From aef8efba8af060dbd9ef5816666ee0e99df15da8 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sun, 13 Apr 2025 13:48:16 +0200 Subject: [PATCH 41/85] Drop mipmaps for foveation --- ...001-c-multi-early-wake-of-compositor.patch | 4 +- ...02-ipc-server-Always-listen-to-stdin.patch | 4 +- .../monado/0003-Use-extern-socket-fd.patch | 4 +- ...Add-storage-usage-to-distortion-mesh.patch | 4 +- ...vironment-blend-mode-selection-logic.patch | 4 +- ... => 0006-Convert-to-YCbCr-in-Monado.patch} | 105 +- ...06-Use-mipmaps-for-distortion-shader.patch | 2764 ----------------- ...0007-store-alpha-channel-in-layer-1.patch} | 12 +- ...-oxr-bind-to-dynamic-role-s-profile.patch} | 4 +- ...ain-allow-custom-pacing-app-factory.patch} | 4 +- ... 0010-st-oxr-forward-0-refresh-rate.patch} | 4 +- server/driver/wivrn_foveation.cpp | 44 +- server/driver/wivrn_hmd.cpp | 16 +- server/main.cpp | 3 - server/shaders/foveate.comp.glsl | 9 - 15 files changed, 92 insertions(+), 2893 deletions(-) rename patches/monado/{0007-Convert-to-YCbCr-in-Monado.patch => 0006-Convert-to-YCbCr-in-Monado.patch} (90%) delete mode 100644 patches/monado/0006-Use-mipmaps-for-distortion-shader.patch rename patches/monado/{0008-store-alpha-channel-in-layer-1.patch => 0007-store-alpha-channel-in-layer-1.patch} (93%) rename patches/monado/{0009-st-oxr-bind-to-dynamic-role-s-profile.patch => 0008-st-oxr-bind-to-dynamic-role-s-profile.patch} (93%) rename patches/monado/{0010-c-main-allow-custom-pacing-app-factory.patch => 0009-c-main-allow-custom-pacing-app-factory.patch} (96%) rename patches/monado/{0011-st-oxr-forward-0-refresh-rate.patch => 0010-st-oxr-forward-0-refresh-rate.patch} (90%) diff --git a/patches/monado/0001-c-multi-early-wake-of-compositor.patch b/patches/monado/0001-c-multi-early-wake-of-compositor.patch index 89e1a5ab..70868313 100644 --- a/patches/monado/0001-c-multi-early-wake-of-compositor.patch +++ b/patches/monado/0001-c-multi-early-wake-of-compositor.patch @@ -1,7 +1,7 @@ -From e18311e2b207f784cdd48ab6faf3834f912a1f8d Mon Sep 17 00:00:00 2001 +From 239084ca0a8c5fbc9b3d9efdf9121a60be399650 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Tue, 22 Oct 2024 15:23:19 +0200 -Subject: [PATCH 01/11] c/multi: early wake of compositor +Subject: [PATCH 01/10] c/multi: early wake of compositor --- .../compositor/multi/comp_multi_compositor.c | 14 +++++++++ diff --git a/patches/monado/0002-ipc-server-Always-listen-to-stdin.patch b/patches/monado/0002-ipc-server-Always-listen-to-stdin.patch index 2e600dae..71134c2d 100644 --- a/patches/monado/0002-ipc-server-Always-listen-to-stdin.patch +++ b/patches/monado/0002-ipc-server-Always-listen-to-stdin.patch @@ -1,7 +1,7 @@ -From 0b802694d3a46668acbb7962cb6cc9e7634fa519 Mon Sep 17 00:00:00 2001 +From 86c09de420ebd47d57bfedc2374c57df8d82aa5a Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Tue, 2 Apr 2024 17:14:42 +0200 -Subject: [PATCH 02/11] ipc/server: Always listen to stdin +Subject: [PATCH 02/10] ipc/server: Always listen to stdin --- src/xrt/ipc/server/ipc_server_mainloop_linux.c | 2 +- diff --git a/patches/monado/0003-Use-extern-socket-fd.patch b/patches/monado/0003-Use-extern-socket-fd.patch index 80746d17..f2ffdf3d 100644 --- a/patches/monado/0003-Use-extern-socket-fd.patch +++ b/patches/monado/0003-Use-extern-socket-fd.patch @@ -1,7 +1,7 @@ -From 7a53f4a771a8386d659ad03a025447e8193c284c Mon Sep 17 00:00:00 2001 +From 49c6eaabb908fca0614f11cd23b82db3d57f514e Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Tue, 8 Oct 2024 22:13:15 +0200 -Subject: [PATCH 03/11] Use extern socket fd +Subject: [PATCH 03/10] Use extern socket fd --- src/xrt/ipc/server/ipc_server_mainloop_linux.c | 8 ++++++++ diff --git a/patches/monado/0004-c-render-Add-storage-usage-to-distortion-mesh.patch b/patches/monado/0004-c-render-Add-storage-usage-to-distortion-mesh.patch index 7079f123..56b60c28 100644 --- a/patches/monado/0004-c-render-Add-storage-usage-to-distortion-mesh.patch +++ b/patches/monado/0004-c-render-Add-storage-usage-to-distortion-mesh.patch @@ -1,7 +1,7 @@ -From 018341025bf1ddd2a59e063e7dd972b914ebfbb5 Mon Sep 17 00:00:00 2001 +From 47c5d07b6974f42714db8433677c158cd5828a94 Mon Sep 17 00:00:00 2001 From: galister <3123227-galister@users.noreply.gitlab.com> Date: Mon, 19 Aug 2024 18:51:45 +0900 -Subject: [PATCH 04/11] c/render: Add storage usage to distortion mesh +Subject: [PATCH 04/10] c/render: Add storage usage to distortion mesh --- src/xrt/compositor/render/render_distortion.c | 2 +- diff --git a/patches/monado/0005-change-environment-blend-mode-selection-logic.patch b/patches/monado/0005-change-environment-blend-mode-selection-logic.patch index 759e6467..c59774a1 100644 --- a/patches/monado/0005-change-environment-blend-mode-selection-logic.patch +++ b/patches/monado/0005-change-environment-blend-mode-selection-logic.patch @@ -1,7 +1,7 @@ -From e7159c1bb460909c7c8fe4d54f2a1513462e24b0 Mon Sep 17 00:00:00 2001 +From d0c421a582c8e9429b237bc08829f6882185a6fe Mon Sep 17 00:00:00 2001 From: galister <85970-galister@users.noreply.gitlab.freedesktop.org> Date: Sat, 23 Nov 2024 02:42:12 +0900 -Subject: [PATCH 05/11] change environment blend mode selection logic +Subject: [PATCH 05/10] change environment blend mode selection logic --- src/xrt/compositor/multi/comp_multi_system.c | 26 +++++++++++++------- diff --git a/patches/monado/0007-Convert-to-YCbCr-in-Monado.patch b/patches/monado/0006-Convert-to-YCbCr-in-Monado.patch similarity index 90% rename from patches/monado/0007-Convert-to-YCbCr-in-Monado.patch rename to patches/monado/0006-Convert-to-YCbCr-in-Monado.patch index e26f6bc2..f7f74679 100644 --- a/patches/monado/0007-Convert-to-YCbCr-in-Monado.patch +++ b/patches/monado/0006-Convert-to-YCbCr-in-Monado.patch @@ -1,7 +1,7 @@ -From 30eb60e3716c0bb0df118f4b36eb1820c567ee5b Mon Sep 17 00:00:00 2001 +From dc2780aa2e27e00ec38442490e1b24728b30c6c1 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Wed, 11 Sep 2024 22:56:29 +0200 -Subject: [PATCH 07/11] Convert to YCbCr in Monado +Subject: [PATCH 06/10] Convert to YCbCr in Monado --- src/xrt/compositor/main/comp_renderer.c | 6 +- @@ -9,16 +9,16 @@ Subject: [PATCH 07/11] Convert to YCbCr in Monado src/xrt/compositor/render/render_compute.c | 104 +++++++++++++------ src/xrt/compositor/render/render_interface.h | 15 ++- src/xrt/compositor/render/render_resources.c | 35 +++++-- - src/xrt/compositor/shaders/distortion.comp | 55 +++++++--- + src/xrt/compositor/shaders/distortion.comp | 62 +++++++---- src/xrt/compositor/util/comp_render.h | 12 ++- src/xrt/compositor/util/comp_render_cs.c | 41 +++++--- - 8 files changed, 186 insertions(+), 85 deletions(-) + 8 files changed, 186 insertions(+), 92 deletions(-) diff --git a/src/xrt/compositor/main/comp_renderer.c b/src/xrt/compositor/main/comp_renderer.c -index 89982e654..55aaed69e 100644 +index 6df4d2b29..ea581accd 100644 --- a/src/xrt/compositor/main/comp_renderer.c +++ b/src/xrt/compositor/main/comp_renderer.c -@@ -1009,7 +1009,8 @@ dispatch_compute(struct comp_renderer *r, +@@ -1001,7 +1001,8 @@ dispatch_compute(struct comp_renderer *r, // Target Vulkan resources.. VkImage target_image = r->c->target->images[r->acquired_buffer].handle; @@ -28,7 +28,7 @@ index 89982e654..55aaed69e 100644 // Target view information. struct render_viewport_data views[XRT_MAX_VIEWS]; -@@ -1020,7 +1021,8 @@ dispatch_compute(struct comp_renderer *r, +@@ -1012,7 +1013,8 @@ dispatch_compute(struct comp_renderer *r, comp_render_cs_initial_init( // &data, // data target_image, // target_image @@ -53,7 +53,7 @@ index 876ff8cd9..924b4ea08 100644 /*! diff --git a/src/xrt/compositor/render/render_compute.c b/src/xrt/compositor/render/render_compute.c -index 131b97066..a9552cf2c 100644 +index 27b1953cf..fd04801d4 100644 --- a/src/xrt/compositor/render/render_compute.c +++ b/src/xrt/compositor/render/render_compute.c @@ -66,8 +66,8 @@ calc_dispatch_dims_views(const struct render_viewport_data views[XRT_MAX_VIEWS], @@ -199,7 +199,7 @@ index 131b97066..a9552cf2c 100644 }; vk->vkUpdateDescriptorSets( // -@@ -409,7 +439,8 @@ render_compute_layers(struct render_compute *render, +@@ -395,7 +425,8 @@ render_compute_layers(struct render_compute *render, VkSampler src_samplers[RENDER_MAX_IMAGES_SIZE], VkImageView src_image_views[RENDER_MAX_IMAGES_SIZE], uint32_t num_srcs, @@ -209,7 +209,7 @@ index 131b97066..a9552cf2c 100644 const struct render_viewport_data *view, bool do_timewarp) { -@@ -429,8 +460,10 @@ render_compute_layers(struct render_compute *render, +@@ -415,8 +446,10 @@ render_compute_layers(struct render_compute *render, src_samplers, // src_image_views, // num_srcs, // @@ -222,7 +222,7 @@ index 131b97066..a9552cf2c 100644 r->compute.ubo_binding, // ubo, // VK_WHOLE_SIZE, // -@@ -473,7 +506,8 @@ render_compute_projection_timewarp(struct render_compute *render, +@@ -459,7 +492,8 @@ render_compute_projection_timewarp(struct render_compute *render, const struct xrt_fov src_fovs[XRT_MAX_VIEWS], const struct xrt_pose new_poses[XRT_MAX_VIEWS], VkImage target_image, @@ -232,7 +232,7 @@ index 131b97066..a9552cf2c 100644 const struct render_viewport_data views[XRT_MAX_VIEWS]) { assert(render->r != NULL); -@@ -542,8 +576,10 @@ render_compute_projection_timewarp(struct render_compute *render, +@@ -528,8 +562,10 @@ render_compute_projection_timewarp(struct render_compute *render, r->compute.distortion_binding, // distortion_samplers, // r->distortion.image_views, // @@ -245,7 +245,7 @@ index 131b97066..a9552cf2c 100644 r->compute.ubo_binding, // r->compute.distortion.ubo.buffer, // VK_WHOLE_SIZE, // -@@ -581,7 +617,7 @@ render_compute_projection_timewarp(struct render_compute *render, +@@ -567,7 +603,7 @@ render_compute_projection_timewarp(struct render_compute *render, .srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT, .dstAccessMask = VK_ACCESS_MEMORY_READ_BIT, .oldLayout = VK_IMAGE_LAYOUT_GENERAL, @@ -254,7 +254,7 @@ index 131b97066..a9552cf2c 100644 .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .image = target_image, -@@ -607,7 +643,8 @@ render_compute_projection(struct render_compute *render, +@@ -593,7 +629,8 @@ render_compute_projection(struct render_compute *render, VkImageView src_image_views[XRT_MAX_VIEWS], const struct xrt_normalized_rect src_norm_rects[XRT_MAX_VIEWS], VkImage target_image, @@ -264,7 +264,7 @@ index 131b97066..a9552cf2c 100644 const struct render_viewport_data views[XRT_MAX_VIEWS]) { assert(render->r != NULL); -@@ -666,8 +703,10 @@ render_compute_projection(struct render_compute *render, +@@ -652,8 +689,10 @@ render_compute_projection(struct render_compute *render, r->compute.distortion_binding, // distortion_samplers, // r->distortion.image_views, // @@ -277,7 +277,7 @@ index 131b97066..a9552cf2c 100644 r->compute.ubo_binding, // r->compute.distortion.ubo.buffer, // VK_WHOLE_SIZE, // -@@ -705,7 +744,7 @@ render_compute_projection(struct render_compute *render, +@@ -691,7 +730,7 @@ render_compute_projection(struct render_compute *render, .srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT, .dstAccessMask = VK_ACCESS_MEMORY_READ_BIT, .oldLayout = VK_IMAGE_LAYOUT_GENERAL, @@ -286,7 +286,7 @@ index 131b97066..a9552cf2c 100644 .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .image = target_image, -@@ -728,7 +767,8 @@ render_compute_projection(struct render_compute *render, +@@ -714,7 +753,8 @@ render_compute_projection(struct render_compute *render, void render_compute_clear(struct render_compute *render, VkImage target_image, @@ -296,7 +296,7 @@ index 131b97066..a9552cf2c 100644 const struct render_viewport_data views[XRT_MAX_VIEWS]) { assert(render->r != NULL); -@@ -795,8 +835,10 @@ render_compute_clear(struct render_compute *render, +@@ -781,8 +821,10 @@ render_compute_clear(struct render_compute *render, r->compute.distortion_binding, // distortion_samplers, // r->distortion.image_views, // @@ -309,7 +309,7 @@ index 131b97066..a9552cf2c 100644 r->compute.ubo_binding, // r->compute.clear.ubo.buffer, // VK_WHOLE_SIZE, // ubo_size -@@ -834,7 +876,7 @@ render_compute_clear(struct render_compute *render, +@@ -820,7 +862,7 @@ render_compute_clear(struct render_compute *render, .srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT, .dstAccessMask = VK_ACCESS_MEMORY_READ_BIT, .oldLayout = VK_IMAGE_LAYOUT_GENERAL, @@ -319,10 +319,10 @@ index 131b97066..a9552cf2c 100644 .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .image = target_image, diff --git a/src/xrt/compositor/render/render_interface.h b/src/xrt/compositor/render/render_interface.h -index aab965e0c..b0e568401 100644 +index d5d2bc4cb..2f8ce5287 100644 --- a/src/xrt/compositor/render/render_interface.h +++ b/src/xrt/compositor/render/render_interface.h -@@ -488,7 +488,8 @@ struct render_resources +@@ -481,7 +481,8 @@ struct render_resources uint32_t distortion_binding; //! Writing the image out too. @@ -332,7 +332,7 @@ index aab965e0c..b0e568401 100644 //! Uniform data binding. uint32_t ubo_binding; -@@ -1374,7 +1375,8 @@ render_compute_layers(struct render_compute *render, +@@ -1350,7 +1351,8 @@ render_compute_layers(struct render_compute *render, VkSampler src_samplers[RENDER_MAX_IMAGES_SIZE], VkImageView src_image_views[RENDER_MAX_IMAGES_SIZE], uint32_t num_srcs, @@ -342,7 +342,7 @@ index aab965e0c..b0e568401 100644 const struct render_viewport_data *view, bool timewarp); -@@ -1390,7 +1392,8 @@ render_compute_projection_timewarp(struct render_compute *render, +@@ -1366,7 +1368,8 @@ render_compute_projection_timewarp(struct render_compute *render, const struct xrt_fov src_fovs[XRT_MAX_VIEWS], const struct xrt_pose new_poses[XRT_MAX_VIEWS], VkImage target_image, @@ -352,7 +352,7 @@ index aab965e0c..b0e568401 100644 const struct render_viewport_data views[XRT_MAX_VIEWS]); /*! -@@ -1402,7 +1405,8 @@ render_compute_projection(struct render_compute *render, +@@ -1378,7 +1381,8 @@ render_compute_projection(struct render_compute *render, VkImageView src_image_views[XRT_MAX_VIEWS], const struct xrt_normalized_rect src_rects[XRT_MAX_VIEWS], VkImage target_image, @@ -362,7 +362,7 @@ index aab965e0c..b0e568401 100644 const struct render_viewport_data views[XRT_MAX_VIEWS]); /*! -@@ -1411,7 +1415,8 @@ render_compute_projection(struct render_compute *render, +@@ -1387,7 +1391,8 @@ render_compute_projection(struct render_compute *render, void render_compute_clear(struct render_compute *render, VkImage target_image, @@ -373,7 +373,7 @@ index aab965e0c..b0e568401 100644 diff --git a/src/xrt/compositor/render/render_resources.c b/src/xrt/compositor/render/render_resources.c -index b9b8d4a22..cd9d82072 100644 +index ccc6f10cf..5b9addd59 100644 --- a/src/xrt/compositor/render/render_resources.c +++ b/src/xrt/compositor/render/render_resources.c @@ -184,14 +184,15 @@ init_mesh_ubo_buffers(struct vk_bundle *vk, struct render_buffer ubo[XRT_MAX_VIE @@ -455,7 +455,7 @@ index b9b8d4a22..cd9d82072 100644 }; VkDescriptorSetLayoutCreateInfo set_layout_info = { -@@ -601,8 +615,9 @@ render_resources_init(struct render_resources *r, +@@ -539,8 +553,9 @@ render_resources_init(struct render_resources *r, } r->compute.src_binding = 0; r->compute.distortion_binding = 1; @@ -466,7 +466,7 @@ index b9b8d4a22..cd9d82072 100644 r->compute.layer.image_array_size = MIN(vk->features.max_per_stage_descriptor_sampled_images, RENDER_MAX_IMAGES_COUNT(r)); -@@ -919,7 +934,8 @@ render_resources_init(struct render_resources *r, +@@ -856,7 +871,8 @@ render_resources_init(struct render_resources *r, ret = create_compute_layer_descriptor_set_layout( // vk, // vk_bundle r->compute.src_binding, // src_binding, @@ -476,7 +476,7 @@ index b9b8d4a22..cd9d82072 100644 r->compute.ubo_binding, // ubo_binding, r->compute.layer.image_array_size, // source_images_count, &r->compute.layer.descriptor_set_layout); // out_descriptor_set_layout -@@ -1000,7 +1016,8 @@ render_resources_init(struct render_resources *r, +@@ -937,7 +953,8 @@ render_resources_init(struct render_resources *r, vk, // vk_bundle r->compute.src_binding, // src_binding, r->compute.distortion_binding, // distortion_binding, @@ -487,7 +487,7 @@ index b9b8d4a22..cd9d82072 100644 &r->compute.distortion.descriptor_set_layout); // out_descriptor_set_layout VK_CHK_WITH_RET(ret, "create_compute_distortion_descriptor_set_layout", false); diff --git a/src/xrt/compositor/shaders/distortion.comp b/src/xrt/compositor/shaders/distortion.comp -index 9a09c03db..461aeb4ec 100644 +index 08b44d4cf..e1dd1cb58 100644 --- a/src/xrt/compositor/shaders/distortion.comp +++ b/src/xrt/compositor/shaders/distortion.comp @@ -18,7 +18,7 @@ layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; @@ -520,7 +520,7 @@ index 9a09c03db..461aeb4ec 100644 vec2 position_to_uv(ivec2 extent, uint ix, uint iy) { -@@ -124,30 +137,40 @@ mat3x2 source_coord(ivec3 xyv, ivec2 extent) +@@ -104,37 +117,40 @@ vec2 transform_uv(vec2 uv, uint iz) void main() { @@ -545,18 +545,25 @@ index 9a09c03db..461aeb4ec 100644 + vec2 uv = texture(distortion[iz + 0], dist_uv).xy; + vec2 lod = texture(distortion[iz + 2], dist_uv).xy; -- vec2 uv = texture(distortion[iz + 0], dist_uv).xy; -- vec2 lod = texture(distortion[iz + 2], dist_uv).xy; +- vec2 r_uv = texture(distortion[iz + 0], dist_uv).xy; +- vec2 g_uv = texture(distortion[iz + 2], dist_uv).xy; +- vec2 b_uv = texture(distortion[iz + 4], dist_uv).xy; + // Do any transformation needed. + uv = transform_uv(uv, iz); - // Do any transformation needed. -- uv = transform_uv(uv, iz); +- r_uv = transform_uv(r_uv, iz); +- g_uv = transform_uv(g_uv, iz); +- b_uv = transform_uv(b_uv, iz); + // Sample the source + vec3 colour = textureLod(source[iz], uv, mix(lod.x, lod.y, 0.5)).rgb; -- // Sample the source -- vec4 colour = textureLod(source[iz], uv, mix(lod.x, lod.y, 0.5)); +- // Sample the source with distorted and chromatic-aberration corrected samples. +- vec4 colour = vec4( +- texture(source[iz], r_uv).r, +- texture(source[iz], g_uv).g, +- texture(source[iz], b_uv).b, +- 1); + colour = rgb_to_ycbcr(from_linear_to_srgb(colour)); - // Do colour correction here since there are no automatic conversion in hardware available. @@ -577,10 +584,10 @@ index 9a09c03db..461aeb4ec 100644 + imageStore(chroma, ivec2(offset.xy/2 + gl_GlobalInvocationID.xy), vec4(cbcr.x, cbcr.y, 0, 0)); } diff --git a/src/xrt/compositor/util/comp_render.h b/src/xrt/compositor/util/comp_render.h -index e6fd072be..d0733b650 100644 +index 579b91413..ad1b960cd 100644 --- a/src/xrt/compositor/util/comp_render.h +++ b/src/xrt/compositor/util/comp_render.h -@@ -166,7 +166,8 @@ struct comp_render_dispatch_data +@@ -161,7 +161,8 @@ struct comp_render_dispatch_data VkImage target_image; //! Target image view for distortion. @@ -590,7 +597,7 @@ index e6fd072be..d0733b650 100644 } cs; }; -@@ -432,7 +433,8 @@ comp_render_gfx_dispatch(struct render_gfx *render, +@@ -424,7 +425,8 @@ comp_render_gfx_dispatch(struct render_gfx *render, static inline void comp_render_cs_initial_init(struct comp_render_dispatch_data *data, VkImage target_image, @@ -600,7 +607,7 @@ index e6fd072be..d0733b650 100644 bool fast_path, bool do_timewarp) { -@@ -442,7 +444,8 @@ comp_render_cs_initial_init(struct comp_render_dispatch_data *data, +@@ -434,7 +436,8 @@ comp_render_cs_initial_init(struct comp_render_dispatch_data *data, data->do_timewarp = do_timewarp; data->cs.target_image = target_image; @@ -610,7 +617,7 @@ index e6fd072be..d0733b650 100644 } /*! -@@ -534,7 +537,8 @@ comp_render_cs_layer(struct render_compute *render, +@@ -522,7 +525,8 @@ comp_render_cs_layer(struct render_compute *render, const struct xrt_pose *world_pose, const struct xrt_pose *eye_pose, const VkImage target_image, @@ -621,10 +628,10 @@ index e6fd072be..d0733b650 100644 bool do_timewarp); diff --git a/src/xrt/compositor/util/comp_render_cs.c b/src/xrt/compositor/util/comp_render_cs.c -index fc11a0521..3db6c8d2e 100644 +index dbc2fec7e..c06dda63d 100644 --- a/src/xrt/compositor/util/comp_render_cs.c +++ b/src/xrt/compositor/util/comp_render_cs.c -@@ -430,11 +430,12 @@ crc_clear_output(struct render_compute *render, const struct comp_render_dispatc +@@ -343,11 +343,12 @@ crc_clear_output(struct render_compute *render, const struct comp_render_dispatc } @@ -642,7 +649,7 @@ index fc11a0521..3db6c8d2e 100644 } /* -@@ -480,14 +481,15 @@ crc_distortion_after_squash(struct render_compute *render, const struct comp_ren +@@ -391,14 +392,15 @@ crc_distortion_after_squash(struct render_compute *render, const struct comp_ren target_viewport_datas[i] = viewport_data; } @@ -666,7 +673,7 @@ index fc11a0521..3db6c8d2e 100644 } /// Fast path -@@ -559,7 +561,8 @@ crc_distortion_fast_path(struct render_compute *render, +@@ -470,7 +472,8 @@ crc_distortion_fast_path(struct render_compute *render, src_image_views, // src_norm_rects, // d->cs.target_image, // @@ -676,7 +683,7 @@ index fc11a0521..3db6c8d2e 100644 target_viewport_datas); // } else { render_compute_projection_timewarp( // -@@ -571,7 +574,8 @@ crc_distortion_fast_path(struct render_compute *render, +@@ -482,7 +485,8 @@ crc_distortion_fast_path(struct render_compute *render, src_fovs, // world_poses, // d->cs.target_image, // @@ -686,7 +693,7 @@ index fc11a0521..3db6c8d2e 100644 target_viewport_datas); // } } -@@ -592,7 +596,8 @@ comp_render_cs_layer(struct render_compute *render, +@@ -503,7 +507,8 @@ comp_render_cs_layer(struct render_compute *render, const struct xrt_pose *world_pose, const struct xrt_pose *eye_pose, const VkImage target_image, @@ -696,7 +703,7 @@ index fc11a0521..3db6c8d2e 100644 const struct render_viewport_data *target_view, bool do_timewarp) { -@@ -749,7 +754,8 @@ comp_render_cs_layer(struct render_compute *render, +@@ -660,7 +665,8 @@ comp_render_cs_layer(struct render_compute *render, src_samplers, // src_image_views, // cur_image, // @@ -706,7 +713,7 @@ index fc11a0521..3db6c8d2e 100644 target_view, // do_timewarp); // } -@@ -785,6 +791,7 @@ comp_render_cs_layers(struct render_compute *render, +@@ -696,6 +702,7 @@ comp_render_cs_layers(struct render_compute *render, &view->eye_pose, // view->image, // view->cs.unorm_view, // diff --git a/patches/monado/0006-Use-mipmaps-for-distortion-shader.patch b/patches/monado/0006-Use-mipmaps-for-distortion-shader.patch deleted file mode 100644 index a59214d1..00000000 --- a/patches/monado/0006-Use-mipmaps-for-distortion-shader.patch +++ /dev/null @@ -1,2764 +0,0 @@ -From 5f506fb48a7dc284bb64598617bed6d8d481b662 Mon Sep 17 00:00:00 2001 -From: galister <3123227-galister@users.noreply.gitlab.com> -Date: Thu, 31 Oct 2024 04:37:27 +0900 -Subject: [PATCH 06/11] Use mipmaps for distortion shader - ---- - src/external/CMakeLists.txt | 23 + - src/external/nvpro_pyramid/CMakeLists.txt | 5 + - src/external/nvpro_pyramid/LICENSE | 216 +++++ - src/external/nvpro_pyramid/nvpro_pyramid.glsl | 889 ++++++++++++++++++ - .../nvpro_pyramid/nvpro_pyramid_dispatch.hpp | 292 ++++++ - .../srgba8_mipmap_fast_pipeline.comp | 14 + - .../srgba8_mipmap_general_pipeline.comp | 14 + - .../nvpro_pyramid/srgba8_mipmap_preamble.glsl | 128 +++ - src/xrt/auxiliary/vk/vk_helpers.c | 1 + - src/xrt/compositor/CMakeLists.txt | 6 +- - src/xrt/compositor/main/comp_renderer.c | 58 +- - src/xrt/compositor/main/comp_settings.c | 6 + - src/xrt/compositor/main/comp_settings.h | 3 + - src/xrt/compositor/render/render_compute.c | 14 + - src/xrt/compositor/render/render_gfx.c | 6 +- - src/xrt/compositor/render/render_interface.h | 24 + - src/xrt/compositor/render/render_resources.c | 130 ++- - src/xrt/compositor/render/render_shaders.c | 24 +- - src/xrt/compositor/shaders/distortion.comp | 39 +- - src/xrt/compositor/util/comp_mipmap.cpp | 25 + - src/xrt/compositor/util/comp_mipmap.h | 22 + - src/xrt/compositor/util/comp_render.h | 12 + - src/xrt/compositor/util/comp_render_cs.c | 92 ++ - src/xrt/compositor/util/comp_render_helpers.h | 26 +- - src/xrt/compositor/util/comp_scratch.c | 69 +- - src/xrt/compositor/util/comp_scratch.h | 7 +- - 26 files changed, 2071 insertions(+), 74 deletions(-) - create mode 100644 src/external/nvpro_pyramid/CMakeLists.txt - create mode 100644 src/external/nvpro_pyramid/LICENSE - create mode 100644 src/external/nvpro_pyramid/nvpro_pyramid.glsl - create mode 100644 src/external/nvpro_pyramid/nvpro_pyramid_dispatch.hpp - create mode 100644 src/external/nvpro_pyramid/srgba8_mipmap_fast_pipeline.comp - create mode 100644 src/external/nvpro_pyramid/srgba8_mipmap_general_pipeline.comp - create mode 100644 src/external/nvpro_pyramid/srgba8_mipmap_preamble.glsl - create mode 100644 src/xrt/compositor/util/comp_mipmap.cpp - create mode 100644 src/xrt/compositor/util/comp_mipmap.h - -diff --git a/src/external/CMakeLists.txt b/src/external/CMakeLists.txt -index 6b1566e42..570d1a30f 100644 ---- a/src/external/CMakeLists.txt -+++ b/src/external/CMakeLists.txt -@@ -215,3 +215,26 @@ add_library(xrt-external-vdf INTERFACE) - target_include_directories( - xrt-external-vdf SYSTEM INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/valve-file-vdf - ) -+ -+# nvpro pyramid -+if(XRT_HAVE_VULKAN) -+ -+ spirv_shaders( -+ SHADER_HEADERS -+ SPIRV_VERSION -+ 1.3 -+ SOURCES -+ nvpro_pyramid/srgba8_mipmap_fast_pipeline.comp -+ nvpro_pyramid/srgba8_mipmap_general_pipeline.comp -+ ) -+ add_library(xrt-external-nvpro-pyramid INTERFACE -+ ${SHADER_HEADERS} -+ nvpro_pyramid/nvpro_pyramid_dispatch.hpp -+ ) -+ target_include_directories( -+ xrt-external-nvpro-pyramid SYSTEM INTERFACE -+ ${CMAKE_CURRENT_SOURCE_DIR}/nvpro_pyramid -+ ${CMAKE_CURRENT_BINARY_DIR}/nvpro_pyramid -+ ) -+ add_subdirectory(nvpro_pyramid) -+endif() -diff --git a/src/external/nvpro_pyramid/CMakeLists.txt b/src/external/nvpro_pyramid/CMakeLists.txt -new file mode 100644 -index 000000000..2d4ea96e2 ---- /dev/null -+++ b/src/external/nvpro_pyramid/CMakeLists.txt -@@ -0,0 +1,5 @@ -+# Copyright 2024, Collabora, Ltd. -+# SPDX-License-Identifier: BSL-1.0 -+ -+# CMakeLists.txt required for CMake to create the directory in the build tree. -+# Generated shaders will be placed there. -diff --git a/src/external/nvpro_pyramid/LICENSE b/src/external/nvpro_pyramid/LICENSE -new file mode 100644 -index 000000000..9a5f6e6e2 ---- /dev/null -+++ b/src/external/nvpro_pyramid/LICENSE -@@ -0,0 +1,216 @@ -+Copyright 2021 NVIDIA CORPORATION -+ -+Licensed under the Apache License, Version 2.0 (the "License"); -+you may not use this file except in compliance with the License. -+You may obtain a copy of the License at -+ -+ http://www.apache.org/licenses/LICENSE-2.0 -+ -+Unless required by applicable law or agreed to in writing, software -+distributed under the License is distributed on an "AS IS" BASIS, -+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+See the License for the specific language governing permissions and -+limitations under the License. -+ -+ -+ Apache License -+ Version 2.0, January 2004 -+ http://www.apache.org/licenses/ -+ -+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION -+ -+ 1. Definitions. -+ -+ "License" shall mean the terms and conditions for use, reproduction, -+ and distribution as defined by Sections 1 through 9 of this document. -+ -+ "Licensor" shall mean the copyright owner or entity authorized by -+ the copyright owner that is granting the License. -+ -+ "Legal Entity" shall mean the union of the acting entity and all -+ other entities that control, are controlled by, or are under common -+ control with that entity. For the purposes of this definition, -+ "control" means (i) the power, direct or indirect, to cause the -+ direction or management of such entity, whether by contract or -+ otherwise, or (ii) ownership of fifty percent (50%) or more of the -+ outstanding shares, or (iii) beneficial ownership of such entity. -+ -+ "You" (or "Your") shall mean an individual or Legal Entity -+ exercising permissions granted by this License. -+ -+ "Source" form shall mean the preferred form for making modifications, -+ including but not limited to software source code, documentation -+ source, and configuration files. -+ -+ "Object" form shall mean any form resulting from mechanical -+ transformation or translation of a Source form, including but -+ not limited to compiled object code, generated documentation, -+ and conversions to other media types. -+ -+ "Work" shall mean the work of authorship, whether in Source or -+ Object form, made available under the License, as indicated by a -+ copyright notice that is included in or attached to the work -+ (an example is provided in the Appendix below). -+ -+ "Derivative Works" shall mean any work, whether in Source or Object -+ form, that is based on (or derived from) the Work and for which the -+ editorial revisions, annotations, elaborations, or other modifications -+ represent, as a whole, an original work of authorship. For the purposes -+ of this License, Derivative Works shall not include works that remain -+ separable from, or merely link (or bind by name) to the interfaces of, -+ the Work and Derivative Works thereof. -+ -+ "Contribution" shall mean any work of authorship, including -+ the original version of the Work and any modifications or additions -+ to that Work or Derivative Works thereof, that is intentionally -+ submitted to Licensor for inclusion in the Work by the copyright owner -+ or by an individual or Legal Entity authorized to submit on behalf of -+ the copyright owner. For the purposes of this definition, "submitted" -+ means any form of electronic, verbal, or written communication sent -+ to the Licensor or its representatives, including but not limited to -+ communication on electronic mailing lists, source code control systems, -+ and issue tracking systems that are managed by, or on behalf of, the -+ Licensor for the purpose of discussing and improving the Work, but -+ excluding communication that is conspicuously marked or otherwise -+ designated in writing by the copyright owner as "Not a Contribution." -+ -+ "Contributor" shall mean Licensor and any individual or Legal Entity -+ on behalf of whom a Contribution has been received by Licensor and -+ subsequently incorporated within the Work. -+ -+ 2. Grant of Copyright License. Subject to the terms and conditions of -+ this License, each Contributor hereby grants to You a perpetual, -+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable -+ copyright license to reproduce, prepare Derivative Works of, -+ publicly display, publicly perform, sublicense, and distribute the -+ Work and such Derivative Works in Source or Object form. -+ -+ 3. Grant of Patent License. Subject to the terms and conditions of -+ this License, each Contributor hereby grants to You a perpetual, -+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable -+ (except as stated in this section) patent license to make, have made, -+ use, offer to sell, sell, import, and otherwise transfer the Work, -+ where such license applies only to those patent claims licensable -+ by such Contributor that are necessarily infringed by their -+ Contribution(s) alone or by combination of their Contribution(s) -+ with the Work to which such Contribution(s) was submitted. If You -+ institute patent litigation against any entity (including a -+ cross-claim or counterclaim in a lawsuit) alleging that the Work -+ or a Contribution incorporated within the Work constitutes direct -+ or contributory patent infringement, then any patent licenses -+ granted to You under this License for that Work shall terminate -+ as of the date such litigation is filed. -+ -+ 4. Redistribution. You may reproduce and distribute copies of the -+ Work or Derivative Works thereof in any medium, with or without -+ modifications, and in Source or Object form, provided that You -+ meet the following conditions: -+ -+ (a) You must give any other recipients of the Work or -+ Derivative Works a copy of this License; and -+ -+ (b) You must cause any modified files to carry prominent notices -+ stating that You changed the files; and -+ -+ (c) You must retain, in the Source form of any Derivative Works -+ that You distribute, all copyright, patent, trademark, and -+ attribution notices from the Source form of the Work, -+ excluding those notices that do not pertain to any part of -+ the Derivative Works; and -+ -+ (d) If the Work includes a "NOTICE" text file as part of its -+ distribution, then any Derivative Works that You distribute must -+ include a readable copy of the attribution notices contained -+ within such NOTICE file, excluding those notices that do not -+ pertain to any part of the Derivative Works, in at least one -+ of the following places: within a NOTICE text file distributed -+ as part of the Derivative Works; within the Source form or -+ documentation, if provided along with the Derivative Works; or, -+ within a display generated by the Derivative Works, if and -+ wherever such third-party notices normally appear. The contents -+ of the NOTICE file are for informational purposes only and -+ do not modify the License. You may add Your own attribution -+ notices within Derivative Works that You distribute, alongside -+ or as an addendum to the NOTICE text from the Work, provided -+ that such additional attribution notices cannot be construed -+ as modifying the License. -+ -+ You may add Your own copyright statement to Your modifications and -+ may provide additional or different license terms and conditions -+ for use, reproduction, or distribution of Your modifications, or -+ for any such Derivative Works as a whole, provided Your use, -+ reproduction, and distribution of the Work otherwise complies with -+ the conditions stated in this License. -+ -+ 5. Submission of Contributions. Unless You explicitly state otherwise, -+ any Contribution intentionally submitted for inclusion in the Work -+ by You to the Licensor shall be under the terms and conditions of -+ this License, without any additional terms or conditions. -+ Notwithstanding the above, nothing herein shall supersede or modify -+ the terms of any separate license agreement you may have executed -+ with Licensor regarding such Contributions. -+ -+ 6. Trademarks. This License does not grant permission to use the trade -+ names, trademarks, service marks, or product names of the Licensor, -+ except as required for reasonable and customary use in describing the -+ origin of the Work and reproducing the content of the NOTICE file. -+ -+ 7. Disclaimer of Warranty. Unless required by applicable law or -+ agreed to in writing, Licensor provides the Work (and each -+ Contributor provides its Contributions) on an "AS IS" BASIS, -+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -+ implied, including, without limitation, any warranties or conditions -+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A -+ PARTICULAR PURPOSE. You are solely responsible for determining the -+ appropriateness of using or redistributing the Work and assume any -+ risks associated with Your exercise of permissions under this License. -+ -+ 8. Limitation of Liability. In no event and under no legal theory, -+ whether in tort (including negligence), contract, or otherwise, -+ unless required by applicable law (such as deliberate and grossly -+ negligent acts) or agreed to in writing, shall any Contributor be -+ liable to You for damages, including any direct, indirect, special, -+ incidental, or consequential damages of any character arising as a -+ result of this License or out of the use or inability to use the -+ Work (including but not limited to damages for loss of goodwill, -+ work stoppage, computer failure or malfunction, or any and all -+ other commercial damages or losses), even if such Contributor -+ has been advised of the possibility of such damages. -+ -+ 9. Accepting Warranty or Additional Liability. While redistributing -+ the Work or Derivative Works thereof, You may choose to offer, -+ and charge a fee for, acceptance of support, warranty, indemnity, -+ or other liability obligations and/or rights consistent with this -+ License. However, in accepting such obligations, You may act only -+ on Your own behalf and on Your sole responsibility, not on behalf -+ of any other Contributor, and only if You agree to indemnify, -+ defend, and hold each Contributor harmless for any liability -+ incurred by, or claims asserted against, such Contributor by reason -+ of your accepting any such warranty or additional liability. -+ -+ END OF TERMS AND CONDITIONS -+ -+ APPENDIX: How to apply the Apache License to your work. -+ -+ To apply the Apache License to your work, attach the following -+ boilerplate notice, with the fields enclosed by brackets "[]" -+ replaced with your own identifying information. (Don't include -+ the brackets!) The text should be enclosed in the appropriate -+ comment syntax for the file format. We also recommend that a -+ file or class name and description of purpose be included on the -+ same "printed page" as the copyright notice for easier -+ identification within third-party archives. -+ -+ Copyright [yyyy] [name of copyright owner] -+ -+ Licensed under the Apache License, Version 2.0 (the "License"); -+ you may not use this file except in compliance with the License. -+ You may obtain a copy of the License at -+ -+ http://www.apache.org/licenses/LICENSE-2.0 -+ -+ Unless required by applicable law or agreed to in writing, software -+ distributed under the License is distributed on an "AS IS" BASIS, -+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ See the License for the specific language governing permissions and -+ limitations under the License. -diff --git a/src/external/nvpro_pyramid/nvpro_pyramid.glsl b/src/external/nvpro_pyramid/nvpro_pyramid.glsl -new file mode 100644 -index 000000000..6a5b17e4c ---- /dev/null -+++ b/src/external/nvpro_pyramid/nvpro_pyramid.glsl -@@ -0,0 +1,889 @@ -+// Copyright 2021 NVIDIA CORPORATION -+// SPDX-License-Identifier: Apache-2.0 -+ -+// Skeleton code for an image pyramid generation compute shader. This -+// only defines a "schedule" for doing work; you need to provide the -+// reduction (kernel) implementation and code for loading and storing -+// samples. This code is injected into nvproPyramidMain, the entry -+// point to the pyramid generation shader. -+// -+// Since GLSL doesn't really have advanced meta-programming -+// capabilities, this is all configured with preprocessor macros, -+// which must be defined before including this file. Your macros, this -+// include file, and a main function that does any needed -+// initialization before calling nvproPyramidMain, together form the -+// complete compute shader. -+// -+// When you compile the full compute pipeline, the pipeline must -+// include a 32-bit integer within its push constants; this is needed -+// to communicate to the shader which mip levels to work on. -+// By default, this push constant is at offset 0; see -+// NvproPyramidPipelines::pushConstantOffset and the -+// NVPRO_PYRAMID_PUSH_CONSTANT macro if you need to change this. -+// -+// This shader is designed to be dispatched by the host code in -+// nvpro_pyramid_dispatch.hpp -+// -+// The following macros are required: -+// -+// * NVPRO_PYRAMID_REDUCE(a0, v0, a1, v1, a2, v2, out_) -+// Set out_ to the reduction of the three inputs v0...v2, each using -+// a0...a2 as their weights. -+// -+// Please see the optional NVPRO_PYRAMID_LOAD_REDUCE4 macro as well. -+// -+// * NVPRO_PYRAMID_LOAD(coord : ivec2, level : int, out_) -+// Load the sample at the given texel and mip level, and store in out_ -+// You DO NOT have to do bounds-checking; and level is dynamically uniform. -+// Note there's nothing stopping you from loading from multiple images. -+// -+// * NVPRO_PYRAMID_STORE(coord : ivec2, level : int, in_) -+// Store the sample in_ into the given texel of the given mip level. -+// You DO NOT have to do bounds-checking; and level is dynamically uniform. -+// -+// * NVPRO_PYRAMID_TYPE -+// The data type of in_ and out_, above. -+// Recommend 32 bytes max to avoid excessive memory usage. -+// -+// * NVPRO_PYRAMID_LEVEL_SIZE(level : int) -+// Resolve to an ivec2 giving the size of the given mip level. -+// -+// * NVPRO_PYRAMID_IS_FAST_PIPELINE -+// If nonzero, this shader compiles to the pipeline stored in -+// NvproPyramidPipelines::fastPipeline. Otherwise, corresponds to pipeline -+// NvproPyramidPipelines::generalPipeline. -+// -+// NvproPyramidPipelines::generalPipeline has no special hardware requirements. -+// -+// NvproPyramidPipelines::fastPipeline requires these three abilities: -+// #extension GL_KHR_shader_subgroup_shuffle : enable -+// VkPhysicalDeviceSubgroupProperties::subgroupSize >= 16 -+// VkPhysicalDeviceSubgroupProperties::supportedOperations & VK_SUBGROUP_FEATURE_SHUFFLE_BIT -+// -+// The following macros are optional: -+// -+// * NVPRO_PYRAMID_PUSH_CONSTANT -+// If you need to declare your shader push constant manually, this macro -+// must resolve to the name of the 32-bit int variable used for push constant. -+// If not provided, the shader uses the 32-bits at offset 0. -+// Related: NvproPyramidPipelines::pushConstantOffset -+// -+// * NVPRO_PYRAMID_REDUCE2(v0, v1, out_) -+// Special case of reducing 2 samples of equal weight. -+// -+// * NVPRO_PYRAMID_REDUCE4(v00, v01, v10, v11, out_) -+// Special case of reducing a square of 4 samples of equal weight. -+// For fast pipelines only, this removes the need for NVPRO_PYRAMID_REDUCE. -+// -+// * NVPRO_PYRAMID_LOAD_REDUCE4(srcCoord : ivec2, srcLevel : int, out_) -+// Load the 2x2 texel square from srcCoord to (srcCoord + (1,1)), inclusive, -+// from mip level srcLevel. Reduce the 4 texels, and write the result to out_. -+// This can be used, for example, to take advantage of bilinear filtering. -+// For fast pipelines only, this removes the need for NVPRO_PYRAMID_LOAD. -+// -+// *********************************************************************** -+// * This macro is optional to simplify getting a minimum viable shader * -+// * in working condition, but it is STRONGLY recommended to define this * -+// * macro to use hardware samplers whenever practical. Please do not * -+// * do speed comparisons without defining NVPRO_PYRAMID_LOAD_REDUCE4!!! * -+// *********************************************************************** -+// -+// * NVPRO_PYRAMID_SHUFFLE_XOR(in_, mask_) -+// Conceptually identical to subgroupShuffleXor(in_, mask_) -+// Advanced feature, only needed for potential edge cases. -+// This macro is only used when NVPRO_PYRAMID_IS_FAST_PIPELINE != 0 -+// -+// The following must all be undefined or all be defined: -+// -+// * NVPRO_PYRAMID_SHARED_TYPE -+// The code needs to cache some texel outputs in shared memory to use -+// as inputs for subsequent mip levels. This can be used to customize -+// the cached texel type, e.g. to store a compacted reperesentation to -+// reduce memory usage. -+// -+// * NVPRO_PYRAMID_SHARED_LOAD(smem_, out_) -+// Convert the NVPRO_PYRAMID_SHARED_TYPE smem_ to NVPRO_PYRAMID_TYPE out_ -+// -+// * NVPRO_PYRAMID_SHARED_STORE(smem_, in_) -+// Convert the NVPRO_PYRAMID_TYPE in_ to NVPRO_PYRAMID_SHARED_TYPE smem_. -+// -+// Macro details: -+// -+// For function-like macros, it's guaranteed that the output does not -+// alias the inputs, and you do not have to parenthesize any -+// arguments. I parenthesize all arguments before calling your macros -+// (unless I missed a spot). -+// -+// You may optionally enclose multiple statements or variable -+// declarations in braces in function-like macros; to help with this, -+// I declare all variables in this file with an underscore suffix, to -+// avoid name collisions. -+ -+ -+ -+// Check required macros -+#ifndef NVPRO_PYRAMID_IS_FAST_PIPELINE -+#error "Missing required macro NVPRO_PYRAMID_IS_FAST_PIPELINE" -+#endif -+#ifndef NVPRO_PYRAMID_REDUCE -+ #if !defined(NVPRO_PYRAMID_REDUCE4) || !NVPRO_PYRAMID_IS_FAST_PIPELINE -+ #error "Missing required macro NVPRO_PYRAMID_REDUCE" -+ #endif -+#endif -+#ifndef NVPRO_PYRAMID_LOAD -+ #if !defined(NVPRO_PYRAMID_LOAD_REDUCE4) || !NVPRO_PYRAMID_IS_FAST_PIPELINE -+ #error "Missing required macro NVPRO_PYRAMID_LOAD" -+ #endif -+#endif -+#ifndef NVPRO_PYRAMID_STORE -+#error "Missing required macro NVPRO_PYRAMID_STORE" -+#endif -+#ifndef NVPRO_PYRAMID_TYPE -+#error "Missing required macro NVPRO_PYRAMID_TYPE" -+#endif -+#ifndef NVPRO_PYRAMID_LEVEL_SIZE -+#error "Missing required macro NVPRO_PYRAMID_LEVEL_SIZE" -+#endif -+ -+// Provide defaults for optional macros. -+#ifndef NVPRO_PYRAMID_PUSH_CONSTANT -+layout(push_constant) uniform NvproPyramidPushConstantBlock_ -+{ -+ uint nvproPyramidPushConstant_; -+}; -+#define NVPRO_PYRAMID_PUSH_CONSTANT nvproPyramidPushConstant_ -+#endif -+ -+// The mip level used as source data for the current dispatch. -+// Change nvpro_pyramid_dispatch.hpp nvproPyramidInputLevelShift if changed. -+#define NVPRO_PYRAMID_INPUT_LEVEL_ int(uint(NVPRO_PYRAMID_PUSH_CONSTANT) >> 5u) -+ -+// Number of subsequent mip levels to fill. -+#define NVPRO_PYRAMID_LEVEL_COUNT_ int(uint(NVPRO_PYRAMID_PUSH_CONSTANT) & 31u) -+ -+#ifndef NVPRO_PYRAMID_REDUCE2 -+#define NVPRO_PYRAMID_REDUCE2(v0, v1, out_) \ -+ NVPRO_PYRAMID_REDUCE(0.5, v0, 0.5, v1, 0, v1, out_) -+#endif -+ -+#ifndef NVPRO_PYRAMID_REDUCE4 -+#define NVPRO_PYRAMID_REDUCE4(v00, v01, v10, v11, out_) \ -+{ \ -+ NVPRO_PYRAMID_TYPE v0_, v1_; \ -+ NVPRO_PYRAMID_REDUCE2(v00, v01, v0_); \ -+ NVPRO_PYRAMID_REDUCE2(v10, v11, v1_); \ -+ NVPRO_PYRAMID_REDUCE2(v0_, v1_, out_); \ -+} -+#endif -+ -+#ifndef NVPRO_PYRAMID_LOAD_REDUCE4 -+#define NVPRO_PYRAMID_LOAD_REDUCE4(srcCoord_, srcLevel_, out_) \ -+{ \ -+ NVPRO_PYRAMID_TYPE v00_, v01_, v10_, v11_; \ -+ NVPRO_PYRAMID_LOAD((srcCoord_) + ivec2(0, 0), srcLevel_, v00_); \ -+ NVPRO_PYRAMID_LOAD((srcCoord_) + ivec2(0, 1), srcLevel_, v01_); \ -+ NVPRO_PYRAMID_LOAD((srcCoord_) + ivec2(1, 0), srcLevel_, v10_); \ -+ NVPRO_PYRAMID_LOAD((srcCoord_) + ivec2(1, 1), srcLevel_, v11_); \ -+ NVPRO_PYRAMID_REDUCE4(v00_, v01_, v10_, v11_, out_); \ -+} -+#endif -+ -+#if !defined(NVPRO_PYRAMID_SHUFFLE_XOR) && NVPRO_PYRAMID_IS_FAST_PIPELINE != 0 -+#define NVPRO_PYRAMID_SHUFFLE_XOR(in_, mask_) subgroupShuffleXor(in_, mask_) -+#endif -+ -+// Handle optional specialized shared memory type. -+#ifdef NVPRO_PYRAMID_SHARED_TYPE -+ #if !defined(NVPRO_PYRAMID_SHARED_LOAD) || !defined(NVPRO_PYRAMID_SHARED_STORE) -+ #error "Missing NVPRO_PYRAMID_SHARED_LOAD or NVPRO_PYRAMID_SHARED_STORE; needed when NVPRO_PYRAMID_SHARED_TYPE is defined." -+ #endif -+#else -+ #if defined(NVPRO_PYRAMID_SHARED_LOAD) || defined(NVPRO_PYRAMID_SHARED_STORE) -+ #error "Missing NVPRO_PYRAMID_SHARED_TYPE, needed when NVPRO_PYRAMID_SHARED_LOAD or NVPRO_PYRAMID_SHARED_STORE is defined." -+ #endif -+ #define NVPRO_PYRAMID_SHARED_TYPE NVPRO_PYRAMID_TYPE -+ #define NVPRO_PYRAMID_SHARED_LOAD(smem_, out_) out_ = smem_ -+ #define NVPRO_PYRAMID_SHARED_STORE(smem_, in_) smem_ = in_ -+#endif -+ -+#if NVPRO_PYRAMID_IS_FAST_PIPELINE != 0 -+ -+// Code for testing alternative designs during development, can ignore. -+#if defined(NVPRO_USE_FAST_PIPELINE_ALTERNATIVE_) && NVPRO_USE_FAST_PIPELINE_ALTERNATIVE_ != 0 -+#include "fast_pipeline_alternative.glsl" -+#else -+ -+// Efficient special case image pyramid generation kernel. Generates -+// up to 6 levels at once: each workgroup reads up to N samples (see below) -+// of the input mip level and generates the resulting samples for the next -+// up to 6 levels. Dispatch with y, z = 1. -+// -+// N = 1024 if NVPRO_PYRAMID_LEVEL_COUNT_ <= 5; 4096 otherwise. -+// -+// This only works when the input mip level has edges divisible by 2 -+// to the power of NVPRO_PYRAMID_LEVEL_COUNT_, and -+// NVPRO_PYRAMID_LEVEL_COUNT_ can be at most 6. -+// -+// TODO: Test if this works for subgroup size != 32. -+ -+layout(local_size_x = 256) in; -+ -+// Cache for the tile generated for level NVPRO_PYRAMID_INPUT_LEVEL_ + N -+// used only when NVPRO_PYRAMID_LEVEL_COUNT_ >= 4. -+// N is 3 if said level count is 4 or 5, 4 if level count is 6. -+// If level count is 5 or higher, the layout of the tile is: -+// +---+---++---+---+ -+// | 0 | 1 || 4 | 5 | -+// +---+---++---+---+ -+// | 2 | 3 || 6 | 7 | -+// +===+===++===+===+ -+// | 8 | 9 ||12 |13 | -+// +---+---++---+---+ -+// |10 |11 ||14 |15 | -+// +---+---++---+---+ -+// -+// If level count is 4, there are up to 4 consecutive tiles of layout: -+// +---+---+ -+// | 0 | 1 | -+// +---+---+ -+// | 2 | 3 | -+// +---+---+ -+// -+// These diagrams are referenced later. -+shared NVPRO_PYRAMID_SHARED_TYPE sharedTile_[16]; -+ -+ -+// Handle the tile at the given input level and offset (position -+// of upper-left corner), and write out the resulting minified tiles -+// in the next 1 to 4 mip levels (depending on levelCount_). -+// Tiles are squares with edge length 1 << levelCount_ -+// -+// Only 1 to 3 levels are supported if !sharedMemoryWrite_; -+// Only 3 to 4 levels are supported otherwise (micro-optimization). -+// -+// Must be executed by N consecutive threads with same inputs, with -+// the lowest thread number being a multiple of N; N given by -+// -+// levelCount_ 1 2 3 4 -+// N 1 4 16 16 [NOT 64] -+// -+// If sharedMemoryWrite_ == true, then the 1x1 sample generated for -+// the final output level is written to sharedTile_[sharedMemoryIdx_]. -+void handleTile_(ivec2 srcTileOffset_, int inputLevel_, uint levelCount_, -+ bool sharedMemoryWrite_, uint sharedMemoryIdx_) -+{ -+ // Discussion for levelCount_ == 3 -+ // -+ // Break the input tile into 16 2x2 sub-tiles. Each thread in the team -+ // generates 1 sample (from 4 inputs), writes them to inputLevel_ + 1. -+ // +---+---++---+---+ -+ // | 0 | 1 || 4 | 5 | -+ // +---+---++---+---+ -+ // | 2 | 3 || 6 | 7 | -+ // +===+===++===+===+ -+ // | 8 | 9 ||12 |13 | -+ // +---+---++---+---+ -+ // |10 |11 ||14 |15 | -+ // +---+---++---+---+ -+ // -+ // For levelCount_ < 3, just cut out the parts of the 8x8 tile -+ // that are not applicable. -+ // -+ // For levelCount_ == 4, the input 16x16 tile is broken into 4x4 -+ // sub-tiles in the same pattern. Each thread generates the -+ // corresponding 2x2 sub-tile of the inputLevel_ + 1 8x8 tile. -+ // The problem then reduces to the levelCount_ == 3 case. -+ NVPRO_PYRAMID_TYPE sample00_, sample01_, sample10_, sample11_, out_; -+ int dstLevel_ = inputLevel_ + 1; -+ ivec2 dstSubTile_; -+ -+ // Calculate the index of this thread within the team. -+ uint teamMask_ = levelCount_ >= 3 ? 15 : levelCount_ == 2 ? 3 : 0; -+ uint idxInTeam_ = gl_LocalInvocationIndex & teamMask_; -+ -+ // NOTE the extra sharedMemoryWrite_ requirement!!! -+ if (sharedMemoryWrite_ && levelCount_ == 4) -+ { -+ // The location of the sub-tile assigned to this thread in level inputLevel_ -+ uint xOffset_ = (idxInTeam_ & 1) << 2 | (idxInTeam_ & 4) << 1; -+ uint yOffset_ = (idxInTeam_ & 2) << 1 | (idxInTeam_ & 8); -+ ivec2 srcSubTile_ = srcTileOffset_ + ivec2(xOffset_, yOffset_); -+ dstSubTile_ = srcSubTile_ >> 1; -+ -+ // Thread calculates upper-left sample of 2x2 output sub-tile. -+ ivec2 srcCoord_, dstCoord_; -+ srcCoord_ = srcSubTile_; -+ dstCoord_ = dstSubTile_; -+ NVPRO_PYRAMID_LOAD_REDUCE4(srcCoord_, inputLevel_, sample00_); -+ NVPRO_PYRAMID_STORE(dstCoord_, dstLevel_, sample00_); -+ -+ // Thread calculates lower-left sample of 2x2 output sub-tile. -+ srcCoord_ = srcSubTile_ + ivec2(0, 2); -+ dstCoord_ = dstSubTile_ + ivec2(0, 1); -+ NVPRO_PYRAMID_LOAD_REDUCE4(srcCoord_, inputLevel_, sample01_); -+ NVPRO_PYRAMID_STORE(dstCoord_, dstLevel_, sample01_); -+ -+ // Thread calculates upper-right sample of 2x2 output sub-tile. -+ srcCoord_ = srcSubTile_ + ivec2(2, 0); -+ dstCoord_ = dstSubTile_ + ivec2(1, 0); -+ NVPRO_PYRAMID_LOAD_REDUCE4(srcCoord_, inputLevel_, sample10_); -+ NVPRO_PYRAMID_STORE(dstCoord_, dstLevel_, sample10_); -+ -+ // Thread calculates lower-right sample of 2x2 output sub-tile. -+ srcCoord_ = srcSubTile_ + ivec2(2, 2); -+ dstCoord_ = dstSubTile_ + ivec2(1, 1); -+ NVPRO_PYRAMID_LOAD_REDUCE4(srcCoord_, inputLevel_, sample11_); -+ NVPRO_PYRAMID_STORE(dstCoord_, dstLevel_, sample11_); -+ -+ // Now the full assigned 2x2 subtile has been filled, move on to -+ // the 1x1 sample of the next level assigned to this thread. -+ dstLevel_++; -+ dstSubTile_ >>= 1; -+ NVPRO_PYRAMID_REDUCE4(sample00_, sample01_, sample10_, sample11_, out_); -+ NVPRO_PYRAMID_STORE(dstSubTile_, dstLevel_, out_); -+ } -+ else // levelCount_ != 4 -+ { -+ // The location of the sub-tile assigned to this thread in the -+ // level after level inputLevel_. -+ uint xOffset_ = (idxInTeam_ & 1) << 1 | (idxInTeam_ & 4); -+ uint yOffset_ = (idxInTeam_ & 2) | (idxInTeam_ & 8) >> 1; -+ ivec2 srcSubTile_ = srcTileOffset_ + ivec2(xOffset_, yOffset_); -+ dstSubTile_ = srcSubTile_ >> 1; -+ -+ // Thread calculates the sample in that sub-tile. -+ NVPRO_PYRAMID_LOAD_REDUCE4(srcSubTile_, inputLevel_, out_); -+ NVPRO_PYRAMID_STORE(dstSubTile_, dstLevel_, out_); -+ } -+ -+ if (!sharedMemoryWrite_ && levelCount_ == 1) return; -+ -+ // The whole team computes the 2x2 tile in the next level; only 1 -+ // out of every 4 threads does this. Use shuffle to get the needed -+ // data from the other three threads. -+ dstLevel_++; -+ dstSubTile_ >>= 1; -+ sample00_ = out_; -+ sample01_ = NVPRO_PYRAMID_SHUFFLE_XOR(out_, 1); -+ sample10_ = NVPRO_PYRAMID_SHUFFLE_XOR(out_, 2); -+ sample11_ = NVPRO_PYRAMID_SHUFFLE_XOR(out_, 3); -+ -+ if (0 == (gl_SubgroupInvocationID & 3)) -+ { -+ NVPRO_PYRAMID_REDUCE4(sample00_, sample01_, sample10_, sample11_, out_); -+ NVPRO_PYRAMID_STORE(dstSubTile_, dstLevel_, out_); -+ } -+ -+ if (!sharedMemoryWrite_ && levelCount_ == 2) return; -+ -+ // Compute 1x1 "tile" in the last level handled by this function; -+ // only 1 thread per 16 does this. Shuffle again. -+ // This is also the thread that does the optional shared memory write. -+ dstLevel_++; -+ dstSubTile_ >>= 1; -+ sample00_ = out_; -+ sample01_ = NVPRO_PYRAMID_SHUFFLE_XOR(out_, 4); -+ sample10_ = NVPRO_PYRAMID_SHUFFLE_XOR(out_, 8); -+ sample11_ = NVPRO_PYRAMID_SHUFFLE_XOR(out_, 12); -+ -+ if (0 == (gl_SubgroupInvocationID & 15)) -+ { -+ NVPRO_PYRAMID_REDUCE4(sample00_, sample01_, sample10_, sample11_, out_); -+ NVPRO_PYRAMID_STORE(dstSubTile_, dstLevel_, out_); -+ if (sharedMemoryWrite_) -+ { -+ NVPRO_PYRAMID_SHARED_STORE(sharedTile_[sharedMemoryIdx_], out_); -+ } -+ } -+} -+ -+ -+void nvproPyramidMain() -+{ -+ // Cut the input mip level into square tiles of edge length -+ // 2 to the power of NVPRO_PYRAMID_LEVEL_COUNT_. -+ int levelCount_ = NVPRO_PYRAMID_LEVEL_COUNT_; -+ int inputLevel_ = NVPRO_PYRAMID_INPUT_LEVEL_; -+ ivec2 srcImageSize_ = NVPRO_PYRAMID_LEVEL_SIZE(inputLevel_); -+ uint horizontalTiles_ = uint(srcImageSize_.x) >> levelCount_; -+ uint verticalTiles_ = uint(srcImageSize_.y) >> levelCount_; -+ -+ // Calculate the team size from the level count. Each thread -+ // handles 4 inupt samples, except when levelCount_ == 6, then each -+ // handles 16 samples. -+ uint teamSizeLog2_ = min(8u, levelCount_ * 2u - 2u); -+ -+ // Assign tiles to each team. -+ uint tileIndex_ = gl_GlobalInvocationID.x >> teamSizeLog2_; -+ uint horizontalIndex_ = tileIndex_ % horizontalTiles_; -+ uint verticalIndex_ = tileIndex_ / horizontalTiles_; -+ ivec2 tileOffset_ = ivec2(horizontalIndex_, verticalIndex_) << levelCount_; -+ -+ if (levelCount_ <= 3) -+ { -+ if (verticalIndex_ < verticalTiles_) -+ { -+ // Reminder to self: can't handle 4 level case when -+ // sharedMemoryWrite_ is false. -+ handleTile_(tileOffset_, inputLevel_, levelCount_, false, 0); -+ } -+ return; -+ } -+ -+ // For 4 or more levels, team size is too big for shuffle communication. -+ // Need to split the tile into sub-tiles and teams into 16 thread sub-teams. -+ // Each sub-team writes one sample to shared memory. -+ // Refer to sharedTile_ diagram for details. -+ if (verticalIndex_ < verticalTiles_) -+ { -+ // Number of levels to fill for now. -+ int subLevelCount_ = levelCount_ == 6 ? 4 : 3; -+ -+ // Calculate the index of the sub-team within the team. -+ int subTeamMask_ = levelCount_ == 4 ? 3 : 15; -+ int subTeamIdx_ = int(gl_GlobalInvocationID.x >> 4) & subTeamMask_; -+ -+ // Location of sub-tile; they are 8x8 or 16x16 depending on subLevelCount_ -+ ivec2 subTeamOffset_; -+ subTeamOffset_.x = (subTeamIdx_ & 1) << 3 | (subTeamIdx_ & 4) << 2; -+ subTeamOffset_.y = (subTeamIdx_ & 2) << 2 | (subTeamIdx_ & 8) << 1; -+ if (subLevelCount_ == 4) -+ { -+ subTeamOffset_ <<= 1; -+ } -+ -+ // Index in shared memory that this sub-team will write to. -+ uint sharedMemoryIndex_ = (gl_GlobalInvocationID.x >> 4u) & 15u; -+ -+ // Handle the sub-tile and write the last level 1x1 sample to shared memory. -+ handleTile_(tileOffset_ + subTeamOffset_, inputLevel_, subLevelCount_, -+ true, sharedMemoryIndex_); -+ -+ // Problem reduces to handling 1 or 2 remaining levels. -+ inputLevel_ += subLevelCount_; -+ levelCount_ -= subLevelCount_; -+ } -+ -+ // Wait for shared memory to fill. -+ barrier(); -+ -+ // Handle the remaining 1 or 2 levels. -+ // Only 4 threads have to do this per workgroup (NOT per team) -+ if (gl_LocalInvocationIndex < 4) -+ { -+ NVPRO_PYRAMID_TYPE in00_, in01_, in10_, in11_, out_; -+ if (levelCount_ == 1) -+ { -+ // Handle up to 4 2x2 tiles in shared memory, 1 tile per thread. -+ // Tile location calculated for the output level (final level). -+ tileIndex_ = gl_WorkGroupID.x * 4 + gl_LocalInvocationIndex; -+ horizontalIndex_ = tileIndex_ % horizontalTiles_; -+ verticalIndex_ = tileIndex_ / horizontalTiles_; -+ tileOffset_ = ivec2(horizontalIndex_, verticalIndex_); -+ uint smemOffset_ = gl_LocalInvocationIndex * 4u; -+ -+ if (verticalIndex_ < verticalTiles_) -+ { -+ NVPRO_PYRAMID_SHARED_LOAD(sharedTile_[smemOffset_ + 0u], in00_); -+ NVPRO_PYRAMID_SHARED_LOAD(sharedTile_[smemOffset_ + 1u], in10_); -+ NVPRO_PYRAMID_SHARED_LOAD(sharedTile_[smemOffset_ + 2u], in01_); -+ NVPRO_PYRAMID_SHARED_LOAD(sharedTile_[smemOffset_ + 3u], in11_); -+ NVPRO_PYRAMID_REDUCE4(in00_, in01_, in10_, in11_, out_); -+ NVPRO_PYRAMID_STORE(tileOffset_, (inputLevel_ + 1), out_); -+ } -+ } -+ else // levelCount_ == 2 -+ { -+ // Handle the 4x4 tile in shared memory, 1 2x2 sub-tile per -+ // thread. Tile location calculated for the final output level -+ // (here we first calculate an intermediate level). -+ tileIndex_ = gl_WorkGroupID.x; -+ horizontalIndex_ = tileIndex_ % horizontalTiles_; -+ verticalIndex_ = tileIndex_ / horizontalTiles_; -+ tileOffset_ = ivec2(horizontalIndex_, verticalIndex_); -+ uint smemOffset_ = gl_LocalInvocationIndex * 4u; -+ -+ if (verticalIndex_ < verticalTiles_) -+ { -+ // Handle first level after inputLevel_ -+ NVPRO_PYRAMID_SHARED_LOAD(sharedTile_[smemOffset_ + 0u], in00_); -+ NVPRO_PYRAMID_SHARED_LOAD(sharedTile_[smemOffset_ + 1u], in10_); -+ NVPRO_PYRAMID_SHARED_LOAD(sharedTile_[smemOffset_ + 2u], in01_); -+ NVPRO_PYRAMID_SHARED_LOAD(sharedTile_[smemOffset_ + 3u], in11_); -+ NVPRO_PYRAMID_REDUCE4(in00_, in01_, in10_, in11_, out_); -+ ivec2 threadOffset_ = ivec2(gl_LocalInvocationIndex & 1, -+ (gl_LocalInvocationIndex & 2) >> 1); -+ NVPRO_PYRAMID_STORE((tileOffset_ * 2 + threadOffset_), -+ (inputLevel_ + 1), out_); -+ // Shuffle 4 samples and produce sole last level sample. -+ in00_ = out_; -+ in10_ = NVPRO_PYRAMID_SHUFFLE_XOR(out_, 1); -+ in01_ = NVPRO_PYRAMID_SHUFFLE_XOR(out_, 2); -+ in11_ = NVPRO_PYRAMID_SHUFFLE_XOR(out_, 3); -+ -+ if (gl_LocalInvocationIndex == 0u) -+ { -+ NVPRO_PYRAMID_REDUCE4(in00_, in01_, in10_, in11_, out_); -+ NVPRO_PYRAMID_STORE(tileOffset_, (inputLevel_ + 2), out_); -+ } -+ } -+ } -+ } -+} -+ -+#endif /* !NVPRO_USE_FAST_PIPELINE_ALTERNATIVE_ */ -+ -+#else /* non-fast path */ -+ -+// Code for testing alternative designs during development, can ignore. -+#if defined(NVPRO_USE_GENERAL_PIPELINE_ALTERNATIVE_) && NVPRO_USE_GENERAL_PIPELINE_ALTERNATIVE_ != 0 -+#include "general_pipeline_alternative.glsl" -+#else -+ -+// General-case shader for generating 1 or 2 levels of the mip pyramid. -+// When generating 1 level, each workgroup handles up to 128 samples of the -+// output mip level. When generating 2 levels, each workgroup handles -+// a 8x8 tile of the last (2nd) output mip level, generating up to -+// 17x17 samples of the intermediate (1st) output mip level along the way. -+// -+// Dispatch with y, z = 1 -+layout(local_size_x = 4 * 32) in; -+ -+// When generating 2 levels, the results of generating the intermediate -+// level (first level generated) are cached here; this is the input tile -+// needed to generate the 8x8 tile of the second level generated. -+shared NVPRO_PYRAMID_SHARED_TYPE sharedLevel_[17][17]; // [y][x] -+ -+ivec2 kernelSizeFromInputSize_(ivec2 inputSize_) -+{ -+ return ivec2(inputSize_.x == 1 ? 1 : (2 | (inputSize_.x & 1)), -+ inputSize_.y == 1 ? 1 : (2 | (inputSize_.y & 1))); -+} -+ -+NVPRO_PYRAMID_TYPE -+loadSample_(ivec2 srcCoord_, int srcLevel_, bool loadFromShared_); -+ -+// Handle loading and reducing a rectangle of size kernelSize_ -+// with the given upper-left coordinate srcCoord_. Samples read from -+// mip level srcLevel_ if !loadFromShared_, sharedLevel_ otherwise. -+// -+// kernelSize_ must range from 1x1 to 3x3. -+// -+// Once computed, the sample is written to the given coordinate of the -+// specified destination mip level, and returned. The destination -+// image size is needed to compute the kernel weights. -+NVPRO_PYRAMID_TYPE reduceStoreSample_(ivec2 srcCoord_, int srcLevel_, -+ bool loadFromShared_, -+ ivec2 kernelSize_, -+ ivec2 dstImageSize_, -+ ivec2 dstCoord_, int dstLevel_) -+{ -+ bool lfs_ = loadFromShared_; -+ float n_ = dstImageSize_.y; -+ float rcp_ = 1.0f / (2 * n_ + 1); -+ float w0_ = rcp_ * (n_ - dstCoord_.y); -+ float w1_ = rcp_ * n_; -+ float w2_ = 1.0f - w0_ - w1_; -+ -+ NVPRO_PYRAMID_TYPE v0_, v1_, v2_, h0_, h1_, h2_, out_; -+ -+ // Reduce vertically up to 3 times (depending on kernel horizontal size) -+ switch (kernelSize_.x) -+ { -+ case 3: -+ switch (kernelSize_.y) -+ { -+ case 3: v2_ = loadSample_(srcCoord_ + ivec2(2, 2), srcLevel_, lfs_); -+ case 2: v1_ = loadSample_(srcCoord_ + ivec2(2, 1), srcLevel_, lfs_); -+ case 1: v0_ = loadSample_(srcCoord_ + ivec2(2, 0), srcLevel_, lfs_); -+ } -+ switch (kernelSize_.y) -+ { -+ case 3: NVPRO_PYRAMID_REDUCE(w0_, v0_, w1_, v1_, w2_, v2_, h2_); break; -+ case 2: NVPRO_PYRAMID_REDUCE2(v0_, v1_, h2_); break; -+ case 1: h2_ = v0_; break; -+ } -+ // fallthru -+ case 2: -+ switch (kernelSize_.y) -+ { -+ case 3: v2_ = loadSample_(srcCoord_ + ivec2(1, 2), srcLevel_, lfs_); -+ case 2: v1_ = loadSample_(srcCoord_ + ivec2(1, 1), srcLevel_, lfs_); -+ case 1: v0_ = loadSample_(srcCoord_ + ivec2(1, 0), srcLevel_, lfs_); -+ } -+ switch (kernelSize_.y) -+ { -+ case 3: NVPRO_PYRAMID_REDUCE(w0_, v0_, w1_, v1_, w2_, v2_, h1_); break; -+ case 2: NVPRO_PYRAMID_REDUCE2(v0_, v1_, h1_); break; -+ case 1: h1_ = v0_; break; -+ } -+ case 1: -+ switch (kernelSize_.y) -+ { -+ case 3: v2_ = loadSample_(srcCoord_ + ivec2(0, 2), srcLevel_, lfs_); -+ case 2: v1_ = loadSample_(srcCoord_ + ivec2(0, 1), srcLevel_, lfs_); -+ case 1: v0_ = loadSample_(srcCoord_ + ivec2(0, 0), srcLevel_, lfs_); -+ } -+ switch (kernelSize_.y) -+ { -+ case 3: NVPRO_PYRAMID_REDUCE(w0_, v0_, w1_, v1_, w2_, v2_, h0_); break; -+ case 2: NVPRO_PYRAMID_REDUCE2(v0_, v1_, h0_); break; -+ case 1: h0_ = v0_; break; -+ } -+ } -+ -+ // Reduce up to 3 samples horizontally. -+ switch (kernelSize_.x) -+ { -+ case 3: -+ n_ = dstImageSize_.x; -+ rcp_ = 1.0f / (2 * n_ + 1); -+ w0_ = rcp_ * (n_ - dstCoord_.x); -+ w1_ = rcp_ * n_; -+ w2_ = 1.0f - w0_ - w1_; -+ NVPRO_PYRAMID_REDUCE(w0_, h0_, w1_, h1_, w2_, h2_, out_); -+ break; -+ case 2: -+ NVPRO_PYRAMID_REDUCE2(h0_, h1_, out_); -+ break; -+ case 1: -+ out_ = h0_; -+ } -+ -+ // Write out sample. -+ NVPRO_PYRAMID_STORE(dstCoord_, dstLevel_, out_); -+ return out_; -+} -+ -+NVPRO_PYRAMID_TYPE -+loadSample_(ivec2 srcCoord_, int srcLevel_, bool loadFromShared_) -+{ -+ NVPRO_PYRAMID_TYPE loaded_; -+ if (loadFromShared_) -+ { -+ NVPRO_PYRAMID_SHARED_LOAD((sharedLevel_[srcCoord_.y][srcCoord_.x]), loaded_); -+ } -+ else -+ { -+ NVPRO_PYRAMID_LOAD(srcCoord_, srcLevel_, loaded_); -+ } -+ return loaded_; -+} -+ -+ -+ -+// Compute and write out (to the 1st mip level generated) the samples -+// at coordinates -+// initDstCoord_, -+// initDstCoord_ + step_, ... -+// initDstCoord_ + (iterations_-1) * step_ -+// and cache them at in the sharedLevel_ tile at coordinates -+// initSharedCoord_, -+// initSharedCoord_ + step_, ... -+// initSharedCoord_ + (iterations_-1) * step_ -+// If boundsCheck_ is true, skip coordinates that are out of bounds. -+void intermediateLevelLoop_(ivec2 initDstCoord_, -+ ivec2 initSharedCoord_, -+ ivec2 step_, -+ int iterations_, -+ bool boundsCheck_) -+{ -+ ivec2 dstCoord_ = initDstCoord_; -+ ivec2 sharedCoord_ = initSharedCoord_; -+ int srcLevel_ = int(NVPRO_PYRAMID_INPUT_LEVEL_); -+ int dstLevel_ = srcLevel_ + 1; -+ ivec2 srcImageSize_ = NVPRO_PYRAMID_LEVEL_SIZE(srcLevel_); -+ ivec2 dstImageSize_ = NVPRO_PYRAMID_LEVEL_SIZE(dstLevel_); -+ ivec2 kernelSize_ = kernelSizeFromInputSize_(srcImageSize_); -+ -+ for (int i_ = 0; i_ < iterations_; ++i_) -+ { -+ ivec2 srcCoord_ = dstCoord_ * 2; -+ -+ // Optional bounds check. -+ if (boundsCheck_) -+ { -+ if (uint(dstCoord_.x) >= uint(dstImageSize_.x)) continue; -+ if (uint(dstCoord_.y) >= uint(dstImageSize_.y)) continue; -+ } -+ -+ bool loadFromShared_ = false; -+ NVPRO_PYRAMID_TYPE sample_ = -+ reduceStoreSample_(srcCoord_, srcLevel_, loadFromShared_, kernelSize_, -+ dstImageSize_, dstCoord_, dstLevel_); -+ -+ // Above function handles writing to the actual output; manually -+ // cache into shared memory here. -+ NVPRO_PYRAMID_SHARED_STORE((sharedLevel_[sharedCoord_.y][sharedCoord_.x]), -+ sample_); -+ dstCoord_ += step_; -+ sharedCoord_ += step_; -+ } -+} -+ -+// Function for the workgroup that handles filling the intermediate level -+// (caching it in shared memory as well). -+// -+// We need somewhere from 16x16 to 17x17 samples, depending -+// on what the kernel size for the 2nd mip level generation will be. -+// -+// dstTileCoord_ : upper left coordinate of the tile to generate. -+// boundsCheck_ : whether to skip samples that are out-of-bounds. -+void fillIntermediateTile_(ivec2 dstTileCoord_, bool boundsCheck_) -+{ -+ uint localIdx_ = int(gl_LocalInvocationIndex); -+ -+ ivec2 initThreadOffset_; -+ ivec2 step_; -+ int iterations_; -+ -+ ivec2 dstImageSize_ = -+ NVPRO_PYRAMID_LEVEL_SIZE((int(NVPRO_PYRAMID_INPUT_LEVEL_) + 1)); -+ ivec2 futureKernelSize_ = kernelSizeFromInputSize_(dstImageSize_); -+ -+ if (futureKernelSize_.x == 3) -+ { -+ if (futureKernelSize_.y == 3) -+ { -+ // Fill in 2 17x7 steps and 1 17x3 step (9 idle threads) -+ initThreadOffset_ = ivec2(localIdx_ % 17u, localIdx_ / 17u); -+ step_ = ivec2(0, 7); -+ iterations_ = localIdx_ >= 7 * 17 ? 0 : localIdx_ < 3 * 17 ? 3 : 2; -+ } -+ else // Future 3x[2,1] kernel -+ { -+ // Fill in 2 8x16 steps and 1 1x16 step -+ initThreadOffset_ = ivec2(localIdx_ / 16u, localIdx_ % 16u); -+ step_ = ivec2(8, 0); -+ iterations_ = localIdx_ < 1 * 16 ? 3 : 2; -+ } -+ } -+ else -+ { -+ if (futureKernelSize_.y == 3) -+ { -+ // Fill in 2 16x8 steps and 1 16x1 step -+ initThreadOffset_ = ivec2(localIdx_ % 16u, localIdx_ / 16u); -+ step_ = ivec2(0, 8); -+ iterations_ = localIdx_ < 1 * 16 ? 3 : 2; -+ } -+ else -+ { -+ // Fill in 2 16x8 steps -+ initThreadOffset_ = ivec2(localIdx_ % 16u, localIdx_ / 16u); -+ step_ = ivec2(0, 8); -+ iterations_ = 2; -+ } -+ } -+ -+ intermediateLevelLoop_(dstTileCoord_ + initThreadOffset_, initThreadOffset_, -+ step_, iterations_, boundsCheck_); -+} -+ -+ -+ -+// Function for the workgroup that handles filling the last level tile -+// (2nd level after the original input level), using as input the -+// tile in shared memory. -+// -+// dstTileCoord_ : upper left coordinate of the tile to generate. -+// boundsCheck_ : whether to skip samples that are out-of-bounds. -+void fillLastTile_(ivec2 dstTileCoord_, bool boundsCheck_) -+{ -+ uint localIdx_ = gl_LocalInvocationIndex; -+ -+ if (localIdx_ < 8 * 8) -+ { -+ ivec2 threadOffset_ = ivec2(localIdx_ % 8u, localIdx_ / 8u); -+ int srcLevel_ = int(NVPRO_PYRAMID_INPUT_LEVEL_) + 1; -+ int dstLevel_ = int(NVPRO_PYRAMID_INPUT_LEVEL_) + 2; -+ ivec2 srcImageSize_ = NVPRO_PYRAMID_LEVEL_SIZE(srcLevel_); -+ ivec2 dstImageSize_ = NVPRO_PYRAMID_LEVEL_SIZE(dstLevel_); -+ -+ ivec2 srcSharedCoord_ = threadOffset_ * 2; -+ bool loadFromShared_ = true; -+ ivec2 kernelSize_ = kernelSizeFromInputSize_(srcImageSize_); -+ ivec2 dstCoord_ = threadOffset_ + dstTileCoord_; -+ -+ bool inBounds_ = true; -+ if (boundsCheck_) -+ { -+ inBounds_ = (uint(dstCoord_.x) < uint(dstImageSize_.x)) -+ && (uint(dstCoord_.y) < uint(dstImageSize_.y)); -+ } -+ if (inBounds_) -+ { -+ reduceStoreSample_(srcSharedCoord_, 0, loadFromShared_, kernelSize_, -+ dstImageSize_, dstCoord_, dstLevel_); -+ } -+ } -+} -+ -+ -+ -+void nvproPyramidMain() -+{ -+ int inputLevel_ = int(NVPRO_PYRAMID_INPUT_LEVEL_); -+ -+ if (NVPRO_PYRAMID_LEVEL_COUNT_ == 1u) -+ { -+ ivec2 kernelSize_ = -+ kernelSizeFromInputSize_(NVPRO_PYRAMID_LEVEL_SIZE(inputLevel_)); -+ ivec2 dstImageSize_ = NVPRO_PYRAMID_LEVEL_SIZE((inputLevel_ + 1)); -+ ivec2 dstCoord_ = ivec2(int(gl_GlobalInvocationID.x) % dstImageSize_.x, -+ int(gl_GlobalInvocationID.x) / dstImageSize_.x); -+ ivec2 srcCoord_ = dstCoord_ * 2; -+ -+ if (dstCoord_.y < dstImageSize_.y) -+ { -+ reduceStoreSample_(srcCoord_, inputLevel_, false, kernelSize_, -+ dstImageSize_, dstCoord_, inputLevel_ + 1); -+ } -+ } -+ else // Handling two levels. -+ { -+ // Assign a 8x8 tile of mip level inputLevel_ + 2 to this workgroup. -+ int level2_ = inputLevel_ + 2; -+ ivec2 level2Size_ = NVPRO_PYRAMID_LEVEL_SIZE(level2_); -+ ivec2 tileCount_; -+ tileCount_.x = int(uint(level2Size_.x + 7) / 8u); -+ tileCount_.y = int(uint(level2Size_.y + 7) / 8u); -+ ivec2 tileIdx_ = ivec2(gl_WorkGroupID.x % uint(tileCount_.x), -+ gl_WorkGroupID.x / uint(tileCount_.x)); -+ uint localIdx_ = gl_LocalInvocationIndex; -+ -+ // Determine if bounds checking is needed; this is only the case -+ // for tiles at the right or bottom fringe that might be cut off -+ // by the image border. Note that later, I use if statements rather -+ // than passing boundsCheck_ directly to convince the compiler -+ // to inline everything. -+ bool boundsCheck_ = tileIdx_.x >= tileCount_.x - 1 || -+ tileIdx_.y >= tileCount_.y - 1; -+ -+ if (boundsCheck_) -+ { -+ // Compute the tile in level inputLevel_ + 1 that's needed to -+ // compute the above 8x8 tile. -+ fillIntermediateTile_(tileIdx_ * 2 * ivec2(8, 8), true); -+ barrier(); -+ -+ // Compute the inputLevel_ + 2 tile of size 8x8, loading -+ // inupts from shared memory. -+ fillLastTile_(tileIdx_ * ivec2(8, 8), true); -+ } -+ else -+ { -+ // Same with no bounds checking. -+ fillIntermediateTile_(tileIdx_ * 2 * ivec2(8, 8), false); -+ barrier(); -+ fillLastTile_(tileIdx_ * ivec2(8, 8), false); -+ } -+ } -+} -+ -+#endif /* !NVPRO_USE_GENERAL_PIPELINE_ALTERNATIVE_ */ -+#endif /* !NVPRO_PYRAMID_IS_FAST_PIPELINE */ -+ -+#undef NVPRO_PYRAMID_2D_REDUCE_ -+#undef NVPRO_PYRAMID_LEVEL_COUNT_ -+#undef NVPRO_PYRAMID_INPUT_LEVEL_ -diff --git a/src/external/nvpro_pyramid/nvpro_pyramid_dispatch.hpp b/src/external/nvpro_pyramid/nvpro_pyramid_dispatch.hpp -new file mode 100644 -index 000000000..a84b23843 ---- /dev/null -+++ b/src/external/nvpro_pyramid/nvpro_pyramid_dispatch.hpp -@@ -0,0 +1,292 @@ -+// Copyright 2021 NVIDIA CORPORATION -+// SPDX-License-Identifier: Apache-2.0 -+#ifndef NVPRO_SAMPLES_COMPUTE_MIPMAPS_NVPRO_PYRAMID_DISPATCH_HPP_ -+#define NVPRO_SAMPLES_COMPUTE_MIPMAPS_NVPRO_PYRAMID_DISPATCH_HPP_ -+ -+#include -+#include -+ -+// Struct for passing the pipelines and associated data for the mipmap -+// dispatch function. -+// -+// generalPipeline: compute pipeline, created as described in -+// nvpro_pyramid.glsl with NVPRO_PYRAMID_IS_FAST_PIPELINE defined as 0. -+// Mandatory; see nvproPyramidDefaultFastDispatcher if you want to use -+// fastPipeline alone and handle the non-fast case yourself in an alternate way. -+// -+// fastPipeline: optional (may be VK_NULL_HANDLE). -+// Compute pipeline, created as described in nvpro_pyramid.glsl -+// with NVPRO_PYRAMID_IS_FAST_PIPELINE defined as nonzero. -+// Must be VK_NULL_HANDLE if the executing device lacks the needed -+// features (see nvpro_pyramid.glsl). -+// -+// layout: shared pipeline layout for both pipelines. -+// -+// pushConstantOffset: offset of the 32-bit push constant needed by -+// nvpro_pyramid.glsl; this must be 0 if the user did not manually -+// override the default push constant by defining NVPRO_PYRAMID_PUSH_CONSTANT. -+struct NvproPyramidPipelines -+{ -+ VkPipeline generalPipeline; -+ VkPipeline fastPipeline; -+ VkPipelineLayout layout; -+ uint32_t pushConstantOffset; -+}; -+ -+// Record commands for dispatching the compute shaders in NvproPyramidPipelines -+// that are appropriate for an image with the given base mip width, -+// height, and mip levels (defaults to the maximum number of mip -+// levels theoretically allowed for the given image size). -+// -+// This handles: -+// -+// * Recording dispatch commands -+// * Binding compute pipelines -+// * Inserting appropriate barriers strictly between dispatches -+// -+// The caller is responsible for: -+// -+// * Performing any needed synchronization before and after -+// * Binding any needed descriptor sets -+// * Setting any needed push constants, except the push constant declared -+// by NVPRO_PYRAMID_PUSH_CONSTANT (if any) -+inline void nvproCmdPyramidDispatch(VkCommandBuffer cmdBuf, -+ NvproPyramidPipelines pipelines, -+ uint32_t baseWidth, -+ uint32_t baseHeight, -+ uint32_t mipLevels = 0u); -+ -+// Struct used for tracking the progress of scheduling mipmap -+// generation commands. -+struct NvproPyramidState -+{ -+ // Input level for the next dispatch. -+ uint32_t currentLevel; -+ -+ // Levels that remain to be filled, i.e. -+ // nvproCmdPyramidDispatch::mipLevels - currentLevel - 1. -+ // Will never be 0 when passed to an nvpro_pyramid_dispatcher_t instance. -+ uint32_t remainingLevels; -+ -+ // Width and height of mip level currentLevel. -+ uint32_t currentX, currentY; -+}; -+ -+constexpr uint32_t nvproPyramidInputLevelShift = 5u; // TODO Use consistently -+ -+ -+// Callback host function for a pipeline. Attempt to record commands -+// for one bind and dispatch of the given pipeline, which may be -+// VK_NULL_HANDLE (to indicate that the pipeline is already bound and -+// need not be bound again). This function should not record any barriers. -+// -+// The return value is the number of mip levels filled by the dispatch. -+// -+// If this is a callback for a fast pipeline, this may fail (return 0) -+// if the pipeline is not suitable (e.g. the current mip level fails -+// some divisibility requirements). -+// -+// Callbacks for general pipelines must never return 0. -+// -+// This function may set the 32-bit push constant at offset -+// `pushConstantOffset` (and no other push constant). It may use this -+// push constant as it sees fit, but the NVPRO_PYRAMID_INPUT_LEVEL_ -+// and NVPRO_PYRAMID_LEVEL_COUNT_ macros assume -+// -+// { input level } << nvproPyramidInputLevelShift | { levels filled } -+typedef uint32_t (*nvpro_pyramid_dispatcher_t)(VkCommandBuffer cmdBuf, -+ VkPipelineLayout layout, -+ uint32_t pushConstantOffset, -+ VkPipeline pipelineIfNeeded, -+ const NvproPyramidState& state); -+ -+// Base implementation function for the typical user-facing -+// nvproCmdPyramidDispatch. Try to use the fastPipeline if possible, -+// then fall back to the general pipeline if not usable. -+inline void -+nvproCmdPyramidDispatch(VkCommandBuffer cmdBuf, -+ NvproPyramidPipelines pipelines, -+ uint32_t baseWidth, -+ uint32_t baseHeight, -+ uint32_t mipLevels, -+ nvpro_pyramid_dispatcher_t generalDispatcher, -+ nvpro_pyramid_dispatcher_t fastDispatcher) -+{ -+ VkMemoryBarrier barrier{ -+ VK_STRUCTURE_TYPE_MEMORY_BARRIER, 0, -+ VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT}; -+ if (mipLevels == 0) -+ { -+ uint32_t srcWidth = baseWidth, srcHeight = baseHeight; -+ while (srcWidth != 0 || srcHeight != 0) -+ { -+ srcWidth >>= 1; -+ srcHeight >>= 1; -+ ++mipLevels; -+ } -+ } -+ NvproPyramidState state; -+ state.currentLevel = 0u; -+ state.remainingLevels = mipLevels - 1u; -+ state.currentX = baseWidth; -+ state.currentY = baseHeight; -+ -+ VkPipeline fastPipelineIfNeeded = pipelines.fastPipeline; -+ VkPipeline generalPipelineIfNeeded = pipelines.generalPipeline; -+ -+ while (1) -+ { -+ uint32_t levelsDone = 0; -+ -+ // Try to use the fast pipeline if possible. -+ if (pipelines.fastPipeline) -+ { -+ levelsDone = -+ fastDispatcher(cmdBuf, pipelines.layout, pipelines.pushConstantOffset, -+ fastPipelineIfNeeded, state); -+ } -+ -+ if (levelsDone != 0) -+ { -+ fastPipelineIfNeeded = VK_NULL_HANDLE; -+ generalPipelineIfNeeded = pipelines.generalPipeline; -+ } -+ else -+ { -+ // Otherwise fall back on general pipeline. -+ levelsDone = generalDispatcher(cmdBuf, pipelines.layout, -+ pipelines.pushConstantOffset, -+ generalPipelineIfNeeded, state); -+ -+ fastPipelineIfNeeded = pipelines.fastPipeline; -+ generalPipelineIfNeeded = VK_NULL_HANDLE; -+ } -+ assert(levelsDone != 0); -+ -+ // Update the progress. -+ assert(levelsDone <= state.remainingLevels); -+ state.currentLevel += levelsDone; -+ state.remainingLevels -= levelsDone; -+ state.currentX >>= levelsDone; -+ state.currentX = state.currentX ? state.currentX : 1u; -+ state.currentY >>= levelsDone; -+ state.currentY = state.currentY ? state.currentY : 1u; -+ -+ // Put barriers only between dispatches. -+ if (state.remainingLevels == 0u) break; -+ vkCmdPipelineBarrier(cmdBuf, -+ VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, -+ VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, -+ 0, 1, &barrier, 0, 0, 0, 0); -+ } -+} -+ -+ -+// nvpro_pyramid_dispatcher_t implementation for nvpro_pyramid.glsl -+// shaders with NVPRO_PYRAMID_IS_FAST_PIPELINE != 0 -+// -+// Note: this function is referenced by name in ComputeMipmapPipeline::cmdBindGenerate -+template -+static uint32_t -+nvproPyramidDefaultFastDispatcher(VkCommandBuffer cmdBuf, -+ VkPipelineLayout layout, -+ uint32_t pushConstantOffset, -+ VkPipeline pipelineIfNeeded, -+ const NvproPyramidState& state) -+{ -+ // For maybequad pipeline. -+ static_assert(DivisibilityRequirement > 0 && DivisibilityRequirement % 2 == 0, -+ "Can only handle even sizes."); -+ bool success = state.currentX % DivisibilityRequirement == 0u -+ && state.currentY % DivisibilityRequirement == 0u; -+ if (success) -+ { -+ if (pipelineIfNeeded) -+ { -+ vkCmdBindPipeline(cmdBuf, VK_PIPELINE_BIND_POINT_COMPUTE, -+ pipelineIfNeeded); -+ } -+ -+ // Choose the number of levels to fill. -+ static_assert(MaxLevels <= 6, "Can only handle up to 6 levels"); -+ uint32_t x = state.currentX, y = state.currentY; -+ uint32_t levels = 0u; -+ while (x % 2u == 0u && y % 2u == 0u && levels < state.remainingLevels -+ && levels < MaxLevels) -+ { -+ x /= 2u; -+ y /= 2u; -+ levels++; -+ } -+ uint32_t srcLevel = state.currentLevel; -+ uint32_t pc = srcLevel << nvproPyramidInputLevelShift | levels; -+ vkCmdPushConstants(cmdBuf, layout, VK_SHADER_STAGE_COMPUTE_BIT, -+ pushConstantOffset, sizeof pc, &pc); -+ // Each workgroup handles up to 4096 input samples if levels > 5; 1024 otherwise. -+ uint32_t shift = levels > 5 ? 12u : 10u; -+ uint32_t mask = levels > 5 ? 4095u : 1023u; -+ uint32_t samples = state.currentX * state.currentY; -+ vkCmdDispatch(cmdBuf, (samples + mask) >> shift, 1u, 1u); -+ return levels; -+ } -+ return 0u; -+} -+ -+ -+// nvpro_pyramid_dispatcher_t implementation for nvpro_pyramid.glsl -+// shaders with NVPRO_PYRAMID_IS_FAST_PIPELINE == 0 -+inline uint32_t -+nvproPyramidDefaultGeneralDispatcher(VkCommandBuffer cmdBuf, -+ VkPipelineLayout layout, -+ uint32_t pushConstantOffset, -+ VkPipeline pipelineIfNeeded, -+ const NvproPyramidState& state) -+{ -+ // Use py2_4_8_8 pipeline parameters. -+ constexpr uint32_t MaxLevels = 2, Warps = 4, TileWidth = 8, TileHeight = 8; -+ -+ if (pipelineIfNeeded) -+ { -+ vkCmdBindPipeline(cmdBuf, VK_PIPELINE_BIND_POINT_COMPUTE, -+ pipelineIfNeeded); -+ } -+ static_assert(MaxLevels <= 2u && MaxLevels != 0, "can do 1 or 2 levels"); -+ uint32_t levels = -+ state.remainingLevels >= MaxLevels ? MaxLevels : state.remainingLevels; -+ uint32_t srcLevel = state.currentLevel; -+ uint32_t pc = srcLevel << nvproPyramidInputLevelShift | levels; -+ vkCmdPushConstants(cmdBuf, layout, VK_SHADER_STAGE_COMPUTE_BIT, -+ pushConstantOffset, sizeof pc, &pc); -+ uint32_t dstWidth = state.currentX >> levels; -+ dstWidth = dstWidth ? dstWidth : 1u; -+ uint32_t dstHeight = state.currentY >> levels; -+ dstHeight = dstHeight ? dstHeight : 1u; -+ -+ if (levels == 1u) -+ { -+ // Each thread writes one sample. -+ uint32_t samples = dstWidth * dstHeight; -+ uint32_t threads = Warps * 32u; -+ vkCmdDispatch(cmdBuf, (samples + (threads - 1u)) / threads, 1u, 1u); -+ } -+ else -+ { -+ // Each workgroup handles a tile. -+ uint32_t horizontalTiles = (dstWidth + (TileWidth - 1)) / TileWidth; -+ uint32_t verticalTiles = (dstHeight + (TileHeight - 1)) / TileHeight; -+ vkCmdDispatch(cmdBuf, horizontalTiles * verticalTiles, 1u, 1u); -+ } -+ return levels; -+} -+ -+inline void nvproCmdPyramidDispatch(VkCommandBuffer cmdBuf, -+ NvproPyramidPipelines pipelines, -+ uint32_t baseWidth, -+ uint32_t baseHeight, -+ uint32_t mipLevels) -+{ -+ nvproCmdPyramidDispatch(cmdBuf, pipelines, baseWidth, baseHeight, mipLevels, -+ nvproPyramidDefaultGeneralDispatcher, -+ nvproPyramidDefaultFastDispatcher); -+} -+#endif -diff --git a/src/external/nvpro_pyramid/srgba8_mipmap_fast_pipeline.comp b/src/external/nvpro_pyramid/srgba8_mipmap_fast_pipeline.comp -new file mode 100644 -index 000000000..71d09b894 ---- /dev/null -+++ b/src/external/nvpro_pyramid/srgba8_mipmap_fast_pipeline.comp -@@ -0,0 +1,14 @@ -+// Copyright 2021 NVIDIA CORPORATION -+// SPDX-License-Identifier: Apache-2.0 -+#version 460 -+#extension GL_GOOGLE_include_directive : enable -+#extension GL_KHR_shader_subgroup_shuffle : enable -+ -+#define NVPRO_PYRAMID_IS_FAST_PIPELINE 1 -+#include "srgba8_mipmap_preamble.glsl" -+#include "nvpro_pyramid.glsl" -+ -+void main() -+{ -+ nvproPyramidMain(); -+} -diff --git a/src/external/nvpro_pyramid/srgba8_mipmap_general_pipeline.comp b/src/external/nvpro_pyramid/srgba8_mipmap_general_pipeline.comp -new file mode 100644 -index 000000000..e8e7a85e7 ---- /dev/null -+++ b/src/external/nvpro_pyramid/srgba8_mipmap_general_pipeline.comp -@@ -0,0 +1,14 @@ -+// Copyright 2021 NVIDIA CORPORATION -+// SPDX-License-Identifier: Apache-2.0 -+#version 460 -+#extension GL_GOOGLE_include_directive : enable -+/* #extension GL_KHR_shader_subgroup_shuffle : enable */ -+ -+#define NVPRO_PYRAMID_IS_FAST_PIPELINE 0 -+#include "srgba8_mipmap_preamble.glsl" -+#include "nvpro_pyramid.glsl" -+ -+void main() -+{ -+ nvproPyramidMain(); -+} -diff --git a/src/external/nvpro_pyramid/srgba8_mipmap_preamble.glsl b/src/external/nvpro_pyramid/srgba8_mipmap_preamble.glsl -new file mode 100644 -index 000000000..524a74120 ---- /dev/null -+++ b/src/external/nvpro_pyramid/srgba8_mipmap_preamble.glsl -@@ -0,0 +1,128 @@ -+// Copyright 2021 NVIDIA CORPORATION -+// SPDX-License-Identifier: Apache-2.0 -+ -+// Defines the pipeline interface and macros for nvproPyramidMain for -+// the srgba8-mipmap-generation shader; EXCEPT that -+// NVPRO_PYRAMID_IS_FAST_PIPELINE is not defined. -+ -+// ************************************************************************ -+// Input: Entire sRGBA8 texture with bilinear filtering. -+layout(set=0, binding=0) uniform sampler2D srgbTex; -+// Output: Same texture, imageMipLevels[n] refers to mip level n. -+// Requires manual linear (vec4) color to sRGBA8 conversion. -+layout(set=0, binding=1, rgba8ui) uniform writeonly uimage2D imageMipLevels[16]; -+ -+// ************************************************************************ -+// Mandatory macros, except NVPRO_PYRAMID_IS_FAST_PIPELINE -+uvec4 srgbFromLinearVec(vec4 arg); -+ -+#define NVPRO_PYRAMID_TYPE vec4 -+ -+#define NVPRO_PYRAMID_LOAD(coord, level, out_) \ -+ out_ = texelFetch(srgbTex, coord, level) -+ -+#define NVPRO_PYRAMID_REDUCE(a0, v0, a1, v1, a2, v2, out_) \ -+ out_ = a0 * v0 + a1 * v1 + a2 * v2 -+ -+#define NVPRO_PYRAMID_STORE(coord, level, in_) \ -+ imageStore(imageMipLevels[level], coord, srgbFromLinearVec(in_)) -+ -+ivec2 levelSize(int level) { return imageSize(imageMipLevels[level]); } -+#define NVPRO_PYRAMID_LEVEL_SIZE levelSize -+ -+// ************************************************************************ -+// Optional macros (including recommended NVPRO_PYRAMID_LOAD_REDUCE4) -+#define NVPRO_PYRAMID_REDUCE2(v0, v1, out_) out_ = 0.5 * (v0 + v1) -+ -+#define NVPRO_PYRAMID_REDUCE4(v00, v01, v10, v11, out_) \ -+ out_ = 0.25 * ((v00 + v01) + (v10 + v11)) -+ -+#if !defined(USE_BILINEAR_SAMPLING) || USE_BILINEAR_SAMPLING -+ void loadReduce4(in ivec2 srcTexelCoord, in int srcLevel, out vec4 out_) -+ { -+ // Construct the normalized coordinate in the exact center of the 4 -+ // texels we want and use it to sample the input texture. -+ // +--+--+ -- srcTexelCoord.y / imageSize.y -+ // | | | -+ // +--X <--- normCoord -+ // | | | -+ // +--+--+ -- (srcTexelCoord.y + 2) / imageSize.y -+ // | | -+ // | (srcTexelCoord.x + 2) / imageSize.x -+ // srcTexelCoord.x / imageSize.x -+ vec2 normCoord = (vec2(srcTexelCoord) + vec2(1)) -+ / vec2(imageSize(imageMipLevels[srcLevel])); -+ out_ = textureLod(srgbTex, normCoord, srcLevel); -+ } -+ #define NVPRO_PYRAMID_LOAD_REDUCE4 loadReduce4 -+#endif -+ -+#if defined(SRGB_SHARED) && SRGB_SHARED -+ #define RED_SHIFT 0 -+ #define GREEN_SHIFT 8 -+ #define BLUE_SHIFT 16 -+ #define ALPHA_SHIFT 24 -+ #define NVPRO_PYRAMID_SHARED_TYPE uint -+ -+ // Convert float (0-1) sRGB red/green/blue component value to linear. -+ float linearFromSrgbComponent(float srgb) -+ { -+ return srgb <= 0.04045 ? srgb * (25 / 323.) -+ : pow((200 * srgb + 11) * (1/211.), 2.4); -+ } -+ -+ // Convert linear red/green/blue component to float (0-1) sRGB -+ float srgbComponentFromLinear(float linear) -+ { -+ return linear <= 0.0031308 ? (323 / 25.) * linear -+ : 1.055 * pow(linear, 1 / 2.4) - 0.055; -+ } -+ -+ void srgbUnpack(in uint srgbPacked, out vec4 linearColor) -+ { -+ vec4 srgba = unpackUnorm4x8(srgbPacked); -+ linearColor.r = linearFromSrgbComponent(srgba.r); -+ linearColor.g = linearFromSrgbComponent(srgba.g); -+ linearColor.b = linearFromSrgbComponent(srgba.b); -+ linearColor.a = srgba.a; -+ } -+ #define NVPRO_PYRAMID_SHARED_LOAD srgbUnpack -+ -+ void srgbPack(out uint srgbPacked, in vec4 linearColor) -+ { -+ vec4 srgba; -+ srgba.r = srgbComponentFromLinear(linearColor.r); -+ srgba.g = srgbComponentFromLinear(linearColor.g); -+ srgba.b = srgbComponentFromLinear(linearColor.b); -+ srgba.a = linearColor.a; -+ srgbPacked = packUnorm4x8(srgba); -+ } -+ #define NVPRO_PYRAMID_SHARED_STORE srgbPack -+#endif -+ -+#if defined(F16_SHARED) && F16_SHARED -+ // Requires GL_EXT_shader_explicit_arithmetic_types -+ #define NVPRO_PYRAMID_SHARED_TYPE f16vec4 -+ #define NVPRO_PYRAMID_SHARED_LOAD(smem_, out_) out_ = vec4(smem_) -+ #define NVPRO_PYRAMID_SHARED_STORE(smem_, in_) smem_ = f16vec4(in_) -+#endif -+ -+uint srgbFromLinearBias(float arg, float bias) -+{ -+ float srgb = arg <= 0.0031308 ? (323/25.) * arg -+ : 1.055 * pow(arg, 1/2.4) - 0.055; -+ return uint(clamp(srgb * 255. + bias, 0, 255)); -+} -+ -+// Convert float linear red/green/blue value to 8-bit sRGB component. -+uint srgbFromLinear(float arg) -+{ -+ return srgbFromLinearBias(arg, 0.5); -+} -+ -+uvec4 srgbFromLinearVec(vec4 arg) -+{ -+ uint alpha = clamp(uint(arg.a * 255.0f + 0.5f), 0u, 255u); -+ return uvec4(srgbFromLinear(arg.r), srgbFromLinear(arg.g), -+ srgbFromLinear(arg.b), alpha); -+} -diff --git a/src/xrt/auxiliary/vk/vk_helpers.c b/src/xrt/auxiliary/vk/vk_helpers.c -index 3aebad12a..7e6630d4d 100644 ---- a/src/xrt/auxiliary/vk/vk_helpers.c -+++ b/src/xrt/auxiliary/vk/vk_helpers.c -@@ -1382,6 +1382,7 @@ vk_create_sampler(struct vk_bundle *vk, VkSamplerAddressMode clamp_mode, VkSampl - .addressModeW = clamp_mode, - .borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK, - .unnormalizedCoordinates = VK_FALSE, -+ .maxLod = VK_LOD_CLAMP_NONE, - }; - - ret = vk->vkCreateSampler(vk->device, &info, NULL, &sampler); -diff --git a/src/xrt/compositor/CMakeLists.txt b/src/xrt/compositor/CMakeLists.txt -index f1c54ed4d..3bc9302f7 100644 ---- a/src/xrt/compositor/CMakeLists.txt -+++ b/src/xrt/compositor/CMakeLists.txt -@@ -127,7 +127,7 @@ if(XRT_HAVE_VULKAN) - target_link_libraries( - comp_render - PUBLIC xrt-interfaces aux_vk -- PRIVATE aux_util aux_os -+ PRIVATE aux_util aux_os xrt-external-nvpro-pyramid - ) - # So it can be used without any other compositor libraries. - target_include_directories(comp_render PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) -@@ -146,6 +146,8 @@ if(XRT_HAVE_VULKAN) - comp_util STATIC - util/comp_base.h - util/comp_base.c -+ util/comp_mipmap.h -+ util/comp_mipmap.cpp - util/comp_layer_accum.h - util/comp_layer_accum.c - util/comp_render.h -@@ -166,7 +168,7 @@ if(XRT_HAVE_VULKAN) - target_link_libraries( - comp_util - PUBLIC xrt-interfaces -- PRIVATE aux_util aux_os aux_vk comp_render -+ PRIVATE aux_util aux_os aux_vk comp_render xrt-external-nvpro-pyramid - ) - target_include_directories(comp_util PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) - endif() -diff --git a/src/xrt/compositor/main/comp_renderer.c b/src/xrt/compositor/main/comp_renderer.c -index 6df4d2b29..89982e654 100644 ---- a/src/xrt/compositor/main/comp_renderer.c -+++ b/src/xrt/compositor/main/comp_renderer.c -@@ -366,6 +366,9 @@ renderer_build_rendering_target_resources(struct comp_renderer *r, - VkImageView image_view = r->c->target->images[index].view; - VkExtent2D extent = {r->c->target->width, r->c->target->height}; - -+ if (r->settings->use_compute) -+ return; -+ - render_gfx_target_resources_init( // - rtr, // - &c->nr, // -@@ -574,12 +577,16 @@ renderer_init(struct comp_renderer *r, struct comp_compositor *c, VkExtent2D scr - VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); // final_layout - - for (uint32_t i = 0; i < c->nr.view_count; i++) { -- bret = comp_scratch_single_images_ensure(&r->c->scratch.views[i], &r->c->base.vk, scratch_extent); -+ bret = comp_scratch_single_images_ensure(&r->c->scratch.views[i], &r->c->base.vk, scratch_extent, -+ r->settings->mip_levels); - if (!bret) { - COMP_ERROR(c, "comp_scratch_single_images_ensure: false"); - assert(false && "Whelp, can't return an error. But should never really fail."); - } - -+ if (r->settings->use_compute) -+ continue; -+ - for (uint32_t k = 0; k < COMP_SCRATCH_NUM_IMAGES; k++) { - struct render_scratch_color_image *rsci = &c->scratch.views[i].images[k]; - -@@ -919,18 +926,19 @@ dispatch_graphics(struct comp_renderer *r, - // Scratch image covers the whole image. - struct xrt_normalized_rect layer_norm_rect = {.x = 0.0f, .y = 0.0f, .w = 1.0f, .h = 1.0f}; - -- comp_render_gfx_add_view( // -- &data, // -- &world_poses[i], // -- &eye_poses[i], // -- &fovs[i], // -- rsci_rtr, // -- &layer_viewport_data, // -- &layer_norm_rect, // -- rsci->image, // -- rsci->srgb_view, // -- &vertex_rots[i], // -- &viewport_datas[i]); // target_viewport_data -+ comp_render_gfx_add_view( // -+ &data, // -+ &world_poses[i], // -+ &eye_poses[i], // -+ &fovs[i], // -+ rsci_rtr, // -+ &layer_viewport_data, // -+ &layer_norm_rect, // -+ rsci->image, // -+ rsci->srgb_view, // -+ scratch_view->info.mip_count, // -+ &vertex_rots[i], // -+ &viewport_datas[i]); // target_viewport_data - - if (layer_count == 0) { - crss->views[i].used = false; -@@ -1037,17 +1045,19 @@ dispatch_compute(struct comp_renderer *r, - // Scratch image covers the whole image. - struct xrt_normalized_rect layer_norm_rect = {.x = 0.0f, .y = 0.0f, .w = 1.0f, .h = 1.0f}; - -- comp_render_cs_add_view( // -- &data, // -- &world_poses[i], // -- &eye_poses[i], // -- &fovs[i], // -- &layer_viewport_data, // -- &layer_norm_rect, // -- rsci->image, // -- rsci->srgb_view, // -- rsci->unorm_view, // -- &views[i]); // target_viewport_data -+ comp_render_cs_add_view( // -+ &data, // -+ &world_poses[i], // -+ &eye_poses[i], // -+ &fovs[i], // -+ &layer_viewport_data, // -+ &layer_norm_rect, // -+ rsci->image, // -+ rsci->srgb_view, // -+ rsci->unorm_view, // -+ rsci->mip_views, // -+ scratch_view->info.mip_count, // -+ &views[i]); // target_viewport_data - - if (layer_count == 0) { - crss->views[i].used = false; -diff --git a/src/xrt/compositor/main/comp_settings.c b/src/xrt/compositor/main/comp_settings.c -index 7aad08906..0fb1da013 100644 ---- a/src/xrt/compositor/main/comp_settings.c -+++ b/src/xrt/compositor/main/comp_settings.c -@@ -30,6 +30,7 @@ DEBUG_GET_ONCE_BOOL_OPTION(xcb_fullscreen, "XRT_COMPOSITOR_XCB_FULLSCREEN", fals - DEBUG_GET_ONCE_NUM_OPTION(xcb_display, "XRT_COMPOSITOR_XCB_DISPLAY", -1) - DEBUG_GET_ONCE_NUM_OPTION(default_framerate, "XRT_COMPOSITOR_DEFAULT_FRAMERATE", 60) - DEBUG_GET_ONCE_BOOL_OPTION(compute, "XRT_COMPOSITOR_COMPUTE", USE_COMPUTE_DEFAULT) -+DEBUG_GET_ONCE_NUM_OPTION(distortion_mip_levels, "XRT_DISTORTION_MIP_LEVELS", 1) - // clang-format on - - static inline void -@@ -81,6 +82,8 @@ comp_settings_init(struct comp_settings *s, struct xrt_device *xdev) - - // Untested: Super constrained platforms. - add_format(s, VK_FORMAT_A1R5G5B5_UNORM_PACK16); -+ -+ s->mip_levels = debug_get_num_option_distortion_mip_levels(); - } else { - #if defined(XRT_OS_ANDROID) - /* -@@ -109,6 +112,9 @@ comp_settings_init(struct comp_settings *s, struct xrt_device *xdev) - - // Seen as the only sRGB format on some NVIDIA cards. - add_format(s, VK_FORMAT_A8B8G8R8_SRGB_PACK32); -+ -+ // mipmaps not supported on graphics pipeline -+ s->mip_levels = 1; - } - - s->display = debug_get_num_option_xcb_display(); -diff --git a/src/xrt/compositor/main/comp_settings.h b/src/xrt/compositor/main/comp_settings.h -index 2766b9228..b3d20c451 100644 ---- a/src/xrt/compositor/main/comp_settings.h -+++ b/src/xrt/compositor/main/comp_settings.h -@@ -107,6 +107,9 @@ struct comp_settings - - //! Try to choose the mode with this index for direct mode - int desired_mode; -+ -+ //! Number of mip levels for distortion, 0 for full mipmaps, only when using compute -+ int mip_levels; - }; - - /*! -diff --git a/src/xrt/compositor/render/render_compute.c b/src/xrt/compositor/render/render_compute.c -index 27b1953cf..131b97066 100644 ---- a/src/xrt/compositor/render/render_compute.c -+++ b/src/xrt/compositor/render/render_compute.c -@@ -315,6 +315,17 @@ render_compute_init(struct render_compute *render, struct render_resources *r) - - VK_NAME_DESCRIPTOR_SET(vk, render->shared_descriptor_set, "render_compute shared descriptor set"); - -+ for (uint32_t i = 0; i < ARRAY_SIZE(render->mip_descriptor_set); ++i) { -+ ret = vk_create_descriptor_set( // -+ vk, // vk_bundle -+ r->compute.descriptor_pool, // descriptor_pool -+ r->compute.mipmap.descriptor_set_layout, // descriptor_set_layout -+ &render->mip_descriptor_set[i]); // descriptor_set -+ VK_CHK_WITH_RET(ret, "vk_create_descriptor_set", false); -+ VK_NAME_DESCRIPTOR_SET(vk, render->mip_descriptor_set[i], "render_compute mipmap descriptor set"); -+ } -+ -+ - return true; - } - -@@ -377,6 +388,9 @@ render_compute_fini(struct render_compute *render) - - struct vk_bundle *vk = vk_from_render(render); - -+ for (uint32_t i = 0; i < ARRAY_SIZE(render->mip_descriptor_set); i++) { -+ render->mip_descriptor_set[i] = VK_NULL_HANDLE; -+ } - // Reclaimed by vkResetDescriptorPool. - render->shared_descriptor_set = VK_NULL_HANDLE; - for (uint32_t i = 0; i < ARRAY_SIZE(render->layer_descriptor_sets); i++) { -diff --git a/src/xrt/compositor/render/render_gfx.c b/src/xrt/compositor/render/render_gfx.c -index d1a155e1d..a06ac2ba1 100644 ---- a/src/xrt/compositor/render/render_gfx.c -+++ b/src/xrt/compositor/render/render_gfx.c -@@ -942,9 +942,11 @@ render_gfx_target_resources_init(struct render_gfx_target_resources *rtr, - void - render_gfx_target_resources_fini(struct render_gfx_target_resources *rtr) - { -- struct vk_bundle *vk = vk_from_rtr(rtr); -+ if (rtr->r) { -+ struct vk_bundle *vk = vk_from_rtr(rtr); - -- D(Framebuffer, rtr->framebuffer); -+ D(Framebuffer, rtr->framebuffer); -+ } - - U_ZERO(rtr); - } -diff --git a/src/xrt/compositor/render/render_interface.h b/src/xrt/compositor/render/render_interface.h -index d5d2bc4cb..aab965e0c 100644 ---- a/src/xrt/compositor/render/render_interface.h -+++ b/src/xrt/compositor/render/render_interface.h -@@ -64,6 +64,11 @@ extern "C" { - #define RENDER_MAX_IMAGES_SIZE (RENDER_MAX_LAYERS * XRT_MAX_VIEWS) - #define RENDER_MAX_IMAGES_COUNT(RENDER_RESOURCES) (RENDER_MAX_LAYERS * RENDER_RESOURCES->view_count) - -+/*! -+ * Max number of mip levels for distortion calculation -+ */ -+#define COMP_MAX_MIP_LEVELS 16 -+ - /*! - * Maximum number of times that the layer squasher shader can run per - * @ref render_compute. Since you run the layer squasher shader once per view -@@ -138,6 +143,8 @@ struct render_shaders - VkShaderModule clear_comp; - VkShaderModule layer_comp; - VkShaderModule distortion_comp; -+ VkShaderModule mipmap_fast_comp; -+ VkShaderModule mipmap_general_comp; - - VkShaderModule mesh_vert; - VkShaderModule mesh_frag; -@@ -535,6 +542,19 @@ struct render_resources - - //! @todo other resources - } clear; -+ -+ struct -+ { -+ //! Descriptor set layout for compute mipmaps. -+ VkDescriptorSetLayout descriptor_set_layout; -+ -+ //! Pipeline layout used for compute mipmaps. -+ VkPipelineLayout pipeline_layout; -+ -+ //! Doesn't depend on target so is static. -+ VkPipeline fast_pipeline; -+ VkPipeline general_pipeline; -+ } mipmap; - } compute; - - struct -@@ -645,6 +665,7 @@ struct render_scratch_color_image - VkImage image; - VkImageView srgb_view; - VkImageView unorm_view; -+ VkImageView mip_views[COMP_MAX_MIP_LEVELS]; - }; - - /*! -@@ -1176,6 +1197,9 @@ struct render_compute - * @ref render_compute_projection, and @ref render_compute_clear. - */ - VkDescriptorSet shared_descriptor_set; -+ -+ //! Descriptor set to generate mipmaps -+ VkDescriptorSet mip_descriptor_set[XRT_MAX_VIEWS]; - }; - - /*! -diff --git a/src/xrt/compositor/render/render_resources.c b/src/xrt/compositor/render/render_resources.c -index ccc6f10cf..b9b8d4a22 100644 ---- a/src/xrt/compositor/render/render_resources.c -+++ b/src/xrt/compositor/render/render_resources.c -@@ -287,6 +287,45 @@ create_compute_distortion_descriptor_set_layout(struct vk_bundle *vk, - return VK_SUCCESS; - } - -+XRT_CHECK_RESULT static VkResult -+create_compute_mipmap_descriptor_set_layout(struct vk_bundle *vk, VkDescriptorSetLayout *out_descriptor_set_layout) -+{ -+ VkResult ret; -+ -+ VkDescriptorSetLayoutBinding set_layout_bindings[] = { -+ { -+ .binding = 0, -+ .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, -+ .descriptorCount = 1, -+ .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, -+ }, -+ { -+ .binding = 1, -+ .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, -+ .descriptorCount = COMP_MAX_MIP_LEVELS, -+ .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, -+ }, -+ }; -+ -+ VkDescriptorSetLayoutCreateInfo set_layout_info = { -+ .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, -+ .bindingCount = ARRAY_SIZE(set_layout_bindings), -+ .pBindings = set_layout_bindings, -+ }; -+ -+ VkDescriptorSetLayout descriptor_set_layout = VK_NULL_HANDLE; -+ ret = vk->vkCreateDescriptorSetLayout( // -+ vk->device, // -+ &set_layout_info, // -+ NULL, // -+ &descriptor_set_layout); // -+ VK_CHK_AND_RET(ret, "vkCreateDescriptorSetLayout"); -+ -+ *out_descriptor_set_layout = descriptor_set_layout; -+ -+ return VK_SUCCESS; -+} -+ - struct compute_layer_params - { - VkBool32 do_timewarp; -@@ -481,6 +520,29 @@ create_scratch_image_and_view(struct vk_bundle *vk, VkExtent2D extent, struct re - - VK_NAME_IMAGE_VIEW(vk, unorm_view, "render_scratch_color_image image view unorm"); - -+ for (uint32_t level = 0; level < COMP_MAX_MIP_LEVELS; level++) { -+ const VkImageSubresourceRange mip_subresource_range = { -+ .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, -+ .baseMipLevel = level, -+ .levelCount = 1, -+ .baseArrayLayer = 0, -+ .layerCount = VK_REMAINING_ARRAY_LAYERS, -+ }; -+ ret = vk_create_view_usage( // -+ vk, // vk_bundle -+ image, // image -+ view_type, // type -+ unorm_format, // format -+ VK_IMAGE_USAGE_STORAGE_BIT, // image_usage -+ mip_subresource_range, // subresource_range -+ &rsci->mip_views[level]); // out_image_view -+ VK_CHK_WITH_RET(ret, "vk_create_view_usage(mip)", false); -+ -+ char buf[100]; -+ sprintf(buf, "render_scratch_image_view(mip)[%d]", level); -+ VK_NAME_IMAGE_VIEW(vk, rsci->mip_views[level], buf); -+ } -+ - rsci->device_memory = device_memory; - rsci->image = image; - rsci->srgb_view = srgb_view; -@@ -829,13 +891,14 @@ render_resources_init(struct render_resources *r, - - const uint32_t compute_descriptor_count = // - 1 + // Shared/distortion run(s). -- RENDER_MAX_LAYER_RUNS_COUNT(r); // Layer shader run(s). -+ RENDER_MAX_LAYER_RUNS_COUNT(r) + // Layer shader run(s). -+ XRT_MAX_VIEWS; // Mipmap - - struct vk_descriptor_pool_info compute_pool_info = { - .uniform_per_descriptor_count = 1, - // layer images -- .sampler_per_descriptor_count = r->compute.layer.image_array_size + RENDER_DISTORTION_IMAGES_COUNT(r), -- .storage_image_per_descriptor_count = 1, -+ .sampler_per_descriptor_count = r->compute.layer.image_array_size + RENDER_DISTORTION_IMAGES_COUNT(r) + 1, -+ .storage_image_per_descriptor_count = 1 + COMP_MAX_MIP_LEVELS, - .storage_buffer_per_descriptor_count = 0, - .descriptor_count = compute_descriptor_count, - .freeable = false, -@@ -1034,6 +1097,62 @@ render_resources_init(struct render_resources *r, - &r->compute.clear.ubo); // buffer - VK_CHK_WITH_RET(ret, "render_buffer_map", false); - -+ /* -+ * Mipmap pipeline -+ */ -+ ret = create_compute_mipmap_descriptor_set_layout( -+ vk, // vk_bundle -+ &r->compute.mipmap.descriptor_set_layout // out_descriptor_set_layout -+ ); -+ VK_CHK_WITH_RET(ret, "create_compute_mipmap_descriptor_set_layout", false); -+ -+ VK_NAME_DESCRIPTOR_SET_LAYOUT(vk, r->compute.mipmap.descriptor_set_layout, -+ "render_resources compute mipmap descriptor set layout"); -+ -+ VkPushConstantRange push_constant_range = { -+ .size = 4, -+ .offset = 0, -+ .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, -+ }; -+ -+ VkPipelineLayoutCreateInfo pipeline_layout_info = { -+ .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, -+ .setLayoutCount = 1, -+ .pSetLayouts = &r->compute.mipmap.descriptor_set_layout, -+ .pushConstantRangeCount = 1, -+ .pPushConstantRanges = &push_constant_range, -+ }; -+ -+ ret = vk->vkCreatePipelineLayout( // -+ vk->device, // device -+ &pipeline_layout_info, // pCreateInfo -+ NULL, // pAllocator -+ &r->compute.mipmap.pipeline_layout); // pPipelineLayout -+ VK_CHK_WITH_RET(ret, "vk_create_pipeline_layout", false); -+ -+ VK_NAME_PIPELINE_LAYOUT(vk, r->compute.distortion.pipeline_layout, -+ "render_resources compute mipmap pipeline layout"); -+ -+ ret = vk_create_compute_pipeline( // -+ vk, // vk_bundle -+ r->pipeline_cache, // pipeline_cache -+ r->shaders->mipmap_fast_comp, // shader -+ r->compute.mipmap.pipeline_layout, // pipeline_layout -+ NULL, // specialization_info -+ &r->compute.mipmap.fast_pipeline); // out_compute_pipeline -+ VK_CHK_WITH_RET(ret, "vk_create_compute_pipeline", false); -+ VK_NAME_PIPELINE(vk, r->compute.mipmap.fast_pipeline, "render_resources compute mipmap fast pipeline"); -+ -+ ret = vk_create_compute_pipeline( // -+ vk, // vk_bundle -+ r->pipeline_cache, // pipeline_cache -+ r->shaders->mipmap_general_comp, // shader -+ r->compute.mipmap.pipeline_layout, // pipeline_layout -+ NULL, // specialization_info -+ &r->compute.mipmap.general_pipeline); // out_compute_pipeline -+ VK_CHK_WITH_RET(ret, "vk_create_compute_pipeline", false); -+ VK_NAME_PIPELINE(vk, r->compute.mipmap.general_pipeline, "render_resources compute mipmap general pipeline"); -+ - - /* - * Compute distortion textures, not created until later. -@@ -1129,6 +1248,11 @@ render_resources_fini(struct render_resources *r) - - D(Pipeline, r->compute.clear.pipeline); - -+ D(DescriptorSetLayout, r->compute.mipmap.descriptor_set_layout); -+ D(Pipeline, r->compute.mipmap.fast_pipeline); -+ D(Pipeline, r->compute.mipmap.general_pipeline); -+ D(PipelineLayout, r->compute.mipmap.pipeline_layout); -+ - render_distortion_images_fini(r); - render_buffer_fini(vk, &r->compute.clear.ubo); - for (uint32_t i = 0; i < r->view_count; i++) { -diff --git a/src/xrt/compositor/render/render_shaders.c b/src/xrt/compositor/render/render_shaders.c -index b6bae2690..02847ca45 100644 ---- a/src/xrt/compositor/render/render_shaders.c -+++ b/src/xrt/compositor/render/render_shaders.c -@@ -39,6 +39,8 @@ - #include "shaders/layer_shared.frag.h" - #include "shaders/mesh.frag.h" - #include "shaders/mesh.vert.h" -+#include "srgba8_mipmap_fast_pipeline.comp.h" -+#include "srgba8_mipmap_general_pipeline.comp.h" - - #if defined(__GNUC__) - #pragma GCC diagnostic pop -@@ -51,22 +53,23 @@ - * - */ - --#define LOAD(SHADER) \ -+#define LOAD_NAME(VAR, SHADER) \ - do { \ -- const uint32_t *code = shaders_##SHADER; \ -- size_t size = sizeof(shaders_##SHADER); \ -- VkResult ret = shader_load(vk, /* vk_bundle */ \ -- code, /* code */ \ -- size, /* size */ \ -- &s->SHADER); /* out */ \ -+ const uint32_t *code = SHADER; \ -+ size_t size = sizeof(SHADER); \ -+ VkResult ret = shader_load(vk, /* vk_bundle */ \ -+ code, /* code */ \ -+ size, /* size */ \ -+ &s->VAR); /* out */ \ - if (ret != VK_SUCCESS) { \ - VK_ERROR(vk, "Failed to load shader '" #SHADER "'"); \ - render_shaders_fini(s, vk); \ - return false; \ - } \ -- VK_NAME_SHADER_MODULE(vk, s->SHADER, #SHADER); \ -+ VK_NAME_SHADER_MODULE(vk, s->VAR, #SHADER); \ - } while (false) - -+#define LOAD(SHADER) LOAD_NAME(SHADER, shaders_##SHADER) - - /* - * -@@ -109,6 +112,9 @@ render_shaders_load(struct render_shaders *s, struct vk_bundle *vk) - - LOAD(distortion_comp); - -+ LOAD_NAME(mipmap_fast_comp, nvpro_pyramid_srgba8_mipmap_fast_pipeline_comp); -+ LOAD_NAME(mipmap_general_comp, nvpro_pyramid_srgba8_mipmap_general_pipeline_comp); -+ - LOAD(mesh_vert); - LOAD(mesh_frag); - -@@ -131,6 +137,8 @@ render_shaders_fini(struct render_shaders *s, struct vk_bundle *vk) - D(ShaderModule, s->blit_comp); - D(ShaderModule, s->clear_comp); - D(ShaderModule, s->distortion_comp); -+ D(ShaderModule, s->mipmap_fast_comp); -+ D(ShaderModule, s->mipmap_general_comp); - D(ShaderModule, s->layer_comp); - D(ShaderModule, s->mesh_vert); - D(ShaderModule, s->mesh_frag); -diff --git a/src/xrt/compositor/shaders/distortion.comp b/src/xrt/compositor/shaders/distortion.comp -index 08b44d4cf..9a09c03db 100644 ---- a/src/xrt/compositor/shaders/distortion.comp -+++ b/src/xrt/compositor/shaders/distortion.comp -@@ -102,6 +102,26 @@ vec2 transform_uv(vec2 uv, uint iz) - } - } - -+mat3x2 source_coord(ivec3 xyv, ivec2 extent) -+{ -+ uint ix = xyv.x; -+ uint iy = xyv.y; -+ uint iz = xyv.z; -+ -+ vec2 dist_uv = position_to_uv(extent, ix, iy); -+ -+ vec2 r_uv = texture(distortion[iz + 0], dist_uv).xy; -+ vec2 g_uv = texture(distortion[iz + 2], dist_uv).xy; -+ vec2 b_uv = texture(distortion[iz + 4], dist_uv).xy; -+ -+ // Do any transformation needed. -+ mat3x2 res; -+ res[0] = transform_uv(r_uv, iz); -+ res[1] = transform_uv(g_uv, iz); -+ res[2] = transform_uv(b_uv, iz); -+ return res; -+} -+ - void main() - { - uint ix = gl_GlobalInvocationID.x; -@@ -117,21 +137,14 @@ void main() - - vec2 dist_uv = position_to_uv(extent, ix, iy); - -- vec2 r_uv = texture(distortion[iz + 0], dist_uv).xy; -- vec2 g_uv = texture(distortion[iz + 2], dist_uv).xy; -- vec2 b_uv = texture(distortion[iz + 4], dist_uv).xy; -+ vec2 uv = texture(distortion[iz + 0], dist_uv).xy; -+ vec2 lod = texture(distortion[iz + 2], dist_uv).xy; - - // Do any transformation needed. -- r_uv = transform_uv(r_uv, iz); -- g_uv = transform_uv(g_uv, iz); -- b_uv = transform_uv(b_uv, iz); -- -- // Sample the source with distorted and chromatic-aberration corrected samples. -- vec4 colour = vec4( -- texture(source[iz], r_uv).r, -- texture(source[iz], g_uv).g, -- texture(source[iz], b_uv).b, -- 1); -+ uv = transform_uv(uv, iz); -+ -+ // Sample the source -+ vec4 colour = textureLod(source[iz], uv, mix(lod.x, lod.y, 0.5)); - - // Do colour correction here since there are no automatic conversion in hardware available. - colour = vec4(from_linear_to_srgb(colour.rgb), 1); -diff --git a/src/xrt/compositor/util/comp_mipmap.cpp b/src/xrt/compositor/util/comp_mipmap.cpp -new file mode 100644 -index 000000000..37a5d5f60 ---- /dev/null -+++ b/src/xrt/compositor/util/comp_mipmap.cpp -@@ -0,0 +1,25 @@ -+// Copyright 2023, Collabora, Ltd. -+// SPDX-License-Identifier: BSL-1.0 -+ -+#include "comp_mipmap.h" -+ -+#include "nvpro_pyramid_dispatch.hpp" -+ -+void -+comp_do_mipmaps(VkCommandBuffer cmdBuf, -+ VkPipeline fast_pipeline, -+ VkPipeline general_pipeline, -+ VkPipelineLayout layout, -+ uint32_t width, -+ uint32_t height, -+ uint32_t mip_levels) -+{ -+ nvproCmdPyramidDispatch(cmdBuf, -+ NvproPyramidPipelines{ -+ .generalPipeline = general_pipeline, -+ .fastPipeline = fast_pipeline, -+ .layout = layout, -+ .pushConstantOffset = 0, -+ }, -+ width, height, mip_levels); -+} -diff --git a/src/xrt/compositor/util/comp_mipmap.h b/src/xrt/compositor/util/comp_mipmap.h -new file mode 100644 -index 000000000..e5d3c670d ---- /dev/null -+++ b/src/xrt/compositor/util/comp_mipmap.h -@@ -0,0 +1,22 @@ -+// Copyright 2023, Collabora, Ltd. -+// SPDX-License-Identifier: BSL-1.0 -+ -+#include "vulkan/vulkan.h" -+ -+#ifdef __cplusplus -+extern "C" { -+#endif -+ -+void -+comp_do_mipmaps(VkCommandBuffer cmdBuf, -+ VkPipeline fast_pipeline, -+ VkPipeline general_pipeline, -+ VkPipelineLayout layout, -+ uint32_t width, -+ uint32_t height, -+ uint32_t mip_levels); -+ -+ -+#ifdef __cplusplus -+} -+#endif -diff --git a/src/xrt/compositor/util/comp_render.h b/src/xrt/compositor/util/comp_render.h -index 579b91413..e6fd072be 100644 ---- a/src/xrt/compositor/util/comp_render.h -+++ b/src/xrt/compositor/util/comp_render.h -@@ -125,6 +125,11 @@ struct comp_render_view_data - { - //! Only used on compute path. - VkImageView unorm_view; -+ -+ //! Number of mip levels of scratch images -+ int mip_count; -+ -+ VkImageView mip_views[COMP_MAX_MIP_LEVELS]; - } cs; - }; - -@@ -297,6 +302,7 @@ comp_render_gfx_add_view(struct comp_render_dispatch_data *data, - const struct xrt_normalized_rect *layer_norm_rect, - VkImage image, - VkImageView srgb_view, -+ int mip_count, - const struct xrt_matrix_2x2 *vertex_rot, - const struct render_viewport_data *target_viewport_data) - { -@@ -314,6 +320,8 @@ comp_render_gfx_add_view(struct comp_render_dispatch_data *data, - // TODO why is the one in data not used instead - view->gfx.rtr = rtr; - view->gfx.vertex_rot = *vertex_rot; -+ -+ view->cs.mip_count = mip_count; - } - - /*! -@@ -469,6 +477,8 @@ comp_render_cs_add_view(struct comp_render_dispatch_data *data, - VkImage image, - VkImageView srgb_view, - VkImageView unorm_view, -+ VkImageView *mip_views, -+ int mip_count, - const struct render_viewport_data *target_viewport_data) - { - struct comp_render_view_data *view = comp_render_dispatch_add_view( // -@@ -483,6 +493,8 @@ comp_render_cs_add_view(struct comp_render_dispatch_data *data, - target_viewport_data); - - view->cs.unorm_view = unorm_view; -+ view->cs.mip_count = mip_count; -+ memcpy(view->cs.mip_views, mip_views, mip_count * sizeof(VkImageView)); - } - - /*! -diff --git a/src/xrt/compositor/util/comp_render_cs.c b/src/xrt/compositor/util/comp_render_cs.c -index dbc2fec7e..fc11a0521 100644 ---- a/src/xrt/compositor/util/comp_render_cs.c -+++ b/src/xrt/compositor/util/comp_render_cs.c -@@ -25,6 +25,7 @@ - - #include "render/render_interface.h" - -+#include "util/comp_mipmap.h" - #include "util/comp_render.h" - #include "util/comp_render_helpers.h" - #include "util/comp_base.h" -@@ -328,6 +329,92 @@ do_cs_quad_layer(const struct comp_layer *layer, - *out_cur_image = cur_image; - } - -+static void -+fill_mip_levels(struct render_resources *r, const struct comp_render_view_data *view, VkDescriptorSet descriptor_set) -+{ -+ if (view->cs.mip_count == 1) -+ return; -+ -+ uint32_t width = view->layer_viewport_data.w; -+ uint32_t height = view->layer_viewport_data.h; -+ -+ VkDescriptorImageInfo src_image_info = { -+ .sampler = r->samplers.clamp_to_edge, -+ .imageView = view->srgb_view, -+ .imageLayout = VK_IMAGE_LAYOUT_GENERAL, -+ }; -+ -+ VkDescriptorImageInfo target_image_info[COMP_MAX_MIP_LEVELS]; -+ for (int i = 0; i < COMP_MAX_MIP_LEVELS; ++i) { -+ target_image_info[i].sampler = r->samplers.mock; -+ if (i < view->cs.mip_count) { -+ target_image_info[i].imageView = view->cs.mip_views[i]; -+ } else { -+ // descriptors must be bound, even if unused -+ target_image_info[i].imageView = view->cs.mip_views[0]; -+ } -+ target_image_info[i].imageLayout = VK_IMAGE_LAYOUT_GENERAL; -+ }; -+ -+ VkWriteDescriptorSet write_descriptor_sets[] = { -+ { -+ .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, -+ .dstSet = descriptor_set, -+ .dstBinding = 0, -+ .descriptorCount = 1, -+ .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, -+ .pImageInfo = &src_image_info, -+ }, -+ { -+ .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, -+ .dstSet = descriptor_set, -+ .dstBinding = 1, -+ .descriptorCount = ARRAY_SIZE(target_image_info), -+ .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, -+ .pImageInfo = target_image_info, -+ }, -+ }; -+ -+ r->vk->vkUpdateDescriptorSets( // -+ r->vk->device, // -+ ARRAY_SIZE(write_descriptor_sets), // descriptorWriteCount -+ write_descriptor_sets, // pDescriptorWrites -+ 0, // descriptorCopyCount -+ NULL); // pDescriptorCopies -+ -+ r->vk->vkCmdBindDescriptorSets( // -+ r->cmd, // commandBuffer -+ VK_PIPELINE_BIND_POINT_COMPUTE, // pipelineBindPoint -+ r->compute.mipmap.pipeline_layout, // layout -+ 0, // firstSet -+ 1, // descriptorSetCount -+ &descriptor_set, // pDescriptorSets -+ 0, // dynamicOffsetCount -+ NULL); // pDynamicOffsets -+ comp_do_mipmaps(r->cmd, r->compute.mipmap.fast_pipeline, r->compute.mipmap.general_pipeline, -+ r->compute.mipmap.pipeline_layout, width, height, view->cs.mip_count); -+ -+ VkImageSubresourceRange range = { -+ .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, -+ .baseMipLevel = 0, -+ .levelCount = view->cs.mip_count, -+ .baseArrayLayer = 0, -+ .layerCount = 1, -+ }; -+ -+ vk_cmd_image_barrier_locked( // -+ r->vk, // vk_bundle -+ r->cmd, // cmd_buffer -+ view->image, // image -+ VK_ACCESS_MEMORY_WRITE_BIT, // src_access_mask -+ VK_ACCESS_MEMORY_READ_BIT, // dst_access_mask -+ VK_IMAGE_LAYOUT_GENERAL, // old_image_layout -+ VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, // new_image_layout -+ VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, // src_stage_mask -+ VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, // dst_stage_mask -+ range); // subresource_range -+} -+ - static void - crc_clear_output(struct render_compute *render, const struct comp_render_dispatch_data *d) - { -@@ -374,6 +461,8 @@ crc_distortion_after_squash(struct render_compute *render, const struct comp_ren - struct xrt_normalized_rect src_norm_rects[XRT_MAX_VIEWS]; - - for (uint32_t i = 0; i < d->view_count; i++) { -+ fill_mip_levels(render->r, &d->views[i], render->mip_descriptor_set[i]); -+ - // Data to be filled in. - VkImageView src_image_view; - struct render_viewport_data viewport_data; -@@ -762,6 +851,9 @@ comp_render_cs_dispatch(struct render_compute *render, - U_LOG_W("Wanted fast path but no projection layer, falling back to layer squasher."); - } - -+ if (d->views[0].cs.mip_count != 1) -+ transition_to = VK_IMAGE_LAYOUT_GENERAL; -+ - /* - * Layer squashing. - */ -diff --git a/src/xrt/compositor/util/comp_render_helpers.h b/src/xrt/compositor/util/comp_render_helpers.h -index 8fa3af8f0..4e525be5a 100644 ---- a/src/xrt/compositor/util/comp_render_helpers.h -+++ b/src/xrt/compositor/util/comp_render_helpers.h -@@ -149,10 +149,10 @@ cmd_barrier_view_images(struct vk_bundle *vk, - VkPipelineStageFlags src_stage_mask, - VkPipelineStageFlags dst_stage_mask) - { -- VkImageSubresourceRange first_color_level_subresource_range = { -+ VkImageSubresourceRange all_color_level_subresource_range = { - .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, - .baseMipLevel = 0, -- .levelCount = 1, -+ .levelCount = VK_REMAINING_MIP_LEVELS, - .baseArrayLayer = 0, - .layerCount = 1, - }; -@@ -176,17 +176,17 @@ cmd_barrier_view_images(struct vk_bundle *vk, - continue; - } - -- vk_cmd_image_barrier_locked( // -- vk, // vk_bundle -- cmd, // cmd_buffer -- image, // image -- src_access_mask, // src_access_mask -- dst_access_mask, // dst_access_mask -- transition_from, // old_image_layout -- transition_to, // new_image_layout -- src_stage_mask, // src_stage_mask -- dst_stage_mask, // dst_stage_mask -- first_color_level_subresource_range); // subresource_range -+ vk_cmd_image_barrier_locked( // -+ vk, // vk_bundle -+ cmd, // cmd_buffer -+ image, // image -+ src_access_mask, // src_access_mask -+ dst_access_mask, // dst_access_mask -+ transition_from, // old_image_layout -+ transition_to, // new_image_layout -+ src_stage_mask, // src_stage_mask -+ dst_stage_mask, // dst_stage_mask -+ all_color_level_subresource_range); // subresource_range - } - } - -diff --git a/src/xrt/compositor/util/comp_scratch.c b/src/xrt/compositor/util/comp_scratch.c -index 48bfda7c7..1d892a31b 100644 ---- a/src/xrt/compositor/util/comp_scratch.c -+++ b/src/xrt/compositor/util/comp_scratch.c -@@ -16,7 +16,7 @@ - - #include "vk/vk_mini_helpers.h" - #include "vk/vk_image_allocator.h" -- -+#include - - /* - * -@@ -25,7 +25,7 @@ - */ - - static inline void --fill_info(VkExtent2D extent, struct xrt_swapchain_create_info *out_info) -+fill_info(VkExtent2D extent, int mip_count, struct xrt_swapchain_create_info *out_info) - { - enum xrt_swapchain_create_flags create = 0; - -@@ -46,12 +46,22 @@ fill_info(VkExtent2D extent, struct xrt_swapchain_create_info *out_info) - .height = extent.height, - .face_count = 1, - .array_size = 1, -- .mip_count = 1, -+ .mip_count = mip_count, - }; - -+ if (info.mip_count == 0) { -+ uint32_t w = info.width, h = info.height; -+ while (w != 0 || h != 0) { -+ w >>= 1; -+ h >>= 1; -+ ++(info.mip_count); -+ } -+ } -+ - // Use format list to get good performance everywhere. - info.formats[info.format_count++] = VK_FORMAT_R8G8B8A8_UNORM; - info.formats[info.format_count++] = VK_FORMAT_R8G8B8A8_SRGB; -+ info.formats[info.format_count++] = VK_FORMAT_R8G8B8A8_UINT; - - *out_info = info; - } -@@ -131,6 +141,9 @@ struct tmp - - //! For storage operations in compute shaders. - VkImageView unorm_views[COMP_SCRATCH_NUM_IMAGES]; -+ -+ //! For mipmap generation -+ VkImageView mip_views[COMP_SCRATCH_NUM_IMAGES * COMP_MAX_MIP_LEVELS]; - }; - - static inline bool -@@ -159,6 +172,7 @@ tmp_init_and_create(struct tmp *t, struct vk_bundle *vk, const struct xrt_swapch - // Base info. - const VkFormat srgb_format = VK_FORMAT_R8G8B8A8_SRGB; - const VkFormat unorm_format = VK_FORMAT_R8G8B8A8_UNORM; -+ const VkFormat mip_format = VK_FORMAT_R8G8B8A8_UINT; - const VkImageViewType view_type = VK_IMAGE_VIEW_TYPE_2D; - - // Both usages are common. -@@ -201,6 +215,29 @@ tmp_init_and_create(struct tmp *t, struct vk_bundle *vk, const struct xrt_swapch - VK_CHK_WITH_GOTO(ret, "vk_create_view_usage(unorm)", err_destroy_views); - - VK_NAME_IMAGE_VIEW(vk, t->unorm_views[i], "comp_scratch_image_view(unorm)"); -+ -+ for (uint32_t level = 0; level < info->mip_count; level++) { -+ const VkImageSubresourceRange mip_subresource_range = { -+ .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, -+ .baseMipLevel = level, -+ .levelCount = 1, -+ .baseArrayLayer = 0, -+ .layerCount = VK_REMAINING_ARRAY_LAYERS, -+ }; -+ ret = vk_create_view_usage( // -+ vk, // vk_bundle -+ image, // image -+ view_type, // type -+ mip_format, // format -+ VK_IMAGE_USAGE_STORAGE_BIT, // image_usage -+ mip_subresource_range, // subresource_range -+ &t->mip_views[i * COMP_MAX_MIP_LEVELS + level]); // out_image_view -+ VK_CHK_WITH_GOTO(ret, "vk_create_view_usage(mip)", err_destroy_views); -+ -+ char buf[100]; -+ sprintf(buf, "comp_scratch_image_view(mip)[%d]", level); -+ VK_NAME_IMAGE_VIEW(vk, t->mip_views[i * COMP_MAX_MIP_LEVELS + level], buf); -+ } - } - - return true; -@@ -210,6 +247,9 @@ err_destroy_views: - D(ImageView, t->srgb_views[i]); - D(ImageView, t->unorm_views[i]); - } -+ for (uint32_t i = 0; i < ARRAY_SIZE(t->mip_views); i++) { -+ D(ImageView, t->mip_views[i]); -+ } - - err_destroy_vkic: - vk_ic_destroy(vk, &t->vkic); -@@ -227,6 +267,8 @@ tmp_take(struct tmp *t, - images[i].device_memory = t->vkic.images[i].memory; - images[i].srgb_view = t->srgb_views[i]; - images[i].unorm_view = t->unorm_views[i]; -+ memcpy(images[i].mip_views, &t->mip_views[COMP_MAX_MIP_LEVELS * i], -+ COMP_MAX_MIP_LEVELS * sizeof(VkImageView)); - - native_images[i].size = t->vkic.images[i].size; - native_images[i].use_dedicated_allocation = t->vkic.images[i].use_dedicated_allocation; -@@ -236,6 +278,7 @@ tmp_take(struct tmp *t, - t->unorm_views[i] = VK_NULL_HANDLE; - t->handles[i] = XRT_GRAPHICS_BUFFER_HANDLE_INVALID; - } -+ memset(t->mip_views, 0, sizeof(t->mip_views)); - - // We now own everything. - U_ZERO(&t->vkic); -@@ -250,6 +293,9 @@ tmp_destroy(struct tmp *t, struct vk_bundle *vk) - D(ImageView, t->srgb_views[i]); - D(ImageView, t->unorm_views[i]); - } -+ for (uint32_t i = 0; i < ARRAY_SIZE(t->mip_views); i++) { -+ D(ImageView, t->mip_views[i]); -+ } - } - - -@@ -276,7 +322,10 @@ comp_scratch_single_images_init(struct comp_scratch_single_images *cssi) - } - - bool --comp_scratch_single_images_ensure(struct comp_scratch_single_images *cssi, struct vk_bundle *vk, VkExtent2D extent) -+comp_scratch_single_images_ensure(struct comp_scratch_single_images *cssi, -+ struct vk_bundle *vk, -+ VkExtent2D extent, -+ int mip_count) - { - if (cssi->info.width == extent.width && cssi->info.height == extent.height) { - // Our work here is done! -@@ -284,7 +333,7 @@ comp_scratch_single_images_ensure(struct comp_scratch_single_images *cssi, struc - } - - struct xrt_swapchain_create_info info = XRT_STRUCT_INIT; -- fill_info(extent, &info); -+ fill_info(extent, mip_count, &info); - - struct tmp t; // Is initialized in function. - if (!tmp_init_and_create(&t, vk, &info)) { -@@ -316,6 +365,9 @@ comp_scratch_single_images_free(struct comp_scratch_single_images *cssi, struct - - D(ImageView, cssi->images[i].srgb_view); - D(ImageView, cssi->images[i].unorm_view); -+ for (uint32_t j = 0; j < ARRAY_SIZE(cssi->images[i].mip_views); j++) { -+ D(ImageView, cssi->images[i].mip_views[j]); -+ } - D(Image, cssi->images[i].image); - DF(Memory, cssi->images[i].device_memory); - } -@@ -400,7 +452,7 @@ comp_scratch_stereo_images_init(struct comp_scratch_stereo_images *cssi) - } - - bool --comp_scratch_stereo_images_ensure(struct comp_scratch_stereo_images *cssi, struct vk_bundle *vk, VkExtent2D extent) -+comp_scratch_stereo_images_ensure(struct comp_scratch_stereo_images *cssi, struct vk_bundle *vk, VkExtent2D extent, int mip_count) - { - if (cssi->info.width == extent.width && cssi->info.height == extent.height) { - // Our work here is done! -@@ -409,7 +461,7 @@ comp_scratch_stereo_images_ensure(struct comp_scratch_stereo_images *cssi, struc - - // Get info we need to share with. - struct xrt_swapchain_create_info info = XRT_STRUCT_INIT; -- fill_info(extent, &info); -+ fill_info(extent, mip_count, &info); - - struct tmp ts[2]; // Is initialized in function. - if (!tmp_init_and_create(&ts[0], vk, &info)) { -@@ -465,6 +517,9 @@ comp_scratch_stereo_images_free(struct comp_scratch_stereo_images *cssi, struct - // Organised into scratch images, then views. - D(ImageView, cssi->rsis[i].color[view].srgb_view); - D(ImageView, cssi->rsis[i].color[view].unorm_view); -+ for (uint32_t j = 0; j < ARRAY_SIZE(cssi->rsis[i].color[view].mip_views); j++) { -+ D(ImageView, cssi->rsis[i].color[view].mip_views[j]); -+ } - D(Image, cssi->rsis[i].color[view].image); - DF(Memory, cssi->rsis[i].color[view].device_memory); - } -diff --git a/src/xrt/compositor/util/comp_scratch.h b/src/xrt/compositor/util/comp_scratch.h -index 44849c20e..f8c891e49 100644 ---- a/src/xrt/compositor/util/comp_scratch.h -+++ b/src/xrt/compositor/util/comp_scratch.h -@@ -106,7 +106,10 @@ comp_scratch_single_images_init(struct comp_scratch_single_images *cssi); - * @ingroup comp_util - */ - bool --comp_scratch_single_images_ensure(struct comp_scratch_single_images *cssi, struct vk_bundle *vk, VkExtent2D extent); -+comp_scratch_single_images_ensure(struct comp_scratch_single_images *cssi, -+ struct vk_bundle *vk, -+ VkExtent2D extent, -+ int mip_count); - - /*! - * Free all images allocated, @p init must be called before calling this -@@ -215,7 +218,7 @@ void - comp_scratch_stereo_images_init(struct comp_scratch_stereo_images *cssi); - - bool --comp_scratch_stereo_images_ensure(struct comp_scratch_stereo_images *cssi, struct vk_bundle *vk, VkExtent2D extent); -+comp_scratch_stereo_images_ensure(struct comp_scratch_stereo_images *cssi, struct vk_bundle *vk, VkExtent2D extent, int mip_count); - - void - comp_scratch_stereo_images_free(struct comp_scratch_stereo_images *cssi, struct vk_bundle *vk); --- -2.49.0 - diff --git a/patches/monado/0008-store-alpha-channel-in-layer-1.patch b/patches/monado/0007-store-alpha-channel-in-layer-1.patch similarity index 93% rename from patches/monado/0008-store-alpha-channel-in-layer-1.patch rename to patches/monado/0007-store-alpha-channel-in-layer-1.patch index 450d45f0..1e73aeec 100644 --- a/patches/monado/0008-store-alpha-channel-in-layer-1.patch +++ b/patches/monado/0007-store-alpha-channel-in-layer-1.patch @@ -1,7 +1,7 @@ -From d5337b1e4811aef804057e26d67aace90adc36e8 Mon Sep 17 00:00:00 2001 +From b40c83a38d13fe511c9dceadeb23dd4fd2cc77f4 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sun, 3 Nov 2024 13:40:00 +0100 -Subject: [PATCH 08/11] store alpha channel in layer 1 +Subject: [PATCH 07/10] store alpha channel in layer 1 --- src/xrt/compositor/shaders/clear.comp | 4 ++-- @@ -29,7 +29,7 @@ index 036da401a..db8e5178e 100644 + imageStore(target, ivec3(offset.x + ix, offset.y + iy, 0), colour); } diff --git a/src/xrt/compositor/shaders/distortion.comp b/src/xrt/compositor/shaders/distortion.comp -index 461aeb4ec..237221a54 100644 +index e1dd1cb58..9ce46fe6f 100644 --- a/src/xrt/compositor/shaders/distortion.comp +++ b/src/xrt/compositor/shaders/distortion.comp @@ -18,7 +18,7 @@ layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; @@ -50,7 +50,7 @@ index 461aeb4ec..237221a54 100644 const mat3 color_space = mat3( // clang-format off -@@ -142,6 +142,7 @@ void main() +@@ -122,6 +122,7 @@ void main() ivec2 offset = ivec2(ubo.views[iz].xy); ivec2 extent = ivec2(ubo.views[iz].zw); vec2 cbcrs[4]; @@ -58,7 +58,7 @@ index 461aeb4ec..237221a54 100644 for (int k = 0; k < 2; k += 1) { uint iy = gl_GlobalInvocationID.y * 2 + k; for (int j = 0; j < 2; j += 1) { -@@ -156,15 +157,16 @@ void main() +@@ -136,15 +137,16 @@ void main() uv = transform_uv(uv, iz); // Sample the source @@ -78,7 +78,7 @@ index 461aeb4ec..237221a54 100644 } } } -@@ -172,5 +174,9 @@ void main() +@@ -152,5 +154,9 @@ void main() return; } vec2 cbcr = mix(mix(cbcrs[0], cbcrs[1], 0.5), mix(cbcrs[2], cbcrs[3], 0.5), 0.5); diff --git a/patches/monado/0009-st-oxr-bind-to-dynamic-role-s-profile.patch b/patches/monado/0008-st-oxr-bind-to-dynamic-role-s-profile.patch similarity index 93% rename from patches/monado/0009-st-oxr-bind-to-dynamic-role-s-profile.patch rename to patches/monado/0008-st-oxr-bind-to-dynamic-role-s-profile.patch index c2566ed7..686308ac 100644 --- a/patches/monado/0009-st-oxr-bind-to-dynamic-role-s-profile.patch +++ b/patches/monado/0008-st-oxr-bind-to-dynamic-role-s-profile.patch @@ -1,7 +1,7 @@ -From dffeb683c92b6ab2fbbf240817e4087a134d997f Mon Sep 17 00:00:00 2001 +From ee2d823a7959b01b47cdfc03287ffd75361d5b7d Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Wed, 19 Feb 2025 10:13:36 +0100 -Subject: [PATCH 09/11] st/oxr: bind to dynamic role's profile +Subject: [PATCH 08/10] st/oxr: bind to dynamic role's profile --- src/xrt/state_trackers/oxr/oxr_binding.c | 17 +++++++++++++++++ diff --git a/patches/monado/0010-c-main-allow-custom-pacing-app-factory.patch b/patches/monado/0009-c-main-allow-custom-pacing-app-factory.patch similarity index 96% rename from patches/monado/0010-c-main-allow-custom-pacing-app-factory.patch rename to patches/monado/0009-c-main-allow-custom-pacing-app-factory.patch index 91f9d340..298cf2d5 100644 --- a/patches/monado/0010-c-main-allow-custom-pacing-app-factory.patch +++ b/patches/monado/0009-c-main-allow-custom-pacing-app-factory.patch @@ -1,7 +1,7 @@ -From 644f84e916d40d6341de91687a3dc9b0eecd13a4 Mon Sep 17 00:00:00 2001 +From 8c1dc166ecef3c51c37d78859690cbfd8338d636 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Thu, 27 Feb 2025 22:45:36 +0100 -Subject: [PATCH 10/11] c/main: allow custom pacing app factory +Subject: [PATCH 09/10] c/main: allow custom pacing app factory --- src/xrt/compositor/main/comp_compositor.c | 10 ++++++---- diff --git a/patches/monado/0011-st-oxr-forward-0-refresh-rate.patch b/patches/monado/0010-st-oxr-forward-0-refresh-rate.patch similarity index 90% rename from patches/monado/0011-st-oxr-forward-0-refresh-rate.patch rename to patches/monado/0010-st-oxr-forward-0-refresh-rate.patch index f1b0dbfe..9791dc4f 100644 --- a/patches/monado/0011-st-oxr-forward-0-refresh-rate.patch +++ b/patches/monado/0010-st-oxr-forward-0-refresh-rate.patch @@ -1,7 +1,7 @@ -From f3dbf64ec2a45ac0e44a5d017b66d12fd8d63e77 Mon Sep 17 00:00:00 2001 +From 837e5f090583f5c0f7f8c1a06ecc032b4b3733a4 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sat, 15 Mar 2025 22:19:48 +0100 -Subject: [PATCH 11/11] st/oxr: forward 0 refresh rate +Subject: [PATCH 10/10] st/oxr: forward 0 refresh rate --- src/xrt/state_trackers/oxr/oxr_api_session.c | 6 +----- diff --git a/server/driver/wivrn_foveation.cpp b/server/driver/wivrn_foveation.cpp index 68fc4d49..c3673bc6 100644 --- a/server/driver/wivrn_foveation.cpp +++ b/server/driver/wivrn_foveation.cpp @@ -52,7 +52,7 @@ static const std::array pool_sizes = { vk::DescriptorPoolSize{ .type = vk::DescriptorType::eStorageImage, - .descriptorCount = 4, + .descriptorCount = 2, }}; static const std::array layout_bindings{ @@ -60,10 +60,6 @@ static const std::array layout_bindings{ .descriptorType = vk::DescriptorType::eStorageImage, .descriptorCount = 1, .stageFlags = vk::ShaderStageFlagBits::eCompute}, - vk::DescriptorSetLayoutBinding{.binding = 1, - .descriptorType = vk::DescriptorType::eStorageImage, - .descriptorCount = 1, - .stageFlags = vk::ShaderStageFlagBits::eCompute}, }; wivrn_foveation_renderer::wivrn_foveation_renderer(wivrn_vk_bundle & vk, vk::raii::CommandPool & cmd_pool) : @@ -178,33 +174,19 @@ void wivrn_foveation_renderer::render_distortion_images(std::array solve_foveation(float λ, float c) { // Compute a and b for the foveation function such that: @@ -122,20 +115,17 @@ bool wivrn_hmd::wivrn_hmd_compute_distortion(xrt_device * xdev, uint32_t view_in // result is in the input coordinates (from the application) const auto & param = ((wivrn_hmd *)xdev)->foveation_parameters[view_index]; xrt_vec2 out; - xrt_vec2 lod; if (param.x.scale < 1) { u = 2 * u - 1; out.x = foveate(param.x.a, param.x.b, param.x.scale, param.x.center, u); - lod.x = foveate_lod(param.x.a, param.x.b, param.x.scale, param.x.center, u); out.x = std::clamp((1 + out.x) / 2, 0, 1); } else { out.x = u; - lod.x = 0; } if (param.y.scale < 1) @@ -143,19 +133,15 @@ bool wivrn_hmd::wivrn_hmd_compute_distortion(xrt_device * xdev, uint32_t view_in v = 2 * v - 1; out.y = foveate(param.y.a, param.y.b, param.y.scale, param.y.center, v); - lod.y = foveate_lod(param.y.a, param.y.b, param.y.scale, param.y.center, v); out.y = std::clamp((1 + out.y) / 2, 0, 1); } else { out.y = v; - lod.y = 0; } - U_LOG_D("distortion parameters: %f %f (%f %f)", lod.x, lod.y, u, v); - result->r = out; - result->g = lod; + result->g = out; result->b = out; return true; diff --git a/server/main.cpp b/server/main.cpp index 22e90386..d2e36a87 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -288,9 +288,6 @@ void start_server(configuration config) // there is no need for oversampling. setenv("XRT_COMPOSITOR_SCALE_PERCENTAGE", "100", false); - // Enable mipmaps for distortion - setenv("XRT_DISTORTION_MIP_LEVELS", "0", false); - // FIXME: synchronization fails on gfx pipeline setenv("XRT_COMPOSITOR_COMPUTE", "1", true); diff --git a/server/shaders/foveate.comp.glsl b/server/shaders/foveate.comp.glsl index 3cc25cd6..527b02a4 100644 --- a/server/shaders/foveate.comp.glsl +++ b/server/shaders/foveate.comp.glsl @@ -21,7 +21,6 @@ layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; layout(set = 0, binding = 0, rgba8) uniform writeonly restrict image2D target; -layout(set = 0, binding = 1, rgba8) uniform writeonly restrict image2D dtarget; layout(push_constant) uniform PushConstants { @@ -37,11 +36,6 @@ float foveate(float a, float b, float scale, float c, float x) { return scale / a * tan(a * x + b) + c; } -float foveate_lod(float a, float b, float scale, float c, float x) { - // derivate foveation and add a bias - return max(0, log2(1 / (cos(a * x + b) * cos(a * x + b)) - 0.5)); -} - void main() { ivec2 coords = ivec2(gl_GlobalInvocationID.x, gl_GlobalInvocationID.y); @@ -55,17 +49,14 @@ void main() if (pcs.scale.x < 1.0) { float u = uv.x * 2.0 - 1.0; float val = foveate(pcs.a.x, pcs.b.x, pcs.scale.x, pcs.center.x, u); - duv.x = foveate_lod(pcs.a.x, pcs.b.x, pcs.scale.x, pcs.center.x, u); uv.x = clamp((1.0 + val) / 2.0, 0.0, 1.0); } if (pcs.scale.y < 1.0) { float v = uv.y * 2.0 - 1.0; float val = foveate(pcs.a.y, pcs.b.y, pcs.scale.y, pcs.center.y, v); - duv.y= foveate_lod(pcs.a.y, pcs.b.y, pcs.scale.y, pcs.center.y, v); uv.y = clamp((1.0 + val) / 2.0, 0.0, 1.0); } imageStore(target, coords, vec4(uv.x, uv.y, 0.0, 0.0)); - imageStore(dtarget, coords, vec4(duv.x, duv.y, 0.0, 0.0)); } From 64b446c0d8ea7ee44fc7531a778888d86a6a0428 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Tue, 3 Jun 2025 22:04:24 +0200 Subject: [PATCH 42/85] Rewrite foveation to enforce pixel alignment foveation now uses integer pixel ratios, and tries to follow the previous tangent function. --- client/scenes/stream.cpp | 24 +- client/scenes/stream_reprojection.cpp | 273 +++---- client/scenes/stream_reprojection.h | 25 +- client/shaders/reprojection.glsl | 49 +- common/wivrn_packets.h | 25 +- ...001-c-multi-early-wake-of-compositor.patch | 4 +- ...02-ipc-server-Always-listen-to-stdin.patch | 4 +- .../monado/0003-Use-extern-socket-fd.patch | 4 +- ...Add-storage-usage-to-distortion-mesh.patch | 4 +- ...vironment-blend-mode-selection-logic.patch | 4 +- .../0006-Convert-to-YCbCr-in-Monado.patch | 4 +- .../0007-store-alpha-channel-in-layer-1.patch | 4 +- ...t-oxr-bind-to-dynamic-role-s-profile.patch | 4 +- ...main-allow-custom-pacing-app-factory.patch | 4 +- .../0010-st-oxr-forward-0-refresh-rate.patch | 4 +- ...tortion-with-pixel-aligned-foveation.patch | 700 ++++++++++++++++++ server/driver/wivrn_comp_target.cpp | 80 +- server/driver/wivrn_comp_target.h | 5 +- server/driver/wivrn_foveation.cpp | 473 +++++++----- server/driver/wivrn_foveation.h | 60 +- server/driver/wivrn_hmd.cpp | 166 +---- server/driver/wivrn_hmd.h | 14 +- server/driver/wivrn_session.cpp | 39 +- server/driver/wivrn_session.h | 18 +- 24 files changed, 1291 insertions(+), 700 deletions(-) create mode 100644 patches/monado/0011-Replace-distortion-with-pixel-aligned-foveation.patch diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index eb03c4eb..010cc84a 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -860,10 +860,9 @@ void scenes::stream::render(const XrFrameState & frame_state) } command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 1); - reprojector->set_foveation(foveation); - // Unfoveate the image to the real pose - reprojector->reproject(command_buffer, image_index); + // defoveate the image + auto extents = reprojector->reproject(command_buffer, foveation, image_index); command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 2); @@ -908,10 +907,7 @@ void scenes::stream::render(const XrFrameState & frame_state) .swapchain = swapchain, .imageRect = { .offset = {0, 0}, - .extent = { - swapchain.width(), - swapchain.height(), - }, + .extent = extents[view], }, .imageArrayIndex = view, }, @@ -1161,8 +1157,8 @@ void scenes::stream::setup_reprojection_swapchain() const uint32_t video_width = video_stream_description->width / view_count; const uint32_t video_height = video_stream_description->height; - uint32_t swapchain_width = video_width / video_stream_description->foveation[0].x.scale; - uint32_t swapchain_height = video_height / video_stream_description->foveation[0].y.scale; + uint32_t swapchain_width = video_stream_description->defoveated_width / view_count; + uint32_t swapchain_height = video_stream_description->defoveated_height; const configuration::sgsr_settings sgsr = application::get_config().sgsr; if (sgsr.enabled) @@ -1189,7 +1185,15 @@ void scenes::stream::setup_reprojection_swapchain() for (auto & image: swapchain.images()) swapchain_images.push_back(image.image); - reprojector.emplace(device, physical_device, decoder_out_image, 2, swapchain_images, extent, swapchain.format(), *video_stream_description); + reprojector.emplace( + device, + physical_device, + decoder_out_image, + vk::Extent2D{.width = video_width, .height = video_height}, + 2, + swapchain_images, + extent, + swapchain.format()); } scene::meta & scenes::stream::get_meta_scene() diff --git a/client/scenes/stream_reprojection.cpp b/client/scenes/stream_reprojection.cpp index fc701634..5600de02 100644 --- a/client/scenes/stream_reprojection.cpp +++ b/client/scenes/stream_reprojection.cpp @@ -20,30 +20,24 @@ #include "stream_reprojection.h" #include "application.h" #include "utils/contains.h" +#include "utils/ranges.h" #include "vk/allocation.h" #include "vk/pipeline.h" #include "vk/shader.h" #include #include #include -#include #include #include #include -namespace +struct stream_reprojection::vertex { -struct uniform -{ - // Foveation parameters - alignas(8) glm::vec2 a; - alignas(8) glm::vec2 b; - alignas(8) glm::vec2 lambda; - alignas(8) glm::vec2 xc; + // output image position + alignas(8) glm::vec2 position; + // input texture coordinates + alignas(8) glm::vec2 uv; }; -} // namespace - -const int nb_reprojection_vertices = 128; struct SgsrSpecializationConstants { @@ -52,24 +46,47 @@ struct SgsrSpecializationConstants float edge_sharpness; }; +void stream_reprojection::ensure_vertices(size_t num_vertices) +{ + vk::BufferCreateInfo create_info{ + .size = num_vertices * sizeof(vertex) * view_count, + .usage = vk::BufferUsageFlagBits::eVertexBuffer, + .sharingMode = vk::SharingMode::eExclusive, + }; + + if (create_info.size <= buffer.info().size) + return; + + VmaAllocationCreateInfo alloc_info{ + .requiredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, + }; + + buffer = buffer_allocation(device, create_info, alloc_info); + vertices_size = num_vertices * sizeof(vertex); +} + +stream_reprojection::vertex * stream_reprojection::get_vertices(size_t view) +{ + assert(buffer); + return reinterpret_cast(reinterpret_cast(buffer.map()) + view * vertices_size); +} + stream_reprojection::stream_reprojection( vk::raii::Device & device, vk::raii::PhysicalDevice & physical_device, vk::Image input_image_, + vk::Extent2D input_extent, uint32_t view_count, std::vector output_images_, - vk::Extent2D extent, - vk::Format format, - const wivrn::to_headset::video_stream_description & description) : + vk::Extent2D output_extent, + vk::Format format) : view_count(view_count), + device(device), input_image(input_image_), + input_extent(input_extent), output_images(std::move(output_images_)), - extent(extent) + output_extent(output_extent) { - foveation_parameters = description.foveation; - - vk::PhysicalDeviceProperties properties = physical_device.getProperties(); - vk::SamplerCreateInfo sampler_info{ .magFilter = vk::Filter::eLinear, .minFilter = vk::Filter::eLinear, @@ -93,35 +110,12 @@ stream_reprojection::stream_reprojection( sampler = vk::raii::Sampler(device, sampler_info); - uniform_size = sizeof(uniform) + properties.limits.minUniformBufferOffsetAlignment - 1; - uniform_size = uniform_size - uniform_size % properties.limits.minUniformBufferOffsetAlignment; - - vk::BufferCreateInfo create_info{ - .size = uniform_size * view_count, - .usage = vk::BufferUsageFlagBits::eUniformBuffer, - .sharingMode = vk::SharingMode::eExclusive, - }; - - VmaAllocationCreateInfo alloc_info{ - .requiredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, - }; - - buffer = buffer_allocation(device, create_info, alloc_info); - // Create VkDescriptorSetLayout - std::array layout_binding{ - vk::DescriptorSetLayoutBinding{ - .binding = 0, - .descriptorType = vk::DescriptorType::eCombinedImageSampler, - .descriptorCount = 1, - .stageFlags = vk::ShaderStageFlagBits::eFragment, - }, - vk::DescriptorSetLayoutBinding{ - .binding = 1, - .descriptorType = vk::DescriptorType::eUniformBuffer, - .descriptorCount = 1, - .stageFlags = vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment, - }, + vk::DescriptorSetLayoutBinding layout_binding{ + .binding = 0, + .descriptorType = vk::DescriptorType::eCombinedImageSampler, + .descriptorCount = 1, + .stageFlags = vk::ShaderStageFlagBits::eFragment, }; vk::DescriptorSetLayoutCreateInfo layout_info; @@ -134,10 +128,6 @@ stream_reprojection::stream_reprojection( .type = vk::DescriptorType::eCombinedImageSampler, .descriptorCount = (uint32_t)view_count, }, - vk::DescriptorPoolSize{ - .type = vk::DescriptorType::eUniformBuffer, - .descriptorCount = (uint32_t)view_count, - }, }; vk::DescriptorPoolCreateInfo pool_info{ @@ -186,13 +176,7 @@ stream_reprojection::stream_reprojection( .imageLayout = vk::ImageLayout::eShaderReadOnlyOptimal, }; - vk::DescriptorBufferInfo buffer_info{ - .buffer = buffer, - .offset = uniform_size * view, - .range = sizeof(uniform), - }; - - std::array write{ + device.updateDescriptorSets( vk::WriteDescriptorSet{ .dstSet = descriptor_set, .dstBinding = 0, @@ -201,17 +185,7 @@ stream_reprojection::stream_reprojection( .descriptorType = vk::DescriptorType::eCombinedImageSampler, .pImageInfo = &image_info, }, - vk::WriteDescriptorSet{ - .dstSet = descriptor_set, - .dstBinding = 1, - .dstArrayElement = 0, - .descriptorCount = 1, - .descriptorType = vk::DescriptorType::eUniformBuffer, - .pBufferInfo = &buffer_info, - }, - }; - - device.updateDescriptorSets(write, {}); + {}); } // Create renderpass @@ -248,40 +222,6 @@ stream_reprojection::stream_reprojection( // Vertex shader vk::raii::ShaderModule vertex_shader = load_shader(device, "reprojection.vert"); - int vertex_specialization_constants[] = { - foveation_parameters[0].x.scale < 1, - foveation_parameters[0].y.scale < 1, - nb_reprojection_vertices, - nb_reprojection_vertices, - }; - - std::array vertex_specialization_constants_desc{ - vk::SpecializationMapEntry{ - .constantID = 0, - .offset = 0, - .size = sizeof(int), - }, - vk::SpecializationMapEntry{ - .constantID = 1, - .offset = sizeof(int), - .size = sizeof(int), - }, - vk::SpecializationMapEntry{ - .constantID = 2, - .offset = 2 * sizeof(int), - .size = sizeof(int), - }, - vk::SpecializationMapEntry{ - .constantID = 3, - .offset = 3 * sizeof(int), - .size = sizeof(int), - }, - }; - - vk::SpecializationInfo vertex_specialization_info; - vertex_specialization_info.setMapEntries(vertex_specialization_constants_desc); - vertex_specialization_info.setData(vertex_specialization_constants); - // Fragment shader std::string fragment_shader_name = "reprojection.frag"; @@ -337,7 +277,6 @@ stream_reprojection::stream_reprojection( .stage = vk::ShaderStageFlagBits::eVertex, .module = *vertex_shader, .pName = "main", - .pSpecializationInfo = &vertex_specialization_info, }, { .stage = vk::ShaderStageFlagBits::eFragment, @@ -346,22 +285,41 @@ stream_reprojection::stream_reprojection( .pSpecializationInfo = &fragment_specialization_info, }, }, - .VertexBindingDescriptions = {}, - .VertexAttributeDescriptions = {}, + .VertexBindingDescriptions = { + { + .binding = 0, + .stride = sizeof(vertex), + .inputRate = vk::VertexInputRate::eVertex, + }, + }, + .VertexAttributeDescriptions = { + { + .location = 0, + .binding = 0, + .format = vk::Format::eR32G32Sfloat, + .offset = offsetof(vertex, position), + }, + { + .location = 1, + .binding = 0, + .format = vk::Format::eR32G32Sfloat, + .offset = offsetof(vertex, uv), + }, + }, .InputAssemblyState = {{ - .topology = vk::PrimitiveTopology::eTriangleList, + .topology = vk::PrimitiveTopology::eTriangleStrip, }}, .Viewports = {{ .x = 0, .y = 0, - .width = (float)extent.width, - .height = (float)extent.height, + .width = (float)output_extent.width, + .height = (float)output_extent.height, .minDepth = 0, .maxDepth = 1, }}, .Scissors = {{ .offset = {.x = 0, .y = 0}, - .extent = extent, + .extent = output_extent, }}, .RasterizationState = {{ .polygonMode = vk::PolygonMode::eFill, @@ -411,8 +369,8 @@ stream_reprojection::stream_reprojection( vk::FramebufferCreateInfo fb_create_info{ .renderPass = *renderpass, - .width = extent.width, - .height = extent.height, + .width = output_extent.width, + .height = output_extent.height, .layers = 1, }; fb_create_info.setAttachments(*output_image_views.back()); @@ -422,28 +380,82 @@ stream_reprojection::stream_reprojection( } } -void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer, int destination) +static size_t required_vertices(const wivrn::to_headset::foveation_parameter & p) +{ + // strips are constructed like this: + // 0 2 4 + // 1 3 5 5* + // there is one such line per value in y + // the last element is repeated to break the line + return (2 * (p.x.size() + 1) + 1) * p.y.size(); +} + +std::vector stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer, + const std::array & foveation, + int destination) { if (destination < 0 || destination >= (int)output_images.size()) throw std::runtime_error("Invalid destination image index"); + ensure_vertices(std::max(required_vertices(foveation[0]), required_vertices(foveation[1]))); + std::vector out_extents(view_count, XrExtent2Di{}); + for (size_t view = 0; view < view_count; ++view) { - auto & ubo = *reinterpret_cast(reinterpret_cast(buffer.map()) + view * uniform_size); - if (foveation_parameters[view].x.scale < 1) + auto vertices = get_vertices(view); + const auto & [px, py] = foveation[view]; + assert(px.size() % 2 == 1); + assert(py.size() % 2 == 1); + const int n_ratio_y = (py.size() - 1) / 2; + const int n_ratio_x = (px.size() - 1) / 2; + + for (auto [ix, n_out_x]: utils::enumerate_range(px)) { - ubo.a.x = foveation_parameters[view].x.a; - ubo.b.x = foveation_parameters[view].x.b; - ubo.lambda.x = foveation_parameters[view].x.scale / foveation_parameters[view].x.a; - ubo.xc.x = foveation_parameters[view].x.center; + // number of output pixels per source pixels + const int ratio_x = std::abs(n_ratio_x - int(ix)) + 1; + out_extents[view].width += ratio_x * n_out_x; } - if (foveation_parameters[view].y.scale < 1) + glm::vec2 in(0), out(0); // pixel coordinates + glm::vec2 in_pixel_size(1. / input_extent.width, + 1. / input_extent.height); + glm::vec2 out_pixel_size(2. / output_extent.width, + 2. / output_extent.height); + for (auto [iy, n_out_y]: utils::enumerate_range(py)) { - ubo.a.y = foveation_parameters[view].y.a; - ubo.b.y = foveation_parameters[view].y.b; - ubo.lambda.y = foveation_parameters[view].y.scale / foveation_parameters[view].y.a; - ubo.xc.y = foveation_parameters[view].y.center; + // number of output pixels per source pixels + const int ratio_y = std::abs(n_ratio_y - int(iy)) + 1; + out_extents[view].height += ratio_y * n_out_y; + in.x = 0; + out.x = 0; + for (auto [ix, n_out_x]: utils::enumerate_range(px)) + { + const int ratio_x = std::abs(n_ratio_x - int(ix)) + 1; + *vertices++ = { + .position = out * out_pixel_size - glm::vec2(1), + .uv = in * in_pixel_size, + }; + *vertices++ = { + .position = (out + glm::vec2(0, n_out_y * ratio_y)) * out_pixel_size - glm::vec2(1), + .uv = (in + glm::vec2(0, n_out_y)) * in_pixel_size, + }; + in.x += n_out_x; + out.x += n_out_x * ratio_x; + } + *vertices++ = { + .position = out * out_pixel_size - glm::vec2(1), + .uv = in * in_pixel_size, + }; + *vertices++ = { + .position = (out + glm::vec2(0, n_out_y * ratio_y)) * out_pixel_size - glm::vec2(1), + .uv = (in + glm::vec2(0, n_out_y)) * in_pixel_size, + }; + *vertices++ = { + .position = (out + glm::vec2(0, n_out_y * ratio_y)) * out_pixel_size - glm::vec2(1), + .uv = (in + glm::vec2(0, n_out_y)) * in_pixel_size, + }; + in.y += n_out_y; + out.y += n_out_y * ratio_y; } } @@ -473,19 +485,16 @@ void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer, in .framebuffer = *framebuffers[destination * view_count + view], .renderArea = { .offset = {0, 0}, - .extent = extent, + .extent = output_extent, }, }; command_buffer.beginRenderPass(begin_info, vk::SubpassContents::eInline); command_buffer.bindPipeline(vk::PipelineBindPoint::eGraphics, *pipeline); command_buffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, *layout, 0, descriptor_sets[view], {}); - command_buffer.draw(6 * nb_reprojection_vertices * nb_reprojection_vertices, 1, 0, 0); + command_buffer.bindVertexBuffers(0, vk::Buffer(buffer), vertices_size * view); + command_buffer.draw(required_vertices(foveation[view]), 1, 0, 0); command_buffer.endRenderPass(); } -} - -void stream_reprojection::set_foveation(std::array foveation) -{ - foveation_parameters = foveation; + return out_extents; } diff --git a/client/scenes/stream_reprojection.h b/client/scenes/stream_reprojection.h index ee755b07..72ef1ad8 100644 --- a/client/scenes/stream_reprojection.h +++ b/client/scenes/stream_reprojection.h @@ -26,10 +26,13 @@ class stream_reprojection { + struct vertex; const uint32_t view_count; - // Uniform buffer + // Vertex buffer buffer_allocation buffer; - size_t uniform_size; + size_t vertices_size = 0; + + vk::raii::Device & device; // Graphic pipeline vk::raii::DescriptorSetLayout descriptor_set_layout = nullptr; @@ -43,32 +46,32 @@ class stream_reprojection vk::Image input_image; std::vector input_image_views; std::vector descriptor_sets; + vk::Extent2D input_extent; // Destination images std::vector output_images; std::vector output_image_views; std::vector framebuffers; - vk::Extent2D extent; + vk::Extent2D output_extent; - // Foveation - std::array foveation_parameters; + void ensure_vertices(size_t num_vertices); + vertex * get_vertices(size_t view); public: stream_reprojection( vk::raii::Device & device, vk::raii::PhysicalDevice & physical_device, vk::Image input_image, + vk::Extent2D input_extent, uint32_t view_count, std::vector output_images, - vk::Extent2D extent, - vk::Format format, - const wivrn::to_headset::video_stream_description & description); + vk::Extent2D output_extent, + vk::Format format); stream_reprojection(const stream_reprojection &) = delete; - void reproject( + std::vector reproject( vk::raii::CommandBuffer & command_buffer, + const std::array & foveation, int destination); - - void set_foveation(std::array foveation); }; diff --git a/client/shaders/reprojection.glsl b/client/shaders/reprojection.glsl index 6ab6dbda..119ec2c1 100644 --- a/client/shaders/reprojection.glsl +++ b/client/shaders/reprojection.glsl @@ -21,56 +21,15 @@ #ifdef VERT_SHADER -layout (constant_id = 0) const bool use_foveation_x = false; -layout (constant_id = 1) const bool use_foveation_y = false; -layout (constant_id = 2) const int nb_x = 64; -layout (constant_id = 3) const int nb_y = 64; - -layout(set = 0, binding = 1) uniform UniformBufferObject -{ - vec2 a; - vec2 b; - vec2 lambda; - vec2 xc; -} -ubo; +layout (location = 0) in vec2 vPosition; +layout (location = 1) in vec2 vUV; layout(location = 0) out vec2 outUV; -vec2 positions[6] = vec2[]( - vec2(0, 0), vec2(1, 0), vec2(0, 1), - vec2(1, 0), vec2(0, 1), vec2(1, 1)); - -vec2 unfoveate(vec2 uv) -{ - uv = 2 * uv - 1; - if (use_foveation_x && use_foveation_y) - { - uv = ubo.lambda * tan(ubo.a * uv + ubo.b) + ubo.xc; - } - else - { - if (use_foveation_x) - { - uv.x = (ubo.lambda * tan(ubo.a * uv + ubo.b) + ubo.xc).y; - } - if (use_foveation_y) - { - uv.y = (ubo.lambda * tan(ubo.a * uv + ubo.b) + ubo.xc).y; - } - } - return uv; -} - void main() { - vec2 quad_size = 1 / vec2(nb_x, nb_y); - int cell_id = gl_VertexIndex / 6; - - vec2 top_left = quad_size * vec2(cell_id % nb_x, cell_id / nb_x); - outUV = top_left + positions[gl_VertexIndex % 6] * quad_size; - - gl_Position = vec4(unfoveate(outUV), 0.0, 1.0); + gl_Position = vec4(vPosition, 0.0, 1.0); + outUV = vUV; } #endif diff --git a/common/wivrn_packets.h b/common/wivrn_packets.h index 26fb076f..a44a3f64 100644 --- a/common/wivrn_packets.h +++ b/common/wivrn_packets.h @@ -439,18 +439,20 @@ struct handshake int stream_port; }; -struct foveation_parameter_item -{ - float center; - float scale; - float a; - float b; -}; - struct foveation_parameter { - foveation_parameter_item x; - foveation_parameter_item y; + // The number of source pixels for each ratio, + // the middle one is 1:1 + // + // how to read it: + // 1, 4, 5, 3, 1 means: + // the first output pixel has 3 source pixels + // the 4 that come after have 2 source pixels + // then 5 with 1 source pixel + // 3 with 2 source pixels + // 1 with 3 source pixels + std::vector x; + std::vector y; }; struct audio_stream_description @@ -490,7 +492,8 @@ struct video_stream_description uint16_t width; uint16_t height; float fps; - std::array foveation; + uint16_t defoveated_width; + uint16_t defoveated_height; std::vector items; }; diff --git a/patches/monado/0001-c-multi-early-wake-of-compositor.patch b/patches/monado/0001-c-multi-early-wake-of-compositor.patch index 70868313..81ae48b4 100644 --- a/patches/monado/0001-c-multi-early-wake-of-compositor.patch +++ b/patches/monado/0001-c-multi-early-wake-of-compositor.patch @@ -1,7 +1,7 @@ -From 239084ca0a8c5fbc9b3d9efdf9121a60be399650 Mon Sep 17 00:00:00 2001 +From 75d2fe061edd2a268ea9f5fbedc90efd8ffea519 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Tue, 22 Oct 2024 15:23:19 +0200 -Subject: [PATCH 01/10] c/multi: early wake of compositor +Subject: [PATCH 01/11] c/multi: early wake of compositor --- .../compositor/multi/comp_multi_compositor.c | 14 +++++++++ diff --git a/patches/monado/0002-ipc-server-Always-listen-to-stdin.patch b/patches/monado/0002-ipc-server-Always-listen-to-stdin.patch index 71134c2d..aa92ea9a 100644 --- a/patches/monado/0002-ipc-server-Always-listen-to-stdin.patch +++ b/patches/monado/0002-ipc-server-Always-listen-to-stdin.patch @@ -1,7 +1,7 @@ -From 86c09de420ebd47d57bfedc2374c57df8d82aa5a Mon Sep 17 00:00:00 2001 +From 3a8d64c0f569425e2f07b4c2a7803c9bfbc224df Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Tue, 2 Apr 2024 17:14:42 +0200 -Subject: [PATCH 02/10] ipc/server: Always listen to stdin +Subject: [PATCH 02/11] ipc/server: Always listen to stdin --- src/xrt/ipc/server/ipc_server_mainloop_linux.c | 2 +- diff --git a/patches/monado/0003-Use-extern-socket-fd.patch b/patches/monado/0003-Use-extern-socket-fd.patch index f2ffdf3d..91dac0c2 100644 --- a/patches/monado/0003-Use-extern-socket-fd.patch +++ b/patches/monado/0003-Use-extern-socket-fd.patch @@ -1,7 +1,7 @@ -From 49c6eaabb908fca0614f11cd23b82db3d57f514e Mon Sep 17 00:00:00 2001 +From 1a8f4aada945314ac852b19ce20c2ed0345f5bb2 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Tue, 8 Oct 2024 22:13:15 +0200 -Subject: [PATCH 03/10] Use extern socket fd +Subject: [PATCH 03/11] Use extern socket fd --- src/xrt/ipc/server/ipc_server_mainloop_linux.c | 8 ++++++++ diff --git a/patches/monado/0004-c-render-Add-storage-usage-to-distortion-mesh.patch b/patches/monado/0004-c-render-Add-storage-usage-to-distortion-mesh.patch index 56b60c28..ab7de0cc 100644 --- a/patches/monado/0004-c-render-Add-storage-usage-to-distortion-mesh.patch +++ b/patches/monado/0004-c-render-Add-storage-usage-to-distortion-mesh.patch @@ -1,7 +1,7 @@ -From 47c5d07b6974f42714db8433677c158cd5828a94 Mon Sep 17 00:00:00 2001 +From 2f38475c9b51f2d2e92f2fd3d51dcef6d7a53e83 Mon Sep 17 00:00:00 2001 From: galister <3123227-galister@users.noreply.gitlab.com> Date: Mon, 19 Aug 2024 18:51:45 +0900 -Subject: [PATCH 04/10] c/render: Add storage usage to distortion mesh +Subject: [PATCH 04/11] c/render: Add storage usage to distortion mesh --- src/xrt/compositor/render/render_distortion.c | 2 +- diff --git a/patches/monado/0005-change-environment-blend-mode-selection-logic.patch b/patches/monado/0005-change-environment-blend-mode-selection-logic.patch index c59774a1..1dddb321 100644 --- a/patches/monado/0005-change-environment-blend-mode-selection-logic.patch +++ b/patches/monado/0005-change-environment-blend-mode-selection-logic.patch @@ -1,7 +1,7 @@ -From d0c421a582c8e9429b237bc08829f6882185a6fe Mon Sep 17 00:00:00 2001 +From 15eec19c226eb78cb9bc7ebd0021ab226402245a Mon Sep 17 00:00:00 2001 From: galister <85970-galister@users.noreply.gitlab.freedesktop.org> Date: Sat, 23 Nov 2024 02:42:12 +0900 -Subject: [PATCH 05/10] change environment blend mode selection logic +Subject: [PATCH 05/11] change environment blend mode selection logic --- src/xrt/compositor/multi/comp_multi_system.c | 26 +++++++++++++------- diff --git a/patches/monado/0006-Convert-to-YCbCr-in-Monado.patch b/patches/monado/0006-Convert-to-YCbCr-in-Monado.patch index f7f74679..69665f7c 100644 --- a/patches/monado/0006-Convert-to-YCbCr-in-Monado.patch +++ b/patches/monado/0006-Convert-to-YCbCr-in-Monado.patch @@ -1,7 +1,7 @@ -From dc2780aa2e27e00ec38442490e1b24728b30c6c1 Mon Sep 17 00:00:00 2001 +From 06497b57fc56d48611ffc9b6f1bd431141097174 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Wed, 11 Sep 2024 22:56:29 +0200 -Subject: [PATCH 06/10] Convert to YCbCr in Monado +Subject: [PATCH 06/11] Convert to YCbCr in Monado --- src/xrt/compositor/main/comp_renderer.c | 6 +- diff --git a/patches/monado/0007-store-alpha-channel-in-layer-1.patch b/patches/monado/0007-store-alpha-channel-in-layer-1.patch index 1e73aeec..fe6754ae 100644 --- a/patches/monado/0007-store-alpha-channel-in-layer-1.patch +++ b/patches/monado/0007-store-alpha-channel-in-layer-1.patch @@ -1,7 +1,7 @@ -From b40c83a38d13fe511c9dceadeb23dd4fd2cc77f4 Mon Sep 17 00:00:00 2001 +From 2be6264cd7091d593cfec71b7952ff2409ceae4d Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sun, 3 Nov 2024 13:40:00 +0100 -Subject: [PATCH 07/10] store alpha channel in layer 1 +Subject: [PATCH 07/11] store alpha channel in layer 1 --- src/xrt/compositor/shaders/clear.comp | 4 ++-- diff --git a/patches/monado/0008-st-oxr-bind-to-dynamic-role-s-profile.patch b/patches/monado/0008-st-oxr-bind-to-dynamic-role-s-profile.patch index 686308ac..ed9b82ce 100644 --- a/patches/monado/0008-st-oxr-bind-to-dynamic-role-s-profile.patch +++ b/patches/monado/0008-st-oxr-bind-to-dynamic-role-s-profile.patch @@ -1,7 +1,7 @@ -From ee2d823a7959b01b47cdfc03287ffd75361d5b7d Mon Sep 17 00:00:00 2001 +From f5f2fafe497c688170e176ee4e47b9d9dce8ab7b Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Wed, 19 Feb 2025 10:13:36 +0100 -Subject: [PATCH 08/10] st/oxr: bind to dynamic role's profile +Subject: [PATCH 08/11] st/oxr: bind to dynamic role's profile --- src/xrt/state_trackers/oxr/oxr_binding.c | 17 +++++++++++++++++ diff --git a/patches/monado/0009-c-main-allow-custom-pacing-app-factory.patch b/patches/monado/0009-c-main-allow-custom-pacing-app-factory.patch index 298cf2d5..72e86a6d 100644 --- a/patches/monado/0009-c-main-allow-custom-pacing-app-factory.patch +++ b/patches/monado/0009-c-main-allow-custom-pacing-app-factory.patch @@ -1,7 +1,7 @@ -From 8c1dc166ecef3c51c37d78859690cbfd8338d636 Mon Sep 17 00:00:00 2001 +From a906c4d2bc48306a60cd38ceef7dda9d3c7ab0ab Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Thu, 27 Feb 2025 22:45:36 +0100 -Subject: [PATCH 09/10] c/main: allow custom pacing app factory +Subject: [PATCH 09/11] c/main: allow custom pacing app factory --- src/xrt/compositor/main/comp_compositor.c | 10 ++++++---- diff --git a/patches/monado/0010-st-oxr-forward-0-refresh-rate.patch b/patches/monado/0010-st-oxr-forward-0-refresh-rate.patch index 9791dc4f..a00455f9 100644 --- a/patches/monado/0010-st-oxr-forward-0-refresh-rate.patch +++ b/patches/monado/0010-st-oxr-forward-0-refresh-rate.patch @@ -1,7 +1,7 @@ -From 837e5f090583f5c0f7f8c1a06ecc032b4b3733a4 Mon Sep 17 00:00:00 2001 +From aab3a63932eafc7781d6ebbcbb3e825beb0ef4de Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sat, 15 Mar 2025 22:19:48 +0100 -Subject: [PATCH 10/10] st/oxr: forward 0 refresh rate +Subject: [PATCH 10/11] st/oxr: forward 0 refresh rate --- src/xrt/state_trackers/oxr/oxr_api_session.c | 6 +----- diff --git a/patches/monado/0011-Replace-distortion-with-pixel-aligned-foveation.patch b/patches/monado/0011-Replace-distortion-with-pixel-aligned-foveation.patch new file mode 100644 index 00000000..3af6b980 --- /dev/null +++ b/patches/monado/0011-Replace-distortion-with-pixel-aligned-foveation.patch @@ -0,0 +1,700 @@ +From e3efcbec31cfc515be3316d51d9e65bd51f4fe07 Mon Sep 17 00:00:00 2001 +From: Patrick Nicolas +Date: Mon, 2 Jun 2025 14:51:11 +0200 +Subject: [PATCH 11/11] Replace distortion with pixel-aligned foveation + +--- + src/xrt/compositor/CMakeLists.txt | 2 +- + src/xrt/compositor/render/render_compute.c | 181 ++----------------- + src/xrt/compositor/render/render_interface.h | 33 ++-- + src/xrt/compositor/render/render_resources.c | 71 +------- + src/xrt/compositor/shaders/distortion.comp | 134 ++++---------- + src/xrt/compositor/util/comp_render_cs.c | 33 +--- + 6 files changed, 76 insertions(+), 378 deletions(-) + +diff --git a/src/xrt/compositor/CMakeLists.txt b/src/xrt/compositor/CMakeLists.txt +index f1c54ed4d..a2f7ba5cc 100644 +--- a/src/xrt/compositor/CMakeLists.txt ++++ b/src/xrt/compositor/CMakeLists.txt +@@ -115,7 +115,7 @@ if(XRT_HAVE_VULKAN) + ${SHADER_HEADERS} + render/render_buffer.c + render/render_compute.c +- render/render_distortion.c ++ # render/render_distortion.c implemented in wivrn + render/render_gfx.c + render/render_interface.h + render/render_resources.c +diff --git a/src/xrt/compositor/render/render_compute.c b/src/xrt/compositor/render/render_compute.c +index fd04801d4..5cd5a1726 100644 +--- a/src/xrt/compositor/render/render_compute.c ++++ b/src/xrt/compositor/render/render_compute.c +@@ -167,8 +167,8 @@ update_compute_shared_descriptor_set(struct vk_bundle *vk, + VkSampler src_samplers[XRT_MAX_VIEWS], + VkImageView src_image_views[XRT_MAX_VIEWS], + uint32_t distortion_binding, +- VkSampler distortion_samplers[3 * XRT_MAX_VIEWS], +- VkImageView distortion_image_views[3 * XRT_MAX_VIEWS], ++ VkDeviceSize foveation_size, ++ VkBuffer foveation_buffer, + uint32_t target_binding_y, + uint32_t target_binding_cbcr, + VkImageView target_image_view_y, +@@ -186,12 +186,11 @@ update_compute_shared_descriptor_set(struct vk_bundle *vk, + src_image_info[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + } + +- VkDescriptorImageInfo distortion_image_info[3 * XRT_MAX_VIEWS]; +- for (uint32_t i = 0; i < 3 * view_count; ++i) { +- distortion_image_info[i].sampler = distortion_samplers[i]; +- distortion_image_info[i].imageView = distortion_image_views[i]; +- distortion_image_info[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; +- } ++ VkDescriptorBufferInfo foveation_buffer_info = { ++ .buffer = foveation_buffer, ++ .offset = 0, ++ .range = foveation_size, ++ }; + + VkDescriptorImageInfo target_image_y_info = { + .imageView = target_image_view_y, +@@ -222,9 +221,9 @@ update_compute_shared_descriptor_set(struct vk_bundle *vk, + .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, + .dstSet = descriptor_set, + .dstBinding = distortion_binding, +- .descriptorCount = 3 * view_count, +- .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, +- .pImageInfo = distortion_image_info, ++ .descriptorCount = 1, ++ .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, ++ .pBufferInfo = &foveation_buffer_info, + }, + { + .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, +@@ -483,146 +482,6 @@ render_compute_layers(struct render_compute *render, + 1); // groupCountZ + } + +-void +-render_compute_projection_timewarp(struct render_compute *render, +- VkSampler src_samplers[XRT_MAX_VIEWS], +- VkImageView src_image_views[XRT_MAX_VIEWS], +- const struct xrt_normalized_rect src_norm_rects[XRT_MAX_VIEWS], +- const struct xrt_pose src_poses[XRT_MAX_VIEWS], +- const struct xrt_fov src_fovs[XRT_MAX_VIEWS], +- const struct xrt_pose new_poses[XRT_MAX_VIEWS], +- VkImage target_image, +- VkImageView target_image_view_y, +- VkImageView target_image_view_cbcr, +- const struct render_viewport_data views[XRT_MAX_VIEWS]) +-{ +- assert(render->r != NULL); +- +- struct vk_bundle *vk = vk_from_render(render); +- struct render_resources *r = render->r; +- +- +- /* +- * UBO +- */ +- +- struct xrt_matrix_4x4 time_warp_matrix[XRT_MAX_VIEWS]; +- for (uint32_t i = 0; i < render->r->view_count; ++i) { +- render_calc_time_warp_matrix( // +- &src_poses[i], // +- &src_fovs[i], // +- &new_poses[i], // +- &time_warp_matrix[i]); // +- } +- +- struct render_compute_distortion_ubo_data *data = +- (struct render_compute_distortion_ubo_data *)r->compute.distortion.ubo.mapped; +- for (uint32_t i = 0; i < render->r->view_count; ++i) { +- data->views[i] = views[i]; +- data->pre_transforms[i] = r->distortion.uv_to_tanangle[i]; +- data->transforms[i] = time_warp_matrix[i]; +- data->post_transforms[i] = src_norm_rects[i]; +- } +- +- /* +- * Source, target and distortion images. +- */ +- +- VkImageSubresourceRange subresource_range = { +- .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, +- .baseMipLevel = 0, +- .levelCount = VK_REMAINING_MIP_LEVELS, +- .baseArrayLayer = 0, +- .layerCount = VK_REMAINING_ARRAY_LAYERS, +- }; +- +- vk_cmd_image_barrier_gpu_locked( // +- vk, // +- r->cmd, // +- target_image, // +- 0, // +- VK_ACCESS_SHADER_WRITE_BIT, // +- VK_IMAGE_LAYOUT_UNDEFINED, // +- VK_IMAGE_LAYOUT_GENERAL, // +- subresource_range); // +- +- VkSampler sampler = r->samplers.clamp_to_edge; +- VkSampler distortion_samplers[3 * XRT_MAX_VIEWS]; +- for (uint32_t i = 0; i < render->r->view_count; ++i) { +- distortion_samplers[3 * i + 0] = sampler; +- distortion_samplers[3 * i + 1] = sampler; +- distortion_samplers[3 * i + 2] = sampler; +- } +- +- update_compute_shared_descriptor_set( // +- vk, // +- r->compute.src_binding, // +- src_samplers, // +- src_image_views, // +- r->compute.distortion_binding, // +- distortion_samplers, // +- r->distortion.image_views, // +- r->compute.target_binding_y, // +- r->compute.target_binding_cbcr, // +- target_image_view_y, // +- target_image_view_cbcr, // +- r->compute.ubo_binding, // +- r->compute.distortion.ubo.buffer, // +- VK_WHOLE_SIZE, // +- render->shared_descriptor_set, // +- render->r->view_count); // +- +- vk->vkCmdBindPipeline( // +- r->cmd, // +- VK_PIPELINE_BIND_POINT_COMPUTE, // pipelineBindPoint +- r->compute.distortion.timewarp_pipeline); // pipeline +- +- vk->vkCmdBindDescriptorSets( // +- r->cmd, // +- VK_PIPELINE_BIND_POINT_COMPUTE, // pipelineBindPoint +- r->compute.distortion.pipeline_layout, // layout +- 0, // firstSet +- 1, // descriptorSetCount +- &render->shared_descriptor_set, // pDescriptorSets +- 0, // dynamicOffsetCount +- NULL); // pDynamicOffsets +- +- +- uint32_t w = 0, h = 0; +- calc_dispatch_dims_views(views, render->r->view_count, &w, &h); +- assert(w != 0 && h != 0); +- +- vk->vkCmdDispatch( // +- r->cmd, // +- w, // groupCountX +- h, // groupCountY +- 2); // groupCountZ +- +- VkImageMemoryBarrier memoryBarrier = { +- .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, +- .srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT, +- .dstAccessMask = VK_ACCESS_MEMORY_READ_BIT, +- .oldLayout = VK_IMAGE_LAYOUT_GENERAL, +- .newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, +- .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, +- .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, +- .image = target_image, +- .subresourceRange = subresource_range, +- }; +- +- vk->vkCmdPipelineBarrier( // +- r->cmd, // +- VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, // +- VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, // +- 0, // +- 0, // +- NULL, // +- 0, // +- NULL, // +- 1, // +- &memoryBarrier); // +-} +- + void + render_compute_projection(struct render_compute *render, + VkSampler src_samplers[XRT_MAX_VIEWS], +@@ -673,22 +532,14 @@ render_compute_projection(struct render_compute *render, + VK_IMAGE_LAYOUT_GENERAL, // + subresource_range); // + +- VkSampler sampler = r->samplers.clamp_to_edge; +- VkSampler distortion_samplers[3 * XRT_MAX_VIEWS]; +- for (uint32_t i = 0; i < render->r->view_count; ++i) { +- distortion_samplers[3 * i + 0] = sampler; +- distortion_samplers[3 * i + 1] = sampler; +- distortion_samplers[3 * i + 2] = sampler; +- } +- + update_compute_shared_descriptor_set( // + vk, // + r->compute.src_binding, // + src_samplers, // + src_image_views, // + r->compute.distortion_binding, // +- distortion_samplers, // +- r->distortion.image_views, // ++ VK_WHOLE_SIZE, // ++ r->distortion.buffer, // + r->compute.target_binding_y, // + r->compute.target_binding_cbcr, // + target_image_view_y, // +@@ -804,13 +655,9 @@ render_compute_clear(struct render_compute *render, + VkSampler sampler = r->samplers.mock; + VkSampler src_samplers[XRT_MAX_VIEWS]; + VkImageView src_image_views[XRT_MAX_VIEWS]; +- VkSampler distortion_samplers[3 * XRT_MAX_VIEWS]; + for (uint32_t i = 0; i < render->r->view_count; ++i) { + src_samplers[i] = sampler; + src_image_views[i] = r->mock.color.image_view; +- distortion_samplers[3 * i + 0] = sampler; +- distortion_samplers[3 * i + 1] = sampler; +- distortion_samplers[3 * i + 2] = sampler; + } + + update_compute_shared_descriptor_set( // +@@ -819,8 +666,8 @@ render_compute_clear(struct render_compute *render, + src_samplers, // + src_image_views, // + r->compute.distortion_binding, // +- distortion_samplers, // +- r->distortion.image_views, // ++ VK_WHOLE_SIZE, // ++ r->distortion.buffer, // + r->compute.target_binding_y, // + r->compute.target_binding_cbcr, // + target_image_view_y, // +diff --git a/src/xrt/compositor/render/render_interface.h b/src/xrt/compositor/render/render_interface.h +index 2f8ce5287..d74ec78dd 100644 +--- a/src/xrt/compositor/render/render_interface.h ++++ b/src/xrt/compositor/render/render_interface.h +@@ -74,12 +74,8 @@ extern "C" { + #define RENDER_MAX_LAYER_RUNS_SIZE (XRT_MAX_VIEWS) + #define RENDER_MAX_LAYER_RUNS_COUNT(RENDER_RESOURCES) (RENDER_RESOURCES->view_count) + +-//! Distortion image dimension in pixels +-#define RENDER_DISTORTION_IMAGE_DIMENSIONS (128) +- +-//! How many distortion images we have, one for each channel (3 rgb) and per view. +-#define RENDER_DISTORTION_IMAGES_SIZE (3 * XRT_MAX_VIEWS) +-#define RENDER_DISTORTION_IMAGES_COUNT(RENDER_RESOURCES) (3 * RENDER_RESOURCES->view_count) ++//! Foveation buffer dimension in pixels (including past-the end pixel) ++#define RENDER_FOVEATION_BUFFER_DIMENSIONS (4096 + 1) + + //! The binding that the layer projection and quad shader have their UBO on. + #define RENDER_BINDING_LAYER_SHARED_UBO 0 +@@ -519,9 +515,6 @@ struct render_resources + //! Doesn't depend on target so is static. + VkPipeline pipeline; + +- //! Doesn't depend on target so is static. +- VkPipeline timewarp_pipeline; +- + //! Target info. + struct render_buffer ubo; + } distortion; +@@ -543,17 +536,11 @@ struct render_resources + //! Transform to go from UV to tangle angles. + struct xrt_normalized_rect uv_to_tanangle[XRT_MAX_VIEWS]; + +- //! Backing memory to distortion images. +- VkDeviceMemory device_memories[RENDER_DISTORTION_IMAGES_SIZE]; +- +- //! Distortion images. +- VkImage images[RENDER_DISTORTION_IMAGES_SIZE]; ++ //! Backing memory to foveation buffers. ++ VkDeviceMemory device_memory; + +- //! The views into the distortion images. +- VkImageView image_views[RENDER_DISTORTION_IMAGES_SIZE]; +- +- //! Whether distortion images have been pre-rotated 90 degrees. +- bool pre_rotated; ++ //! Foveation buffer. ++ VkBuffer buffer; + } distortion; + }; + +@@ -1298,6 +1285,14 @@ struct render_compute_distortion_ubo_data + struct xrt_matrix_4x4 transforms[XRT_MAX_VIEWS]; + }; + ++struct render_compute_distortion_foveation_data ++{ ++ // For each output pixel: index of the first pixel to read. ++ // contains 1 additional value at the end for past-the end pixel ++ uint32_t x[XRT_MAX_VIEWS * RENDER_FOVEATION_BUFFER_DIMENSIONS]; ++ uint32_t y[XRT_MAX_VIEWS * RENDER_FOVEATION_BUFFER_DIMENSIONS]; ++}; ++ + /*! + * Init struct and create resources needed for compute rendering. + * +diff --git a/src/xrt/compositor/render/render_resources.c b/src/xrt/compositor/render/render_resources.c +index 5b9addd59..7d4d9cddb 100644 +--- a/src/xrt/compositor/render/render_resources.c ++++ b/src/xrt/compositor/render/render_resources.c +@@ -258,8 +258,8 @@ create_compute_distortion_descriptor_set_layout(struct vk_bundle *vk, + }, + { + .binding = distortion_binding, +- .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, +- .descriptorCount = 6, ++ .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, ++ .descriptorCount = 1, + .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, + }, + { +@@ -309,12 +309,6 @@ struct compute_layer_params + uint32_t image_array_size; + }; + +-struct compute_distortion_params +-{ +- uint32_t distortion_texel_count; +- VkBool32 do_timewarp; +-}; +- + XRT_CHECK_RESULT static VkResult + create_compute_layer_pipeline(struct vk_bundle *vk, + VkPipelineCache pipeline_cache, +@@ -359,35 +353,15 @@ create_compute_distortion_pipeline(struct vk_bundle *vk, + VkPipelineCache pipeline_cache, + VkShaderModule shader, + VkPipelineLayout pipeline_layout, +- const struct compute_distortion_params *params, + VkPipeline *out_compute_pipeline) + { +-#define ENTRY(ID, FIELD) \ +- { \ +- .constantID = ID, \ +- .offset = offsetof(struct compute_distortion_params, FIELD), \ +- sizeof(params->FIELD), \ +- } +- +- VkSpecializationMapEntry entries[2] = { +- ENTRY(0, distortion_texel_count), +- ENTRY(1, do_timewarp), +- }; +-#undef ENTRY +- +- VkSpecializationInfo specialization_info = { +- .mapEntryCount = ARRAY_SIZE(entries), +- .pMapEntries = entries, +- .dataSize = sizeof(*params), +- .pData = params, +- }; + + return vk_create_compute_pipeline( // + vk, // vk_bundle + pipeline_cache, // pipeline_cache + shader, // shader + pipeline_layout, // pipeline_layout +- &specialization_info, // specialization_info ++ NULL, // specialization_info + out_compute_pipeline); // out_compute_pipeline + } + +@@ -849,9 +823,9 @@ render_resources_init(struct render_resources *r, + struct vk_descriptor_pool_info compute_pool_info = { + .uniform_per_descriptor_count = 1, + // layer images +- .sampler_per_descriptor_count = r->compute.layer.image_array_size + RENDER_DISTORTION_IMAGES_COUNT(r), ++ .sampler_per_descriptor_count = r->compute.layer.image_array_size, + .storage_image_per_descriptor_count = 1, +- .storage_buffer_per_descriptor_count = 0, ++ .storage_buffer_per_descriptor_count = 1, + .descriptor_count = compute_descriptor_count, + .freeable = false, + }; +@@ -971,39 +945,16 @@ render_resources_init(struct render_resources *r, + VK_NAME_PIPELINE_LAYOUT(vk, r->compute.distortion.pipeline_layout, + "render_resources compute distortion pipeline layout"); + +- struct compute_distortion_params distortion_params = { +- .distortion_texel_count = RENDER_DISTORTION_IMAGE_DIMENSIONS, +- .do_timewarp = false, +- }; +- + ret = create_compute_distortion_pipeline( // + vk, // vk_bundle + r->pipeline_cache, // pipeline_cache + r->shaders->distortion_comp, // shader + r->compute.distortion.pipeline_layout, // pipeline_layout +- &distortion_params, // params + &r->compute.distortion.pipeline); // out_compute_pipeline + VK_CHK_WITH_RET(ret, "create_compute_distortion_pipeline", false); + + VK_NAME_PIPELINE(vk, r->compute.distortion.pipeline, "render_resources compute distortion pipeline"); + +- struct compute_distortion_params distortion_timewarp_params = { +- .distortion_texel_count = RENDER_DISTORTION_IMAGE_DIMENSIONS, +- .do_timewarp = true, +- }; +- +- ret = create_compute_distortion_pipeline( // +- vk, // vk_bundle +- r->pipeline_cache, // pipeline_cache +- r->shaders->distortion_comp, // shader +- r->compute.distortion.pipeline_layout, // pipeline_layout +- &distortion_timewarp_params, // params +- &r->compute.distortion.timewarp_pipeline); // out_compute_pipeline +- VK_CHK_WITH_RET(ret, "create_compute_distortion_pipeline", false); +- +- VK_NAME_PIPELINE(vk, r->compute.distortion.timewarp_pipeline, +- "render_resources compute distortion timewarp pipeline"); +- + size_t distortion_ubo_size = sizeof(struct render_compute_distortion_ubo_data); + + ret = render_buffer_init( // +@@ -1056,15 +1007,8 @@ render_resources_init(struct render_resources *r, + * Compute distortion textures, not created until later. + */ + +- for (uint32_t i = 0; i < RENDER_DISTORTION_IMAGES_COUNT(r); i++) { +- r->distortion.image_views[i] = VK_NULL_HANDLE; +- } +- for (uint32_t i = 0; i < RENDER_DISTORTION_IMAGES_COUNT(r); i++) { +- r->distortion.images[i] = VK_NULL_HANDLE; +- } +- for (uint32_t i = 0; i < RENDER_DISTORTION_IMAGES_COUNT(r); i++) { +- r->distortion.device_memories[i] = VK_NULL_HANDLE; +- } ++ r->distortion.buffer = VK_NULL_HANDLE; ++ r->distortion.device_memory = VK_NULL_HANDLE; + + + /* +@@ -1141,7 +1085,6 @@ render_resources_fini(struct render_resources *r) + + D(DescriptorSetLayout, r->compute.distortion.descriptor_set_layout); + D(Pipeline, r->compute.distortion.pipeline); +- D(Pipeline, r->compute.distortion.timewarp_pipeline); + D(PipelineLayout, r->compute.distortion.pipeline_layout); + + D(Pipeline, r->compute.clear.pipeline); +diff --git a/src/xrt/compositor/shaders/distortion.comp b/src/xrt/compositor/shaders/distortion.comp +index 9ce46fe6f..f3be617bd 100644 +--- a/src/xrt/compositor/shaders/distortion.comp ++++ b/src/xrt/compositor/shaders/distortion.comp +@@ -7,17 +7,17 @@ + + #include "srgb.inc.glsl" + +- +-// The size of the distortion texture dimensions in texels. +-layout(constant_id = 0) const int distortion_texel_count = 2; +- +-// Should we do timewarp. +-layout(constant_id = 1) const bool do_timewarp = false; +- + layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; + ++#define MAX_DIM 4097 ++ + layout(set = 0, binding = 0) uniform sampler2D source[2]; +-layout(set = 0, binding = 1) uniform sampler2D distortion[6]; ++layout(set = 0, binding = 1, std430) buffer restrict Foveation ++{ ++ uint x[2*MAX_DIM]; ++ uint y[2*MAX_DIM]; ++} foveation; ++ + layout(set = 0, binding = 2) uniform writeonly restrict image2DArray luma; + layout(set = 0, binding = 3, std140) uniform restrict Config + { +@@ -41,109 +41,40 @@ vec3 rgb_to_ycbcr(vec3 color) + return transpose(color_space) * color + vec3(0, 0.5, 0.5); + } + +-vec2 position_to_uv(ivec2 extent, uint ix, uint iy) +-{ +- // Turn the index into floating point. +- vec2 xy = vec2(float(ix), float(iy)); +- +- // The inverse of the extent of the target image is the pixel size in [0 .. 1] space. +- vec2 extent_pixel_size = vec2(1.0 / float(extent.x), 1.0 / float(extent.y)); +- +- // Per-target pixel we move the size of the pixels. +- vec2 dist_uv = xy * extent_pixel_size; +- +- // Emulate a triangle sample position by offset half target pixel size. +- dist_uv = dist_uv + extent_pixel_size / 2.0; +- +- +- // To correctly sample we need to put position (0, 0) in the +- // middle of the (0, 0) texel in the distortion textures. That's why we +- // offset with half the texel size, pushing all samples into the middle +- // of each texels, a kin to a vertex buffer. We need to put uv coord +- // (1, 1) in the middle of the last texel, that pixel is (size - 1) +- // texels away from the first texel. So we need to scale [0 .. 1] to +- // [0 .. size - 1]. +- +-#define DIM (float(distortion_texel_count)) +-#define STRETCH ((DIM - 1.0) / DIM) +-#define OFFSET (1.0 / (DIM * 2.0)) +- +- dist_uv = (dist_uv * STRETCH) + OFFSET; +- +- return dist_uv; +-} +- +-vec2 transform_uv_subimage(vec2 uv, uint iz) +-{ +- vec2 values = uv; +- +- // To deal with OpenGL flip and sub image view. +- values.xy = values.xy * ubo.post_transform[iz].zw + ubo.post_transform[iz].xy; +- +- // Ready to be used. +- return values.xy; +-} +- +-vec2 transform_uv_timewarp(vec2 uv, uint iz) +-{ +- vec4 values = vec4(uv, -1, 1); +- +- // From uv to tan angle (tangent space). +- values.xy = values.xy * ubo.pre_transform[iz].zw + ubo.pre_transform[iz].xy; +- values.y = -values.y; // Flip to OpenXR coordinate system. +- +- // Timewarp. +- values = ubo.transform[iz] * values; +- values.xy = values.xy * (1.0 / max(values.w, 0.00001)); +- +- // From [-1, 1] to [0, 1] +- values.xy = values.xy * 0.5 + 0.5; +- +- // To deal with OpenGL flip and sub image view. +- values.xy = values.xy * ubo.post_transform[iz].zw + ubo.post_transform[iz].xy; +- +- // Done. +- return values.xy; +-} +- +-vec2 transform_uv(vec2 uv, uint iz) +-{ +- if (do_timewarp) { +- return transform_uv_timewarp(uv, iz); +- } else { +- return transform_uv_subimage(uv, iz); +- } +-} +- + void main() + { + uint iz = gl_GlobalInvocationID.z; + + ivec2 offset = ivec2(ubo.views[iz].xy); + ivec2 extent = ivec2(ubo.views[iz].zw); +- vec2 cbcrs[4]; +- vec4 alpha; ++ vec3 cbcra = vec3(0); + for (int k = 0; k < 2; k += 1) { + uint iy = gl_GlobalInvocationID.y * 2 + k; ++ uint ymin = foveation.y[MAX_DIM * iz + iy]; ++ uint ymax = foveation.y[MAX_DIM * iz + iy + 1]; ++ if (ymin > ymax) ++ { ++ uint tmp = ymin; ++ ymin = ymax; ++ ymax = tmp; ++ } + for (int j = 0; j < 2; j += 1) { + uint ix = gl_GlobalInvocationID.x * 2 + j; + +- vec2 dist_uv = position_to_uv(extent, ix, iy); ++ uint xmin = foveation.x[MAX_DIM * iz + ix]; ++ uint xmax = foveation.x[MAX_DIM * iz + ix + 1]; + +- vec2 uv = texture(distortion[iz + 0], dist_uv).xy; +- vec2 lod = texture(distortion[iz + 2], dist_uv).xy; +- +- // Do any transformation needed. +- uv = transform_uv(uv, iz); +- +- // Sample the source +- vec4 colour = textureLod(source[iz], uv, mix(lod.x, lod.y, 0.5)); +- +- colour.rgb = rgb_to_ycbcr(from_linear_to_srgb(colour.rgb)); ++ vec4 colour = vec4(0); ++ for (uint y = ymin ; y < ymax; y += 1) { ++ for (uint x = xmin ; x < xmax; x += 1) { ++ colour += texelFetch(source[iz], ivec2(x, y), 0); ++ } ++ } ++ colour /= (xmax - xmin) * (ymax - ymin); ++ colour.xyz = rgb_to_ycbcr(from_linear_to_srgb(colour.rgb)); + +- int i = k * 2 + j; +- cbcrs[i] = colour.yz; +- alpha[i] = colour.a; ++ cbcra.xy += colour.yz; ++ cbcra.z += colour.a; + + if (ix < extent.x && iy < extent.y) { + imageStore(luma, ivec3(offset.x + ix, offset.y + iy, 0), vec4(colour.x)); +@@ -153,10 +84,7 @@ void main() + if (gl_GlobalInvocationID.x >= extent.x || gl_GlobalInvocationID.y >= extent.y) { + return; + } +- vec2 cbcr = mix(mix(cbcrs[0], cbcrs[1], 0.5), mix(cbcrs[2], cbcrs[3], 0.5), 0.5); +- imageStore(chroma, ivec3(offset.xy/2 + gl_GlobalInvocationID.xy, 0), vec4(cbcr.x, cbcr.y, 0, 0)); +- ++ imageStore(chroma, ivec3(offset.xy/2 + gl_GlobalInvocationID.xy, 0), vec4(cbcra.x, cbcra.y, 0, 0) / 4); ++ imageStore(luma, ivec3(offset.xy/2 + gl_GlobalInvocationID.xy, 1), vec4(cbcra.z, 0, 0, 0) / 4); + imageStore(chroma, ivec3(offset.xy/2 + gl_GlobalInvocationID.xy, 1), vec4(0.5, 0.5, 0, 0)); +- alpha = vec4(mix(mix(alpha[0], alpha[1], 0.5), mix(alpha[2], alpha[3], 0.5), 0.5)); +- imageStore(luma, ivec3(offset.xy/2 + gl_GlobalInvocationID.xy, 1), alpha); + } +diff --git a/src/xrt/compositor/util/comp_render_cs.c b/src/xrt/compositor/util/comp_render_cs.c +index c06dda63d..a4934890f 100644 +--- a/src/xrt/compositor/util/comp_render_cs.c ++++ b/src/xrt/compositor/util/comp_render_cs.c +@@ -465,30 +465,15 @@ crc_distortion_fast_path(struct render_compute *render, + world_poses[i] = world_pose; + } + +- if (!d->do_timewarp) { +- render_compute_projection( // +- render, // +- src_samplers, // +- src_image_views, // +- src_norm_rects, // +- d->cs.target_image, // +- d->cs.target_unorm_view_y, // +- d->cs.target_unorm_view_cbcr, // +- target_viewport_datas); // +- } else { +- render_compute_projection_timewarp( // +- render, // +- src_samplers, // +- src_image_views, // +- src_norm_rects, // +- src_poses, // +- src_fovs, // +- world_poses, // +- d->cs.target_image, // +- d->cs.target_unorm_view_y, // +- d->cs.target_unorm_view_cbcr, // +- target_viewport_datas); // +- } ++ render_compute_projection( // ++ render, // ++ src_samplers, // ++ src_image_views, // ++ src_norm_rects, // ++ d->cs.target_image, // ++ d->cs.target_unorm_view_y, // ++ d->cs.target_unorm_view_cbcr, // ++ target_viewport_datas); // + } + + +-- +2.49.0 + diff --git a/server/driver/wivrn_comp_target.cpp b/server/driver/wivrn_comp_target.cpp index 0c7184d8..314e9a9b 100644 --- a/server/driver/wivrn_comp_target.cpp +++ b/server/driver/wivrn_comp_target.cpp @@ -109,6 +109,9 @@ static void destroy_images(struct wivrn_comp_target * cn) if (cn->images == nullptr) return; + if (cn->wivrn_bundle) + cn->wivrn_bundle->device.waitIdle(); + cn->psc.status = 1; cn->psc.status.notify_all(); cn->encoder_threads.clear(); @@ -135,7 +138,9 @@ static void create_encoders(wivrn_comp_target * cn) to_headset::video_stream_description & desc = cn->desc; desc.width = cn->width; desc.height = cn->height; - desc.foveation = cn->cnx.set_foveated_size(desc.width, desc.height); + const auto & hmd = cn->cnx.get_hmd().hmd; + desc.defoveated_width = hmd->views[0].display.w_pixels * 2; + desc.defoveated_height = hmd->views[0].display.h_pixels; std::map>> thread_params; @@ -316,11 +321,8 @@ static bool comp_wivrn_init_post_vulkan(struct comp_target * ct, uint32_t prefer U_LOG_E("Failed to create video encoder: %s", e.what()); return false; } - - if (cn->cnx.has_dynamic_foveation()) - { - cn->foveation_renderer = std::make_unique(*cn->wivrn_bundle, cn->command_pool); - } + cn->cnx.set_foveated_size(cn->c->settings.preferred.width, cn->c->settings.preferred.height); + cn->foveation.emplace(*cn->wivrn_bundle, *cn->cnx.get_hmd().hmd); return true; } @@ -609,7 +611,7 @@ static VkResult comp_wivrn_present(struct comp_target * ct, #endif auto & view_info = cn->psc.view_info; - view_info.foveation = cn->cnx.get_foveation_parameters(); + view_info.foveation = cn->foveation->get_parameters(); view_info.display_time = cn->cnx.get_offset().to_headset(info.predicted_display_time); if (view_info.alpha != do_alpha) cn->pacer.reset(); @@ -651,16 +653,47 @@ static void comp_wivrn_flush(struct comp_target * ct) r->StartFrameCapture(NULL, NULL); #endif + vk::CommandBuffer cmd; // apply foveation for current frame - if (cn->cnx.apply_dynamic_foveation()) - // foveation renderer already signaled the semaphore; nothing to do - return; + if (cn->c->base.frame_params.one_projection_layer_fast_path) + { + const auto & data = cn->c->base.layer_accum.layers[0].data; + const auto & hmd = cn->cnx.get_hmd().hmd; + xrt_rect rect[] = {data.proj.v[0].sub.rect, data.proj.v[1].sub.rect}; + xrt_fov fov[] = {data.proj.v[0].fov, data.proj.v[1].fov}; + cmd = cn->foveation->update_foveation_buffer( + ct->c->nr.distortion.buffer, + data.flip_y, + rect, + fov); + } + else + { + const auto & hmd = cn->cnx.get_hmd().hmd; + xrt_rect rect[] = { + {.extent = { + .w = int(hmd->views[0].display.w_pixels), + .h = int(hmd->views[0].display.h_pixels), + }}, + {.extent = { + .w = int(hmd->views[1].display.w_pixels), + .h = int(hmd->views[1].display.h_pixels), + }}, + }; + cmd = cn->foveation->update_foveation_buffer( + ct->c->nr.distortion.buffer, + false, + rect, + hmd->distortion.fov); + } struct vk_bundle * vk = get_vk(cn); vk::Semaphore sem(cn->semaphores.present_complete); vk::SubmitInfo submit_info{ + .commandBufferCount = cmd ? 1u : 0, + .pCommandBuffers = &cmd, .signalSemaphoreCount = 1, .pSignalSemaphores = &sem, }; @@ -753,14 +786,14 @@ static xrt_result_t comp_wivrn_request_refresh_rate(struct comp_target * ct, flo wivrn_comp_target::~wivrn_comp_target() { - if (wivrn_bundle) - wivrn_bundle->device.waitIdle(); destroy_images(this); } static void comp_wivrn_destroy(struct comp_target * ct) { - delete (struct wivrn_comp_target *)ct; + auto cn = (struct wivrn_comp_target *)ct; + destroy_images(cn); + cn->self = nullptr; } static void comp_wivrn_info_gpu(struct comp_target * ct, int64_t frame_id, int64_t gpu_start_ns, int64_t gpu_end_ns, int64_t when_ns) @@ -800,27 +833,6 @@ void wivrn_comp_target::set_bitrate(int bitrate_bps) } } -void wivrn_comp_target::render_dynamic_foveation(std::array foveation) -{ - assert(foveation_renderer); - - vk::Semaphore sem(semaphores.present_complete); - - vk::SubmitInfo submit_info{ - .commandBufferCount = 1, - .pCommandBuffers = &*foveation_renderer->cmd_buf, - .signalSemaphoreCount = 1, - .pSignalSemaphores = &sem, - }; - - foveation_renderer->render_distortion_images(foveation, c->nr.distortion.images, c->nr.distortion.image_views); - - { - scoped_lock lock(c->base.vk.queue_mutex); - wivrn_bundle->queue.submit(submit_info); - } -} - void wivrn_comp_target::set_refresh_rate(float refresh_rate_hz) { U_LOG_I("Refresh rate change from %.0f to %.0f", desc.fps, refresh_rate_hz); diff --git a/server/driver/wivrn_comp_target.h b/server/driver/wivrn_comp_target.h index 9ed0a7a4..76bedf2d 100644 --- a/server/driver/wivrn_comp_target.h +++ b/server/driver/wivrn_comp_target.h @@ -78,6 +78,7 @@ struct pseudo_swapchain struct wivrn_comp_target : public comp_target { + std::shared_ptr self; to_headset::video_stream_description desc{}; wivrn_pacer pacer; @@ -98,7 +99,7 @@ struct wivrn_comp_target : public comp_target std::vector> encoders; wivrn::wivrn_session & cnx; - std::unique_ptr foveation_renderer = nullptr; + std::optional foveation; std::atomic requested_refresh_rate; @@ -109,8 +110,6 @@ struct wivrn_comp_target : public comp_target void reset_encoders(); void set_bitrate(int bitrate_bps); - void render_dynamic_foveation(std::array foveation); - void set_refresh_rate(float); }; diff --git a/server/driver/wivrn_foveation.cpp b/server/driver/wivrn_foveation.cpp index c3673bc6..80158abf 100644 --- a/server/driver/wivrn_foveation.cpp +++ b/server/driver/wivrn_foveation.cpp @@ -1,6 +1,7 @@ /* * WiVRn VR streaming * Copyright (C) 2024 galister + * Copyright (C) 2025 Patrick Nicolas * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,6 +18,7 @@ */ #include "render/render_interface.h" +#include "vk/vk_mini_helpers.h" #include "wivrn_foveation.h" @@ -29,200 +31,113 @@ #include #include #include +#include #include #include #include extern const std::map> shaders; -namespace wivrn +bool render_distortion_images_ensure(struct render_resources * r, + struct vk_bundle * vk, + struct xrt_device * xdev, + bool pre_rotate) { - -const uint32_t dispatch_group_count = RENDER_DISTORTION_IMAGE_DIMENSIONS / 8; - -struct FoveationParamsPcs -{ - float a[2]; - float b[2]; - float scale[2]; - float center[2]; -}; - -static const std::array pool_sizes = - { - vk::DescriptorPoolSize{ - .type = vk::DescriptorType::eStorageImage, - .descriptorCount = 2, - }}; - -static const std::array layout_bindings{ - vk::DescriptorSetLayoutBinding{.binding = 0, - .descriptorType = vk::DescriptorType::eStorageImage, - .descriptorCount = 1, - .stageFlags = vk::ShaderStageFlagBits::eCompute}, -}; - -wivrn_foveation_renderer::wivrn_foveation_renderer(wivrn_vk_bundle & vk, vk::raii::CommandPool & cmd_pool) : - vk(vk), - dp(vk.device, - vk::DescriptorPoolCreateInfo{ - .flags = vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, - .maxSets = pool_sizes[0].descriptorCount, - .poolSizeCount = pool_sizes.size(), - .pPoolSizes = pool_sizes.data(), - }), - ds_layout(vk.device, vk::DescriptorSetLayoutCreateInfo{.bindingCount = layout_bindings.size(), .pBindings = layout_bindings.data()}) -{ - cmd_buf = std::move(vk.device.allocateCommandBuffers( - {.commandPool = *cmd_pool, - .commandBufferCount = 1})[0]); - - // Pipeline layout + if (r->distortion.buffer == VK_NULL_HANDLE) { - vk::PushConstantRange push_constant_range{ - .stageFlags = vk::ShaderStageFlagBits::eCompute, - .offset = 0, - .size = sizeof(FoveationParamsPcs), - }; - layout = vk.device.createPipelineLayout({ - .setLayoutCount = 1, - .pSetLayouts = &*ds_layout, - .pushConstantRangeCount = 1, - .pPushConstantRanges = &push_constant_range, - }); + return vk_buffer_init(vk, + sizeof(render_compute_distortion_foveation_data), + VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, + &r->distortion.buffer, + &r->distortion.device_memory); } - - // Pipeline - { - auto & spirv = shaders.at("foveate.comp"); - vk::raii::ShaderModule shader(vk.device, { - .codeSize = spirv.size() * sizeof(uint32_t), - .pCode = spirv.data(), - }); - - float one_over_dim = 1.0 / (RENDER_DISTORTION_IMAGE_DIMENSIONS - 1); - - vk::SpecializationMapEntry specMapEntry{ - .constantID = 0, - .offset = 0, - .size = sizeof(float), - }; - - vk::SpecializationInfo specInfo{ - .mapEntryCount = 1, - .pMapEntries = &specMapEntry, - .dataSize = sizeof(float), - .pData = &one_over_dim, - }; - - pipeline = vk::raii::Pipeline(vk.device, nullptr, vk::ComputePipelineCreateInfo{ - .stage = { - .stage = vk::ShaderStageFlagBits::eCompute, - .module = *shader, - .pName = "main", - .pSpecializationInfo = &specInfo, - }, - .layout = *layout, - }); - } - - std::array layouts = {*ds_layout, *ds_layout}; - - auto my_ds = vk.device.allocateDescriptorSets({ - .descriptorPool = *dp, - .descriptorSetCount = 2, - .pSetLayouts = layouts.data(), - }); - - ds = { - my_ds[0].release(), - my_ds[1].release(), - }; + return true; } -void wivrn_foveation_renderer::render_distortion_images(std::array foveations, const VkImage * images, const VkImageView * image_views) +void render_distortion_images_fini(struct render_resources * r) { - cmd_buf.reset(); - cmd_buf.begin(vk::CommandBufferBeginInfo{}); - - // images: left position, right position, left derivate, right derivate - std::array im_barriers; - im_barriers.fill({ - .srcAccessMask = vk::AccessFlagBits::eNone, - .dstAccessMask = vk::AccessFlagBits::eMemoryWrite, - .oldLayout = vk::ImageLayout::eShaderReadOnlyOptimal, - .newLayout = vk::ImageLayout::eGeneral, - .subresourceRange = {.aspectMask = vk::ImageAspectFlagBits::eColor, - .baseMipLevel = 0, - .levelCount = 1, - .baseArrayLayer = 0, - .layerCount = 1}, - }); - for (size_t i = 0; i < im_barriers.size(); ++i) - im_barriers[i].image = vk::Image(images[i]); - - cmd_buf.pipelineBarrier( - vk::PipelineStageFlagBits::eTopOfPipe, - vk::PipelineStageFlagBits::eComputeShader, - {}, - nullptr, - nullptr, - im_barriers); - - // Monado's distortion shader is patched to read red as position and green as derivate - for (int eye = 0; eye < 2; ++eye) - { - // Descriptor set - - vk::DescriptorImageInfo image_info{ - .imageView = vk::ImageView(image_views[eye]), - .imageLayout = vk::ImageLayout::eGeneral, - }; - vk.device.updateDescriptorSets( - vk::WriteDescriptorSet{ - .dstSet = ds[eye], - .dstBinding = 0, - .descriptorCount = 1, - .descriptorType = vk::DescriptorType::eStorageImage, - .pImageInfo = &image_info, - }, - nullptr); - - auto foveation = foveations[eye]; - - FoveationParamsPcs f_params{ - .a = {foveation.x.a, foveation.y.a}, - .b = {foveation.x.b, foveation.y.b}, - .scale = {foveation.x.scale, foveation.y.scale}, - .center = {foveation.x.center, foveation.y.center}, - }; - - cmd_buf.bindPipeline(vk::PipelineBindPoint::eCompute, *pipeline); - cmd_buf.bindDescriptorSets(vk::PipelineBindPoint::eCompute, *layout, 0, ds[eye], {}); - cmd_buf.pushConstants(*layout, vk::ShaderStageFlagBits::eCompute, 0, f_params); - cmd_buf.dispatch(dispatch_group_count, dispatch_group_count, 1); - } - - for (auto & barrier: im_barriers) - { - barrier.srcAccessMask = vk::AccessFlagBits::eMemoryWrite; - barrier.dstAccessMask = vk::AccessFlagBits::eNone; - barrier.oldLayout = vk::ImageLayout::eGeneral; - barrier.newLayout = vk::ImageLayout::eShaderReadOnlyOptimal; - } - - cmd_buf.pipelineBarrier( - vk::PipelineStageFlagBits::eComputeShader, - vk::PipelineStageFlagBits::eBottomOfPipe, - {}, - nullptr, - nullptr, - im_barriers); - - cmd_buf.end(); + auto * vk = r->vk; + D(Buffer, r->distortion.buffer); + DF(Memory, r->distortion.device_memory); } -xrt_vec2 yaw_pitch(xrt_quat q) +static double foveate(double a, double b, double λ, double c, double x) +{ + // In order to save encoding, transmit and decoding time, only a portion of the image is encoded in full resolution. + // on each axis, foveated coordinates are defined by the following formula. + return λ / a * tan(a * x + b) + c; + // a and b are defined such as: + // edges of the image are not moved + // f(-1) = -1 + // f( 1) = 1 + // the function also enforces pixel ratio 1:1 at fovea + // df⁻¹(x)/dx = 1/scale for x = c + + // We then ensure that source and destination pixel grids match by + // rounding to integer pixel ratios: 1:1, 1:2 etc. + // Finally, pixel spans are sorted so that we only have increasing + // ratios going out from the center. +} + +static std::tuple solve_foveation(float λ, float c) +{ + // Compute a and b for the foveation function such that: + // foveate(a, b, scale, c, -1) = -1 (eq. 1) + // foveate(a, b, scale, c, 1) = 1 (eq. 2) + // + // Use eq. 2 to express a as function of b, then replace in eq. 1 + // equation that needs to be null is: + auto b = [λ, c](double a) { return atan(a * (1 - c) / λ) - a; }; + auto eq = [λ, c](double a) { return atan(a * (1 - c) / λ) + atan(a * (1 + c) / λ) - 2 * a; }; // (eq. 3) + + // function starts positive, reaches a maximum then decreases to -∞ + double a0 = 0; + // Find a negative value by computing eq(2^n) + double a1 = 1; + while (eq(a1) > 0) + a1 *= 2; + + // last computed values for f(a0) and f(a1) + std::optional f_a0; + double f_a1 = eq(a1); + + int n = 0; + double a = 0; + while (std::abs(a1 - a0) > 0.0000001 && n++ < 100) + { + if (not f_a0) + { + // use binary search + a = 0.5 * (a0 + a1); + double val = eq(a); + if (val > 0) + { + a0 = a; + f_a0 = val; + } + else + { + a1 = a; + f_a1 = val; + } + } + else + { + // f(a1) is always defined + // when f(a0) is defined, use secant method + a = a1 - f_a1 * (a1 - a0) / (f_a1 - *f_a0); + a0 = a1; + a1 = a; + f_a0 = f_a1; + f_a1 = eq(a); + } + } + + return {a, b(a)}; +} + +static xrt_vec2 yaw_pitch(xrt_quat q) { float sine_theta = std::clamp(-2.0f * (q.y * q.z - q.w * q.x), -1.0f, 1.0f); @@ -240,20 +155,108 @@ xrt_vec2 yaw_pitch(xrt_quat q) pitch}; } -std::array wivrn_foveation::get_center() +void fill_param_2d( + float angle_min, + float angle_max, + size_t foveated_dim, + size_t source_dim, + std::vector & out) +{ + float scale = float(foveated_dim) / source_dim; + const float l = tan(angle_min); + const float r = tan(angle_max); + // FIXME: use tan_center + float c = (r + l) / (l - r); + auto [a, b] = solve_foveation(scale, c); + + uint16_t last = 0; + std::vector left; // index 0: 1:1 ratio, then 2:1 etc. + std::vector right; + for (size_t i = 1; i < foveated_dim; ++i) + { + double u = (i * 2.) / foveated_dim - 1; + auto f = foveate(a, b, scale, c, u); + uint16_t n = std::clamp((f * 0.5 + 0.5) * source_dim + 0.5, 0, source_dim); + assert(n > last); + size_t count = n - last; + auto & vec = u < c ? left : right; + if (count > vec.size()) + vec.resize(count); + vec[count - 1]++; + last = n; + } + assert(last < source_dim); + size_t count = source_dim - last; + if (count > right.size()) + right.resize(count); + right[count - 1]++; + + count = std::max(left.size(), right.size()); + out.clear(); + out.resize(count - left.size()); + out.insert(out.end(), left.rbegin(), left.rend()); + if (not right.empty()) + out.back() += right.front(); + if (right.size() > 1) + out.insert(out.end(), right.begin() + 1, right.end()); + out.resize(count * 2 - 1); +} + +namespace wivrn +{ + +void wivrn_foveation::compute_params( + xrt_rect src[2], + const xrt_fov fovs[2]) { std::lock_guard lock(mutex); - std::array uvs; - auto e = yaw_pitch(last_gaze); - - for (int i = 0; i < 2; i++) + xrt_vec2 tan_center{}; + if (gaze.x != 0 or gaze.y != 0 or gaze.z != 0 or gaze.w != 0) { - uvs[i].x = (e.x - views[i].fov.angleLeft) / (views[i].fov.angleRight - views[i].fov.angleLeft) * 2 - 1 + center_offset[i].x; - uvs[i].y = (e.y - views[i].fov.angleDown) / (views[i].fov.angleUp - views[i].fov.angleDown) * 2 - 1 + center_offset[i].y; + auto e = yaw_pitch(gaze); + for (size_t i = 0; i < 2; ++i) + { + (void)e; + // TODO: implement + // uvs[i].x = (e.x - views[i].fov.angleLeft) / (views[i].fov.angleRight - views[i].fov.angleLeft) * 2 - 1 + center_offset[i].x; + // uvs[i].y = (e.y - views[i].fov.angleDown) / (views[i].fov.angleUp - views[i].fov.angleDown) * 2 - 1 + center_offset[i].y; + } } - return uvs; + for (int i = 0; i < 2; ++i) + { + const auto & fov = fovs[i]; + if (foveated_width < src[i].extent.w) + fill_param_2d(fov.angle_left, fov.angle_right, foveated_width, src[i].extent.w, params[i].x); + else + params[i].x = {uint16_t(src[i].extent.w)}; + if (foveated_height < src[i].extent.h) + fill_param_2d(fov.angle_up, fov.angle_down, foveated_height, src[i].extent.h, params[i].y); + else + params[i].y = {uint16_t(src[i].extent.h)}; + } +} + +wivrn_foveation::wivrn_foveation(wivrn_vk_bundle & bundle, const xrt_hmd_parts & hmd) : + foveated_width(hmd.screens[0].w_pixels / 2), + foveated_height(hmd.screens[0].h_pixels), + command_pool(bundle.device, vk::CommandPoolCreateInfo{.queueFamilyIndex = bundle.queue_family_index}), + cmd(std::move(bundle.device.allocateCommandBuffers({ + .commandPool = command_pool, + .commandBufferCount = 1, + })[0])), + host_buffer( + bundle.device, + { + .size = sizeof(render_compute_distortion_foveation_data), + .usage = vk::BufferUsageFlagBits::eTransferSrc, + }, + VmaAllocationCreateInfo{ + .flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT, + .usage = VMA_MEMORY_USAGE_AUTO, + }) +{ } void wivrn_foveation::update_tracking(const from_headset::tracking & tracking, const clock_offset & offset) @@ -290,16 +293,102 @@ void wivrn_foveation::update_tracking(const from_headset::tracking & tracking, c return; xrt_quat qgaze = xrt_cast(pose.pose.orientation); - math_quat_unrotate(&qgaze, &head.value(), &last_gaze); + math_quat_unrotate(&qgaze, &head.value(), &gaze); break; } } -void wivrn_foveation::set_initial_parameters(std::array p) +std::array wivrn_foveation::get_parameters() { std::lock_guard lock(mutex); + return params; +} - center_offset[0] = {p[0].x.center, p[0].y.center}; - center_offset[1] = {p[1].x.center, p[1].y.center}; +static void fill_ubo( + uint32_t * ubo, + const std::vector & params, + bool flip, + size_t offset, + size_t size, + int count) +{ + assert(params.size() % 2 == 1); + const int n_ratio = (params.size() - 1) / 2; + *ubo = offset; + if (flip) + *ubo += size; + for (auto [i, n]: std::ranges::enumerate_view(params)) + { + const int n_source = std::abs(n_ratio - int(i)) + 1; + for (size_t j = 0; j < n; ++j) + { + if (flip) + ubo[1] = ubo[0] - n_source; + else + ubo[1] = ubo[0] + n_source; + ++ubo; + --count; + } + } + if (count > 0) + std::fill(ubo + 1, ubo + count + 1, *ubo); +} + +template +static bool operator==(const T & a, const T & b) +{ + static_assert(std::has_unique_object_representations_v); + return std::memcmp(&a, &b, sizeof(T)) == 0; +} +bool operator==(const xrt_quat & a, const xrt_quat & b) +{ + return a.x == b.x and a.y == b.y and a.z == b.z and a.w == b.w; +} +bool operator==(const xrt_fov & a, const xrt_fov & b) +{ + return a.angle_left == b.angle_left and a.angle_right == b.angle_right and a.angle_up == b.angle_up and a.angle_down == b.angle_down; +} + +vk::CommandBuffer wivrn_foveation::update_foveation_buffer( + vk::Buffer target, + bool flip_y, + xrt_rect source[2], + xrt_fov fovs[2]) +{ + if (not target) + return nullptr; + + if (target != gpu_buffer) + { + command_pool.reset(); + cmd.begin({}); + cmd.copyBuffer(host_buffer, target, vk::BufferCopy{.size = sizeof(render_compute_distortion_foveation_data)}); + cmd.end(); + } + + // Check if the last value is still valid + if (last.flip_y == flip_y and last.src[0] == source[0] and last.src[1] == source[1] and last.fovs[0] == fovs[0]) + { + std::lock_guard lock(mutex); + if (last.gaze == gaze) + return nullptr; + } + + last = { + .gaze = gaze, + .flip_y = flip_y, + .src = {source[0], source[1]}, + .fovs = {fovs[0], fovs[1]}, + }; + + compute_params(source, fovs); + + auto ubo = (render_compute_distortion_foveation_data *)host_buffer.map(); + for (size_t view = 0; view < 2; ++view) + { + fill_ubo(ubo->x + view * RENDER_FOVEATION_BUFFER_DIMENSIONS, params[view].x, false, source[view].offset.w, source[view].extent.w, foveated_width); + fill_ubo(ubo->y + view * RENDER_FOVEATION_BUFFER_DIMENSIONS, params[view].y, flip_y, source[view].offset.h, source[view].extent.h, foveated_height); + } + return cmd; } } // namespace wivrn diff --git a/server/driver/wivrn_foveation.h b/server/driver/wivrn_foveation.h index 0f80da17..a638a102 100644 --- a/server/driver/wivrn_foveation.h +++ b/server/driver/wivrn_foveation.h @@ -1,6 +1,7 @@ /* * WiVRn VR streaming * Copyright (C) 2024 galister + * Copyright (C) 2025 Patrick Nicolas * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,50 +19,61 @@ #pragma once +#include "vk/allocation.h" #include "wivrn_packets.h" #include "xrt/xrt_defines.h" +#include "xrt/xrt_device.h" #include +struct render_resources; + namespace wivrn { struct clock_offset; struct wivrn_vk_bundle; -// Calculates the center parameter from the received eye tracking data. class wivrn_foveation { std::mutex mutex; - std::array center_offset = {}; + const size_t foveated_width; // per eye + const size_t foveated_height; + std::array views = {}; - xrt_quat last_gaze = {}; + xrt_quat gaze = {}; + std::array params; + + vk::raii::CommandPool command_pool; + vk::raii::CommandBuffer cmd; + buffer_allocation host_buffer; + vk::Buffer gpu_buffer = nullptr; + + // parameters used for last computation + struct P + { + xrt_quat gaze = {}; + bool flip_y = false; + xrt_rect src[2] = {}; + xrt_fov fovs[2] = {}; + }; + P last; + + void compute_params( + xrt_rect src[2], + const xrt_fov fovs[2]); public: - wivrn_foveation() {} + wivrn_foveation(wivrn_vk_bundle &, const xrt_hmd_parts &); - void set_initial_parameters(std::array p); void update_tracking(const from_headset::tracking &, const clock_offset &); - std::array get_center(); -}; + std::array get_parameters(); -// Renders foveation parameters to Monado's distortion images using a compute shader -class wivrn_foveation_renderer -{ - wivrn_vk_bundle & vk; - - vk::raii::DescriptorPool dp = nullptr; - vk::raii::DescriptorSetLayout ds_layout = nullptr; - vk::raii::PipelineLayout layout = nullptr; - vk::raii::Pipeline pipeline = nullptr; - std::array ds; - -public: - wivrn_foveation_renderer(wivrn_vk_bundle & vk, vk::raii::CommandPool & cmd_pool); - - vk::raii::CommandBuffer cmd_buf = nullptr; - - void render_distortion_images(std::array foveation_arr, const VkImage * images, const VkImageView * image_views); + vk::CommandBuffer update_foveation_buffer( + vk::Buffer target, + bool flip_y, + xrt_rect src[2], + xrt_fov fovs[2]); }; } // namespace wivrn diff --git a/server/driver/wivrn_hmd.cpp b/server/driver/wivrn_hmd.cpp index 401381f5..9d3a330c 100644 --- a/server/driver/wivrn_hmd.cpp +++ b/server/driver/wivrn_hmd.cpp @@ -28,8 +28,6 @@ #include "utils/method.h" #include "xrt_cast.h" -#include -#include #include #include #include @@ -39,114 +37,6 @@ namespace wivrn { -static double foveate(double a, double b, double λ, double c, double x) -{ - // In order to save encoding, transmit and decoding time, only a portion of the image is encoded in full resolution. - // on each axis, foveated coordinates are defined by the following formula. - return λ / a * tan(a * x + b) + c; - // a and b are defined such as: - // edges of the image are not moved - // f(-1) = -1 - // f( 1) = 1 - // the function also enforces pixel ratio 1:1 at fovea - // df⁻¹(x)/dx = 1/scale for x = c -} - -static std::tuple solve_foveation(float λ, float c) -{ - // Compute a and b for the foveation function such that: - // foveate(a, b, scale, c, -1) = -1 (eq. 1) - // foveate(a, b, scale, c, 1) = 1 (eq. 2) - // - // Use eq. 2 to express a as function of b, then replace in eq. 1 - // equation that needs to be null is: - auto b = [λ, c](double a) { return atan(a * (1 - c) / λ) - a; }; - auto eq = [λ, c](double a) { return atan(a * (1 - c) / λ) + atan(a * (1 + c) / λ) - 2 * a; }; // (eq. 3) - - // function starts positive, reaches a maximum then decreases to -∞ - double a0 = 0; - // Find a negative value by computing eq(2^n) - double a1 = 1; - while (eq(a1) > 0) - a1 *= 2; - - // last computed values for f(a0) and f(a1) - std::optional f_a0; - double f_a1 = eq(a1); - - int n = 0; - double a = 0; - while (std::abs(a1 - a0) > 0.0000001 && n++ < 100) - { - if (not f_a0) - { - // use binary search - a = 0.5 * (a0 + a1); - double val = eq(a); - if (val > 0) - { - a0 = a; - f_a0 = val; - } - else - { - a1 = a; - f_a1 = val; - } - } - else - { - // f(a1) is always defined - // when f(a0) is defined, use secant method - a = a1 - f_a1 * (a1 - a0) / (f_a1 - *f_a0); - a0 = a1; - a1 = a; - f_a0 = f_a1; - f_a1 = eq(a); - } - } - - return {a, b(a)}; -} - -bool wivrn_hmd::wivrn_hmd_compute_distortion(xrt_device * xdev, uint32_t view_index, float u, float v, xrt_uv_triplet * result) -{ - // u,v are in the output coordinates (sent to the encoder) - // result is in the input coordinates (from the application) - const auto & param = ((wivrn_hmd *)xdev)->foveation_parameters[view_index]; - xrt_vec2 out; - - if (param.x.scale < 1) - { - u = 2 * u - 1; - - out.x = foveate(param.x.a, param.x.b, param.x.scale, param.x.center, u); - out.x = std::clamp((1 + out.x) / 2, 0, 1); - } - else - { - out.x = u; - } - - if (param.y.scale < 1) - { - v = 2 * v - 1; - - out.y = foveate(param.y.a, param.y.b, param.y.scale, param.y.center, v); - out.y = std::clamp((1 + out.y) / 2, 0, 1); - } - else - { - out.y = v; - } - - result->r = out; - result->g = out; - result->b = out; - - return true; -} - xrt_result_t wivrn_hmd::get_visibility_mask(xrt_visibility_mask_type type, uint32_t view_index, xrt_visibility_mask ** mask) { static_assert(sizeof(uint32_t) == sizeof(decltype(from_headset::visibility_mask_changed::mask::indices)::value_type)); @@ -304,14 +194,10 @@ xrt_result_t wivrn_hmd::get_battery_status(bool * out_present, return XRT_SUCCESS; } -decltype(wivrn_hmd::foveation_parameters) wivrn_hmd::set_foveated_size(uint32_t width, uint32_t height) +void wivrn_hmd::set_foveated_size(uint32_t width, uint32_t height) { assert(width % 2 == 0); uint32_t eye_width = width / 2; - std::array scale{ - double(eye_width) / hmd->views[0].display.w_pixels, - double(height) / hmd->views[0].display.h_pixels, - }; hmd->screens[0].w_pixels = width; hmd->screens[0].h_pixels = height; @@ -324,56 +210,6 @@ decltype(wivrn_hmd::foveation_parameters) wivrn_hmd::set_foveated_size(uint32_t view.viewport.w_pixels = eye_width; view.viewport.h_pixels = height; - - foveation_parameters[i].x.scale = scale[0]; - foveation_parameters[i].y.scale = scale[1]; - - const auto & fov = hmd->distortion.fov[i]; - float l = tan(fov.angle_left); - float r = tan(fov.angle_right); - float t = tan(fov.angle_up); - float b = tan(fov.angle_down); - if (scale[0] < 1) - { - float cu = (r + l) / (l - r); - foveation_parameters[i].x.center = cu; - - std::tie(foveation_parameters[i].x.a, foveation_parameters[i].x.b) = solve_foveation(scale[0], cu); - } - - if (scale[1] < 1) - { - float cv = (t + b) / (t - b); - foveation_parameters[i].y.center = cv; - - std::tie(foveation_parameters[i].y.a, foveation_parameters[i].y.b) = solve_foveation(scale[1], cv); - } - } - - // Distortion information - compute_distortion = wivrn_hmd_compute_distortion; - hmd->distortion.models = XRT_DISTORTION_MODEL_COMPUTE; - hmd->distortion.preferred = XRT_DISTORTION_MODEL_COMPUTE; - return foveation_parameters; -} - -void wivrn_hmd::set_foveation_center(std::array center) -{ - for (int i = 0; i < 2; ++i) - { - foveation_parameters[i].x.center = center[i].x; - foveation_parameters[i].y.center = center[i].y; - - if (foveation_parameters[i].x.scale < 1) - { - std::tie(foveation_parameters[i].x.a, foveation_parameters[i].x.b) = - solve_foveation(foveation_parameters[i].x.scale, foveation_parameters[i].x.center); - } - if (foveation_parameters[i].y.scale < 1) - { - std::tie(foveation_parameters[i].y.a, foveation_parameters[i].y.b) = - solve_foveation(foveation_parameters[i].y.scale, foveation_parameters[i].y.center); - } } } diff --git a/server/driver/wivrn_hmd.h b/server/driver/wivrn_hmd.h index 006b85a7..f3cb0ebf 100644 --- a/server/driver/wivrn_hmd.h +++ b/server/driver/wivrn_hmd.h @@ -51,15 +51,12 @@ class wivrn_hmd : public xrt_device }; view_list views; - std::array foveation_parameters{}; from_headset::battery battery{}; thread_safe, 2>> visibility_mask; wivrn::wivrn_session * cnx; - static bool wivrn_hmd_compute_distortion(xrt_device * xdev, uint32_t view_index, float u, float v, xrt_uv_triplet * result); - xrt_result_t get_visibility_mask(xrt_visibility_mask_type, uint32_t view_index, xrt_visibility_mask **); public: @@ -67,6 +64,8 @@ public: wivrn_hmd(wivrn::wivrn_session * cnx, const from_headset::headset_info_packet & info); + void set_foveated_size(uint32_t width, uint32_t height); + xrt_result_t get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation *); void get_view_poses(const xrt_vec3 * default_eye_relation, int64_t at_timestamp_ns, @@ -80,15 +79,6 @@ public: void update_battery(const from_headset::battery &); void update_tracking(const from_headset::tracking &, const clock_offset &); - - decltype(foveation_parameters) set_foveated_size(uint32_t width, uint32_t height); - void set_foveation_center(std::array center); - - std::array get_foveation_parameters() - { - return foveation_parameters; - } - void update_visibility_mask(const from_headset::visibility_mask_changed &); }; } // namespace wivrn diff --git a/server/driver/wivrn_session.cpp b/server/driver/wivrn_session.cpp index 6ed67c81..187bce17 100644 --- a/server/driver/wivrn_session.cpp +++ b/server/driver/wivrn_session.cpp @@ -20,7 +20,6 @@ #include "wivrn_session.h" #include "accept_connection.h" -#include "configuration.h" #include "driver/app_pacer.h" #include "main/comp_compositor.h" #include "main/comp_main_interface.h" @@ -35,20 +34,19 @@ #include "wivrn_config.h" #include "wivrn_eye_tracker.h" #include "wivrn_fb_face2_tracker.h" -#include "wivrn_foveation.h" #include "wivrn_htc_face_tracker.h" #include "wivrn_ipc.h" #include "wivrn_packets.h" #include "xrt/xrt_device.h" #include "xrt/xrt_session.h" -#include #include #include #include #include #if WIVRN_FEATURE_STEAMVR_LIGHTHOUSE +#include "configuration.h" #include "steamvr_lh_interface.h" #endif @@ -88,8 +86,9 @@ struct wivrn_comp_target_factory : public comp_target_factory static bool create_target(const struct comp_target_factory * ctf, struct comp_compositor * c, struct comp_target ** out_ct) { auto self = (wivrn_comp_target_factory *)ctf; - self->session.comp_target = new wivrn_comp_target(self->session, c); - *out_ct = self->session.comp_target; + self->session.comp_target = std::make_shared(self->session, c); + self->session.comp_target->self = self->session.comp_target; + *out_ct = self->session.comp_target.get(); return true; } }; @@ -198,7 +197,6 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr connection if (get_info().eye_gaze || is_forced_extension("EXT_eye_gaze_interaction")) { eye_tracker = std::make_unique(&hmd); - foveation = std::make_unique(); static_roles.eyes = eye_tracker.get(); xdevs[xdev_count++] = eye_tracker.get(); } @@ -406,8 +404,9 @@ void wivrn_session::operator()(const from_headset::tracking & tracking) right_hand.update_tracking(tracking, offset); if (eye_tracker) eye_tracker->update_tracking(tracking, offset); - if (foveation) - foveation->update_tracking(tracking, offset); + assert(comp_target); + assert(comp_target->foveation); + comp_target->foveation->update_tracking(tracking, offset); if (fb_face2_tracker) fb_face2_tracker->update_tracking(tracking, offset); @@ -618,29 +617,9 @@ xrt_result_t wivrn_session::push_event(const xrt_session_event & event) return xrt_session_event_sink_push(&xrt_system.broadcast, &event); } -std::array wivrn_session::set_foveated_size(uint32_t width, uint32_t height) +void wivrn_session::set_foveated_size(uint32_t width, uint32_t height) { - auto p = hmd.set_foveated_size(width, height); - - if (foveation) - foveation->set_initial_parameters(p); - - return p; -} - -bool wivrn_session::apply_dynamic_foveation() -{ - if (!foveation) - return false; - - hmd.set_foveation_center(foveation->get_center()); - comp_target->render_dynamic_foveation(hmd.get_foveation_parameters()); - return true; -} - -std::array wivrn_session::get_foveation_parameters() -{ - return hmd.get_foveation_parameters(); + hmd.set_foveated_size(width, height); } void wivrn_session::dump_time(const std::string & event, uint64_t frame, int64_t time, uint8_t stream, const char * extra) diff --git a/server/driver/wivrn_session.h b/server/driver/wivrn_session.h index 95584f23..4fe0ddce 100644 --- a/server/driver/wivrn_session.h +++ b/server/driver/wivrn_session.h @@ -44,8 +44,6 @@ namespace wivrn class wivrn_eye_tracker; class wivrn_fb_face2_tracker; class wivrn_htc_face_tracker; -class wivrn_foveation; -class wivrn_foveation_renderer; struct audio_device; struct wivrn_comp_target; struct wivrn_comp_target_factory; @@ -109,8 +107,7 @@ class wivrn_session : public xrt_system_devices std::unique_ptr eye_tracker; std::unique_ptr fb_face2_tracker; std::unique_ptr htc_face_tracker; - std::unique_ptr foveation; - wivrn_comp_target * comp_target; + std::shared_ptr comp_target; clock_offset_estimator offset_est; @@ -143,6 +140,11 @@ public: return connection->info(); }; + wivrn_hmd & get_hmd() + { + return hmd; + } + void add_predict_offset(std::chrono::nanoseconds off) { tracking_control.add(off); @@ -185,13 +187,7 @@ public: xrt_result_t push_event(const xrt_session_event &); - std::array set_foveated_size(uint32_t width, uint32_t height); - std::array get_foveation_parameters(); - bool apply_dynamic_foveation(); - bool has_dynamic_foveation() - { - return (bool)foveation; - } + void set_foveated_size(uint32_t width, uint32_t height); void dump_time(const std::string & event, uint64_t frame, int64_t time, uint8_t stream = -1, const char * extra = ""); From 7a7fc7aacca25234775750693f13bd125e08db6a Mon Sep 17 00:00:00 2001 From: galister <22305755+galister@users.noreply.github.com> Date: Sat, 7 Jun 2025 03:00:40 +0900 Subject: [PATCH 43/85] The Return of Dynamic Foveation --- server/driver/wivrn_foveation.cpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/server/driver/wivrn_foveation.cpp b/server/driver/wivrn_foveation.cpp index 80158abf..90029ac8 100644 --- a/server/driver/wivrn_foveation.cpp +++ b/server/driver/wivrn_foveation.cpp @@ -155,18 +155,18 @@ static xrt_vec2 yaw_pitch(xrt_quat q) pitch}; } +static float angles_to_center(float e, float l, float r) +{ + return (e - l) / (r - l) * 2 - 1; +} + void fill_param_2d( - float angle_min, - float angle_max, + float c, size_t foveated_dim, size_t source_dim, std::vector & out) { float scale = float(foveated_dim) / source_dim; - const float l = tan(angle_min); - const float r = tan(angle_max); - // FIXME: use tan_center - float c = (r + l) / (l - r); auto [a, b] = solve_foveation(scale, c); uint16_t last = 0; @@ -211,16 +211,20 @@ void wivrn_foveation::compute_params( { std::lock_guard lock(mutex); - xrt_vec2 tan_center{}; + xrt_vec2 tan_center[2]{}; if (gaze.x != 0 or gaze.y != 0 or gaze.z != 0 or gaze.w != 0) { auto e = yaw_pitch(gaze); for (size_t i = 0; i < 2; ++i) { - (void)e; - // TODO: implement - // uvs[i].x = (e.x - views[i].fov.angleLeft) / (views[i].fov.angleRight - views[i].fov.angleLeft) * 2 - 1 + center_offset[i].x; - // uvs[i].y = (e.y - views[i].fov.angleDown) / (views[i].fov.angleUp - views[i].fov.angleDown) * 2 - 1 + center_offset[i].y; + xrt_quat view_quat{ + .x = views[i].pose.orientation.x, + .y = views[i].pose.orientation.y, + .z = views[i].pose.orientation.z, + .w = views[i].pose.orientation.w}; + auto view = yaw_pitch(view_quat); + tan_center[i].x = angles_to_center(e.x - view.x, views[i].fov.angleLeft, views[i].fov.angleRight); + tan_center[i].y = angles_to_center(-view.y - e.y, views[i].fov.angleUp, views[i].fov.angleDown); } } @@ -228,11 +232,11 @@ void wivrn_foveation::compute_params( { const auto & fov = fovs[i]; if (foveated_width < src[i].extent.w) - fill_param_2d(fov.angle_left, fov.angle_right, foveated_width, src[i].extent.w, params[i].x); + fill_param_2d(tan_center[i].x, foveated_width, src[i].extent.w, params[i].x); else params[i].x = {uint16_t(src[i].extent.w)}; if (foveated_height < src[i].extent.h) - fill_param_2d(fov.angle_up, fov.angle_down, foveated_height, src[i].extent.h, params[i].y); + fill_param_2d(tan_center[i].y, foveated_height, src[i].extent.h, params[i].y); else params[i].y = {uint16_t(src[i].extent.h)}; } From 695ac2ea042fc0b2355f0d2dce46e4cad05e3d5d Mon Sep 17 00:00:00 2001 From: galister <22305755+galister@users.noreply.github.com> Date: Sat, 7 Jun 2025 05:55:25 +0900 Subject: [PATCH 44/85] simulate eye convergence when using eye tracked foveation --- server/driver/wivrn_foveation.cpp | 4 +++- server/driver/wivrn_foveation.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/server/driver/wivrn_foveation.cpp b/server/driver/wivrn_foveation.cpp index 90029ac8..d23eab19 100644 --- a/server/driver/wivrn_foveation.cpp +++ b/server/driver/wivrn_foveation.cpp @@ -223,7 +223,9 @@ void wivrn_foveation::compute_params( .z = views[i].pose.orientation.z, .w = views[i].pose.orientation.w}; auto view = yaw_pitch(view_quat); - tan_center[i].x = angles_to_center(e.x - view.x, views[i].fov.angleLeft, views[i].fov.angleRight); + + auto converge_angle = std::copysign(std::atan(std::abs(views[i].pose.position.x) / CONVERGENCE_DIST_M), views[i].pose.position.x); + tan_center[i].x = angles_to_center(e.x - view.x - converge_angle, views[i].fov.angleLeft, views[i].fov.angleRight); tan_center[i].y = angles_to_center(-view.y - e.y, views[i].fov.angleUp, views[i].fov.angleDown); } } diff --git a/server/driver/wivrn_foveation.h b/server/driver/wivrn_foveation.h index a638a102..34bdff58 100644 --- a/server/driver/wivrn_foveation.h +++ b/server/driver/wivrn_foveation.h @@ -28,6 +28,8 @@ struct render_resources; +#define CONVERGENCE_DIST_M 1.5 + namespace wivrn { From f5b6faf32731fb9c7258a86c47b7ad15529c8f6e Mon Sep 17 00:00:00 2001 From: galister <22305755+galister@users.noreply.github.com> Date: Sat, 7 Jun 2025 05:58:05 +0900 Subject: [PATCH 45/85] bump default eye-tracked scale to 0.4 --- docs/configuration.md | 2 +- server/encoder/encoder_settings.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 5e52937f..ddd10b26 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -5,7 +5,7 @@ Configuration is done on server side, in `$XDG_CONFIG_HOME/wivrn/config.json` or All elements are optional and have default values. ## `scale` -Default value: `0.5`, `0.35` if headset supports eye tracking +Default value: `0.5`, `0.4` if headset supports eye tracking Controls the size of the video stream, either a number between 0 and 1 or a pair of numbers between 0 and 1. If two numbers are provided the first one is horizontal scale and the second vertical. Scaling is applied in a foveated fashion: the center has a 1:1 ratio and the rest is scaled so that the total number of pixels matches the desired scale. diff --git a/server/encoder/encoder_settings.cpp b/server/encoder/encoder_settings.cpp index 1b44539e..35f36a07 100644 --- a/server/encoder/encoder_settings.cpp +++ b/server/encoder/encoder_settings.cpp @@ -351,7 +351,7 @@ std::vector get_encoder_settings(wivrn_vk_bundle & bundle, uin uint64_t bitrate = config.bitrate.value_or(default_bitrate); std::array default_scale; - default_scale.fill(info.eye_gaze ? 0.35 : 0.5); + default_scale.fill(info.eye_gaze ? 0.4 : 0.5); auto scale = config.scale.value_or(default_scale); check_scale(config.encoder_passthrough->name, From c55bdc6e894e98b4000c21ab63e96b9cdb73f07b Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Fri, 6 Jun 2025 23:15:47 +0200 Subject: [PATCH 46/85] Drop obsolete foveate shader --- server/CMakeLists.txt | 8 ----- server/shaders/foveate.comp.glsl | 62 -------------------------------- 2 files changed, 70 deletions(-) delete mode 100644 server/shaders/foveate.comp.glsl diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index f0dfcc78..89c7da77 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -105,8 +105,6 @@ if (WIVRN_BUILD_SERVER) driver/xrt_cast.cpp utils/wivrn_vk_bundle.cpp - - ${WIVRN_SHADER_HEADERS} ) target_compile_features(wivrn-server PRIVATE cxx_std_20) target_compile_definitions(wivrn-server PRIVATE VULKAN_HPP_NO_CONSTRUCTORS) @@ -188,12 +186,6 @@ if (WIVRN_BUILD_SERVER) target_link_libraries(wivrn-server PUBLIC wivrn-server-dbus) target_link_libraries(wivrn-server PUBLIC PkgConfig::libnotify) - include(CompileGLSL) - - file(GLOB VULKAN_SHADERS CONFIGURE_DEPENDS "shaders/*.glsl") - target_sources(wivrn-server PRIVATE ${VULKAN_SHADERS}) - wivrn_compile_glsl(wivrn-server ${VULKAN_SHADERS}) - target_link_libraries( wivrn-server PRIVATE diff --git a/server/shaders/foveate.comp.glsl b/server/shaders/foveate.comp.glsl deleted file mode 100644 index 527b02a4..00000000 --- a/server/shaders/foveate.comp.glsl +++ /dev/null @@ -1,62 +0,0 @@ -/* - * WiVRn VR streaming - * Copyright (C) 2024 galister - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#version 450 - -layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; - -layout(set = 0, binding = 0, rgba8) uniform writeonly restrict image2D target; - -layout(push_constant) uniform PushConstants -{ - vec2 a; - vec2 b; - vec2 scale; - vec2 center; -} pcs; - -layout(constant_id = 0) const float one_over_dim = 0.0; - -float foveate(float a, float b, float scale, float c, float x) { - return scale / a * tan(a * x + b) + c; -} - -void main() -{ - ivec2 coords = ivec2(gl_GlobalInvocationID.x, gl_GlobalInvocationID.y); - - vec2 uv = vec2( - float(coords.x), - float(coords.y) - ) * one_over_dim; - vec2 duv = vec2(1.0); - - if (pcs.scale.x < 1.0) { - float u = uv.x * 2.0 - 1.0; - float val = foveate(pcs.a.x, pcs.b.x, pcs.scale.x, pcs.center.x, u); - uv.x = clamp((1.0 + val) / 2.0, 0.0, 1.0); - } - - if (pcs.scale.y < 1.0) { - float v = uv.y * 2.0 - 1.0; - float val = foveate(pcs.a.y, pcs.b.y, pcs.scale.y, pcs.center.y, v); - uv.y = clamp((1.0 + val) / 2.0, 0.0, 1.0); - } - - imageStore(target, coords, vec4(uv.x, uv.y, 0.0, 0.0)); -} From 0a53801f70554c184db4f19306f7c580e8535d59 Mon Sep 17 00:00:00 2001 From: galister <22305755+galister@users.noreply.github.com> Date: Sat, 7 Jun 2025 23:56:56 +0900 Subject: [PATCH 47/85] foveation: rework eye convergence; account for asymmetric v-fov --- server/driver/wivrn_foveation.cpp | 15 ++++++++++++--- server/driver/wivrn_foveation.h | 2 -- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/server/driver/wivrn_foveation.cpp b/server/driver/wivrn_foveation.cpp index d23eab19..6e7fd807 100644 --- a/server/driver/wivrn_foveation.cpp +++ b/server/driver/wivrn_foveation.cpp @@ -160,6 +160,13 @@ static float angles_to_center(float e, float l, float r) return (e - l) / (r - l) * 2 - 1; } +static float convergence_angle(float eye_x, float gaze_yaw) +{ + const float c = 0.5; // simutaled convergence distance + auto b = c * std::sin(gaze_yaw) - eye_x; + return std::asin(b / c); +} + void fill_param_2d( float c, size_t foveated_dim, @@ -224,9 +231,11 @@ void wivrn_foveation::compute_params( .w = views[i].pose.orientation.w}; auto view = yaw_pitch(view_quat); - auto converge_angle = std::copysign(std::atan(std::abs(views[i].pose.position.x) / CONVERGENCE_DIST_M), views[i].pose.position.x); - tan_center[i].x = angles_to_center(e.x - view.x - converge_angle, views[i].fov.angleLeft, views[i].fov.angleRight); - tan_center[i].y = angles_to_center(-view.y - e.y, views[i].fov.angleUp, views[i].fov.angleDown); + auto angle_x = convergence_angle(views[i].pose.position.x, e.x); + tan_center[i].x = angles_to_center(view.x + angle_x, views[i].fov.angleLeft, views[i].fov.angleRight); + + auto offset_y = (views[i].fov.angleDown + views[i].fov.angleUp) / 2; + tan_center[i].y = angles_to_center(-view.y - e.y, views[i].fov.angleUp, views[i].fov.angleDown) + offset_y; } } diff --git a/server/driver/wivrn_foveation.h b/server/driver/wivrn_foveation.h index 34bdff58..a638a102 100644 --- a/server/driver/wivrn_foveation.h +++ b/server/driver/wivrn_foveation.h @@ -28,8 +28,6 @@ struct render_resources; -#define CONVERGENCE_DIST_M 1.5 - namespace wivrn { From e29a08ea2e480924a557faec9ed1e60f6fe02f2f Mon Sep 17 00:00:00 2001 From: galister <22305755+galister@users.noreply.github.com> Date: Sat, 7 Jun 2025 23:58:28 +0900 Subject: [PATCH 48/85] Revert "bump default eye-tracked scale to 0.4" This reverts commit f5b6faf32731fb9c7258a86c47b7ad15529c8f6e. --- docs/configuration.md | 2 +- server/encoder/encoder_settings.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index ddd10b26..5e52937f 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -5,7 +5,7 @@ Configuration is done on server side, in `$XDG_CONFIG_HOME/wivrn/config.json` or All elements are optional and have default values. ## `scale` -Default value: `0.5`, `0.4` if headset supports eye tracking +Default value: `0.5`, `0.35` if headset supports eye tracking Controls the size of the video stream, either a number between 0 and 1 or a pair of numbers between 0 and 1. If two numbers are provided the first one is horizontal scale and the second vertical. Scaling is applied in a foveated fashion: the center has a 1:1 ratio and the rest is scaled so that the total number of pixels matches the desired scale. diff --git a/server/encoder/encoder_settings.cpp b/server/encoder/encoder_settings.cpp index 35f36a07..1b44539e 100644 --- a/server/encoder/encoder_settings.cpp +++ b/server/encoder/encoder_settings.cpp @@ -351,7 +351,7 @@ std::vector get_encoder_settings(wivrn_vk_bundle & bundle, uin uint64_t bitrate = config.bitrate.value_or(default_bitrate); std::array default_scale; - default_scale.fill(info.eye_gaze ? 0.4 : 0.5); + default_scale.fill(info.eye_gaze ? 0.35 : 0.5); auto scale = config.scale.value_or(default_scale); check_scale(config.encoder_passthrough->name, From 460fbec06dfc2044f78b2a07c79e53790710f97d Mon Sep 17 00:00:00 2001 From: Sapphire Date: Sun, 1 Jun 2025 04:33:51 -0500 Subject: [PATCH 49/85] Quest and Pico body tracking * Update OpenXR SDK to 1.1.48 --- .gitignore | 3 + AndroidManifest.xml | 2 + CMakeLists.txt | 8 +- client/application.cpp | 30 ++++- client/application.h | 26 ++++ client/configuration.cpp | 25 ++++ client/configuration.h | 2 + client/hardware.cpp | 9 ++ client/hardware.h | 1 + client/scenes/lobby_gui.cpp | 55 ++++++++- client/scenes/stream.cpp | 15 +++ client/scenes/stream_tracking.cpp | 38 ++++++ client/xr/fb_body_tracker.cpp | 142 ++++++++++++++++++++++ client/xr/fb_body_tracker.h | 69 +++++++++++ client/xr/pico_body_tracker.cpp | 99 +++++++++++++++ client/xr/pico_body_tracker.h | 57 +++++++++ client/xr/session.cpp | 24 ++++ client/xr/session.h | 4 + client/xr/system.cpp | 36 ++++++ client/xr/system.h | 2 + common/wivrn_packets.h | 3 + common/xr/meta_body_tracking_fidelity.h | 41 +++++++ server/CMakeLists.txt | 1 + server/driver/wivrn_controller.cpp | 1 + server/driver/wivrn_generic_tracker.cpp | 154 ++++++++++++++++++++++++ server/driver/wivrn_generic_tracker.h | 60 +++++++++ server/driver/wivrn_session.cpp | 44 +++++++ server/driver/wivrn_session.h | 4 + 28 files changed, 949 insertions(+), 6 deletions(-) create mode 100644 client/xr/fb_body_tracker.cpp create mode 100644 client/xr/fb_body_tracker.h create mode 100644 client/xr/pico_body_tracker.cpp create mode 100644 client/xr/pico_body_tracker.h create mode 100644 common/xr/meta_body_tracking_fidelity.h create mode 100644 server/driver/wivrn_generic_tracker.cpp create mode 100644 server/driver/wivrn_generic_tracker.h diff --git a/.gitignore b/.gitignore index b2fae216..a16fdcd7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,15 @@ *~ .cxx/ .cache/ +.direnv/ .gradle/ _deps/ .idea/ +.vscode/ build/ build-*/ +**/result *.so a.out diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 9df29233..6bb9d6b9 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -39,12 +39,14 @@ + + diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e213697..aaf7dd5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -223,9 +223,9 @@ if (WIVRN_BUILD_CLIENT AND NOT ANDROID) find_package(Fontconfig REQUIRED) if (WIVRN_USE_SYSTEM_OPENXR STREQUAL "AUTO") - find_package(OpenXR 1.0.26) + find_package(OpenXR 1.1.48) elseif(WIVRN_USE_SYSTEM_OPENXR STREQUAL "ON") - find_package(OpenXR 1.0.26 REQUIRED) + find_package(OpenXR 1.1.48 REQUIRED) endif() endif() @@ -264,8 +264,8 @@ FetchContent_Declare(fastgltf EXCLUDE_FROM_ALL SYSTEM URL https://github.co URL_HASH SHA256=44bcb025dd5cd480236a3bc7a3f8c9a708a801ed773b7859677440d22e0e1e7c) FetchContent_Declare(glm EXCLUDE_FROM_ALL SYSTEM URL https://github.com/g-truc/glm/archive/refs/tags/1.0.1.tar.gz URL_HASH SHA256=9f3174561fd26904b23f0db5e560971cbf9b3cbda0b280f04d5c379d03bf234c) -FetchContent_Declare(openxr_loader EXCLUDE_FROM_ALL SYSTEM URL https://github.com/KhronosGroup/OpenXR-SDK/archive/refs/tags/release-1.0.34.tar.gz - URL_HASH SHA256=5fa2fac1b442a31e267ea522799a247e3aff6e6f5a418b1e31c337b8ca835b69) +FetchContent_Declare(openxr_loader EXCLUDE_FROM_ALL SYSTEM URL https://github.com/KhronosGroup/OpenXR-SDK/archive/refs/tags/release-1.1.48.tar.gz + URL_HASH SHA256=c9372992dcdfac643e28796e41d4dbd36c4cdf0388d01fa89245628edae9d411) FetchContent_Declare(spdlog EXCLUDE_FROM_ALL SYSTEM URL https://github.com/gabime/spdlog/archive/refs/tags/v1.14.1.tar.gz URL_HASH SHA256=1586508029a7d0670dfcb2d97575dcdc242d3868a259742b69f100801ab4e16b) FetchContent_Declare(stb EXCLUDE_FROM_ALL SYSTEM URL https://github.com/nothings/stb/archive/013ac3beddff3dbffafd5177e7972067cd2b5083.zip diff --git a/client/application.cpp b/client/application.cpp index 404d4c22..e0d30712 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -31,7 +31,7 @@ #include "wifi_lock.h" #include "xr/actionset.h" #include "xr/check.h" -#include "xr/pico_eye_types.h" +#include "xr/meta_body_tracking_fidelity.h" #include "xr/xr.h" #include #include @@ -1041,6 +1041,10 @@ void application::initialize() opt_extensions.push_back(XR_HTC_PASSTHROUGH_EXTENSION_NAME); opt_extensions.push_back(XR_HTC_FACIAL_TRACKING_EXTENSION_NAME); opt_extensions.push_back(XR_FB_FACE_TRACKING2_EXTENSION_NAME); + opt_extensions.push_back(XR_FB_BODY_TRACKING_EXTENSION_NAME); + opt_extensions.push_back(XR_META_BODY_TRACKING_FULL_BODY_EXTENSION_NAME); + opt_extensions.push_back(XR_META_BODY_TRACKING_FIDELITY_EXTENSION_NAME); + opt_extensions.push_back(XR_BD_BODY_TRACKING_EXTENSION_NAME); opt_extensions.push_back(XR_EXT_PALM_POSE_EXTENSION_NAME); opt_extensions.push_back(XR_KHR_COMPOSITION_LAYER_DEPTH_EXTENSION_NAME); opt_extensions.push_back(XR_FB_COMPOSITION_LAYER_DEPTH_TEST_EXTENSION_NAME); @@ -1141,6 +1145,20 @@ void application::initialize() htc_face_tracking_lip_supported = htc_face_properties.supportLipFacialTracking; } + 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); + fb_body_tracking_supported = fb_body_properties.supportsBodyTracking; + } + + if (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); + pico_body_tracking_supported = bd_body_properties.supportsBodyTracking; + } + if (utils::contains(xr_extensions, XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME)) { spdlog::info(" OpenXR post-processing extension support: true"); @@ -1205,6 +1223,16 @@ void application::initialize() pico_face_tracker = xr_session.create_pico_face_tracker(); } + if (fb_body_tracking_supported) + { + fb_body_tracker = xr_session.create_fb_body_tracker(); + } + + if (pico_body_tracking_supported) + { + pico_body_tracker = xr_session.create_pico_body_tracker(); + } + vk::CommandPoolCreateInfo cmdpool_create_info; cmdpool_create_info.queueFamilyIndex = vk_queue_family_index; cmdpool_create_info.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer; diff --git a/client/application.h b/client/application.h index 67758507..b429cf50 100644 --- a/client/application.h +++ b/client/application.h @@ -21,6 +21,7 @@ #include "configuration.h" #include "wifi_lock.h" +#include "xr/fb_body_tracker.h" #include "xr/fb_face_tracker2.h" #include "xr/hand_tracker.h" #include "xr/htc_face_tracker.h" @@ -137,6 +138,11 @@ class application : public singleton bool pico_face_tracking_supported = false; xr::pico_face_tracker pico_face_tracker; + bool fb_body_tracking_supported = false; + xr::fb_body_tracker fb_body_tracker; + bool pico_body_tracking_supported = false; + xr::pico_body_tracker pico_body_tracker; + bool eye_gaze_supported = false; bool openxr_post_processing_supported = false; @@ -445,6 +451,16 @@ public: return instance().pico_face_tracking_supported; } + static bool get_fb_body_tracking_supported() + { + return instance().fb_body_tracking_supported; + } + + static bool get_pico_body_tracking_supported() + { + return instance().pico_body_tracking_supported; + } + static bool get_eye_gaze_supported() { return instance().eye_gaze_supported; @@ -485,6 +501,16 @@ public: return instance().pico_face_tracker; } + static xr::fb_body_tracker & get_fb_body_tracker() + { + return instance().fb_body_tracker; + } + + static xr::pico_body_tracker & get_pico_body_tracker() + { + return instance().pico_body_tracker; + } + static const std::vector & get_xr_extensions() { return instance().xr_extensions; diff --git a/client/configuration.cpp b/client/configuration.cpp index cf52494d..557e9094 100644 --- a/client/configuration.cpp +++ b/client/configuration.cpp @@ -121,6 +121,27 @@ bool configuration::check_feature(feature f) const return false; break; } + break; + case feature::body_tracking: + switch (guess_model()) + { + case model::meta_quest_3: + case model::meta_quest_3s: + if (not application::get_fb_body_tracking_supported()) + 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 application::get_pico_body_tracking_supported()) + return false; + break; + default: + break; + } + break; } } #ifdef __ANDROID__ @@ -203,6 +224,9 @@ configuration::configuration(xr::system & system) if (auto val = root["mic_unprocessed_audio"]; val.is_bool()) mic_unprocessed_audio = val.get_bool(); + if (auto val = root["fb_lower_body"]; val.is_bool()) + fb_lower_body = val.get_bool(); + if (auto val = root["virtual_keyboard_layout"]; val.is_string()) virtual_keyboard_layout = val.get_string().value(); @@ -325,6 +349,7 @@ void configuration::save() 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; for (auto & [key, value]: features) json << "," << key << ":" << std::boolalpha << value; json << ",\"virtual_keyboard_layout\":" << json_string(virtual_keyboard_layout); diff --git a/client/configuration.h b/client/configuration.h index e261a87c..565dc6dd 100644 --- a/client/configuration.h +++ b/client/configuration.h @@ -54,6 +54,8 @@ public: bool passthrough_enabled = false; bool mic_unprocessed_audio = false; + bool fb_lower_body = false; + // Snapdragon Game Super Resolution struct sgsr_settings { diff --git a/client/hardware.cpp b/client/hardware.cpp index 0e7cccb0..c12960de 100644 --- a/client/hardware.cpp +++ b/client/hardware.cpp @@ -251,6 +251,15 @@ const char * permission_name(feature f) return nullptr; } __builtin_unreachable(); + case feature::body_tracking: + switch (guess_model()) + { + case model::meta_quest_3: + case model::meta_quest_3s: + return "com.oculus.permission.BODY_TRACKING"; + default: + return nullptr; + } } __builtin_unreachable(); } diff --git a/client/hardware.h b/client/hardware.h index 608aa644..29d73cbd 100644 --- a/client/hardware.h +++ b/client/hardware.h @@ -50,6 +50,7 @@ enum class feature hand_tracking, eye_gaze, face_tracking, + body_tracking, }; model guess_model(); diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index c8bf6fd8..09333779 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -740,6 +740,49 @@ void scenes::lobby::gui_settings() vibrate_on_hover(); } + { + ImGui::BeginDisabled(not(application::get_fb_body_tracking_supported() or application::get_pico_body_tracking_supported())); + bool enabled = config.check_feature(feature::body_tracking); + if (ImGui::Checkbox(_S("Enable body tracking"), &enabled)) + { + config.set_feature(feature::body_tracking, enabled); + config.save(); + } + ImGui::EndDisabled(); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) + { + if (ImGui::GetItemFlags() & ImGuiItemFlags_Disabled) + { + tooltip(_("This feature is not supported by your headset")); + } + else + { + if (application::get_fb_body_tracking_supported()) + tooltip(_("Requires 'Hand and body tracking' to be enabled in the Quest movement tracking settings, otherwise estimated joint positions will be used")); + else if (application::get_pico_body_tracking_supported()) + { + tooltip(_("Uses the Pico Motion Trackers to track body joint positions")); + } + } + } + + vibrate_on_hover(); + } + if (application::get_fb_body_tracking_supported()) + { + ImGui::BeginDisabled(not config.check_feature(feature::body_tracking)); + ImGui::Indent(); + if (ImGui::Checkbox(_S("Enable lower body tracking"), &config.fb_lower_body)) + { + config.save(); + } + vibrate_on_hover(); + if (ImGui::IsItemHovered()) + tooltip(_("Estimate lower body joint positions using Generative Legs, requires 'Hand and body tracking' to be enabled in the Quest movement tracking settings")); + ImGui::Unindent(); + ImGui::EndDisabled(); + } + ImGui::BeginDisabled(passthrough_supported == xr::system::passthrough_type::no_passthrough); if (ImGui::Checkbox(_S("Enable video passthrough in lobby"), &config.passthrough_enabled)) { @@ -1430,6 +1473,16 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time) }); } + if (application::get_fb_body_tracking_supported() or application::get_pico_body_tracking_supported()) + { + items.push_back({ + .f = feature::body_tracking, + .tooltip_enabled = _("Body tracking is enabled"), + .tooltip_disabled = _("Body tracking is disabled"), + .icon_enabled = ICON_FA_PERSON, + }); + } + // Get statuses for (auto & i: items) { @@ -1456,7 +1509,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time) if (&i != &items.front()) ImGui::SameLine(); auto pos = ImGui::GetCursorPos(); - if (ImGui::Button(i.enabled ? i.icon_enabled : i.icon_disabled)) + if (ImGui::Button(fmt::format("{}##{}", i.enabled ? i.icon_enabled : i.icon_disabled, i.icon_enabled).c_str())) { // button doesn't alter the bool config.set_feature(i.f, not i.enabled); diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index 010cc84a..bd1388ec 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -17,6 +17,7 @@ * along with this program. If not, see . */ #include "utils/overloaded.h" +#include "xr/fb_body_tracker.h" #define GLM_FORCE_RADIANS #include "stream.h" @@ -224,6 +225,20 @@ std::shared_ptr scenes::stream::create(std::unique_ptrsystem.passthrough_supported() != xr::system::passthrough_type::no_passthrough; info.system_name = std::string(self->system.properties().systemName); diff --git a/client/scenes/stream_tracking.cpp b/client/scenes/stream_tracking.cpp index aa6a76bc..2cc2e3ca 100644 --- a/client/scenes/stream_tracking.cpp +++ b/client/scenes/stream_tracking.cpp @@ -258,6 +258,26 @@ void scenes::stream::tracking() } } + enum + { + body_none, + body_fb, + body_pico, + } body_tracking = body_none; + + if (config.check_feature(feature::body_tracking)) + { + if (application::get_fb_body_tracking_supported()) + { + body_tracking = body_fb; + // We start the tracker on connection because there are togglable settings. + // TODO handle reconnection? + application::get_fb_body_tracker().start(config.fb_lower_body); + } + else if (application::get_pico_body_tracking_supported()) + body_tracking = body_pico; + } + on_interaction_profile_changed({}); while (not exiting) @@ -359,6 +379,21 @@ void scenes::stream::tracking() break; } } + + if (control.enabled[size_t(tid::generic_tracker)]) + { + switch (body_tracking) + { + case body_none: + break; + case body_fb: + application::get_fb_body_tracker().locate_spaces(t0 + Δt, packet.device_poses, world_space); + break; + case body_pico: + application::get_pico_body_tracker().locate_spaces(t0 + Δt, packet.device_poses, world_space); + break; + } + } } catch (const std::system_error & e) { @@ -453,6 +488,9 @@ void scenes::stream::tracking() if (face_tracking == from_headset::face_type::pico) application::get_pico_face_tracker().stop(); + + if (body_tracking == body_fb) + application::get_fb_body_tracker().stop(); } void scenes::stream::operator()(to_headset::tracking_control && packet) diff --git a/client/xr/fb_body_tracker.cpp b/client/xr/fb_body_tracker.cpp new file mode 100644 index 00000000..8d5946f3 --- /dev/null +++ b/client/xr/fb_body_tracker.cpp @@ -0,0 +1,142 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2025 Sapphire + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "fb_body_tracker.h" +#include "spdlog/spdlog.h" +#include "xr/meta_body_tracking_fidelity.h" +#include "xr/xr.h" +#include + +xr::fb_body_tracker::fb_body_tracker(instance & inst, session & s) : + s(s) +{ + xrCreateBodyTrackerFB = inst.get_proc("xrCreateBodyTrackerFB"); + xrRequestBodyTrackingFidelityMETA = inst.get_proc("xrRequestBodyTrackingFidelityMETA"); + xrLocateBodyJointsFB = inst.get_proc("xrLocateBodyJointsFB"); + xrDestroyBodyTrackerFB = inst.get_proc("xrDestroyBodyTrackerFB"); +} +xr::fb_body_tracker::~fb_body_tracker() +{ + stop(); +} + +void xr::fb_body_tracker::start(bool full_body) +{ + assert(xrCreateBodyTrackerFB); + this->full_body = full_body; + + XrBodyTrackerCreateInfoFB create_info{ + .type = XR_TYPE_BODY_TRACKER_CREATE_INFO_FB, + .next = nullptr, + }; + create_info.bodyJointSet = full_body + ? XR_BODY_JOINT_SET_FULL_BODY_META + : XR_BODY_JOINT_SET_DEFAULT_FB; + + CHECK_XR(xrCreateBodyTrackerFB(s, &create_info, &handle)); + + // Enable IOBT. + CHECK_XR(xrRequestBodyTrackingFidelityMETA(handle, XR_BODY_TRACKING_FIDELITY_HIGH_META)); +} +void xr::fb_body_tracker::stop() +{ + assert(xrDestroyBodyTrackerFB); + full_body = false; + if (handle) + CHECK_XR(xrDestroyBodyTrackerFB(std::exchange(handle, nullptr))); +} + +void xr::fb_body_tracker::locate_spaces(XrTime time, std::vector & out_poses, XrSpace reference) +{ + auto fill_poses = [&]() { + for (auto joint: joint_whitelist) + { + if (!full_body && joint >= XR_FULL_BODY_JOINT_LEFT_UPPER_LEG_META) + return; + + wivrn::from_headset::tracking::pose pose{ + .pose = {}, + .device = wivrn::device_id::GENERIC_TRACKER, + .flags = 0, + }; + out_poses.push_back(std::move(pose)); + } + }; + if (!handle) + { + fill_poses(); + return; + } + + assert(xrLocateBodyJointsFB); + + XrBodyJointsLocateInfoFB locate_info{ + .type = XR_TYPE_BODY_JOINTS_LOCATE_INFO_FB, + .next = nullptr, + .baseSpace = reference, + .time = time, + }; + + std::array joints{}; + XrBodyJointLocationsFB joint_locations{ + .type = XR_TYPE_BODY_JOINT_LOCATIONS_FB, + .next = nullptr, + .jointCount = (uint32_t)(full_body ? XR_FULL_BODY_JOINT_COUNT_META : (XrFullBodyJointMETA)XR_BODY_JOINT_COUNT_FB), + .jointLocations = joints.data(), + }; + + if (auto res = xrLocateBodyJointsFB(handle, &locate_info, &joint_locations); !XR_SUCCEEDED(res)) + { + spdlog::warn("xrLocateBodyJointsFB returned {}", xr::to_string(res)); + + fill_poses(); + return; + } + + if (!joint_locations.isActive) + { + spdlog::warn("Body tracker is not active."); + fill_poses(); + return; + } + + for (auto joint: joint_whitelist) + { + if (!full_body && joint >= XR_FULL_BODY_JOINT_LEFT_UPPER_LEG_META) + return; + + auto joint_pose = joints[joint]; + wivrn::from_headset::tracking::pose pose{ + .pose = joint_pose.pose, + .device = wivrn::device_id::GENERIC_TRACKER, + .flags = 0, + }; + + if (joint_pose.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT) + pose.flags |= wivrn::from_headset::tracking::position_valid; + if (joint_pose.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT) + pose.flags |= wivrn::from_headset::tracking::orientation_valid; + if (joint_pose.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT) + pose.flags |= wivrn::from_headset::tracking::position_tracked; + if (joint_pose.locationFlags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT) + pose.flags |= wivrn::from_headset::tracking::orientation_tracked; + + out_poses.push_back(std::move(pose)); + } + return; +} diff --git a/client/xr/fb_body_tracker.h b/client/xr/fb_body_tracker.h new file mode 100644 index 00000000..95202c13 --- /dev/null +++ b/client/xr/fb_body_tracker.h @@ -0,0 +1,69 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2025 Sapphire + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include "wivrn_packets.h" + +#include "xr/meta_body_tracking_fidelity.h" +#include +#include + +namespace xr +{ +class instance; +class session; + +class fb_body_tracker +{ + XrSession s; + XrBodyTrackerFB handle{}; + + PFN_xrCreateBodyTrackerFB xrCreateBodyTrackerFB{}; + PFN_xrRequestBodyTrackingFidelityMETA xrRequestBodyTrackingFidelityMETA{}; + PFN_xrLocateBodyJointsFB xrLocateBodyJointsFB{}; + PFN_xrDestroyBodyTrackerFB xrDestroyBodyTrackerFB{}; + + bool full_body{}; + +public: + static constexpr std::array joint_whitelist{ + XR_FULL_BODY_JOINT_HIPS_META, + XR_FULL_BODY_JOINT_CHEST_META, + XR_FULL_BODY_JOINT_LEFT_ARM_UPPER_META, + XR_FULL_BODY_JOINT_RIGHT_ARM_UPPER_META, + XR_FULL_BODY_JOINT_LEFT_ARM_LOWER_META, + XR_FULL_BODY_JOINT_RIGHT_ARM_LOWER_META, + + XR_FULL_BODY_JOINT_LEFT_LOWER_LEG_META, + XR_FULL_BODY_JOINT_RIGHT_LOWER_LEG_META, + + XR_FULL_BODY_JOINT_LEFT_FOOT_TRANSVERSE_META, + XR_FULL_BODY_JOINT_RIGHT_FOOT_TRANSVERSE_META, + }; + + fb_body_tracker() = default; + fb_body_tracker(instance & inst, session & s); + ~fb_body_tracker(); + + void start(bool lower_body); + void stop(); + + void locate_spaces(XrTime time, std::vector & out_poses, XrSpace reference); +}; +} // namespace xr diff --git a/client/xr/pico_body_tracker.cpp b/client/xr/pico_body_tracker.cpp new file mode 100644 index 00000000..99219411 --- /dev/null +++ b/client/xr/pico_body_tracker.cpp @@ -0,0 +1,99 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2025 Sapphire + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "pico_body_tracker.h" +#include "spdlog/spdlog.h" +#include "xr/xr.h" +#include + +static PFN_xrDestroyBodyTrackerBD xrDestroyBodyTrackerBD{}; + +XrResult xr::destroy_pico_body_tracker(XrBodyTrackerBD id) +{ + return xrDestroyBodyTrackerBD(id); +} + +xr::pico_body_tracker::pico_body_tracker(instance & inst, XrBodyTrackerBD h) +{ + id = h; + xrLocateBodyJointsBD = inst.get_proc("xrLocateBodyJointsBD"); +} + +void xr::pico_body_tracker::locate_spaces(XrTime time, std::vector & out_poses, XrSpace reference) +{ + auto fill_poses = [&]() { + for (auto _: joint_whitelist) + { + wivrn::from_headset::tracking::pose pose{ + .pose = {}, + .device = wivrn::device_id::GENERIC_TRACKER, + .flags = 0, + }; + out_poses.push_back(std::move(pose)); + } + }; + + if (!xrLocateBodyJointsBD) + { + fill_poses(); + return; + } + + XrBodyJointsLocateInfoBD locate_info{ + .type = XR_TYPE_BODY_JOINTS_LOCATE_INFO_BD, + .next = nullptr, + .baseSpace = reference, + .time = time, + }; + + std::array joints{}; + XrBodyJointLocationsBD joint_locations{ + .type = XR_TYPE_BODY_JOINT_LOCATIONS_BD, + .next = nullptr, + .jointLocationCount = joints.size(), + .jointLocations = joints.data(), + }; + + if (auto res = xrLocateBodyJointsBD(id, &locate_info, &joint_locations); !XR_SUCCEEDED(res)) + { + spdlog::warn("Unable to get body joints: xrLocateBodyJointsBD returned {}", xr::to_string(res)); + fill_poses(); + return; + } + + for (auto & joint: joint_whitelist) + { + auto & joint_location = joints[joint]; + wivrn::from_headset::tracking::pose pose{ + .pose = joint_location.pose, + .device = wivrn::device_id::GENERIC_TRACKER, + .flags = 0, + }; + + if (joint_location.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT) + pose.flags |= wivrn::from_headset::tracking::position_valid; + if (joint_location.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT) + pose.flags |= wivrn::from_headset::tracking::orientation_valid; + if (joint_location.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT) + pose.flags |= wivrn::from_headset::tracking::position_tracked; + if (joint_location.locationFlags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT) + pose.flags |= wivrn::from_headset::tracking::orientation_tracked; + + out_poses.push_back(std::move(pose)); + } +} diff --git a/client/xr/pico_body_tracker.h b/client/xr/pico_body_tracker.h new file mode 100644 index 00000000..1f2e393f --- /dev/null +++ b/client/xr/pico_body_tracker.h @@ -0,0 +1,57 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2025 Sapphire + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include "utils/handle.h" +#include "wivrn_packets.h" + +#include +#include + +namespace xr +{ +class instance; +class session; + +XrResult destroy_pico_body_tracker(XrBodyTrackerBD); + +class pico_body_tracker : public utils::handle +{ + PFN_xrLocateBodyJointsBD xrLocateBodyJointsBD{}; + +public: + static constexpr std::array joint_whitelist{ + XR_BODY_JOINT_PELVIS_BD, + XR_BODY_JOINT_LEFT_SHOULDER_BD, + XR_BODY_JOINT_RIGHT_SHOULDER_BD, + XR_BODY_JOINT_LEFT_ELBOW_BD, + XR_BODY_JOINT_RIGHT_ELBOW_BD, + + XR_BODY_JOINT_LEFT_KNEE_BD, + XR_BODY_JOINT_RIGHT_KNEE_BD, + XR_BODY_JOINT_LEFT_FOOT_BD, + XR_BODY_JOINT_RIGHT_FOOT_BD, + }; + + pico_body_tracker() = default; + pico_body_tracker(instance & inst, XrBodyTrackerBD h); + + void locate_spaces(XrTime time, std::vector & out_poses, XrSpace reference); +}; +} // namespace xr diff --git a/client/xr/session.cpp b/client/xr/session.cpp index ab6e6978..0d86d0b5 100644 --- a/client/xr/session.cpp +++ b/client/xr/session.cpp @@ -23,6 +23,8 @@ #include "details/enumerate.h" #include "openxr/openxr.h" #include "utils/contains.h" +#include "xr/fb_body_tracker.h" +#include "xr/pico_body_tracker.h" #include "xr/instance.h" #include "xr/system.h" #include @@ -142,6 +144,28 @@ xr::pico_face_tracker xr::session::create_pico_face_tracker() return {*inst, *this}; } +xr::fb_body_tracker xr::session::create_fb_body_tracker() +{ + return {*inst, *this}; +} + +xr::pico_body_tracker xr::session::create_pico_body_tracker() +{ + XrBodyTrackerCreateInfoBD create_info{ + .type = XR_TYPE_BODY_TRACKER_CREATE_INFO_BD, + .next = nullptr, + .jointSet = XR_BODY_JOINT_SET_FULL_BODY_JOINTS_BD, + }; + + XrBodyTrackerBD bt; + + auto xrCreateBodyTrackerBD = inst->get_proc("xrCreateBodyTrackerBD"); + assert(xrCreateBodyTrackerBD); + + CHECK_XR(xrCreateBodyTrackerBD(id, &create_info, &bt)); + return {*inst, bt}; +} + std::vector xr::session::get_swapchain_formats() const { std::vector formats; diff --git a/client/xr/session.h b/client/xr/session.h index bd43147f..23c1b705 100644 --- a/client/xr/session.h +++ b/client/xr/session.h @@ -29,6 +29,8 @@ #include "fb_face_tracker2.h" #include "hand_tracker.h" #include "htc_face_tracker.h" +#include "fb_body_tracker.h" +#include "pico_body_tracker.h" #include "passthrough.h" #include "pico_face_tracker.h" #include "space.h" @@ -54,6 +56,8 @@ public: fb_face_tracker2 create_fb_face_tracker2(); htc_face_tracker create_htc_face_tracker(XrFacialTrackingTypeHTC); pico_face_tracker create_pico_face_tracker(); + fb_body_tracker create_fb_body_tracker(); + pico_body_tracker create_pico_body_tracker(); std::vector get_swapchain_formats() const; diff --git a/client/xr/system.cpp b/client/xr/system.cpp index 33769ba7..5357b192 100644 --- a/client/xr/system.cpp +++ b/client/xr/system.cpp @@ -141,6 +141,42 @@ XrSystemFacialTrackingPropertiesHTC xr::system::htc_face_tracking_properties() c return face_tracking_prop; } +XrSystemBodyTrackingPropertiesFB xr::system::fb_body_tracking_properties() const +{ + if (!id) + throw std::invalid_argument("this"); + + XrSystemBodyTrackingPropertiesFB body_tracking_prop{ + .type = XR_TYPE_SYSTEM_BODY_TRACKING_PROPERTIES_FB, + }; + + XrSystemProperties prop{ + .type = XR_TYPE_SYSTEM_PROPERTIES, + .next = &body_tracking_prop, + }; + CHECK_XR(xrGetSystemProperties(*inst, id, &prop)); + + return body_tracking_prop; +} + +XrSystemBodyTrackingPropertiesBD xr::system::bd_body_tracking_properties() const +{ + if (!id) + throw std::invalid_argument("this"); + + XrSystemBodyTrackingPropertiesBD body_tracking_prop{ + .type = XR_TYPE_SYSTEM_BODY_TRACKING_PROPERTIES_BD, + }; + + XrSystemProperties prop{ + .type = XR_TYPE_SYSTEM_PROPERTIES, + .next = &body_tracking_prop, + }; + CHECK_XR(xrGetSystemProperties(*inst, id, &prop)); + + return body_tracking_prop; +} + xr::system::passthrough_type xr::system::passthrough_supported() const { if (utils::contains(environment_blend_modes(XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO), XR_ENVIRONMENT_BLEND_MODE_ALPHA_BLEND)) diff --git a/client/xr/system.h b/client/xr/system.h index 0a1b76fc..45e7729b 100644 --- a/client/xr/system.h +++ b/client/xr/system.h @@ -64,6 +64,8 @@ public: XrSystemEyeGazeInteractionPropertiesEXT eye_gaze_interaction_properties() const; XrSystemFaceTrackingProperties2FB fb_face_tracking2_properties() const; XrSystemFacialTrackingPropertiesHTC htc_face_tracking_properties() const; + XrSystemBodyTrackingPropertiesFB fb_body_tracking_properties() const; + XrSystemBodyTrackingPropertiesBD bd_body_tracking_properties() const; passthrough_type passthrough_supported() const; XrGraphicsRequirementsVulkan2KHR graphics_requirements() const; diff --git a/common/wivrn_packets.h b/common/wivrn_packets.h index a44a3f64..74e53979 100644 --- a/common/wivrn_packets.h +++ b/common/wivrn_packets.h @@ -116,6 +116,7 @@ enum class device_id : uint8_t RIGHT_TRACKPAD_FORCE, // /user/hand/right/input/trackpad/force RIGHT_STYLUS_FORCE, // /user/hand/right/input/stylus_fb/force EYE_GAZE, // /user/eyes_ext/input/gaze_ext/pose + GENERIC_TRACKER, }; enum class interaction_profile : uint8_t @@ -220,6 +221,7 @@ struct headset_info_packet bool palm_pose; bool passthrough; face_type face_tracking; + uint32_t num_generic_trackers; std::vector supported_codecs; // from preferred to least preferred std::string system_name; }; @@ -571,6 +573,7 @@ struct tracking_control left_hand, right_hand, face, + generic_tracker, battery, microphone, diff --git a/common/xr/meta_body_tracking_fidelity.h b/common/xr/meta_body_tracking_fidelity.h new file mode 100644 index 00000000..acb31417 --- /dev/null +++ b/common/xr/meta_body_tracking_fidelity.h @@ -0,0 +1,41 @@ +// clang-format off +#pragma once + +#include + +// XR_META_body_tracking_fidelity is a preprocessor guard. Do not pass it to API calls. +#define XR_META_body_tracking_fidelity 1 +#define XR_META_body_tracking_fidelity_SPEC_VERSION 1 +#define XR_META_BODY_TRACKING_FIDELITY_EXTENSION_NAME "XR_META_body_tracking_fidelity" +static const XrStructureType XR_TYPE_BODY_TRACKING_FIDELITY_STATUS_META = (XrStructureType) 1000284000; +static const XrStructureType XR_TYPE_SYSTEM_PROPERTIES_BODY_TRACKING_FIDELITY_META = (XrStructureType) 1000284001; + +typedef enum XrBodyTrackingFidelityMETA { + XR_BODY_TRACKING_FIDELITY_LOW_META = 1, + XR_BODY_TRACKING_FIDELITY_HIGH_META = 2, + XR_BODY_TRACKING_FIDELITY_MAX_ENUM_META = 0x7FFFFFFF +} XrBodyTrackingFidelityMETA; +typedef struct XrSystemPropertiesBodyTrackingFidelityMETA { + XrStructureType type; + void* XR_MAY_ALIAS next; + XrBool32 supportsBodyTrackingFidelity; +} XrSystemPropertiesBodyTrackingFidelityMETA; + +// XrBodyTrackingFidelityStatusMETA extends XrBodyJointLocationsFB +typedef struct XrBodyTrackingFidelityStatusMETA { + XrStructureType type; + const void* XR_MAY_ALIAS next; + XrBodyTrackingFidelityMETA fidelity; +} XrBodyTrackingFidelityStatusMETA; + +typedef XrResult (XRAPI_PTR *PFN_xrRequestBodyTrackingFidelityMETA)(XrBodyTrackerFB bodyTracker, const XrBodyTrackingFidelityMETA fidelity); + +#ifndef XR_NO_PROTOTYPES +#ifdef XR_EXTENSION_PROTOTYPES +XRAPI_ATTR XrResult XRAPI_CALL xrRequestBodyTrackingFidelityMETA( + XrBodyTrackerFB bodyTracker, + const XrBodyTrackingFidelityMETA fidelity); +#endif /* XR_EXTENSION_PROTOTYPES */ +#endif /* !XR_NO_PROTOTYPES */ + +// clang-format on diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 89c7da77..285e8bbf 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -96,6 +96,7 @@ if (WIVRN_BUILD_SERVER) driver/wivrn_eye_tracker.cpp driver/wivrn_fb_face2_tracker.cpp driver/wivrn_htc_face_tracker.cpp + driver/wivrn_generic_tracker.cpp driver/wivrn_foveation.cpp driver/pose_list.cpp driver/view_list.cpp diff --git a/server/driver/wivrn_controller.cpp b/server/driver/wivrn_controller.cpp index 8592be65..f757f604 100644 --- a/server/driver/wivrn_controller.cpp +++ b/server/driver/wivrn_controller.cpp @@ -234,6 +234,7 @@ static input_data map_input(device_id id) return {WIVRN_CONTROLLER_THUMBREST_FORCE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER}; case device_id::RIGHT_STYLUS_FORCE: return {WIVRN_CONTROLLER_STYLUS_FORCE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER}; + default: break; } throw std::range_error("bad input id " + std::to_string((int)id)); diff --git a/server/driver/wivrn_generic_tracker.cpp b/server/driver/wivrn_generic_tracker.cpp new file mode 100644 index 00000000..f8a272fd --- /dev/null +++ b/server/driver/wivrn_generic_tracker.cpp @@ -0,0 +1,154 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2022 Guillaume Meunier + * Copyright (C) 2022 Patrick Nicolas + * Copyright (C) 2025 Sapphire + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "wivrn_generic_tracker.h" +#include "utils/method.h" +#include "wivrn_session.h" + +#include "math/m_api.h" +#include "math/m_eigen_interop.hpp" +#include "math/m_space.h" +#include "math/m_vec3.h" +#include "xrt/xrt_defines.h" +#include "xrt/xrt_results.h" +#include "xrt_cast.h" +#include +#include + +using namespace xrt::auxiliary::math; + +namespace wivrn +{ + +xrt_space_relation tracker_pose_list::interpolate(const xrt_space_relation & a, const xrt_space_relation & b, float t) +{ + xrt_space_relation result; + xrt_space_relation_flags flags = xrt_space_relation_flags(a.relation_flags & b.relation_flags); + m_space_relation_interpolate(const_cast(&a), const_cast(&b), t, flags, &result); + return result; +} + +xrt_space_relation tracker_pose_list::extrapolate(const xrt_space_relation & a, const xrt_space_relation & b, int64_t ta, int64_t tb, int64_t t) +{ + float h = (tb - ta) / 1.e9; + + xrt_space_relation res = t < ta ? a : b; + + xrt_vec3 lin_vel = res.relation_flags & XRT_SPACE_RELATION_LINEAR_VELOCITY_VALID_BIT ? res.linear_velocity : (b.pose.position - a.pose.position) / h; + + float dt = (t - tb) / 1.e9; + + float dt2_over_2 = dt * dt / 2; + res.pose.position = res.pose.position + lin_vel * dt; + + if (res.relation_flags & XRT_SPACE_RELATION_ANGULAR_VELOCITY_VALID_BIT) + { + xrt_vec3 dtheta = res.angular_velocity * dt; + xrt_quat dq; + math_quat_exp(&dtheta, &dq); + + map_quat(res.pose.orientation) = map_quat(res.pose.orientation) * map_quat(dq); + } + + return res; +} + +bool tracker_pose_list::update_tracking(XrTime produced_timestamp, XrTime timestamp, const from_headset::tracking::pose & pose, const clock_offset & offset) +{ + return add_sample(produced_timestamp, timestamp, convert_pose(pose), offset); +} + +std::pair tracker_pose_list::get_pose_at(XrTime at_timestamp_ns) +{ + return get_at(at_timestamp_ns); +} + +static xrt_space_relation_flags convert_flags(uint8_t flags) +{ + static_assert(int(from_headset::tracking::position_valid) == XRT_SPACE_RELATION_POSITION_VALID_BIT); + static_assert(int(from_headset::tracking::orientation_valid) == XRT_SPACE_RELATION_ORIENTATION_VALID_BIT); + static_assert(int(from_headset::tracking::linear_velocity_valid) == XRT_SPACE_RELATION_LINEAR_VELOCITY_VALID_BIT); + static_assert(int(from_headset::tracking::angular_velocity_valid) == XRT_SPACE_RELATION_ANGULAR_VELOCITY_VALID_BIT); + static_assert(int(from_headset::tracking::orientation_tracked) == XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT); + static_assert(int(from_headset::tracking::position_tracked) == XRT_SPACE_RELATION_POSITION_TRACKED_BIT); + return xrt_space_relation_flags(flags); +} + +xrt_space_relation tracker_pose_list::convert_pose(const from_headset::tracking::pose & pose) +{ + return xrt_space_relation{ + .relation_flags = convert_flags(pose.flags), + .pose = xrt_cast(pose.pose), + .linear_velocity = xrt_cast(pose.linear_velocity), + .angular_velocity = xrt_cast(pose.angular_velocity), + }; +} + +wivrn_generic_tracker::wivrn_generic_tracker(int index, xrt_device * hmd, wivrn_session & cnx) : + xrt_device{ + .name = XRT_DEVICE_VIVE_TRACKER, + .device_type = XRT_DEVICE_TYPE_GENERIC_TRACKER, + .hmd = nullptr, + .tracking_origin = hmd->tracking_origin, + .orientation_tracking_supported = true, + .position_tracking_supported = true, + .update_inputs = method_pointer<&wivrn_generic_tracker::update_inputs>, + .get_tracked_pose = method_pointer<&wivrn_generic_tracker::get_tracked_pose>, + .destroy = [](xrt_device *) {}, + }, + cnx(cnx) +{ + auto unique_name = std::format("WiVRn Generic Tracker #{}", index); + strlcpy(str, unique_name.c_str(), std::size(str)); + strlcpy(serial, unique_name.c_str(), std::size(serial)); + + pose_input.name = XRT_INPUT_GENERIC_TRACKER_POSE; + pose_input.active = true; + + inputs = &pose_input; + input_count = 1; +} + +xrt_result_t wivrn_generic_tracker::update_inputs() +{ + return XRT_SUCCESS; +} +xrt_result_t wivrn_generic_tracker::get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation * res) +{ + std::chrono::nanoseconds extrapolation_time; + + if (name == XRT_INPUT_GENERIC_TRACKER_POSE) + { + std::tie(extrapolation_time, *res) = poses.get_pose_at(at_timestamp_ns); + + cnx.set_enabled(to_headset::tracking_control::id::generic_tracker, true); + cnx.add_predict_offset(extrapolation_time); + return XRT_SUCCESS; + } + return XRT_ERROR_NOT_IMPLEMENTED; +} + +void wivrn_generic_tracker::update_tracking(const from_headset::tracking & tracking, const from_headset::tracking::pose & pose, const clock_offset & offset) +{ + // TODO: Right now we ignore the return value, because if the pose of one of the trackers is not requested for a while, all of them get deactivated, which isn't ideal. + poses.update_tracking(tracking.production_timestamp, tracking.timestamp, pose, offset); + // cnx.set_enabled(to_headset::tracking_control::id::generic_tracker, false); +} +} // namespace wivrn \ No newline at end of file diff --git a/server/driver/wivrn_generic_tracker.h b/server/driver/wivrn_generic_tracker.h new file mode 100644 index 00000000..60531aaf --- /dev/null +++ b/server/driver/wivrn_generic_tracker.h @@ -0,0 +1,60 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2025 Sapphire + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include "history.h" +#include "xrt/xrt_device.h" + +namespace wivrn +{ +class wivrn_session; +struct clock_offset; + +class tracker_pose_list : public history +{ +public: + static xrt_space_relation interpolate(const xrt_space_relation & a, const xrt_space_relation & b, float t); + static xrt_space_relation extrapolate(const xrt_space_relation & a, const xrt_space_relation & b, int64_t ta, int64_t tb, int64_t t); + + tracker_pose_list() = default; + + bool update_tracking(XrTime produced_timestamp, XrTime timestamp, const from_headset::tracking::pose & pose, const clock_offset & offset); + + std::pair get_pose_at(XrTime at_timestamp_ns); + + static xrt_space_relation convert_pose(const wivrn::from_headset::tracking::pose &); +}; + +class wivrn_generic_tracker : public xrt_device +{ + tracker_pose_list poses; + xrt_input pose_input; + + wivrn_session & cnx; + +public: + using base = xrt_device; + wivrn_generic_tracker(int index, xrt_device * hmd, wivrn_session & cnx); + + xrt_result_t update_inputs(); + xrt_result_t get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation * out_relation); + + void update_tracking(const from_headset::tracking & tracking, const from_headset::tracking::pose & pose, const clock_offset & offset); +}; +} // namespace wivrn \ No newline at end of file diff --git a/server/driver/wivrn_session.cpp b/server/driver/wivrn_session.cpp index 187bce17..ea18fbb2 100644 --- a/server/driver/wivrn_session.cpp +++ b/server/driver/wivrn_session.cpp @@ -34,12 +34,14 @@ #include "wivrn_config.h" #include "wivrn_eye_tracker.h" #include "wivrn_fb_face2_tracker.h" +#include "wivrn_generic_tracker.h" #include "wivrn_htc_face_tracker.h" #include "wivrn_ipc.h" #include "wivrn_packets.h" #include "xrt/xrt_device.h" #include "xrt/xrt_session.h" +#include #include #include #include @@ -116,6 +118,11 @@ void wivrn::tracking_control_t::send(wivrn_connection & connection, bool now) next_sample += std::chrono::seconds(1); } +bool wivrn::tracking_control_t::get_enabled(to_headset::tracking_control::id id) +{ + std::lock_guard lock(mutex); + return this->enabled[size_t(id)]; +} bool wivrn::tracking_control_t::set_enabled(to_headset::tracking_control::id id, bool enabled) { std::lock_guard lock(mutex); @@ -215,6 +222,20 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr connection xdevs[xdev_count++] = htc_face_tracker.get(); } + if (auto num_trackers = get_info().num_generic_trackers; num_trackers > 0) + { + generic_trackers.clear(); + generic_trackers.reserve(num_trackers); + U_LOG_I("Creating %d generic trackers", num_trackers); + + for (int i = 1; i <= num_trackers; ++i) + { + auto dev = std::make_unique(i, &hmd, *this); + xdevs[xdev_count++] = dev.get(); + generic_trackers.push_back(std::move(dev)); + } + } + #if WIVRN_FEATURE_SOLARXR xrt_device * solar_devs[XRT_SYSTEM_MAX_DEVICES]; uint32_t solar_devs_cap = XRT_SYSTEM_MAX_DEVICES - xdev_count; @@ -412,6 +433,29 @@ void wivrn_session::operator()(const from_headset::tracking & tracking) fb_face2_tracker->update_tracking(tracking, offset); else if (htc_face_tracker) htc_face_tracker->update_tracking(tracking, offset); + + auto num_trackers = std::ranges::count(tracking.device_poses, device_id::GENERIC_TRACKER, &from_headset::tracking::pose::device); + if (num_trackers == generic_trackers.size()) + { + // the generic trackers should always be at end of poses list + auto tracker = std::ranges::find(tracking.device_poses, device_id::GENERIC_TRACKER, &from_headset::tracking::pose::device); + assert(tracker != tracking.device_poses.cend()); + for (size_t i = 0; i < num_trackers; ++i, ++tracker) + { + generic_trackers[i]->update_tracking(tracking, *tracker, offset); + } + } + else if (tracking_control.get_enabled(to_headset::tracking_control::id::generic_tracker)) + { + static std::chrono::steady_clock::time_point last_log{std::chrono::nanoseconds(0)}; + auto now = std::chrono::steady_clock::now(); + // rate limit it because the log gets annoying when i'm trying to debug + if (now - last_log > std::chrono::milliseconds(100)) + { + U_LOG_W("[rate limited] Generic tracker count mismatch! Expected %" PRIu64 " poses, got %" PRIu64 " poses", generic_trackers.size(), num_trackers); + last_log = now; + } + } } void wivrn_session::operator()(from_headset::derived_pose && derived) diff --git a/server/driver/wivrn_session.h b/server/driver/wivrn_session.h index 4fe0ddce..a1163ba0 100644 --- a/server/driver/wivrn_session.h +++ b/server/driver/wivrn_session.h @@ -33,6 +33,7 @@ #include #include #include +#include struct u_system; struct xrt_space_overseer; @@ -44,6 +45,7 @@ namespace wivrn class wivrn_eye_tracker; class wivrn_fb_face2_tracker; class wivrn_htc_face_tracker; +class wivrn_generic_tracker; struct audio_device; struct wivrn_comp_target; struct wivrn_comp_target_factory; @@ -80,6 +82,7 @@ public: } void send(wivrn_connection & connection, bool now = false); + bool get_enabled(to_headset::tracking_control::id id); // Return true if value changed bool set_enabled(to_headset::tracking_control::id id, bool enabled); }; @@ -108,6 +111,7 @@ class wivrn_session : public xrt_system_devices std::unique_ptr fb_face2_tracker; std::unique_ptr htc_face_tracker; std::shared_ptr comp_target; + std::vector> generic_trackers; clock_offset_estimator offset_est; From 1d6b444ec68e1e9dff8431c736ea6646ab08a7a8 Mon Sep 17 00:00:00 2001 From: Sapphire Date: Tue, 3 Jun 2025 12:01:33 -0500 Subject: [PATCH 50/85] Use separate packet to send generic tracker poses --- client/scenes/stream_tracking.cpp | 53 +++++++++++++++++-------- client/xr/fb_body_tracker.cpp | 53 +++++++++---------------- client/xr/fb_body_tracker.h | 5 ++- client/xr/pico_body_tracker.cpp | 45 ++++++++------------- client/xr/pico_body_tracker.h | 5 ++- client/xr/session.cpp | 8 ++-- client/xr/session.h | 4 +- client/xr/system.cpp | 6 +-- common/wivrn_packets.h | 24 ++++++++++- server/driver/wivrn_generic_tracker.cpp | 29 ++++++++------ server/driver/wivrn_generic_tracker.h | 6 +-- server/driver/wivrn_session.cpp | 36 ++++++----------- server/driver/wivrn_session.h | 1 + 13 files changed, 145 insertions(+), 130 deletions(-) diff --git a/client/scenes/stream_tracking.cpp b/client/scenes/stream_tracking.cpp index 2cc2e3ca..1bdb3bae 100644 --- a/client/scenes/stream_tracking.cpp +++ b/client/scenes/stream_tracking.cpp @@ -232,9 +232,11 @@ void scenes::stream::tracking() XrTime t0 = instance.now(); XrTime last_hand_sample = t0; + XrTime last_body_sample = t0; std::vector tracking; std::vector tracking_pool; // pre-allocated objects std::vector hands; + std::vector body; std::vector views; std::vector merged_tracking; @@ -286,6 +288,7 @@ void scenes::stream::tracking() { tracking.clear(); hands.clear(); + body.clear(); XrTime now = instance.now(); if (now < t0) @@ -355,6 +358,30 @@ void scenes::stream::tracking() locate_hands(application::get_right_hand(), world_space, t0 + Δt)); } + if (body_tracking != body_none and t0 >= last_body_sample + period and + (Δt == 0 or Δt >= prediction - 2 * period)) + { + last_body_sample = t0; + if (control.enabled[size_t(tid::generic_tracker)]) + { + auto & body_packet = body.emplace_back(from_headset::body_tracking{ + .production_timestamp = t0, + .timestamp = t0 + Δt, + }); + switch (body_tracking) + { + case body_none: + __builtin_unreachable(); + case body_fb: + body_packet.poses = application::get_fb_body_tracker().locate_spaces(t0 + Δt, world_space); + break; + case body_pico: + body_packet.poses = application::get_pico_body_tracker().locate_spaces(t0 + Δt, world_space); + break; + } + } + } + if (control.enabled[size_t(tid::face)]) { switch (face_tracking) @@ -379,21 +406,6 @@ void scenes::stream::tracking() break; } } - - if (control.enabled[size_t(tid::generic_tracker)]) - { - switch (body_tracking) - { - case body_none: - break; - case body_fb: - application::get_fb_body_tracker().locate_spaces(t0 + Δt, packet.device_poses, world_space); - break; - case body_pico: - application::get_pico_body_tracker().locate_spaces(t0 + Δt, packet.device_poses, world_space); - break; - } - } } catch (const std::system_error & e) { @@ -443,7 +455,7 @@ void scenes::stream::tracking() merged_tracking.back().items.emplace_back(std::move(item)); } - packets.resize(std::max(packets.size(), merged_tracking.size() + hands.size())); + packets.resize(std::max(packets.size(), merged_tracking.size() + hands.size() + body.size())); size_t packet_count = 0; for (const auto & i: merged_tracking) { @@ -460,6 +472,15 @@ void scenes::stream::tracking() wivrn_session::stream_socket_t::serialize(packet, i); } } + for (const auto & i: body) + { + if (i.poses) + { + auto & packet = packets[packet_count++]; + packet.clear(); + wivrn_session::stream_socket_t::serialize(packet, i); + } + } network_session->send_stream(std::span(packets.data(), packet_count)); diff --git a/client/xr/fb_body_tracker.cpp b/client/xr/fb_body_tracker.cpp index 8d5946f3..691513a7 100644 --- a/client/xr/fb_body_tracker.cpp +++ b/client/xr/fb_body_tracker.cpp @@ -22,6 +22,8 @@ #include "xr/xr.h" #include +static_assert(xr::pico_body_tracker::joint_whitelist.size() <= wivrn::from_headset::body_tracking::max_tracked_poses); + xr::fb_body_tracker::fb_body_tracker(instance & inst, session & s) : s(s) { @@ -61,26 +63,11 @@ void xr::fb_body_tracker::stop() CHECK_XR(xrDestroyBodyTrackerFB(std::exchange(handle, nullptr))); } -void xr::fb_body_tracker::locate_spaces(XrTime time, std::vector & out_poses, XrSpace reference) +std::optional> xr::fb_body_tracker::locate_spaces(XrTime time, XrSpace reference) { - auto fill_poses = [&]() { - for (auto joint: joint_whitelist) - { - if (!full_body && joint >= XR_FULL_BODY_JOINT_LEFT_UPPER_LEG_META) - return; - - wivrn::from_headset::tracking::pose pose{ - .pose = {}, - .device = wivrn::device_id::GENERIC_TRACKER, - .flags = 0, - }; - out_poses.push_back(std::move(pose)); - } - }; if (!handle) { - fill_poses(); - return; + return std::nullopt; } assert(xrLocateBodyJointsFB); @@ -103,40 +90,38 @@ void xr::fb_body_tracker::locate_spaces(XrTime time, std::vector poses{}; + for (int i = 0; i < joint_whitelist.size(); i++) { + auto joint = joint_whitelist[i]; if (!full_body && joint >= XR_FULL_BODY_JOINT_LEFT_UPPER_LEG_META) - return; + break; auto joint_pose = joints[joint]; - wivrn::from_headset::tracking::pose pose{ + wivrn::from_headset::body_tracking::pose pose{ .pose = joint_pose.pose, - .device = wivrn::device_id::GENERIC_TRACKER, .flags = 0, }; - if (joint_pose.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT) - pose.flags |= wivrn::from_headset::tracking::position_valid; if (joint_pose.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT) - pose.flags |= wivrn::from_headset::tracking::orientation_valid; - if (joint_pose.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT) - pose.flags |= wivrn::from_headset::tracking::position_tracked; + pose.flags |= wivrn::from_headset::body_tracking::orientation_valid; + if (joint_pose.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT) + pose.flags |= wivrn::from_headset::body_tracking::position_valid; if (joint_pose.locationFlags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT) - pose.flags |= wivrn::from_headset::tracking::orientation_tracked; + pose.flags |= wivrn::from_headset::body_tracking::orientation_tracked; + if (joint_pose.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT) + pose.flags |= wivrn::from_headset::body_tracking::position_tracked; - out_poses.push_back(std::move(pose)); + poses[i] = std::move(pose); } - return; + return poses; } diff --git a/client/xr/fb_body_tracker.h b/client/xr/fb_body_tracker.h index 95202c13..5e0f6af2 100644 --- a/client/xr/fb_body_tracker.h +++ b/client/xr/fb_body_tracker.h @@ -21,7 +21,8 @@ #include "wivrn_packets.h" #include "xr/meta_body_tracking_fidelity.h" -#include +#include +#include #include namespace xr @@ -64,6 +65,6 @@ public: void start(bool lower_body); void stop(); - void locate_spaces(XrTime time, std::vector & out_poses, XrSpace reference); + std::optional> locate_spaces(XrTime time, XrSpace reference); }; } // namespace xr diff --git a/client/xr/pico_body_tracker.cpp b/client/xr/pico_body_tracker.cpp index 99219411..6a195296 100644 --- a/client/xr/pico_body_tracker.cpp +++ b/client/xr/pico_body_tracker.cpp @@ -21,6 +21,8 @@ #include "xr/xr.h" #include +static_assert(xr::pico_body_tracker::joint_whitelist.size() <= wivrn::from_headset::body_tracking::max_tracked_poses); + static PFN_xrDestroyBodyTrackerBD xrDestroyBodyTrackerBD{}; XrResult xr::destroy_pico_body_tracker(XrBodyTrackerBD id) @@ -34,24 +36,11 @@ xr::pico_body_tracker::pico_body_tracker(instance & inst, XrBodyTrackerBD h) xrLocateBodyJointsBD = inst.get_proc("xrLocateBodyJointsBD"); } -void xr::pico_body_tracker::locate_spaces(XrTime time, std::vector & out_poses, XrSpace reference) +std::optional> xr::pico_body_tracker::locate_spaces(XrTime time, XrSpace reference) { - auto fill_poses = [&]() { - for (auto _: joint_whitelist) - { - wivrn::from_headset::tracking::pose pose{ - .pose = {}, - .device = wivrn::device_id::GENERIC_TRACKER, - .flags = 0, - }; - out_poses.push_back(std::move(pose)); - } - }; - if (!xrLocateBodyJointsBD) { - fill_poses(); - return; + return std::nullopt; } XrBodyJointsLocateInfoBD locate_info{ @@ -72,28 +61,28 @@ void xr::pico_body_tracker::locate_spaces(XrTime time, std::vector poses{}; + for (int i = 0; i < joint_whitelist.size(); i++) { - auto & joint_location = joints[joint]; - wivrn::from_headset::tracking::pose pose{ + auto & joint_location = joints[joint_whitelist[i]]; + wivrn::from_headset::body_tracking::pose pose{ .pose = joint_location.pose, - .device = wivrn::device_id::GENERIC_TRACKER, .flags = 0, }; - if (joint_location.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT) - pose.flags |= wivrn::from_headset::tracking::position_valid; if (joint_location.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT) - pose.flags |= wivrn::from_headset::tracking::orientation_valid; - if (joint_location.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT) - pose.flags |= wivrn::from_headset::tracking::position_tracked; + pose.flags |= wivrn::from_headset::body_tracking::orientation_valid; + if (joint_location.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT) + pose.flags |= wivrn::from_headset::body_tracking::position_valid; if (joint_location.locationFlags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT) - pose.flags |= wivrn::from_headset::tracking::orientation_tracked; + pose.flags |= wivrn::from_headset::body_tracking::orientation_tracked; + if (joint_location.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT) + pose.flags |= wivrn::from_headset::body_tracking::position_tracked; - out_poses.push_back(std::move(pose)); + poses[i] = std::move(pose); } + return poses; } diff --git a/client/xr/pico_body_tracker.h b/client/xr/pico_body_tracker.h index 1f2e393f..dbdfc03c 100644 --- a/client/xr/pico_body_tracker.h +++ b/client/xr/pico_body_tracker.h @@ -21,7 +21,8 @@ #include "utils/handle.h" #include "wivrn_packets.h" -#include +#include +#include #include namespace xr @@ -52,6 +53,6 @@ public: pico_body_tracker() = default; pico_body_tracker(instance & inst, XrBodyTrackerBD h); - void locate_spaces(XrTime time, std::vector & out_poses, XrSpace reference); + std::optional> locate_spaces(XrTime time, XrSpace reference); }; } // namespace xr diff --git a/client/xr/session.cpp b/client/xr/session.cpp index 0d86d0b5..5c92a8e7 100644 --- a/client/xr/session.cpp +++ b/client/xr/session.cpp @@ -24,8 +24,8 @@ #include "openxr/openxr.h" #include "utils/contains.h" #include "xr/fb_body_tracker.h" -#include "xr/pico_body_tracker.h" #include "xr/instance.h" +#include "xr/pico_body_tracker.h" #include "xr/system.h" #include #include @@ -152,9 +152,9 @@ xr::fb_body_tracker xr::session::create_fb_body_tracker() xr::pico_body_tracker xr::session::create_pico_body_tracker() { XrBodyTrackerCreateInfoBD create_info{ - .type = XR_TYPE_BODY_TRACKER_CREATE_INFO_BD, - .next = nullptr, - .jointSet = XR_BODY_JOINT_SET_FULL_BODY_JOINTS_BD, + .type = XR_TYPE_BODY_TRACKER_CREATE_INFO_BD, + .next = nullptr, + .jointSet = XR_BODY_JOINT_SET_FULL_BODY_JOINTS_BD, }; XrBodyTrackerBD bt; diff --git a/client/xr/session.h b/client/xr/session.h index 23c1b705..e3c31647 100644 --- a/client/xr/session.h +++ b/client/xr/session.h @@ -26,12 +26,12 @@ #include #include +#include "fb_body_tracker.h" #include "fb_face_tracker2.h" #include "hand_tracker.h" #include "htc_face_tracker.h" -#include "fb_body_tracker.h" -#include "pico_body_tracker.h" #include "passthrough.h" +#include "pico_body_tracker.h" #include "pico_face_tracker.h" #include "space.h" diff --git a/client/xr/system.cpp b/client/xr/system.cpp index 5357b192..0c88054d 100644 --- a/client/xr/system.cpp +++ b/client/xr/system.cpp @@ -147,12 +147,12 @@ XrSystemBodyTrackingPropertiesFB xr::system::fb_body_tracking_properties() const throw std::invalid_argument("this"); XrSystemBodyTrackingPropertiesFB body_tracking_prop{ - .type = XR_TYPE_SYSTEM_BODY_TRACKING_PROPERTIES_FB, + .type = XR_TYPE_SYSTEM_BODY_TRACKING_PROPERTIES_FB, }; XrSystemProperties prop{ - .type = XR_TYPE_SYSTEM_PROPERTIES, - .next = &body_tracking_prop, + .type = XR_TYPE_SYSTEM_PROPERTIES, + .next = &body_tracking_prop, }; CHECK_XR(xrGetSystemProperties(*inst, id, &prop)); diff --git a/common/wivrn_packets.h b/common/wivrn_packets.h index 74e53979..1d4cbcab 100644 --- a/common/wivrn_packets.h +++ b/common/wivrn_packets.h @@ -116,7 +116,6 @@ enum class device_id : uint8_t RIGHT_TRACKPAD_FORCE, // /user/hand/right/input/trackpad/force RIGHT_STYLUS_FORCE, // /user/hand/right/input/stylus_fb/force EYE_GAZE, // /user/eyes_ext/input/gaze_ext/pose - GENERIC_TRACKER, }; enum class interaction_profile : uint8_t @@ -339,6 +338,28 @@ struct hand_tracking std::optional> joints; }; +struct body_tracking +{ + inline static const size_t max_tracked_poses = 16; + enum flags : uint8_t + { + orientation_valid = 1 << 0, + position_valid = 1 << 1, + orientation_tracked = 1 << 2, + position_tracked = 1 << 3, + }; + struct pose + { + XrPosef pose{}; + // maybe add velocity? + uint8_t flags{0}; + }; + + XrTime production_timestamp; + XrTime timestamp; + std::optional> poses; +}; + struct inputs { struct input_value @@ -401,6 +422,7 @@ using packets = std::variant< trackings, derived_pose, hand_tracking, + body_tracking, inputs, timesync_response, battery, diff --git a/server/driver/wivrn_generic_tracker.cpp b/server/driver/wivrn_generic_tracker.cpp index f8a272fd..688a6652 100644 --- a/server/driver/wivrn_generic_tracker.cpp +++ b/server/driver/wivrn_generic_tracker.cpp @@ -70,7 +70,7 @@ xrt_space_relation tracker_pose_list::extrapolate(const xrt_space_relation & a, return res; } -bool tracker_pose_list::update_tracking(XrTime produced_timestamp, XrTime timestamp, const from_headset::tracking::pose & pose, const clock_offset & offset) +bool tracker_pose_list::update_tracking(XrTime produced_timestamp, XrTime timestamp, const from_headset::body_tracking::pose & pose, const clock_offset & offset) { return add_sample(produced_timestamp, timestamp, convert_pose(pose), offset); } @@ -82,22 +82,27 @@ std::pair tracker_pose_list::get_p static xrt_space_relation_flags convert_flags(uint8_t flags) { - static_assert(int(from_headset::tracking::position_valid) == XRT_SPACE_RELATION_POSITION_VALID_BIT); - static_assert(int(from_headset::tracking::orientation_valid) == XRT_SPACE_RELATION_ORIENTATION_VALID_BIT); - static_assert(int(from_headset::tracking::linear_velocity_valid) == XRT_SPACE_RELATION_LINEAR_VELOCITY_VALID_BIT); - static_assert(int(from_headset::tracking::angular_velocity_valid) == XRT_SPACE_RELATION_ANGULAR_VELOCITY_VALID_BIT); - static_assert(int(from_headset::tracking::orientation_tracked) == XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT); - static_assert(int(from_headset::tracking::position_tracked) == XRT_SPACE_RELATION_POSITION_TRACKED_BIT); - return xrt_space_relation_flags(flags); + std::underlying_type_t out_flags = 0; + if (flags & from_headset::body_tracking::orientation_valid) + out_flags |= XRT_SPACE_RELATION_ORIENTATION_VALID_BIT; + if (flags & from_headset::body_tracking::position_valid) + out_flags |= XRT_SPACE_RELATION_POSITION_VALID_BIT; + + if (flags & from_headset::body_tracking::orientation_tracked) + out_flags |= XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT; + if (flags & from_headset::body_tracking::position_tracked) + out_flags |= XRT_SPACE_RELATION_POSITION_TRACKED_BIT; + + return xrt_space_relation_flags(out_flags); } -xrt_space_relation tracker_pose_list::convert_pose(const from_headset::tracking::pose & pose) +xrt_space_relation tracker_pose_list::convert_pose(const from_headset::body_tracking::pose & pose) { return xrt_space_relation{ .relation_flags = convert_flags(pose.flags), .pose = xrt_cast(pose.pose), - .linear_velocity = xrt_cast(pose.linear_velocity), - .angular_velocity = xrt_cast(pose.angular_velocity), + .linear_velocity = {}, + .angular_velocity = {}, }; } @@ -145,7 +150,7 @@ xrt_result_t wivrn_generic_tracker::get_tracked_pose(xrt_input_name name, int64_ return XRT_ERROR_NOT_IMPLEMENTED; } -void wivrn_generic_tracker::update_tracking(const from_headset::tracking & tracking, const from_headset::tracking::pose & pose, const clock_offset & offset) +void wivrn_generic_tracker::update_tracking(const from_headset::body_tracking & tracking, const from_headset::body_tracking::pose & pose, const clock_offset & offset) { // TODO: Right now we ignore the return value, because if the pose of one of the trackers is not requested for a while, all of them get deactivated, which isn't ideal. poses.update_tracking(tracking.production_timestamp, tracking.timestamp, pose, offset); diff --git a/server/driver/wivrn_generic_tracker.h b/server/driver/wivrn_generic_tracker.h index 60531aaf..dcf2675f 100644 --- a/server/driver/wivrn_generic_tracker.h +++ b/server/driver/wivrn_generic_tracker.h @@ -34,11 +34,11 @@ public: tracker_pose_list() = default; - bool update_tracking(XrTime produced_timestamp, XrTime timestamp, const from_headset::tracking::pose & pose, const clock_offset & offset); + bool update_tracking(XrTime produced_timestamp, XrTime timestamp, const from_headset::body_tracking::pose & pose, const clock_offset & offset); std::pair get_pose_at(XrTime at_timestamp_ns); - static xrt_space_relation convert_pose(const wivrn::from_headset::tracking::pose &); + static xrt_space_relation convert_pose(const wivrn::from_headset::body_tracking::pose &); }; class wivrn_generic_tracker : public xrt_device @@ -55,6 +55,6 @@ public: xrt_result_t update_inputs(); xrt_result_t get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation * out_relation); - void update_tracking(const from_headset::tracking & tracking, const from_headset::tracking::pose & pose, const clock_offset & offset); + void update_tracking(const from_headset::body_tracking & tracking, const from_headset::body_tracking::pose & pose, const clock_offset & offset); }; } // namespace wivrn \ No newline at end of file diff --git a/server/driver/wivrn_session.cpp b/server/driver/wivrn_session.cpp index ea18fbb2..d47f65a0 100644 --- a/server/driver/wivrn_session.cpp +++ b/server/driver/wivrn_session.cpp @@ -433,29 +433,6 @@ void wivrn_session::operator()(const from_headset::tracking & tracking) fb_face2_tracker->update_tracking(tracking, offset); else if (htc_face_tracker) htc_face_tracker->update_tracking(tracking, offset); - - auto num_trackers = std::ranges::count(tracking.device_poses, device_id::GENERIC_TRACKER, &from_headset::tracking::pose::device); - if (num_trackers == generic_trackers.size()) - { - // the generic trackers should always be at end of poses list - auto tracker = std::ranges::find(tracking.device_poses, device_id::GENERIC_TRACKER, &from_headset::tracking::pose::device); - assert(tracker != tracking.device_poses.cend()); - for (size_t i = 0; i < num_trackers; ++i, ++tracker) - { - generic_trackers[i]->update_tracking(tracking, *tracker, offset); - } - } - else if (tracking_control.get_enabled(to_headset::tracking_control::id::generic_tracker)) - { - static std::chrono::steady_clock::time_point last_log{std::chrono::nanoseconds(0)}; - auto now = std::chrono::steady_clock::now(); - // rate limit it because the log gets annoying when i'm trying to debug - if (now - last_log > std::chrono::milliseconds(100)) - { - U_LOG_W("[rate limited] Generic tracker count mismatch! Expected %" PRIu64 " poses, got %" PRIu64 " poses", generic_trackers.size(), num_trackers); - last_log = now; - } - } } void wivrn_session::operator()(from_headset::derived_pose && derived) @@ -471,6 +448,19 @@ void wivrn_session::operator()(from_headset::hand_tracking && hand_tracking) left_hand.update_hand_tracking(hand_tracking, offset); right_hand.update_hand_tracking(hand_tracking, offset); } +void wivrn_session::operator()(from_headset::body_tracking && body_tracking) +{ + auto offset = offset_est.get_offset(); + + for (int i = 0; i < generic_trackers.size(); i++) + { + auto pose = body_tracking.poses ? body_tracking.poses->at(i) : from_headset::body_tracking::pose{ + .pose = {}, + .flags = 0, + }; + generic_trackers[i]->update_tracking(body_tracking, pose, offset); + } +} void wivrn_session::operator()(from_headset::inputs && inputs) { auto offset = get_offset(); diff --git a/server/driver/wivrn_session.h b/server/driver/wivrn_session.h index a1163ba0..a2e70ae4 100644 --- a/server/driver/wivrn_session.h +++ b/server/driver/wivrn_session.h @@ -166,6 +166,7 @@ public: void operator()(const from_headset::tracking &); void operator()(from_headset::derived_pose &&); void operator()(from_headset::hand_tracking &&); + void operator()(from_headset::body_tracking &&); void operator()(from_headset::inputs &&); void operator()(from_headset::timesync_response &&); void operator()(from_headset::feedback &&); From 40f02b9404fcb8e2b95324e182592334dada1afa Mon Sep 17 00:00:00 2001 From: Sapphire Date: Tue, 3 Jun 2025 16:19:54 -0500 Subject: [PATCH 51/85] Add hip tracking toggle for fb body tracking * Only forward hip joint from FB_body_tracking when lower body is enabled * Fix body tracking tooltips being too wide --- client/configuration.cpp | 3 +++ client/configuration.h | 1 + client/scenes/lobby_gui.cpp | 17 +++++++++++++---- client/scenes/stream.cpp | 8 ++++++-- client/scenes/stream_tracking.cpp | 2 +- client/xr/fb_body_tracker.cpp | 12 ++++++++---- client/xr/fb_body_tracker.h | 3 ++- 7 files changed, 34 insertions(+), 12 deletions(-) diff --git a/client/configuration.cpp b/client/configuration.cpp index 557e9094..ca8685e6 100644 --- a/client/configuration.cpp +++ b/client/configuration.cpp @@ -226,6 +226,8 @@ configuration::configuration(xr::system & system) if (auto val = root["fb_lower_body"]; val.is_bool()) fb_lower_body = val.get_bool(); + if (auto val = root["fb_hip"]; val.is_bool()) + fb_hip = val.get_bool(); if (auto val = root["virtual_keyboard_layout"]; val.is_string()) virtual_keyboard_layout = val.get_string().value(); @@ -350,6 +352,7 @@ void configuration::save() 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; for (auto & [key, value]: features) json << "," << key << ":" << std::boolalpha << value; json << ",\"virtual_keyboard_layout\":" << json_string(virtual_keyboard_layout); diff --git a/client/configuration.h b/client/configuration.h index 565dc6dd..cdfdd8f5 100644 --- a/client/configuration.h +++ b/client/configuration.h @@ -55,6 +55,7 @@ public: bool mic_unprocessed_audio = false; bool fb_lower_body = false; + bool fb_hip = true; // Snapdragon Game Super Resolution struct sgsr_settings diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index 09333779..238a4b3f 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -758,11 +758,9 @@ void scenes::lobby::gui_settings() else { if (application::get_fb_body_tracking_supported()) - tooltip(_("Requires 'Hand and body tracking' to be enabled in the Quest movement tracking settings, otherwise estimated joint positions will be used")); + tooltip(_("Requires 'Hand and body tracking' to be enabled in the Quest movement tracking settings,\notherwise estimated joint positions will be used")); else if (application::get_pico_body_tracking_supported()) - { tooltip(_("Uses the Pico Motion Trackers to track body joint positions")); - } } } @@ -778,7 +776,18 @@ void scenes::lobby::gui_settings() } vibrate_on_hover(); if (ImGui::IsItemHovered()) - tooltip(_("Estimate lower body joint positions using Generative Legs, requires 'Hand and body tracking' to be enabled in the Quest movement tracking settings")); + tooltip(_("Estimate lower body joint positions using Generative Legs\nRequires 'Hand and body tracking' to be enabled in the Quest movement tracking settings")); + + ImGui::BeginDisabled(not config.fb_lower_body); + if (ImGui::Checkbox(_S("Enable hip tracking"), &config.fb_hip)) + { + config.save(); + } + vibrate_on_hover(); + if (ImGui::IsItemHovered()) + tooltip(_("Only takes affect with lower body tracking enabled\nMay be desired when using another source of hip tracking")); + ImGui::EndDisabled(); + ImGui::Unindent(); ImGui::EndDisabled(); } diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index bd1388ec..1f64c129 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -231,8 +231,12 @@ std::shared_ptr scenes::stream::create(std::unique_ptrfull_body = full_body; + this->hip = hip; XrBodyTrackerCreateInfoFB create_info{ .type = XR_TYPE_BODY_TRACKER_CREATE_INFO_FB, @@ -100,11 +101,14 @@ std::optional poses{}; + int num_poses = 0; for (int i = 0; i < joint_whitelist.size(); i++) { auto joint = joint_whitelist[i]; - if (!full_body && joint >= XR_FULL_BODY_JOINT_LEFT_UPPER_LEG_META) - break; + if (!full_body && (joint == XR_FULL_BODY_JOINT_HIPS_META || joint >= XR_FULL_BODY_JOINT_LEFT_UPPER_LEG_META)) + continue; + if (!hip && joint == XR_FULL_BODY_JOINT_HIPS_META) + continue; auto joint_pose = joints[joint]; wivrn::from_headset::body_tracking::pose pose{ @@ -121,7 +125,7 @@ std::optional> locate_spaces(XrTime time, XrSpace reference); From ecfda51852fb5f0a148def6c830afdfaf0920893 Mon Sep 17 00:00:00 2001 From: Sapphire Date: Wed, 4 Jun 2025 00:07:54 -0500 Subject: [PATCH 52/85] Don't forward shoulder joints --- client/xr/fb_body_tracker.h | 2 -- client/xr/pico_body_tracker.h | 2 -- 2 files changed, 4 deletions(-) diff --git a/client/xr/fb_body_tracker.h b/client/xr/fb_body_tracker.h index 4d980d11..b1c67345 100644 --- a/client/xr/fb_body_tracker.h +++ b/client/xr/fb_body_tracker.h @@ -47,8 +47,6 @@ public: static constexpr std::array joint_whitelist{ XR_FULL_BODY_JOINT_HIPS_META, XR_FULL_BODY_JOINT_CHEST_META, - XR_FULL_BODY_JOINT_LEFT_ARM_UPPER_META, - XR_FULL_BODY_JOINT_RIGHT_ARM_UPPER_META, XR_FULL_BODY_JOINT_LEFT_ARM_LOWER_META, XR_FULL_BODY_JOINT_RIGHT_ARM_LOWER_META, diff --git a/client/xr/pico_body_tracker.h b/client/xr/pico_body_tracker.h index dbdfc03c..96c1944f 100644 --- a/client/xr/pico_body_tracker.h +++ b/client/xr/pico_body_tracker.h @@ -39,8 +39,6 @@ class pico_body_tracker : public utils::handle Date: Wed, 4 Jun 2025 13:47:16 -0500 Subject: [PATCH 53/85] Log when unknown input name is requested for generic trackers --- server/driver/wivrn_generic_tracker.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/server/driver/wivrn_generic_tracker.cpp b/server/driver/wivrn_generic_tracker.cpp index 688a6652..8d5a39d9 100644 --- a/server/driver/wivrn_generic_tracker.cpp +++ b/server/driver/wivrn_generic_tracker.cpp @@ -19,6 +19,7 @@ */ #include "wivrn_generic_tracker.h" +#include "util/u_logging.h" #include "utils/method.h" #include "wivrn_session.h" @@ -131,6 +132,20 @@ wivrn_generic_tracker::wivrn_generic_tracker(int index, xrt_device * hmd, wivrn_ input_count = 1; } +#define XRT_INPUT_NAME_CASE(NAME, VALUE) \ + case VALUE: \ + return #NAME; + +const char * input_name_str(xrt_input_name name) +{ + switch (name) + { + XRT_INPUT_LIST(XRT_INPUT_NAME_CASE) + default: + return "Unknown"; + } +} + xrt_result_t wivrn_generic_tracker::update_inputs() { return XRT_SUCCESS; @@ -147,6 +162,8 @@ xrt_result_t wivrn_generic_tracker::get_tracked_pose(xrt_input_name name, int64_ cnx.add_predict_offset(extrapolation_time); return XRT_SUCCESS; } + + U_LOG_D("Unknown input name %s", input_name_str(name)); return XRT_ERROR_NOT_IMPLEMENTED; } From 7bf24565d9b64b829fe1364a3eb81b7b7bd31825 Mon Sep 17 00:00:00 2001 From: Sapphire Date: Wed, 4 Jun 2025 14:18:29 -0500 Subject: [PATCH 54/85] Set orientation/position tracked bits when valid for FB body tracking Quest runtime appears to not set these bits even while the orientation and position are being tracked. --- client/xr/fb_body_tracker.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/client/xr/fb_body_tracker.cpp b/client/xr/fb_body_tracker.cpp index 3d5ee37f..2472863f 100644 --- a/client/xr/fb_body_tracker.cpp +++ b/client/xr/fb_body_tracker.cpp @@ -117,13 +117,15 @@ std::optional Date: Thu, 5 Jun 2025 00:26:03 -0500 Subject: [PATCH 55/85] Disable generic trackers when no poses have been requested on server --- server/driver/wivrn_generic_tracker.cpp | 12 +++++----- server/driver/wivrn_generic_tracker.h | 1 + server/driver/wivrn_session.cpp | 30 +++++++++++++++++-------- server/driver/wivrn_session.h | 5 ++++- 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/server/driver/wivrn_generic_tracker.cpp b/server/driver/wivrn_generic_tracker.cpp index 8d5a39d9..379e17dc 100644 --- a/server/driver/wivrn_generic_tracker.cpp +++ b/server/driver/wivrn_generic_tracker.cpp @@ -119,9 +119,10 @@ wivrn_generic_tracker::wivrn_generic_tracker(int index, xrt_device * hmd, wivrn_ .get_tracked_pose = method_pointer<&wivrn_generic_tracker::get_tracked_pose>, .destroy = [](xrt_device *) {}, }, - cnx(cnx) + cnx(cnx), + index(index) { - auto unique_name = std::format("WiVRn Generic Tracker #{}", index); + auto unique_name = std::format("WiVRn Generic Tracker #{}", index + 1); strlcpy(str, unique_name.c_str(), std::size(str)); strlcpy(serial, unique_name.c_str(), std::size(serial)); @@ -158,7 +159,7 @@ xrt_result_t wivrn_generic_tracker::get_tracked_pose(xrt_input_name name, int64_ { std::tie(extrapolation_time, *res) = poses.get_pose_at(at_timestamp_ns); - cnx.set_enabled(to_headset::tracking_control::id::generic_tracker, true); + cnx.set_tracker_enabled(index, true); cnx.add_predict_offset(extrapolation_time); return XRT_SUCCESS; } @@ -169,8 +170,7 @@ xrt_result_t wivrn_generic_tracker::get_tracked_pose(xrt_input_name name, int64_ void wivrn_generic_tracker::update_tracking(const from_headset::body_tracking & tracking, const from_headset::body_tracking::pose & pose, const clock_offset & offset) { - // TODO: Right now we ignore the return value, because if the pose of one of the trackers is not requested for a while, all of them get deactivated, which isn't ideal. - poses.update_tracking(tracking.production_timestamp, tracking.timestamp, pose, offset); - // cnx.set_enabled(to_headset::tracking_control::id::generic_tracker, false); + if (!poses.update_tracking(tracking.production_timestamp, tracking.timestamp, pose, offset)) + cnx.set_tracker_enabled(index, false); } } // namespace wivrn \ No newline at end of file diff --git a/server/driver/wivrn_generic_tracker.h b/server/driver/wivrn_generic_tracker.h index dcf2675f..8cb974c3 100644 --- a/server/driver/wivrn_generic_tracker.h +++ b/server/driver/wivrn_generic_tracker.h @@ -47,6 +47,7 @@ class wivrn_generic_tracker : public xrt_device xrt_input pose_input; wivrn_session & cnx; + int index; public: using base = xrt_device; diff --git a/server/driver/wivrn_session.cpp b/server/driver/wivrn_session.cpp index d47f65a0..8bdad43b 100644 --- a/server/driver/wivrn_session.cpp +++ b/server/driver/wivrn_session.cpp @@ -41,6 +41,7 @@ #include "wivrn_packets.h" #include "xrt/xrt_device.h" #include "xrt/xrt_session.h" +#include #include #include #include @@ -127,8 +128,10 @@ bool wivrn::tracking_control_t::set_enabled(to_headset::tracking_control::id id, { std::lock_guard lock(mutex); bool changed = enabled != this->enabled[size_t(id)]; - if (changed) - U_LOG_I("%s tracking: %s", std::string(magic_enum::enum_name(id)).c_str(), enabled ? "enabled" : "disabled"); + if (!changed) + return false; + + U_LOG_I("%s tracking: %s", std::string(magic_enum::enum_name(id)).c_str(), enabled ? "enabled" : "disabled"); this->enabled[size_t(id)] = enabled; return changed; } @@ -222,17 +225,18 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr connection xdevs[xdev_count++] = htc_face_tracker.get(); } - if (auto num_trackers = get_info().num_generic_trackers; num_trackers > 0) + num_generic_trackers = get_info().num_generic_trackers; + enabled_trackers.fill(false); + if (num_generic_trackers > 0) { - generic_trackers.clear(); - generic_trackers.reserve(num_trackers); - U_LOG_I("Creating %d generic trackers", num_trackers); + U_LOG_I("Creating %d generic trackers", num_generic_trackers); - for (int i = 1; i <= num_trackers; ++i) + for (int i = 0; i < num_generic_trackers; ++i) { auto dev = std::make_unique(i, &hmd, *this); xdevs[xdev_count++] = dev.get(); - generic_trackers.push_back(std::move(dev)); + generic_trackers[i] = std::move(dev); + enabled_trackers[i] = true; } } @@ -452,7 +456,7 @@ void wivrn_session::operator()(from_headset::body_tracking && body_tracking) { auto offset = offset_est.get_offset(); - for (int i = 0; i < generic_trackers.size(); i++) + for (int i = 0; i < num_generic_trackers; i++) { auto pose = body_tracking.poses ? body_tracking.poses->at(i) : from_headset::body_tracking::pose{ .pose = {}, @@ -507,6 +511,14 @@ void wivrn_session::set_enabled(device_id id, bool enabled) if (tracking_control.set_enabled(to_tracking_control(id), enabled) and enabled) tracking_control.send(*connection, true); } +void wivrn_session::set_tracker_enabled(int index, bool enabled) +{ + assert(index < std::size(enabled_trackers)); + enabled_trackers[index] = enabled; + bool keep_active = std::ranges::any_of(enabled_trackers, [](bool b) { return b; }); + if (tracking_control.set_enabled(to_headset::tracking_control::id::generic_tracker, keep_active)) + tracking_control.send(*connection, true); +} void wivrn_session::operator()(from_headset::feedback && feedback) { diff --git a/server/driver/wivrn_session.h b/server/driver/wivrn_session.h index a2e70ae4..1c6a234a 100644 --- a/server/driver/wivrn_session.h +++ b/server/driver/wivrn_session.h @@ -110,8 +110,10 @@ class wivrn_session : public xrt_system_devices std::unique_ptr eye_tracker; std::unique_ptr fb_face2_tracker; std::unique_ptr htc_face_tracker; + uint32_t num_generic_trackers; + std::array, from_headset::body_tracking::max_tracked_poses> generic_trackers; + std::array enabled_trackers; std::shared_ptr comp_target; - std::vector> generic_trackers; clock_offset_estimator offset_est; @@ -156,6 +158,7 @@ public: void set_enabled(to_headset::tracking_control::id id, bool enabled); void set_enabled(device_id id, bool enabled); + void set_tracker_enabled(int index, bool enabled); void operator()(from_headset::crypto_handshake &&) {} void operator()(from_headset::pin_check_1 &&) {} From 2fc35832b91ee79fd54a61fe7e365dd0d83de840 Mon Sep 17 00:00:00 2001 From: Sapphire Date: Fri, 6 Jun 2025 06:24:38 -0500 Subject: [PATCH 56/85] cleanup --- client/xr/fb_body_tracker.cpp | 12 +++++------- client/xr/pico_body_tracker.cpp | 16 +++++++--------- client/xr/pico_body_tracker.h | 1 - 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/client/xr/fb_body_tracker.cpp b/client/xr/fb_body_tracker.cpp index 2472863f..606e5082 100644 --- a/client/xr/fb_body_tracker.cpp +++ b/client/xr/fb_body_tracker.cpp @@ -67,9 +67,7 @@ void xr::fb_body_tracker::stop() std::optional> xr::fb_body_tracker::locate_spaces(XrTime time, XrSpace reference) { if (!handle) - { return std::nullopt; - } assert(xrLocateBodyJointsFB); @@ -110,24 +108,24 @@ std::optional> xr::pico_body_tracker::locate_spaces(XrTime time, XrSpace reference) { if (!xrLocateBodyJointsBD) - { return std::nullopt; - } XrBodyJointsLocateInfoBD locate_info{ .type = XR_TYPE_BODY_JOINTS_LOCATE_INFO_BD, @@ -67,22 +65,22 @@ std::optional poses{}; for (int i = 0; i < joint_whitelist.size(); i++) { - auto & joint_location = joints[joint_whitelist[i]]; + const auto & joint_loc = joints[joint_whitelist[i]]; wivrn::from_headset::body_tracking::pose pose{ - .pose = joint_location.pose, + .pose = joint_loc.pose, .flags = 0, }; - if (joint_location.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT) + if (joint_loc.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT) pose.flags |= wivrn::from_headset::body_tracking::orientation_valid; - if (joint_location.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT) + if (joint_loc.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT) pose.flags |= wivrn::from_headset::body_tracking::position_valid; - if (joint_location.locationFlags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT) + if (joint_loc.locationFlags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT) pose.flags |= wivrn::from_headset::body_tracking::orientation_tracked; - if (joint_location.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT) + if (joint_loc.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT) pose.flags |= wivrn::from_headset::body_tracking::position_tracked; - poses[i] = std::move(pose); + poses[i] = pose; } return poses; } diff --git a/client/xr/pico_body_tracker.h b/client/xr/pico_body_tracker.h index 96c1944f..3cb0dfbf 100644 --- a/client/xr/pico_body_tracker.h +++ b/client/xr/pico_body_tracker.h @@ -28,7 +28,6 @@ namespace xr { class instance; -class session; XrResult destroy_pico_body_tracker(XrBodyTrackerBD); From 9bb11ae693df85697e2466a2c1fd57a95e3fe58e Mon Sep 17 00:00:00 2001 From: Sapphire Date: Fri, 6 Jun 2025 12:14:48 -0500 Subject: [PATCH 57/85] Change body tracking tooltip --- client/scenes/lobby_gui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index 238a4b3f..a764e275 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -758,7 +758,7 @@ void scenes::lobby::gui_settings() else { if (application::get_fb_body_tracking_supported()) - tooltip(_("Requires 'Hand and body tracking' to be enabled in the Quest movement tracking settings,\notherwise estimated joint positions will be used")); + 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")); else if (application::get_pico_body_tracking_supported()) tooltip(_("Uses the Pico Motion Trackers to track body joint positions")); } From 2f9a46ff91cd6e1627d1e5555629b012edfde2d5 Mon Sep 17 00:00:00 2001 From: Sapphire Date: Sun, 1 Jun 2025 19:09:50 -0500 Subject: [PATCH 58/85] flake: don't strip package --- flake.nix | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index 1121315e..420c349c 100644 --- a/flake.nix +++ b/flake.nix @@ -5,10 +5,11 @@ outputs = inputs@{ nixpkgs, flake-parts, ... }: flake-parts.lib.mkFlake { inherit inputs; } { systems = [ "x86_64-linux" ]; - perSystem = { pkgs, ... }: let + perSystem = { lib, pkgs, ... }: let # Tools used for development work (clangd, clang-format) devTools = with pkgs; [ clang-tools + gdb ]; # Extra build inputs not yet in the nixpkgs recipe. # Should be submitted to nixpkgs on release @@ -17,7 +18,7 @@ sdl2-compat ]; - package = pkgs.wivrn.overrideAttrs (finalAttrs: oldAttrs: { + package = pkgs.enableDebugging (pkgs.wivrn.overrideAttrs (finalAttrs: oldAttrs: { src = ./.; version = "next"; @@ -25,6 +26,8 @@ # We also don't need the check since we read the revision from the monado-rev file. postUnpack = null; + separateDebugInfo = false; + monado = pkgs.applyPatches { inherit (oldAttrs.monado) patches postPatch; # Force a refetch when the monado rev changes. @@ -39,7 +42,11 @@ }; buildInputs = oldAttrs.buildInputs ++ extraBuildInputs; - }); + + cmakeFlags = (oldAttrs.cmakeFlags or [ ]) ++ [ + (lib.cmakeFeature "CMAKE_BUILD_TYPE" "Debug") + ]; + })); in { packages.default = package; devShells.default = package.overrideAttrs (oldAttrs: { @@ -47,4 +54,4 @@ }); }; }; -} \ No newline at end of file +} From fd6435e920a001d0831ec0e3cfd85391320dd398 Mon Sep 17 00:00:00 2001 From: Sapphire Date: Mon, 2 Jun 2025 00:45:28 -0500 Subject: [PATCH 59/85] flake: avoid unnecessary wrapping --- flake.nix | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/flake.nix b/flake.nix index 420c349c..b13ddd01 100644 --- a/flake.nix +++ b/flake.nix @@ -43,6 +43,14 @@ buildInputs = oldAttrs.buildInputs ++ extraBuildInputs; + dontWrapQtApps = true; + + preFixup = '' + wrapQtApp "$out/bin/wivrn-dashboard" \ + --prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ pkgs.vulkan-loader ]} + ''; + postFixup = null; + cmakeFlags = (oldAttrs.cmakeFlags or [ ]) ++ [ (lib.cmakeFeature "CMAKE_BUILD_TYPE" "Debug") ]; From 260fdea64a3ca4180c1253cae47443f39dc0e09e Mon Sep 17 00:00:00 2001 From: Sapphire Date: Fri, 6 Jun 2025 14:29:19 -0500 Subject: [PATCH 60/85] flake: add toktx for android build --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index b13ddd01..fbbd5071 100644 --- a/flake.nix +++ b/flake.nix @@ -10,9 +10,9 @@ devTools = with pkgs; [ clang-tools gdb + ktx-tools ]; # Extra build inputs not yet in the nixpkgs recipe. - # Should be submitted to nixpkgs on release extraBuildInputs = with pkgs; [ # XRT_FEATURE_DEBUG_GUI requires SDL2 sdl2-compat From bfd102831ec3d7106335702307a953c7607610b1 Mon Sep 17 00:00:00 2001 From: Sapphire Date: Sat, 7 Jun 2025 23:07:55 -0500 Subject: [PATCH 61/85] workaround quest runtime bugs --- client/application.cpp | 2 ++ client/scenes/stream_tracking.cpp | 8 +++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/client/application.cpp b/client/application.cpp index e0d30712..ebcca4c2 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -1226,6 +1226,8 @@ void application::initialize() if (fb_body_tracking_supported) { fb_body_tracker = xr_session.create_fb_body_tracker(); + // HACK: always have an active body tracker so the quest runtime doesn't blow up (crash in random functions, controllers not working) + fb_body_tracker.start(false, false); } if (pico_body_tracking_supported) diff --git a/client/scenes/stream_tracking.cpp b/client/scenes/stream_tracking.cpp index 3ad46555..2bfe7d17 100644 --- a/client/scenes/stream_tracking.cpp +++ b/client/scenes/stream_tracking.cpp @@ -272,8 +272,9 @@ void scenes::stream::tracking() if (application::get_fb_body_tracking_supported()) { body_tracking = body_fb; - // We start the tracker on connection because there are togglable settings. - // TODO handle reconnection? + // We start the tracker on connection because there are toggleable settings. + // TODO maybe handle reconnection better, if the settings are changed the tracker count will mismatch and stuff might break + application::get_fb_body_tracker().stop(); application::get_fb_body_tracker().start(config.fb_lower_body, config.fb_hip); } else if (application::get_pico_body_tracking_supported()) @@ -509,9 +510,6 @@ void scenes::stream::tracking() if (face_tracking == from_headset::face_type::pico) application::get_pico_face_tracker().stop(); - - if (body_tracking == body_fb) - application::get_fb_body_tracker().stop(); } void scenes::stream::operator()(to_headset::tracking_control && packet) From b3f3c1c7fc1396701c18afa5e03aa47f0e762e3a Mon Sep 17 00:00:00 2001 From: galister <22305755+galister@users.noreply.github.com> Date: Sun, 8 Jun 2025 17:30:25 +0900 Subject: [PATCH 62/85] fixed foveation: account for asymmetric v-fov --- server/driver/wivrn_foveation.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/server/driver/wivrn_foveation.cpp b/server/driver/wivrn_foveation.cpp index 6e7fd807..e2e9cc94 100644 --- a/server/driver/wivrn_foveation.cpp +++ b/server/driver/wivrn_foveation.cpp @@ -233,9 +233,7 @@ void wivrn_foveation::compute_params( auto angle_x = convergence_angle(views[i].pose.position.x, e.x); tan_center[i].x = angles_to_center(view.x + angle_x, views[i].fov.angleLeft, views[i].fov.angleRight); - - auto offset_y = (views[i].fov.angleDown + views[i].fov.angleUp) / 2; - tan_center[i].y = angles_to_center(-view.y - e.y, views[i].fov.angleUp, views[i].fov.angleDown) + offset_y; + tan_center[i].y = angles_to_center(-view.y - e.y, views[i].fov.angleUp, views[i].fov.angleDown); } } @@ -247,7 +245,10 @@ void wivrn_foveation::compute_params( else params[i].x = {uint16_t(src[i].extent.w)}; if (foveated_height < src[i].extent.h) - fill_param_2d(tan_center[i].y, foveated_height, src[i].extent.h, params[i].y); + { + auto offset_y = (views[i].fov.angleDown + views[i].fov.angleUp) / 2; + fill_param_2d(tan_center[i].y + offset_y, foveated_height, src[i].extent.h, params[i].y); + } else params[i].y = {uint16_t(src[i].extent.h)}; } From 18d1619d200677e5ab163986834acb191a3dcc5c Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sun, 8 Jun 2025 17:57:59 +0200 Subject: [PATCH 63/85] Don't crash on bigger than recommended image --- client/scenes/stream.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index 1f64c129..fdca2bf9 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -882,6 +882,13 @@ void scenes::stream::render(const XrFrameState & frame_state) // defoveate the image auto extents = reprojector->reproject(command_buffer, foveation, image_index); + for (size_t i = 0; i < view_count; ++i) + { + extents[i] = { + .width = std::min(extents[i].width, swapchain.width()), + .height = std::min(extents[i].height, swapchain.height()), + }; + } command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 2); From fedd7917db58c3c2ddbc3a406c792b122f2a2b70 Mon Sep 17 00:00:00 2001 From: mitsuami-megane <173323057+mitsuami-megane@users.noreply.github.com> Date: Tue, 10 Jun 2025 00:17:04 +0900 Subject: [PATCH 64/85] update ja locale --- locale/ja/wivrn-dashboard.po | 26 +++---- locale/ja/wivrn.po | 145 ++++++++++++++++++++++++----------- 2 files changed, 112 insertions(+), 59 deletions(-) diff --git a/locale/ja/wivrn-dashboard.po b/locale/ja/wivrn-dashboard.po index 40f425ba..a1fa1681 100644 --- a/locale/ja/wivrn-dashboard.po +++ b/locale/ja/wivrn-dashboard.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: WiVRn-dashboard\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-05-22 03:31+0900\n" +"POT-Creation-Date: 2025-06-09 19:04+0900\n" "PO-Revision-Date: 2025-04-10 07:14+0900\n" "Last-Translator: Mitsuami Megane \n" "Language-Team: Japanese <>\n" @@ -517,22 +517,22 @@ msgstr "H.265" msgid "AV1" msgstr "AV1" -#: dashboard/qml/SettingsPage.qml:320 +#: dashboard/qml/SettingsPage.qml:319 #, kde-format msgid "Advanced options" msgstr "詳細設定" -#: dashboard/qml/SettingsPage.qml:326 +#: dashboard/qml/SettingsPage.qml:325 #, kde-format msgid "Enable debug window" msgstr "デバッグ・ウィンドウを表示する" -#: dashboard/qml/SettingsPage.qml:333 +#: dashboard/qml/SettingsPage.qml:332 #, kde-format msgid "Enable SteamVR tracked devices support" msgstr "SteamVR・ライトハウス・トラッキング" -#: dashboard/qml/SettingsPage.qml:336 +#: dashboard/qml/SettingsPage.qml:335 #, kde-format msgid "" "Allows the use of lighthouse-based controllers and trackers.\n" @@ -545,44 +545,44 @@ msgstr "" "すべてのデバイスの電源が入ってからHMDを接続しましょう。\n" "キャリブレーションはmotocなどのソフトウェアで行います。" -#: dashboard/qml/SettingsPage.qml:344 +#: dashboard/qml/SettingsPage.qml:343 #, kde-format msgid "Custom adb location" msgstr "特定なADBの場所" -#: dashboard/qml/SettingsPage.qml:355 +#: dashboard/qml/SettingsPage.qml:354 #, kde-format msgid "Adb location:" msgstr "ADBの場所:" -#: dashboard/qml/SettingsPage.qml:364 +#: dashboard/qml/SettingsPage.qml:363 #, kde-format msgctxt "browse a file to choose the adb binary" msgid "Browse" msgstr "検索する" -#: dashboard/qml/SettingsPage.qml:374 +#: dashboard/qml/SettingsPage.qml:373 #, kde-format msgid "Default" msgstr "デフォルト" -#: dashboard/qml/SettingsPage.qml:388 +#: dashboard/qml/SettingsPage.qml:387 #, kde-format msgctxt "set a custom OpenVR compatibility library" msgid "Custom" msgstr "カスタム" -#: dashboard/qml/SettingsPage.qml:393 +#: dashboard/qml/SettingsPage.qml:392 #, kde-format msgid "Disabled" msgstr "無し" -#: dashboard/qml/SettingsPage.qml:401 +#: dashboard/qml/SettingsPage.qml:400 #, kde-format msgid "OpenVR compatibility library:" msgstr "OpenVR実装ライブラリー" -#: dashboard/qml/SettingsPage.qml:427 +#: dashboard/qml/SettingsPage.qml:426 #, kde-format msgid "Library path, excluding bin/linux64/vrclient.so" msgstr "ライブラリーの場所(bin/linux64/vrclient.so 無し)" diff --git a/locale/ja/wivrn.po b/locale/ja/wivrn.po index 6d30b208..a6878f66 100644 --- a/locale/ja/wivrn.po +++ b/locale/ja/wivrn.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: WiVRn 0.16\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-04-20 17:32+0900\n" +"POT-Creation-Date: 2025-06-09 19:04+0900\n" "PO-Revision-Date: 2024-06-20 10:33+0900\n" "Last-Translator: Mitsuami Megane \n" "Language: Japanese\n" @@ -171,12 +171,12 @@ msgstr "最低リフレッシュレート" msgid "Resolution scale" msgstr "解像度" -#: client/scenes/lobby_gui.cpp:666 client/scenes/lobby_gui.cpp:915 +#: client/scenes/lobby_gui.cpp:666 client/scenes/lobby_gui.cpp:967 #, c-format, c++-format msgid "%d%% - {}x{} per eye" msgstr "%d%% - 目あたり{}x{}" -#: client/scenes/lobby_gui.cpp:677 client/scenes/lobby_gui.cpp:926 +#: client/scenes/lobby_gui.cpp:677 client/scenes/lobby_gui.cpp:978 #, c++-format msgid "Resolution larger than {}x{} may not be supported by the headset" msgstr "" @@ -199,7 +199,8 @@ msgid "Enable hand tracking" msgstr "ハンドトラッキングを有効する" #: client/scenes/lobby_gui.cpp:713 client/scenes/lobby_gui.cpp:726 -#: client/scenes/lobby_gui.cpp:739 client/scenes/lobby_gui.cpp:751 +#: client/scenes/lobby_gui.cpp:739 client/scenes/lobby_gui.cpp:756 +#: client/scenes/lobby_gui.cpp:803 msgid "This feature is not supported by your headset" msgstr "デバイスはこの機能をサポートしていません" @@ -211,45 +212,89 @@ msgstr "アイトラッキングを有効する" msgid "Enable face tracking" msgstr "顔トラッキングを有効する" -#: client/scenes/lobby_gui.cpp:744 +#: client/scenes/lobby_gui.cpp:746 +msgid "Enable body tracking" +msgstr "ボディラッキングを有効する" + +#: client/scenes/lobby_gui.cpp:761 +msgid "" +"Requires 'Hand and body tracking' to be enabled in the Quest movement " +"tracking settings,\n" +"otherwise body data will be guessed from controller and headset positions" +msgstr "" +"Quest設定・動きのトラッキング・ジェスチャーコントロールとボディトラッキング" +"を有効する必要がある。\n" +"そうでなければ、トラッキングデータはHMDとコントローラーの情報から推測されることになる。" + +#: client/scenes/lobby_gui.cpp:763 +msgid "Uses the Pico Motion Trackers to track body joint positions" +msgstr "Pico Motion Trackerによるフルボディトラッキング" + +#: client/scenes/lobby_gui.cpp:773 +msgid "Enable lower body tracking" +msgstr "下半身トラッキングを有効する" + +#: client/scenes/lobby_gui.cpp:779 +msgid "" +"Estimate lower body joint positions using Generative Legs\n" +"Requires 'Hand and body tracking' to be enabled in the Quest movement " +"tracking settings" +msgstr "" +"下半身に計算された疑似トラッキングを使用する。" +"Quest設定・動きのトラッキング・ジェスチャーコントロールとボディトラッキング" +"を有効する必要がある。\n" + +#: client/scenes/lobby_gui.cpp:782 +msgid "Enable hip tracking" +msgstr "腰のトラッキングを有効する" + +#: client/scenes/lobby_gui.cpp:788 +msgid "" +"Only takes affect with lower body tracking enabled\n" +"May be desired when using another source of hip tracking" +msgstr "" +"下半身トラッキングが有効な場合に使用可能。" +"腰トラッカーを持ってる方は無効にしましょう。" + +#: client/scenes/lobby_gui.cpp:796 msgid "Enable video passthrough in lobby" msgstr "ロビーでパススルーを有効する" -#: client/scenes/lobby_gui.cpp:754 +#: client/scenes/lobby_gui.cpp:806 msgid "Show performance metrics" msgstr "パフォーマンスグラフを表示する" -#: client/scenes/lobby_gui.cpp:758 +#: client/scenes/lobby_gui.cpp:810 msgid "Overlay can be toggled by pressing both thumbsticks" msgstr "両方のサムスティックを同時に押すことで切り替え可能" -#: client/scenes/lobby_gui.cpp:788 client/scenes/lobby_gui.cpp:796 +#: client/scenes/lobby_gui.cpp:840 client/scenes/lobby_gui.cpp:848 #: client/scenes/stream_stats.cpp:159 msgid "CPU time" msgstr "CPU使用時間" -#: client/scenes/lobby_gui.cpp:792 +#: client/scenes/lobby_gui.cpp:844 msgid "CPU time [ms]" msgstr "CPU使用時間、ミリ秒" -#: client/scenes/lobby_gui.cpp:802 client/scenes/lobby_gui.cpp:810 +#: client/scenes/lobby_gui.cpp:854 client/scenes/lobby_gui.cpp:862 #: client/scenes/stream_stats.cpp:161 msgid "GPU time" msgstr "GPU使用時間" -#: client/scenes/lobby_gui.cpp:806 +#: client/scenes/lobby_gui.cpp:858 msgid "GPU time [ms]" msgstr "GPU使用時間、ミリ秒" -#: client/scenes/lobby_gui.cpp:825 +#: client/scenes/lobby_gui.cpp:877 msgid "OpenXR post-processing" msgstr "OpenXRポストエフェクト" -#: client/scenes/lobby_gui.cpp:829 +#: client/scenes/lobby_gui.cpp:881 msgid "Supersampling" msgstr "スーパーサンプリング" -#: client/scenes/lobby_gui.cpp:849 +#: client/scenes/lobby_gui.cpp:901 msgid "" "Reduce flicker for high contrast edges.\n" "Useful when the input resolution is high compared to the headset display" @@ -257,11 +302,11 @@ msgstr "" "コントラストが高い部分のギザギザを低減する。\n" "ストリームの解像度は、HMDの解像度より高い場合は有用です。" -#: client/scenes/lobby_gui.cpp:854 +#: client/scenes/lobby_gui.cpp:906 msgid "Sharpening" msgstr "シャープ" -#: client/scenes/lobby_gui.cpp:874 +#: client/scenes/lobby_gui.cpp:926 msgid "" "Improve clarity of high contrast edges and counteract blur.\n" "Useful when the input resolution is low compared to the headset display" @@ -269,115 +314,123 @@ msgstr "" "ぼかしを低減し、コントラストが高い部分の鮮明度を向上する。\n" "ストリームの解像度は、HMDの解像度より低い場合に有用です。" -#: client/scenes/lobby_gui.cpp:883 +#: client/scenes/lobby_gui.cpp:935 msgid "Enable Snapdragon Game Super Resolution" msgstr "Snapdragon Game Super Resolutionを有効する" -#: client/scenes/lobby_gui.cpp:891 +#: client/scenes/lobby_gui.cpp:943 msgid "" "On this headset, this setting has been fully superseded by the native " "Sharpening setting above.\n" "Only enable if you know what you're doing." msgstr "" -"この設定は、使用中のHMDでは非推奨です。" -"OpenXRの方法を使用してください。" +"この設定は、使用中のHMDでは非推奨です。OpenXRの方法を使用してください。" -#: client/scenes/lobby_gui.cpp:893 +#: client/scenes/lobby_gui.cpp:945 msgid "" "Client-side upscaling and sharpening, adds a performance cost on the headset" msgstr "" -"HMD側のアップスケーリングやシャープニングを使用する場合、要求性能が上がります。" +"HMD側のアップスケーリングやシャープニングを使用する場合、要求性能が上がりま" +"す。" -#: client/scenes/lobby_gui.cpp:911 +#: client/scenes/lobby_gui.cpp:963 msgid "Upscaling factor" msgstr "アップスケーリング係数" -#: client/scenes/lobby_gui.cpp:930 +#: client/scenes/lobby_gui.cpp:982 msgid "Use edge direction" msgstr "エッジ方向を使用する" -#: client/scenes/lobby_gui.cpp:936 +#: client/scenes/lobby_gui.cpp:988 msgid "Adds an additional performance cost" msgstr "HMDに対する要求性能が上がります。" -#: client/scenes/lobby_gui.cpp:941 +#: client/scenes/lobby_gui.cpp:993 msgid "Edge threshold" msgstr "エッジのしきい値" -#: client/scenes/lobby_gui.cpp:948 client/scenes/lobby_gui.cpp:957 +#: client/scenes/lobby_gui.cpp:1000 client/scenes/lobby_gui.cpp:1009 #, c++-format msgid "Recommended: {:.1f}" msgstr "推奨値:{:.1f}" -#: client/scenes/lobby_gui.cpp:951 +#: client/scenes/lobby_gui.cpp:1003 msgid "Edge sharpness" msgstr "エッジのシャープ" -#: client/scenes/lobby_gui.cpp:1045 client/scenes/lobby_gui.cpp:1691 +#: client/scenes/lobby_gui.cpp:1097 client/scenes/lobby_gui.cpp:1753 msgid "Licenses" msgstr "ライセンス" -#: client/scenes/lobby_gui.cpp:1384 +#: client/scenes/lobby_gui.cpp:1436 msgid "Microphone is enabled" msgstr "マイクは有効です" -#: client/scenes/lobby_gui.cpp:1385 +#: client/scenes/lobby_gui.cpp:1437 msgid "Microphone is disabled" msgstr "マイクは無効です" -#: client/scenes/lobby_gui.cpp:1394 +#: client/scenes/lobby_gui.cpp:1446 msgid "Hand tracking is enabled" msgstr "ハンドトラッキングは有効です" -#: client/scenes/lobby_gui.cpp:1395 +#: client/scenes/lobby_gui.cpp:1447 msgid "Hand tracking is disabled" msgstr "ハンドラッキングは無効です" -#: client/scenes/lobby_gui.cpp:1404 +#: client/scenes/lobby_gui.cpp:1456 msgid "Eye tracking is enabled" msgstr "アイトラッキングは有効です" -#: client/scenes/lobby_gui.cpp:1405 +#: client/scenes/lobby_gui.cpp:1457 msgid "Eye tracking is disabled" msgstr "アイトラッキングは無効です" -#: client/scenes/lobby_gui.cpp:1415 client/scenes/lobby_gui.cpp:1426 +#: client/scenes/lobby_gui.cpp:1467 client/scenes/lobby_gui.cpp:1478 msgid "Face tracking is enabled" msgstr "顔トラッキングは有効です" -#: client/scenes/lobby_gui.cpp:1416 client/scenes/lobby_gui.cpp:1427 +#: client/scenes/lobby_gui.cpp:1468 client/scenes/lobby_gui.cpp:1479 msgid "Face tracking is disabled" msgstr "フェーストラッキングは無効です" -#: client/scenes/lobby_gui.cpp:1444 +#: client/scenes/lobby_gui.cpp:1489 +msgid "Body tracking is enabled" +msgstr "ボディトラッキングは有効です" + +#: client/scenes/lobby_gui.cpp:1490 +msgid "Body tracking is disabled" +msgstr "ボディトラッキングは無効です" + +#: client/scenes/lobby_gui.cpp:1506 msgid "Add server" msgstr "サーバーを追加する" -#: client/scenes/lobby_gui.cpp:1673 +#: client/scenes/lobby_gui.cpp:1735 msgid "Server list" msgstr "サーバー" -#: client/scenes/lobby_gui.cpp:1676 +#: client/scenes/lobby_gui.cpp:1738 msgid "Settings" msgstr "設定" -#: client/scenes/lobby_gui.cpp:1679 +#: client/scenes/lobby_gui.cpp:1741 msgid "Post-processing" msgstr "ポストエフェクト" -#: client/scenes/lobby_gui.cpp:1683 +#: client/scenes/lobby_gui.cpp:1745 msgid "Debug" msgstr "デバッグ" -#: client/scenes/lobby_gui.cpp:1688 +#: client/scenes/lobby_gui.cpp:1750 msgid "About" msgstr "WiVRnについて" -#: client/scenes/lobby_gui.cpp:1694 +#: client/scenes/lobby_gui.cpp:1756 msgid "Exit" msgstr "完了" -#: client/scenes/lobby_gui.cpp:1708 +#: client/scenes/lobby_gui.cpp:1770 msgid "" "Press A or X or put your palm up\n" "to move the main window" @@ -385,7 +438,7 @@ msgstr "" "ウィンドウを移動するには、手のひらを上に向けるか、\n" "AまたはBボタンを押しましょう" -#: client/scenes/lobby_gui.cpp:1710 +#: client/scenes/lobby_gui.cpp:1772 msgid "Press A or X to move the main window" msgstr "AまたはXボタンを押してウィンドウを移動" From 24c38e2a024f29db15900ea413ca88196aa04abf Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Mon, 9 Jun 2025 19:26:30 +0200 Subject: [PATCH 65/85] Move assert in body tracker destructor --- client/xr/fb_body_tracker.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/xr/fb_body_tracker.cpp b/client/xr/fb_body_tracker.cpp index 606e5082..efe40c9c 100644 --- a/client/xr/fb_body_tracker.cpp +++ b/client/xr/fb_body_tracker.cpp @@ -58,10 +58,12 @@ void xr::fb_body_tracker::start(bool full_body, bool hip) } void xr::fb_body_tracker::stop() { - assert(xrDestroyBodyTrackerFB); full_body = false; if (handle) + { + assert(xrDestroyBodyTrackerFB); CHECK_XR(xrDestroyBodyTrackerFB(std::exchange(handle, nullptr))); + } } std::optional> xr::fb_body_tracker::locate_spaces(XrTime time, XrSpace reference) From 09ff9abba879c367af5131ccc29d33707bef59a7 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Mon, 9 Jun 2025 19:26:55 +0200 Subject: [PATCH 66/85] silence locale error --- locale/ja/wivrn.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locale/ja/wivrn.po b/locale/ja/wivrn.po index a6878f66..ecc870e1 100644 --- a/locale/ja/wivrn.po +++ b/locale/ja/wivrn.po @@ -242,7 +242,7 @@ msgid "" msgstr "" "下半身に計算された疑似トラッキングを使用する。" "Quest設定・動きのトラッキング・ジェスチャーコントロールとボディトラッキング" -"を有効する必要がある。\n" +"を有効する必要がある。" #: client/scenes/lobby_gui.cpp:782 msgid "Enable hip tracking" From 810d3e9af3dc41a980894474999abf6b2f067b53 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Mon, 9 Jun 2025 19:46:13 +0200 Subject: [PATCH 67/85] fix newline in ja translation --- locale/ja/wivrn.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locale/ja/wivrn.po b/locale/ja/wivrn.po index ecc870e1..70b53518 100644 --- a/locale/ja/wivrn.po +++ b/locale/ja/wivrn.po @@ -240,7 +240,7 @@ msgid "" "Requires 'Hand and body tracking' to be enabled in the Quest movement " "tracking settings" msgstr "" -"下半身に計算された疑似トラッキングを使用する。" +"下半身に計算された疑似トラッキングを使用する。\n" "Quest設定・動きのトラッキング・ジェスチャーコントロールとボディトラッキング" "を有効する必要がある。" From cc8092dd90f570370bff5f2d71ab9be8127463f4 Mon Sep 17 00:00:00 2001 From: Sapphire Date: Tue, 10 Jun 2025 00:54:37 -0500 Subject: [PATCH 68/85] Cleanup body tracking --- client/application.cpp | 2 -- client/scenes/stream.cpp | 11 +---------- client/scenes/stream_tracking.cpp | 5 +++-- client/xr/fb_body_tracker.cpp | 27 +++++++++++++++++++-------- client/xr/fb_body_tracker.h | 2 ++ client/xr/pico_body_tracker.cpp | 7 ++++--- 6 files changed, 29 insertions(+), 25 deletions(-) diff --git a/client/application.cpp b/client/application.cpp index ebcca4c2..e0d30712 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -1226,8 +1226,6 @@ void application::initialize() if (fb_body_tracking_supported) { fb_body_tracker = xr_session.create_fb_body_tracker(); - // HACK: always have an active body tracker so the quest runtime doesn't blow up (crash in random functions, controllers not working) - fb_body_tracker.start(false, false); } if (pico_body_tracking_supported) diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index fdca2bf9..c4a0aa88 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -229,16 +229,7 @@ std::shared_ptr scenes::stream::create(std::unique_ptr #include -static_assert(xr::pico_body_tracker::joint_whitelist.size() <= wivrn::from_headset::body_tracking::max_tracked_poses); +static_assert(xr::fb_body_tracker::joint_whitelist.size() <= wivrn::from_headset::body_tracking::max_tracked_poses); + +std::vector xr::fb_body_tracker::get_whitelisted_joints(bool full_body, bool hip) +{ + auto whitelisted_joints = std::ranges::filter_view(xr::fb_body_tracker::joint_whitelist, [=](auto joint) { + if (!full_body && (joint == XR_FULL_BODY_JOINT_HIPS_META || joint >= XR_FULL_BODY_JOINT_LEFT_UPPER_LEG_META)) + return false; + if (!hip && joint == XR_FULL_BODY_JOINT_HIPS_META) + return false; + + return true; + }); + return {whitelisted_joints.begin(), whitelisted_joints.end()}; +} xr::fb_body_tracker::fb_body_tracker(instance & inst, session & s) : s(s) @@ -55,10 +69,13 @@ void xr::fb_body_tracker::start(bool full_body, bool hip) // Enable IOBT. CHECK_XR(xrRequestBodyTrackingFidelityMETA(handle, XR_BODY_TRACKING_FIDELITY_HIGH_META)); + + whitelisted_joints = get_whitelisted_joints(full_body, hip); } void xr::fb_body_tracker::stop() { full_body = false; + hip = false; if (handle) { assert(xrDestroyBodyTrackerFB); @@ -102,14 +119,8 @@ std::optional poses{}; int num_poses = 0; - for (int i = 0; i < joint_whitelist.size(); i++) + for (auto joint: whitelisted_joints) { - auto joint = joint_whitelist[i]; - if (!full_body && (joint == XR_FULL_BODY_JOINT_HIPS_META || joint >= XR_FULL_BODY_JOINT_LEFT_UPPER_LEG_META)) - continue; - if (!hip && joint == XR_FULL_BODY_JOINT_HIPS_META) - continue; - const auto & joint_loc = joints[joint]; wivrn::from_headset::body_tracking::pose pose{ .pose = joint_loc.pose, diff --git a/client/xr/fb_body_tracker.h b/client/xr/fb_body_tracker.h index b1c67345..70715ec3 100644 --- a/client/xr/fb_body_tracker.h +++ b/client/xr/fb_body_tracker.h @@ -42,6 +42,7 @@ class fb_body_tracker bool full_body{}; bool hip{}; + std::vector whitelisted_joints{}; public: static constexpr std::array joint_whitelist{ @@ -56,6 +57,7 @@ public: XR_FULL_BODY_JOINT_LEFT_FOOT_TRANSVERSE_META, XR_FULL_BODY_JOINT_RIGHT_FOOT_TRANSVERSE_META, }; + static std::vector get_whitelisted_joints(bool full_body, bool hip); fb_body_tracker() = default; fb_body_tracker(instance & inst, session & s); diff --git a/client/xr/pico_body_tracker.cpp b/client/xr/pico_body_tracker.cpp index 5f6a7bb6..983bdc7e 100644 --- a/client/xr/pico_body_tracker.cpp +++ b/client/xr/pico_body_tracker.cpp @@ -63,9 +63,10 @@ std::optional poses{}; - for (int i = 0; i < joint_whitelist.size(); i++) + int num_poses = 0; + for (auto joint: joint_whitelist) { - const auto & joint_loc = joints[joint_whitelist[i]]; + const auto & joint_loc = joints[joint]; wivrn::from_headset::body_tracking::pose pose{ .pose = joint_loc.pose, .flags = 0, @@ -80,7 +81,7 @@ std::optional Date: Tue, 10 Jun 2025 11:26:32 +0200 Subject: [PATCH 69/85] fix vulkan video conformance issues --- server/encoder/video_encoder_vulkan.cpp | 7 ++++--- server/encoder/video_encoder_vulkan.h | 5 +++-- server/encoder/video_encoder_vulkan_h264.cpp | 7 ++++--- server/encoder/video_encoder_vulkan_h264.h | 3 ++- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/server/encoder/video_encoder_vulkan.cpp b/server/encoder/video_encoder_vulkan.cpp index ca2e0088..f96f42d7 100644 --- a/server/encoder/video_encoder_vulkan.cpp +++ b/server/encoder/video_encoder_vulkan.cpp @@ -55,11 +55,12 @@ vk::VideoFormatPropertiesKHR wivrn::video_encoder_vulkan::select_video_format( wivrn::video_encoder_vulkan::video_encoder_vulkan( wivrn_vk_bundle & vk, vk::Rect2D rect, - vk::VideoEncodeCapabilitiesKHR in_encode_caps, + const vk::VideoCapabilitiesKHR & video_caps, + const vk::VideoEncodeCapabilitiesKHR & in_encode_caps, float fps, uint8_t stream_idx, const encoder_settings & settings) : - video_encoder(stream_idx, settings.channels, settings.bitrate_multiplier, true), vk(vk), encode_caps(patch_capabilities(in_encode_caps)), rect(rect) + video_encoder(stream_idx, settings.channels, settings.bitrate_multiplier, true), vk(vk), encode_caps(patch_capabilities(in_encode_caps)), rect(rect), num_dpb_slots(video_caps.maxDpbSlots) { // Initialize Rate control U_LOG_D("Supported rate control modes: %s", vk::to_string(encode_caps.rateControlModes).c_str()); @@ -211,7 +212,7 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca .maxCodedExtent = rect.extent, .referencePictureFormat = reference_picture_format.format, .maxDpbSlots = num_dpb_slots, - .maxActiveReferencePictures = uint32_t(num_dpb_slots - 1), + .maxActiveReferencePictures = 2, .pStdHeaderVersion = &std_header_version, }); diff --git a/server/encoder/video_encoder_vulkan.h b/server/encoder/video_encoder_vulkan.h index b111eea8..a311e0db 100644 --- a/server/encoder/video_encoder_vulkan.h +++ b/server/encoder/video_encoder_vulkan.h @@ -82,12 +82,13 @@ class video_encoder_vulkan : public video_encoder vk::VideoEncodeRateControlLayerInfoKHR rate_control_layer; protected: - const uint8_t num_dpb_slots = 16; + const uint8_t num_dpb_slots; std::optional rate_control; video_encoder_vulkan(wivrn_vk_bundle & vk, vk::Rect2D rect, - vk::VideoEncodeCapabilitiesKHR encode_caps, + const vk::VideoCapabilitiesKHR & video_caps, + const vk::VideoEncodeCapabilitiesKHR & encode_caps, float fps, uint8_t stream_idx, const encoder_settings & settings); diff --git a/server/encoder/video_encoder_vulkan_h264.cpp b/server/encoder/video_encoder_vulkan_h264.cpp index 079a29a6..33ea3a38 100644 --- a/server/encoder/video_encoder_vulkan_h264.cpp +++ b/server/encoder/video_encoder_vulkan_h264.cpp @@ -71,11 +71,12 @@ static StdVideoH264LevelIdc compute_level(const StdVideoH264SequenceParameterSet wivrn::video_encoder_vulkan_h264::video_encoder_vulkan_h264( wivrn_vk_bundle & vk, vk::Rect2D rect, - vk::VideoEncodeCapabilitiesKHR encode_caps, + const vk::VideoCapabilitiesKHR & video_caps, + const vk::VideoEncodeCapabilitiesKHR & encode_caps, float fps, uint8_t stream_idx, const encoder_settings & settings) : - video_encoder_vulkan(vk, rect, encode_caps, fps, stream_idx, settings), + video_encoder_vulkan(vk, rect, video_caps, encode_caps, fps, stream_idx, settings), sps{ .flags = { @@ -191,7 +192,7 @@ std::unique_ptr wivrn::video_encoder_vulkan_h2 vk::VideoEncodeCapabilitiesKHR, vk::VideoEncodeH264CapabilitiesKHR>(video_profile_info.get()); - std::unique_ptr self(new video_encoder_vulkan_h264(vk, rect, encode_caps, fps, stream_idx, settings)); + std::unique_ptr self(new video_encoder_vulkan_h264(vk, rect, video_caps, encode_caps, fps, stream_idx, settings)); vk::VideoEncodeH264SessionParametersAddInfoKHR h264_add_info{}; h264_add_info.setStdSPSs(self->sps); diff --git a/server/encoder/video_encoder_vulkan_h264.h b/server/encoder/video_encoder_vulkan_h264.h index 2ff5653b..df43c11c 100644 --- a/server/encoder/video_encoder_vulkan_h264.h +++ b/server/encoder/video_encoder_vulkan_h264.h @@ -49,7 +49,8 @@ class video_encoder_vulkan_h264 : public video_encoder_vulkan video_encoder_vulkan_h264(wivrn_vk_bundle & vk, vk::Rect2D rect, - vk::VideoEncodeCapabilitiesKHR encode_caps, + const vk::VideoCapabilitiesKHR & video_caps, + const vk::VideoEncodeCapabilitiesKHR & encode_caps, float fps, uint8_t stream_idx, const encoder_settings & settings); From caa2219a99e00b9332a5b312a9be854b4829e1b9 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sat, 7 Jun 2025 11:35:22 +0200 Subject: [PATCH 70/85] Rebuild on monado-rev change --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index aaf7dd5b..6771e75f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -284,6 +284,7 @@ FetchContent_Declare(uni-algo EXCLUDE_FROM_ALL SYSTEM URL https://github.co URL_HASH SHA256=f2a1539cd8635bc6088d05144a73ecfe7b4d74ee0361fabed6f87f9f19e74ca9) file(GLOB MONADO_PATCHES CONFIGURE_DEPENDS patches/monado/*) +set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS monado-rev) file(READ monado-rev MONADO_REV) # Server dependencies FetchContent_Declare(monado From 80622e16e60a2e6ff7af4909c57254a1d27b0593 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sat, 7 Jun 2025 11:40:46 +0200 Subject: [PATCH 71/85] Update monado git url --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6771e75f..89df11c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -288,7 +288,7 @@ set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS monado-rev) file(READ monado-rev MONADO_REV) # Server dependencies FetchContent_Declare(monado - GIT_REPOSITORY https://gitlab.freedesktop.org/monado/monado + GIT_REPOSITORY https://gitlab.freedesktop.org/monado/monado.git # The flatpak manifest is updated automatically GIT_TAG ${MONADO_REV} PATCH_COMMAND ${CMAKE_CURRENT_LIST_DIR}/patches/apply.sh ${MONADO_PATCHES} From 629f26acd7e9e18ed348fccf6ff28c128481b6e7 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sat, 7 Jun 2025 11:58:02 +0200 Subject: [PATCH 72/85] Ignore newline in monado-rev --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 89df11c1..94cafdf2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -285,7 +285,7 @@ FetchContent_Declare(uni-algo EXCLUDE_FROM_ALL SYSTEM URL https://github.co file(GLOB MONADO_PATCHES CONFIGURE_DEPENDS patches/monado/*) set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS monado-rev) -file(READ monado-rev MONADO_REV) +file(STRINGS monado-rev MONADO_REV) # Server dependencies FetchContent_Declare(monado GIT_REPOSITORY https://gitlab.freedesktop.org/monado/monado.git From d065229cb7b427cfe041201eb308bbc61441fb9a Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sat, 7 Jun 2025 12:16:20 +0200 Subject: [PATCH 73/85] update monado --- monado-rev | 2 +- ...001-c-multi-early-wake-of-compositor.patch | 2 +- ...02-ipc-server-Always-listen-to-stdin.patch | 2 +- .../monado/0003-Use-extern-socket-fd.patch | 2 +- ...Add-storage-usage-to-distortion-mesh.patch | 2 +- ...vironment-blend-mode-selection-logic.patch | 2 +- .../0006-Convert-to-YCbCr-in-Monado.patch | 2 +- .../0007-store-alpha-channel-in-layer-1.patch | 2 +- ...t-oxr-bind-to-dynamic-role-s-profile.patch | 6 +-- ...main-allow-custom-pacing-app-factory.patch | 2 +- .../0010-st-oxr-forward-0-refresh-rate.patch | 4 +- ...tortion-with-pixel-aligned-foveation.patch | 2 +- server/driver/wivrn_controller.cpp | 8 ++-- server/driver/wivrn_eye_tracker.cpp | 41 +++++++++---------- server/driver/wivrn_fb_face2_tracker.cpp | 15 ++++--- server/driver/wivrn_generic_tracker.cpp | 8 ++-- server/driver/wivrn_hmd.cpp | 8 ++-- server/driver/wivrn_htc_face_tracker.cpp | 23 +++++++---- server/driver/wivrn_session.cpp | 2 +- 19 files changed, 75 insertions(+), 60 deletions(-) diff --git a/monado-rev b/monado-rev index f4e7a1ab..2e25f8a6 100644 --- a/monado-rev +++ b/monado-rev @@ -1 +1 @@ -2a6932d46dad9aa957205e8a47ec2baa33041076 \ No newline at end of file +bd9a43c9d1a43d2ddece158d98387a7c9b872c6b diff --git a/patches/monado/0001-c-multi-early-wake-of-compositor.patch b/patches/monado/0001-c-multi-early-wake-of-compositor.patch index 81ae48b4..e7a959aa 100644 --- a/patches/monado/0001-c-multi-early-wake-of-compositor.patch +++ b/patches/monado/0001-c-multi-early-wake-of-compositor.patch @@ -1,4 +1,4 @@ -From 75d2fe061edd2a268ea9f5fbedc90efd8ffea519 Mon Sep 17 00:00:00 2001 +From 1fb49a24efe49e99776ff84bf72af4124b466b8c Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Tue, 22 Oct 2024 15:23:19 +0200 Subject: [PATCH 01/11] c/multi: early wake of compositor diff --git a/patches/monado/0002-ipc-server-Always-listen-to-stdin.patch b/patches/monado/0002-ipc-server-Always-listen-to-stdin.patch index aa92ea9a..223d012d 100644 --- a/patches/monado/0002-ipc-server-Always-listen-to-stdin.patch +++ b/patches/monado/0002-ipc-server-Always-listen-to-stdin.patch @@ -1,4 +1,4 @@ -From 3a8d64c0f569425e2f07b4c2a7803c9bfbc224df Mon Sep 17 00:00:00 2001 +From 0bbc60f44d226a4da375bbca774ddb6804815ad9 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Tue, 2 Apr 2024 17:14:42 +0200 Subject: [PATCH 02/11] ipc/server: Always listen to stdin diff --git a/patches/monado/0003-Use-extern-socket-fd.patch b/patches/monado/0003-Use-extern-socket-fd.patch index 91dac0c2..a2dc1cb6 100644 --- a/patches/monado/0003-Use-extern-socket-fd.patch +++ b/patches/monado/0003-Use-extern-socket-fd.patch @@ -1,4 +1,4 @@ -From 1a8f4aada945314ac852b19ce20c2ed0345f5bb2 Mon Sep 17 00:00:00 2001 +From 32acb282e86e85c24c276a8b55d948b09fe77f13 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Tue, 8 Oct 2024 22:13:15 +0200 Subject: [PATCH 03/11] Use extern socket fd diff --git a/patches/monado/0004-c-render-Add-storage-usage-to-distortion-mesh.patch b/patches/monado/0004-c-render-Add-storage-usage-to-distortion-mesh.patch index ab7de0cc..ad453507 100644 --- a/patches/monado/0004-c-render-Add-storage-usage-to-distortion-mesh.patch +++ b/patches/monado/0004-c-render-Add-storage-usage-to-distortion-mesh.patch @@ -1,4 +1,4 @@ -From 2f38475c9b51f2d2e92f2fd3d51dcef6d7a53e83 Mon Sep 17 00:00:00 2001 +From e5f9b59f15df9e1902612bec6b038d435e42c5f1 Mon Sep 17 00:00:00 2001 From: galister <3123227-galister@users.noreply.gitlab.com> Date: Mon, 19 Aug 2024 18:51:45 +0900 Subject: [PATCH 04/11] c/render: Add storage usage to distortion mesh diff --git a/patches/monado/0005-change-environment-blend-mode-selection-logic.patch b/patches/monado/0005-change-environment-blend-mode-selection-logic.patch index 1dddb321..34042bd7 100644 --- a/patches/monado/0005-change-environment-blend-mode-selection-logic.patch +++ b/patches/monado/0005-change-environment-blend-mode-selection-logic.patch @@ -1,4 +1,4 @@ -From 15eec19c226eb78cb9bc7ebd0021ab226402245a Mon Sep 17 00:00:00 2001 +From 158d65a9870dedee447e48b63edd7e5539499c30 Mon Sep 17 00:00:00 2001 From: galister <85970-galister@users.noreply.gitlab.freedesktop.org> Date: Sat, 23 Nov 2024 02:42:12 +0900 Subject: [PATCH 05/11] change environment blend mode selection logic diff --git a/patches/monado/0006-Convert-to-YCbCr-in-Monado.patch b/patches/monado/0006-Convert-to-YCbCr-in-Monado.patch index 69665f7c..faa8e6ee 100644 --- a/patches/monado/0006-Convert-to-YCbCr-in-Monado.patch +++ b/patches/monado/0006-Convert-to-YCbCr-in-Monado.patch @@ -1,4 +1,4 @@ -From 06497b57fc56d48611ffc9b6f1bd431141097174 Mon Sep 17 00:00:00 2001 +From 404e894924ea3aea43bcc8a810b452e03a8fb100 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Wed, 11 Sep 2024 22:56:29 +0200 Subject: [PATCH 06/11] Convert to YCbCr in Monado diff --git a/patches/monado/0007-store-alpha-channel-in-layer-1.patch b/patches/monado/0007-store-alpha-channel-in-layer-1.patch index fe6754ae..40f8ea96 100644 --- a/patches/monado/0007-store-alpha-channel-in-layer-1.patch +++ b/patches/monado/0007-store-alpha-channel-in-layer-1.patch @@ -1,4 +1,4 @@ -From 2be6264cd7091d593cfec71b7952ff2409ceae4d Mon Sep 17 00:00:00 2001 +From 39d6494d479f4337dad4108f465d3b62c8f4bc88 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sun, 3 Nov 2024 13:40:00 +0100 Subject: [PATCH 07/11] store alpha channel in layer 1 diff --git a/patches/monado/0008-st-oxr-bind-to-dynamic-role-s-profile.patch b/patches/monado/0008-st-oxr-bind-to-dynamic-role-s-profile.patch index ed9b82ce..ba0bfcae 100644 --- a/patches/monado/0008-st-oxr-bind-to-dynamic-role-s-profile.patch +++ b/patches/monado/0008-st-oxr-bind-to-dynamic-role-s-profile.patch @@ -1,4 +1,4 @@ -From f5f2fafe497c688170e176ee4e47b9d9dce8ab7b Mon Sep 17 00:00:00 2001 +From cbd5dcee4a70e265853c40f5517a7700c521d813 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Wed, 19 Feb 2025 10:13:36 +0100 Subject: [PATCH 08/11] st/oxr: bind to dynamic role's profile @@ -8,10 +8,10 @@ Subject: [PATCH 08/11] st/oxr: bind to dynamic role's profile 1 file changed, 17 insertions(+) diff --git a/src/xrt/state_trackers/oxr/oxr_binding.c b/src/xrt/state_trackers/oxr/oxr_binding.c -index 07378d7b3..83a7b241d 100644 +index ce4c0cca1..8ba94dc55 100644 --- a/src/xrt/state_trackers/oxr/oxr_binding.c +++ b/src/xrt/state_trackers/oxr/oxr_binding.c -@@ -380,6 +380,23 @@ oxr_find_profile_for_device(struct oxr_logger *log, +@@ -488,6 +488,23 @@ oxr_find_profile_for_device(struct oxr_logger *log, return; } diff --git a/patches/monado/0009-c-main-allow-custom-pacing-app-factory.patch b/patches/monado/0009-c-main-allow-custom-pacing-app-factory.patch index 72e86a6d..4b8172f2 100644 --- a/patches/monado/0009-c-main-allow-custom-pacing-app-factory.patch +++ b/patches/monado/0009-c-main-allow-custom-pacing-app-factory.patch @@ -1,4 +1,4 @@ -From a906c4d2bc48306a60cd38ceef7dda9d3c7ab0ab Mon Sep 17 00:00:00 2001 +From b6289de166fc95aea2b350ddb8f3c3ddaacefd99 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Thu, 27 Feb 2025 22:45:36 +0100 Subject: [PATCH 09/11] c/main: allow custom pacing app factory diff --git a/patches/monado/0010-st-oxr-forward-0-refresh-rate.patch b/patches/monado/0010-st-oxr-forward-0-refresh-rate.patch index a00455f9..9fa50e79 100644 --- a/patches/monado/0010-st-oxr-forward-0-refresh-rate.patch +++ b/patches/monado/0010-st-oxr-forward-0-refresh-rate.patch @@ -1,4 +1,4 @@ -From aab3a63932eafc7781d6ebbcbb3e825beb0ef4de Mon Sep 17 00:00:00 2001 +From bcd94f8cdb871a34f16cb236d59734701b125612 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sat, 15 Mar 2025 22:19:48 +0100 Subject: [PATCH 10/11] st/oxr: forward 0 refresh rate @@ -8,7 +8,7 @@ Subject: [PATCH 10/11] st/oxr: forward 0 refresh rate 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/xrt/state_trackers/oxr/oxr_api_session.c b/src/xrt/state_trackers/oxr/oxr_api_session.c -index df8ec96b7..cbc542130 100644 +index b3dac8c8a..27d80be9a 100644 --- a/src/xrt/state_trackers/oxr/oxr_api_session.c +++ b/src/xrt/state_trackers/oxr/oxr_api_session.c @@ -645,15 +645,11 @@ oxr_xrRequestDisplayRefreshRateFB(XrSession session, float displayRefreshRate) diff --git a/patches/monado/0011-Replace-distortion-with-pixel-aligned-foveation.patch b/patches/monado/0011-Replace-distortion-with-pixel-aligned-foveation.patch index 3af6b980..2e612c30 100644 --- a/patches/monado/0011-Replace-distortion-with-pixel-aligned-foveation.patch +++ b/patches/monado/0011-Replace-distortion-with-pixel-aligned-foveation.patch @@ -1,4 +1,4 @@ -From e3efcbec31cfc515be3316d51d9e65bd51f4fe07 Mon Sep 17 00:00:00 2001 +From 223392cfd24edfd937335279b7fb505dcd0c03a0 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Mon, 2 Jun 2025 14:51:11 +0200 Subject: [PATCH 11/11] Replace distortion with pixel-aligned foveation diff --git a/server/driver/wivrn_controller.cpp b/server/driver/wivrn_controller.cpp index f757f604..13668bb7 100644 --- a/server/driver/wivrn_controller.cpp +++ b/server/driver/wivrn_controller.cpp @@ -540,9 +540,11 @@ wivrn_controller::wivrn_controller(int hand_id, .binding_profile_count = std::size(wivrn_binding_profiles), .binding_profiles = wivrn_binding_profiles, .input_count = WIVRN_CONTROLLER_INPUT_COUNT, - .orientation_tracking_supported = true, - .position_tracking_supported = true, - .hand_tracking_supported = cnx->get_info().hand_tracking, + .supported = { + .orientation_tracking = true, + .position_tracking = true, + .hand_tracking = cnx->get_info().hand_tracking, + }, .update_inputs = method_pointer<&wivrn_controller::update_inputs>, .get_tracked_pose = method_pointer<&wivrn_controller::get_tracked_pose>, .get_hand_tracking = method_pointer<&wivrn_controller::get_hand_tracking>, diff --git a/server/driver/wivrn_eye_tracker.cpp b/server/driver/wivrn_eye_tracker.cpp index 4cf427a2..03c330b3 100644 --- a/server/driver/wivrn_eye_tracker.cpp +++ b/server/driver/wivrn_eye_tracker.cpp @@ -52,28 +52,27 @@ static xrt_result_t wivrn_eye_tracker_get_tracked_pose(xrt_device * xdev, } wivrn_eye_tracker::wivrn_eye_tracker(xrt_device * hmd) : - xrt_device{}, gaze(device_id::EYE_GAZE) + xrt_device{ + .name = XRT_DEVICE_EYE_GAZE_INTERACTION, + .device_type = XRT_DEVICE_TYPE_EYE_TRACKER, + .str = "WiVRn Eye Tracker", + .serial = "WiVRn Eye Tracker", + .tracking_origin = hmd->tracking_origin, + .input_count = 1, + .inputs = &gaze_input, + .supported = { + .eye_gaze = true, + }, + .update_inputs = wivrn_eye_tracker_update_inputs, + .get_tracked_pose = wivrn_eye_tracker_get_tracked_pose, + .destroy = wivrn_eye_tracker_destroy, + }, + gaze_input{ + .active = true, + .name = XRT_INPUT_GENERIC_EYE_GAZE_POSE, + }, + gaze(device_id::EYE_GAZE) { - xrt_device * base = this; - base->tracking_origin = hmd->tracking_origin; - - base->update_inputs = wivrn_eye_tracker_update_inputs; - base->get_tracked_pose = wivrn_eye_tracker_get_tracked_pose; - base->destroy = wivrn_eye_tracker_destroy; - name = XRT_DEVICE_EYE_GAZE_INTERACTION; - device_type = XRT_DEVICE_TYPE_EYE_TRACKER; - eye_gaze_supported = true; - - // Print name. - strcpy(str, "WiVRn Eye Tracker"); - strcpy(serial, "WiVRn Eye Tracker"); - - gaze_input.active = true; - gaze_input.name = XRT_INPUT_GENERIC_EYE_GAZE_POSE; - - // Setup input. - inputs = &gaze_input; - input_count = 1; } void wivrn_eye_tracker::update_inputs() diff --git a/server/driver/wivrn_fb_face2_tracker.cpp b/server/driver/wivrn_fb_face2_tracker.cpp index 3b51f28f..1f1095ac 100644 --- a/server/driver/wivrn_fb_face2_tracker.cpp +++ b/server/driver/wivrn_fb_face2_tracker.cpp @@ -45,18 +45,21 @@ wivrn_fb_face2_tracker::wivrn_fb_face2_tracker(xrt_device * hmd, .str = "WiVRn FB v2 Face Tracker", .serial = "WiVRn FB v2 Face Tracker", .tracking_origin = hmd->tracking_origin, - .face_tracking_supported = true, + .input_count = 1, + .inputs = &face_input, + .supported = { + .face_tracking = true, + }, .update_inputs = method_pointer<&wivrn_fb_face2_tracker::update_inputs>, .get_face_tracking = method_pointer<&wivrn_fb_face2_tracker::get_face_tracking>, .destroy = [](xrt_device *) {}, }, + face_input{ + .active = true, + .name = XRT_INPUT_FB_FACE_TRACKING2_VISUAL, + }, cnx(cnx) { - // Setup input. - face_input.name = XRT_INPUT_FB_FACE_TRACKING2_VISUAL; - face_input.active = true; - inputs = &face_input; - input_count = 1; } xrt_result_t wivrn_fb_face2_tracker::update_inputs() diff --git a/server/driver/wivrn_generic_tracker.cpp b/server/driver/wivrn_generic_tracker.cpp index 379e17dc..fde72969 100644 --- a/server/driver/wivrn_generic_tracker.cpp +++ b/server/driver/wivrn_generic_tracker.cpp @@ -113,8 +113,10 @@ wivrn_generic_tracker::wivrn_generic_tracker(int index, xrt_device * hmd, wivrn_ .device_type = XRT_DEVICE_TYPE_GENERIC_TRACKER, .hmd = nullptr, .tracking_origin = hmd->tracking_origin, - .orientation_tracking_supported = true, - .position_tracking_supported = true, + .supported = { + .orientation_tracking = true, + .position_tracking = true, + }, .update_inputs = method_pointer<&wivrn_generic_tracker::update_inputs>, .get_tracked_pose = method_pointer<&wivrn_generic_tracker::get_tracked_pose>, .destroy = [](xrt_device *) {}, @@ -173,4 +175,4 @@ void wivrn_generic_tracker::update_tracking(const from_headset::body_tracking & if (!poses.update_tracking(tracking.production_timestamp, tracking.timestamp, pose, offset)) cnx.set_tracker_enabled(index, false); } -} // namespace wivrn \ No newline at end of file +} // namespace wivrn diff --git a/server/driver/wivrn_hmd.cpp b/server/driver/wivrn_hmd.cpp index 9d3a330c..582ba8d3 100644 --- a/server/driver/wivrn_hmd.cpp +++ b/server/driver/wivrn_hmd.cpp @@ -73,9 +73,11 @@ wivrn_hmd::wivrn_hmd(wivrn::wivrn_session * cnx, .tracking_origin = &tracking_origin, .input_count = 1, .inputs = &pose_input, - .orientation_tracking_supported = true, - .position_tracking_supported = true, - .battery_status_supported = true, + .supported = { + .orientation_tracking = true, + .position_tracking = true, + .battery_status = true, + }, .update_inputs = [](xrt_device *) { return XRT_SUCCESS; }, .get_tracked_pose = method_pointer<&wivrn_hmd::get_tracked_pose>, .get_view_poses = method_pointer<&wivrn_hmd::get_view_poses>, diff --git a/server/driver/wivrn_htc_face_tracker.cpp b/server/driver/wivrn_htc_face_tracker.cpp index c5b018f0..e5080381 100644 --- a/server/driver/wivrn_htc_face_tracker.cpp +++ b/server/driver/wivrn_htc_face_tracker.cpp @@ -45,20 +45,27 @@ wivrn_htc_face_tracker::wivrn_htc_face_tracker(xrt_device * hmd, .str = "WiVRn HTC Face Tracker", .serial = "WiVRn HTC Face Tracker", .tracking_origin = hmd->tracking_origin, - .face_tracking_supported = true, + .supported = { + .face_tracking = true, + }, .update_inputs = method_pointer<&wivrn_htc_face_tracker::update_inputs>, .get_face_tracking = method_pointer<&wivrn_htc_face_tracker::get_face_tracking>, .destroy = [](xrt_device *) {}, }, + inputs_array{ + { + { + .active = true, + .name = XRT_INPUT_HTC_EYE_FACE_TRACKING, + }, + { + .active = true, + .name = XRT_INPUT_HTC_LIP_FACE_TRACKING, + }, + }, + }, cnx(cnx) { - // Setup input. - inputs_array[0].name = XRT_INPUT_HTC_EYE_FACE_TRACKING; - inputs_array[0].active = true; - - inputs_array[1].name = XRT_INPUT_HTC_LIP_FACE_TRACKING; - inputs_array[1].active = true; - inputs = inputs_array.data(); input_count = inputs_array.size(); } diff --git a/server/driver/wivrn_session.cpp b/server/driver/wivrn_session.cpp index 8bdad43b..0502af1b 100644 --- a/server/driver/wivrn_session.cpp +++ b/server/driver/wivrn_session.cpp @@ -169,7 +169,7 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr connection static_roles.head = xdevs[xdev_count++] = &hmd; - if (hmd.face_tracking_supported) + if (hmd.supported.face_tracking) static_roles.face = &hmd; roles.left = xdev_count; From f2679f21d0ed18c44351da3c009cb02c66b5fca2 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sat, 7 Jun 2025 12:36:32 +0200 Subject: [PATCH 74/85] Update monado --- monado-rev | 2 +- server/driver/wivrn_controller.cpp | 5 +++-- server/driver/wivrn_controller.h | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/monado-rev b/monado-rev index 2e25f8a6..f81195e6 100644 --- a/monado-rev +++ b/monado-rev @@ -1 +1 @@ -bd9a43c9d1a43d2ddece158d98387a7c9b872c6b +f46d3cdefba6fa220a473fc3db7f24767d1b9f26 diff --git a/server/driver/wivrn_controller.cpp b/server/driver/wivrn_controller.cpp index 13668bb7..d6e088c5 100644 --- a/server/driver/wivrn_controller.cpp +++ b/server/driver/wivrn_controller.cpp @@ -769,7 +769,7 @@ xrt_result_t wivrn_controller::get_tracked_pose(xrt_input_name name, int64_t at_ return XRT_SUCCESS; } -void wivrn_controller::get_hand_tracking(xrt_input_name name, int64_t desired_timestamp_ns, xrt_hand_joint_set * out_value, int64_t * out_timestamp_ns) +xrt_result_t wivrn_controller::get_hand_tracking(xrt_input_name name, int64_t desired_timestamp_ns, xrt_hand_joint_set * out_value, int64_t * out_timestamp_ns) { switch (name) { @@ -780,12 +780,13 @@ void wivrn_controller::get_hand_tracking(xrt_input_name name, int64_t desired_ti std::tie(extrapolation_time, *out_value) = joints.get_at(desired_timestamp_ns); cnx->add_predict_offset(extrapolation_time); cnx->set_enabled(joints.hand_id == 0 ? to_headset::tracking_control::id::left_hand : to_headset::tracking_control::id::right_hand, true); - return; + return XRT_SUCCESS; } default: U_LOG_W("Unknown input name requested %d", int(name)); } + return XRT_ERROR_INPUT_UNSUPPORTED; } void wivrn_controller::set_derived_pose(const from_headset::derived_pose & derived) diff --git a/server/driver/wivrn_controller.h b/server/driver/wivrn_controller.h index f383e026..ced51562 100644 --- a/server/driver/wivrn_controller.h +++ b/server/driver/wivrn_controller.h @@ -53,7 +53,7 @@ public: xrt_result_t update_inputs(); xrt_result_t get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation * out_relation); - void get_hand_tracking(xrt_input_name name, int64_t desired_timestamp_ns, xrt_hand_joint_set * out_value, int64_t * out_timestamp_ns); + xrt_result_t get_hand_tracking(xrt_input_name name, int64_t desired_timestamp_ns, xrt_hand_joint_set * out_value, int64_t * out_timestamp_ns); void set_output(xrt_output_name name, const xrt_output_value * value); From e5fd6a69dc69a2d095f445f1bf51437bf509895b Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sat, 7 Jun 2025 12:41:52 +0200 Subject: [PATCH 75/85] Update monado --- flake.nix | 2 +- monado-rev | 2 +- .../monado/0001-c-multi-early-wake-of-compositor.patch | 10 +++++----- .../0002-ipc-server-Always-listen-to-stdin.patch | 2 +- patches/monado/0003-Use-extern-socket-fd.patch | 2 +- ...c-render-Add-storage-usage-to-distortion-mesh.patch | 2 +- ...change-environment-blend-mode-selection-logic.patch | 4 ++-- patches/monado/0006-Convert-to-YCbCr-in-Monado.patch | 2 +- .../monado/0007-store-alpha-channel-in-layer-1.patch | 2 +- .../0008-st-oxr-bind-to-dynamic-role-s-profile.patch | 2 +- .../0009-c-main-allow-custom-pacing-app-factory.patch | 2 +- .../monado/0010-st-oxr-forward-0-refresh-rate.patch | 2 +- ...place-distortion-with-pixel-aligned-foveation.patch | 2 +- 13 files changed, 18 insertions(+), 18 deletions(-) diff --git a/flake.nix b/flake.nix index fbbd5071..67bd4600 100644 --- a/flake.nix +++ b/flake.nix @@ -37,7 +37,7 @@ # Keep in sync with CMakeLists.txt monado rev rev = builtins.readFile ./monado-rev; # Nix will output the correct hash when it doesn't match - hash = "sha256-Bus9GTNC4+nOSwN8pUsMaFsiXjlpHYioQfBLxbQEF+0="; + hash = "sha256-KSHnJ+H/JdLFg/oFERDk+dXTJY44yUP04WHxa7xp6LY="; }; }; diff --git a/monado-rev b/monado-rev index f81195e6..26d0187f 100644 --- a/monado-rev +++ b/monado-rev @@ -1 +1 @@ -f46d3cdefba6fa220a473fc3db7f24767d1b9f26 +9f9d26270ef5131f94adaecc4d6b87aebe50d841 diff --git a/patches/monado/0001-c-multi-early-wake-of-compositor.patch b/patches/monado/0001-c-multi-early-wake-of-compositor.patch index e7a959aa..6bd0fb26 100644 --- a/patches/monado/0001-c-multi-early-wake-of-compositor.patch +++ b/patches/monado/0001-c-multi-early-wake-of-compositor.patch @@ -1,4 +1,4 @@ -From 1fb49a24efe49e99776ff84bf72af4124b466b8c Mon Sep 17 00:00:00 2001 +From 4c22024929342b69b4a1c7d30334b994ea8c78c1 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Tue, 22 Oct 2024 15:23:19 +0200 Subject: [PATCH 01/11] c/multi: early wake of compositor @@ -51,7 +51,7 @@ index 3351defa4..e8f0c8295 100644 { int64_t predicted_display_time_ns; diff --git a/src/xrt/compositor/multi/comp_multi_system.c b/src/xrt/compositor/multi/comp_multi_system.c -index b06b03a58..249e07d7d 100644 +index a0bd04e08..9d7610d02 100644 --- a/src/xrt/compositor/multi/comp_multi_system.c +++ b/src/xrt/compositor/multi/comp_multi_system.c @@ -23,6 +23,8 @@ @@ -93,7 +93,7 @@ index b06b03a58..249e07d7d 100644 } static void -@@ -525,10 +534,13 @@ multi_main_loop(struct multi_system_compositor *msc) +@@ -526,10 +535,13 @@ multi_main_loop(struct multi_system_compositor *msc) broadcast_timings_to_clients(msc, predicted_display_time_ns); // Now we can wait. @@ -109,7 +109,7 @@ index b06b03a58..249e07d7d 100644 // Now we know the diff, broadcast to pacers. broadcast_timings_to_pacers(msc, predicted_display_time_ns, predicted_display_period_ns, diff_ns); -@@ -705,6 +717,8 @@ system_compositor_destroy(struct xrt_system_compositor *xsc) +@@ -706,6 +718,8 @@ system_compositor_destroy(struct xrt_system_compositor *xsc) xrt_comp_native_destroy(&msc->xcn); os_mutex_destroy(&msc->list_and_timing_lock); @@ -118,7 +118,7 @@ index b06b03a58..249e07d7d 100644 free(msc); } -@@ -759,6 +773,8 @@ comp_multi_create_system_compositor(struct xrt_compositor_native *xcn, +@@ -760,6 +774,8 @@ comp_multi_create_system_compositor(struct xrt_compositor_native *xcn, msc->sessions.state = do_warm_start ? MULTI_SYSTEM_STATE_INIT_WARM_START : MULTI_SYSTEM_STATE_STOPPED; os_mutex_init(&msc->list_and_timing_lock); diff --git a/patches/monado/0002-ipc-server-Always-listen-to-stdin.patch b/patches/monado/0002-ipc-server-Always-listen-to-stdin.patch index 223d012d..7b170603 100644 --- a/patches/monado/0002-ipc-server-Always-listen-to-stdin.patch +++ b/patches/monado/0002-ipc-server-Always-listen-to-stdin.patch @@ -1,4 +1,4 @@ -From 0bbc60f44d226a4da375bbca774ddb6804815ad9 Mon Sep 17 00:00:00 2001 +From dab0f39ec43bd1eb7d17d3bc32d1a2404cfa3702 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Tue, 2 Apr 2024 17:14:42 +0200 Subject: [PATCH 02/11] ipc/server: Always listen to stdin diff --git a/patches/monado/0003-Use-extern-socket-fd.patch b/patches/monado/0003-Use-extern-socket-fd.patch index a2dc1cb6..aa6a4f28 100644 --- a/patches/monado/0003-Use-extern-socket-fd.patch +++ b/patches/monado/0003-Use-extern-socket-fd.patch @@ -1,4 +1,4 @@ -From 32acb282e86e85c24c276a8b55d948b09fe77f13 Mon Sep 17 00:00:00 2001 +From 4abefae5f0c3bfbe959368d2708384e4cb503ef5 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Tue, 8 Oct 2024 22:13:15 +0200 Subject: [PATCH 03/11] Use extern socket fd diff --git a/patches/monado/0004-c-render-Add-storage-usage-to-distortion-mesh.patch b/patches/monado/0004-c-render-Add-storage-usage-to-distortion-mesh.patch index ad453507..bfd3f08d 100644 --- a/patches/monado/0004-c-render-Add-storage-usage-to-distortion-mesh.patch +++ b/patches/monado/0004-c-render-Add-storage-usage-to-distortion-mesh.patch @@ -1,4 +1,4 @@ -From e5f9b59f15df9e1902612bec6b038d435e42c5f1 Mon Sep 17 00:00:00 2001 +From da5a76a27abe3b9b44bc0dd432eb273c89cd4575 Mon Sep 17 00:00:00 2001 From: galister <3123227-galister@users.noreply.gitlab.com> Date: Mon, 19 Aug 2024 18:51:45 +0900 Subject: [PATCH 04/11] c/render: Add storage usage to distortion mesh diff --git a/patches/monado/0005-change-environment-blend-mode-selection-logic.patch b/patches/monado/0005-change-environment-blend-mode-selection-logic.patch index 34042bd7..386bea85 100644 --- a/patches/monado/0005-change-environment-blend-mode-selection-logic.patch +++ b/patches/monado/0005-change-environment-blend-mode-selection-logic.patch @@ -1,4 +1,4 @@ -From 158d65a9870dedee447e48b63edd7e5539499c30 Mon Sep 17 00:00:00 2001 +From 322b8b36d52afe7f5b57f5785c8b07bc37d315e8 Mon Sep 17 00:00:00 2001 From: galister <85970-galister@users.noreply.gitlab.freedesktop.org> Date: Sat, 23 Nov 2024 02:42:12 +0900 Subject: [PATCH 05/11] change environment blend mode selection logic @@ -8,7 +8,7 @@ Subject: [PATCH 05/11] change environment blend mode selection logic 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/xrt/compositor/multi/comp_multi_system.c b/src/xrt/compositor/multi/comp_multi_system.c -index 249e07d7d..12c8fc455 100644 +index 9d7610d02..f3131e810 100644 --- a/src/xrt/compositor/multi/comp_multi_system.c +++ b/src/xrt/compositor/multi/comp_multi_system.c @@ -232,23 +232,31 @@ find_active_blend_mode(struct multi_compositor **overlay_sorted_clients, size_t diff --git a/patches/monado/0006-Convert-to-YCbCr-in-Monado.patch b/patches/monado/0006-Convert-to-YCbCr-in-Monado.patch index faa8e6ee..12180fdb 100644 --- a/patches/monado/0006-Convert-to-YCbCr-in-Monado.patch +++ b/patches/monado/0006-Convert-to-YCbCr-in-Monado.patch @@ -1,4 +1,4 @@ -From 404e894924ea3aea43bcc8a810b452e03a8fb100 Mon Sep 17 00:00:00 2001 +From 52417118d51d284ab5c0cd3d2c9a93c487b66f5f Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Wed, 11 Sep 2024 22:56:29 +0200 Subject: [PATCH 06/11] Convert to YCbCr in Monado diff --git a/patches/monado/0007-store-alpha-channel-in-layer-1.patch b/patches/monado/0007-store-alpha-channel-in-layer-1.patch index 40f8ea96..3e98a8bf 100644 --- a/patches/monado/0007-store-alpha-channel-in-layer-1.patch +++ b/patches/monado/0007-store-alpha-channel-in-layer-1.patch @@ -1,4 +1,4 @@ -From 39d6494d479f4337dad4108f465d3b62c8f4bc88 Mon Sep 17 00:00:00 2001 +From 40c05c4cae8af77048580a83631aa51b0f48dfec Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sun, 3 Nov 2024 13:40:00 +0100 Subject: [PATCH 07/11] store alpha channel in layer 1 diff --git a/patches/monado/0008-st-oxr-bind-to-dynamic-role-s-profile.patch b/patches/monado/0008-st-oxr-bind-to-dynamic-role-s-profile.patch index ba0bfcae..4585bbb3 100644 --- a/patches/monado/0008-st-oxr-bind-to-dynamic-role-s-profile.patch +++ b/patches/monado/0008-st-oxr-bind-to-dynamic-role-s-profile.patch @@ -1,4 +1,4 @@ -From cbd5dcee4a70e265853c40f5517a7700c521d813 Mon Sep 17 00:00:00 2001 +From e92fb94901fc652bde712af1e90c14237ea26f8f Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Wed, 19 Feb 2025 10:13:36 +0100 Subject: [PATCH 08/11] st/oxr: bind to dynamic role's profile diff --git a/patches/monado/0009-c-main-allow-custom-pacing-app-factory.patch b/patches/monado/0009-c-main-allow-custom-pacing-app-factory.patch index 4b8172f2..f54e5557 100644 --- a/patches/monado/0009-c-main-allow-custom-pacing-app-factory.patch +++ b/patches/monado/0009-c-main-allow-custom-pacing-app-factory.patch @@ -1,4 +1,4 @@ -From b6289de166fc95aea2b350ddb8f3c3ddaacefd99 Mon Sep 17 00:00:00 2001 +From 685e9804eb0abe3fcd6da67ffbc180db35ca4e1d Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Thu, 27 Feb 2025 22:45:36 +0100 Subject: [PATCH 09/11] c/main: allow custom pacing app factory diff --git a/patches/monado/0010-st-oxr-forward-0-refresh-rate.patch b/patches/monado/0010-st-oxr-forward-0-refresh-rate.patch index 9fa50e79..dd1ed8c2 100644 --- a/patches/monado/0010-st-oxr-forward-0-refresh-rate.patch +++ b/patches/monado/0010-st-oxr-forward-0-refresh-rate.patch @@ -1,4 +1,4 @@ -From bcd94f8cdb871a34f16cb236d59734701b125612 Mon Sep 17 00:00:00 2001 +From cbb5662aacc68f28e6628c9fda86a156b08d63a9 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sat, 15 Mar 2025 22:19:48 +0100 Subject: [PATCH 10/11] st/oxr: forward 0 refresh rate diff --git a/patches/monado/0011-Replace-distortion-with-pixel-aligned-foveation.patch b/patches/monado/0011-Replace-distortion-with-pixel-aligned-foveation.patch index 2e612c30..78594608 100644 --- a/patches/monado/0011-Replace-distortion-with-pixel-aligned-foveation.patch +++ b/patches/monado/0011-Replace-distortion-with-pixel-aligned-foveation.patch @@ -1,4 +1,4 @@ -From 223392cfd24edfd937335279b7fb505dcd0c03a0 Mon Sep 17 00:00:00 2001 +From b659d6c6034b8714a014fc6a5819bb2556c6f0bb Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Mon, 2 Jun 2025 14:51:11 +0200 Subject: [PATCH 11/11] Replace distortion with pixel-aligned foveation From 52b0bb0c42657b5751c8cd1371e1a69b2304529c Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Mon, 9 Jun 2025 18:47:28 +0200 Subject: [PATCH 76/85] update monado --- flake.nix | 2 +- monado-rev | 2 +- server/driver/wivrn_hmd.cpp | 13 +++++++------ server/driver/wivrn_hmd.h | 12 ++++++------ 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/flake.nix b/flake.nix index 67bd4600..39a4b4eb 100644 --- a/flake.nix +++ b/flake.nix @@ -37,7 +37,7 @@ # Keep in sync with CMakeLists.txt monado rev rev = builtins.readFile ./monado-rev; # Nix will output the correct hash when it doesn't match - hash = "sha256-KSHnJ+H/JdLFg/oFERDk+dXTJY44yUP04WHxa7xp6LY="; + hash = "sha256-+PiWxnvMXaSFc+67r17GBRXo7kbjikSElawNMJCydrk="; }; }; diff --git a/monado-rev b/monado-rev index 26d0187f..f6c566ab 100644 --- a/monado-rev +++ b/monado-rev @@ -1 +1 @@ -9f9d26270ef5131f94adaecc4d6b87aebe50d841 +bb9bcee2a3be75592de819d9e3fb2c8ed27bb7dc diff --git a/server/driver/wivrn_hmd.cpp b/server/driver/wivrn_hmd.cpp index 582ba8d3..b5378316 100644 --- a/server/driver/wivrn_hmd.cpp +++ b/server/driver/wivrn_hmd.cpp @@ -147,12 +147,12 @@ void wivrn_hmd::update_battery(const from_headset::battery & new_battery) battery = new_battery; } -void wivrn_hmd::get_view_poses(const xrt_vec3 * default_eye_relation, - int64_t at_timestamp_ns, - uint32_t view_count, - xrt_space_relation * out_head_relation, - xrt_fov * out_fovs, - xrt_pose * out_poses) +xrt_result_t wivrn_hmd::get_view_poses(const xrt_vec3 * default_eye_relation, + int64_t at_timestamp_ns, + uint32_t view_count, + xrt_space_relation * out_head_relation, + xrt_fov * out_fovs, + xrt_pose * out_poses) { auto [extrapolation_time, view] = views.get_at(at_timestamp_ns); cnx->add_predict_offset(extrapolation_time); @@ -180,6 +180,7 @@ void wivrn_hmd::get_view_poses(const xrt_vec3 * default_eye_relation, out_fovs[eye] = view.fovs[eye]; out_poses[eye] = view.poses[eye]; } + return XRT_SUCCESS; } xrt_result_t wivrn_hmd::get_battery_status(bool * out_present, diff --git a/server/driver/wivrn_hmd.h b/server/driver/wivrn_hmd.h index f3cb0ebf..c90f4f4b 100644 --- a/server/driver/wivrn_hmd.h +++ b/server/driver/wivrn_hmd.h @@ -67,12 +67,12 @@ public: void set_foveated_size(uint32_t width, uint32_t height); xrt_result_t get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation *); - void get_view_poses(const xrt_vec3 * default_eye_relation, - int64_t at_timestamp_ns, - uint32_t view_count, - xrt_space_relation * out_head_relation, - xrt_fov * out_fovs, - xrt_pose * out_poses); + xrt_result_t get_view_poses(const xrt_vec3 * default_eye_relation, + int64_t at_timestamp_ns, + uint32_t view_count, + xrt_space_relation * out_head_relation, + xrt_fov * out_fovs, + xrt_pose * out_poses); xrt_result_t get_battery_status(bool * out_present, bool * out_charging, float * out_charge); From a6c20e95207cfb194a5b614feb23318b0c66f18c Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Thu, 12 Jun 2025 11:07:10 +0200 Subject: [PATCH 77/85] Send vulkan video idr over tcp --- server/encoder/video_encoder.cpp | 12 ++++--- server/encoder/video_encoder.h | 4 ++- server/encoder/video_encoder_vulkan.cpp | 35 ++++++++------------ server/encoder/video_encoder_vulkan.h | 1 + server/encoder/video_encoder_vulkan_h264.cpp | 2 +- 5 files changed, 26 insertions(+), 28 deletions(-) diff --git a/server/encoder/video_encoder.cpp b/server/encoder/video_encoder.cpp index 16a2d077..344bfecb 100644 --- a/server/encoder/video_encoder.cpp +++ b/server/encoder/video_encoder.cpp @@ -60,7 +60,7 @@ video_encoder::sender::sender() : } if (d and not d->span.empty()) { - d->encoder->SendData(d->span, true); + d->encoder->SendData(d->span, true, d->prefer_control); std::unique_lock lock(mutex); pending.pop_front(); cv.notify_all(); @@ -314,7 +314,7 @@ void video_encoder::encode(wivrn_session & cnx, std::rethrow_exception(ex); } -void video_encoder::SendData(std::span data, bool end_of_frame) +void video_encoder::SendData(std::span data, bool end_of_frame, bool control) { std::lock_guard lock(mutex); if (end_of_frame) @@ -336,8 +336,7 @@ void video_encoder::SendData(std::span data, bool end_of_frame) auto end = data.end(); while (begin != end) { - const size_t view_info_size = sizeof(to_headset::video_stream_data_shard::view_info_t); - const size_t max_payload_size = to_headset::video_stream_data_shard::max_payload_size - (shard.view_info ? view_info_size : 0); + const size_t max_payload_size = to_headset::video_stream_data_shard::max_payload_size - serialized_size(shard.view_info); auto next = std::min(end, begin + max_payload_size); if (next == end) { @@ -351,7 +350,10 @@ void video_encoder::SendData(std::span data, bool end_of_frame) shard.payload = {begin, next}; try { - cnx->send_stream(to_headset::video_stream_data_shard{shard}); + if (control) + cnx->send_control(to_headset::video_stream_data_shard{shard}); + else + cnx->send_stream(to_headset::video_stream_data_shard{shard}); } catch (...) { diff --git a/server/encoder/video_encoder.h b/server/encoder/video_encoder.h index 25c2cffa..104a97c7 100644 --- a/server/encoder/video_encoder.h +++ b/server/encoder/video_encoder.h @@ -53,6 +53,8 @@ protected: video_encoder * encoder; std::span span; std::shared_ptr mem; + // true if data should be sent over reliable (TCP) socket + bool prefer_control = false; }; private: @@ -140,7 +142,7 @@ public: // called when command buffer finished executing virtual std::optional encode(bool idr, std::chrono::steady_clock::time_point target_timestamp, uint8_t slot) = 0; - void SendData(std::span data, bool end_of_frame); + void SendData(std::span data, bool end_of_frame, bool control = false); }; } // namespace wivrn diff --git a/server/encoder/video_encoder_vulkan.cpp b/server/encoder/video_encoder_vulkan.cpp index f96f42d7..01d9b895 100644 --- a/server/encoder/video_encoder_vulkan.cpp +++ b/server/encoder/video_encoder_vulkan.cpp @@ -416,9 +416,11 @@ std::vector wivrn::video_encoder_vulkan::get_encoded_parameters(void * std::optional wivrn::video_encoder_vulkan::encode(bool idr, std::chrono::steady_clock::time_point target_timestamp, uint8_t encode_slot) { - if (idr) - send_idr_data(); + // we manage idrs ourselves + (void)idr; auto & slot_item = slot_data[encode_slot]; + if (slot_item.idr) + send_idr_data(); if (auto res = vk.device.waitForFences(*slot_item.fence, true, 1'000'000'000); res != vk::Result::eSuccess) @@ -438,6 +440,7 @@ std::optional wivrn::video_encoder_vulkan::encode(bo return data{ .encoder = this, .span = std::span(((uint8_t *)mapped) + feedback[0], feedback[1]), + .prefer_control = slot_item.idr, }; } @@ -611,31 +614,15 @@ std::pair wivrn::video_encoder_vulkan::present_image(vk::Im auto last_ack = this->last_ack.load(); dpb_item * ref_slot = nullptr; - for (size_t i = 0; i < dpb.size(); ++i) + for (auto & i: dpb) { - if (dpb[i].frame_index == last_ack and dpb[i].info.slotIndex != -1) + if (i.frame_index == last_ack and i.info.slotIndex != -1) { - ref_slot = &dpb[i]; + ref_slot = &i; break; } } - // Avoid sending many IDR in a row - if (frame_num < 100 and not ref_slot) - { - for (size_t i = 0; i < dpb.size(); ++i) - { - if (dpb[i].info.slotIndex != -1) - { - if (not ref_slot or ref_slot->frame_index < dpb[i].frame_index) - { - ref_slot = &dpb[i]; - break; - } - } - } - } - if (not ref_slot) { frame_num = 0; @@ -645,6 +632,12 @@ std::pair wivrn::video_encoder_vulkan::present_image(vk::Im slot.info.pPictureResource = nullptr; slot.frame_index = -1; } + slot_item.idr = true; + last_ack = frame_index; + } + else + { + slot_item.idr = false; } slot->frame_index = frame_index; slot->info.pPictureResource = &slot->resource; diff --git a/server/encoder/video_encoder_vulkan.h b/server/encoder/video_encoder_vulkan.h index a311e0db..354e075d 100644 --- a/server/encoder/video_encoder_vulkan.h +++ b/server/encoder/video_encoder_vulkan.h @@ -52,6 +52,7 @@ class video_encoder_vulkan : public video_encoder vk::raii::ImageView view = nullptr; buffer_allocation output_buffer; buffer_allocation host_buffer; + bool idr = false; }; std::array slot_data; diff --git a/server/encoder/video_encoder_vulkan_h264.cpp b/server/encoder/video_encoder_vulkan_h264.cpp index 33ea3a38..9db4ef74 100644 --- a/server/encoder/video_encoder_vulkan_h264.cpp +++ b/server/encoder/video_encoder_vulkan_h264.cpp @@ -241,7 +241,7 @@ std::vector wivrn::video_encoder_vulkan_h264::get_sps_pps() void wivrn::video_encoder_vulkan_h264::send_idr_data() { auto data = get_sps_pps(); - SendData(data, false); + SendData(data, false, true); } void * wivrn::video_encoder_vulkan_h264::encode_info_next(uint32_t frame_num, size_t slot, std::optional ref_slot) From 5be3a8aef4cd8712147ab68914e4844dd704a2df Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Thu, 12 Jun 2025 14:13:17 +0200 Subject: [PATCH 78/85] Utility to name vulkan objects --- server/utils/wivrn_vk_bundle.cpp | 11 +++++++++ server/utils/wivrn_vk_bundle.h | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/server/utils/wivrn_vk_bundle.cpp b/server/utils/wivrn_vk_bundle.cpp index c91330c1..5a01c2a9 100644 --- a/server/utils/wivrn_vk_bundle.cpp +++ b/server/utils/wivrn_vk_bundle.cpp @@ -224,3 +224,14 @@ uint32_t wivrn::wivrn_vk_bundle::get_memory_type(uint32_t type_bits, vk::MemoryP } throw std::runtime_error("Failed to get memory type"); } + +void wivrn::wivrn_vk_bundle::name(vk::ObjectType type, uint64_t handle, const char * value) +{ + if (not vk.has_EXT_debug_utils) + return; + device.setDebugUtilsObjectNameEXT(vk::DebugUtilsObjectNameInfoEXT{ + .objectType = type, + .objectHandle = handle, + .pObjectName = value, + }); +} diff --git a/server/utils/wivrn_vk_bundle.h b/server/utils/wivrn_vk_bundle.h index 946485ea..6da274a9 100644 --- a/server/utils/wivrn_vk_bundle.h +++ b/server/utils/wivrn_vk_bundle.h @@ -22,6 +22,7 @@ #include "vk/vk_allocator.h" #include #include +#include #include #include @@ -53,6 +54,36 @@ struct raii_device : public vk::raii::Device } }; +namespace details +{ +template +struct vk_handle +{ + uint64_t operator()(const T & handle) + { + typename T::CType chandle = handle; + return uint64_t(chandle); + } +}; + +// vk::raii specialization +template +struct vk_handle> +{ + uint64_t operator()(const T & handle) + { + typename T::CType chandle = *handle; + return uint64_t(chandle); + } +}; +} // namespace details + +template +uint64_t vk_handle(const T & handle) +{ + return details::vk_handle{}(handle); +} + struct wivrn_vk_bundle { vk_bundle & vk; @@ -75,5 +106,14 @@ struct wivrn_vk_bundle wivrn_vk_bundle(vk_bundle & vk, std::span requested_instance_extensions, std::span requested_device_extensions); uint32_t get_memory_type(uint32_t type_bits, vk::MemoryPropertyFlags memory_props); + + template + void name(const T & handle, const char * value) + { + return name(T::objectType, vk_handle(handle), value); + } + +private: + void name(vk::ObjectType, uint64_t handle, const char * value); }; } // namespace wivrn From 1ed4d3cfe648729e91064f31f9ed7a40c4b6abbf Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Thu, 12 Jun 2025 14:13:32 +0200 Subject: [PATCH 79/85] Name vulkan video objects --- server/encoder/video_encoder_vulkan.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/server/encoder/video_encoder_vulkan.cpp b/server/encoder/video_encoder_vulkan.cpp index 01d9b895..1ccb296e 100644 --- a/server/encoder/video_encoder_vulkan.cpp +++ b/server/encoder/video_encoder_vulkan.cpp @@ -165,6 +165,7 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca { .usage = VMA_MEMORY_USAGE_AUTO, }); + vk.name(vk::Image(dpb_image), "vulkan encoder DPB image"); } // Output buffer @@ -183,6 +184,7 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca .flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT, .usage = VMA_MEMORY_USAGE_AUTO, }); + vk.name(vk::Buffer(item.output_buffer), "vulkan encode output buffer"); if (not(item.output_buffer.properties() & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)) { @@ -195,6 +197,7 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca .flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT, .usage = VMA_MEMORY_USAGE_AUTO, }); + vk.name(vk::Buffer(item.host_buffer), "vulkan encode host buffer"); } } @@ -278,8 +281,10 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca { .usage = VMA_MEMORY_USAGE_AUTO, }); + vk.name(vk::Image(slot_data[i].tmp_image), "vulkan encoder temporary image"); image_view_template.image = vk::Image(slot_data[i].tmp_image); slot_data[i].view = vk.device.createImageView(image_view_template); + vk.name(slot_data[i].view, "vulkan encoder temporary image view"); } } @@ -317,6 +322,7 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca .image_view = vk.device.createImageView(img_view_create_info), .info = dpb_info[i], }); + vk.name(dpb.back().image_view, "vulkan encoder dpb view"); } } @@ -344,6 +350,8 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca { item.fence = vk.device.createFence({.flags = vk::FenceCreateFlagBits::eSignaled}); item.wait_sem = vk.device.createSemaphore({}); + vk.name(item.fence, "vulkan encoder fence"); + vk.name(item.fence, "vulkan encoder semaphore"); } // query pool @@ -363,6 +371,7 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca }; query_pool = vk.device.createQueryPool(query_pool_create.get()); + vk.name(query_pool, "vulkan encoder query pool"); } // command pools @@ -372,13 +381,17 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca .flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer, .queueFamilyIndex = vk.encode_queue_family_index, }); + vk.name(query_pool, "vulkan encoder video command pool"); auto command_buffers = vk.device.allocateCommandBuffers( {.commandPool = *video_command_pool, .commandBufferCount = num_slots}); for (size_t i = 0; i < num_slots; ++i) + { slot_data[i].video_cmd_buf = std::move(command_buffers[i]); + vk.name(slot_data[i].video_cmd_buf, "vulkan encoder video command buffer"); + } auto properties = vk.physical_device.getQueueFamilyProperties().at(vk.encode_queue_family_index); if (not(properties.queueFlags & vk::QueueFlagBits::eTransfer)) @@ -388,6 +401,7 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca .flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer, .queueFamilyIndex = vk.queue_family_index, }); + vk.name(transfer_command_pool, "vulkan encoder transfer command pool"); auto command_buffers = vk.device.allocateCommandBuffers( {.commandPool = *transfer_command_pool, @@ -396,6 +410,8 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca { slot_data[i].sem = vk.device.createSemaphore({}); slot_data[i].transfer_cmd_buf = std::move(command_buffers[i]); + vk.name(slot_data[i].sem, "vulkan encoder transfer semaphore"); + vk.name(slot_data[i].transfer_cmd_buf, "vulkan encoder transfer command buffer"); } } } From f6eb528ea7aaa0ba9aa98a6a872a74560147d47a Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Thu, 12 Jun 2025 14:24:58 +0200 Subject: [PATCH 80/85] Name most vulkan objects --- server/driver/wivrn_comp_target.cpp | 6 ++++++ server/driver/wivrn_foveation.cpp | 3 +++ server/encoder/ffmpeg/video_encoder_va.cpp | 2 ++ server/encoder/video_encoder_nvenc.cpp | 2 ++ server/encoder/video_encoder_x264.cpp | 2 ++ 5 files changed, 15 insertions(+) diff --git a/server/driver/wivrn_comp_target.cpp b/server/driver/wivrn_comp_target.cpp index 314e9a9b..f2a9553a 100644 --- a/server/driver/wivrn_comp_target.cpp +++ b/server/driver/wivrn_comp_target.cpp @@ -235,6 +235,7 @@ static VkResult create_images(struct wivrn_comp_target * cn, vk::ImageUsageFlags .usage = VMA_MEMORY_USAGE_AUTO, }); cn->images[i].handle = image; + cn->wivrn_bundle->name(vk::Image(image), "comp target image"); } for (uint32_t i = 0; i < cn->image_count; i++) @@ -269,13 +270,17 @@ static VkResult create_images(struct wivrn_comp_target * cn, vk::ImageUsageFlags }); cn->images[i].view = VkImageView(*item.image_view_y); cn->images[i].view_cbcr = VkImageView(*item.image_view_cbcr); + cn->wivrn_bundle->name(item.image_view_y, "comp target image view (y)"); + cn->wivrn_bundle->name(item.image_view_cbcr, "comp target image view (CbCr)"); } cn->psc.fence = vk::raii::Fence(device, vk::FenceCreateInfo{.flags = vk::FenceCreateFlagBits::eSignaled}); + cn->wivrn_bundle->name(cn->psc.fence, "comp target fence"); cn->psc.command_buffer = std::move(device.allocateCommandBuffers( {.commandPool = *cn->command_pool, .commandBufferCount = 1})[0]); + cn->wivrn_bundle->name(cn->psc.command_buffer, "comp target command buffer"); return VK_SUCCESS; } @@ -300,6 +305,7 @@ static bool comp_wivrn_init_post_vulkan(struct comp_target * ct, uint32_t prefer .flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer, .queueFamilyIndex = vk->queue_family_index, }); + cn->wivrn_bundle->name(cn->command_pool, "comp target command pool"); } catch (std::exception & e) { diff --git a/server/driver/wivrn_foveation.cpp b/server/driver/wivrn_foveation.cpp index e2e9cc94..2bccec66 100644 --- a/server/driver/wivrn_foveation.cpp +++ b/server/driver/wivrn_foveation.cpp @@ -273,6 +273,9 @@ wivrn_foveation::wivrn_foveation(wivrn_vk_bundle & bundle, const xrt_hmd_parts & .usage = VMA_MEMORY_USAGE_AUTO, }) { + bundle.name(command_pool, "foveation command pool"); + bundle.name(cmd, "foveation command buffer"); + bundle.name(vk::Buffer(host_buffer), "foveation staging buffer"); } void wivrn_foveation::update_tracking(const from_headset::tracking & tracking, const clock_offset & offset) diff --git a/server/encoder/ffmpeg/video_encoder_va.cpp b/server/encoder/ffmpeg/video_encoder_va.cpp index cbf2f9c5..14892529 100644 --- a/server/encoder/ffmpeg/video_encoder_va.cpp +++ b/server/encoder/ffmpeg/video_encoder_va.cpp @@ -311,6 +311,7 @@ video_encoder_va::video_encoder_va(wivrn_vk_bundle & vk, auto & image = (i == 0 ? luma : chroma); image = vk.device.createImage(image_create_info.get()); + vk.name(image, i == 0 ? "va encoder luma image" : "va encoder chroma image"); auto [req, ded_req] = vk.device.getImageMemoryRequirements2({.image = *image}); @@ -336,6 +337,7 @@ video_encoder_va::video_encoder_va(wivrn_vk_bundle & vk, try { mem.emplace_back(vk.device, alloc_info.get()); + vk.name(mem.back(), "va encoder memory"); } catch (...) { diff --git a/server/encoder/video_encoder_nvenc.cpp b/server/encoder/video_encoder_nvenc.cpp index b07ed634..8c61d1d1 100644 --- a/server/encoder/video_encoder_nvenc.cpp +++ b/server/encoder/video_encoder_nvenc.cpp @@ -248,6 +248,7 @@ video_encoder_nvenc::video_encoder_nvenc( for (auto & i: in) { i.yuv = vk::raii::Buffer(vk.device, buffer_create_info.get()); + vk.name(i.yuv, "nvenc yuv buffer"); auto memory_req = i.yuv.getMemoryRequirements(); vk::StructureChain mem_info{ @@ -263,6 +264,7 @@ video_encoder_nvenc::video_encoder_nvenc( }, }; i.mem = vk.device.allocateMemory(mem_info.get()); + vk.name(i.mem, "nvenc memory"); i.yuv.bindMemory(*i.mem, 0); int fd = vk.device.getMemoryFdKHR({ diff --git a/server/encoder/video_encoder_x264.cpp b/server/encoder/video_encoder_x264.cpp index 618260d5..0499b912 100644 --- a/server/encoder/video_encoder_x264.cpp +++ b/server/encoder/video_encoder_x264.cpp @@ -175,6 +175,8 @@ video_encoder_x264::video_encoder_x264( .flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT, .usage = VMA_MEMORY_USAGE_AUTO, }); + vk.name(vk::Buffer(i.luma), "x264 luma buffer"); + vk.name(vk::Buffer(i.chroma), "x264 chroma buffer"); auto & pic = i.pic; x264_picture_init(&pic); From 711be3754bf39ec0ee90cdd82237ccfbb1edcc77 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Thu, 12 Jun 2025 14:47:10 +0200 Subject: [PATCH 81/85] fix comp_target deletion (again) --- server/driver/wivrn_comp_target.cpp | 4 +-- server/driver/wivrn_comp_target.h | 1 - server/driver/wivrn_session.cpp | 52 +++++++++++++++++++++-------- server/driver/wivrn_session.h | 8 +++-- 4 files changed, 47 insertions(+), 18 deletions(-) diff --git a/server/driver/wivrn_comp_target.cpp b/server/driver/wivrn_comp_target.cpp index f2a9553a..0357d15f 100644 --- a/server/driver/wivrn_comp_target.cpp +++ b/server/driver/wivrn_comp_target.cpp @@ -798,8 +798,8 @@ wivrn_comp_target::~wivrn_comp_target() static void comp_wivrn_destroy(struct comp_target * ct) { auto cn = (struct wivrn_comp_target *)ct; - destroy_images(cn); - cn->self = nullptr; + cn->cnx.unset_comp_target(); + delete cn; } static void comp_wivrn_info_gpu(struct comp_target * ct, int64_t frame_id, int64_t gpu_start_ns, int64_t gpu_end_ns, int64_t when_ns) diff --git a/server/driver/wivrn_comp_target.h b/server/driver/wivrn_comp_target.h index 76bedf2d..a05e5f33 100644 --- a/server/driver/wivrn_comp_target.h +++ b/server/driver/wivrn_comp_target.h @@ -78,7 +78,6 @@ struct pseudo_swapchain struct wivrn_comp_target : public comp_target { - std::shared_ptr self; to_headset::video_stream_description desc{}; wivrn_pacer pacer; diff --git a/server/driver/wivrn_session.cpp b/server/driver/wivrn_session.cpp index 0502af1b..e1e29de7 100644 --- a/server/driver/wivrn_session.cpp +++ b/server/driver/wivrn_session.cpp @@ -89,9 +89,8 @@ struct wivrn_comp_target_factory : public comp_target_factory static bool create_target(const struct comp_target_factory * ctf, struct comp_compositor * c, struct comp_target ** out_ct) { auto self = (wivrn_comp_target_factory *)ctf; - self->session.comp_target = std::make_shared(self->session, c); - self->session.comp_target->self = self->session.comp_target; - *out_ct = self->session.comp_target.get(); + self->session.comp_target = new wivrn_comp_target(self->session, c); + *out_ct = self->session.comp_target; return true; } }; @@ -336,6 +335,12 @@ bool wivrn_session::connected() return connection->is_active(); } +void wivrn_session::unset_comp_target() +{ + std::lock_guard lock(comp_target_mutex); + comp_target = nullptr; +} + void wivrn_session::operator()(from_headset::headset_info_packet &&) { U_LOG_W("unexpected headset info packet, ignoring"); @@ -429,9 +434,11 @@ void wivrn_session::operator()(const from_headset::tracking & tracking) right_hand.update_tracking(tracking, offset); if (eye_tracker) eye_tracker->update_tracking(tracking, offset); - assert(comp_target); - assert(comp_target->foveation); - comp_target->foveation->update_tracking(tracking, offset); + { + std::shared_lock lock(comp_target_mutex); + if (comp_target) + comp_target->foveation->update_tracking(tracking, offset); + } if (fb_face2_tracker) fb_face2_tracker->update_tracking(tracking, offset); @@ -522,11 +529,14 @@ void wivrn_session::set_tracker_enabled(int index, bool enabled) void wivrn_session::operator()(from_headset::feedback && feedback) { - assert(comp_target); clock_offset o = offset_est.get_offset(); if (not o) return; - comp_target->on_feedback(feedback, o); + { + std::shared_lock lock(comp_target_mutex); + if (comp_target) + comp_target->on_feedback(feedback, o); + } if (feedback.received_first_packet) dump_time("receive_begin", feedback.frame_index, o.from_headset(feedback.received_first_packet), feedback.stream_index); @@ -561,7 +571,11 @@ void wivrn_session::operator()(from_headset::visibility_mask_changed && mask) void wivrn_session::operator()(from_headset::refresh_rate_changed && event) { - comp_target->set_refresh_rate(event.to); + { + std::shared_lock lock(comp_target_mutex); + if (comp_target) + comp_target->set_refresh_rate(event.to); + } push_event( { .display = { @@ -585,7 +599,9 @@ void wivrn_session::operator()(to_monado::disconnect &&) void wivrn_session::operator()(to_monado::set_bitrate && data) { - comp_target->set_bitrate(data.bitrate_bps); + std::shared_lock lock(comp_target_mutex); + if (comp_target) + comp_target->set_bitrate(data.bitrate_bps); } struct refresh_rate_adjuster @@ -645,8 +661,14 @@ void wivrn_session::run(std::stop_token stop) { offset_est.request_sample(*connection); tracking_control.send(*connection); - if (comp_target->requested_refresh_rate == 0) - refresh.adjust(*connection); + { + std::shared_lock lock(comp_target_mutex); + if (comp_target) + { + if (comp_target->requested_refresh_rate == 0) + refresh.adjust(*connection); + } + } connection->poll(*this, 20); } catch (const std::exception & e) @@ -723,7 +745,11 @@ void wivrn_session::reconnect() // const auto & info = connection->info(); // FIXME: ensure new client is compatible - comp_target->reset_encoders(); + { + std::shared_lock lock(comp_target_mutex); + if (comp_target) + comp_target->reset_encoders(); + } if (audio_handle) send_control(audio_handle->description()); diff --git a/server/driver/wivrn_session.h b/server/driver/wivrn_session.h index 1c6a234a..93ee8a93 100644 --- a/server/driver/wivrn_session.h +++ b/server/driver/wivrn_session.h @@ -32,8 +32,8 @@ #include #include #include +#include #include -#include struct u_system; struct xrt_space_overseer; @@ -113,7 +113,9 @@ class wivrn_session : public xrt_system_devices uint32_t num_generic_trackers; std::array, from_headset::body_tracking::max_tracked_poses> generic_trackers; std::array enabled_trackers; - std::shared_ptr comp_target; + + std::shared_mutex comp_target_mutex; + wivrn_comp_target * comp_target; clock_offset_estimator offset_est; @@ -146,6 +148,8 @@ public: return connection->info(); }; + void unset_comp_target(); + wivrn_hmd & get_hmd() { return hmd; From 40aeaab762dbaf80b8148823dcc42b9362dcf6c4 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Thu, 12 Jun 2025 21:34:33 +0200 Subject: [PATCH 82/85] Cap num DPB slots to 16 --- server/encoder/video_encoder_vulkan.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server/encoder/video_encoder_vulkan.cpp b/server/encoder/video_encoder_vulkan.cpp index 1ccb296e..ea151952 100644 --- a/server/encoder/video_encoder_vulkan.cpp +++ b/server/encoder/video_encoder_vulkan.cpp @@ -60,11 +60,21 @@ wivrn::video_encoder_vulkan::video_encoder_vulkan( float fps, uint8_t stream_idx, const encoder_settings & settings) : - video_encoder(stream_idx, settings.channels, settings.bitrate_multiplier, true), vk(vk), encode_caps(patch_capabilities(in_encode_caps)), rect(rect), num_dpb_slots(video_caps.maxDpbSlots) + video_encoder(stream_idx, settings.channels, settings.bitrate_multiplier, true), + vk(vk), + encode_caps(patch_capabilities(in_encode_caps)), + rect(rect), + num_dpb_slots(std::min(video_caps.maxDpbSlots, 16u)) { // Initialize Rate control U_LOG_D("Supported rate control modes: %s", vk::to_string(encode_caps.rateControlModes).c_str()); + U_LOG_D("video caps:\n" + "\t maxDpbSlots: %d\n" + "\t maxActiveReferencePictures: %d", + video_caps.maxDpbSlots, + video_caps.maxActiveReferencePictures); + if (encode_caps.rateControlModes & (vk::VideoEncodeRateControlModeFlagBitsKHR::eCbr | vk::VideoEncodeRateControlModeFlagBitsKHR::eVbr)) { U_LOG_D("Maximum bitrate: %" PRIu64, encode_caps.maxBitrate / 1'000'000); From 2ee0604ccf5909a890366616f870808278db003c Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Fri, 13 Jun 2025 11:38:50 +0200 Subject: [PATCH 83/85] fix "Steam informations" -> "Steam information" --- dashboard/qml/Main.qml | 2 +- locale/es/wivrn-dashboard.po | 2 +- locale/fr/wivrn-dashboard.po | 2 +- locale/ja/wivrn-dashboard.po | 2 +- locale/pt_BR/wivrn-dashboard.po | 2 +- locale/zh_TW/wivrn-dashboard.po | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dashboard/qml/Main.qml b/dashboard/qml/Main.qml index f7fc7bb1..17952b9f 100644 --- a/dashboard/qml/Main.qml +++ b/dashboard/qml/Main.qml @@ -292,7 +292,7 @@ Kirigami.ApplicationWindow { Kirigami.Heading { level: 1 wrapMode: Text.WordWrap - text: i18n("Steam informations") + text: i18n("Steam information") opacity: root.server_started Layout.maximumHeight: root.server_started ? -1 : 0 } diff --git a/locale/es/wivrn-dashboard.po b/locale/es/wivrn-dashboard.po index 0e971829..6fe4cc17 100644 --- a/locale/es/wivrn-dashboard.po +++ b/locale/es/wivrn-dashboard.po @@ -324,7 +324,7 @@ msgstr "Aplicación" #: dashboard/qml/Main.qml:295 #, kde-format -msgid "Steam informations" +msgid "Steam information" msgstr "Información de Steam" #: dashboard/qml/Main.qml:313 diff --git a/locale/fr/wivrn-dashboard.po b/locale/fr/wivrn-dashboard.po index ce67fd84..e8cad738 100644 --- a/locale/fr/wivrn-dashboard.po +++ b/locale/fr/wivrn-dashboard.po @@ -323,7 +323,7 @@ msgstr "Application" #: dashboard/qml/Main.qml:295 #, kde-format -msgid "Steam informations" +msgid "Steam information" msgstr "Informations pour Steam" #: dashboard/qml/Main.qml:313 diff --git a/locale/ja/wivrn-dashboard.po b/locale/ja/wivrn-dashboard.po index a1fa1681..55816ac8 100644 --- a/locale/ja/wivrn-dashboard.po +++ b/locale/ja/wivrn-dashboard.po @@ -310,7 +310,7 @@ msgstr "アプリ" #: dashboard/qml/Main.qml:295 #, kde-format -msgid "Steam informations" +msgid "Steam information" msgstr "ストリーム情報" #: dashboard/qml/Main.qml:313 diff --git a/locale/pt_BR/wivrn-dashboard.po b/locale/pt_BR/wivrn-dashboard.po index 3c71714f..d2c21312 100644 --- a/locale/pt_BR/wivrn-dashboard.po +++ b/locale/pt_BR/wivrn-dashboard.po @@ -322,7 +322,7 @@ msgstr "Aplicação" #: dashboard/qml/Main.qml:295 #, kde-format -msgid "Steam informations" +msgid "Steam information" msgstr "Informações da Steam" #: dashboard/qml/Main.qml:313 diff --git a/locale/zh_TW/wivrn-dashboard.po b/locale/zh_TW/wivrn-dashboard.po index 9ad4b125..afef4e8d 100644 --- a/locale/zh_TW/wivrn-dashboard.po +++ b/locale/zh_TW/wivrn-dashboard.po @@ -317,7 +317,7 @@ msgstr "應用程式" #: dashboard/qml/Main.qml:295 #, kde-format -msgid "Steam informations" +msgid "Steam information" msgstr "Steam 資訊" #: dashboard/qml/Main.qml:313 From 804bfc62911828fdf67c0755075306b0ead93403 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sun, 15 Jun 2025 09:53:01 +0200 Subject: [PATCH 84/85] Fix build with older vulkan_hpp --- server/driver/wivrn_foveation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/driver/wivrn_foveation.cpp b/server/driver/wivrn_foveation.cpp index 2bccec66..faa4003c 100644 --- a/server/driver/wivrn_foveation.cpp +++ b/server/driver/wivrn_foveation.cpp @@ -408,6 +408,6 @@ vk::CommandBuffer wivrn_foveation::update_foveation_buffer( fill_ubo(ubo->x + view * RENDER_FOVEATION_BUFFER_DIMENSIONS, params[view].x, false, source[view].offset.w, source[view].extent.w, foveated_width); fill_ubo(ubo->y + view * RENDER_FOVEATION_BUFFER_DIMENSIONS, params[view].y, flip_y, source[view].offset.h, source[view].extent.h, foveated_height); } - return cmd; + return *cmd; } } // namespace wivrn From f2050fbe5425db0aee1cb171c985208dce28859f Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sun, 15 Jun 2025 10:00:29 +0200 Subject: [PATCH 85/85] Re-fix build with older vulkan_hpp --- server/driver/wivrn_foveation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/driver/wivrn_foveation.cpp b/server/driver/wivrn_foveation.cpp index faa4003c..c507ce0f 100644 --- a/server/driver/wivrn_foveation.cpp +++ b/server/driver/wivrn_foveation.cpp @@ -259,7 +259,7 @@ wivrn_foveation::wivrn_foveation(wivrn_vk_bundle & bundle, const xrt_hmd_parts & foveated_height(hmd.screens[0].h_pixels), command_pool(bundle.device, vk::CommandPoolCreateInfo{.queueFamilyIndex = bundle.queue_family_index}), cmd(std::move(bundle.device.allocateCommandBuffers({ - .commandPool = command_pool, + .commandPool = *command_pool, .commandBufferCount = 1, })[0])), host_buffer(