Compare commits

..
165 changed files with 6620 additions and 7832 deletions
-2
View File
@@ -80,7 +80,6 @@ body:
attributes:
label: Vulkan Info
description: Provide the output of `vulkaninfo --summary` command.
render: text
placeholder: Attach the output as a file here.
- type: dropdown
@@ -107,5 +106,4 @@ body:
attributes:
label: ADB Logs
description: Provide the output of `adb logcat` command.
render: plain
placeholder: Attach the output of adb logcat as a file.
+12 -7
View File
@@ -25,13 +25,11 @@ jobs:
repository: 'Vindicus999/WiVRn'
ref: ${{ github.sha }}
fetch-depth: 0
- name: Prepare Vulkan SDK
uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944
with:
vulkan-query-version: 1.3.296.0
vulkan-components: Glslang, SPIRV-Tools
vulkan-use-cache: true
#
# - uses: actions/checkout@v4
# with:
# repository: 'Vindicus999/WiVRn'
# ref: sneed
- name: set up JDK
uses: actions/setup-java@v4
@@ -75,7 +73,9 @@ jobs:
- name: Prepare before archiving artifacts
run: |
mkdir apk
ls build/outputs/apk/
mv $(find build/outputs/apk/ -name "*.apk") apk/
ls apk/
mkdir debug
mv build/intermediates/merged_native_libs/*/*/out/lib/* debug/
find debug -name libopenxr_loader.so -delete
@@ -131,6 +131,11 @@ jobs:
cd symbols
zip -r ../debug-symbols.zip .
- name: How the hell doesnt it work
run: |
ls apk
ls
- name: APK Release
uses: softprops/action-gh-release@v2
with:
+15 -19
View File
@@ -34,12 +34,11 @@ jobs:
- name: Install dependencies
run: >
sudo apt-get update && sudo apt-get install libvulkan-dev libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libavahi-client-dev libavahi-glib-dev libeigen3-dev glslang-tools libudev-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev nlohmann-json3-dev libpulse-dev xz-utils libpipewire-0.3-dev libcli11-dev libboost-all-dev librsvg2-bin libssl-dev libnotify-dev librsvg2-dev libarchive-dev
- name: Prepare Vulkan SDK
uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944
with:
vulkan-query-version: 1.3.296.0
vulkan-components: Vulkan-Headers, Glslang, SPIRV-Tools
vulkan-query-version: 1.3.283.0
vulkan-components: Vulkan-Headers
vulkan-use-cache: true
- name: Configure CMake
@@ -79,7 +78,7 @@ jobs:
build-dashboard:
name: Linux dashboard
runs-on: ubuntu-24.04
container: ubuntu:plucky
container: ubuntu:oracular
if: ${{ vars.APK_ONLY == '' }}
steps:
- uses: actions/checkout@v4
@@ -88,8 +87,14 @@ jobs:
- name: Install dependencies
run: >
apt-get update && apt-get install --yes libvulkan-dev libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev nlohmann-json3-dev qt6-base-dev qt6-tools-dev libcap-dev pkexec libboost-all-dev librsvg2-bin libssl-dev libnotify-dev qt6-declarative-dev extra-cmake-modules libkirigami-dev libkf6i18n-dev libkf6coreaddons-dev libkf6qqc2desktopstyle-dev libkf6iconthemes-dev jq sudo cmake gcc g++ git qcoro-qt6-dev librsvg2-dev libarchive-dev libglm-dev glslang-tools
apt-get update && apt-get install --yes libvulkan-dev libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev nlohmann-json3-dev qt6-base-dev qt6-tools-dev libcap-dev pkexec libboost-all-dev librsvg2-bin libssl-dev libnotify-dev qt6-declarative-dev extra-cmake-modules libkirigami-dev libkf6i18n-dev libkf6coreaddons-dev libkf6qqc2desktopstyle-dev libkf6iconthemes-dev jq sudo cmake gcc g++ git qcoro-qt6-dev librsvg2-dev libarchive-dev
# runtime: qml6-module-qtqml-workerscript qml6-module-qtquick-dialogs
- name: Prepare Vulkan SDK
uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944
with:
vulkan-query-version: 1.3.283.0
vulkan-components: Vulkan-Headers
vulkan-use-cache: true
- name: Configure CMake
run: >
@@ -177,8 +182,8 @@ jobs:
- name: Prepare Vulkan SDK
uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944
with:
vulkan-query-version: 1.3.296.0
vulkan-components: Vulkan-Headers, Glslang, SPIRV-Tools
vulkan-query-version: 1.3.283.0
vulkan-components: Vulkan-Headers
vulkan-use-cache: true
- name: Install dependencies
@@ -194,7 +199,6 @@ jobs:
cmake -B ${{github.workspace}}/build
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
-DCMAKE_INSTALL_PREFIX=/usr
-DWIVRN_USE_SYSTEM_OPENXR=OFF
--preset everything
-DWIVRN_BUILD_DASHBOARD=OFF
-DWIVRN_BUILD_DISSECTOR=OFF
@@ -289,8 +293,8 @@ jobs:
- name: Prepare Vulkan SDK
uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944
with:
vulkan-query-version: 1.3.296.0
vulkan-components: Vulkan-Headers, Glslang, SPIRV-Tools
vulkan-query-version: 1.3.268.0
vulkan-components: Vulkan-Headers
vulkan-use-cache: true
- name: Install dependencies
@@ -303,7 +307,6 @@ jobs:
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
-DCMAKE_INSTALL_PREFIX=/usr
--preset ${{ matrix.cmake_preset }}
-DWIVRN_USE_SYSTEM_OPENXR=OFF
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
@@ -323,13 +326,6 @@ jobs:
with:
fetch-depth: 0
- name: Prepare Vulkan SDK
uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944
with:
vulkan-query-version: 1.3.296.0
vulkan-components: Glslang, SPIRV-Tools
vulkan-use-cache: true
- name: set up JDK
uses: actions/setup-java@v4
with:
@@ -463,7 +459,7 @@ jobs:
strategy:
fail-fast: false
matrix:
distro: ['plucky']
distro: ['oracular', 'plucky']
runs-on: ubuntu-24.04
container: ubuntu:${{ matrix.distro }}
steps:
+88 -32
View File
@@ -6,7 +6,6 @@ set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
@@ -18,12 +17,13 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
include(FetchContent)
include(ExternalProject)
include(GNUInstallDirs)
include("cmake/AutoOption.cmake")
option(WIVRN_USE_SYSTEM_FREETYPE "Use system FreeType" ON)
option(WIVRN_USE_SYSTEM_BOOST "Use system Boost headers" ON)
option(WIVRN_USE_SYSTEM_OPENXR "Use system OpenXR headers" ON)
option(WIVRN_USE_SYSTEMD "Use libsystemd" ON)
option(WIVRN_USE_LIBKTX "Use libktx" ${ANDROID})
auto_option(WIVRN_USE_SYSTEM_BOOST "Use system Boost headers" AUTO)
auto_option(WIVRN_USE_SYSTEM_OPENXR "Use system OpenXR headers" AUTO)
auto_option(WIVRN_USE_SYSTEMD "Use libsystemd" AUTO)
auto_option(WIVRN_USE_LIBKTX "Use libktx" AUTO)
option(WIVRN_USE_ANDROID_VALIDATION_LAYER "Download the android version of the Vulkan validation layer" OFF)
option(WIVRN_BUILD_CLIENT "Build WiVRn client" OFF)
option(WIVRN_BUILD_SERVER "Build WiVRn server" ON)
@@ -33,17 +33,16 @@ option(WIVRN_BUILD_WIVRNCTL "Build wivrnctl" ON)
option(WIVRN_BUILD_DISSECTOR "Build Wireshark dissector" OFF)
option(WIVRN_BUILD_TEST "Build test binaries" OFF)
option(WIVRN_WERROR "Treat warnings as errors" OFF)
option(WIVRN_OPTIMIZE_SHADERS "Run siprv-opt on compiled shaders" ON)
option(WIVRN_USE_NVENC "Enable nvenc (Nvidia) hardware encoder" ON)
option(WIVRN_USE_VAAPI "Enable vaapi (AMD/Intel) hardware encoder" ON)
option(WIVRN_USE_VULKAN_ENCODE "Enable vulkan video encoder" ON)
option(WIVRN_USE_X264 "Enable x264 software encoder" ON)
auto_option(WIVRN_USE_VAAPI "Enable vaapi (AMD/Intel) hardware encoder" AUTO)
auto_option(WIVRN_USE_VULKAN_ENCODE "Enable vulkan video encoder" AUTO)
auto_option(WIVRN_USE_X264 "Enable x264 software encoder" AUTO)
option(WIVRN_USE_PIPEWIRE "Enable pipewire backend" ON)
option(WIVRN_USE_PULSEAUDIO "Enable pulseaudio backend" OFF)
auto_option(WIVRN_USE_PIPEWIRE "Enable pipewire backend" AUTO)
auto_option(WIVRN_USE_PULSEAUDIO "Enable pulseaudio backend" AUTO)
set(OVR_COMPAT_SEARCH_PATH "/usr/local/lib/OpenComposite:/usr/lib/OpenComposite:/opt/OpenComposite:/opt/opencomposite:/opt/xrizer"
set(OVR_COMPAT_SEARCH_PATH "/opt/xrizer:/usr/local/lib/OpenComposite:/usr/lib/OpenComposite:/opt/OpenComposite:/opt/opencomposite"
CACHE STRING "List of places to search for the OpenVR compatibility layer, separated by :")
option(WIVRN_FEATURE_DEBUG_GUI "Enable Monado debug GUI" OFF)
@@ -65,12 +64,6 @@ endif()
option(ENABLE_COLOURED_OUTPUT "Always produce ANSI-coloured output (GNU/Clang only)." ON)
if (WIVRN_BUILD_CLIENT OR WIVRN_BUILD_SERVER OR WIVRN_BUILD_DASHBOARD OR WIVRN_BUILD_DISSECTOR)
set(NEED_COMMON TRUE)
else()
set(NEED_COMMON FALSE)
endif()
if(ENABLE_COLOURED_OUTPUT)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options(-fdiagnostics-color=always)
@@ -82,13 +75,19 @@ endif()
find_package(PkgConfig REQUIRED)
find_package(Vulkan REQUIRED)
find_package(Git)
if (NEED_COMMON AND NOT ANDROID)
if (NOT ANDROID)
find_package(OpenSSL REQUIRED)
endif()
include(VulkanVersion)
if (WIVRN_USE_SYSTEM_BOOST AND NEED_COMMON)
if (WIVRN_BUILD_DISSECTOR)
if (WIVRN_USE_SYSTEM_BOOST STREQUAL "AUTO")
if(WIVRN_BUILD_DISSECTOR)
find_package(Boost 1.84.0 COMPONENTS locale url)
else()
find_package(Boost 1.75.0 COMPONENTS locale url)
endif()
elseif(WIVRN_USE_SYSTEM_BOOST STREQUAL "ON")
if(WIVRN_BUILD_DISSECTOR)
find_package(Boost 1.84.0 REQUIRED COMPONENTS locale url)
else()
find_package(Boost 1.75.0 REQUIRED COMPONENTS locale url)
@@ -105,30 +104,72 @@ if (WIVRN_BUILD_SERVER)
message(FATAL_ERROR "No encoder selected, use at least one of WIVRN_USE_NVENC, WIVRN_USE_VAAPI, WIVRN_USE_VULKAN_ENCODE or WIVRN_USE_X264")
endif()
if (WIVRN_USE_VAAPI)
if (WIVRN_USE_VAAPI STREQUAL "AUTO")
pkg_check_modules(LIBAV IMPORTED_TARGET libavcodec libavutil libswscale libavfilter)
pkg_check_modules(LIBDRM IMPORTED_TARGET libdrm)
if (LIBAV_FOUND AND LIBDRM_FOUND)
set(WIVRN_USE_VAAPI ON)
else()
set(WIVRN_USE_VAAPI OFF)
endif()
elseif (WIVRN_USE_VAAPI)
pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET libavcodec libavutil libswscale libavfilter)
pkg_check_modules(LIBDRM REQUIRED IMPORTED_TARGET libdrm)
endif()
if (WIVRN_USE_VULKAN_ENCODE)
if (WIVRN_USE_VULKAN_ENCODE STREQUAL "AUTO")
if (Vulkan_VERSION VERSION_GREATER_EQUAL 1.3.283)
set(WIVRN_USE_VULKAN_ENCODE ON)
else()
set(WIVRN_USE_VULKAN_ENCODE OFF)
endif()
elseif(WIVRN_USE_VULKAN_ENCODE)
if (Vulkan_VERSION VERSION_LESS 1.3.283)
message(FATAL_ERROR "Vulkan video encode requires 1.3.283, found ${Vulkan_VERSION}")
endif()
endif()
if (WIVRN_USE_X264)
if (WIVRN_USE_X264 STREQUAL "AUTO")
pkg_check_modules(X264 IMPORTED_TARGET x264)
if (X264_FOUND)
set(WIVRN_USE_X264 ON)
else()
set(WIVRN_USE_X264 OFF)
endif()
elseif (WIVRN_USE_X264)
pkg_check_modules(X264 REQUIRED IMPORTED_TARGET x264)
endif()
if (WIVRN_USE_SYSTEMD)
if (WIVRN_USE_SYSTEMD STREQUAL "AUTO")
pkg_check_modules(SYSTEMD IMPORTED_TARGET libsystemd)
if (SYSTEMD_FOUND)
set(WIVRN_USE_SYSTEMD ON)
else()
set(WIVRN_USE_SYSTEMD OFF)
endif()
elseif (WIVRN_USE_SYSTEMD)
pkg_check_modules(SYSTEMD REQUIRED IMPORTED_TARGET libsystemd)
endif()
if (WIVRN_USE_PIPEWIRE)
if (WIVRN_USE_PIPEWIRE STREQUAL "AUTO")
pkg_check_modules(libpipewire IMPORTED_TARGET libpipewire-0.3)
if (libpipewire_FOUND)
set(WIVRN_USE_PIPEWIRE ON)
else()
set(WIVRN_USE_PIPEWIRE OFF)
endif()
elseif (WIVRN_USE_PIPEWIRE)
pkg_check_modules(libpipewire REQUIRED IMPORTED_TARGET libpipewire-0.3)
endif()
if (WIVRN_USE_PULSEAUDIO)
if (WIVRN_USE_PULSEAUDIO STREQUAL "AUTO")
pkg_check_modules(libpulse IMPORTED_TARGET libpulse)
if (libpulse_FOUND)
set(WIVRN_USE_PULSEAUDIO ON)
else()
set(WIVRN_USE_PULSEAUDIO OFF)
endif()
elseif (WIVRN_USE_PULSEAUDIO)
pkg_check_modules(libpulse REQUIRED IMPORTED_TARGET libpulse)
endif()
@@ -174,11 +215,23 @@ if (WIVRN_BUILD_CLIENT OR WIVRN_BUILD_DASHBOARD)
find_package(Gettext REQUIRED)
endif()
if (WIVRN_BUILD_CLIENT)
if (WIVRN_USE_LIBKTX STREQUAL "AUTO")
if (ANDROID)
set(WIVRN_USE_LIBKTX ON)
else()
set(WIVRN_USE_LIBKTX OFF)
endif()
endif()
endif()
if (WIVRN_BUILD_CLIENT AND NOT ANDROID)
pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET libavcodec libavutil libswscale libavfilter)
find_package(Fontconfig REQUIRED)
if (WIVRN_USE_SYSTEM_OPENXR)
if (WIVRN_USE_SYSTEM_OPENXR STREQUAL "AUTO")
find_package(OpenXR 1.1.48)
elseif(WIVRN_USE_SYSTEM_OPENXR STREQUAL "ON")
find_package(OpenXR 1.1.48 REQUIRED)
endif()
@@ -192,7 +245,9 @@ if(ANDROID)
endif()
if (WIVRN_BUILD_DISSECTOR)
if (WIVRN_USE_SYSTEM_OPENXR)
if (WIVRN_USE_SYSTEM_OPENXR STREQUAL "AUTO")
find_package(OpenXR 1.1.48)
elseif(WIVRN_USE_SYSTEM_OPENXR STREQUAL "ON")
find_package(OpenXR 1.1.48 REQUIRED)
endif()
find_package(Wireshark REQUIRED)
@@ -222,8 +277,9 @@ FetchContent_Declare(spdlog EXCLUDE_FROM_ALL SYSTEM URL https://github.co
URL_HASH SHA256=1586508029a7d0670dfcb2d97575dcdc242d3868a259742b69f100801ab4e16b)
FetchContent_Declare(stb EXCLUDE_FROM_ALL SYSTEM URL https://github.com/nothings/stb/archive/013ac3beddff3dbffafd5177e7972067cd2b5083.zip
URL_HASH SHA256=b7f476902bbef1b30f8ecc2d9d95c459c32302c8b559d09b589b5955463b7af8)
FetchContent_Declare(libktx EXCLUDE_FROM_ALL SYSTEM URL https://github.com/KhronosGroup/KTX-Software/archive/refs/tags/v4.4.0.tar.gz
URL_HASH SHA256=3585d76edcdcbe3a671479686f8c81c1c10339f419e4b02a9a6f19cc6e4e0612)
FetchContent_Declare(libktx EXCLUDE_FROM_ALL SYSTEM
GIT_REPOSITORY https://github.com/KhronosGroup/KTX-Software
GIT_TAG 91ace88675ac59a97e55d0378a6602a9ae6b98bd)
FetchContent_Declare(implot EXCLUDE_FROM_ALL SYSTEM URL https://github.com/epezent/implot/archive/3da8bd34299965d3b0ab124df743fe3e076fa222.zip
URL_HASH SHA256=e9b439a94aa6f09fcf12ed9c2cd784efe5e99e96242122aa683e690b29f7a59f)
file(GLOB IMGUI_PATCHES CONFIGURE_DEPENDS patches/imgui/*)
@@ -249,7 +305,7 @@ FetchContent_Declare(monado
)
add_subdirectory(external)
if (NEED_COMMON)
if (WIVRN_BUILD_CLIENT OR WIVRN_BUILD_SERVER OR WIVRN_BUILD_DASHBOARD OR WIVRN_BUILD_DISSECTOR)
add_subdirectory(common)
endif()
Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 930 B

+32
View File
@@ -0,0 +1,32 @@
Snapdragon(TM) Game Super Resolution
Copyright (c) 2023, Qualcomm Innovation Center, Inc. All rights reserved.
https://github.com/SnapdragonStudios/snapdragon-gsr
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
SPDX-License-Identifier: BSD-3-Clause
+32 -88
View File
@@ -4,7 +4,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.12.1'
classpath 'com.android.tools.build:gradle:8.7.3'
}
}
@@ -17,86 +17,45 @@ allprojects {
apply plugin: 'com.android.application'
task "generatePngs"() {
group = 'Custom'
import javax.inject.Inject
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.*
import org.gradle.api.file.DirectoryProperty
import org.gradle.process.ExecOperations
mkdir layout.buildDirectory.dir('generated_resources')
["mipmap-mdpi", "mipmap-hdpi", "mipmap-xhdpi", "mipmap-xxhdpi", "mipmap-xxxhdpi", ].each {
mkdir layout.buildDirectory.dir("generated_resources/${it}")
}
abstract class GeneratePngsTask extends DefaultTask {
@Inject
abstract ExecOperations getExecOps()
def css = project.hasProperty('wivrn_css') ? project.wivrn_css: "images/wivrn-local.css"
@InputFile
abstract RegularFileProperty getSvg()
exec {
executable = 'rsvg-convert'
args = [ "images/wivrn.svg", "-w", "48", "-h", "48", "-o", layout.buildDirectory.file('generated_resources/mipmap-mdpi/ic_wivrn_launcher.png').get().asFile, '--stylesheet=' + css ]
}
@InputFile
@Optional
abstract RegularFileProperty getCss()
exec {
executable = 'rsvg-convert'
args = [ "images/wivrn.svg", "-w", "72", "-h", "72", "-o", layout.buildDirectory.file('generated_resources/mipmap-hdpi/ic_wivrn_launcher.png').get().asFile, '--stylesheet=' + css ]
}
@OutputDirectory
abstract DirectoryProperty getOutputDir()
exec {
executable = 'rsvg-convert'
args = [ "images/wivrn.svg", "-w", "96", "-h", "96", "-o", layout.buildDirectory.file('generated_resources/mipmap-xhdpi/ic_wivrn_launcher.png').get().asFile, '--stylesheet=' + css ]
}
@TaskAction
void generate() {
def outDir = getOutputDir().get().asFile
outDir.mkdirs()
exec {
executable = 'rsvg-convert'
args = [ "images/wivrn.svg", "-w", "144", "-h", "144", "-o", layout.buildDirectory.file('generated_resources/mipmap-xxhdpi/ic_wivrn_launcher.png').get().asFile, '--stylesheet=' + css ]
}
// Map of density → size
def dpiConfigs = [
"mipmap-mdpi" : 48,
"mipmap-hdpi" : 72,
"mipmap-xhdpi" : 96,
"mipmap-xxhdpi" : 144,
"mipmap-xxxhdpi": 192
]
def cssFile = getCss().isPresent() ? getCss().get().asFile : null
dpiConfigs.each { dpi, size ->
def dpiDir = new File(outDir, dpi)
dpiDir.mkdirs()
def outputFile = new File(dpiDir, "ic_wivrn_launcher.png")
def argsList = [
getSvg().get().asFile.absolutePath,
"-w", size.toString(),
"-h", size.toString(),
"-o", outputFile.absolutePath
]
if (cssFile != null) {
argsList.add("--stylesheet=${cssFile.absolutePath}")
}
execOps.exec {
executable = "rsvg-convert"
args = argsList
}
}
exec {
executable = 'rsvg-convert'
args = [ "images/wivrn.svg", "-w", "192", "-h", "192", "-o", layout.buildDirectory.file('generated_resources/mipmap-xxxhdpi/ic_wivrn_launcher.png').get().asFile, '--stylesheet=' + css ]
}
}
tasks.register("generatePngs", GeneratePngsTask) {
group = "Custom"
// configure defaults
svg.set(layout.projectDirectory.file("images/wivrn.svg"))
outputDir.set(layout.buildDirectory.dir("generated_resources"))
if (project.hasProperty("wivrn_css")) {
css.set(layout.projectDirectory.file(project.wivrn_css))
} else {
css.set(layout.projectDirectory.file("images/wivrn-local.css"))
}
}
android {
namespace = "org.meumeu.wivrn"
ndkVersion = "28.1.13356709"
namespace "org.meumeu.wivrn"
ndkVersion "28.1.13356709"
lint {
disable += "ExpiredTargetSdkVersion"
@@ -124,7 +83,6 @@ android {
'-DCMAKE_ANDROID_NDK_VERSION=' + ndkVersion,
'-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON',
'-DCMAKE_EXPORT_COMPILE_COMMANDS=ON',
'-DWIVRN_USE_SYSTEM_BOOST=OFF',
'-DWIVRN_USE_SYSTEM_FREETYPE=OFF',
'-DWIVRN_BUILD_CLIENT=ON',
'-DWIVRN_BUILD_SERVER=OFF',
@@ -147,7 +105,7 @@ android {
keyAlias "default_key"
storePassword signingKeyPassword // Set in gradle.properties
keyPassword signingKeyPassword
enableV2Signing = true
enableV2Signing true
}
}
}
@@ -155,7 +113,7 @@ android {
buildTypes {
if (project.hasProperty("signingKeyPassword")) {
release {
signingConfig = signingConfigs.release
signingConfig signingConfigs.release
}
}
@@ -224,7 +182,7 @@ android {
externalNativeBuild {
cmake {
version = '3.30.3'
version '3.30.3'
path 'CMakeLists.txt'
}
}
@@ -249,18 +207,4 @@ android {
}
}
}
buildTypes.all { variant ->
sourceSets {
"${variant.name}" {
jniLibs.srcDirs layout.buildDirectory.dir("libs${variant.name.capitalize()}")
}
}
externalNativeBuild{
cmake {
arguments '-DCMAKE_ANDROID_LIB_DIRECTORIES=' + layout.buildDirectory.dir("libs${variant.name.capitalize()}").get().asFile
}
}
}
}
+19 -15
View File
@@ -13,7 +13,7 @@ if (WIVRN_USE_LIBKTX)
FetchContent_MakeAvailable(libktx)
endif()
if (NOT WIVRN_USE_SYSTEM_BOOST)
if (NOT BOOST_FOUND)
FetchContent_MakeAvailable(boost)
endif()
@@ -51,7 +51,7 @@ if(ANDROID)
else()
add_executable(wivrn)
if (WIVRN_USE_SYSTEM_OPENXR)
if (OpenXR_FOUND)
target_link_libraries(wivrn OpenXR::openxr_loader OpenXR::headers)
else()
FetchContent_MakeAvailable(openxr_loader)
@@ -89,7 +89,7 @@ file(GLOB LOCAL_SOURCE CONFIGURE_DEPENDS
file(GLOB_RECURSE VULKAN_SHADERS CONFIGURE_DEPENDS "*.glsl")
target_sources(wivrn PRIVATE ${LOCAL_SOURCE} ${VULKAN_SHADERS})
wivrn_compile_glsl(wivrn SHADERS ${VULKAN_SHADERS})
wivrn_compile_glsl(wivrn ${VULKAN_SHADERS})
target_link_libraries(wivrn
Boost::locale
@@ -166,14 +166,14 @@ khronos_validation.enables = VK_VALIDATION_FEATURE_ENABLE_THREAD_SAFETY_EXT
endif()
if(USE_ANDROID_VALIDATION_LAYER)
set(VVL_VERSION "1.4.321.0")
set(VVL_VERSION "1.3.231.1")
if(NOT EXISTS ${CMAKE_BINARY_DIR}/Vulkan-ValidationLayers-${VVL_VERSION}.zip)
if (EXISTS ${CMAKE_SOURCE_DIR}/Vulkan-ValidationLayers-${VVL_VERSION}.zip)
file(CREATE_LINK ${CMAKE_SOURCE_DIR}/Vulkan-ValidationLayers-${VVL_VERSION}.zip ${CMAKE_BINARY_DIR}/Vulkan-ValidationLayers-${VVL_VERSION}.zip SYMBOLIC)
else()
file(DOWNLOAD https://github.com/KhronosGroup/Vulkan-ValidationLayers/releases/download/vulkan-sdk-${VVL_VERSION}/android-binaries-${VVL_VERSION}.zip ${CMAKE_BINARY_DIR}/Vulkan-ValidationLayers-${VVL_VERSION}.zip
EXPECTED_HASH SHA256=75f2881ba7af0507c8cec13b4bf6c95556c6333485cdb8be41f608fccf762128)
file(DOWNLOAD https://github.com/KhronosGroup/Vulkan-ValidationLayers/releases/download/sdk-${VVL_VERSION}/android-binaries-${VVL_VERSION}.zip ${CMAKE_BINARY_DIR}/Vulkan-ValidationLayers-${VVL_VERSION}.zip
EXPECTED_HASH SHA256=eec3a54222d6d33d4f787a13a45c60ac5b9e8d7bf795fc41e4242354a02e34ba)
endif()
endif()
@@ -181,12 +181,12 @@ if(USE_ANDROID_VALIDATION_LAYER)
file(ARCHIVE_EXTRACT INPUT ${CMAKE_BINARY_DIR}/Vulkan-ValidationLayers-${VVL_VERSION}.zip DESTINATION ${CMAKE_BINARY_DIR}/Vulkan-ValidationLayer)
file(COPY
${CMAKE_BINARY_DIR}/Vulkan-ValidationLayer/android-binaries-${VVL_VERSION}/${CMAKE_ANDROID_ARCH_ABI}
DESTINATION ${CMAKE_ANDROID_LIB_DIRECTORIES})
else()
# silence "Manually-specified variables were not used by the project" warning
set(_unused ${CMAKE_ANDROID_LIB_DIRECTORIES})
add_library(vvl1 SHARED IMPORTED)
set_property(TARGET vvl1 PROPERTY IMPORTED_LOCATION ${CMAKE_BINARY_DIR}/Vulkan-ValidationLayer/${CMAKE_ANDROID_ARCH_ABI}/libVkLayer_khronos_validation.so)
add_library(vvl2 SHARED IMPORTED)
set_property(TARGET vvl2 PROPERTY IMPORTED_LOCATION ${CMAKE_BINARY_DIR}/Vulkan-ValidationLayer/${CMAKE_ANDROID_ARCH_ABI}/libc++_shared.so)
target_link_libraries(wivrn vvl1 vvl2) # Hack to get gradle to package the validation layer in the APK
endif()
@@ -237,7 +237,7 @@ add_custom_command(OUTPUT ${ASSETS_DIR}/wivrn.png
DEPENDS ${IMG_SRC_DIR}/wivrn.svg ${WIVRN_CSS_ABS})
add_custom_target(assets ALL DEPENDS
${ASSETS_DIR}/wivrn.png)
${ASSETS_DIR}/wivrn.png)
add_dependencies(wivrn assets)
@@ -247,6 +247,10 @@ if(ANDROID)
COMMAND ${TOKTX} --encode astc --astc_blk_d 4x4 --astc_quality 100 --genmipmap ${ASSETS_DIR}/wivrn.ktx2 ${ASSETS_DIR}/wivrn.png
DEPENDS ${ASSETS_DIR}/wivrn.png)
add_custom_command(OUTPUT ${ASSETS_DIR}/default_icon.ktx2
COMMAND ${TOKTX} --encode astc --astc_blk_d 4x4 --astc_quality 100 --genmipmap ${ASSETS_DIR}/wivrn-pride.ktx2 ${ASSETS_DIR}/default_icon.png
DEPENDS ${ASSETS_DIR}/default_icon.png)
add_custom_command(OUTPUT ${ASSETS_DIR}/WoodFloor051_1K-JPG_Color.ktx2
COMMAND ${TOKTX} --encode astc --astc_blk_d 12x12 --astc_quality 100 --genmipmap ${ASSETS_DIR}/WoodFloor051_1K-JPG_Color.ktx2 ${AST_SRC_DIR}/WoodFloor051_1K-JPG_Color.jpg
DEPENDS ${AST_SRC_DIR}/WoodFloor051_1K-JPG_Color.jpg)
@@ -258,8 +262,8 @@ if(ANDROID)
add_custom_target(assets-android ALL DEPENDS
${ASSETS_DIR}/wivrn.ktx2
${ASSETS_DIR}/WoodFloor051_1K-JPG_Color.ktx2
${ASSETS_DIR}/vr_splash.png
)
${ASSETS_DIR}/vr_splash.png)
add_dependencies(assets-android assets)
add_dependencies(wivrn assets-android)
endif()
+163 -135
View File
@@ -18,7 +18,7 @@
*/
#include "application.h"
#include "asset.h"
#include "hardware.h"
#include "openxr/openxr.h"
#include "scene.h"
@@ -26,23 +26,18 @@
#include "spdlog/spdlog.h"
#include "utils/contains.h"
#include "utils/files.h"
#include "utils/i18n.h"
#include "vk/check.h"
#include "wifi_lock.h"
#include "wivrn_packets.h"
#include "xr/actionset.h"
#include "xr/check.h"
#include "xr/htc_exts.h"
#include "xr/htc_face_tracker.h"
#include "xr/meta_body_tracking_fidelity.h"
#include "xr/to_string.h"
#include "xr/xr.h"
#include <algorithm>
#include <boost/locale.hpp>
#include <boost/url/parse.hpp>
#include <chrono>
#include <ctype.h>
#include <exception>
#include <magic_enum.hpp>
#include <string>
#include <thread>
#include <vector>
@@ -72,6 +67,7 @@ struct interaction_profile
std::string profile_name;
std::vector<std::string> required_extensions;
XrVersion min_version = XR_MAKE_VERSION(1, 0, 0);
XrVersion max_version = XR_MAKE_VERSION(2, 0, 0); // exclusive
std::vector<std::string> input_sources;
bool available;
};
@@ -138,7 +134,8 @@ static std::vector<interaction_profile> interaction_profiles{
},
interaction_profile{
.profile_name = "/interaction_profiles/facebook/touch_controller_pro",
.required_extensions = {XR_FB_TOUCH_CONTROLLER_PRO_EXTENSION_NAME},
.required_extensions = {"XR_FB_touch_controller_pro"},
.max_version = XR_MAKE_VERSION(1, 1, 0),
.input_sources = {
"/user/hand/left/output/haptic",
"/user/hand/left/output/haptic_trigger_fb",
@@ -250,7 +247,8 @@ static std::vector<interaction_profile> interaction_profiles{
},
interaction_profile{
.profile_name = "/interaction_profiles/meta/touch_controller_plus",
.required_extensions = {XR_META_TOUCH_CONTROLLER_PLUS_EXTENSION_NAME},
.required_extensions = {"XR_META_touch_controller_plus"},
.max_version = XR_MAKE_VERSION(1, 1, 0),
.input_sources = {
"/user/hand/left/output/haptic",
"/user/hand/right/output/haptic",
@@ -350,7 +348,7 @@ static std::vector<interaction_profile> interaction_profiles{
},
interaction_profile{
.profile_name = "/interaction_profiles/bytedance/pico_neo3_controller",
.required_extensions = {XR_BD_CONTROLLER_INTERACTION_EXTENSION_NAME},
.required_extensions = {"XR_BD_controller_interaction"},
.input_sources = {
"/user/hand/left/output/haptic",
"/user/hand/right/output/haptic",
@@ -393,7 +391,7 @@ static std::vector<interaction_profile> interaction_profiles{
},
interaction_profile{
.profile_name = "/interaction_profiles/bytedance/pico4_controller",
.required_extensions = {XR_BD_CONTROLLER_INTERACTION_EXTENSION_NAME},
.required_extensions = {"XR_BD_controller_interaction"},
.input_sources = {
"/user/hand/left/output/haptic",
"/user/hand/right/output/haptic",
@@ -436,7 +434,7 @@ static std::vector<interaction_profile> interaction_profiles{
},
interaction_profile{
.profile_name = "/interaction_profiles/bytedance/pico4s_controller",
.required_extensions = {XR_BD_CONTROLLER_INTERACTION_EXTENSION_NAME},
.required_extensions = {"XR_BD_controller_interaction"},
.input_sources = {
"/user/hand/left/output/haptic",
"/user/hand/right/output/haptic",
@@ -479,7 +477,7 @@ static std::vector<interaction_profile> interaction_profiles{
},
interaction_profile{
.profile_name = "/interaction_profiles/htc/vive_focus3_controller",
.required_extensions = {XR_HTC_VIVE_FOCUS3_CONTROLLER_INTERACTION_EXTENSION_NAME},
.required_extensions = {"XR_HTC_vive_focus3_controller_interaction"},
.input_sources = {
"/user/hand/left/output/haptic",
"/user/hand/right/output/haptic",
@@ -521,7 +519,7 @@ static std::vector<interaction_profile> interaction_profiles{
},
interaction_profile{
.profile_name = "/interaction_profiles/ext/hand_interaction_ext",
.required_extensions = {XR_EXT_HAND_INTERACTION_EXTENSION_NAME},
.required_extensions = {"XR_EXT_hand_interaction"},
.input_sources = {
"/user/hand/left/input/aim/pose",
"/user/hand/left/input/grip/pose",
@@ -550,14 +548,11 @@ static std::vector<interaction_profile> interaction_profiles{
},
interaction_profile{
.profile_name = "/interaction_profiles/htc/vive_xr_tracker",
.required_extensions = {
XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME,
XR_HTC_PATH_ENUMERATION_EXTENSION_NAME,
},
.required_extensions = {"XR_HTC_vive_xr_tracker_interaction", "XR_HTC_path_enumeration"},
},
interaction_profile{
.profile_name = "/interaction_profiles/ext/eye_gaze_interaction",
.required_extensions = {XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME},
.required_extensions = {"XR_EXT_eye_gaze_interaction"},
.input_sources = {
"/user/eyes_ext/input/gaze_ext/pose",
},
@@ -654,7 +649,6 @@ VkBool32 application::vulkan_debug_report_callback(
}
#ifndef NDEBUG
bool my_error = true;
if (level >= spdlog::level::warn)
{
bool validation_layer_found = false;
@@ -665,13 +659,10 @@ VkBool32 application::vulkan_debug_report_callback(
if (validation_layer_found && i.library != "libVkLayer_khronos_validation.so")
spdlog::log(level, "{:#016x}: {} + {:#x}", i.pc, i.library, i.pc - i.library_base);
if (i.library == "libopenxr_loader.so")
my_error = false;
}
}
if (level >= spdlog::level::err and my_error)
if (level >= spdlog::level::err)
abort();
#endif
@@ -726,13 +717,15 @@ void application::initialize_vulkan()
spdlog::info("Using Vulkan validation layer");
layers.push_back("VK_LAYER_KHRONOS_validation");
}
bool debug_report_found = false;
bool debug_utils_found = false;
#endif
std::vector<const char *> instance_extensions{};
std::unordered_set<std::string_view> optional_device_extensions{};
#ifndef NDEBUG
bool debug_report_found = false;
bool debug_utils_found = false;
#endif
spdlog::info("Available Vulkan instance extensions:");
std::vector<std::pair<std::string, int>> extensions;
for (vk::ExtensionProperties & i: vk_context.enumerateInstanceExtensionProperties(nullptr))
@@ -741,27 +734,28 @@ void application::initialize_vulkan()
#ifndef NDEBUG
if (!strcmp(i.extensionName, VK_EXT_DEBUG_REPORT_EXTENSION_NAME))
{
debug_report_found = true;
instance_extensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
}
if (!strcmp(i.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) and
guess_model() != model::oculus_quest) // Quest 1 lies, the extension won't load
{
if (!strcmp(i.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME))
debug_utils_found = true;
instance_extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
}
#endif
}
std::ranges::sort(extensions);
for (const auto & [extension_name, spec_version]: extensions)
spdlog::info(" {} (version {})", extension_name, spec_version);
#ifndef NDEBUG
if (debug_utils_found && debug_report_found)
{
// debug_extensions_found = true;
// spdlog::info("Using debug extensions");
instance_extensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
// instance_extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
}
#endif
vk_device_extensions.push_back(VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME);
optional_device_extensions.emplace(VK_IMG_FILTER_CUBIC_EXTENSION_NAME);
optional_device_extensions.emplace(VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME);
optional_device_extensions.emplace(VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME);
#ifdef __ANDROID__
vk_device_extensions.push_back(VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME);
@@ -880,7 +874,6 @@ void application::initialize_vulkan()
.ppEnabledExtensionNames = vk_device_extensions.data(),
.pEnabledFeatures = &device_features,
},
vk::PhysicalDeviceFragmentShadingRateFeaturesKHR{},
#ifdef __ANDROID__
vk::PhysicalDeviceSamplerYcbcrConversionFeaturesKHR{
.samplerYcbcrConversion = VK_TRUE,
@@ -888,22 +881,6 @@ void application::initialize_vulkan()
#endif
};
if (utils::contains(vk_device_extensions, VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME) and
utils::contains(vk_device_extensions, VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME))
{
auto [feat, fragment_feat] = vk_physical_device.getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceFragmentShadingRateFeaturesKHR>();
auto & create_feat = device_create_info.get<vk::PhysicalDeviceFragmentShadingRateFeaturesKHR>();
create_feat.primitiveFragmentShadingRate = fragment_feat.primitiveFragmentShadingRate;
create_feat.attachmentFragmentShadingRate = fragment_feat.attachmentFragmentShadingRate;
spdlog::info("Fragment shading rate features: primitive={} attachment={}",
create_feat.primitiveFragmentShadingRate,
create_feat.attachmentFragmentShadingRate);
}
else
{
device_create_info.unlink<vk::PhysicalDeviceFragmentShadingRateFeaturesKHR>();
}
vk_device = xr_system_id.create_device(vk_physical_device, device_create_info.get());
*vk_queue.lock() = vk_device.getQueue(vk_queue_family_index, 0);
@@ -925,16 +902,10 @@ void application::initialize_vulkan()
pipeline_cache = vk::raii::PipelineCache(vk_device, pipeline_cache_info);
allocator.emplace(VmaAllocatorCreateInfo{
.physicalDevice = *vk_physical_device,
.device = *vk_device,
.instance = *vk_instance,
},
#ifndef NDEBUG
debug_utils_found
#else
false
#endif
);
.physicalDevice = *vk_physical_device,
.device = *vk_device,
.instance = *vk_instance,
});
}
void application::log_views()
@@ -981,6 +952,8 @@ void application::initialize_actions()
{
spdlog::debug("Initializing actions");
auto * htc_body = std::get_if<xr::htc_body_tracker>(&body_tracker);
// Build an action set with all possible input sources
std::vector<XrActionSet> action_sets;
xr_actionset = xr::actionset(xr_instance, "all_actions", "All actions");
@@ -994,8 +967,7 @@ void application::initialize_actions()
std::vector<std::string> sources;
for (auto & profile: interaction_profiles)
{
profile.available = std::ranges::all_of(profile.required_extensions, [&](auto & ext) { return xr_instance.has_extension(ext); }) and
profile.min_version <= api_version;
profile.available = utils::contains_all(xr_extensions, profile.required_extensions) and profile.min_version <= api_version and profile.max_version > api_version;
if (profile.profile_name.ends_with("khr/simple_controller"))
{
@@ -1036,15 +1008,15 @@ void application::initialize_actions()
}
if (add_palms)
{
if ((api_version >= XR_MAKE_VERSION(1, 1, 0) or xr_instance.has_extension(XR_KHR_MAINTENANCE1_EXTENSION_NAME)) //
and utils::contains(profile.input_sources, "/user/hand/left/input/grip/pose") //
if ((api_version >= XR_MAKE_VERSION(1, 1, 0) or utils::contains(xr_extensions, XR_KHR_MAINTENANCE1_EXTENSION_NAME)) //
and utils::contains(profile.input_sources, "/user/hand/left/input/grip/pose") //
and not utils::contains(profile.input_sources, "/user/hand/left/input/grip_surface/pose"))
{
spdlog::info("Adding grip_surface/pose for interaction profile {}", profile.profile_name);
profile.input_sources.push_back("/user/hand/left/input/grip_surface/pose");
profile.input_sources.push_back("/user/hand/right/input/grip_surface/pose");
}
else if (xr_instance.has_extension(XR_EXT_PALM_POSE_EXTENSION_NAME) //
else if (utils::contains(xr_extensions, XR_EXT_PALM_POSE_EXTENSION_NAME) //
and utils::contains(profile.input_sources, "/user/hand/left/input/grip/pose") //
and not utils::contains(profile.input_sources, "/user/hand/left/input/palm_ext/pose"))
{
@@ -1055,15 +1027,14 @@ void application::initialize_actions()
}
// Dynamically add VIVE XR Trackers to the profile if available
if (utils::contains(profile.required_extensions, XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME) and
xr_instance.has_extension(XR_HTC_PATH_ENUMERATION_EXTENSION_NAME))
if (htc_body && utils::contains(profile.required_extensions, XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME))
{
XrPath tracker_profile = xr_instance.string_to_path("/interaction_profiles/htc/vive_xr_tracker");
for (const auto & user_path: xr_instance.enumerate_paths_for_interaction_profile(tracker_profile))
for (const auto & user_path: htc_body->get_paths())
{
generic_trackers.emplace_back(user_path, nullptr);
for (const auto & input_path: xr_instance.enumerate_paths_for_interaction_profile(tracker_profile, user_path))
profile.input_sources.push_back(xr_instance.path_to_string(user_path) + xr_instance.path_to_string(input_path));
for (const auto & input_path: htc_body->get_paths(user_path))
{
profile.input_sources.push_back(path_to_string(user_path) + path_to_string(input_path));
}
}
}
@@ -1111,14 +1082,8 @@ void application::initialize_actions()
spaces[size_t(xr::spaces::poke_right)] = xr_session.create_action_space(a);
else if (name == "/user/eyes_ext/input/gaze_ext/pose")
spaces[size_t(xr::spaces::eye_gaze)] = xr_session.create_action_space(a);
else if (name.contains("/input/entity_htc/pose"))
{
for (auto & [path, action]: generic_trackers)
{
if (name.starts_with(xr_instance.path_to_string(path)))
action = xr_session.create_action_space(a);
}
}
else if (name.contains("/input/entity_htc/pose") && htc_body)
htc_body->add(xr_session.create_action_space(a));
}
// Build an action set for each scene
@@ -1155,7 +1120,7 @@ void application::initialize_actions()
xr_bindings.push_back(XrActionSuggestedBinding{
.action = a,
.binding = xr_instance.string_to_path(k.input_source)});
.binding = string_to_path(k.input_source)});
}
}
}
@@ -1172,7 +1137,7 @@ void application::initialize_actions()
for (const auto & name: profile.input_sources)
{
xr_bindings.push_back({actions_by_name[name], xr_instance.string_to_path(name)});
xr_bindings.push_back({actions_by_name[name], string_to_path(name)});
}
try
@@ -1192,7 +1157,7 @@ void application::initialize()
{
// LogLayersAndExtensions
assert(!xr_instance);
std::vector<std::string> xr_extensions;
xr_extensions.clear();
// Required extensions
xr_extensions.push_back(XR_KHR_CONVERT_TIMESPEC_TIME_EXTENSION_NAME);
@@ -1265,16 +1230,21 @@ void application::initialize()
spdlog::info(" Orientation tracking: {}", (bool)properties.trackingProperties.orientationTracking);
spdlog::info(" Position tracking: {}", (bool)properties.trackingProperties.positionTracking);
spdlog::info(" Hand tracking support: {}", xr_system_id.hand_tracking_supported());
if (utils::contains(xr_extensions, XR_EXT_HAND_TRACKING_EXTENSION_NAME))
{
XrSystemHandTrackingPropertiesEXT hand_tracking_properties = xr_system_id.hand_tracking_properties();
spdlog::info(" Hand tracking support: {}", (bool)hand_tracking_properties.supportsHandTracking);
hand_tracking_supported = hand_tracking_properties.supportsHandTracking;
}
if (xr_instance.has_extension(XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME))
if (utils::contains(xr_extensions, XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME))
{
XrSystemEyeGazeInteractionPropertiesEXT eye_gaze_properties = xr_system_id.eye_gaze_interaction_properties();
spdlog::info(" Eye gaze support: {}", (bool)eye_gaze_properties.supportsEyeGazeInteraction);
eye_gaze_supported = eye_gaze_properties.supportsEyeGazeInteraction;
}
if (xr_instance.has_extension(XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME))
if (utils::contains(xr_extensions, XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME))
{
spdlog::info(" OpenXR post-processing extension support: true");
openxr_post_processing_supported = true;
@@ -1282,39 +1252,23 @@ void application::initialize()
switch (xr_system_id.passthrough_supported())
{
case xr::passthrough_type::none:
case xr::system::passthrough_type::no_passthrough:
spdlog::info(" Passthrough: not supported");
break;
case xr::passthrough_type::bw:
case xr::system::passthrough_type::bw:
spdlog::info(" Passthrough: black and white");
break;
case xr::passthrough_type::color:
case xr::system::passthrough_type::color:
spdlog::info(" Passthrough: color");
break;
}
spdlog::info(" Face tracker: {}", magic_enum::enum_name(xr_system_id.face_tracker_supported()));
spdlog::info(" Body tracker: {}", magic_enum::enum_name(xr_system_id.body_tracker_supported()));
// Log view configurations and blend modes
log_views();
initialize_vulkan();
xr_session = xr::session(xr_instance, xr_system_id, vk_instance, vk_physical_device, vk_device, vk_queue, vk_queue_family_index);
spaces[size_t(xr::spaces::view)] = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_VIEW);
spaces[size_t(xr::spaces::world)] = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_STAGE);
config.emplace(xr_system_id);
// HTC face tracker fails if created later
// we can destroy it right away, it actually stores static handles
if (xr_system_id.face_tracker_supported() == xr::face_tracker_type::htc)
{
auto props = xr_system_id.htc_face_tracking_properties();
xr::htc_face_tracker(xr_instance, xr_session, props.supportEyeFacialTracking, props.supportLipFacialTracking);
}
xr_session = xr::session(xr_instance, xr_system_id, vk_instance, vk_physical_device, vk_device, vk_queue_family_index);
{
auto spaces = xr_session.get_reference_spaces();
@@ -1323,6 +1277,70 @@ void application::initialize()
spdlog::info(" {}", xr::to_string(i));
}
spaces[size_t(xr::spaces::view)] = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_VIEW);
spaces[size_t(xr::spaces::world)] = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_STAGE);
config.emplace(xr_system_id);
if (hand_tracking_supported)
{
left_hand = xr_session.create_hand_tracker(XR_HAND_LEFT_EXT);
right_hand = xr_session.create_hand_tracker(XR_HAND_RIGHT_EXT);
}
if (utils::contains(xr_extensions, XR_FB_FACE_TRACKING2_EXTENSION_NAME))
{
XrSystemFaceTrackingProperties2FB fb_face2_properties = xr_system_id.fb_face_tracking2_properties();
spdlog::info(" FB face tracking support: {}", (bool)fb_face2_properties.supportsVisualFaceTracking);
if (fb_face2_properties.supportsVisualFaceTracking)
face_tracker.emplace<xr::fb_face_tracker2>(xr_instance, xr_session);
}
if (std::holds_alternative<std::monostate>(face_tracker) && utils::contains(xr_extensions, XR_HTC_FACIAL_TRACKING_EXTENSION_NAME))
{
XrSystemFacialTrackingPropertiesHTC htc_face_properties = xr_system_id.htc_face_tracking_properties();
spdlog::info(" HTC eye tracking support: {}", (bool)htc_face_properties.supportEyeFacialTracking);
spdlog::info(" HTC lip tracking support: {}", (bool)htc_face_properties.supportLipFacialTracking);
if (htc_face_properties.supportEyeFacialTracking || htc_face_properties.supportLipFacialTracking)
face_tracker.emplace<xr::htc_face_tracker>(xr_instance, xr_session, htc_face_properties.supportEyeFacialTracking, htc_face_properties.supportLipFacialTracking);
}
if (std::holds_alternative<std::monostate>(face_tracker) && eye_gaze_supported)
{
switch (guess_model())
{
case model::pico_4_pro:
case model::pico_4_enterprise:
spdlog::info(" PICO face tracking support: true");
face_tracker.emplace<xr::pico_face_tracker>(xr_instance, xr_session);
break;
default:
break;
}
}
if (utils::contains_all(xr_extensions, std::array{XR_FB_BODY_TRACKING_EXTENSION_NAME, XR_META_BODY_TRACKING_FULL_BODY_EXTENSION_NAME, XR_META_BODY_TRACKING_FIDELITY_EXTENSION_NAME}))
{
XrSystemBodyTrackingPropertiesFB fb_body_properties = xr_system_id.fb_body_tracking_properties();
spdlog::info(" FB body tracking support: {}", (bool)fb_body_properties.supportsBodyTracking);
if (fb_body_properties.supportsBodyTracking)
body_tracker.emplace<xr::fb_body_tracker>(xr_instance, xr_session);
}
if (std::holds_alternative<std::monostate>(body_tracker) && utils::contains_all(xr_extensions, std::array{XR_HTC_PATH_ENUMERATION_EXTENSION_NAME, XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME}))
{
spdlog::info(" HTC body tracking support: true");
body_tracker.emplace<xr::htc_body_tracker>(xr_instance, xr_session);
}
if (std::holds_alternative<std::monostate>(body_tracker) && utils::contains(xr_extensions, XR_BD_BODY_TRACKING_EXTENSION_NAME))
{
XrSystemBodyTrackingPropertiesBD bd_body_properties = xr_system_id.bd_body_tracking_properties();
spdlog::info(" PICO body tracking support: {}", (bool)bd_body_properties.supportsBodyTracking);
if (bd_body_properties.supportsBodyTracking)
body_tracker.emplace<xr::pico_body_tracker>(xr_instance, xr_session);
}
vk::CommandPoolCreateInfo cmdpool_create_info;
cmdpool_create_info.queueFamilyIndex = vk_queue_family_index;
cmdpool_create_info.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer;
@@ -1330,47 +1348,50 @@ void application::initialize()
vk_cmdpool = vk::raii::CommandPool{vk_device, cmdpool_create_info};
initialize_actions();
load_locale();
}
void application::load_locale()
{
gen.add_messages_domain("wivrn");
std::locale loc = gen("");
messages_info.encoding = "UTF-8";
if (config->locale.empty())
{
#ifdef __ANDROID__
jni::klass java_util_Locale("java/util/Locale");
auto default_locale = java_util_Locale.call<jni::object<"java/util/Locale">>("getDefault");
jni::klass java_util_Locale("java/util/Locale");
auto default_locale = java_util_Locale.call<jni::object<"java/util/Locale">>("getDefault");
// if (auto language = default_locale.call<jni::string>("toString"))
if (auto language = default_locale.call<jni::string>("getLanguage"))
messages_info.language = language;
// if (auto language = default_locale.call<jni::string>("toString"))
if (auto language = default_locale.call<jni::string>("getLanguage"))
messages_info.language = language;
if (auto country = default_locale.call<jni::string>("getCountry"))
messages_info.country = country;
messages_info.encoding = "UTF-8";
if (auto country = default_locale.call<jni::string>("getCountry"))
messages_info.country = country;
#else
auto & facet = std::use_facet<boost::locale::info>(loc);
messages_info.language = facet.language();
messages_info.country = facet.country();
auto & facet = std::use_facet<boost::locale::info>(loc);
messages_info.language = facet.language();
messages_info.country = facet.country();
messages_info.encoding = "UTF-8";
#endif
}
else
{
auto pos = config->locale.find("_");
messages_info.language = config->locale.substr(0, pos);
if (pos != std::string::npos)
messages_info.country = config->locale.substr(pos + 1);
}
spdlog::info("Current locale: language {}, country {}, encoding {}", messages_info.language, messages_info.country, messages_info.encoding);
messages_info.paths.push_back("locale");
messages_info.domains.push_back(boost::locale::gnu_gettext::messages_info::domain("wivrn"));
messages_info.callback = open_locale_file;
messages_info.callback = [](const std::string & file_name, const std::string & encoding) {
std::vector<char> buffer;
try
{
asset file(file_name);
buffer.resize(file.size());
memcpy(buffer.data(), file.data(), file.size());
}
catch (...)
{
}
return buffer;
};
loc = std::locale(loc, boost::locale::gnu_gettext::create_messages_facet<char>(messages_info));
std::locale::global(loc);
@@ -1854,6 +1875,13 @@ void application::poll_events()
exit_requested = true;
}
break;
case XR_TYPE_EVENT_DATA_INTERACTION_PROFILE_CHANGED: {
if (auto * htc_body = std::get_if<xr::htc_body_tracker>(&body_tracker))
{
htc_body->update_active();
}
}
break;
case XR_TYPE_EVENT_DATA_REFERENCE_SPACE_CHANGE_PENDING:
break;
case XR_TYPE_EVENT_DATA_SESSION_STATE_CHANGED: {
+82 -15
View File
@@ -28,11 +28,14 @@
#include "utils/thread_safe.h"
#include "vk/vk_allocator.h"
#include "wifi_lock.h"
#include "xr/actionset.h"
#include "xr/instance.h"
#include "xr/session.h"
#include "xr/swapchain.h"
#include "xr/system.h"
#include "xr/fb_body_tracker.h"
#include "xr/fb_face_tracker2.h"
#include "xr/hand_tracker.h"
#include "xr/htc_body_tracker.h"
#include "xr/htc_face_tracker.h"
#include "xr/pico_body_tracker.h"
#include "xr/pico_face_tracker.h"
#include "xr/xr.h"
#include <atomic>
#include <boost/locale/generator.hpp>
#include <boost/locale/gnu_gettext.hpp>
@@ -123,7 +126,12 @@ class application : public singleton<application>
xr::actionset xr_actionset;
std::vector<std::tuple<XrAction, XrActionType, std::string>> actions;
std::vector<std::pair<XrPath, xr::space>> generic_trackers;
bool hand_tracking_supported = false;
xr::hand_tracker left_hand;
xr::hand_tracker right_hand;
std::variant<std::monostate, xr::fb_face_tracker2, xr::htc_face_tracker, xr::pico_face_tracker> face_tracker;
std::variant<std::monostate, xr::fb_body_tracker, xr::htc_body_tracker, xr::pico_body_tracker> body_tracker;
bool eye_gaze_supported = false;
@@ -133,6 +141,7 @@ class application : public singleton<application>
bool session_focused = false;
bool session_visible = false;
bool debug_extensions_found = false;
std::vector<std::string> xr_extensions;
std::vector<const char *> vk_device_extensions;
std::atomic<bool> exit_requested = false;
std::filesystem::path config_path;
@@ -262,6 +271,16 @@ public:
return std::make_pair(position, orientation);
}
static XrPath string_to_path(const std::string & s)
{
return instance().xr_instance.string_to_path(s);
}
static std::string path_to_string(XrPath p)
{
return instance().xr_instance.path_to_string(p);
}
void run();
static void push_scene(std::shared_ptr<scene>);
@@ -332,6 +351,16 @@ public:
// #endif
}
static XrTime now()
{
return instance().xr_instance.now();
}
static uint32_t queue_family_index()
{
return instance().vk_queue_family_index;
}
static thread_safe<vk::raii::Queue> & get_queue()
{
return instance().vk_queue;
@@ -347,21 +376,26 @@ public:
return intent;
}
static vk::raii::PhysicalDevice & get_physical_device()
{
return instance().vk_physical_device;
}
static const vk::PhysicalDeviceProperties & get_physical_device_properties()
{
return instance().physical_device_properties;
}
static vk::raii::Device & get_device()
{
return instance().vk_device;
}
static vk::raii::Instance & get_vulkan_instance()
{
return instance().vk_instance;
}
static xr::system & get_system()
{
return instance().xr_system_id;
}
static vk::raii::PipelineCache & get_pipeline_cache()
{
return instance().pipeline_cache;
@@ -382,6 +416,21 @@ public:
return instance().last_scene_cpu_time;
}
static bool get_hand_tracking_supported()
{
return instance().hand_tracking_supported;
}
static bool get_face_tracking_supported()
{
return !std::holds_alternative<std::monostate>(instance().face_tracker);
}
static bool get_body_tracking_supported()
{
return !std::holds_alternative<std::monostate>(instance().body_tracker);
}
static bool get_eye_gaze_supported()
{
return instance().eye_gaze_supported;
@@ -392,9 +441,29 @@ public:
return instance().openxr_post_processing_supported;
}
static auto & get_generic_trackers()
static xr::hand_tracker & get_left_hand()
{
return instance().generic_trackers;
return instance().left_hand;
}
static xr::hand_tracker & get_right_hand()
{
return instance().right_hand;
}
static auto & get_face_tracker()
{
return instance().face_tracker;
}
static auto & get_body_tracker()
{
return instance().body_tracker;
}
static const std::vector<std::string> & get_xr_extensions()
{
return instance().xr_extensions;
}
static const std::vector<const char *> & get_vk_device_extensions()
@@ -417,6 +486,4 @@ public:
{
return instance().messages_info;
}
void load_locale();
};
+83 -15
View File
@@ -82,8 +82,6 @@ bool configuration::check_feature(feature f) const
{
std::lock_guard lock(mutex);
auto & system = application::get_system();
auto it = features.find(f);
if (it == features.end())
return false;
@@ -96,7 +94,7 @@ bool configuration::check_feature(feature f) const
case feature::microphone:
break;
case feature::hand_tracking:
if (not system.hand_tracking_supported())
if (not application::get_hand_tracking_supported())
return false;
break;
case feature::eye_gaze:
@@ -104,12 +102,50 @@ bool configuration::check_feature(feature f) const
return false;
break;
case feature::face_tracking:
if (system.face_tracker_supported() == xr::face_tracker_type::none)
return false;
switch (guess_model())
{
case model::htc_vive_focus_3:
case model::htc_vive_focus_vision:
case model::htc_vive_xr_elite:
if (not std::holds_alternative<xr::htc_face_tracker>(application::get_face_tracker()))
return false;
break;
case model::pico_4_pro:
case model::pico_4_enterprise:
if (not std::holds_alternative<xr::pico_face_tracker>(application::get_face_tracker()))
return false;
break;
default:
if (not std::holds_alternative<xr::fb_face_tracker2>(application::get_face_tracker()))
return false;
break;
}
break;
case feature::body_tracking:
if (system.body_tracker_supported() == xr::body_tracker_type::none)
return false;
switch (guess_model())
{
case model::meta_quest_3:
case model::meta_quest_3s:
if (not std::holds_alternative<xr::fb_body_tracker>(application::get_body_tracker()))
return false;
break;
case model::htc_vive_focus_3:
case model::htc_vive_xr_elite:
case model::htc_vive_focus_vision:
if (not std::holds_alternative<xr::htc_body_tracker>(application::get_body_tracker()))
return false;
break;
case model::pico_neo_3:
case model::pico_4:
case model::pico_4s:
case model::pico_4_pro:
case model::pico_4_enterprise:
if (not std::holds_alternative<xr::pico_body_tracker>(application::get_body_tracker()))
return false;
break;
default:
break;
}
break;
}
}
@@ -145,8 +181,8 @@ void configuration::set_feature(feature f, bool state)
configuration::configuration(xr::system & system)
{
passthrough_enabled = system.passthrough_supported() == xr::passthrough_type::color;
features[feature::hand_tracking] = system.hand_tracking_supported();
passthrough_enabled = system.passthrough_supported() == xr::system::passthrough_type::color;
features[feature::hand_tracking] = application::get_hand_tracking_supported();
try
{
simdjson::dom::parser parser;
@@ -181,6 +217,9 @@ configuration::configuration(xr::system & system)
if (auto val = root["enable_stream_gui"]; val.is_bool())
enable_stream_gui = val.get_bool();
if (auto val = root["sgsr"]; val.is_object())
parse_sgsr_options(val.get_object());
if (auto val = root["openxr_post_processing"]; val.is_object())
parse_openxr_post_processing_options(val.get_object());
@@ -204,7 +243,7 @@ configuration::configuration(xr::system & system)
features[i] = val.get_bool();
}
if (system.passthrough_supported() == xr::passthrough_type::none)
if (system.passthrough_supported() == xr::system::passthrough_type::no_passthrough)
passthrough_enabled = false;
if (auto val = root["override_foveation_enable"]; val.is_bool())
@@ -218,9 +257,6 @@ configuration::configuration(xr::system & system)
if (auto val = root["first_run"]; val.is_bool())
first_run = val.get_bool();
if (auto val = root["locale"]; val.is_string())
locale = val.get_string().value();
}
catch (std::exception & e)
{
@@ -231,11 +267,31 @@ configuration::configuration(xr::system & system)
preferred_refresh_rate.reset();
minimum_refresh_rate.reset();
resolution_scale = 1.4;
sgsr = {};
openxr_post_processing = {};
passthrough_enabled = system.passthrough_supported() == xr::passthrough_type::color;
passthrough_enabled = system.passthrough_supported() == xr::system::passthrough_type::color;
}
}
void configuration::parse_sgsr_options(simdjson::simdjson_result<simdjson::dom::object> sgsr_root)
{
sgsr = {};
if (auto val = sgsr_root["enabled"]; val.is_bool())
sgsr.enabled = val.get_bool();
if (auto val = sgsr_root["upscaling_factor"]; val.is_double())
sgsr.upscaling_factor = val.get_double();
if (auto val = sgsr_root["use_edge_direction"]; val.is_bool())
sgsr.use_edge_direction = val.get_bool();
if (auto val = sgsr_root["edge_threshold"]; val.is_double())
sgsr.edge_threshold = val.get_double();
if (auto val = sgsr_root["edge_sharpness"]; val.is_double())
sgsr.edge_sharpness = val.get_double();
}
void configuration::parse_openxr_post_processing_options(simdjson::simdjson_result<simdjson::dom::object> openxr_post_processing_root)
{
openxr_post_processing = {};
@@ -251,6 +307,17 @@ static std::ostream & operator<<(std::ostream & stream, feature f)
return stream << "\"" << magic_enum::enum_name(f) << "\"";
}
static std::ostream & write_sgsr(std::ofstream & stream, const configuration::sgsr_settings & sgsr)
{
stream << "{\"enabled\":" << std::boolalpha << sgsr.enabled;
stream << ",\"upscaling_factor\":" << sgsr.upscaling_factor;
stream << ",\"use_edge_direction\":" << std::boolalpha << sgsr.use_edge_direction;
stream << ",\"edge_threshold\":" << sgsr.edge_threshold;
stream << ",\"edge_sharpness\":" << sgsr.edge_sharpness;
stream << "}";
return stream;
}
static std::ostream & write_openxr_post_processing(std::ofstream & stream, const configuration::openxr_post_processing_settings & openxr_post_processing)
{
stream << "{\"super_sampling\":" << openxr_post_processing.super_sampling;
@@ -293,6 +360,8 @@ void configuration::save()
if (minimum_refresh_rate)
json << ",\"minimum_refresh_rate\":" << *minimum_refresh_rate;
json << ",\"resolution_scale\":" << resolution_scale;
json << ",\"sgsr\":";
write_sgsr(json, sgsr);
json << ",\"openxr_post_processing\":";
write_openxr_post_processing(json, openxr_post_processing);
json << ",\"passthrough_enabled\":" << std::boolalpha << passthrough_enabled;
@@ -307,6 +376,5 @@ void configuration::save()
json << ",\"override_foveation_pitch\":" << override_foveation_pitch;
json << ",\"override_foveation_distance\":" << override_foveation_distance;
json << ",\"first_run\":" << std::boolalpha << first_run;
json << ",\"locale\":" << json_string(locale);
json << "}";
}
+12 -2
View File
@@ -58,6 +58,17 @@ public:
bool enable_stream_gui = true;
// Snapdragon Game Super Resolution
struct sgsr_settings
{
bool enabled = false;
float upscaling_factor = 1.5;
bool use_edge_direction = true;
float edge_threshold = 4.0;
float edge_sharpness = 2.0;
};
sgsr_settings sgsr{};
// XR_FB_composition_layer_settings extension flags
struct openxr_post_processing_settings
{
@@ -74,8 +85,6 @@ public:
bool first_run = true;
std::string locale;
bool check_feature(feature f) const;
void set_feature(feature f, bool state);
@@ -83,6 +92,7 @@ private:
mutable std::mutex mutex;
std::map<feature, bool> features;
void parse_sgsr_options(simdjson::simdjson_result<simdjson::dom::object> root);
void parse_openxr_post_processing_options(simdjson::simdjson_result<simdjson::dom::object> root);
public:
+17 -31
View File
@@ -61,7 +61,6 @@ const char * mime(wivrn::video_codec codec)
return "video/av01";
}
assert(false);
__builtin_unreachable();
}
void check(media_status_t status, const char * msg)
@@ -73,26 +72,6 @@ void check(media_status_t status, const char * msg)
}
}
struct android_blit_handle : public decoder::blit_handle
{
std::shared_ptr<wivrn::android::decoder::mapped_hardware_buffer> vk_data;
std::shared_ptr<AImageReader> image_reader;
AImage_ptr aimage;
android_blit_handle(
const wivrn::from_headset::feedback & feedback,
const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info,
vk::ImageView image_view,
vk::Image image,
vk::ImageLayout & current_layout,
decltype(vk_data) vk_data,
decltype(image_reader) image_reader,
decltype(aimage) aimage) :
decoder::blit_handle(feedback, view_info, image_view, image, current_layout),
vk_data(vk_data),
image_reader(image_reader),
aimage(std::move(aimage)) {}
};
} // namespace
namespace wivrn::android
@@ -106,7 +85,7 @@ decoder::decoder(
uint8_t stream_index,
std::weak_ptr<scenes::stream> weak_scene,
shard_accumulator * accumulator) :
wivrn::decoder(description), stream_index(stream_index), fps(fps), device(device), weak_scene(weak_scene), accumulator(accumulator)
description(description), stream_index(stream_index), fps(fps), device(device), weak_scene(weak_scene), accumulator(accumulator)
{
spdlog::info("hbm_mutex.native_handle() = {}", (void *)hbm_mutex.native_handle());
@@ -243,7 +222,7 @@ void decoder::push_data(std::span<std::span<const uint8_t>> data, uint64_t frame
current_input_buffer = input_buffer{};
}
void decoder::frame_completed(const wivrn::from_headset::feedback & feedback, const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info)
void decoder::frame_completed(wivrn::from_headset::feedback & feedback, const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info)
{
if (not media_codec)
{
@@ -276,7 +255,7 @@ void decoder::on_image_available(AImageReader * reader)
assert(reader == image_reader.get());
// Executed on image reader thread
decltype(android_blit_handle::aimage) image;
decltype(blit_handle::aimage) image;
try
{
AImage * tmp;
@@ -301,13 +280,13 @@ void decoder::on_image_available(AImageReader * reader)
auto vk_data = map_hardware_buffer(image.get());
auto handle = std::make_shared<android_blit_handle>(
auto handle = std::make_shared<decoder::blit_handle>(
info->feedback,
info->view_info,
*vk_data->image_view,
vk_data->image_view,
*vk_data->vimage,
vk_data->layout,
std::move(vk_data),
&vk_data->layout,
vk_data,
image_reader,
std::move(image));
@@ -409,8 +388,7 @@ std::shared_ptr<decoder::mapped_hardware_buffer> decoder::map_hardware_buffer(AI
if (!*ycbcr_sampler || memcmp(&ahb_format, &format_properties, sizeof(format_properties)))
{
memcpy(&ahb_format, &format_properties, sizeof(format_properties));
extent_ = {buffer_desc.width, buffer_desc.height};
spdlog::info("decoded image size: {}x{}", buffer_desc.width, buffer_desc.height);
extent = {buffer_desc.width, buffer_desc.height};
create_sampler(buffer_desc, ahb_format);
hardware_buffer_map.clear();
// TODO tell the reprojector to recreate the pipeline
@@ -536,6 +514,11 @@ void decoder::on_media_output_available(AMediaCodec * media_codec, void * userda
});
}
void decoder::blit_handle::deleter::operator()(AImage * aimage)
{
AImage_delete(aimage);
}
static bool hardware_accelerated(AMediaCodec * media_codec)
{
// MediaCodecInfo has isHardwareAccelerated, but this does not exist in NDK.
@@ -559,8 +542,9 @@ static bool hardware_accelerated(AMediaCodec * media_codec)
return true;
}
void decoder::supported_codecs(std::vector<wivrn::video_codec> & result)
std::vector<wivrn::video_codec> decoder::supported_codecs()
{
std::vector<wivrn::video_codec> result;
// Make sure we update this code when codecs are changed
static_assert(magic_enum::enum_count<wivrn::video_codec>() == 3);
@@ -579,6 +563,8 @@ void decoder::supported_codecs(std::vector<wivrn::video_codec> & result)
spdlog::info("video codec {}: {}supported", magic_enum::enum_name(codec), supported ? "" : "NOT ");
}
return result;
}
} // namespace wivrn::android
+39 -7
View File
@@ -19,7 +19,6 @@
#pragma once
#include "decoder/decoder.h"
#include "utils/sync_queue.h"
#include "wivrn_packets.h"
#include <functional>
@@ -60,12 +59,31 @@ class stream;
namespace wivrn::android
{
class decoder : public wivrn::decoder
class decoder
{
public:
struct mapped_hardware_buffer;
struct blit_handle
{
struct deleter
{
void operator()(AImage *);
};
wivrn::from_headset::feedback feedback;
wivrn::to_headset::video_stream_data_shard::view_info_t view_info;
vk::raii::ImageView & image_view;
vk::Image image = nullptr;
vk::ImageLayout * current_layout = nullptr;
std::shared_ptr<mapped_hardware_buffer> vk_data;
std::shared_ptr<AImageReader> image_reader;
AImage_ptr aimage;
};
private:
wivrn::to_headset::video_stream_description::item description;
uint8_t stream_index;
float fps;
@@ -74,6 +92,7 @@ private:
vk::AndroidHardwareBufferFormatPropertiesANDROID ahb_format;
vk::raii::SamplerYcbcrConversion ycbcr_conversion = nullptr;
vk::raii::Sampler ycbcr_sampler = nullptr;
vk::Extent2D extent{};
std::mutex hbm_mutex;
std::shared_ptr<AImageReader> image_reader;
@@ -127,20 +146,33 @@ public:
uint8_t stream_index,
std::weak_ptr<scenes::stream> scene,
shard_accumulator * accumulator);
decoder(const decoder &) = delete;
decoder(decoder &&) = delete;
~decoder();
void push_data(std::span<std::span<const uint8_t>> data, uint64_t frame_index, bool partial) override;
void push_data(std::span<std::span<const uint8_t>> data, uint64_t frame_index, bool partial);
void frame_completed(
const wivrn::from_headset::feedback & feedback,
const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info) override;
wivrn::from_headset::feedback & feedback,
const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info);
vk::Sampler sampler() override
const auto & desc() const
{
return description;
}
vk::Sampler sampler()
{
return *ycbcr_sampler;
}
static void supported_codecs(std::vector<wivrn::video_codec> &);
vk::Extent2D image_size()
{
return extent;
}
static std::vector<wivrn::video_codec> supported_codecs();
};
} // namespace wivrn::android
-67
View File
@@ -1,67 +0,0 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
*
* 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 <https://www.gnu.org/licenses/>.
*/
#include "decoder.h"
#ifdef __ANDROID__
#include "decoder/android/android_decoder.h"
#else
#include "decoder/ffmpeg/ffmpeg_decoder.h"
#endif
wivrn::decoder::~decoder() = default;
std::shared_ptr<wivrn::decoder> wivrn::decoder::make(
vk::raii::Device & device,
vk::raii::PhysicalDevice & phys_dev,
const wivrn::to_headset::video_stream_description::item & description,
float fps,
uint8_t stream_index,
std::weak_ptr<scenes::stream> scene,
shard_accumulator * acc)
{
#ifdef __ANDROID__
return std::make_shared<wivrn::android::decoder>(
device,
phys_dev,
description,
fps,
stream_index,
scene,
acc);
#else
return std::make_shared<wivrn::ffmpeg::decoder>(
device,
phys_dev,
description,
stream_index,
scene,
acc);
#endif
}
std::vector<wivrn::video_codec> wivrn::decoder::supported_codecs()
{
std::vector<wivrn::video_codec> res;
#ifdef __ANDROID__
android::decoder::supported_codecs(res);
#else
ffmpeg::decoder::supported_codecs(res);
#endif
return res;
}
-79
View File
@@ -1,79 +0,0 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
*
* 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 <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "wivrn_packets.h"
#include <cstdint>
#include <memory>
#include <span>
#include <vulkan/vulkan_raii.hpp>
namespace scenes
{
class stream;
}
namespace wivrn
{
class shard_accumulator;
class decoder
{
public:
struct blit_handle
{
wivrn::from_headset::feedback feedback;
wivrn::to_headset::video_stream_data_shard::view_info_t view_info;
vk::ImageView image_view = nullptr;
vk::Image image = nullptr;
vk::ImageLayout & current_layout;
};
const wivrn::to_headset::video_stream_description::item description;
protected:
decoder(const wivrn::to_headset::video_stream_description::item & description) :
description(description) {}
vk::Extent2D extent_; // Must be populated when sampler is set
public:
static std::shared_ptr<decoder> make(
vk::raii::Device &,
vk::raii::PhysicalDevice &,
const wivrn::to_headset::video_stream_description::item & description,
float fps,
uint8_t stream_index,
std::weak_ptr<scenes::stream>,
shard_accumulator *);
virtual ~decoder();
virtual void push_data(std::span<std::span<const uint8_t>> data, uint64_t frame_index, bool partial) = 0;
virtual void frame_completed(
const from_headset::feedback & feedback,
const to_headset::video_stream_data_shard::view_info_t & view_info) = 0;
virtual vk::Sampler sampler() = 0;
const vk::Extent2D extent()
{
return extent_;
}
static std::vector<wivrn::video_codec> supported_codecs();
};
} // namespace wivrn
+19 -46
View File
@@ -61,53 +61,24 @@ static AVCodecID codec_id(wivrn::video_codec codec)
__builtin_unreachable();
}
struct decoder::ffmpeg_blit_handle : public wivrn::decoder::blit_handle
decoder::blit_handle::~blit_handle()
{
int image_index;
wivrn::ffmpeg::decoder * self;
std::unique_lock lock(self->mutex);
if (image_index < 0)
return;
ffmpeg_blit_handle(
const wivrn::from_headset::feedback & feedback,
const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info,
vk::ImageView image_view,
vk::Image image,
vk::ImageLayout & current_layout,
int image_index,
wivrn::ffmpeg::decoder * self) :
wivrn::decoder::blit_handle{
feedback,
view_info,
image_view,
image,
current_layout,
},
image_index(image_index),
self(self)
{}
~ffmpeg_blit_handle()
{
std::unique_lock lock(self->mutex);
if (image_index < 0)
return;
self->free_images.push_back(image_index);
}
};
self->free_images.push_back(image_index);
}
decoder::decoder(
vk::raii::Device & device,
vk::raii::PhysicalDevice & physical_device,
const wivrn::to_headset::video_stream_description::item & description,
float fps,
uint8_t stream_index,
std::weak_ptr<scenes::stream> scene,
shard_accumulator * accumulator) :
wivrn::decoder(description),
device(device),
codec(nullptr, free_codec_context),
sws(nullptr, sws_freeContext),
weak_scene(scene),
accumulator(accumulator)
device(device), description(description), codec(nullptr, free_codec_context), sws(nullptr, sws_freeContext), weak_scene(scene), accumulator(accumulator)
{
free_images.resize(image_count);
@@ -137,7 +108,7 @@ decoder::decoder(
decoded_images[i].image = image_allocation(device, image_info, alloc_info);
decoded_images[i].image.map();
extent_ = vk::Extent2D{description.width, description.height};
extent = vk::Extent2D{description.width, description.height};
vk::ImageSubresource resource;
resource.aspectMask = vk::ImageAspectFlagBits::eColor;
@@ -250,12 +221,12 @@ void decoder::frame_completed(const wivrn::from_headset::feedback & feedback, co
if (res == 0)
throw std::runtime_error{"sws_scale failed"};
auto handle = std::make_shared<ffmpeg_blit_handle>(
auto handle = std::make_shared<decoder::blit_handle>(
feedback,
view_info,
*decoded_images[index].image_view,
decoded_images[index].image,
decoded_images[index].current_layout,
decoded_images[index].image_view,
(vk::Image)decoded_images[index].image,
&decoded_images[index].current_layout,
index,
this);
@@ -263,11 +234,13 @@ void decoder::frame_completed(const wivrn::from_headset::feedback & feedback, co
scene->push_blit_handle(accumulator, std::move(handle));
}
void decoder::supported_codecs(std::vector<wivrn::video_codec> & res)
std::vector<wivrn::video_codec> decoder::supported_codecs()
{
res.push_back(wivrn::video_codec::h264);
res.push_back(wivrn::video_codec::h265);
res.push_back(wivrn::video_codec::av1);
return {
wivrn::video_codec::h264,
wivrn::video_codec::h265,
wivrn::video_codec::av1,
};
}
} // namespace wivrn::ffmpeg
+37 -7
View File
@@ -19,7 +19,6 @@
#pragma once
#include "decoder/decoder.h"
#include "vk/allocation.h"
#include "wivrn_packets.h"
#include <memory>
@@ -47,10 +46,24 @@ class stream;
namespace wivrn::ffmpeg
{
class decoder : public wivrn::decoder
class decoder
{
public:
struct blit_handle
{
wivrn::from_headset::feedback feedback;
wivrn::to_headset::video_stream_data_shard::view_info_t view_info;
vk::raii::ImageView & image_view;
vk::Image image = nullptr;
vk::ImageLayout * current_layout = nullptr;
int image_index;
decoder * self;
~blit_handle();
};
private:
struct ffmpeg_blit_handle;
static const int image_count = 12;
struct image
{
@@ -65,8 +78,11 @@ private:
vk::raii::Sampler rgb_sampler = nullptr;
std::array<image, image_count> decoded_images;
vk::Extent2D extent{};
std::vector<int> free_images;
wivrn::to_headset::video_stream_description::item description;
std::unique_ptr<AVCodecContext, void (*)(AVCodecContext *)> codec;
std::unique_ptr<SwsContext, void (*)(SwsContext *)> sws;
std::vector<uint8_t> packet;
@@ -80,21 +96,35 @@ public:
decoder(vk::raii::Device & device,
vk::raii::PhysicalDevice & physical_device,
const wivrn::to_headset::video_stream_description::item & description,
float fps,
uint8_t stream_index,
std::weak_ptr<scenes::stream> scene,
shard_accumulator * accumulator);
void push_data(std::span<std::span<const uint8_t>> data, uint64_t frame_index, bool partial) override;
decoder(const decoder &) = delete;
decoder(decoder &&) = delete;
void push_data(std::span<std::span<const uint8_t>> data, uint64_t frame_index, bool partial);
void frame_completed(
const wivrn::from_headset::feedback & feedback,
const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info) override;
const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info);
vk::Sampler sampler() override
const auto & desc() const
{
return description;
}
vk::Sampler sampler()
{
return *rgb_sampler;
}
static void supported_codecs(std::vector<wivrn::video_codec> &);
vk::Extent2D image_size()
{
return extent;
}
static std::vector<wivrn::video_codec> supported_codecs();
};
} // namespace wivrn::ffmpeg
+10 -10
View File
@@ -18,9 +18,9 @@
*/
#include "shard_accumulator.h"
#include "scenes/stream.h" // IWYU pragma: keep
#include "application.h"
#include "scenes/stream.h"
#include "spdlog/spdlog.h"
#include "xr/instance.h"
namespace wivrn
{
@@ -63,10 +63,10 @@ static bool is_complete(const shard_set & shards)
return true;
}
std::optional<uint16_t> shard_set::insert(data_shard && shard, xr::instance & instance)
std::optional<uint16_t> shard_set::insert(data_shard && shard)
{
if (empty())
feedback.received_first_packet = instance.now();
feedback.received_first_packet = application::now();
auto idx = shard.shard_idx;
if (idx >= data.size())
@@ -121,12 +121,12 @@ void shard_accumulator::push_shard(video_stream_data_shard && shard)
}
else if (frame_diff == 0)
{
auto shard_idx = current.insert(std::move(shard), instance);
auto shard_idx = current.insert(std::move(shard));
try_submit_frame(shard_idx);
}
else if (frame_diff == 1)
{
next.insert(std::move(shard), instance);
next.insert(std::move(shard));
if (is_complete(next))
{
debug_why_not_sent(current);
@@ -186,12 +186,12 @@ void shard_accumulator::try_submit_frame(uint16_t shard_idx)
payload.emplace_back(data_shards[idx]->payload);
bool frame_complete = last_idx == data_shards.size() and data_shards.back()->flags & video_stream_data_shard::end_of_frame;
decoder_->push_data(payload, data_shards[shard_idx]->frame_idx, not frame_complete);
decoder->push_data(payload, data_shards[shard_idx]->frame_idx, not frame_complete);
if (not frame_complete)
return;
current.feedback.received_last_packet = instance.now();
current.feedback.received_last_packet = application::now();
current.feedback.sent_to_decoder = current.feedback.received_last_packet;
data_shard::timing_info_t timing_info = data_shards.back()->timing_info.value_or(data_shard::timing_info_t{});
current.feedback.encode_begin = timing_info.encode_begin;
@@ -206,7 +206,7 @@ void shard_accumulator::try_submit_frame(uint16_t shard_idx)
}
// Try to extract a frame
decoder_->frame_completed(current.feedback, *data_shards.front()->view_info);
decoder->frame_completed(current.feedback, *data_shards.front()->view_info);
send_feedback(current.feedback);
@@ -216,7 +216,7 @@ void shard_accumulator::try_submit_frame(uint16_t shard_idx)
void shard_accumulator::send_feedback(wivrn::from_headset::feedback & feedback)
{
if (not feedback.received_last_packet)
feedback.received_first_packet = instance.now();
feedback.received_first_packet = application::now();
auto scene = weak_scene.lock();
if (scene)
scene->send_feedback(feedback);
+20 -26
View File
@@ -19,30 +19,27 @@
#pragma once
#include "decoder.h"
#include "wivrn_packets.h"
#include <memory>
#include <vulkan/vulkan.hpp>
#ifdef __ANDROID__
#include "decoder/android/android_decoder.h"
using decoder_impl = ::wivrn::android::decoder;
#else
#include "decoder/ffmpeg/ffmpeg_decoder.h"
using decoder_impl = ::wivrn::ffmpeg::decoder;
#endif
#include "wivrn_packets.h"
#include <optional>
#include <vector>
#include <vulkan/vulkan_raii.hpp>
namespace xr
{
class instance;
}
namespace scenes
{
class stream;
}
namespace wivrn
{
class shard_accumulator
{
std::shared_ptr<decoder> decoder_;
std::shared_ptr<decoder_impl> decoder;
public:
using data_shard = wivrn::to_headset::video_stream_data_shard;
@@ -53,7 +50,7 @@ public:
void reset(uint64_t frame_index);
bool empty() const;
std::optional<uint16_t> insert(data_shard &&, xr::instance & instance);
std::optional<uint16_t> insert(data_shard &&);
wivrn::from_headset::feedback feedback{};
@@ -73,22 +70,19 @@ private:
shard_set current;
shard_set next;
std::weak_ptr<scenes::stream> weak_scene;
xr::instance & instance;
public:
explicit shard_accumulator(
vk::raii::Device & device,
vk::raii::PhysicalDevice & physical_device,
xr::instance & instance,
const wivrn::to_headset::video_stream_description::item & description,
float fps,
std::weak_ptr<scenes::stream> scene,
uint8_t stream_index) :
decoder_(decoder::make(device, physical_device, description, fps, stream_index, scene, this)),
decoder(std::make_shared<decoder_impl>(device, physical_device, description, fps, stream_index, scene, this)),
current(stream_index),
next(stream_index),
weak_scene(scene),
instance(instance)
weak_scene(scene)
{
next.reset(1);
}
@@ -97,20 +91,20 @@ public:
auto & desc() const
{
return decoder_->description;
return decoder->desc();
}
vk::Sampler sampler()
{
return decoder_->sampler();
return decoder->sampler();
}
const vk::Extent2D extent()
vk::Extent2D image_size()
{
return decoder_->extent();
return decoder->image_size();
}
using blit_handle = decoder::blit_handle;
using blit_handle = decoder_impl::blit_handle;
private:
void try_submit_frame(std::optional<uint16_t> shard_idx);
+3 -2
View File
@@ -18,6 +18,7 @@
#pragma once
#include "application.h"
#include "utils/alignment.h"
#include "vk/allocation.h"
#include <fastgltf/tools.hpp>
@@ -114,10 +115,10 @@ public:
}
}
buffer_allocation copy_to_gpu(vk::raii::Device & device)
buffer_allocation copy_to_gpu()
{
buffer_allocation gpu_buffer{
device,
application::get_device(),
vk::BufferCreateInfo{
.size = bytes.size(),
.usage = usage},
+17 -24
View File
@@ -345,9 +345,9 @@ imgui_context::imgui_context(
ImGui_ImplVulkan_InitInfo init_info = {
.Instance = *application::get_vulkan_instance(),
.PhysicalDevice = *physical_device,
.Device = *device,
.QueueFamily = queue_family_index,
.PhysicalDevice = *application::get_physical_device(),
.Device = *application::get_device(),
.QueueFamily = application::queue_family_index(),
.Queue = *queue.get_unsafe(),
.RenderPass = *renderpass,
.MinImageCount = 2,
@@ -490,22 +490,22 @@ static std::vector<std::string> find_font(std::u16string sample_text, const std:
void imgui_context::initialize_fonts()
{
std::vector<std::string> fonts;
for (auto & [code, glyphs]: glyph_set_per_language)
{
std::u16string sample_text = u"Hello world";
std::u16string sample_text = u"Hello world";
for (char16_t c: glyphs)
const auto & locale = application::get_messages_info();
auto it = glyph_set_per_language.find(locale.language + "_" + locale.country);
if (it == glyph_set_per_language.end())
it = glyph_set_per_language.find(locale.language);
if (it != glyph_set_per_language.end())
for (char16_t c: it->second)
sample_text += c;
auto language = code.substr(0, code.find("_"));
// Load Fonts
for (auto && i: find_font(sample_text, language))
{
spdlog::info("Font for {} {}", code, i);
if (not std::ranges::contains(fonts, i))
fonts.push_back(std::move(i));
}
// Load Fonts
auto fonts = find_font(sample_text, application::get_messages_info().language);
for (auto & i: fonts)
{
spdlog::info("Font {}", i);
}
asset font_awesome_regular("Font Awesome 6 Free-Regular-400.otf");
@@ -718,7 +718,7 @@ void imgui_context::new_frame(XrTime display_time)
ImPlot::SetCurrentContext(plot_context);
if (last_display_time)
io.DeltaTime = std::clamp((display_time - last_display_time) * 1e-9f, 0.001f, 0.0166f);
io.DeltaTime = std::min((display_time - last_display_time) * 1e-9f, 0.0166f);
last_display_time = display_time;
// Uses the window list from last frame
@@ -1099,13 +1099,6 @@ ImTextureID imgui_context::load_texture(const std::string & filename)
void imgui_context::free_texture(ImTextureID texture)
{
// Make sure we are done using the texture
std::vector<vk::Fence> fences;
for (auto & f: command_buffers)
fences.push_back(*f.fence);
if (auto result = device.waitForFences(fences, true, 1'000'000'000); result != vk::Result::eSuccess)
spdlog::error("vkWaitForfences: {}", vk::to_string(result));
textures.erase(texture);
}
+1 -1
View File
@@ -785,7 +785,7 @@ entt::registry scene_loader::operator()(const std::filesystem::path & gltf_path)
// Copy the staging buffer to the GPU
spdlog::debug("Uploading scene data ({} bytes) to GPU memory", staging_buffer.size());
auto buffer = std::make_shared<buffer_allocation>(staging_buffer.copy_to_gpu(device));
auto buffer = std::make_shared<buffer_allocation>(staging_buffer.copy_to_gpu());
for (auto & i: materials)
i->buffer = buffer;
+34 -9
View File
@@ -28,13 +28,13 @@
#include "vk/allocation.h"
#include "vk/pipeline.h"
#include "vk/shader.h"
#include "vk/specialization_constants.h"
#include <boost/pfr/core.hpp>
#include <entt/entity/entity.hpp>
#include <entt/entt.hpp>
#include <glm/gtc/matrix_access.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtx/quaternion.hpp>
#include <map>
#include <memory>
#include <ranges>
#include <spdlog/spdlog.h>
@@ -42,6 +42,8 @@
#include <vulkan/vulkan_enums.hpp>
#include <vulkan/vulkan_structs.hpp>
extern const std::map<std::string, std::vector<uint32_t>> shaders;
// TODO move in lobby?
vk::Format scene_renderer::find_usable_image_format(
vk::raii::PhysicalDevice physical_device,
@@ -533,11 +535,34 @@ vk::raii::Pipeline scene_renderer::create_pipeline(const pipeline_info & info)
auto vertex_shader = load_shader(device, info.shader_name + ".vert");
auto fragment_shader = load_shader(device, info.shader_name + ".frag");
auto specialization = make_specialization_constants(
int32_t(info.nb_texcoords),
VkBool32(info.dithering),
VkBool32(info.alpha_cutout),
VkBool32(info.skinning));
std::array specialization_constants_desc{
vk::SpecializationMapEntry{
.constantID = 0,
.offset = offsetof(pipeline_info, nb_texcoords),
.size = sizeof(int32_t),
},
vk::SpecializationMapEntry{
.constantID = 1,
.offset = offsetof(pipeline_info, dithering),
.size = sizeof(VkBool32),
},
vk::SpecializationMapEntry{
.constantID = 2,
.offset = offsetof(pipeline_info, alpha_cutout),
.size = sizeof(VkBool32),
},
vk::SpecializationMapEntry{
.constantID = 3,
.offset = offsetof(pipeline_info, skinning),
.size = sizeof(VkBool32),
}};
vk::SpecializationInfo specialization{
.mapEntryCount = specialization_constants_desc.size(),
.pMapEntries = specialization_constants_desc.data(),
.dataSize = sizeof(pipeline_info),
.pData = &info,
};
return vk::raii::Pipeline{
device,
@@ -548,14 +573,14 @@ vk::raii::Pipeline scene_renderer::create_pipeline(const pipeline_info & info)
.stage = vk::ShaderStageFlagBits::eVertex,
.module = *vertex_shader,
.pName = "main",
.pSpecializationInfo = specialization,
.pSpecializationInfo = &specialization,
},
vk::PipelineShaderStageCreateInfo{
.stage = vk::ShaderStageFlagBits::eFragment,
.module = *fragment_shader,
.pName = "main",
.pSpecializationInfo = specialization,
.pSpecializationInfo = &specialization,
},
},
@@ -772,7 +797,7 @@ void scene_renderer::update_material_descriptor_set(renderer::material & materia
device.updateDescriptorSets(write_ds, {});
}
[[maybe_unused]] static void print_scene_hierarchy(const entt::registry & scene, entt::entity root = entt::null, int level = 0)
static void print_scene_hierarchy(const entt::registry & scene, entt::entity root = entt::null, int level = 0)
{
if (level == 0)
spdlog::info("Node hierarchy:");
+36 -32
View File
@@ -139,42 +139,46 @@ text_rasterizer::text_rasterizer(vk::raii::Device & device, vk::raii::PhysicalDe
image_allocation text_rasterizer::create_image(vk::Extent2D size)
{
return {device,
vk::ImageCreateInfo{
.imageType = vk::ImageType::e2D,
.format = text::format,
.extent = {
.width = size.width,
.height = size.height,
.depth = 1,
},
.mipLevels = 1,
.arrayLayers = 1,
.samples = vk::SampleCountFlagBits::e1,
.tiling = vk::ImageTiling::eOptimal,
.usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst,
.sharingMode = vk::SharingMode::eExclusive,
.initialLayout = vk::ImageLayout::eUndefined,
},
VmaAllocationCreateInfo{
.flags = 0,
.usage = VMA_MEMORY_USAGE_AUTO,
},
"text_rasterizer image"};
image_allocation alloc{device,
vk::ImageCreateInfo{
.imageType = vk::ImageType::e2D,
.format = text::format,
.extent = {
.width = size.width,
.height = size.height,
.depth = 1,
},
.mipLevels = 1,
.arrayLayers = 1,
.samples = vk::SampleCountFlagBits::e1,
.tiling = vk::ImageTiling::eOptimal,
.usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst,
.sharingMode = vk::SharingMode::eExclusive,
.initialLayout = vk::ImageLayout::eUndefined,
},
VmaAllocationCreateInfo{
.flags = 0,
.usage = VMA_MEMORY_USAGE_AUTO,
}};
application::set_debug_reports_name<vk::Image>(alloc, "text_rasterizer image");
return alloc;
}
buffer_allocation text_rasterizer::create_buffer(size_t size)
{
return {device,
vk::BufferCreateInfo{
.size = size,
.usage = vk::BufferUsageFlagBits::eTransferSrc,
},
VmaAllocationCreateInfo{
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
.usage = VMA_MEMORY_USAGE_AUTO,
},
"text_rasterizer buffer"};
buffer_allocation alloc{device,
vk::BufferCreateInfo{
.size = size,
.usage = vk::BufferUsageFlagBits::eTransferSrc,
},
VmaAllocationCreateInfo{
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
.usage = VMA_MEMORY_USAGE_AUTO,
}};
application::set_debug_reports_name<vk::Buffer>(alloc, "text_rasterizer buffer");
return alloc;
}
text_rasterizer::~text_rasterizer()
+3 -1
View File
@@ -51,6 +51,8 @@ scene::scene(key, const meta & current_meta, std::span<const vk::Format> support
queue_family_index(application::instance().vk_queue_family_index),
current_meta(current_meta)
{
passthrough_supported = system.passthrough_supported();
swapchain_format = vk::Format::eUndefined;
spdlog::info("Supported swapchain formats:");
@@ -441,7 +443,7 @@ std::pair<entt::entity, components::node &> scene::load_gltf(const std::filesyst
node.layer_mask = layer_mask;
assert(renderer);
scene_loader loader(device, physical_device, queue, queue_family_index, renderer->get_default_material());
scene_loader loader(device, physical_device, queue, application::queue_family_index(), renderer->get_default_material());
loader.add_prefab(world, loader(path), entity);
+1
View File
@@ -103,6 +103,7 @@ public:
protected:
vk::Format swapchain_format;
vk::Format depth_format;
xr::system::passthrough_type passthrough_supported;
bool composition_layer_depth_test_supported;
bool composition_layer_color_scale_bias_supported;
-364
View File
@@ -1,364 +0,0 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
*
* 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 <https://www.gnu.org/licenses/>.
*/
#include "blitter.h"
#include "application.h"
#include "utils/ranges.h"
#include "vk/pipeline.h"
#include "vk/shader.h"
#include "vk/specialization_constants.h"
#include <format>
#include <ranges>
#include <spdlog/spdlog.h>
namespace wivrn
{
static const uint32_t num_views = 2;
blitter::blitter(vk::raii::Device & device, size_t view) :
device(device), view(view)
{
}
void blitter::reset(const to_headset::video_stream_description & desc)
{
using channels_t = to_headset::video_stream_description::channels_t;
this->desc = desc;
current = {};
target = image_allocation();
image_view = nullptr;
rp = nullptr;
fb = nullptr;
sampler = nullptr;
pipelines.clear();
passthrough_rgb = passthrough_a = -1;
auto w = desc.width / num_views;
for (auto [i, item]: utils::enumerate(desc.items))
{
if (item.offset_x <= view * w and
item.offset_y == 0 and
item.offset_x + item.width * item.subsampling >= (view + 1) * w and
item.height * item.subsampling >= desc.height)
{
spdlog::info("Stream {} is eligible for blit-less path on view {}", i, view);
switch (item.channels)
{
case channels_t::colour:
passthrough_rgb = i;
break;
case channels_t::alpha:
passthrough_a = i;
break;
}
const bool alpha = item.channels == to_headset::video_stream_description::channels_t::alpha;
auto & r = alpha ? current.rect_a : current.rect_rgb;
r = vk::Rect2D{
.offset = {
.x = int32_t(view * w) - item.offset_x,
.y = 0,
},
};
}
}
if (passthrough_rgb != -1 and passthrough_a != -1)
return;
target = image_allocation(
device,
vk::ImageCreateInfo{
.imageType = vk::ImageType::e2D,
.format = vk::Format::eB8G8R8A8Srgb,
.extent = {
.width = w,
.height = desc.height,
.depth = 1,
},
.mipLevels = 1,
.arrayLayers = 1,
.usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eColorAttachment,
},
{
.usage = VMA_MEMORY_USAGE_AUTO,
},
std::format("blit image {}", view));
image_view = device.createImageView(vk::ImageViewCreateInfo{
.image = vk::Image(target),
.viewType = vk::ImageViewType::e2D,
.format = target.info().format,
.subresourceRange = {
.aspectMask = vk::ImageAspectFlagBits::eColor,
.levelCount = 1,
.layerCount = 1,
}});
// render pass
{
vk::AttachmentReference color_ref{
.attachment = 0,
.layout = vk::ImageLayout::eColorAttachmentOptimal,
};
vk::SubpassDescription subpass{
.pipelineBindPoint = vk::PipelineBindPoint::eGraphics,
.colorAttachmentCount = 1,
.pColorAttachments = &color_ref,
};
vk::AttachmentDescription color_desc{
.format = target.info().format,
.loadOp = vk::AttachmentLoadOp::eDontCare,
.finalLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
};
rp = device.createRenderPass(vk::RenderPassCreateInfo{
.attachmentCount = 1,
.pAttachments = &color_desc,
.subpassCount = 1,
.pSubpasses = &subpass,
});
}
fb = device.createFramebuffer(
vk::FramebufferCreateInfo{
.renderPass = *rp,
.attachmentCount = 1,
.pAttachments = &*image_view,
.width = w,
.height = desc.height,
.layers = 1,
});
sampler = device.createSampler(vk::SamplerCreateInfo{
.magFilter = vk::Filter::eLinear,
.minFilter = vk::Filter::eLinear,
.addressModeU = vk::SamplerAddressMode::eClampToBorder,
.addressModeV = vk::SamplerAddressMode::eClampToBorder,
.addressModeW = vk::SamplerAddressMode::eClampToBorder,
.borderColor = vk::BorderColor::eFloatOpaqueBlack,
});
pipelines.resize(desc.items.size());
for (auto [i, item]: utils::enumerate(desc.items))
{
pipelines[i].used = item.offset_x < (view + 1) * w and
item.offset_x + item.width * item.subsampling > view * w;
}
current.rgb = *image_view;
current.sampler_rgb = *sampler;
current.rect_rgb = vk::Rect2D{.extent = {w, desc.height}};
current.layout_rgb = vk::ImageLayout::eShaderReadOnlyOptimal;
}
void blitter::begin(vk::raii::CommandBuffer & cmd)
{
assert(not desc.items.empty());
if (*fb == VK_NULL_HANDLE)
{
current.rgb = nullptr;
current.a = nullptr;
current.sampler_rgb = nullptr;
current.sampler_a = nullptr;
return;
}
current.rgb = *image_view;
current.sampler_rgb = *sampler;
cmd.beginRenderPass(
{
.renderPass = *rp,
.framebuffer = *fb,
.renderArea = {
.offset = {0, 0},
.extent = {target.info().extent.width, target.info().extent.height},
},
},
vk::SubpassContents::eInline);
}
void blitter::push_image(vk::raii::CommandBuffer & cmd, uint8_t stream, vk::Sampler sampler, const vk::Extent2D & extent_, vk::ImageView image, vk::ImageLayout layout)
{
if (stream == passthrough_rgb)
{
current.rgb = image;
current.sampler_rgb = sampler;
current.layout_rgb = layout;
current.rect_rgb.extent = vk::Extent2D{
extent_.width * desc.items[stream].subsampling,
extent_.height * desc.items[stream].subsampling,
};
return;
}
if (stream == passthrough_a)
{
current.a = image;
current.sampler_a = sampler;
current.layout_a = layout;
current.rect_a.extent = vk::Extent2D{
extent_.width * desc.items[stream].subsampling,
extent_.height * desc.items[stream].subsampling,
};
return;
}
if (pipelines.empty())
return;
assert(stream < pipelines.size());
auto & p = pipelines[stream];
if (not p.used)
return;
const auto & extent = target.info().extent;
const auto & description = desc.items[stream];
if (not *p.pipeline)
{
const bool alpha = description.channels == to_headset::video_stream_description::channels_t::alpha;
vk::DescriptorSetLayoutBinding sampler_layout_binding{
.binding = 0,
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
.descriptorCount = 1,
.stageFlags = vk::ShaderStageFlagBits::eFragment,
.pImmutableSamplers = &sampler,
};
p.set_layout = device.createDescriptorSetLayout(vk::DescriptorSetLayoutCreateInfo{
.flags = vk::DescriptorSetLayoutCreateFlagBits::ePushDescriptorKHR,
.bindingCount = 1,
.pBindings = &sampler_layout_binding,
});
auto vert_constants = make_specialization_constants(
float(description.width) / extent_.width,
float(description.height) / extent_.height);
auto frag_constants = make_specialization_constants(
VkBool32(alpha));
// Create graphics pipeline
vk::raii::ShaderModule vertex_shader = load_shader(device, "stream.vert");
vk::raii::ShaderModule fragment_shader = load_shader(device, "stream.frag");
p.layout = device.createPipelineLayout(vk::PipelineLayoutCreateInfo{
.setLayoutCount = 1,
.pSetLayouts = &*p.set_layout,
});
vk::pipeline_builder pipeline_info{
.Stages = {{
.stage = vk::ShaderStageFlagBits::eVertex,
.module = *vertex_shader,
.pName = "main",
.pSpecializationInfo = vert_constants,
},
{
.stage = vk::ShaderStageFlagBits::eFragment,
.module = *fragment_shader,
.pName = "main",
.pSpecializationInfo = frag_constants,
}},
.VertexBindingDescriptions = {},
.VertexAttributeDescriptions = {},
.InputAssemblyState = {{
.topology = vk::PrimitiveTopology::eTriangleStrip,
}},
// With vk::DynamicState::eViewport, vk::DynamicState::eScissor the number of viewports
// and scissors is still used, put a vector with one element
.Viewports = {{}},
.Scissors = {{}},
.RasterizationState = {{
.polygonMode = vk::PolygonMode::eFill,
.lineWidth = 1,
}},
.MultisampleState = {{
.rasterizationSamples = vk::SampleCountFlagBits::e1,
}},
.ColorBlendAttachments = {
{.colorWriteMask = alpha ? vk::ColorComponentFlagBits::eA
: vk::ColorComponentFlagBits::eA | vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB}},
.DynamicStates = {vk::DynamicState::eViewport, vk::DynamicState::eScissor},
.layout = *p.layout,
.renderPass = *rp,
.subpass = 0,
};
p.pipeline = device.createGraphicsPipeline(application::get_pipeline_cache(), pipeline_info);
spdlog::info("Created blit pipeline for stream {}, view {}", stream, view);
}
cmd.bindPipeline(vk::PipelineBindPoint::eGraphics, *p.pipeline);
vk::DescriptorImageInfo image_info{
.imageView = image,
.imageLayout = layout,
};
cmd.pushDescriptorSetKHR(
vk::PipelineBindPoint::eGraphics,
*p.layout,
0,
vk::WriteDescriptorSet{
.dstBinding = 0,
.descriptorCount = 1,
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
.pImageInfo = &image_info,
});
int x0 = description.offset_x - view * extent.width;
int y0 = description.offset_y;
int x1 = x0 + description.width * description.subsampling;
int y1 = y0 + description.height * description.subsampling;
cmd.setViewport(
0,
vk::Viewport{
.x = (float)x0,
.y = (float)y0,
.width = float(description.width * description.subsampling),
.height = float(description.height * description.subsampling),
.minDepth = 0,
.maxDepth = 1,
});
x0 = std::clamp<int>(x0, 0, extent.width);
x1 = std::clamp<int>(x1, 0, extent.width);
y0 = std::clamp<int>(y0, 0, extent.height);
y1 = std::clamp<int>(y1, 0, extent.height);
cmd.setScissor(
0,
vk::Rect2D{
.offset = {.x = x0, .y = y0},
.extent = {.width = uint32_t(x1 - x0), .height = uint32_t(y1 - y0)},
});
cmd.draw(3, 1, 0, 0);
}
blitter::output blitter::end(vk::raii::CommandBuffer & cmd)
{
if (*fb)
cmd.endRenderPass();
return current;
}
} // namespace wivrn
-72
View File
@@ -1,72 +0,0 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
*
* 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 <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "vk/allocation.h"
#include "wivrn_packets.h"
#include <vulkan/vulkan_raii.hpp>
namespace wivrn
{
class blitter
{
public:
struct output
{
vk::ImageView rgb;
vk::Sampler sampler_rgb;
vk::Rect2D rect_rgb;
vk::ImageLayout layout_rgb;
vk::ImageView a;
vk::Sampler sampler_a;
vk::Rect2D rect_a;
vk::ImageLayout layout_a;
};
private:
vk::raii::Device & device;
size_t view;
to_headset::video_stream_description desc;
// indices to simply passthrough, if -1 image needs to be blitted
int passthrough_rgb = -1;
int passthrough_a = -1;
image_allocation target;
vk::raii::ImageView image_view = nullptr;
vk::raii::RenderPass rp = nullptr;
vk::raii::Framebuffer fb = nullptr;
vk::raii::Sampler sampler = nullptr;
struct pipeline_t
{
vk::raii::DescriptorSetLayout set_layout = nullptr;
vk::raii::PipelineLayout layout = nullptr;
vk::raii::Pipeline pipeline = nullptr;
bool used = false; // true if we need this image for blitting
};
std::vector<pipeline_t> pipelines;
output current;
public:
blitter(vk::raii::Device & device, size_t view);
void reset(const to_headset::video_stream_description & desc);
void begin(vk::raii::CommandBuffer &);
void push_image(vk::raii::CommandBuffer & buf, uint8_t stream, vk::Sampler sampler, const vk::Extent2D &, vk::ImageView image, vk::ImageLayout);
output end(vk::raii::CommandBuffer &);
};
} // namespace wivrn
+36 -17
View File
@@ -649,10 +649,10 @@ void scenes::lobby::render(const XrFrameState & frame_state)
if (!new_gui_position and head_position)
new_gui_position = check_recenter_action(frame_state.predictedDisplayTime, head_position->first);
if (left_hand and right_hand)
if (application::get_hand_tracking_supported())
{
auto left = left_hand->locate(world_space, frame_state.predictedDisplayTime);
auto right = right_hand->locate(world_space, frame_state.predictedDisplayTime);
auto left = application::get_left_hand().locate(world_space, frame_state.predictedDisplayTime);
auto right = application::get_right_hand().locate(world_space, frame_state.predictedDisplayTime);
hand_model::apply(world, left, right);
@@ -798,7 +798,7 @@ void scenes::lobby::on_focused()
// assert(std::ranges::all_of(views, [height](const XrViewConfigurationView & view) { return view.recommendedImageRectHeight == height; }));
renderer.emplace(device, physical_device, queue, commandpool);
loader.emplace(device, physical_device, queue, queue_family_index, renderer->get_default_material());
loader.emplace(device, physical_device, queue, application::queue_family_index(), renderer->get_default_material());
lobby_entity = load_gltf("ground.gltf", layer_lobby).first;
@@ -835,6 +835,12 @@ void scenes::lobby::on_focused()
xyz_axes_right_controller = load_gltf("xyz-arrows.glb", layer_controllers).first;
#endif
if (application::get_hand_tracking_supported())
{
hand_model::add_hand(*this, XR_HAND_LEFT_EXT, "left-hand.glb", layer_controllers);
hand_model::add_hand(*this, XR_HAND_RIGHT_EXT, "right-hand.glb", layer_controllers);
}
recenter_left_action = get_action("recenter_left").first;
recenter_right_action = get_action("recenter_right").first;
@@ -856,18 +862,20 @@ void scenes::lobby::on_focused()
.haptic_output = get_action("right_haptic").first,
},
};
if (system.hand_tracking_supported())
if (auto & hand = application::get_left_hand())
{
left_hand = session.create_hand_tracker(XR_HAND_LEFT_EXT);
right_hand = session.create_hand_tracker(XR_HAND_RIGHT_EXT);
hand_model::add_hand(*this, XR_HAND_LEFT_EXT, "left-hand.glb", layer_controllers);
hand_model::add_hand(*this, XR_HAND_RIGHT_EXT, "right-hand.glb", layer_controllers);
imgui_inputs.push_back({.hand = &*left_hand});
imgui_inputs.push_back({.hand = &*right_hand});
imgui_inputs.push_back(
{
.hand = &hand,
});
}
if (auto & hand = application::get_right_hand())
{
imgui_inputs.push_back(
{
.hand = &hand,
});
}
face_tracker = xr::make_face_tracker(instance, system, session);
// 0.4mm / pixel
std::vector<imgui_context::viewport> vps{
@@ -909,7 +917,21 @@ void scenes::lobby::on_focused()
swapchain_imgui = xr::swapchain(session, device, swapchain_format, 3000, 1300);
imgui_ctx.emplace(physical_device, device, queue_family_index, queue, imgui_inputs, swapchain_imgui, vps);
std::string image;
/* Could be used for more patriotics logos
auto t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
auto tm = std::localtime(&t);
switch (tm->tm_mon)
{
default:
image = "wivrn";
break;
}
*/
image = "wivrn";
try
{
@@ -955,9 +977,6 @@ void scenes::lobby::on_unfocused()
world.clear(); // Must be cleared before the renderer so that the descriptor sets are freed before their pools
input.reset();
left_hand.reset();
right_hand.reset();
face_tracker.emplace<std::monostate>();
loader.reset();
renderer.reset();
-6
View File
@@ -29,7 +29,6 @@
#include "wivrn_config.h"
#include "wivrn_discover.h"
#include "wivrn_packets.h"
#include "xr/face_tracker.h"
#include <vulkan/vulkan_raii.hpp>
#include <openxr/openxr.h>
@@ -67,11 +66,6 @@ class lobby : public scene_impl<lobby>
std::optional<imgui_context> imgui_ctx;
std::optional<xr::hand_tracker> left_hand;
std::optional<xr::hand_tracker> right_hand;
xr::face_tracker face_tracker;
std::string selected_item;
std::unique_ptr<asset> license;
+110 -70
View File
@@ -17,7 +17,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <uni_algo/case.h>
#define IMGUI_DEFINE_MATH_OPERATORS
#ifdef __ANDROID__
@@ -35,7 +34,6 @@
#include "utils/overloaded.h"
#include "utils/ranges.h"
#include "version.h"
#include "xr/body_tracker.h"
#include <algorithm>
#include <cassert>
#include <chrono>
@@ -142,7 +140,7 @@ static void InputText(const char * label, std::string & text, const ImVec2 & siz
return 0;
};
ImGui::InputTextEx(label, nullptr, text.data(), text.size() + 1, size, flags | ImGuiInputTextFlags_CallbackResize, callback, &text);
ImGui::InputTextEx(label, nullptr, text.data(), text.size(), size, flags | ImGuiInputTextFlags_CallbackResize, callback, &text);
}
static void display_recentering_tip(imgui_context & ctx, const std::string & tip)
@@ -795,43 +793,6 @@ void scenes::lobby::gui_settings()
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(20, 20));
{
auto language_name = [&](const std::locale & loc = std::locale()) {
return boost::locale::pgettext("language selection, replace with the name of the language", "English", loc);
};
std::vector<std::tuple<std::string, std::locale, std::string>> languages;
for (const auto & msg_info: get_locales())
{
std::string code = msg_info.language;
if (not msg_info.country.empty())
code += "_" + msg_info.country;
std::locale loc(std::locale(), boost::locale::gnu_gettext::create_messages_facet<char>(msg_info));
languages.emplace_back(language_name(loc), loc, std::move(code));
}
std::ranges::sort(languages, [](auto & l, auto & r) {
return una::casesens::collate_utf8(std::get<0>(l), std::get<0>(r)) < 0;
});
if (ImGui::BeginCombo(_S("Language"), config.locale.empty() ? _S("System language") : language_name().c_str()))
{
if (ImGui::Selectable(_S("System language"), config.locale.empty(), ImGuiSelectableFlags_SelectOnRelease))
{
config.locale.clear();
config.save();
application::instance().load_locale();
}
for (const auto & [lang, locale, code]: languages)
{
if (ImGui::Selectable(lang.c_str(), code == config.locale, ImGuiSelectableFlags_SelectOnRelease))
{
config.locale = code;
config.save();
application::instance().load_locale();
}
}
ImGui::EndCombo();
}
}
if (instance.has_extension(XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME))
{
const auto & refresh_rates = session.get_refresh_rates();
@@ -928,7 +889,7 @@ void scenes::lobby::gui_settings()
ImGui::EndDisabled();
}
{
ImGui::BeginDisabled(not system.hand_tracking_supported());
ImGui::BeginDisabled(not application::get_hand_tracking_supported());
bool enabled = config.check_feature(feature::hand_tracking);
if (ImGui::Checkbox(_S("Enable hand tracking"), &enabled))
{
@@ -952,7 +913,7 @@ void scenes::lobby::gui_settings()
ImGui::EndDisabled();
}
{
ImGui::BeginDisabled(std::holds_alternative<std::monostate>(face_tracker));
ImGui::BeginDisabled(not application::get_face_tracking_supported());
bool enabled = config.check_feature(feature::face_tracking);
if (ImGui::Checkbox(_S("Enable face tracking"), &enabled))
{
@@ -964,9 +925,8 @@ void scenes::lobby::gui_settings()
imgui_ctx->vibrate_on_hover();
}
auto body_tracker = system.body_tracker_supported();
{
ImGui::BeginDisabled(body_tracker == xr::body_tracker_type::none);
ImGui::BeginDisabled(not application::get_body_tracking_supported());
bool enabled = config.check_feature(feature::body_tracking);
if (ImGui::Checkbox(_S("Enable body tracking"), &enabled))
{
@@ -981,14 +941,19 @@ void scenes::lobby::gui_settings()
}
else
{
if (body_tracker == xr::body_tracker_type::fb)
imgui_ctx->tooltip(_("Requires 'Hand and body tracking' to be enabled in the Quest movement tracking settings,\notherwise body data will be guessed from controller and headset positions"));
std::visit(utils::overloaded{
[](auto &) {},
[this](xr::fb_body_tracker &) {
imgui_ctx->tooltip(_("Requires 'Hand and body tracking' to be enabled in the Quest movement tracking settings,\notherwise body data will be guessed from controller and headset positions"));
},
},
application::get_body_tracker());
}
}
imgui_ctx->vibrate_on_hover();
}
if (body_tracker == xr::body_tracker_type::fb)
if (std::holds_alternative<xr::fb_body_tracker>(application::get_body_tracker()))
{
ImGui::BeginDisabled(not config.check_feature(feature::body_tracking));
ImGui::Indent();
@@ -1014,7 +979,7 @@ void scenes::lobby::gui_settings()
ImGui::EndDisabled();
}
ImGui::BeginDisabled(system.passthrough_supported() == xr::passthrough_type::none);
ImGui::BeginDisabled(passthrough_supported == xr::system::passthrough_type::no_passthrough);
if (ImGui::Checkbox(_S("Enable video passthrough in lobby"), &config.passthrough_enabled))
{
setup_passthrough();
@@ -1098,6 +1063,89 @@ void scenes::lobby::gui_post_processing()
ImGui::Unindent();
}
{
// SGSR
{
if (ImGui::Checkbox(_S("Enable Snapdragon Game Super Resolution"), &config.sgsr.enabled))
{
config.save();
}
imgui_ctx->vibrate_on_hover();
if (ImGui::IsItemHovered())
{
if (application::get_openxr_post_processing_supported())
imgui_ctx->tooltip(_("On this headset, this setting has been fully superseded by the native Sharpening setting above.\nOnly enable if you know what you're doing."));
else
imgui_ctx->tooltip(_("Client-side upscaling and sharpening, adds a performance cost on the headset"));
}
if (application::get_openxr_post_processing_supported())
{
ImGui::SameLine();
ImGui::TextColored(ImColor(0xf9, 0x73, 0x06) /*orange*/, ICON_FA_TRIANGLE_EXCLAMATION);
}
}
{
ImGui::BeginDisabled(not config.sgsr.enabled);
ImGui::Indent();
{
const auto current = config.sgsr.upscaling_factor;
const auto width = stream_view.recommendedImageRectWidth * config.resolution_scale;
const auto height = stream_view.recommendedImageRectHeight * config.resolution_scale;
auto intScale = int(current * 100);
const auto slider = ImGui::SliderInt(
_("Upscaling factor").append("##upscaling_factor").c_str(),
&intScale,
100,
200,
fmt::format(_F("%d%% - {}x{} per eye"), int(width * current), int(height * current)).c_str());
if (slider)
{
config.sgsr.upscaling_factor = intScale * 0.01;
config.save();
}
imgui_ctx->vibrate_on_hover();
if (width * current > stream_view.maxImageRectWidth or height * current > stream_view.maxImageRectHeight)
{
ImGui::TextColored(ImColor(0xf9, 0x73, 0x06) /*orange*/, ICON_FA_TRIANGLE_EXCLAMATION);
ImGui::SameLine();
ImGui::Text("%s", fmt::format(_F("Resolution larger than {}x{} may not be supported by the headset"), stream_view.maxImageRectWidth, stream_view.maxImageRectHeight).c_str());
}
}
{
if (ImGui::Checkbox(_S("Use edge direction"), &config.sgsr.use_edge_direction))
{
config.save();
}
imgui_ctx->vibrate_on_hover();
if (ImGui::IsItemHovered())
imgui_ctx->tooltip(_("Adds an additional performance cost"));
}
{
const float current = config.sgsr.edge_threshold;
int intScale = int(current);
if (ImGui::SliderInt(_S("Edge threshold"), &intScale, 1, 16, "%d.0"))
{
config.sgsr.edge_threshold = float(intScale);
config.save();
}
imgui_ctx->vibrate_on_hover();
if (ImGui::IsItemHovered())
imgui_ctx->tooltip(fmt::format(_F("Recommended: {:.1f}"), 4.0));
}
{
if (ImGui::SliderFloat(_S("Edge sharpness"), &config.sgsr.edge_sharpness, 1.0, 2.0, "%.2f"))
{
config.save();
}
imgui_ctx->vibrate_on_hover();
if (ImGui::IsItemHovered())
imgui_ctx->tooltip(fmt::format(_F("Recommended: {:.1f}"), 2.0));
}
ImGui::Unindent();
ImGui::EndDisabled();
}
}
ImGui::PopStyleVar();
}
@@ -1263,12 +1311,12 @@ void scenes::lobby::gui_first_run()
item{
.f = feature::face_tracking,
.text = _S("Enable face tracking?"),
.supported = not std::holds_alternative<std::monostate>(face_tracker),
.supported = application::get_face_tracking_supported(),
},
item{
.f = feature::body_tracking,
.text = _S("Enable body tracking?"),
.supported = system.body_tracker_supported() != xr::body_tracker_type::none,
.supported = application::get_body_tracking_supported(),
},
};
@@ -1328,7 +1376,7 @@ void scenes::lobby::gui_licenses()
ImGui::Text("%s", _("Licenses").c_str());
ImGui::PopFont();
const auto components = {"WiVRn", "FontAwesome", "openxr-loader", "simdjson"};
const auto components = {"WiVRn", "FontAwesome", "openxr-loader", "simdjson", "SGSR"};
if (not license)
{
selected_item = *components.begin();
@@ -1598,22 +1646,11 @@ static auto face_weights()
return res;
}
static const char * get_face_icon(XrTime predicted_display_time, xr::face_tracker & face_tracker)
static const char * get_face_icon(XrTime predicted_display_time)
{
static const auto w = face_weights();
wivrn::from_headset::tracking::fb_face2 expression;
const char * result = nullptr;
std::visit(utils::overloaded{
[](std::monostate &) {},
[&](xr::htc_face_tracker &) { result = ICON_FA_FACE_SMILE_WINK; },
[&](auto & ft) {
ft.get_weights(predicted_display_time, expression);
},
},
face_tracker);
if (result)
return result;
std::get<xr::fb_face_tracker2>(application::get_face_tracker()).get_weights(predicted_display_time, expression);
if (not expression.is_valid)
return ICON_FA_FACE_MEH;
@@ -1656,7 +1693,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
.icon_disabled = ICON_FA_MICROPHONE_SLASH,
});
if (system.hand_tracking_supported())
if (application::get_hand_tracking_supported())
{
items.push_back({
.f = feature::hand_tracking,
@@ -1677,18 +1714,21 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
});
}
if (not std::holds_alternative<std::monostate>(face_tracker))
if (application::get_face_tracking_supported())
{
const char * icon_enabled = std::holds_alternative<xr::fb_face_tracker2>(application::get_face_tracker())
? get_face_icon(predicted_display_time)
: ICON_FA_FACE_KISS_WINK_HEART;
items.push_back({
.f = feature::face_tracking,
.tooltip_enabled = _("Face tracking is enabled"),
.tooltip_disabled = _("Face tracking is disabled"),
.icon_enabled = get_face_icon(predicted_display_time, face_tracker),
.icon_enabled = icon_enabled,
.icon_disabled = ICON_FA_FACE_MEH_BLANK,
});
}
if (system.body_tracker_supported() != xr::body_tracker_type::none)
if (application::get_body_tracking_supported())
{
items.push_back({
.f = feature::body_tracking,
@@ -1762,7 +1802,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
if (*status.charge > 0.995)
icon_nr = 5;
else
icon_nr = instance.now() / 500'000'000 % 5;
icon_nr = application::now() / 500'000'000 % 5;
}
else
icon_nr = std::round((*status.charge) * 4);
@@ -1991,7 +2031,7 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
if (not is_gui_visible(*imgui_ctx, predicted_display_time))
{
if (system.hand_tracking_supported())
if (application::get_hand_tracking_supported())
display_recentering_tip(*imgui_ctx, _("Press the grip button or put your palm up\nto move the main window"));
else
display_recentering_tip(*imgui_ctx, _("Press the grip button to move the main window"));
+378 -78
View File
@@ -17,9 +17,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "constants.h"
#include "xr/body_tracker.h"
#include "xr/face_tracker.h"
#include "utils/overloaded.h"
#include "xr/fb_body_tracker.h"
#include "xr/fb_face_tracker2.h"
#include "xr/htc_body_tracker.h"
#include "xr/pico_body_tracker.h"
#include "xr/space.h"
#include <glm/gtc/matrix_access.hpp>
#include <glm/gtc/quaternion.hpp>
@@ -38,6 +40,8 @@
#include "utils/contains.h"
#include "utils/named_thread.h"
#include "utils/ranges.h"
#include "vk/pipeline.h"
#include "vk/shader.h"
#include "wivrn_packets.h"
#include <algorithm>
#include <mutex>
@@ -45,11 +49,6 @@
#include <thread>
#include <vulkan/vulkan_raii.hpp>
#include "wivrn_config.h"
#if WIVRN_FEATURE_RENDERDOC
#include "vk/renderdoc.h"
#endif
using namespace wivrn;
// clang-format off
@@ -152,8 +151,7 @@ static const std::array supported_depth_formats{
};
scenes::stream::stream() :
scene_impl<stream>(supported_color_formats, supported_depth_formats),
blitters{blitter(device, 0), blitter(device, 1)}
scene_impl<stream>(supported_color_formats, supported_depth_formats)
{
}
@@ -257,49 +255,46 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
if (config.check_feature(feature::face_tracking))
{
switch (self->system.face_tracker_supported())
{
case xr::face_tracker_type::none:
info.face_tracking = from_headset::face_type::none;
break;
case xr::face_tracker_type::fb:
case xr::face_tracker_type::pico:
info.face_tracking = from_headset::face_type::fb2;
break;
case xr::face_tracker_type::htc:
info.face_tracking = from_headset::face_type::htc;
break;
}
info.face_tracking = std::visit(utils::overloaded{
[](std::monostate &) {
return from_headset::face_type::none;
},
[](xr::fb_face_tracker2 &) {
return from_headset::face_type::fb2;
},
[](xr::htc_face_tracker &) {
return from_headset::face_type::htc;
},
[](xr::pico_face_tracker &) {
return from_headset::face_type::fb2;
},
},
application::get_face_tracker());
}
info.num_generic_trackers = 0;
if (config.check_feature(feature::body_tracking))
{
switch (self->system.body_tracker_supported())
{
case xr::body_tracker_type::none:
break;
case xr::body_tracker_type::fb:
info.num_generic_trackers = xr::fb_body_tracker::get_whitelisted_joints(config.fb_lower_body, config.fb_hip).size();
break;
case xr::body_tracker_type::htc:
info.num_generic_trackers = application::get_generic_trackers().size();
break;
case xr::body_tracker_type::pico:
info.num_generic_trackers = xr::pico_body_tracker::joint_whitelist.size();
break;
}
info.num_generic_trackers = std::visit(utils::overloaded{
[&](std::monostate &) {
return size_t(0);
},
[&](auto & b) {
return b.count();
},
},
application::get_body_tracker());
}
info.palm_pose = application::space(xr::spaces::palm_left) or application::space(xr::spaces::palm_right);
info.passthrough = self->system.passthrough_supported() != xr::passthrough_type::none;
info.passthrough = self->system.passthrough_supported() != xr::system::passthrough_type::no_passthrough;
info.system_name = std::string(self->system.properties().systemName);
audio::get_audio_description(info);
if (not(config.check_feature(feature::microphone)))
info.microphone = {};
info.supported_codecs = decoder::supported_codecs();
info.supported_codecs = decoder_impl::supported_codecs();
return info;
}());
@@ -363,7 +358,7 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
{
self->haptics_actions.emplace(id, haptics_action{
.action = action.first,
.path = self->instance.string_to_path(path),
.path = application::string_to_path(path),
});
}
}
@@ -394,7 +389,7 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
void scenes::stream::on_focused()
{
gui_status_last_change = instance.now();
gui_status_last_change = application::now();
auto views = system.view_configuration_views(viewconfig);
// stream_view = override_view(views[0], guess_model());
@@ -402,7 +397,7 @@ void scenes::stream::on_focused()
height = views[0].recommendedImageRectHeight;
renderer.emplace(device, physical_device, queue, commandpool);
loader.emplace(device, physical_device, queue, queue_family_index, renderer->get_default_material());
loader.emplace(device, physical_device, queue, application::queue_family_index(), renderer->get_default_material());
std::string profile = controller_name();
input.emplace(
@@ -497,8 +492,6 @@ void scenes::stream::on_unfocused()
loader.reset();
renderer.reset();
clear_swapchains();
left_hand.reset();
right_hand.reset();
imgui_ctx.reset();
swapchain_imgui = xr::swapchain();
@@ -529,16 +522,16 @@ void scenes::stream::push_blit_handle(shard_accumulator * decoder, std::shared_p
{
if (decoder != decoders[stream].decoder.get())
return;
handle->feedback.received_from_decoder = instance.now();
handle->feedback.received_from_decoder = application::now();
std::swap(handle, decoders[stream].latest_frames[handle->feedback.frame_index % decoders[stream].latest_frames.size()]);
}
if (state_ != state::streaming and std::ranges::all_of(decoders, [](accumulator_images & i) {
return i.alpha() or not i.empty();
return i.alpha() or not i.frames().empty();
}))
{
state_ = state::streaming;
spdlog::info("Stream scene ready at t={}", instance.now());
spdlog::info("Stream scene ready at t={}", application::now());
}
}
@@ -553,14 +546,15 @@ bool scenes::stream::accumulator_images::alpha() const
return decoder->desc().channels == wivrn::to_headset::video_stream_description::channels_t::alpha;
}
bool scenes::stream::accumulator_images::empty() const
std::vector<uint64_t> scenes::stream::accumulator_images::frames() const
{
std::vector<uint64_t> result;
for (const auto & frame: latest_frames)
{
if (frame)
return false;
result.push_back(frame->feedback.frame_index);
}
return true;
return result;
}
std::vector<std::shared_ptr<shard_accumulator::blit_handle>> scenes::stream::common_frame(XrTime display_time)
@@ -781,6 +775,135 @@ void scenes::stream::render(const XrFrameState & frame_state)
}
assert(swapchain);
for (auto & i: decoders)
{
if (auto sampler = i.decoder->sampler(); sampler and not *i.blit_pipeline)
{
// Create blit pipeline
// Create VkDescriptorSetLayout with an immutable sampler
vk::DescriptorSetLayoutBinding sampler_layout_binding{
.binding = 0,
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
.descriptorCount = 1,
.stageFlags = vk::ShaderStageFlagBits::eFragment,
.pImmutableSamplers = &sampler,
};
vk::DescriptorSetLayoutCreateInfo layout_info{
.bindingCount = 1,
.pBindings = &sampler_layout_binding,
};
i.descriptor_set_layout = vk::raii::DescriptorSetLayout(device, layout_info);
i.descriptor_set = device.allocateDescriptorSets(
vk::DescriptorSetAllocateInfo{
.descriptorPool = *blit_descriptor_pool,
.descriptorSetCount = 1,
.pSetLayouts = &*i.descriptor_set_layout,
})[0]
.release();
const auto & description = i.decoder->desc();
vk::Extent2D image_size = i.decoder->image_size();
std::array useful_size{
float(description.width) / image_size.width,
float(description.height) / image_size.height,
};
spdlog::info("useful size: {}x{} with buffer {}x{}",
description.width,
description.height,
image_size.width,
image_size.height);
std::array specialization_constants_desc{
vk::SpecializationMapEntry{
.constantID = 0,
.offset = 0,
.size = sizeof(float),
},
vk::SpecializationMapEntry{
.constantID = 1,
.offset = sizeof(float),
.size = sizeof(float),
}};
vk::SpecializationInfo vert_specialization_info;
vert_specialization_info.setMapEntries(specialization_constants_desc);
vert_specialization_info.setData<float>(useful_size);
std::array<VkBool32, 2> constants = {
need_srgb_conversion(guess_model()),
i.alpha(),
};
std::array frag_specialization_constant_desc = {
vk::SpecializationMapEntry{
.constantID = 0,
.offset = 0,
.size = sizeof(constants[0]),
},
vk::SpecializationMapEntry{
.constantID = 1,
.offset = sizeof(constants[0]),
.size = sizeof(constants[1]),
},
};
vk::SpecializationInfo frag_specialization_info;
frag_specialization_info.setMapEntries(frag_specialization_constant_desc);
frag_specialization_info.setData<VkBool32>(constants);
// Create graphics pipeline
vk::raii::ShaderModule vertex_shader = load_shader(device, "stream.vert");
vk::raii::ShaderModule fragment_shader = load_shader(device, "stream.frag");
vk::PipelineLayoutCreateInfo pipeline_layout_info{
.setLayoutCount = 1,
.pSetLayouts = &*i.descriptor_set_layout,
};
i.blit_pipeline_layout = vk::raii::PipelineLayout(device, pipeline_layout_info);
vk::pipeline_builder pipeline_info{
.Stages = {{
.stage = vk::ShaderStageFlagBits::eVertex,
.module = *vertex_shader,
.pName = "main",
.pSpecializationInfo = &vert_specialization_info,
},
{
.stage = vk::ShaderStageFlagBits::eFragment,
.module = *fragment_shader,
.pName = "main",
.pSpecializationInfo = &frag_specialization_info,
}},
.VertexBindingDescriptions = {},
.VertexAttributeDescriptions = {},
.InputAssemblyState = {{
.topology = vk::PrimitiveTopology::eTriangleStrip,
}},
// With vk::DynamicState::eViewport, vk::DynamicState::eScissor the number of viewports
// and scissors is still used, put a vector with one element
.Viewports = {{}},
.Scissors = {{}},
.RasterizationState = {{
.polygonMode = vk::PolygonMode::eFill,
.lineWidth = 1,
}},
.MultisampleState = {{
.rasterizationSamples = vk::SampleCountFlagBits::e1,
}},
.ColorBlendAttachments = {
{.colorWriteMask = i.alpha() ? vk::ColorComponentFlagBits::eA
: vk::ColorComponentFlagBits::eA | vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB}},
.DynamicStates = {vk::DynamicState::eViewport, vk::DynamicState::eScissor},
.layout = *i.blit_pipeline_layout,
.renderPass = *blit_render_pass,
.subpass = 0,
};
i.blit_pipeline = vk::raii::Pipeline(device, application::get_pipeline_cache(), pipeline_info);
}
}
if (device.waitForFences(*fence, VK_TRUE, UINT64_MAX) == vk::Result::eTimeout)
throw std::runtime_error("Vulkan fence timeout");
@@ -811,13 +934,11 @@ void scenes::stream::render(const XrFrameState & frame_state)
std::array<int, view_count> image_indices;
#if WIVRN_FEATURE_RENDERDOC
renderdoc_begin(*vk_instance);
#endif
command_buffer.reset();
command_buffer.begin(vk::CommandBufferBeginInfo{
.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit,
});
vk::CommandBufferBeginInfo begin_info;
begin_info.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit;
command_buffer.begin(begin_info);
// Keep a reference to the resources needed to blit the images until vkWaitForFences
@@ -832,12 +953,13 @@ void scenes::stream::render(const XrFrameState & frame_state)
std::array<wivrn::to_headset::foveation_parameter, 2> foveation{};
bool use_alpha = false;
for (auto & blit_handle: current_blit_handles)
// Blit images from the decoders
for (auto [i, blit_handle]: std::views::zip(decoders, current_blit_handles))
{
if (not blit_handle)
if (not blit_handle or not *i.blit_pipeline)
continue;
blit_handle->feedback.blitted = instance.now();
blit_handle->feedback.blitted = application::now();
if (blit_handle->feedback.blitted - blit_handle->feedback.received_from_decoder > 1'000'000'000)
state_ = stream::state::stalled;
++blit_handle->feedback.times_displayed;
@@ -848,12 +970,27 @@ void scenes::stream::render(const XrFrameState & frame_state)
foveation = blit_handle->view_info.foveation;
use_alpha = blit_handle->view_info.alpha;
if (blit_handle->current_layout == vk::ImageLayout::eUndefined)
vk::DescriptorImageInfo image_info{
.imageView = *blit_handle->image_view,
.imageLayout = vk::ImageLayout::eGeneral,
};
vk::WriteDescriptorSet descriptor_write{
.dstSet = i.descriptor_set,
.dstBinding = 0,
.dstArrayElement = 0,
.descriptorCount = 1,
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
.pImageInfo = &image_info,
};
device.updateDescriptorSets(descriptor_write, {});
if (*blit_handle->current_layout != vk::ImageLayout::eGeneral)
{
vk::ImageMemoryBarrier barrier{
.srcAccessMask = vk::AccessFlagBits::eNone,
.dstAccessMask = vk::AccessFlagBits::eMemoryRead,
.oldLayout = vk::ImageLayout::eUndefined,
.oldLayout = *blit_handle->current_layout,
.newLayout = vk::ImageLayout::eGeneral,
.image = blit_handle->image,
.subresourceRange = {
@@ -864,22 +1001,72 @@ void scenes::stream::render(const XrFrameState & frame_state)
};
command_buffer.pipelineBarrier(vk::PipelineStageFlagBits::eAllCommands, vk::PipelineStageFlagBits::eAllCommands, {}, {}, {}, barrier);
blit_handle->current_layout = vk::ImageLayout::eGeneral;
*blit_handle->current_layout = vk::ImageLayout::eGeneral;
}
}
// Blit images from the decoders
std::array<blitter::output, view_count> blitted;
for (auto [i, b]: utils::enumerate(blitters))
uint16_t x_offset = 0;
for (auto & out: decoder_output)
{
b.begin(command_buffer);
for (auto [j, blit_handle]: utils::enumerate(current_blit_handles))
command_buffer.beginRenderPass(
{
.renderPass = *blit_render_pass,
.framebuffer = *out.frame_buffer,
.renderArea = {
.offset = {0, 0},
.extent = decoder_out_size,
},
.clearValueCount = 0,
},
vk::SubpassContents::eInline);
for (const auto & decoder: decoders)
{
if (not blit_handle)
if (not *decoder.blit_pipeline)
continue;
b.push_image(command_buffer, j, decoders[j].decoder->sampler(), decoders[j].decoder->extent(), blit_handle->image_view, blit_handle->current_layout);
if (decoder.alpha() and not use_alpha)
continue;
command_buffer.bindPipeline(vk::PipelineBindPoint::eGraphics, *decoder.blit_pipeline);
const auto & description = decoder.decoder->desc();
int x0 = description.offset_x - x_offset;
int y0 = description.offset_y;
int x1 = x0 + description.width * description.subsampling;
int y1 = y0 + description.height * description.subsampling;
vk::Viewport viewport{
.x = (float)x0,
.y = (float)y0,
.width = float(description.width * description.subsampling),
.height = float(description.height * description.subsampling),
.minDepth = 0,
.maxDepth = 1,
};
x0 = std::clamp<int>(x0, 0, decoder_out_size.width);
x1 = std::clamp<int>(x1, 0, decoder_out_size.width);
y0 = std::clamp<int>(y0, 0, decoder_out_size.height);
y1 = std::clamp<int>(y1, 0, decoder_out_size.height);
vk::Rect2D scissor{
.offset = {.x = x0, .y = y0},
.extent = {.width = (uint32_t)(x1 - x0), .height = (uint32_t)(y1 - y0)},
};
command_buffer.setViewport(0, viewport);
command_buffer.setScissor(0, scissor);
command_buffer.bindDescriptorSets(
vk::PipelineBindPoint::eGraphics,
*decoder.blit_pipeline_layout,
0,
decoder.descriptor_set,
nullptr);
command_buffer.draw(3, 1, 0, 0);
}
blitted[i] = b.end(command_buffer);
command_buffer.endRenderPass();
x_offset += decoder_out_size.width;
}
command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 1);
@@ -890,7 +1077,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
int32_t max_height = 0;
for (size_t i = 0; i < view_count; ++i)
{
extents[i] = defoveator->defoveated_size(foveation[i]);
extents[i] = reprojector->defoveated_size(foveation[i]);
max_width = std::max(max_width, extents[i].width);
max_height = std::max(max_height, extents[i].height);
}
@@ -920,7 +1107,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
// defoveate the image
int image_index = swapchain.acquire();
swapchain.wait();
defoveator->defoveate(command_buffer, foveation, blitted, image_index);
reprojector->reproject(command_buffer, foveation, image_index);
command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 2);
@@ -928,9 +1115,6 @@ void scenes::stream::render(const XrFrameState & frame_state)
vk::SubmitInfo submit_info;
submit_info.setCommandBuffers(*command_buffer);
queue.lock()->submit(submit_info, *fence);
#if WIVRN_FEATURE_RENDERDOC
renderdoc_end(*vk_instance);
#endif
swapchain.release();
std::vector<XrCompositionLayerProjectionView> layer_view(view_count);
@@ -1097,15 +1281,119 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript
}
video_stream_description = description;
for (auto & b: blitters)
b.reset(description);
const uint32_t video_width = description.width / view_count;
const uint32_t video_height = description.height;
// Create renderpass
{
vk::AttachmentDescription color_desc{
.format = vk::Format::eA8B8G8R8SrgbPack32,
.samples = vk::SampleCountFlagBits::e1,
.loadOp = vk::AttachmentLoadOp::eDontCare,
.storeOp = vk::AttachmentStoreOp::eStore,
.initialLayout = vk::ImageLayout::eUndefined,
.finalLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
};
vk::AttachmentReference color_ref{
.attachment = 0,
.layout = vk::ImageLayout::eColorAttachmentOptimal,
};
vk::SubpassDescription subpass{
.pipelineBindPoint = vk::PipelineBindPoint::eGraphics,
};
subpass.setColorAttachments(color_ref);
vk::RenderPassCreateInfo renderpass_info{
.flags = {},
};
renderpass_info.setAttachments(color_desc);
renderpass_info.setSubpasses(subpass);
blit_render_pass = vk::raii::RenderPass(device, renderpass_info);
}
// Create outputs for the decoders
decoder_out_size = vk::Extent2D{video_width, video_height};
{
decoder_out_format = vk::Format::eA8B8G8R8SrgbPack32;
vk::ImageCreateInfo image_info{
.flags = vk::ImageCreateFlags{},
.imageType = vk::ImageType::e2D,
.format = vk::Format::eA8B8G8R8SrgbPack32,
.extent = {video_width, video_height, 1},
.mipLevels = 1,
.arrayLayers = view_count,
.samples = vk::SampleCountFlagBits::e1,
.tiling = vk::ImageTiling::eOptimal,
.usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eColorAttachment,
.sharingMode = vk::SharingMode::eExclusive,
.initialLayout = vk::ImageLayout::eUndefined,
};
VmaAllocationCreateInfo alloc_info{
.requiredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
};
decoder_out_image = image_allocation{device, image_info, alloc_info};
vk::ImageViewCreateInfo image_view_info{
.image = vk::Image{decoder_out_image},
.viewType = vk::ImageViewType::e2D,
.format = vk::Format::eA8B8G8R8SrgbPack32,
.components = {},
.subresourceRange = {
.aspectMask = vk::ImageAspectFlagBits::eColor,
.baseMipLevel = 0,
.levelCount = 1,
.baseArrayLayer = 0,
.layerCount = 1,
},
};
for (uint32_t view = 0; view < view_count; ++view)
{
auto & output = decoder_output[view];
image_view_info.subresourceRange.baseArrayLayer = view;
output.image_view = vk::raii::ImageView(device, image_view_info);
output.frame_buffer = vk::raii::Framebuffer(
device,
vk::FramebufferCreateInfo{
.renderPass = *blit_render_pass,
.attachmentCount = 1,
.pAttachments = &*output.image_view,
.width = decoder_out_size.width,
.height = decoder_out_size.height,
.layers = 1,
});
}
}
{
vk::DescriptorPoolSize pool_size{
.type = vk::DescriptorType::eCombinedImageSampler,
.descriptorCount = uint32_t(2 * description.items.size()),
};
blit_descriptor_pool = vk::raii::DescriptorPool(
device,
vk::DescriptorPoolCreateInfo{
.maxSets = uint32_t(2 * description.items.size()),
.poolSizeCount = 1,
.pPoolSizes = &pool_size,
});
}
for (const auto & [stream_index, item]: utils::enumerate(description.items))
{
spdlog::info("Creating decoder size {}x{} offset {},{}", item.width, item.height, item.offset_x, item.offset_y);
decoders.push_back(accumulator_images{
.decoder = std::make_unique<shard_accumulator>(device, physical_device, instance, item, description.fps, shared_from_this(), stream_index),
.decoder = std::make_unique<shard_accumulator>(device, physical_device, item, description.fps, shared_from_this(), stream_index),
});
}
}
@@ -1118,6 +1406,15 @@ void scenes::stream::setup_reprojection_swapchain(uint32_t swapchain_width, uint
const uint32_t video_width = video_stream_description->width / view_count;
const uint32_t video_height = video_stream_description->height;
const configuration::sgsr_settings sgsr = application::get_config().sgsr;
if (sgsr.enabled)
{
const float upscaling_factor = sgsr.upscaling_factor;
spdlog::info("Using SGSR with an upscale factor of {}", upscaling_factor);
swapchain_width *= upscaling_factor;
swapchain_height *= upscaling_factor;
}
auto views = system.view_configuration_views(viewconfig);
swapchain = xr::swapchain(session, device, swapchain_format, swapchain_width, swapchain_height, 1, views.size());
@@ -1134,9 +1431,12 @@ void scenes::stream::setup_reprojection_swapchain(uint32_t swapchain_width, uint
for (auto & image: swapchain.images())
swapchain_images.push_back(image.image);
defoveator.emplace(
reprojector.emplace(
device,
physical_device,
decoder_out_image,
vk::Extent2D{.width = video_width, .height = video_height},
2,
swapchain_images,
extent,
swapchain.format());
+23 -10
View File
@@ -21,11 +21,11 @@
#include "audio/audio.h"
#include "decoder/shard_accumulator.h"
#include "imgui.h"
#include "render/imgui_impl.h"
#include "scene.h"
#include "scenes/blitter.h"
#include "scenes/input_profile.h"
#include "stream_defoveator.h"
#include "stream_reprojection.h"
#include "utils/thread_safe.h"
#include "wifi_lock.h"
#include "wivrn_client.h"
@@ -64,12 +64,16 @@ private:
struct accumulator_images
{
std::unique_ptr<wivrn::shard_accumulator> decoder;
// latest frames, rolling buffer
vk::raii::DescriptorSetLayout descriptor_set_layout = nullptr;
vk::DescriptorSet descriptor_set = nullptr;
vk::raii::PipelineLayout blit_pipeline_layout = nullptr;
vk::raii::Pipeline blit_pipeline = nullptr;
// latest frames from oldest to most recent
std::array<std::shared_ptr<wivrn::shard_accumulator::blit_handle>, image_buffer_size> latest_frames;
std::shared_ptr<wivrn::shard_accumulator::blit_handle> frame(uint64_t id) const;
bool alpha() const;
bool empty() const;
std::vector<uint64_t> frames() const;
};
wifi_lock::wifi wifi;
@@ -81,9 +85,9 @@ private:
std::unique_ptr<wivrn_session> network_session;
std::atomic<bool> exiting = false;
std::thread network_thread;
thread_safe<to_headset::tracking_control> tracking_control{};
std::mutex tracking_control_mutex;
to_headset::tracking_control tracking_control{};
std::array<std::atomic<interaction_profile>, 2> interaction_profiles; // left and right hand
std::atomic<bool> interaction_profile_changed = false;
std::atomic<bool> recenter_requested = false;
std::atomic<XrDuration> display_time_phase = 0;
std::atomic<XrDuration> display_time_period = 0;
@@ -94,10 +98,21 @@ private:
std::shared_mutex decoder_mutex;
std::optional<to_headset::video_stream_description> video_stream_description;
std::vector<accumulator_images> decoders; // Locked by decoder_mutex
vk::raii::DescriptorPool blit_descriptor_pool = nullptr;
vk::raii::RenderPass blit_render_pass = nullptr;
std::array<blitter, view_count> blitters;
vk::Extent2D decoder_out_size;
vk::Format decoder_out_format;
image_allocation decoder_out_image;
std::optional<stream_defoveator> defoveator;
struct renderpass_output
{
vk::raii::ImageView image_view = nullptr;
vk::raii::Framebuffer frame_buffer = nullptr;
};
std::array<renderpass_output, view_count> decoder_output;
std::optional<stream_reprojection> reprojector;
vk::raii::Fence fence = nullptr;
vk::raii::CommandBuffer command_buffer = nullptr;
@@ -118,8 +133,6 @@ private:
std::optional<audio> audio_handle;
std::optional<xr::hand_tracker> left_hand;
std::optional<xr::hand_tracker> right_hand;
std::optional<input_profile> input;
static inline const uint32_t layer_controllers = 1 << 0;
static inline const uint32_t layer_rays = 1 << 1;
+6 -30
View File
@@ -389,14 +389,8 @@ void scenes::stream::gui_performance_metrics()
ImPlot::PopStyleColor(5);
{
ImGui::Text(
"%s",
fmt::format(
_F("Estimated motion to photons latency: {}ms"),
std::chrono::duration_cast<std::chrono::milliseconds>(
tracking_control.lock()->max_offset)
.count())
.c_str());
std::lock_guard lock(tracking_control_mutex);
ImGui::Text("%s", fmt::format(_F("Estimated motion to photons latency: {}ms"), std::chrono::duration_cast<std::chrono::milliseconds>(tracking_control.max_offset).count()).c_str());
if (is_gui_interactable())
ImGui::Text("%s", _S("Press the grip button to move the window"));
@@ -423,12 +417,7 @@ void scenes::stream::gui_compact_view()
f(_S("Upload"), 8 * compact_bandwidth_tx * 1e-6, "Mbit/s");
f(_S("CPU time"), compact_cpu_time * 1000, "ms");
f(_S("GPU time"), compact_gpu_time * 1000, "ms");
f(_S("Motion to photon latency"),
std::chrono::duration_cast<std::chrono::microseconds>(
tracking_control.lock()->max_offset)
.count() *
1e-3f,
"ms");
f(_S("Motion to photon latency"), std::chrono::duration_cast<std::chrono::microseconds>(tracking_control.max_offset).count() * 1e-3f, "ms");
ImGui::EndTable();
}
}
@@ -645,19 +634,6 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
break;
}
imgui_ctx->set_controllers_enabled(interactable);
if (interactable)
{
if (system.hand_tracking_supported())
{
left_hand = session.create_hand_tracker(XR_HAND_LEFT_EXT);
right_hand = session.create_hand_tracker(XR_HAND_RIGHT_EXT);
}
}
else
{
left_hand.reset();
right_hand.reset();
}
if (gui_status != last_gui_status)
{
@@ -889,10 +865,10 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
bool hide_left_controller = false;
bool hide_right_controller = false;
if (left_hand and right_hand)
if (application::get_hand_tracking_supported())
{
auto left = left_hand->locate(world_space, predicted_display_time);
auto right = right_hand->locate(world_space, predicted_display_time);
auto left = application::get_left_hand().locate(world_space, predicted_display_time);
auto right = application::get_right_hand().locate(world_space, predicted_display_time);
if (left and xr::hand_tracker::check_flags(*left, XR_SPACE_LOCATION_POSITION_TRACKED_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT, 0))
hide_left_controller = true;
@@ -17,14 +17,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "stream_defoveator.h"
#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 "vk/specialization_constants.h"
#include <array>
#include <glm/glm.hpp>
#include <glm/gtx/quaternion.hpp>
@@ -32,21 +31,22 @@
#include <vulkan/vulkan_core.h>
#include <vulkan/vulkan_raii.hpp>
struct stream_defoveator::vertex
struct stream_reprojection::vertex
{
// output image position
alignas(8) glm::vec2 position;
// input texture coordinates + shading rate in the first 4 bits of x
alignas(8) glm::uvec2 uv;
// input texture coordinates
alignas(8) glm::vec2 uv;
};
struct vert_pc
struct SgsrSpecializationConstants
{
glm::ivec4 rgb_rect;
glm::ivec4 a_rect;
VkBool32 use_edge_direction;
float edge_threshold;
float edge_sharpness;
};
void stream_defoveator::ensure_vertices(size_t num_vertices)
void stream_reprojection::ensure_vertices(size_t num_vertices)
{
vk::BufferCreateInfo create_info{
.size = num_vertices * sizeof(vertex) * view_count,
@@ -65,81 +65,212 @@ void stream_defoveator::ensure_vertices(size_t num_vertices)
vertices_size = num_vertices * sizeof(vertex);
}
stream_defoveator::vertex * stream_defoveator::get_vertices(size_t view)
stream_reprojection::vertex * stream_reprojection::get_vertices(size_t view)
{
assert(buffer);
return reinterpret_cast<vertex *>(reinterpret_cast<uintptr_t>(buffer.map()) + view * vertices_size);
}
stream_defoveator::pipeline_t & stream_defoveator::ensure_pipeline(size_t view, vk::Sampler rgb, vk::Sampler a)
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<vk::Image> output_images_,
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_)),
output_extent(output_extent)
{
auto & target = a ? pipeline_a[view] : pipeline_rgb[view];
if (*target.pipeline)
return target;
vk::SamplerCreateInfo sampler_info{
.magFilter = vk::Filter::eLinear,
.minFilter = vk::Filter::eLinear,
.mipmapMode = vk::SamplerMipmapMode::eNearest,
.addressModeU = vk::SamplerAddressMode::eClampToBorder,
.addressModeV = vk::SamplerAddressMode::eClampToBorder,
.addressModeW = vk::SamplerAddressMode::eClampToBorder,
.mipLodBias = 0.0f,
.anisotropyEnable = VK_FALSE,
.maxAnisotropy = 1,
.compareEnable = VK_FALSE,
.compareOp = vk::CompareOp::eNever,
.minLod = 0.0f,
.maxLod = 0.0f,
.borderColor = vk::BorderColor::eFloatOpaqueBlack,
.unnormalizedCoordinates = VK_FALSE,
};
std::array samplers{rgb, a};
int32_t alpha = a ? 1 : 0;
if (utils::contains(application::get_vk_device_extensions(), VK_IMG_FILTER_CUBIC_EXTENSION_NAME))
sampler_info.magFilter = vk::Filter::eCubicIMG;
sampler = vk::raii::Sampler(device, sampler_info);
// Create VkDescriptorSetLayout
std::array layout_binding{
vk::DescriptorSetLayoutBinding{
.binding = 0,
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
.descriptorCount = uint32_t(alpha + 1),
.stageFlags = vk::ShaderStageFlagBits::eFragment,
.pImmutableSamplers = samplers.data(),
vk::DescriptorSetLayoutBinding layout_binding{
.binding = 0,
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
.descriptorCount = 1,
.stageFlags = vk::ShaderStageFlagBits::eFragment,
};
vk::DescriptorSetLayoutCreateInfo layout_info;
layout_info.setBindings(layout_binding);
descriptor_set_layout = vk::raii::DescriptorSetLayout(device, layout_info);
std::array pool_size{
vk::DescriptorPoolSize{
.type = vk::DescriptorType::eCombinedImageSampler,
.descriptorCount = (uint32_t)view_count,
},
};
target.descriptor_set_layout = device.createDescriptorSetLayout(vk::DescriptorSetLayoutCreateInfo{
.bindingCount = layout_binding.size(),
.pBindings = layout_binding.data(),
});
target.ds = device.allocateDescriptorSets(vk::DescriptorSetAllocateInfo{
.descriptorPool = *ds_pool,
.descriptorSetCount = 1,
.pSetLayouts = &*target.descriptor_set_layout,
})[0]
.release();
// pipeline layout
vk::PushConstantRange pc_range{
.stageFlags = vk::ShaderStageFlagBits::eVertex,
.size = sizeof(vert_pc),
vk::DescriptorPoolCreateInfo pool_info{
.maxSets = view_count,
.poolSizeCount = pool_size.size(),
.pPoolSizes = pool_size.data(),
};
vk::PipelineLayoutCreateInfo pipeline_layout_info{
.setLayoutCount = 1,
.pSetLayouts = &*target.descriptor_set_layout,
.pushConstantRangeCount = 1,
.pPushConstantRanges = &pc_range,
};
descriptor_pool = vk::raii::DescriptorPool(device, pool_info);
target.layout = vk::raii::PipelineLayout(device, pipeline_layout_info);
const auto & vk_device_extensions = application::get_vk_device_extensions();
bool fragment_shading_rate = false;
if (utils::contains(vk_device_extensions, VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME) and
utils::contains(vk_device_extensions, VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME))
// Create image views and descriptor sets
for (uint32_t view = 0; view < view_count; ++view)
{
const auto & [prop, rate_prop] = physical_device.getProperties2<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceFragmentShadingRatePropertiesKHR>();
const auto & [feat, fragment_feat] = physical_device.getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceFragmentShadingRateFeaturesKHR>();
fragment_shading_rate = rate_prop.fragmentShadingRateNonTrivialCombinerOps and
fragment_feat.primitiveFragmentShadingRate and
fragment_feat.attachmentFragmentShadingRate;
vk::ImageViewCreateInfo iv_info{
.image = input_image,
.viewType = vk::ImageViewType::e2D,
.format = vk::Format::eA8B8G8R8SrgbPack32,
.components = {
.r = vk::ComponentSwizzle::eIdentity,
.g = vk::ComponentSwizzle::eIdentity,
.b = vk::ComponentSwizzle::eIdentity,
.a = vk::ComponentSwizzle::eIdentity,
},
.subresourceRange = {
.aspectMask = vk::ImageAspectFlagBits::eColor,
.baseMipLevel = 0,
.levelCount = 1,
.baseArrayLayer = view,
.layerCount = 1,
},
};
vk::ImageView input_image_view = *input_image_views.emplace_back(device, iv_info);
vk::DescriptorSetAllocateInfo ds_info{
.descriptorPool = *descriptor_pool,
.descriptorSetCount = 1,
.pSetLayouts = &*descriptor_set_layout,
};
auto descriptor_set = descriptor_sets.emplace_back(device.allocateDescriptorSets(ds_info)[0].release());
vk::DescriptorImageInfo image_info{
.sampler = *sampler,
.imageView = input_image_view,
.imageLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
};
device.updateDescriptorSets(
vk::WriteDescriptorSet{
.dstSet = descriptor_set,
.dstBinding = 0,
.dstArrayElement = 0,
.descriptorCount = 1,
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
.pImageInfo = &image_info,
},
{});
}
// Create renderpass
vk::AttachmentReference color_ref{
.attachment = 0,
.layout = vk::ImageLayout::eColorAttachmentOptimal,
};
vk::AttachmentDescription attachment{
.format = format,
.samples = vk::SampleCountFlagBits::e1,
.loadOp = vk::AttachmentLoadOp::eDontCare,
.storeOp = vk::AttachmentStoreOp::eStore,
.initialLayout = vk::ImageLayout::eColorAttachmentOptimal,
.finalLayout = vk::ImageLayout::eColorAttachmentOptimal,
};
vk::SubpassDescription subpass{
.pipelineBindPoint = vk::PipelineBindPoint::eGraphics,
};
subpass.setColorAttachments(color_ref);
vk::StructureChain renderpass_info{
vk::RenderPassCreateInfo{
.attachmentCount = 1,
.pAttachments = &attachment,
.subpassCount = 1,
.pSubpasses = &subpass,
},
};
renderpass = vk::raii::RenderPass(device, renderpass_info.get());
// Vertex shader
vk::raii::ShaderModule vertex_shader = load_shader(device, fragment_shading_rate ? "reprojection_vsr.vert" : "reprojection.vert");
vk::raii::ShaderModule vertex_shader = load_shader(device, "reprojection.vert");
// Fragment shader
auto specialization = make_specialization_constants(
int32_t(alpha),
VkBool32(need_srgb_conversion(guess_model())));
vk::raii::ShaderModule fragment_shader = load_shader(device, "reprojection.frag");
std::string fragment_shader_name = "reprojection.frag";
vk::pipeline_builder pipeline_info_builder{
vk::SpecializationInfo fragment_specialization_info;
SgsrSpecializationConstants fragment_specialization_constants;
std::vector<vk::SpecializationMapEntry> fragment_specialization_constants_desc;
const configuration::sgsr_settings sgsr = application::get_config().sgsr;
if (sgsr.enabled)
{
fragment_shader_name = "reprojection_sgsr.frag";
fragment_specialization_constants = {
.use_edge_direction = sgsr.use_edge_direction,
.edge_threshold = float(sgsr.edge_threshold / 255.0),
.edge_sharpness = sgsr.edge_sharpness,
};
fragment_specialization_constants_desc = {
vk::SpecializationMapEntry{
.constantID = 0,
.offset = offsetof(SgsrSpecializationConstants, use_edge_direction),
.size = sizeof(fragment_specialization_constants.use_edge_direction),
},
vk::SpecializationMapEntry{
.constantID = 1,
.offset = offsetof(SgsrSpecializationConstants, edge_threshold),
.size = sizeof(fragment_specialization_constants.edge_threshold),
},
vk::SpecializationMapEntry{
.constantID = 2,
.offset = offsetof(SgsrSpecializationConstants, edge_sharpness),
.size = sizeof(fragment_specialization_constants.edge_sharpness),
},
};
fragment_specialization_info.setMapEntries(fragment_specialization_constants_desc);
fragment_specialization_info.setDataSize(sizeof(fragment_specialization_constants));
fragment_specialization_info.setPData(&fragment_specialization_constants);
}
vk::raii::ShaderModule fragment_shader = load_shader(device, fragment_shader_name);
// Create graphics pipeline
vk::PipelineLayoutCreateInfo pipeline_layout_info;
pipeline_layout_info.setSetLayouts(*descriptor_set_layout);
layout = vk::raii::PipelineLayout(device, pipeline_layout_info);
vk::pipeline_builder pipeline_info{
.flags = {},
.Stages = {
{
@@ -151,7 +282,7 @@ stream_defoveator::pipeline_t & stream_defoveator::ensure_pipeline(size_t view,
.stage = vk::ShaderStageFlagBits::eFragment,
.module = *fragment_shader,
.pName = "main",
.pSpecializationInfo = specialization,
.pSpecializationInfo = &fragment_specialization_info,
},
},
.VertexBindingDescriptions = {
@@ -171,15 +302,25 @@ stream_defoveator::pipeline_t & stream_defoveator::ensure_pipeline(size_t view,
{
.location = 1,
.binding = 0,
.format = vk::Format::eR32G32Uint,
.format = vk::Format::eR32G32Sfloat,
.offset = offsetof(vertex, uv),
},
},
.InputAssemblyState = {{
.topology = vk::PrimitiveTopology::eTriangleStrip,
}},
.Viewports = {{}},
.Scissors = {{}},
.Viewports = {{
.x = 0,
.y = 0,
.width = (float)output_extent.width,
.height = (float)output_extent.height,
.minDepth = 0,
.maxDepth = 1,
}},
.Scissors = {{
.offset = {.x = 0, .y = 0},
.extent = output_extent,
}},
.RasterizationState = {{
.polygonMode = vk::PolygonMode::eFill,
.lineWidth = 1,
@@ -191,109 +332,12 @@ stream_defoveator::pipeline_t & stream_defoveator::ensure_pipeline(size_t view,
.ColorBlendAttachments = {{
.colorWriteMask = vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA,
}},
.DynamicStates = {vk::DynamicState::eViewport, vk::DynamicState::eScissor},
.layout = *target.layout,
.layout = *layout,
.renderPass = *renderpass,
.subpass = 0,
};
vk::GraphicsPipelineCreateInfo pipeline_info(pipeline_info_builder);
// Variable fragment shading
std::array combiner{
vk::FragmentShadingRateCombinerOpKHR::eMax,
vk::FragmentShadingRateCombinerOpKHR::eMax,
};
vk::PipelineFragmentShadingRateStateCreateInfoKHR shading{
.fragmentSize = vk::Extent2D{1, 1},
.combinerOps = combiner,
};
if (fragment_shading_rate)
{
pipeline_info.pNext = &shading;
spdlog::info("Available fragment shading rates:");
for (const auto rate: physical_device.getFragmentShadingRatesKHR())
{
if (rate.sampleCounts & vk::SampleCountFlagBits::e1)
{
spdlog::info("\tfragment size: {}x{}", rate.fragmentSize.width, rate.fragmentSize.height);
int flags = 0;
if (rate.fragmentSize.width == 4)
flags |= 8;
else if (rate.fragmentSize.width == 2)
flags |= 4;
if (rate.fragmentSize.height == 4)
flags |= 2;
else if (rate.fragmentSize.height == 2)
flags |= 1;
for (int y = std::bit_width(rate.fragmentSize.height) - 1; y < 3; ++y)
{
for (int x = std::bit_width(rate.fragmentSize.width) - 1; x < 3; ++x)
{
if (fragment_sizes[x][y] == 0)
fragment_sizes[x][y] = flags << 28;
}
}
}
}
}
target.pipeline = device.createGraphicsPipeline(application::get_pipeline_cache(), pipeline_info);
return target;
}
stream_defoveator::stream_defoveator(
vk::raii::Device & device,
vk::raii::PhysicalDevice & physical_device,
std::vector<vk::Image> output_images_,
vk::Extent2D output_extent,
vk::Format format) :
device(device),
physical_device(physical_device),
output_images(std::move(output_images_)),
output_extent(output_extent)
{
// Create renderpass
vk::AttachmentDescription attachment{
.format = format,
.samples = vk::SampleCountFlagBits::e1,
.loadOp = vk::AttachmentLoadOp::eDontCare,
.storeOp = vk::AttachmentStoreOp::eStore,
.finalLayout = vk::ImageLayout::eColorAttachmentOptimal,
};
vk::AttachmentReference color_ref{
.attachment = 0,
.layout = vk::ImageLayout::eColorAttachmentOptimal,
};
vk::SubpassDescription subpass{
.pipelineBindPoint = vk::PipelineBindPoint::eGraphics,
.colorAttachmentCount = 1,
.pColorAttachments = &color_ref,
};
vk::StructureChain renderpass_info{
vk::RenderPassCreateInfo{
.attachmentCount = 1,
.pAttachments = &attachment,
.subpassCount = 1,
.pSubpasses = &subpass,
},
};
renderpass = vk::raii::RenderPass(device, renderpass_info.get());
vk::DescriptorPoolSize pool_size{
.type = vk::DescriptorType::eCombinedImageSampler,
.descriptorCount = view_count * 4,
};
ds_pool = device.createDescriptorPool(vk::DescriptorPoolCreateInfo{
.maxSets = view_count * 2,
.poolSizeCount = 1,
.pPoolSizes = &pool_size,
});
pipeline = vk::raii::Pipeline(device, application::get_pipeline_cache(), pipeline_info);
// Create image views and framebuffers
output_image_views.reserve(output_images.size() * view_count);
@@ -346,25 +390,9 @@ static size_t required_vertices(const wivrn::to_headset::foveation_parameter & p
return (2 * (p.x.size() + 1) + 1) * p.y.size();
}
uint32_t stream_defoveator::shading_rate(int pixels_x, int pixels_y)
{
int x = 0;
if (pixels_x >= 2)
x = 1;
if (pixels_x >= 4)
x = 2;
int y = 0;
if (pixels_y >= 2)
y = 1;
if (pixels_y >= 4)
y = 2;
return fragment_sizes[x][y];
}
void stream_defoveator::defoveate(vk::raii::CommandBuffer & command_buffer,
const std::array<wivrn::to_headset::foveation_parameter, 2> & foveation,
std::span<wivrn::blitter::output> inputs,
int destination)
void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer,
const std::array<wivrn::to_headset::foveation_parameter, 2> & foveation,
int destination)
{
if (destination < 0 || destination >= (int)output_images.size())
throw std::runtime_error("Invalid destination image index");
@@ -373,7 +401,6 @@ void stream_defoveator::defoveate(vk::raii::CommandBuffer & command_buffer,
for (size_t view = 0; view < view_count; ++view)
{
const auto out_size = defoveated_size(foveation[view]);
auto vertices = get_vertices(view);
const auto & [px, py] = foveation[view];
assert(px.size() % 2 == 1);
@@ -381,64 +408,67 @@ void stream_defoveator::defoveate(vk::raii::CommandBuffer & command_buffer,
const int n_ratio_y = (py.size() - 1) / 2;
const int n_ratio_x = (px.size() - 1) / 2;
command_buffer.setScissor(
0,
vk::Rect2D{
.extent = {.width = uint32_t(out_size.width), .height = uint32_t(out_size.height)},
});
command_buffer.setViewport(
0,
vk::Viewport{
.x = 0,
.y = 0,
.width = float(out_size.width),
.height = float(out_size.height),
.minDepth = 0,
.maxDepth = 1,
});
glm::uvec2 in(0);
glm::vec2 out(-0.5 * out_size.width, -0.5 * out_size.height); // pixel coordinates
glm::vec2 out_pixel_size(2. / out_size.width,
2. / out_size.height);
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))
{
// number of output pixels per source pixels
const int ratio_y = std::abs(n_ratio_y - int(iy)) + 1;
in.x = 0;
out.x = -0.5 * out_size.width;
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;
glm::uvec2 rate = glm::uvec2(shading_rate(ratio_x, ratio_y), 0);
*vertices++ = {
.position = out * out_pixel_size,
.uv = in | rate,
.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,
.uv = (in + glm::uvec2(0, n_out_y)) | rate,
.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,
.uv = in,
.position = out * out_pixel_size - glm::vec2(1),
.uv = in * in_pixel_size,
};
in.y += n_out_y;
out.y += n_out_y * ratio_y;
*vertices++ = {
.position = out * out_pixel_size,
.uv = in,
.position = out * out_pixel_size - glm::vec2(1),
.uv = in * in_pixel_size,
};
*vertices++ = {
.position = out * out_pixel_size,
.uv = in,
.position = out * out_pixel_size - glm::vec2(1),
.uv = in * in_pixel_size,
};
}
}
command_buffer.pipelineBarrier(
vk::PipelineStageFlagBits::eTopOfPipe,
vk::PipelineStageFlagBits::eColorAttachmentOutput,
{},
{},
{},
vk::ImageMemoryBarrier{
.srcAccessMask = {},
.dstAccessMask = vk::AccessFlagBits::eColorAttachmentWrite,
.oldLayout = vk::ImageLayout::eUndefined,
.newLayout = vk::ImageLayout::eColorAttachmentOptimal,
.image = output_images[destination],
.subresourceRange = {
.aspectMask = vk::ImageAspectFlagBits::eColor,
.levelCount = 1,
.layerCount = view_count,
},
});
for (size_t view = 0; view < view_count; ++view)
{
vk::RenderPassBeginInfo begin_info{
@@ -450,49 +480,9 @@ void stream_defoveator::defoveate(vk::raii::CommandBuffer & command_buffer,
},
};
const auto & input = inputs[view];
auto & pipeline = ensure_pipeline(view, input.sampler_rgb, input.sampler_a);
std::array image_info{
vk::DescriptorImageInfo{
.sampler = input.sampler_rgb,
.imageView = input.rgb,
.imageLayout = input.layout_rgb,
},
vk::DescriptorImageInfo{
.sampler = input.sampler_a,
.imageView = input.a,
.imageLayout = input.layout_a,
},
};
std::array descriptor_writes{
vk::WriteDescriptorSet{
.dstSet = pipeline.ds,
.dstBinding = 0,
.descriptorCount = input.sampler_a ? 2u : 1u,
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
.pImageInfo = image_info.data(),
},
};
vert_pc pc{
.rgb_rect = glm::ivec4(input.rect_rgb.offset.x,
input.rect_rgb.offset.y,
input.rect_rgb.extent.width,
input.rect_rgb.extent.height),
.a_rect = glm::ivec4(input.rect_a.offset.x,
input.rect_a.offset.y,
input.rect_a.extent.width,
input.rect_a.extent.height),
};
device.updateDescriptorSets(descriptor_writes, {});
command_buffer.beginRenderPass(begin_info, vk::SubpassContents::eInline);
command_buffer.bindPipeline(vk::PipelineBindPoint::eGraphics, *pipeline.pipeline);
command_buffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, *pipeline.layout, 0, pipeline.ds, {});
command_buffer.pushConstants<vert_pc>(*pipeline.layout, vk::ShaderStageFlagBits::eVertex, 0, pc);
command_buffer.bindPipeline(vk::PipelineBindPoint::eGraphics, *pipeline);
command_buffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, *layout, 0, descriptor_sets[view], {});
command_buffer.bindVertexBuffers(0, vk::Buffer(buffer), vertices_size * view);
command_buffer.draw(required_vertices(foveation[view]), 1, 0, 0);
command_buffer.endRenderPass();
@@ -512,7 +502,7 @@ static uint16_t count_pixels(const std::vector<uint16_t> & param)
return res;
}
XrExtent2Di stream_defoveator::defoveated_size(const wivrn::to_headset::foveation_parameter & view) const
XrExtent2Di stream_reprojection::defoveated_size(const wivrn::to_headset::foveation_parameter & view) const
{
return {
count_pixels(view.x),
@@ -19,42 +19,34 @@
#pragma once
#include "blitter.h"
#include "vk/allocation.h"
#include "wivrn_packets.h"
#include <vulkan/vulkan_raii.hpp>
#include <openxr/openxr.h>
class stream_defoveator
class stream_reprojection
{
struct vertex;
static const uint32_t view_count = 2;
const uint32_t view_count;
// Vertex buffer
buffer_allocation buffer;
size_t vertices_size = 0;
vk::raii::Device & device;
vk::raii::PhysicalDevice & physical_device;
// Graphic pipeline
vk::raii::DescriptorSetLayout descriptor_set_layout = nullptr;
vk::raii::DescriptorPool descriptor_pool = nullptr;
vk::raii::PipelineLayout layout = nullptr;
vk::raii::RenderPass renderpass = nullptr;
vk::raii::DescriptorPool ds_pool = nullptr;
struct pipeline_t
{
vk::raii::DescriptorSetLayout descriptor_set_layout = nullptr;
vk::DescriptorSet ds;
vk::raii::PipelineLayout layout = nullptr;
vk::raii::Pipeline pipeline = nullptr;
};
pipeline_t pipeline_rgb[view_count];
pipeline_t pipeline_a[view_count];
vk::raii::Pipeline pipeline = nullptr;
// Allowed sizes for variable shading rate
// indices are for x, y
// 0 is 1 pixel
// 1 is 2 or 3 pixels
// 2 is 4 pixels or more
uint32_t fragment_sizes[3][3] = {};
// Source image
vk::raii::Sampler sampler = nullptr;
vk::Image input_image;
std::vector<vk::raii::ImageView> input_image_views;
std::vector<vk::DescriptorSet> descriptor_sets;
vk::Extent2D input_extent;
// Destination images
std::vector<vk::Image> output_images;
@@ -65,23 +57,22 @@ class stream_defoveator
void ensure_vertices(size_t num_vertices);
vertex * get_vertices(size_t view);
uint32_t shading_rate(int pixels_x, int pixels_y);
pipeline_t & ensure_pipeline(size_t view, vk::Sampler rgb, vk::Sampler a);
public:
stream_defoveator(
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<vk::Image> output_images,
vk::Extent2D output_extent,
vk::Format format);
stream_defoveator(const stream_defoveator &) = delete;
stream_reprojection(const stream_reprojection &) = delete;
void defoveate(
void reproject(
vk::raii::CommandBuffer & command_buffer,
const std::array<wivrn::to_headset::foveation_parameter, 2> & foveation,
std::span<wivrn::blitter::output> inputs,
int destination);
XrExtent2Di defoveated_size(const wivrn::to_headset::foveation_parameter &) const;
+63 -81
View File
@@ -21,10 +21,7 @@
#include "stream.h"
#include "utils/overloaded.h"
#include "wivrn_packets.h"
#include "xr/body_tracker.h"
#include "xr/face_tracker.h"
#include "xr/fb_body_tracker.h"
#include "xr/to_string.h"
#include <magic_enum.hpp>
#include <ranges>
#include <spdlog/spdlog.h>
@@ -380,6 +377,7 @@ void scenes::stream::tracking()
std::vector<from_headset::tracking> tracking;
std::vector<from_headset::tracking> tracking_pool; // pre-allocated objects
std::vector<from_headset::hand_tracking> hands;
std::array<bool, 2> should_skip_simple_controllers{};
std::vector<from_headset::body_tracking> body;
std::vector<XrView> views;
@@ -387,14 +385,31 @@ void scenes::stream::tracking()
std::vector<serialization_packet> packets;
const bool hand_tracking = config.check_feature(feature::hand_tracking);
std::optional<xr::hand_tracker> left_hand;
std::optional<xr::hand_tracker> right_hand;
const bool face_tracking = config.check_feature(feature::face_tracking);
xr::face_tracker face_tracker;
auto & face_tracker = application::get_face_tracker();
if (face_tracking)
{
// 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.
if (auto * face_pico = std::get_if<xr::pico_face_tracker>(&face_tracker))
face_pico->start();
}
const bool body_tracking = config.check_feature(feature::body_tracking);
xr::body_tracker body_tracker;
auto & body_tracker = application::get_body_tracker();
if (body_tracking)
{
if (auto * body_fb = std::get_if<xr::fb_body_tracker>(&body_tracker))
{
// TODO maybe handle reconnection better, if the settings are changed since
// last connection to running server, the tracker count will mismatch and
// stuff might break
body_fb->stop();
body_fb->start(config.fb_lower_body, config.fb_hip);
}
}
locate_spaces_functor locate_spaces{instance, world_space};
@@ -418,50 +433,11 @@ void scenes::stream::tracking()
timer t(instance);
int samples = 0;
auto control = *tracking_control.lock();
bool interaction_profile_changed = this->interaction_profile_changed.exchange(false);
if (control.enabled[size_t(tid::left_hand)])
to_headset::tracking_control control;
{
if (not left_hand and system.hand_tracking_supported())
left_hand = session.create_hand_tracker(XR_HAND_LEFT_EXT);
std::lock_guard lock(tracking_control_mutex);
control = tracking_control;
}
else
left_hand.reset();
if (control.enabled[size_t(tid::right_hand)])
{
if (not right_hand and system.hand_tracking_supported())
right_hand = session.create_hand_tracker(XR_HAND_RIGHT_EXT);
}
else
right_hand.reset();
if (face_tracking and control.enabled[size_t(tid::face)])
{
if (std::holds_alternative<std::monostate>(face_tracker))
face_tracker = xr::make_face_tracker(instance, system, session);
}
else
face_tracker.emplace<std::monostate>();
if (body_tracking and control.enabled[size_t(tid::generic_tracker)])
{
if (std::holds_alternative<std::monostate>(body_tracker))
body_tracker = xr::make_body_tracker(
instance,
system,
session,
application::get_generic_trackers(),
config.fb_lower_body,
config.fb_hip);
}
else
body_tracker.emplace<std::monostate>();
if (interaction_profile_changed)
if (auto htc = std::get_if<xr::htc_body_tracker>(&body_tracker))
htc->update_active();
XrDuration prediction = std::clamp<XrDuration>(control.max_offset.count(), 0, 80'000'000);
auto period = std::max<XrDuration>(display_time_period.load(), 1'000'000);
@@ -493,9 +469,9 @@ void scenes::stream::tracking()
(Δt == 0 or Δt >= prediction - 2 * period))
{
last_hand_sample = t0;
if (left_hand)
if (control.enabled[size_t(tid::left_hand)])
{
auto joints = locate_hands(*left_hand, world_space, t0 + Δt);
auto joints = locate_hands(application::get_left_hand(), world_space, t0 + Δt);
hands.emplace_back(
t0,
t0 + Δt,
@@ -503,9 +479,9 @@ void scenes::stream::tracking()
joints);
}
if (right_hand)
if (control.enabled[size_t(tid::right_hand)])
{
auto joints = locate_hands(*right_hand, world_space, t0 + Δt);
auto joints = locate_hands(application::get_right_hand(), world_space, t0 + Δt);
hands.emplace_back(
t0,
t0 + Δt,
@@ -522,33 +498,37 @@ void scenes::stream::tracking()
}
locate_spaces.resolve(session, t0 + Δt, packet.device_poses);
std::visit(utils::overloaded{
[](std::monostate &) {},
[&](auto & b) {
if (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)])
if (body_tracking)
std::visit(utils::overloaded{
[](std::monostate &) {},
[&](auto & b) {
if (t0 >= last_body_sample + period and
(Δt == 0 or Δt >= prediction - 2 * period))
{
body.push_back(from_headset::body_tracking{
.production_timestamp = t0,
.timestamp = t0 + Δt,
.poses = b.locate_spaces(t0 + Δt, world_space),
});
last_body_sample = t0;
if (control.enabled[size_t(tid::generic_tracker)])
{
body.push_back(from_headset::body_tracking{
.production_timestamp = t0,
.timestamp = t0 + Δt,
.poses = b.locate_spaces(t0 + Δt, world_space),
});
}
}
}
},
},
body_tracker);
},
},
body_tracker);
std::visit(utils::overloaded{
[](std::monostate &) {},
[&](auto & ft) {
ft.get_weights(t0 + Δt, packet.face.emplace<typename std::remove_reference_t<decltype(ft)>::packet_type>());
},
},
face_tracker);
if (face_tracking && control.enabled[size_t(tid::face)])
{
std::visit(utils::overloaded{
[](std::monostate &) {},
[&](auto & ft) {
ft.get_weights(t0 + Δt, packet.face.emplace<typename std::remove_reference_t<decltype(ft)>::packet_type>());
},
},
face_tracker);
}
}
catch (const std::system_error & e)
{
@@ -649,17 +629,20 @@ void scenes::stream::tracking()
exit();
}
}
if (auto * face_pico = std::get_if<xr::pico_face_tracker>(&face_tracker))
face_pico->stop();
}
void scenes::stream::operator()(to_headset::tracking_control && packet)
{
auto locked = tracking_control.lock();
std::lock_guard lock(tracking_control_mutex);
auto m = size_t(to_headset::tracking_control::id::microphone);
if (audio_handle)
audio_handle->set_mic_state(packet.enabled[m]);
*locked = packet;
locked->min_offset = std::min(locked->min_offset, locked->max_offset);
tracking_control = packet;
tracking_control.min_offset = std::min(tracking_control.min_offset, tracking_control.max_offset);
}
static device_id derived_from(device_id target)
@@ -680,7 +663,6 @@ static device_id derived_from(device_id target)
void scenes::stream::on_interaction_profile_changed(const XrEventDataInteractionProfileChanged &)
{
interaction_profile_changed = true;
std::array path = {
"/user/hand/left",
"/user/hand/right",
+48 -3
View File
@@ -1,4 +1,49 @@
/*
* WiVRn VR streaming
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
*
* 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 <https://www.gnu.org/licenses/>.
*/
#version 450
#extension GL_ARB_shading_language_include : require
#define VSR 0
#include "reprojection.glsl.inc"
#ifdef VERT_SHADER
layout (location = 0) in vec2 vPosition;
layout (location = 1) in vec2 vUV;
layout(location = 0) out vec2 outUV;
void main()
{
gl_Position = vec4(vPosition, 0.0, 1.0);
outUV = vUV;
}
#endif
#ifdef FRAG_SHADER
layout(set = 0, binding = 0) uniform sampler2D texSampler;
layout(location = 0) in vec2 inUV;
layout(location = 0) out vec4 outColor;
void main()
{
outColor = texture(texSampler, inUV).rgba;
}
#endif
-92
View File
@@ -1,92 +0,0 @@
/*
* WiVRn VR streaming
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
*
* 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 <https://www.gnu.org/licenses/>.
*/
#ifdef VERT_SHADER
#if VSR
#extension GL_EXT_fragment_shading_rate: enable
#endif
layout (location = 0) in vec2 vPosition;
layout (location = 1) in uvec2 vUV;
layout(location = 0) out vec4 outUV;
layout(push_constant) uniform pc
{
ivec4 rgb_rect;
ivec4 a_rect;
};
void main()
{
gl_Position = vec4(vPosition, 0.0, 1.0);
#if VSR
gl_PrimitiveShadingRateEXT = int(bitfieldExtract(vUV.x, 28, 4));
vec2 uv = bitfieldInsert(vUV, uvec2(0), 28, 4);
#else
vec2 uv = vUV;
#endif
outUV.xy = (uv + rgb_rect.xy) / rgb_rect.zw;
outUV.zw = (uv + a_rect.xy) / a_rect.zw;
}
#endif
#ifdef FRAG_SHADER
layout(constant_id = 0) const int alpha = 1;
layout(constant_id = 1) const bool do_srgb = false;
layout(set = 0, binding = 0) uniform sampler2D rgb[alpha + 1];
layout(location = 0) in vec4 inUV;
layout(location = 0) out vec4 outColor;
float sRGB_to_linear(float x)
{
if (x <= 0.04045)
return x / 12.92;
return pow((x + 0.055) / 1.055, 2.4);
}
vec4 sRGB_to_linear_rgba(vec4 x)
{
return vec4(
sRGB_to_linear(x.r),
sRGB_to_linear(x.g),
sRGB_to_linear(x.b),
x.a);
}
void main()
{
if (alpha == 1)
outColor = vec4(texture(rgb[0], inUV.xy).rgb, texture(rgb[1], inUV.zw).r);
else
outColor = texture(rgb[0], inUV.xy).rgba;
if (do_srgb)
{
outColor = sRGB_to_linear_rgba(outColor);
}
}
#endif
+179
View File
@@ -0,0 +1,179 @@
/*
* Snapdragon™ Game Super Resolution
* Copyright (c) 2023, Qualcomm Innovation Center, Inc. All rights reserved.
*
* https://github.com/SnapdragonStudios/snapdragon-gsr
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#version 450
precision mediump float;
precision highp int;
#define OperationMode 1
layout (constant_id = 0) const bool use_edge_direction = true;
layout (constant_id = 1) const float edge_threshold = 4.0/255.0;
layout (constant_id = 2) const float edge_sharpness = 2.0;
layout(set = 0, binding = 0) uniform mediump sampler2D texSampler;
layout(location = 0) in highp vec2 inUV;
layout(location = 0) out vec4 outColor;
float fastLanczos2(float x)
{
float wA = x-4.0;
float wB = x*wA-wA;
wA *= wA;
return wB*wA;
}
vec2 weightY(float dx, float dy, float c, vec3 data)
{
float std = data.x;
vec2 dir = data.yz;
float edgeDis = ((dx*dir.y)+(dy*dir.x));
float x = (((dx*dx)+(dy*dy))+((edgeDis*edgeDis)*((clamp(((c*c)*std),0.0,1.0)*0.7)+-1.0)));
float w = fastLanczos2(x);
return vec2(w, w * c);
}
vec2 weightYned(float dx, float dy, float c, float std)
{
float x = ((dx*dx)+(dy* dy))* 0.55 + clamp(abs(c)*std, 0.0, 1.0);
float w = fastLanczos2(x);
return vec2(w, w * c);
}
vec2 edgeDirection(vec4 left, vec4 right)
{
vec2 dir;
float RxLz = (right.x + (-left.z));
float RwLy = (right.w + (-left.y));
vec2 delta;
delta.x = (RxLz + RwLy);
delta.y = (RxLz + (-RwLy));
float lengthInv = inversesqrt((delta.x * delta.x+ 3.075740e-05) + (delta.y * delta.y));
dir.x = (delta.x * lengthInv);
dir.y = (delta.y * lengthInv);
return dir;
}
void main()
{
vec4 color = textureLod(texSampler,inUV,0.0).xyzw;
float alpha = color.a;
if (OperationMode == 1)
color.a = 0.0;
if (OperationMode != 4)
{
vec2 dim = textureSize(texSampler, 0);
vec4 viewportInfo = vec4(1/dim.x, 1/dim.y, dim.x, dim.y);
highp vec2 imgCoord = ((inUV.xy*viewportInfo.zw)+vec2(-0.5,0.5));
highp vec2 imgCoordPixel = floor(imgCoord);
highp vec2 coord = (imgCoordPixel*viewportInfo.xy);
vec2 pl = (imgCoord+(-imgCoordPixel));
vec4 left = textureGather(texSampler,coord, OperationMode);
float edgeVote = abs(left.z - left.y) + abs(color[OperationMode] - left.y) + abs(color[OperationMode] - left.z) ;
if(edgeVote > edge_threshold)
{
coord.x += viewportInfo.x;
vec4 right = textureGather(texSampler,coord + vec2(viewportInfo.x, 0.0), OperationMode);
vec4 upDown;
upDown.xy = textureGather(texSampler,coord + vec2(0.0, -viewportInfo.y),OperationMode).wz;
upDown.zw = textureGather(texSampler,coord + vec2(0.0, viewportInfo.y), OperationMode).yx;
float mean = (left.y+left.z+right.x+right.w)*0.25;
left = left - vec4(mean);
right = right - vec4(mean);
upDown = upDown - vec4(mean);
color.w =color[OperationMode] - mean;
float sum = (((((abs(left.x)+abs(left.y))+abs(left.z))+abs(left.w))+(((abs(right.x)+abs(right.y))+abs(right.z))+abs(right.w)))+(((abs(upDown.x)+abs(upDown.y))+abs(upDown.z))+abs(upDown.w)));
float sumMean = 1.014185e+01/sum;
float std = (sumMean*sumMean);
vec2 aWY;
if (use_edge_direction) {
vec3 data = vec3(std, edgeDirection(left, right));
aWY = weightY(pl.x, pl.y+1.0, upDown.x,data);
aWY += weightY(pl.x-1.0, pl.y+1.0, upDown.y,data);
aWY += weightY(pl.x-1.0, pl.y-2.0, upDown.z,data);
aWY += weightY(pl.x, pl.y-2.0, upDown.w,data);
aWY += weightY(pl.x+1.0, pl.y-1.0, left.x,data);
aWY += weightY(pl.x, pl.y-1.0, left.y,data);
aWY += weightY(pl.x, pl.y, left.z,data);
aWY += weightY(pl.x+1.0, pl.y, left.w,data);
aWY += weightY(pl.x-1.0, pl.y-1.0, right.x,data);
aWY += weightY(pl.x-2.0, pl.y-1.0, right.y,data);
aWY += weightY(pl.x-2.0, pl.y, right.z,data);
aWY += weightY(pl.x-1.0, pl.y, right.w,data);
} else {
aWY = weightYned(pl.x, pl.y+1.0, upDown.x,std);
aWY += weightYned(pl.x-1.0, pl.y+1.0, upDown.y,std);
aWY += weightYned(pl.x-1.0, pl.y-2.0, upDown.z,std);
aWY += weightYned(pl.x, pl.y-2.0, upDown.w,std);
aWY += weightYned(pl.x+1.0, pl.y-1.0, left.x,std);
aWY += weightYned(pl.x, pl.y-1.0, left.y,std);
aWY += weightYned(pl.x, pl.y, left.z,std);
aWY += weightYned(pl.x+1.0, pl.y, left.w,std);
aWY += weightYned(pl.x-1.0, pl.y-1.0, right.x,std);
aWY += weightYned(pl.x-2.0, pl.y-1.0, right.y,std);
aWY += weightYned(pl.x-2.0, pl.y, right.z,std);
aWY += weightYned(pl.x-1.0, pl.y, right.w,std);
}
float finalY = aWY.y/aWY.x;
float maxY = max(max(left.y,left.z),max(right.x,right.w));
float minY = min(min(left.y,left.z),min(right.x,right.w));
float deltaY = clamp(edge_sharpness*finalY, minY, maxY) -color.w;
//smooth high contrast input
deltaY = clamp(deltaY, -23.0 / 255.0, 23.0 / 255.0);
color.x = clamp((color.x+deltaY),0.0,1.0);
color.y = clamp((color.y+deltaY),0.0,1.0);
color.z = clamp((color.z+deltaY),0.0,1.0);
}
}
outColor = vec4(color.rgb, alpha);
}
-5
View File
@@ -1,5 +0,0 @@
#version 450
#extension GL_ARB_shading_language_include : require
#define VSR 1
#include "reprojection.glsl.inc"
+27 -3
View File
@@ -45,16 +45,40 @@ void main()
#ifdef FRAG_SHADER
layout(binding = 0) uniform sampler2D texSampler;
layout(constant_id = 0) const bool is_alpha = false;
layout(constant_id = 0) const bool do_srgb = true;
layout(constant_id = 1) const bool is_alpha = false;
layout(location = 0) in vec2 inUV;
layout(location = 0) out vec4 outColor;
float sRGB_to_linear(float x)
{
if (x <= 0.04045)
return x / 12.92;
return pow((x + 0.055) / 1.055, 2.4);
}
vec4 sRGB_to_linear_rgba(vec4 x)
{
return vec4(
sRGB_to_linear(x.r),
sRGB_to_linear(x.g),
sRGB_to_linear(x.b),
x.r);
}
void main()
{
outColor = texture(texSampler, inUV);
outColor.a = outColor.r;
if (do_srgb)
{
outColor = sRGB_to_linear_rgba(texture(texSampler, inUV));
}
else
{
outColor = texture(texSampler, inUV);
outColor.a = outColor.r;
}
if (!is_alpha)
{
outColor.a = 1;
+3 -11
View File
@@ -26,17 +26,9 @@ namespace utils
template <typename Rng, typename T>
bool contains(Rng && range, const T & value)
{
if constexpr (std::is_convertible_v<T, const char *> and
std::is_convertible_v<typename std::decay_t<Rng>::value_type, const char *>)
{
auto it = std::find_if(range.begin(), range.end(), [&](const char * i) { return strcmp(i, value) == 0; });
return it != range.end();
}
else
{
auto it = std::find(range.begin(), range.end(), value);
return it != range.end();
}
auto it = std::find(range.begin(), range.end(), value);
return it != range.end();
}
// Check if all values of range2 are in range1
+5 -49
View File
@@ -19,81 +19,37 @@
#pragma once
#include <spdlog/spdlog.h>
#include <type_traits>
#include <utility>
#include <variant>
#include <openxr/openxr.h>
namespace utils
{
template <typename T, auto Deleter = nullptr>
template <typename T, XrResult deleter(T)>
class handle
{
public:
// true if the deleter is provided when constructing the object
// typically if it's from an OpenXR extension
static constexpr bool runtime_deleter = Deleter == nullptr;
protected:
static const inline T null_value = 0;
T id = null_value;
[[no_unique_address]] std::conditional_t<runtime_deleter, XrResult (*)(T), std::monostate> deleter;
public:
template <typename = void>
requires(not runtime_deleter)
handle()
{}
template <typename = void>
requires(not runtime_deleter)
handle() {}
handle(T id) :
id(id)
{}
template <typename = void>
requires(runtime_deleter)
handle(XrResult (*deleter)(T)) :
deleter(deleter)
{
assert(deleter);
}
template <typename = void>
requires(runtime_deleter)
handle(T id, XrResult (*deleter)(T)) :
id(id), deleter(deleter)
{
assert(deleter);
}
id(id) {}
~handle()
{
if (id != null_value)
{
XrResult res = XR_SUCCESS;
if constexpr (runtime_deleter)
res = deleter(id);
else
res = Deleter(id);
if (not XR_SUCCEEDED(res))
spdlog::warn("Failed to destroy {}", typeid(T).name());
}
deleter(id);
}
handle(handle && other) noexcept :
id(other.id), deleter(other.deleter)
id(other.id)
{
other.id = null_value;
}
handle & operator=(handle && other) noexcept
{
if constexpr (runtime_deleter)
std::swap(deleter, other.deleter);
std::swap(id, other.id);
return *this;
}
-70
View File
@@ -1,70 +0,0 @@
/*
* WiVRn VR streaming
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2024 Patrick Nicolas <patricknicolas@laposte.net>
*
* 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 <https://www.gnu.org/licenses/>.
*/
#include "i18n.h"
#include "asset.h"
#include <map>
#include <string>
#include <vector>
extern std::map<std::string, std::vector<int>> glyph_set_per_language;
std::vector<boost::locale::gnu_gettext::messages_info> get_locales()
{
boost::locale::gnu_gettext::messages_info messages_info;
messages_info.paths.push_back("locale");
messages_info.encoding = "UTF-8";
messages_info.domains.push_back(boost::locale::gnu_gettext::messages_info::domain("wivrn"));
messages_info.callback = open_locale_file;
std::vector<boost::locale::gnu_gettext::messages_info> res;
messages_info.language = "en";
messages_info.country = "US";
res.push_back(messages_info);
for (const auto & [code, glyphs]: glyph_set_per_language)
{
auto pos = code.find("_");
messages_info.language = code.substr(0, pos);
if (pos == std::string::npos)
messages_info.country = "";
else
messages_info.country = code.substr(pos + 1);
res.push_back(messages_info);
}
return res;
}
std::vector<char> open_locale_file(const std::string & file_name, const std::string & encoding)
{
std::vector<char> buffer;
try
{
asset file(file_name);
buffer.resize(file.size());
memcpy(buffer.data(), file.data(), file.size());
}
catch (...)
{
}
return buffer;
}
-3
View File
@@ -23,6 +23,3 @@
#define _F(x) fmt::runtime(boost::locale::gettext(x))
#define _S(x) boost::locale::gettext(x).c_str()
#define _cS(c, x) boost::locale::pgettext(c, x).c_str()
std::vector<boost::locale::gnu_gettext::messages_info> get_locales();
std::vector<char> open_locale_file(const std::string & file_name, const std::string & encoding);
-45
View File
@@ -1,45 +0,0 @@
#include "renderdoc.h"
#include "renderdoc_app.h"
#include <dlfcn.h>
#include <iostream>
static RENDERDOC_API_1_0_0 * renderdoc_init()
{
RENDERDOC_API_1_0_0 * renderdoc_api = nullptr;
auto renderdoc_module = dlopen("librenderdoc.so", RTLD_NOW | RTLD_NOLOAD);
if (not renderdoc_module)
return nullptr;
auto * func = reinterpret_cast<pRENDERDOC_GetAPI>(dlsym(renderdoc_module, "RENDERDOC_GetAPI"));
if (!func)
{
std::cerr << "Failed to load RENDERDOC_GetAPI function." << std::endl;
return nullptr;
}
if (!func(eRENDERDOC_API_Version_1_0_0, reinterpret_cast<void **>(&renderdoc_api)))
{
std::cerr << "Failed to obtain RenderDoc 1.0.0 API." << std::endl;
return nullptr;
}
int major, minor, patch;
renderdoc_api->GetAPIVersion(&major, &minor, &patch);
return renderdoc_api;
}
static RENDERDOC_API_1_0_0 * get_renderdoc()
{
static RENDERDOC_API_1_0_0 * renderdoc_api = renderdoc_init();
return renderdoc_api;
}
void wivrn::renderdoc_begin(VkInstance inst)
{
if (auto renderdoc_api = get_renderdoc())
renderdoc_api->StartFrameCapture(RENDERDOC_DEVICEPOINTER_FROM_VKINSTANCE(inst), nullptr);
}
void wivrn::renderdoc_end(VkInstance inst)
{
if (auto renderdoc_api = get_renderdoc())
renderdoc_api->EndFrameCapture(RENDERDOC_DEVICEPOINTER_FROM_VKINSTANCE(inst), nullptr);
}
-6
View File
@@ -1,6 +0,0 @@
#include <vulkan/vulkan.h>
namespace wivrn
{
void renderdoc_begin(VkInstance);
void renderdoc_end(VkInstance);
} // namespace wivrn
+1 -2
View File
@@ -18,13 +18,12 @@
*/
#include "shader.h"
#include "wivrn_shaders.h"
vk::raii::ShaderModule load_shader(vk::raii::Device & device, const std::vector<uint32_t> & spirv)
{
vk::ShaderModuleCreateInfo create_info{
.codeSize = spirv.size() * sizeof(uint32_t),
.pCode = spirv.data(),
.pCode = data(spirv),
};
return vk::raii::ShaderModule{device, create_info};
+3
View File
@@ -19,9 +19,12 @@
#pragma once
#include <map>
#include <string>
#include <vector>
#include <vulkan/vulkan_raii.hpp>
extern const std::map<std::string, std::vector<uint32_t>> shaders;
vk::raii::ShaderModule load_shader(vk::raii::Device & device, const std::vector<uint32_t> & spirv);
vk::raii::ShaderModule load_shader(vk::raii::Device & device, const std::string & name);
-80
View File
@@ -1,80 +0,0 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
*
* 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 <https://www.gnu.org/licenses/>.
*/
#include "body_tracker.h"
#include "xr/htc_exts.h"
#include "xr/instance.h"
#include "xr/system.h"
xr::body_tracker_type xr::body_tracker_supported(xr::instance & instance, xr::system & system)
{
if (instance.has_extension(XR_FB_BODY_TRACKING_EXTENSION_NAME) and
instance.has_extension(XR_META_BODY_TRACKING_FULL_BODY_EXTENSION_NAME) and
instance.has_extension(XR_META_BODY_TRACKING_FIDELITY_EXTENSION_NAME))
{
auto fb_body_properties = system.fb_body_tracking_properties();
if (fb_body_properties.supportsBodyTracking)
return body_tracker_type::fb;
}
if (instance.has_extension(XR_HTC_PATH_ENUMERATION_EXTENSION_NAME) and
instance.has_extension(XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME))
return body_tracker_type::htc;
if (instance.has_extension(XR_BD_BODY_TRACKING_EXTENSION_NAME))
{
auto bd_body_properties = system.bd_body_tracking_properties();
if (bd_body_properties.supportsBodyTracking)
return body_tracker_type::pico;
}
return xr::body_tracker_type::none;
}
xr::body_tracker xr::make_body_tracker(xr::instance & instance, xr::system & system, xr::session & session, std::vector<std::pair<XrPath, xr::space>> & generic_trackers, bool full_body, bool hips)
{
if (instance.has_extension(XR_FB_BODY_TRACKING_EXTENSION_NAME) and
instance.has_extension(XR_META_BODY_TRACKING_FULL_BODY_EXTENSION_NAME) and
instance.has_extension(XR_META_BODY_TRACKING_FIDELITY_EXTENSION_NAME))
{
auto fb_body_properties = system.fb_body_tracking_properties();
if (fb_body_properties.supportsBodyTracking)
return xr::body_tracker(std::in_place_type_t<xr::fb_body_tracker>(),
instance,
session,
full_body,
hips);
}
if (not generic_trackers.empty())
return xr::body_tracker(std::in_place_type_t<xr::htc_body_tracker>(),
session,
generic_trackers);
if (instance.has_extension(XR_BD_BODY_TRACKING_EXTENSION_NAME))
{
auto bd_body_properties = system.bd_body_tracking_properties();
if (bd_body_properties.supportsBodyTracking)
return xr::body_tracker(std::in_place_type_t<xr::pico_body_tracker>(),
instance,
session);
}
return std::monostate();
}
-43
View File
@@ -1,43 +0,0 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
*
* 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 <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "fb_body_tracker.h"
#include "htc_body_tracker.h"
#include "pico_body_tracker.h"
#include "xr/system.h"
#include <utility>
#include <variant>
#include <vector>
#include <openxr/openxr.h>
namespace xr
{
class instance;
class session;
using body_tracker = std::variant<std::monostate, xr::fb_body_tracker, xr::htc_body_tracker, xr::pico_body_tracker>;
body_tracker make_body_tracker(xr::instance &, xr::system &, xr::session &, std::vector<std::pair<XrPath, xr::space>> & generic_trackers, bool full_body, bool hips);
body_tracker_type body_tracker_supported(xr::instance &, xr::system &);
} // namespace xr
+1 -1
View File
@@ -17,8 +17,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "xr.h"
#include "xr/check.h"
#include "xr/to_string.h"
#include <system_error>
namespace
-94
View File
@@ -1,94 +0,0 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
*
* 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 <https://www.gnu.org/licenses/>.
*/
#include "face_tracker.h"
#include "hardware.h"
#include "xr/instance.h"
#include "xr/system.h"
xr::face_tracker_type xr::face_tracker_supported(xr::instance & instance, xr::system & system)
{
if (instance.has_extension(XR_FB_FACE_TRACKING2_EXTENSION_NAME))
{
auto properties = system.fb_face_tracking2_properties();
if (properties.supportsVisualFaceTracking)
return xr::face_tracker_type::fb;
}
if (instance.has_extension(XR_HTC_FACIAL_TRACKING_EXTENSION_NAME))
{
auto properties = system.htc_face_tracking_properties();
if (properties.supportEyeFacialTracking or properties.supportLipFacialTracking)
return xr::face_tracker_type::htc;
}
switch (guess_model())
{
case model::pico_4_pro:
case model::pico_4_enterprise:
// The extension used by Pico is not published
// it doesn't even need to be requested...
if (instance.has_extension(XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME) and
system.eye_gaze_interaction_properties().supportsEyeGazeInteraction)
return xr::face_tracker_type::pico;
break;
default:
break;
}
return xr::face_tracker_type::none;
}
xr::face_tracker xr::make_face_tracker(xr::instance & instance, xr::system & system, xr::session & session)
{
if (instance.has_extension(XR_FB_FACE_TRACKING2_EXTENSION_NAME))
{
auto properties = system.fb_face_tracking2_properties();
if (properties.supportsVisualFaceTracking)
return xr::face_tracker(std::in_place_type_t<xr::fb_face_tracker2>(), instance, session);
}
if (instance.has_extension(XR_HTC_FACIAL_TRACKING_EXTENSION_NAME))
{
auto properties = system.htc_face_tracking_properties();
if (properties.supportEyeFacialTracking or properties.supportLipFacialTracking)
return xr::face_tracker(
std::in_place_type_t<xr::htc_face_tracker>(),
instance,
session,
properties.supportEyeFacialTracking,
properties.supportLipFacialTracking);
}
switch (guess_model())
{
case model::pico_4_pro:
case model::pico_4_enterprise:
// The extension used by Pico is not published
// it doesn't even need to be requested...
if (instance.has_extension(XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME) and
system.eye_gaze_interaction_properties().supportsEyeGazeInteraction)
return xr::face_tracker(std::in_place_type_t<xr::pico_face_tracker>(), instance, session);
break;
default:
break;
}
return std::monostate();
}
+42 -17
View File
@@ -17,11 +17,10 @@
*/
#include "fb_body_tracker.h"
#include "application.h"
#include "spdlog/spdlog.h"
#include "xr/instance.h"
#include "xr/meta_body_tracking_fidelity.h"
#include "xr/session.h"
#include "xr/to_string.h"
#include "xr/xr.h"
#include <ranges>
#include <openxr/openxr.h>
@@ -40,33 +39,59 @@ std::vector<XrFullBodyJointMETA> xr::fb_body_tracker::get_whitelisted_joints(boo
return {whitelisted_joints.begin(), whitelisted_joints.end()};
}
xr::fb_body_tracker::fb_body_tracker(instance & inst, session & s, bool full_body, bool hip) :
handle(inst.get_proc<PFN_xrDestroyBodyTrackerFB>("xrDestroyBodyTrackerFB")),
xrRequestBodyTrackingFidelityMETA(inst.get_proc<PFN_xrRequestBodyTrackingFidelityMETA>("xrRequestBodyTrackingFidelityMETA")),
xrLocateBodyJointsFB(inst.get_proc<PFN_xrLocateBodyJointsFB>("xrLocateBodyJointsFB")),
full_body(full_body),
hip(hip)
xr::fb_body_tracker::fb_body_tracker(instance & inst, session & s) :
s(s)
{
auto xrCreateBodyTrackerFB = inst.get_proc<PFN_xrCreateBodyTrackerFB>("xrCreateBodyTrackerFB");
xrCreateBodyTrackerFB = inst.get_proc<PFN_xrCreateBodyTrackerFB>("xrCreateBodyTrackerFB");
xrRequestBodyTrackingFidelityMETA = inst.get_proc<PFN_xrRequestBodyTrackingFidelityMETA>("xrRequestBodyTrackingFidelityMETA");
xrLocateBodyJointsFB = inst.get_proc<PFN_xrLocateBodyJointsFB>("xrLocateBodyJointsFB");
xrDestroyBodyTrackerFB = inst.get_proc<PFN_xrDestroyBodyTrackerFB>("xrDestroyBodyTrackerFB");
}
xr::fb_body_tracker::~fb_body_tracker()
{
stop();
}
void xr::fb_body_tracker::start(bool full_body, bool hip)
{
assert(xrCreateBodyTrackerFB);
this->full_body = full_body;
this->hip = hip;
XrBodyTrackerCreateInfoFB create_info{
.type = XR_TYPE_BODY_TRACKER_CREATE_INFO_FB,
.bodyJointSet = full_body
? XR_BODY_JOINT_SET_FULL_BODY_META
: XR_BODY_JOINT_SET_DEFAULT_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, &id));
CHECK_XR(xrCreateBodyTrackerFB(s, &create_info, &handle));
// Enable IOBT.
CHECK_XR(xrRequestBodyTrackingFidelityMETA(id, XR_BODY_TRACKING_FIDELITY_HIGH_META));
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);
CHECK_XR(xrDestroyBodyTrackerFB(std::exchange(handle, nullptr)));
}
}
size_t xr::fb_body_tracker::count() const
{
const auto & config = application::get_config();
return get_whitelisted_joints(config.fb_lower_body, config.fb_hip).size();
}
std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses>> xr::fb_body_tracker::locate_spaces(XrTime time, XrSpace reference)
{
if (!id)
if (!handle)
return std::nullopt;
assert(xrLocateBodyJointsFB);
@@ -86,7 +111,7 @@ std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_h
.jointLocations = joints.data(),
};
if (auto res = xrLocateBodyJointsFB(id, &locate_info, &joint_locations); !XR_SUCCEEDED(res))
if (auto res = xrLocateBodyJointsFB(handle, &locate_info, &joint_locations); !XR_SUCCEEDED(res))
{
spdlog::warn("xrLocateBodyJointsFB returned {}", xr::to_string(res));
return std::nullopt;
+13 -3
View File
@@ -20,7 +20,6 @@
#include "wivrn_packets.h"
#include "utils/handle.h"
#include "xr/meta_body_tracking_fidelity.h"
#include <array>
#include <optional>
@@ -31,10 +30,15 @@ namespace xr
class instance;
class session;
class fb_body_tracker : public utils::handle<XrBodyTrackerFB>
class fb_body_tracker
{
XrSession s;
XrBodyTrackerFB handle{};
PFN_xrCreateBodyTrackerFB xrCreateBodyTrackerFB{};
PFN_xrRequestBodyTrackingFidelityMETA xrRequestBodyTrackingFidelityMETA{};
PFN_xrLocateBodyJointsFB xrLocateBodyJointsFB{};
PFN_xrDestroyBodyTrackerFB xrDestroyBodyTrackerFB{};
bool full_body{};
bool hip{};
@@ -55,7 +59,13 @@ public:
};
static std::vector<XrFullBodyJointMETA> get_whitelisted_joints(bool full_body, bool hip);
fb_body_tracker(instance & inst, session & s, bool full_body, bool hip);
fb_body_tracker() = default;
fb_body_tracker(instance & inst, session & s);
~fb_body_tracker();
void start(bool lower_body, bool hip);
void stop();
size_t count() const;
std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses>> locate_spaces(XrTime time, XrSpace reference);
};
+9 -2
View File
@@ -23,11 +23,18 @@
#include <cstdint>
#include <openxr/openxr.h>
xr::fb_face_tracker2::fb_face_tracker2(instance & inst, session & s) :
handle(inst.get_proc<PFN_xrDestroyFaceTracker2FB>("xrDestroyFaceTracker2FB"))
static PFN_xrDestroyFaceTracker2FB xrDestroyFaceTracker2FB{};
XrResult xr::destroy_fb_face_tracker2(XrFaceTracker2FB id)
{
return xrDestroyFaceTracker2FB(id);
}
xr::fb_face_tracker2::fb_face_tracker2(instance & inst, session & s)
{
auto xrCreateFaceTracker2FB = inst.get_proc<PFN_xrCreateFaceTracker2FB>("xrCreateFaceTracker2FB");
xrGetFaceExpressionWeights2FB = inst.get_proc<PFN_xrGetFaceExpressionWeights2FB>("xrGetFaceExpressionWeights2FB");
xrDestroyFaceTracker2FB = inst.get_proc<PFN_xrDestroyFaceTracker2FB>("xrDestroyFaceTracker2FB");
assert(xrCreateFaceTracker2FB);
XrFaceTrackingDataSource2FB data_sources[1];
+5 -1
View File
@@ -27,12 +27,16 @@ namespace xr
class instance;
class session;
class fb_face_tracker2 : public utils::handle<XrFaceTracker2FB>
XrResult destroy_fb_face_tracker2(XrFaceTracker2FB);
class fb_face_tracker2 : public utils::handle<XrFaceTracker2FB, destroy_fb_face_tracker2>
{
PFN_xrGetFaceExpressionWeights2FB xrGetFaceExpressionWeights2FB{};
PFN_xrDestroyFaceTracker2FB xrDestroyFaceTracker2FB{};
public:
using packet_type = wivrn::from_headset::tracking::fb_face2;
fb_face_tracker2() = default;
fb_face_tracker2(instance & inst, session & s);
void get_weights(XrTime time, packet_type & out_expressions);
+10 -3
View File
@@ -23,12 +23,19 @@
#include "xr/session.h"
#include <cassert>
xr::hand_tracker::hand_tracker(instance & inst, session & session, const XrHandTrackerCreateInfoEXT & info) :
handle(inst.get_proc<PFN_xrDestroyHandTrackerEXT>("xrDestroyHandTrackerEXT"))
static PFN_xrDestroyHandTrackerEXT xrDestroyHandTrackerEXT{};
XrResult xr::destroy_hand_tracker(XrHandTrackerEXT id)
{
auto xrCreateHandTrackerEXT = inst.get_proc<PFN_xrCreateHandTrackerEXT>("xrCreateHandTrackerEXT");
return xrDestroyHandTrackerEXT(id);
}
xr::hand_tracker::hand_tracker(instance & inst, session & session, const XrHandTrackerCreateInfoEXT & info)
{
static auto xrCreateHandTrackerEXT = inst.get_proc<PFN_xrCreateHandTrackerEXT>("xrCreateHandTrackerEXT");
assert(xrCreateHandTrackerEXT);
xrLocateHandJointsEXT = inst.get_proc<PFN_xrLocateHandJointsEXT>("xrLocateHandJointsEXT");
xrDestroyHandTrackerEXT = inst.get_proc<PFN_xrDestroyHandTrackerEXT>("xrDestroyHandTrackerEXT");
CHECK_XR(xrCreateHandTrackerEXT(session, &info, &id));
}
+3 -1
View File
@@ -28,12 +28,14 @@ namespace xr
{
class instance;
class session;
XrResult destroy_hand_tracker(XrHandTrackerEXT);
class hand_tracker : public utils::handle<XrHandTrackerEXT>
class hand_tracker : public utils::handle<XrHandTrackerEXT, destroy_hand_tracker>
{
PFN_xrLocateHandJointsEXT xrLocateHandJointsEXT{};
public:
hand_tracker() = default;
hand_tracker(instance & inst, session & session, const XrHandTrackerCreateInfoEXT & info);
using joint = std::pair<XrHandJointLocationEXT, XrHandJointVelocityEXT>;
+58 -27
View File
@@ -2,7 +2,6 @@
* WiVRn VR streaming
* Copyright (C) 2025 Awzri <awzri@awzricat.com>
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
*
* 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
@@ -20,7 +19,8 @@
#include "htc_body_tracker.h"
#include "xr/details/enumerate.h"
#include "xr/session.h"
#include "xr/htc_exts.h"
#include "xr/xr.h"
#include <openxr/openxr.h>
// Note: This utilizes extensions not present in the OpenXR spec!
@@ -28,25 +28,11 @@
// https://hub.vive.com/apidoc/api/VIVE.OpenXR.Tracker.ViveXRTracker.html
// https://hub.vive.com/apidoc/api/VIVE.OpenXR.VivePathEnumerationHelper.xrEnumeratePathsForInteractionProfileHTCDelegate.html
xr::vive_xr_tracker::vive_xr_tracker(XrPath path, xr::space & space, XrSession session) :
path(path),
space(space)
xr::vive_xr_tracker::vive_xr_tracker(xr::space && space) :
space(std::move(space)) {}
void xr::vive_xr_tracker::set_active(bool active)
{
update_active(session);
}
void xr::vive_xr_tracker::update_active(XrSession session)
{
XrInputSourceLocalizedNameGetInfo get_info{
.type = XR_TYPE_INPUT_SOURCE_LOCALIZED_NAME_GET_INFO,
.next = nullptr,
.sourcePath = path,
.whichComponents = XR_INPUT_SOURCE_LOCALIZED_NAME_USER_PATH_BIT,
};
auto role = xr::details::enumerate<char>(xrGetInputSourceLocalizedName, session, &get_info);
is_active = not role.contains("_");
is_active = active;
}
bool xr::vive_xr_tracker::get_active() const
{
@@ -90,18 +76,63 @@ static wivrn::from_headset::body_tracking::pose locate_space(XrSpace space, XrSp
return res;
}
xr::htc_body_tracker::htc_body_tracker(session & s, std::vector<std::pair<XrPath, xr::space>> & trackers) :
std::vector<std::string> xr::htc_body_tracker::get_roles()
{
auto paths = get_paths();
std::vector<std::string> roles{};
roles.reserve(paths.size());
for (auto & path: paths)
{
XrInputSourceLocalizedNameGetInfo get_info{
.type = XR_TYPE_INPUT_SOURCE_LOCALIZED_NAME_GET_INFO,
.next = nullptr,
.sourcePath = path,
.whichComponents = XR_INPUT_SOURCE_LOCALIZED_NAME_USER_PATH_BIT,
};
roles.emplace_back(xr::details::enumerate<char>(xrGetInputSourceLocalizedName, s, &get_info));
}
return roles;
}
xr::htc_body_tracker::htc_body_tracker(instance & inst, session & s) :
inst(&inst),
s(s)
{
this->trackers.reserve(trackers.size());
for (auto & [path, space]: trackers)
this->trackers.emplace_back(path, space, s);
xrEnumeratePathsForInteractionProfileHTC = inst.get_proc<PFN_xrEnumeratePathsForInteractionProfileHTC>("xrEnumeratePathsForInteractionProfileHTC");
}
std::vector<XrPath> xr::htc_body_tracker::get_paths(XrPath user_path)
{
assert(xrEnumeratePathsForInteractionProfileHTC);
XrPath tracker_profile = inst->string_to_path("/interaction_profiles/htc/vive_xr_tracker");
XrPathsForInteractionProfileEnumerateInfoHTC profile_info{
.type = XR_TYPE_UNKNOWN,
.next = nullptr,
.interactionProfile = tracker_profile,
.userPath = user_path,
};
return xr::details::enumerate<XrPath>(xrEnumeratePathsForInteractionProfileHTC, *inst, profile_info);
}
void xr::htc_body_tracker::add(xr::space && space)
{
trackers.emplace_back(std::move(space));
}
size_t xr::htc_body_tracker::count() const
{
return trackers.size();
}
void xr::htc_body_tracker::update_active()
{
for (auto & tracker: trackers)
tracker.update_active(s);
auto roles = get_roles();
assert(roles.size() >= trackers.size());
for (int i = 0; i < trackers.size(); i++)
trackers[i].set_active(!roles[i].contains('_'));
}
std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses> xr::htc_body_tracker::locate_spaces(XrTime time, XrSpace reference)
@@ -110,7 +141,7 @@ std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_t
for (int i = 0; i < trackers.size(); i++)
{
auto & tracker = trackers[i];
auto & tracker = trackers.at(i);
wivrn::from_headset::body_tracking::pose pose{
.pose = {},
.flags = 0,
+16 -7
View File
@@ -2,7 +2,6 @@
* WiVRn VR streaming
* Copyright (C) 2025 Awzri <awzri@awzricat.com>
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
*
* 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
@@ -21,7 +20,9 @@
#pragma once
#include "wivrn_packets.h"
#include "xr/htc_exts.h"
#include "xr/space.h"
#include <string>
#include <vector>
#include <openxr/openxr.h>
@@ -33,24 +34,32 @@ class session;
class vive_xr_tracker
{
bool is_active = false;
XrPath path;
xr::space & space;
xr::space space;
public:
vive_xr_tracker(XrPath path, xr::space & s, XrSession session);
void update_active(XrSession session);
vive_xr_tracker(xr::space && s);
void set_active(bool active);
bool get_active() const;
XrSpace get_space() const;
};
class htc_body_tracker
{
instance * inst;
XrSession s;
std::vector<vive_xr_tracker> trackers;
public:
htc_body_tracker(session & s, std::vector<std::pair<XrPath, xr::space>> & trackers);
PFN_xrEnumeratePathsForInteractionProfileHTC xrEnumeratePathsForInteractionProfileHTC{};
std::vector<std::string> get_roles();
public:
htc_body_tracker() = default;
htc_body_tracker(instance & inst, session & s);
std::vector<XrPath> get_paths(XrPath user_path = XR_NULL_PATH);
void add(xr::space && space);
size_t count() const;
void update_active();
std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses> locate_spaces(XrTime time, XrSpace reference);
};
+31 -21
View File
@@ -18,43 +18,53 @@
*/
#include "htc_face_tracker.h"
#include "wivrn_packets.h"
#include "xr/instance.h"
#include "xr/session.h"
#include <openxr/openxr.h>
static XrFacialTrackerHTC make_tracker(xr::instance & inst, xr::session & s, XrFacialTrackingTypeHTC type)
xr::htc_face_tracker::htc_face_tracker(instance & inst, session & s, bool eye, bool lip) :
s(s)
{
if (!eye && !lip)
return;
xrCreateFacialTrackerHTC = inst.get_proc<PFN_xrCreateFacialTrackerHTC>("xrCreateFacialTrackerHTC");
xrGetFacialExpressionsHTC = inst.get_proc<PFN_xrGetFacialExpressionsHTC>("xrGetFacialExpressionsHTC");
xrDestroyFacialTrackerHTC = inst.get_proc<PFN_xrDestroyFacialTrackerHTC>("xrDestroyFacialTrackerHTC");
XrFacialTrackerCreateInfoHTC create_info{
.type = XR_TYPE_FACIAL_TRACKER_CREATE_INFO_HTC,
.facialTrackingType = type,
.next = nullptr,
};
auto xrCreateFacialTrackerHTC = inst.get_proc<PFN_xrCreateFacialTrackerHTC>("xrCreateFacialTrackerHTC");
XrFacialTrackerHTC id;
CHECK_XR(xrCreateFacialTrackerHTC(s, &create_info, &id));
return id;
if (eye)
{
create_info.facialTrackingType = XR_FACIAL_TRACKING_TYPE_EYE_DEFAULT_HTC;
xrCreateFacialTrackerHTC(s, &create_info, &this->eye);
}
if (lip)
{
create_info.facialTrackingType = XR_FACIAL_TRACKING_TYPE_LIP_DEFAULT_HTC;
xrCreateFacialTrackerHTC(s, &create_info, &this->lip);
}
}
static XrFacialTrackerHTC get_eye_tracker(xr::instance & inst, xr::session & s)
xr::htc_face_tracker::~htc_face_tracker()
{
static XrFacialTrackerHTC res = make_tracker(inst, s, XR_FACIAL_TRACKING_TYPE_EYE_DEFAULT_HTC);
return res;
}
static XrFacialTrackerHTC get_lip_tracker(xr::instance & inst, xr::session & s)
{
static XrFacialTrackerHTC res = make_tracker(inst, s, XR_FACIAL_TRACKING_TYPE_LIP_DEFAULT_HTC);
return res;
}
if (!xrDestroyFacialTrackerHTC)
return;
xr::htc_face_tracker::htc_face_tracker(instance & inst, session & s, bool eye, bool lip) :
xrGetFacialExpressionsHTC(inst.get_proc<PFN_xrGetFacialExpressionsHTC>("xrGetFacialExpressionsHTC")),
eye(eye ? get_eye_tracker(inst, s) : XR_NULL_HANDLE),
lip(lip ? get_lip_tracker(inst, s) : XR_NULL_HANDLE)
{
if (eye)
CHECK_XR(xrDestroyFacialTrackerHTC(std::exchange(eye, nullptr)));
if (lip)
CHECK_XR(xrDestroyFacialTrackerHTC(std::exchange(lip, nullptr)));
}
void xr::htc_face_tracker::get_weights(XrTime time, packet_type & out_expressions)
{
assert(xrGetFacialExpressionsHTC);
if (!(eye || lip) || !xrGetFacialExpressionsHTC)
return;
XrFacialExpressionsHTC expressions{
.type = XR_TYPE_FACIAL_EXPRESSIONS_HTC,
+9 -3
View File
@@ -19,6 +19,7 @@
#pragma once
#include "utils/handle.h"
#include "wivrn_packets.h"
#include <openxr/openxr.h>
@@ -29,13 +30,18 @@ class session;
class htc_face_tracker
{
PFN_xrGetFacialExpressionsHTC xrGetFacialExpressionsHTC;
XrFacialTrackerHTC eye;
XrFacialTrackerHTC lip;
XrSession s;
XrFacialTrackerHTC eye{};
XrFacialTrackerHTC lip{};
PFN_xrCreateFacialTrackerHTC xrCreateFacialTrackerHTC{};
PFN_xrGetFacialExpressionsHTC xrGetFacialExpressionsHTC{};
PFN_xrDestroyFacialTrackerHTC xrDestroyFacialTrackerHTC{};
public:
using packet_type = wivrn::from_headset::tracking::htc_face;
htc_face_tracker() = default;
htc_face_tracker(instance & inst, session & s, bool eye, bool lip);
~htc_face_tracker();
void get_weights(XrTime time, packet_type & out_expressions);
};
+17 -104
View File
@@ -19,14 +19,11 @@
#include "instance.h"
#include "xr.h"
#include "xr/details/enumerate.h"
#include "xr/htc_exts.h"
#include "xr/to_string.h"
#include <algorithm>
#include <cassert>
#include <cstring>
#include <map>
#include <set>
#include <spdlog/spdlog.h>
#include <vulkan/vulkan.h>
#include <openxr/openxr.h>
@@ -44,54 +41,7 @@ static XrBool32 debug_callback(
return XR_FALSE;
}
namespace
{
struct version_info
{
std::set<const char *, std::less<>> promoted_extensions;
std::set<const char *, std::less<>> removed_extensions;
bool shall_request(std::string_view extension) const
{
return not(promoted_extensions.contains(extension) or removed_extensions.contains(extension));
}
static const std::map<XrVersion, version_info> versions;
static const version_info * get(XrVersion version)
{
auto it = versions.find(XR_MAKE_VERSION(XR_VERSION_MAJOR(version), XR_VERSION_MINOR(version), 0));
if (it == versions.end())
return nullptr;
return &it->second;
}
};
const std::map<XrVersion, version_info> version_info::versions = {{
XR_MAKE_VERSION(1, 1, 0),
{
.promoted_extensions = {
XR_KHR_LOCATE_SPACES_EXTENSION_NAME,
XR_KHR_MAINTENANCE1_EXTENSION_NAME,
XR_EXT_HP_MIXED_REALITY_CONTROLLER_EXTENSION_NAME,
XR_EXT_LOCAL_FLOOR_EXTENSION_NAME,
XR_EXT_PALM_POSE_EXTENSION_NAME,
XR_EXT_SAMSUNG_ODYSSEY_CONTROLLER_EXTENSION_NAME,
XR_EXT_UUID_EXTENSION_NAME,
XR_BD_CONTROLLER_INTERACTION_EXTENSION_NAME,
XR_HTC_VIVE_COSMOS_CONTROLLER_INTERACTION_EXTENSION_NAME,
XR_HTC_VIVE_FOCUS3_CONTROLLER_INTERACTION_EXTENSION_NAME,
XR_ML_ML2_CONTROLLER_INTERACTION_EXTENSION_NAME,
XR_VARJO_QUAD_VIEWS_EXTENSION_NAME,
},
.removed_extensions = {
// Extensions that are included, but actually different
XR_FB_TOUCH_CONTROLLER_PRO_EXTENSION_NAME,
XR_META_TOUCH_CONTROLLER_PLUS_EXTENSION_NAME,
},
},
}};
} // namespace
static std::pair<XrVersion, XrInstance> create_instance(XrInstanceCreateInfo & info, std::vector<const char *> & in_extensions)
static std::pair<XrVersion, XrInstance> create_instance(XrInstanceCreateInfo & info)
{
XrResult res;
for (XrVersion version: {
@@ -99,34 +49,11 @@ static std::pair<XrVersion, XrInstance> create_instance(XrInstanceCreateInfo & i
XR_API_VERSION_1_0,
})
{
std::vector<const char *> extensions;
info.applicationInfo.apiVersion = version;
auto v_info = version_info::get(version);
if (v_info)
{
std::ranges::copy_if(
in_extensions,
std::back_inserter(extensions),
[v_info](const char * ext) { return v_info->shall_request(ext); });
info.enabledExtensionNames = extensions.data();
info.enabledExtensionCount = extensions.size();
}
else
{
info.enabledExtensionNames = in_extensions.data();
info.enabledExtensionCount = in_extensions.size();
}
XrInstance inst;
res = xrCreateInstance(&info, &inst);
if (XR_SUCCEEDED(res))
{
if (v_info)
{
extensions.insert(extensions.end(), v_info->promoted_extensions.begin(), v_info->promoted_extensions.end());
std::swap(in_extensions, extensions);
}
return {version, inst};
}
spdlog::info("Failed to create OpenXR instance version {}: {}",
xr::to_string(version),
xr::to_string(res));
@@ -201,6 +128,20 @@ xr::instance::instance(std::string_view application_name, std::vector<const char
#endif
}
spdlog::info("Using OpenXR extensions:");
for (auto & i: extensions)
{
uint32_t version = 0;
for (auto & j: all_extensions)
{
if (!strcmp(j.extensionName, i))
version = j.extensionVersion;
}
loaded_extensions.emplace(i, version);
spdlog::info(" {}", i);
}
XrInstanceCreateInfo create_info{
.type = XR_TYPE_INSTANCE_CREATE_INFO,
.enabledApiLayerCount = (uint32_t)layers.size(),
@@ -219,21 +160,7 @@ xr::instance::instance(std::string_view application_name, std::vector<const char
create_info.next = &instanceCreateInfoAndroid;
#endif
std::tie(api_version, id) = create_instance(create_info, extensions);
spdlog::info("Using OpenXR extensions:");
for (auto i: extensions)
{
uint32_t version = 0;
for (auto & j: all_extensions)
{
if (!strcmp(j.extensionName, i))
version = j.extensionVersion;
}
loaded_extensions.emplace(i, version);
spdlog::info(" {}", i);
}
std::tie(api_version, id) = create_instance(create_info);
if (debug_utils_found)
{
@@ -285,20 +212,6 @@ XrPath xr::instance::string_to_path(const std::string & path)
return p;
}
std::vector<XrPath> xr::instance::enumerate_paths_for_interaction_profile(XrPath interaction_profile, XrPath user_path)
{
assert(has_extension(XR_HTC_PATH_ENUMERATION_EXTENSION_NAME));
static auto xrEnumeratePathsForInteractionProfileHTC = get_proc<PFN_xrEnumeratePathsForInteractionProfileHTC>("xrEnumeratePathsForInteractionProfileHTC");
XrPathsForInteractionProfileEnumerateInfoHTC profile_info{
.type = XR_TYPE_UNKNOWN,
.next = nullptr,
.interactionProfile = interaction_profile,
.userPath = user_path,
};
return xr::details::enumerate<XrPath>(xrEnumeratePathsForInteractionProfileHTC, id, profile_info);
}
bool xr::instance::poll_event(xr::event & buffer)
{
buffer.header.type = XR_TYPE_EVENT_DATA_BUFFER;
-2
View File
@@ -90,8 +90,6 @@ public:
XrPath string_to_path(const std::string & path);
std::string path_to_string(XrPath path);
std::vector<XrPath> enumerate_paths_for_interaction_profile(XrPath interaction_profile, XrPath user_path = XR_NULL_PATH);
void suggest_bindings(const std::string & interaction_profile,
std::vector<XrActionSuggestedBinding> & bindings);
+24 -5
View File
@@ -23,9 +23,27 @@
#include "xr/check.h"
#include "xr/instance.h"
xr::passthrough_layer_fb::passthrough_layer_fb(instance & inst, session & s, const XrPassthroughLayerCreateInfoFB & info) :
handle(inst.get_proc<PFN_xrDestroyPassthroughLayerFB>("xrDestroyPassthroughLayerFB"))
static PFN_xrDestroyPassthroughLayerFB xrDestroyPassthroughLayerFB{};
static PFN_xrDestroyPassthroughFB xrDestroyPassthroughFB{};
static PFN_xrDestroyPassthroughHTC xrDestroyPassthroughHTC{};
XrResult xr::destroy_passthrough_layer_fb(XrPassthroughLayerFB id)
{
return xrDestroyPassthroughLayerFB(id);
}
XrResult xr::destroy_passthrough_fb(XrPassthroughFB id)
{
return xrDestroyPassthroughFB(id);
}
XrResult xr::destroy_passthrough_htc(XrPassthroughHTC id)
{
return xrDestroyPassthroughHTC(id);
}
xr::passthrough_layer_fb::passthrough_layer_fb(instance & inst, session & s, const XrPassthroughLayerCreateInfoFB & info)
{
xrDestroyPassthroughLayerFB = inst.get_proc<PFN_xrDestroyPassthroughLayerFB>("xrDestroyPassthroughLayerFB");
PFN_xrCreatePassthroughLayerFB xrCreatePassthroughLayerFB = inst.get_proc<PFN_xrCreatePassthroughLayerFB>("xrCreatePassthroughLayerFB");
CHECK_XR(xrCreatePassthroughLayerFB(s, &info, &id));
}
@@ -33,6 +51,7 @@ xr::passthrough_layer_fb::passthrough_layer_fb(instance & inst, session & s, con
static XrPassthroughFB create_passthrough_fb(xr::instance & inst, xr::session & s)
{
PFN_xrCreatePassthroughFB xrCreatePassthroughFB = inst.get_proc<PFN_xrCreatePassthroughFB>("xrCreatePassthroughFB");
xrDestroyPassthroughFB = inst.get_proc<PFN_xrDestroyPassthroughFB>("xrDestroyPassthroughFB");
XrPassthroughFB id;
XrPassthroughCreateInfoFB info{
@@ -45,7 +64,7 @@ static XrPassthroughFB create_passthrough_fb(xr::instance & inst, xr::session &
}
xr::passthrough_fb::passthrough_fb(instance & inst, session & s) :
handle(create_passthrough_fb(inst, s), inst.get_proc<PFN_xrDestroyPassthroughFB>("xrDestroyPassthroughFB")),
utils::handle<XrPassthroughFB, destroy_passthrough_fb>(create_passthrough_fb(inst, s)),
passthrough_layer(inst, s, XrPassthroughLayerCreateInfoFB{
.type = XR_TYPE_PASSTHROUGH_LAYER_CREATE_INFO_FB,
.passthrough = id,
@@ -79,10 +98,10 @@ void xr::passthrough_fb::pause()
CHECK_XR(xrPassthroughPauseFB(id));
}
xr::passthrough_htc::passthrough_htc(instance & inst, session & s) :
handle(inst.get_proc<PFN_xrDestroyPassthroughHTC>("xrDestroyPassthroughHTC"))
xr::passthrough_htc::passthrough_htc(instance & inst, session & s)
{
PFN_xrCreatePassthroughHTC xrCreatePassthroughHTC = inst.get_proc<PFN_xrCreatePassthroughHTC>("xrCreatePassthroughHTC");
xrDestroyPassthroughHTC = inst.get_proc<PFN_xrDestroyPassthroughHTC>("xrDestroyPassthroughHTC");
XrPassthroughCreateInfoHTC info{
.type = XR_TYPE_PASSTHROUGH_CREATE_INFO_HTC,
+7 -3
View File
@@ -28,13 +28,17 @@ namespace xr
class instance;
class session;
class passthrough_layer_fb : public utils::handle<XrPassthroughLayerFB>
XrResult destroy_passthrough_layer_fb(XrPassthroughLayerFB);
XrResult destroy_passthrough_fb(XrPassthroughFB);
XrResult destroy_passthrough_htc(XrPassthroughHTC);
class passthrough_layer_fb : public utils::handle<XrPassthroughLayerFB, destroy_passthrough_layer_fb>
{
public:
passthrough_layer_fb(instance &, session &, const XrPassthroughLayerCreateInfoFB &);
};
class passthrough_fb : public utils::handle<XrPassthroughFB>
class passthrough_fb : public utils::handle<XrPassthroughFB, destroy_passthrough_fb>
{
PFN_xrPassthroughStartFB xrPassthroughStartFB{};
PFN_xrPassthroughPauseFB xrPassthroughPauseFB{};
@@ -55,7 +59,7 @@ public:
}
};
class passthrough_htc : public utils::handle<XrPassthroughHTC>
class passthrough_htc : public utils::handle<XrPassthroughHTC, destroy_passthrough_htc>
{
XrCompositionLayerPassthroughHTC composition_layer;
+13 -5
View File
@@ -18,15 +18,19 @@
#include "pico_body_tracker.h"
#include "spdlog/spdlog.h"
#include "xr/instance.h"
#include "xr/session.h"
#include "xr/to_string.h"
#include "xr/xr.h"
#include <openxr/openxr.h>
static_assert(xr::pico_body_tracker::joint_whitelist.size() <= wivrn::from_headset::body_tracking::max_tracked_poses);
xr::pico_body_tracker::pico_body_tracker(instance & inst, session & s) :
handle(inst.get_proc<PFN_xrDestroyBodyTrackerBD>("xrDestroyBodyTrackerBD"))
static PFN_xrDestroyBodyTrackerBD xrDestroyBodyTrackerBD{};
XrResult xr::destroy_pico_body_tracker(XrBodyTrackerBD id)
{
return xrDestroyBodyTrackerBD(id);
}
xr::pico_body_tracker::pico_body_tracker(instance & inst, session & s)
{
auto xrCreateBodyTrackerBD = inst.get_proc<PFN_xrCreateBodyTrackerBD>("xrCreateBodyTrackerBD");
xrLocateBodyJointsBD = inst.get_proc<PFN_xrLocateBodyJointsBD>("xrLocateBodyJointsBD");
@@ -41,6 +45,10 @@ xr::pico_body_tracker::pico_body_tracker(instance & inst, session & s) :
CHECK_XR(xrCreateBodyTrackerBD(s, &create_info, &id));
}
size_t xr::pico_body_tracker::count() const
{
return joint_whitelist.size();
}
std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses>> xr::pico_body_tracker::locate_spaces(XrTime time, XrSpace reference)
{
if (!xrLocateBodyJointsBD)
+5 -1
View File
@@ -30,7 +30,9 @@ namespace xr
class instance;
class session;
class pico_body_tracker : public utils::handle<XrBodyTrackerBD>
XrResult destroy_pico_body_tracker(XrBodyTrackerBD);
class pico_body_tracker : public utils::handle<XrBodyTrackerBD, destroy_pico_body_tracker>
{
PFN_xrLocateBodyJointsBD xrLocateBodyJointsBD{};
@@ -46,8 +48,10 @@ public:
XR_BODY_JOINT_RIGHT_FOOT_BD,
};
pico_body_tracker() = default;
pico_body_tracker(instance & inst, session & s);
size_t count() const;
std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses>> locate_spaces(XrTime time, XrSpace reference);
};
} // namespace xr
+124 -135
View File
@@ -18,163 +18,152 @@
*/
#include "pico_face_tracker.h"
#include "spdlog/common.h"
#include "spdlog/spdlog.h"
#include "wivrn_packets.h"
#include "xr/instance.h"
#include "xr/pico_eye_types.h"
#include "xr/pico_eye_types_reflection.h"
#include "xr/session.h"
#include "xr/to_string.h"
#include <mutex>
#include <cstring>
#include <stdexcept>
#include <openxr/openxr.h>
struct xr::pico_face_tracker::impl
xr::pico_face_tracker::pico_face_tracker(instance & inst, session & s_) :
s(s_)
{
const XrSession s;
const PFN_xrStopEyeTrackingPICO xrStopEyeTrackingPICO;
const PFN_xrGetFaceTrackingDataPICO xrGetFaceTrackingDataPICO;
xrStartEyeTrackingPICO = inst.get_proc<PFN_xrStartEyeTrackingPICO>("xrStartEyeTrackingPICO");
xrStopEyeTrackingPICO = inst.get_proc<PFN_xrStopEyeTrackingPICO>("xrStopEyeTrackingPICO");
xrSetTrackingModePICO = inst.get_proc<PFN_xrSetTrackingModePICO>("xrSetTrackingModePICO");
xrGetFaceTrackingDataPICO = inst.get_proc<PFN_xrGetFaceTrackingDataPICO>("xrGetFaceTrackingDataPICO");
}
xr::pico_face_tracker::~pico_face_tracker()
{
stop();
}
impl(instance & inst, session & s) :
s(s),
xrStopEyeTrackingPICO(inst.get_proc<PFN_xrStopEyeTrackingPICO>("xrStopEyeTrackingPICO")),
xrGetFaceTrackingDataPICO(inst.get_proc<PFN_xrGetFaceTrackingDataPICO>("xrGetFaceTrackingDataPICO"))
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)
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));
started = false;
}
void xr::pico_face_tracker::get_weights(XrTime time, wivrn::from_headset::tracking::fb_face2 & out_expressions)
{
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); !XR_SUCCEEDED(res))
{
auto xrStartEyeTrackingPICO = inst.get_proc<PFN_xrStartEyeTrackingPICO>("xrStartEyeTrackingPICO");
auto xrSetTrackingModePICO = inst.get_proc<PFN_xrSetTrackingModePICO>("xrSetTrackingModePICO");
CHECK_XR(xrStartEyeTrackingPICO(s));
CHECK_XR(xrSetTrackingModePICO(s, XR_TRACKING_MODE_FACE_BIT_PICO));
spdlog::warn("Unable to get face tracking data: xrGetFaceTrackingDataPICO returned {}", xr::to_string(res));
return;
}
~impl()
{
if (auto res = xrStopEyeTrackingPICO(s, XR_TRACKING_MODE_FACE_BIT_PICO); not XR_SUCCEEDED(res))
spdlog::warn("Failed to deactivate face tracking: {}", xr::to_string(res));
}
void get_weights(XrTime time, wivrn::from_headset::tracking::fb_face2 & out_expressions)
{
out_expressions.is_valid = false;
out_expressions.is_eye_following_blendshapes_valid = false;
XrFaceTrackingDataPICO face_tracking{.time = 0};
if (auto res = xrGetFaceTrackingDataPICO(s, time, XR_GET_FACE_DATA_DEFAULT_PICO, &face_tracking); !XR_SUCCEEDED(res))
{
spdlog::warn("Unable to get face tracking data: xrGetFaceTrackingDataPICO returned {}", xr::to_string(res));
return;
}
if (face_tracking.time == 0)
return;
if (face_tracking.time == 0)
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 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);
// "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_R_FB, XR_BS_EYELOOKOUT_R_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_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
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;
}
};
xr::pico_face_tracker::pico_face_tracker(instance & inst, session & s)
{
// The API has a global start and stop method
// use a shared handle so we can have independent objects
// and start/stop accordingly
static std::mutex mutex;
std::unique_lock lock(mutex);
static std::weak_ptr<impl> instance;
if (auto shared = instance.lock())
{
i = std::move(shared);
return;
}
i = std::make_unique<impl>(inst, s);
instance = i;
}
void xr::pico_face_tracker::get_weights(XrTime time, packet_type & out_expressions)
{
return i->get_weights(time, out_expressions);
out_expressions.is_valid = true;
out_expressions.is_eye_following_blendshapes_valid = true;
}
+13 -2
View File
@@ -20,6 +20,8 @@
#pragma once
#include "wivrn_packets.h"
#include "xr/pico_eye_types.h"
#include "xr/pico_eye_types_reflection.h"
#include <openxr/openxr.h>
namespace xr
@@ -29,13 +31,22 @@ class session;
class pico_face_tracker
{
struct impl;
std::shared_ptr<impl> i;
PFN_xrStartEyeTrackingPICO xrStartEyeTrackingPICO{};
PFN_xrStopEyeTrackingPICO xrStopEyeTrackingPICO{};
PFN_xrSetTrackingModePICO xrSetTrackingModePICO{};
PFN_xrGetFaceTrackingDataPICO xrGetFaceTrackingDataPICO{};
XrSession s;
bool started{};
public:
using packet_type = wivrn::from_headset::tracking::fb_face2;
pico_face_tracker() = default;
pico_face_tracker(instance & inst, session & s);
~pico_face_tracker();
void start();
void stop();
void get_weights(XrTime time, packet_type & out_expressions);
};
} // namespace xr
+8 -9
View File
@@ -19,19 +19,18 @@
#include "session.h"
#include "application.h"
#include "details/enumerate.h"
#include "openxr/openxr.h"
#include "utils/contains.h"
#include "xr/instance.h"
#include "xr/system.h"
#include "xr/to_string.h"
#include <ranges>
#include <vulkan/vulkan.h>
#include <openxr/openxr_platform.h>
xr::session::session(xr::instance & inst, xr::system & sys, vk::raii::Instance & vk_inst, vk::raii::PhysicalDevice & pdev, vk::raii::Device & dev, thread_safe<vk::raii::Queue> & queue, int queue_family_index) :
inst(&inst),
queue(&queue)
xr::session::session(xr::instance & inst, xr::system & sys, vk::raii::Instance & vk_inst, vk::raii::PhysicalDevice & pdev, vk::raii::Device & dev, int queue_family_index) :
inst(&inst)
{
XrGraphicsBindingVulkan2KHR vulkan_binding{
.type = XR_TYPE_GRAPHICS_BINDING_VULKAN2_KHR,
@@ -128,7 +127,7 @@ void xr::session::begin_frame()
.type = XR_TYPE_FRAME_BEGIN_INFO,
};
auto lock = queue->lock();
auto lock = application::get_queue().lock();
CHECK_XR(xrBeginFrame(id, &begin_info));
}
@@ -142,7 +141,7 @@ void xr::session::end_frame(XrTime display_time, const std::vector<XrComposition
.layers = layers.data(),
};
auto lock = queue->lock();
auto lock = application::get_queue().lock();
CHECK_XR(xrEndFrame(id, &end_info));
}
@@ -345,14 +344,14 @@ void xr::session::enable_passthrough(xr::system & system)
if (not std::holds_alternative<std::monostate>(passthrough))
return;
if (system.passthrough_supported() == xr::passthrough_type::none)
if (system.passthrough_supported() == xr::system::passthrough_type::no_passthrough)
return;
if (inst->has_extension(XR_FB_PASSTHROUGH_EXTENSION_NAME))
if (utils::contains(application::get_xr_extensions(), XR_FB_PASSTHROUGH_EXTENSION_NAME))
{
passthrough.emplace<xr::passthrough_fb>(*inst, *this);
}
else if (inst->has_extension(XR_HTC_PASSTHROUGH_EXTENSION_NAME))
else if (utils::contains(application::get_xr_extensions(), XR_HTC_PASSTHROUGH_EXTENSION_NAME))
{
passthrough.emplace<xr::passthrough_htc>(*inst, *this);
}
+1 -3
View File
@@ -20,7 +20,6 @@
#pragma once
#include "utils/handle.h"
#include "utils/thread_safe.h"
#include <span>
#include <string>
#include <vector>
@@ -40,11 +39,10 @@ class session : public utils::handle<XrSession, xrDestroySession>
{
instance * inst = nullptr;
xr::passthrough passthrough;
thread_safe<vk::raii::Queue> * queue = nullptr;
public:
session() = default;
session(instance &, system &, vk::raii::Instance &, vk::raii::PhysicalDevice &, vk::raii::Device &, thread_safe<vk::raii::Queue> & queue, int queue_family_index);
session(instance &, system &, vk::raii::Instance &, vk::raii::PhysicalDevice &, vk::raii::Device &, int queue_family_index);
std::vector<XrReferenceSpaceType> get_reference_spaces() const;
space create_reference_space(XrReferenceSpaceType ref, const XrPosef & pose = {{0, 0, 0, 1}, {0, 0, 0}});
+17
View File
@@ -68,7 +68,24 @@ xr::swapchain::swapchain(xr::session & s, vk::raii::Device & device, vk::Format
images_.resize(array.size());
for (uint32_t i = 0; i < array.size(); i++)
{
images_[i].image = array[i].image;
vk::ImageViewCreateInfo iv_create_info{
.image = array[i].image,
.viewType = vk::ImageViewType::e2D,
.format = format,
.components = {},
.subresourceRange = {
.aspectMask = vk::ImageAspectFlagBits::eColor,
.baseMipLevel = 0,
.levelCount = 1,
.baseArrayLayer = 0,
.layerCount = 1,
}};
images_[i].view = vk::raii::ImageView(device, iv_create_info);
}
}
int xr::swapchain::acquire()
+1
View File
@@ -38,6 +38,7 @@ public:
struct image
{
vk::Image image{};
vk::raii::ImageView view = nullptr;
};
private:
+7 -28
View File
@@ -19,14 +19,12 @@
#include "system.h"
#include "body_tracker.h"
#include "application.h"
#include "details/enumerate.h"
#include "face_tracker.h"
#include "openxr/openxr.h"
#include "utils/contains.h"
#include "vk/check.h"
#include "xr/check.h"
#include "xr/instance.h"
#include <cassert>
#include <openxr/openxr_platform.h>
@@ -43,12 +41,6 @@ xr::system::system(xr::instance & inst, XrFormFactor formfactor)
CHECK_XR(xrGetSystem(inst, &system_info, &id));
assert(id != XR_NULL_SYSTEM_ID);
if (inst.has_extension(XR_EXT_HAND_TRACKING_EXTENSION_NAME))
hand_tracking_supported_ = hand_tracking_properties().supportsHandTracking;
body_tracker = xr::body_tracker_supported(inst, *this);
face_tracker = xr::face_tracker_supported(inst, *this);
}
XrGraphicsRequirementsVulkan2KHR xr::system::graphics_requirements() const
@@ -203,15 +195,16 @@ XrSystemBodyTrackingPropertiesBD xr::system::bd_body_tracking_properties() const
return body_tracking_prop;
}
xr::passthrough_type xr::system::passthrough_supported() const
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))
return passthrough_type::color;
if (inst->has_extension(XR_HTC_PASSTHROUGH_EXTENSION_NAME))
const std::vector<std::string> & xr_extensions = application::get_xr_extensions();
if (utils::contains(xr_extensions, XR_HTC_PASSTHROUGH_EXTENSION_NAME))
return passthrough_type::color;
if (inst->has_extension(XR_FB_PASSTHROUGH_EXTENSION_NAME))
if (utils::contains(xr_extensions, XR_FB_PASSTHROUGH_EXTENSION_NAME))
{
XrSystemPassthroughProperties2FB passthrough_prop2{
.type = XR_TYPE_SYSTEM_PASSTHROUGH_PROPERTIES2_FB,
@@ -231,7 +224,7 @@ xr::passthrough_type xr::system::passthrough_supported() const
if (passthrough_prop.supportsPassthrough)
{
if (!(passthrough_prop2.capabilities & XR_PASSTHROUGH_CAPABILITY_BIT_FB))
return passthrough_type::none;
return passthrough_type::no_passthrough;
if (passthrough_prop2.capabilities & XR_PASSTHROUGH_CAPABILITY_COLOR_BIT_FB)
return passthrough_type::color;
@@ -240,21 +233,7 @@ xr::passthrough_type xr::system::passthrough_supported() const
}
}
return passthrough_type::none;
}
xr::face_tracker_type xr::system::face_tracker_supported() const
{
return face_tracker;
}
xr::body_tracker_type xr::system::body_tracker_supported() const
{
return body_tracker;
}
bool xr::system::hand_tracking_supported() const
{
return hand_tracking_supported_;
return passthrough_type::no_passthrough;
}
vk::raii::PhysicalDevice xr::system::physical_device(vk::raii::Instance & vulkan) const
+7 -31
View File
@@ -32,39 +32,19 @@ namespace xr
{
class instance;
enum class passthrough_type
{
none,
bw,
color
};
enum class body_tracker_type
{
none,
fb,
htc,
pico,
};
enum class face_tracker_type
{
none,
fb,
htc,
pico,
};
class system
{
instance * inst = nullptr;
XrSystemId id = XR_NULL_SYSTEM_ID;
bool hand_tracking_supported_ = false;
passthrough_type passthrough;
body_tracker_type body_tracker;
face_tracker_type face_tracker;
public:
enum class passthrough_type
{
no_passthrough,
bw,
color
};
system() = default;
system(const system &) = default;
system & operator=(const system &) = default;
@@ -87,11 +67,7 @@ public:
XrSystemFacialTrackingPropertiesHTC htc_face_tracking_properties() const;
XrSystemBodyTrackingPropertiesFB fb_body_tracking_properties() const;
XrSystemBodyTrackingPropertiesBD bd_body_tracking_properties() const;
bool hand_tracking_supported() const;
passthrough_type passthrough_supported() const;
face_tracker_type face_tracker_supported() const;
body_tracker_type body_tracker_supported() const;
XrGraphicsRequirementsVulkan2KHR graphics_requirements() const;
vk::raii::PhysicalDevice physical_device(vk::raii::Instance & vulkan) const;
+10 -21
View File
@@ -1,6 +1,7 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
*
* 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,23 +19,11 @@
#pragma once
#include "fb_face_tracker2.h"
#include "htc_face_tracker.h"
#include "pico_face_tracker.h"
#include "xr/system.h"
#include <variant>
namespace xr
{
class instance;
class session;
using face_tracker = std::variant<std::monostate, xr::fb_face_tracker2, xr::htc_face_tracker, xr::pico_face_tracker>;
face_tracker make_face_tracker(xr::instance &, xr::system &, xr::session &);
face_tracker_type face_tracker_supported(xr::instance &, xr::system &);
} // namespace xr
#include "actionset.h"
#include "error.h"
#include "instance.h"
#include "session.h"
#include "swapchain.h"
#include "system.h"
#include "xr/check.h"
#include "xr/to_string.h"
+4
View File
@@ -0,0 +1,4 @@
function(auto_option name description default)
set(${name} ${default} CACHE STRING "${description}")
set_property(CACHE ${name} PROPERTY STRINGS AUTO ON OFF)
endfunction()
+9 -54
View File
@@ -1,8 +1,5 @@
set(_THIS_MODULE_BASE_DIR "${CMAKE_CURRENT_LIST_DIR}")
find_program(HEXDUMP hexdump REQUIRED)
function(compile_glsl_aux shader_stage shader_name glsl_filename output target_env)
function(compile_glsl_aux shader_stage shader_name glsl_filename output)
string(TOUPPER ${shader_stage} shader_stage_upper)
cmake_path(REPLACE_FILENAME output "${shader_name}.spv" OUTPUT_VARIABLE SPV_FILE)
@@ -13,28 +10,10 @@ function(compile_glsl_aux shader_stage shader_name glsl_filename output target_e
}},
")
add_custom_command(
OUTPUT "${SPV_FILE}-nopt"
COMMAND Vulkan::glslangValidator -V --target-env ${target_env} -S ${shader_stage} -D${shader_stage_upper}_SHADER ${in_file} -o "${SPV_FILE}-nopt"
DEPENDS "${glsl_filename}"
VERBATIM
)
if (WIVRN_OPTIMIZE_SHADERS)
add_custom_command(
OUTPUT "${SPV_FILE}-opt"
COMMAND spirv-opt --target-env=${target_env} -O "${SPV_FILE}-nopt" -o "${SPV_FILE}-opt"
DEPENDS "${SPV_FILE}-nopt"
VERBATIM
)
set(_spv "${SPV_FILE}-opt")
else()
set(_spv "${SPV_FILE}-nopt")
endif()
set(_format "/4 \"0x%02X, \"")
add_custom_command(
OUTPUT "${SPV_FILE}"
COMMAND "${HEXDUMP}" -ve "${_format}" ${_spv} > "${SPV_FILE}"
DEPENDS "${_spv}"
COMMAND Vulkan::glslangValidator -V -S ${shader_stage} -D${shader_stage_upper}_SHADER ${in_file} -x -o "${SPV_FILE}"
DEPENDS "${glsl_filename}"
VERBATIM
)
@@ -51,57 +30,33 @@ endfunction()
function(wivrn_compile_glsl target)
set(options)
set(oneValueArgs TARGET_ENV NAMESPACE)
set(multiValueArgs SHADERS)
cmake_parse_arguments(_args "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT _args_TARGET_ENV)
set(_args_TARGET_ENV vulkan1.0)
endif()
if (_args_NAMESPACE)
set(_namespace_begin "namespace ${_args_NAMESPACE} {")
set(_namespace_end "}")
endif()
cmake_path(APPEND OUTPUT "${CMAKE_CURRENT_BINARY_DIR}" "${target}_shaders.cpp")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${target}_shaders.h" "\
#include <cstdint>
#include <map>
#include <vector>
#include <string>
${_namespace_begin}
extern const std::map<std::string, std::vector<uint32_t>> shaders;
${_namespace_end}")
file(WRITE ${OUTPUT} "\
#include <cstdint>
#include <map>
#include <vector>
#include <string>
${_namespace_begin}
extern const std::map<std::string, std::vector<uint32_t>> shaders = {
")
foreach(in_file IN LISTS _args_SHADERS)
if (in_file MATCHES "\.\(vert|frag|tesc|tese|geom|comp\)\(\.glsl\)?$")
foreach(in_file IN LISTS ARGN)
if (in_file MATCHES "\.\(vert|frag|tesc|tese|geom|comp\)\.glsl$")
set(shader_stage ${CMAKE_MATCH_1})
cmake_path(GET in_file STEM LAST_ONLY shader_name)
compile_glsl_aux(${shader_stage} ${shader_name} ${in_file} ${OUTPUT} ${_args_TARGET_ENV})
compile_glsl_aux(${shader_stage} ${shader_name} ${in_file} ${OUTPUT})
else()
cmake_path(GET in_file STEM LAST_ONLY shader_name)
compile_glsl_aux(vert ${shader_name}.vert ${in_file} ${OUTPUT} ${_args_TARGET_ENV})
compile_glsl_aux(frag ${shader_name}.frag ${in_file} ${OUTPUT} ${_args_TARGET_ENV})
compile_glsl_aux(vert ${shader_name}.vert ${in_file} ${OUTPUT})
compile_glsl_aux(frag ${shader_name}.frag ${in_file} ${OUTPUT})
endif()
endforeach()
file(APPEND ${OUTPUT} "};${_namespace_end}")
file(APPEND ${OUTPUT} "};")
target_sources(${target} PRIVATE ${OUTPUT})
target_include_directories(${target} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
endfunction()
+1
View File
@@ -13,6 +13,7 @@ execute_process(
if (GIT_DESC)
string(STRIP ${GIT_DESC} GIT_DESC)
string(REGEX REPLACE "^v([0-9])" "\\1" GIT_DESC ${GIT_DESC})
message(STATUS "Setting version to ${GIT_DESC} from git")
else()
set(GIT_DESC v${CMAKE_PROJECT_VERSION})
+2 -1
View File
@@ -1,4 +1,4 @@
if (WIVRN_USE_SYSTEM_BOOST)
if (BOOST_FOUND)
add_library(Boost::pfr ALIAS Boost::headers)
elseif (WIVRN_BUILD_CLIENT)
FetchContent_MakeAvailable(boost)
@@ -7,6 +7,7 @@ else()
endif()
if (GIT_DESC)
string(REGEX REPLACE "^v([0-9])" "\\1" GIT_DESC ${GIT_DESC})
configure_file(version.cpp.in version.cpp)
else ()
add_custom_target(wivrn-version ALL
+6 -5
View File
@@ -50,19 +50,20 @@ std::filesystem::path home()
std::pair<std::string, std::optional<std::filesystem::path>> find_steam()
{
auto h = home();
// Flatpak Steam
if (std::filesystem::exists(h / ".var/app/com.valvesoftware.Steam/.steam/steam"))
return {"flatpak run com.valvesoftware.Steam", h / ".var/app/com.valvesoftware.Steam/.steam/steam"};
// system Steam
if (std::filesystem::exists(xdg_data_home() / "Steam"))
return {"steam", xdg_data_home() / "Steam"};
auto h = home();
// system Steam (accessed from flatpak)
if (std::filesystem::exists(h / ".local/share/Steam"))
return {"steam", h / ".local/share/Steam"};
// Flatpak Steam
if (std::filesystem::exists(h / ".var/app/com.valvesoftware.Steam/.steam/steam"))
return {"flatpak run com.valvesoftware.Steam", h / ".var/app/com.valvesoftware.Steam/.steam/steam"};
return {};
}
+406 -370
View File
@@ -20,10 +20,10 @@
#include <archive.h>
#include <archive_entry.h>
#include <bit>
#include <cairo.h>
#include <fstream>
#include <librsvg/rsvg.h>
#include <limits>
#include <png.h>
#include <span>
#include <unordered_map>
@@ -46,7 +46,7 @@ std::vector<std::byte> load_file(const std::filesystem::path & filename)
template <typename T>
requires std::is_integral_v<T>
T read(std::span<const std::byte> & buffer)
T read(std::span<std::byte> & buffer)
{
if (sizeof(T) > buffer.size())
throw std::runtime_error{"File truncated"};
@@ -65,22 +65,27 @@ T read(std::span<const std::byte> & buffer)
template <typename T>
requires std::is_integral_v<T>
std::span<const T> read(std::span<const std::byte> & buffer, size_t count)
std::span<T> read(std::span<std::byte> & buffer, size_t count)
{
if (count * sizeof(T) > buffer.size())
throw std::runtime_error{"File truncated"};
std::span<const T> value{reinterpret_cast<const T *>(buffer.data()), count};
std::span<T> value{reinterpret_cast<T *>(buffer.data()), count};
buffer = buffer.subspan(count * sizeof(T));
return value;
}
std::vector<wivrn::icon> try_load_svg(const std::vector<std::byte> & data, int size)
std::vector<std::byte> load_svg(const std::filesystem::path & filename, int size)
{
// TODO check if aspect ratio needs to be handled, dpi
struct deleter
{
void operator()(GFile * ptr)
{
g_object_unref(ptr);
}
void operator()(RsvgHandle * ptr)
{
g_object_unref(ptr);
@@ -97,15 +102,15 @@ std::vector<wivrn::icon> try_load_svg(const std::vector<std::byte> & data, int s
}
};
using GFile_ptr = std::unique_ptr<GFile, deleter>;
using RsvgHandle_ptr = std::unique_ptr<RsvgHandle, deleter>;
using cairo_surface_t_ptr = std::unique_ptr<cairo_surface_t, deleter>;
using cairo_t_ptr = std::unique_ptr<cairo_t, deleter>;
GError * error{};
GFile_ptr file{g_file_new_for_path(filename.c_str())};
RsvgHandle_ptr handle{rsvg_handle_new_from_data((guint8 *)data.data(), data.size(), &error)};
if (!handle)
throw std::runtime_error{std::string{"Could not open: "} + error->message};
RsvgHandle_ptr handle{rsvg_handle_new_from_gfile_sync(file.get(), RSVG_HANDLE_FLAGS_NONE, nullptr, &error)};
// Create a Cairo image surface and a rendering context for it
cairo_surface_t_ptr surface{cairo_image_surface_create(CAIRO_FORMAT_ARGB32, size, size)};
@@ -140,48 +145,59 @@ std::vector<wivrn::icon> try_load_svg(const std::vector<std::byte> & data, int s
if (auto status = cairo_surface_write_to_png_stream(surface.get(), cb, &png); status != CAIRO_STATUS_SUCCESS)
throw std::runtime_error{std::string{"Could not write output: "} + cairo_status_to_string(status)};
return {{size, size, 32, std::move(png)}};
return png;
}
std::vector<wivrn::icon> try_load_ico(const std::vector<std::byte> & ico)
// See https://gitlab.gnome.org/GNOME/gimp/-/tree/master/plug-ins/file-ico?ref_type=heads
struct ico_file_entry
{
int width; // Width of icon in pixels
int height; // Height of icon in pixels
int bpp; // 1, 4, 8, 16, 24 or 32 bits per pixel
std::span<std::byte> data;
};
constexpr int rowstride(int width, int bpp)
{
int words_per_line = (width * bpp + 31) / 32;
return words_per_line * 4;
}
static_assert(rowstride(1, 1) == 4);
static_assert(rowstride(8, 1) == 4);
static_assert(rowstride(16, 1) == 4);
static_assert(rowstride(32, 1) == 4);
static_assert(rowstride(33, 1) == 8);
static_assert(rowstride(1, 4) == 4);
static_assert(rowstride(8, 4) == 4);
static_assert(rowstride(16, 4) == 8);
static_assert(rowstride(32, 4) == 16);
static_assert(rowstride(33, 4) == 20);
static_assert(rowstride(1, 8) == 4);
static_assert(rowstride(8, 8) == 8);
static_assert(rowstride(16, 8) == 16);
static_assert(rowstride(32, 8) == 32);
static_assert(rowstride(33, 8) == 36);
static_assert(rowstride(1, 24) == 4);
static_assert(rowstride(8, 24) == 24);
static_assert(rowstride(16, 24) == 48);
static_assert(rowstride(32, 24) == 96);
static_assert(rowstride(33, 24) == 100);
static_assert(rowstride(1, 32) == 4);
static_assert(rowstride(8, 32) == 32);
static_assert(rowstride(16, 32) == 64);
static_assert(rowstride(32, 32) == 128);
static_assert(rowstride(33, 32) == 132);
std::vector<std::byte> load_ico(const std::filesystem::path & filename, int size, int index = -1)
{
const uint32_t ICO_PNG_MAGIC = 0x474e5089;
// See https://gitlab.gnome.org/GNOME/gimp/-/tree/master/plug-ins/file-ico?ref_type=heads
auto rowstride = [](int width, int bpp) {
int words_per_line = (width * bpp + 31) / 32;
return words_per_line * 4;
};
static_assert(rowstride(1, 1) == 4);
static_assert(rowstride(8, 1) == 4);
static_assert(rowstride(16, 1) == 4);
static_assert(rowstride(32, 1) == 4);
static_assert(rowstride(33, 1) == 8);
static_assert(rowstride(1, 4) == 4);
static_assert(rowstride(8, 4) == 4);
static_assert(rowstride(16, 4) == 8);
static_assert(rowstride(32, 4) == 16);
static_assert(rowstride(33, 4) == 20);
static_assert(rowstride(1, 8) == 4);
static_assert(rowstride(8, 8) == 8);
static_assert(rowstride(16, 8) == 16);
static_assert(rowstride(32, 8) == 32);
static_assert(rowstride(33, 8) == 36);
static_assert(rowstride(1, 24) == 4);
static_assert(rowstride(8, 24) == 24);
static_assert(rowstride(16, 24) == 48);
static_assert(rowstride(32, 24) == 96);
static_assert(rowstride(33, 24) == 100);
static_assert(rowstride(1, 32) == 4);
static_assert(rowstride(8, 32) == 32);
static_assert(rowstride(16, 32) == 64);
static_assert(rowstride(32, 32) == 128);
static_assert(rowstride(33, 32) == 132);
auto ico = load_file(filename);
std::span header{ico};
@@ -190,303 +206,358 @@ std::vector<wivrn::icon> try_load_ico(const std::vector<std::byte> & ico)
auto icon_count = read<uint16_t>(header);
if (reserved != 0 or resource_type != 1)
throw std::runtime_error{"Cannot read icon"};
throw std::runtime_error{"Cannot read icon: " + filename.native()};
std::vector<wivrn::icon> icons;
std::vector<ico_file_entry> entries;
int max_bpp = 0;
for (int i = 0; i < icon_count; i++)
{
auto width = read<uint8_t>(header);
auto height = read<uint8_t>(header);
ico_file_entry entry;
entry.width = read<uint8_t>(header);
entry.height = read<uint8_t>(header);
auto num_colors = read<uint8_t>(header);
auto reserved = read<uint8_t>(header); // reserved
auto planes = read<uint16_t>(header);
auto bpp = read<uint16_t>(header);
entry.bpp = read<uint16_t>(header);
auto size = read<uint32_t>(header);
auto offset = read<uint32_t>(header);
if (offset + size > ico.size())
throw std::runtime_error{"Cannot read icon"};
throw std::runtime_error{"Cannot read icon: " + filename.native()};
auto data = std::span{ico}.subspan(offset, size);
entry.data = std::span{ico}.subspan(offset, size);
if (entry.width == 0)
entry.width = 256;
if (entry.height == 0)
entry.height = 256;
if (reserved != 0)
throw std::runtime_error{"Cannot read icon"};
throw std::runtime_error{"Cannot read icon: " + filename.native()};
if (planes != 0 and planes != 1)
throw std::runtime_error{"Cannot read icon"};
throw std::runtime_error{"Cannot read icon: " + filename.native()};
auto magic = read<uint32_t>(data);
entries.push_back(entry);
if (magic == ICO_PNG_MAGIC)
{
// PNG file
std::vector<std::byte> png_data;
// The PNG magic has already been consumed, put it back
png_data.insert(png_data.end(), data.begin() - 4, data.end());
// Check if the PNG is valid
std::vector<uint8_t> pixels;
png_image png_ref{
.version = PNG_IMAGE_VERSION,
.format = PNG_FORMAT_BGRA,
};
if (not png_image_begin_read_from_memory(&png_ref, png_data.data(), png_data.size()))
continue;
// throw std::runtime_error{"Cannot read icon: " + filename.native()};
pixels.resize(PNG_IMAGE_SIZE(png_ref));
if (!png_image_finish_read(&png_ref, nullptr, pixels.data(), 0, nullptr))
{
png_image_free(&png_ref);
continue;
// throw std::runtime_error{"Cannot read icon: " + filename.native()};
}
// TODO: get bit depth from PNG instead of trusting the ico header
icons.emplace_back(png_ref.width, png_ref.height, bpp, std::move(png_data));
png_image_free(&png_ref);
}
else if (magic == 40)
{
auto width = read<uint32_t>(data); // Width of image in pixels
auto height = read<uint32_t>(data); // Height of image in pixels
auto planes = read<uint16_t>(data); // Must be 1
auto bpp = read<uint16_t>(data); // 1, 4, 8, 16, 24, 32
auto compression = read<uint32_t>(data); // Must be 0 for icons
auto image_size = read<uint32_t>(data); // Size of image (without this header)
auto x_res = read<uint32_t>(data);
auto y_res = read<uint32_t>(data);
auto used_colors = read<uint32_t>(data);
auto important_colors = read<uint32_t>(data);
if (planes != 1 or compression != 0)
return {};
if (bpp != 1 and
bpp != 4 and
bpp != 8 and
bpp != 16 and
bpp != 24 and
bpp != 32)
return {};
auto w = width;
auto h = height / 2;
std::span<const uint8_t> palette; // BGRX
if (bpp <= 16)
{
// Load the palette
if (used_colors == 0)
used_colors = 1 << bpp;
palette = read<uint8_t>(data, used_colors * 4);
}
size_t xor_stride = rowstride(w, bpp);
size_t and_stride = rowstride(w, 1);
size_t dst_stride = 4 * w;
std::span xor_map = read<uint8_t>(data, xor_stride * h);
std::span and_map = read<uint8_t>(data, and_stride * h);
std::vector<uint8_t> dest_buffer;
dest_buffer.resize(h * dst_stride);
switch (bpp)
{
case 1:
for (int y = 0; y < h; y++)
{
const uint8_t * src_xor_row = xor_map.data() + xor_stride * y;
const uint8_t * src_and_row = and_map.data() + and_stride * y;
uint8_t * dst_row = dest_buffer.data() + dst_stride * (h - 1 - y);
for (int x = 0, i = 0; x < w; x++)
{
int colour = (src_xor_row[x / 8] >> (7 - (x % 8))) & 0x1;
if (colour >= used_colors)
return {};
uint8_t b = palette[4 * colour + 0]; // Blue
uint8_t g = palette[4 * colour + 1]; // Green
uint8_t r = palette[4 * colour + 2]; // Red
// Get alpha from AND mask (0: opaque => 0xff, 1: transparent => 0)
uint8_t a = src_and_row[x / 8] & (1 << (7 - x % 8)) ? 0 : 0xff;
*dst_row++ = b;
*dst_row++ = g;
*dst_row++ = r;
*dst_row++ = a;
}
}
break;
case 4:
for (int y = 0; y < h; y++)
{
const uint8_t * src_xor_row = xor_map.data() + xor_stride * y;
const uint8_t * src_and_row = and_map.data() + and_stride * y;
uint8_t * dst_row = dest_buffer.data() + dst_stride * (h - 1 - y);
for (int x = 0, i = 0; x < w; x++)
{
int colour = (src_xor_row[x / 2] >> (4 - 4 * (x % 2))) & 0xf;
if (colour >= used_colors)
return {};
uint8_t b = palette[4 * colour + 0]; // Blue
uint8_t g = palette[4 * colour + 1]; // Green
uint8_t r = palette[4 * colour + 2]; // Red
// Get alpha from AND mask (0: opaque => 0xff, 1: transparent => 0)
uint8_t a = src_and_row[x / 8] & (1 << (7 - x % 8)) ? 0 : 0xff;
*dst_row++ = b;
*dst_row++ = g;
*dst_row++ = r;
*dst_row++ = a;
}
}
break;
case 8:
for (int y = 0; y < h; y++)
{
const uint8_t * src_xor_row = xor_map.data() + xor_stride * y;
const uint8_t * src_and_row = and_map.data() + and_stride * y;
uint8_t * dst_row = dest_buffer.data() + dst_stride * (h - 1 - y);
for (int x = 0, i = 0; x < w; x++)
{
int colour = *src_xor_row++;
if (colour >= used_colors)
return {};
uint8_t b = palette[4 * colour + 0]; // Blue
uint8_t g = palette[4 * colour + 1]; // Green
uint8_t r = palette[4 * colour + 2]; // Red
// Get alpha from AND mask (0: opaque => 0xff, 1: transparent => 0)
uint8_t a = src_and_row[x / 8] & (1 << (7 - x % 8)) ? 0 : 0xff;
*dst_row++ = b;
*dst_row++ = g;
*dst_row++ = r;
*dst_row++ = a;
}
}
break;
case 16:
for (int y = 0; y < h; y++)
{
const uint8_t * src_xor_row = xor_map.data() + xor_stride * y;
const uint8_t * src_and_row = and_map.data() + and_stride * y;
uint8_t * dst_row = dest_buffer.data() + dst_stride * (h - 1 - y);
for (int x = 0, i = 0; x < w; x++)
{
int colour = (src_xor_row[1] << 8) | src_xor_row[0];
src_xor_row += 2;
if (colour >= used_colors)
return {};
uint8_t b = palette[4 * colour + 0]; // Blue
uint8_t g = palette[4 * colour + 1]; // Green
uint8_t r = palette[4 * colour + 2]; // Red
// Get alpha from AND mask (0: opaque => 0xff, 1: transparent => 0)
uint8_t a = src_and_row[x / 8] & (1 << (7 - x % 8)) ? 0 : 0xff;
*dst_row++ = b;
*dst_row++ = g;
*dst_row++ = r;
*dst_row++ = a;
}
}
break;
case 24:
for (int y = 0; y < h; y++)
{
const uint8_t * src_xor_row = xor_map.data() + xor_stride * y;
const uint8_t * src_and_row = and_map.data() + and_stride * y;
uint8_t * dst_row = dest_buffer.data() + dst_stride * (h - 1 - y);
for (int x = 0, i = 0; x < w; x++)
{
uint8_t b = *src_xor_row++; // Blue
uint8_t g = *src_xor_row++; // Green
uint8_t r = *src_xor_row++; // Red
// Get alpha from AND mask (0: opaque => 0xff, 1: transparent => 0)
uint8_t a = src_and_row[x / 8] & (1 << (7 - x % 8)) ? 0 : 0xff;
*dst_row++ = b;
*dst_row++ = g;
*dst_row++ = r;
*dst_row++ = a;
}
}
break;
case 32:
for (int y = 0; y < h; y++)
{
const uint8_t * src_xor_row = xor_map.data() + xor_stride * y;
uint8_t * dst_row = dest_buffer.data() + dst_stride * (h - 1 - y);
memcpy(dst_row, src_xor_row, dst_stride);
}
break;
}
png_image png{
.version = PNG_IMAGE_VERSION,
.width = w,
.height = h,
.format = PNG_FORMAT_BGRA,
};
std::vector<std::byte> png_data{65536};
png_alloc_size_t png_size = png_data.size();
png_image_write_to_memory(&png, png_data.data(), &png_size, false /* convert_to_8_bit*/, dest_buffer.data(), w * 4, nullptr);
if (png_size > png_data.size())
{
png_data.resize(png_size);
png_image_write_to_memory(&png, png_data.data(), &png_size, false /* convert_to_8_bit*/, dest_buffer.data(), w * 4, nullptr);
}
else
png_data.resize(png_size);
icons.emplace_back(w, h, bpp, std::move(png_data));
}
max_bpp = std::max(max_bpp, entry.bpp);
}
return icons;
const ico_file_entry * best_entry = index >= 0 ? &entries.at(index) : [&]() {
const ico_file_entry * best_entry = nullptr;
// Look for the smallest multiple of the requested size
int criterion = std::numeric_limits<int>::max();
for (const auto & entry: entries)
{
if (entry.bpp != max_bpp)
continue;
if (entry.width % size != 0 or entry.height % size != 0)
continue;
if (std::min(entry.width, entry.height) / size < criterion)
{
criterion = std::min(entry.width, entry.height);
best_entry = &entry;
}
}
if (best_entry)
return best_entry;
// No multiple found: pick the largest icon
criterion = 0;
for (const auto & entry: entries)
{
if (entry.bpp != max_bpp)
continue;
if (entry.width * entry.height > criterion)
{
criterion = entry.width * entry.height;
best_entry = &entry;
}
}
return best_entry;
}();
if (not best_entry)
return {};
auto data = best_entry->data;
auto magic = read<uint32_t>(data);
if (magic == ICO_PNG_MAGIC)
{
// PNG file
std::vector<std::byte> png_data;
// The PNG magic has already been consumed, put it back
png_data.insert(png_data.end(), data.begin() - 4, data.end());
// Check if the PNG is valid
std::vector<uint8_t> pixels;
png_image png_ref{
.version = PNG_IMAGE_VERSION,
.format = PNG_FORMAT_BGRA,
};
if (not png_image_begin_read_from_memory(&png_ref, png_data.data(), png_data.size()))
throw std::runtime_error{"Cannot read icon: " + filename.native()};
pixels.resize(PNG_IMAGE_SIZE(png_ref));
if (!png_image_finish_read(&png_ref, nullptr, pixels.data(), 0, nullptr))
{
png_image_free(&png_ref);
throw std::runtime_error{"Cannot read icon: " + filename.native()};
}
png_image_free(&png_ref);
return png_data;
}
else if (magic == 40)
{
auto width = read<uint32_t>(data); // Width of image in pixels
auto height = read<uint32_t>(data); // Height of image in pixels
auto planes = read<uint16_t>(data); // Must be 1
auto bpp = read<uint16_t>(data); // 1, 4, 8, 16, 24, 32
auto compression = read<uint32_t>(data); // Must be 0 for icons
auto image_size = read<uint32_t>(data); // Size of image (without this header)
auto x_res = read<uint32_t>(data);
auto y_res = read<uint32_t>(data);
auto used_colors = read<uint32_t>(data);
auto important_colors = read<uint32_t>(data);
if (planes != 1 or compression != 0)
return {};
if (bpp != 1 and
bpp != 4 and
bpp != 8 and
bpp != 16 and
bpp != 24 and
bpp != 32)
return {};
auto w = width;
auto h = height / 2;
std::span<uint8_t> palette; // BGRX
if (bpp <= 16)
{
// Load the palette
if (used_colors == 0)
used_colors = 1 << bpp;
palette = read<uint8_t>(data, used_colors * 4);
}
size_t xor_stride = rowstride(w, bpp);
size_t and_stride = rowstride(w, 1);
size_t dst_stride = 4 * w;
std::span<uint8_t> xor_map = read<uint8_t>(data, xor_stride * h);
std::span<uint8_t> and_map = read<uint8_t>(data, and_stride * h);
std::vector<uint8_t> dest_buffer;
dest_buffer.resize(h * dst_stride);
switch (bpp)
{
case 1:
for (int y = 0; y < h; y++)
{
uint8_t * src_xor_row = xor_map.data() + xor_stride * y;
uint8_t * src_and_row = and_map.data() + and_stride * y;
uint8_t * dst_row = dest_buffer.data() + dst_stride * (h - 1 - y);
for (int x = 0, i = 0; x < w; x++)
{
int colour = (src_xor_row[x / 8] >> (7 - (x % 8))) & 0x1;
if (colour >= used_colors)
return {};
uint8_t b = palette[4 * colour + 0]; // Blue
uint8_t g = palette[4 * colour + 1]; // Green
uint8_t r = palette[4 * colour + 2]; // Red
// Get alpha from AND mask (0: opaque => 0xff, 1: transparent => 0)
uint8_t a = src_and_row[x / 8] & (1 << (7 - x % 8)) ? 0 : 0xff;
*dst_row++ = b;
*dst_row++ = g;
*dst_row++ = r;
*dst_row++ = a;
}
}
break;
case 4:
for (int y = 0; y < h; y++)
{
uint8_t * src_xor_row = xor_map.data() + xor_stride * y;
uint8_t * src_and_row = and_map.data() + and_stride * y;
uint8_t * dst_row = dest_buffer.data() + dst_stride * (h - 1 - y);
for (int x = 0, i = 0; x < w; x++)
{
int colour = (src_xor_row[x / 2] >> (4 - 4 * (x % 2))) & 0xf;
if (colour >= used_colors)
return {};
uint8_t b = palette[4 * colour + 0]; // Blue
uint8_t g = palette[4 * colour + 1]; // Green
uint8_t r = palette[4 * colour + 2]; // Red
// Get alpha from AND mask (0: opaque => 0xff, 1: transparent => 0)
uint8_t a = src_and_row[x / 8] & (1 << (7 - x % 8)) ? 0 : 0xff;
*dst_row++ = b;
*dst_row++ = g;
*dst_row++ = r;
*dst_row++ = a;
}
}
break;
case 8:
for (int y = 0; y < h; y++)
{
uint8_t * src_xor_row = xor_map.data() + xor_stride * y;
uint8_t * src_and_row = and_map.data() + and_stride * y;
uint8_t * dst_row = dest_buffer.data() + dst_stride * (h - 1 - y);
for (int x = 0, i = 0; x < w; x++)
{
int colour = *src_xor_row++;
if (colour >= used_colors)
return {};
uint8_t b = palette[4 * colour + 0]; // Blue
uint8_t g = palette[4 * colour + 1]; // Green
uint8_t r = palette[4 * colour + 2]; // Red
// Get alpha from AND mask (0: opaque => 0xff, 1: transparent => 0)
uint8_t a = src_and_row[x / 8] & (1 << (7 - x % 8)) ? 0 : 0xff;
*dst_row++ = b;
*dst_row++ = g;
*dst_row++ = r;
*dst_row++ = a;
}
}
break;
case 16:
for (int y = 0; y < h; y++)
{
uint8_t * src_xor_row = xor_map.data() + xor_stride * y;
uint8_t * src_and_row = and_map.data() + and_stride * y;
uint8_t * dst_row = dest_buffer.data() + dst_stride * (h - 1 - y);
for (int x = 0, i = 0; x < w; x++)
{
int colour = (src_xor_row[1] << 8) | src_xor_row[0];
src_xor_row += 2;
if (colour >= used_colors)
return {};
uint8_t b = palette[4 * colour + 0]; // Blue
uint8_t g = palette[4 * colour + 1]; // Green
uint8_t r = palette[4 * colour + 2]; // Red
// Get alpha from AND mask (0: opaque => 0xff, 1: transparent => 0)
uint8_t a = src_and_row[x / 8] & (1 << (7 - x % 8)) ? 0 : 0xff;
*dst_row++ = b;
*dst_row++ = g;
*dst_row++ = r;
*dst_row++ = a;
}
}
break;
case 24:
for (int y = 0; y < h; y++)
{
uint8_t * src_xor_row = xor_map.data() + xor_stride * y;
uint8_t * src_and_row = and_map.data() + and_stride * y;
uint8_t * dst_row = dest_buffer.data() + dst_stride * (h - 1 - y);
for (int x = 0, i = 0; x < w; x++)
{
uint8_t b = *src_xor_row++; // Blue
uint8_t g = *src_xor_row++; // Green
uint8_t r = *src_xor_row++; // Red
// Get alpha from AND mask (0: opaque => 0xff, 1: transparent => 0)
uint8_t a = src_and_row[x / 8] & (1 << (7 - x % 8)) ? 0 : 0xff;
*dst_row++ = b;
*dst_row++ = g;
*dst_row++ = r;
*dst_row++ = a;
}
}
break;
case 32:
for (int y = 0; y < h; y++)
{
uint8_t * src_xor_row = (uint8_t *)xor_map.data() + xor_stride * y;
uint8_t * dst_row = dest_buffer.data() + dst_stride * (h - 1 - y);
memcpy(dst_row, src_xor_row, dst_stride);
}
break;
}
png_image png{
.version = PNG_IMAGE_VERSION,
.width = w,
.height = h,
.format = PNG_FORMAT_BGRA,
};
std::vector<std::byte> png_data{65536};
png_alloc_size_t png_size = png_data.size();
png_image_write_to_memory(&png, png_data.data(), &png_size, false /* convert_to_8_bit*/, dest_buffer.data(), w * 4, nullptr);
if (png_size > png_data.size())
{
png_data.resize(png_size);
png_image_write_to_memory(&png, png_data.data(), &png_size, false /* convert_to_8_bit*/, dest_buffer.data(), w * 4, nullptr);
}
else
png_data.resize(png_size);
return png_data;
}
throw std::runtime_error{"Wrong magic number in " + filename.native()};
}
std::vector<wivrn::icon> try_load_zip(const std::vector<std::byte> & data)
std::vector<std::byte> load_zip(const std::filesystem::path & filename, int size)
{
std::unique_ptr<archive, decltype(&archive_read_free)> zip{archive_read_new(), &archive_read_free};
archive_read_support_filter_all(zip.get());
archive_read_support_format_all(zip.get());
if (auto rc = archive_read_open_memory(zip.get(), data.data(), data.size()); rc != ARCHIVE_OK)
throw std::runtime_error{std::string("Cannot open ZIP: ") + archive_error_string(zip.get())};
if (auto rc = archive_read_open_filename(zip.get(), filename.c_str(), 1'000'000); rc != ARCHIVE_OK)
throw std::runtime_error{"Cannot open " + filename.native() + ": " + archive_error_string(zip.get())};
archive_entry * entry;
std::vector<wivrn::icon> icons;
int width = 0;
int height = 0;
std::vector<std::byte> png;
while (archive_read_next_header(zip.get(), &entry) == ARCHIVE_OK)
{
printf("%s\n", archive_entry_pathname(entry));
std::vector<std::byte> buffer;
buffer.resize(archive_entry_size(entry));
@@ -506,6 +577,10 @@ std::vector<wivrn::icon> try_load_zip(const std::vector<std::byte> & data)
continue;
}
// Keep the largest icon only
if (png_ref.width * png_ref.height < width * height)
continue;
pixels.resize(PNG_IMAGE_SIZE(png_ref));
if (!png_image_finish_read(&png_ref, nullptr, pixels.data(), 0, nullptr))
@@ -514,87 +589,48 @@ std::vector<wivrn::icon> try_load_zip(const std::vector<std::byte> & data)
continue;
}
// PNG read successfully
icons.emplace_back(png_ref.width, png_ref.height, 32, std::move(buffer)); // TODO: check how to get bit depth
// PNG read successfully: keep it until we find a better one
width = png_ref.width;
height = png_ref.height;
png = std::move(buffer);
png_image_free(&png_ref);
}
return icons;
return png;
}
std::vector<wivrn::icon> try_load_png(const std::vector<std::byte> & png_data)
{
std::vector<wivrn::icon> icons;
// Try reading the PNG
std::vector<uint8_t> pixels;
png_image png_ref{
.version = PNG_IMAGE_VERSION,
.format = PNG_FORMAT_BGRA,
};
if (not png_image_begin_read_from_memory(&png_ref, png_data.data(), png_data.size()))
{
png_image_free(&png_ref);
throw std::runtime_error("");
}
pixels.resize(PNG_IMAGE_SIZE(png_ref));
if (!png_image_finish_read(&png_ref, nullptr, pixels.data(), 0, nullptr))
{
png_image_free(&png_ref);
throw std::runtime_error("");
}
// PNG read successfully
icons.emplace_back(png_ref.width, png_ref.height, 32, std::move(png_data)); // TODO: check how to get bit depth
png_image_free(&png_ref);
return icons;
}
std::unordered_map<std::filesystem::path, std::vector<wivrn::icon>> icon_cache;
std::unordered_map<std::filesystem::path, std::vector<std::byte>> icon_cache;
} // namespace
const std::vector<wivrn::icon> & wivrn::load_icon(const std::filesystem::path & filename)
const std::vector<std::byte> & wivrn::load_icon(const std::filesystem::path & filename, int size)
{
auto it = icon_cache.find(filename);
if (it != icon_cache.end() and not it->second.empty())
return it->second;
auto data = load_file(filename);
std::vector<std::byte> icon;
try
if (filename.extension() == ".svg")
{
return icon_cache.emplace(filename, try_load_svg(data, 256)).first->second;
icon = load_svg(filename, size);
}
catch (...)
{}
try
else if (filename.extension() == ".ico")
{
return icon_cache.emplace(filename, try_load_ico(data)).first->second;
// Steam icon (Windows)
icon = load_ico(filename, size);
}
catch (...)
{}
try
else if (filename.extension() == ".zip")
{
return icon_cache.emplace(filename, try_load_zip(data)).first->second;
// Steam icon (Linux)
icon = load_zip(filename, size);
}
catch (...)
{}
try
else
{
return icon_cache.emplace(filename, try_load_png(data)).first->second;
// TODO read arbitrary format / rewrite as png
icon = load_file(filename);
}
catch (...)
{}
throw std::runtime_error{"Cannot load icon: " + filename.native()};
return icon_cache.emplace(filename, std::move(icon)).first->second;
}
+2 -10
View File
@@ -23,13 +23,5 @@
namespace wivrn
{
struct icon
{
int width;
int height;
int bpp;
std::vector<std::byte> png_data;
};
const std::vector<icon> & load_icon(const std::filesystem::path & filename);
} // namespace wivrn
const std::vector<std::byte> & load_icon(const std::filesystem::path & filename, int size);
}
-11
View File
@@ -17,9 +17,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <cctype>
#include <iterator>
namespace wivrn
{
extern const char git_version[];
@@ -27,12 +24,4 @@ namespace wivrn
extern const char git_commit[];
const char git_commit[] = "@GIT_COMMIT@";
const char* display_version()
{
if (std::size(git_version) > 2 and git_version[0] == 'v' and isdigit(git_version[1]))
return git_version + 1;
else
return git_version;
}
}
-2
View File
@@ -4,6 +4,4 @@ namespace wivrn
{
extern const char git_version[];
extern const char git_commit[];
const char * display_version();
} // namespace wivrn
-6
View File
@@ -131,12 +131,6 @@ public:
std::tie(resource, allocation) = traits::create(device, create_info, alloc_info);
vmaSetAllocationName(vk_allocator::instance(), allocation, name.c_str());
if (vk_allocator::instance().has_debug_utils)
device.setDebugUtilsObjectNameEXT(vk::DebugUtilsObjectNameInfoEXT{
.objectType = T::objectType,
.objectHandle = uint64_t(CType(*resource)),
.pObjectName = name.c_str(),
});
}
basic_allocation(const basic_allocation &) = delete;
-84
View File
@@ -1,84 +0,0 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
*
* 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 <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <array>
#include <cstdint>
#include <tuple>
#include <vulkan/vulkan.hpp>
template <typename... Args>
class specialization_constants
{
std::tuple<Args...> values;
std::array<vk::SpecializationMapEntry, sizeof...(Args)> entries;
vk::SpecializationInfo info_;
specialization_constants(specialization_constants &&) = delete;
specialization_constants(const specialization_constants &) = delete;
specialization_constants & operator=(const specialization_constants &) = delete;
specialization_constants & operator=(specialization_constants &&) = delete;
template <uint32_t i = sizeof...(Args) - 1>
void fill_entries()
{
entries[i] = vk::SpecializationMapEntry{
.constantID = i,
.offset = uint32_t(uintptr_t(std::addressof(std::get<i>(values))) - uintptr_t(std::addressof(values))),
.size = sizeof(std::get<i>(values)),
};
if constexpr (i > 0)
fill_entries<i - 1>();
}
public:
specialization_constants(Args &&... args) :
values(std::forward<Args>(args)...),
info_{
.mapEntryCount = uint32_t(entries.size()),
.pMapEntries = entries.data(),
.dataSize = sizeof(values),
.pData = &values,
}
{
fill_entries();
}
operator vk::SpecializationInfo *()
{
return &info_;
}
vk::SpecializationInfo * info()
{
return &info_;
}
template <uint32_t i>
auto & data()
{
return std::get<i>(values);
}
};
template <typename... Args>
specialization_constants<Args...> make_specialization_constants(Args &&... args)
{
return specialization_constants<Args...>(std::forward<Args>(args)...);
}
+1 -2
View File
@@ -20,8 +20,7 @@
#include "vk_allocator.h"
#include "vk/check.h"
vk_allocator::vk_allocator(const VmaAllocatorCreateInfo & info, bool has_debug_utils) :
has_debug_utils(has_debug_utils)
vk_allocator::vk_allocator(const VmaAllocatorCreateInfo & info)
{
CHECK_VK(vmaCreateAllocator(&info, &handle));
}
+1 -2
View File
@@ -27,8 +27,7 @@ class vk_allocator : public singleton<vk_allocator>
VmaAllocator handle = nullptr;
public:
const bool has_debug_utils;
vk_allocator(const VmaAllocatorCreateInfo &, bool has_debug_utils);
vk_allocator(const VmaAllocatorCreateInfo &);
~vk_allocator();
operator VmaAllocator()
-1
View File
@@ -30,7 +30,6 @@
#cmakedefine01 WIVRN_USE_PULSEAUDIO
#cmakedefine01 WIVRN_FEATURE_DEBUG_GUI
#cmakedefine01 WIVRN_FEATURE_RENDERDOC
#cmakedefine01 WIVRN_FEATURE_STEAMVR_LIGHTHOUSE
#cmakedefine01 WIVRN_FEATURE_SOLARXR
+6 -3
View File
@@ -69,9 +69,10 @@ wivrn::fd_base::~fd_base()
wivrn::UDP::UDP()
{
fd = socket(AF_INET6, SOCK_DGRAM, 0);
fcntl(fd, F_SETFD, FD_CLOEXEC);
if (fd < 0)
throw std::system_error{errno, std::generic_category()};
fcntl(fd, F_SETFD, FD_CLOEXEC);
}
wivrn::UDP::UDP(int fd)
@@ -176,9 +177,10 @@ wivrn::TCP::TCP(int fd)
wivrn::TCP::TCP(in6_addr address, int port)
{
fd = socket(AF_INET6, SOCK_STREAM, 0);
fcntl(fd, F_SETFD, FD_CLOEXEC);
if (fd < 0)
throw std::system_error{errno, std::generic_category()};
fcntl(fd, F_SETFD, FD_CLOEXEC);
sockaddr_in6 sa;
sa.sin6_family = AF_INET6;
@@ -197,9 +199,10 @@ wivrn::TCP::TCP(in6_addr address, int port)
wivrn::TCP::TCP(in_addr address, int port)
{
fd = socket(AF_INET, SOCK_STREAM, 0);
fcntl(fd, F_SETFD, FD_CLOEXEC);
if (fd < 0)
throw std::system_error{errno, std::generic_category()};
fcntl(fd, F_SETFD, FD_CLOEXEC);
sockaddr_in sa;
sa.sin_family = AF_INET;
+3 -1
View File
@@ -42,7 +42,9 @@ bool apk_installer::isTagged() const
QString apk_installer::currentVersion() const
{
return wivrn::display_version();
if (wivrn::git_version[0] == 'v')
return &wivrn::git_version[1];
return wivrn::git_version;
}
QCoro::Task<> apk_installer::doRefreshLatestVersion()
@@ -69,16 +69,6 @@
<content_rating type="oars-1.1" />
<releases>
<release version="25.9" date="2025-09-17">
<url type="details">https://github.com/WiVRn/WiVRn/releases/tag/v25.9</url>
<description>
<ul>
<li>GPU usage reduction on headset</li>
<li>Disable face and body tracking when not used</li>
<li>Fix black screen on Unreal Engine games</li>
</ul>
</description>
</release>
<release version="25.8" date="2025-08-10">
<url type="details">https://github.com/WiVRn/WiVRn/releases/tag/v25.8</url>
<description>
+14 -2
View File
@@ -129,9 +129,15 @@ Kirigami.ScrollablePage {
},
{
width: 0.5,
height: 1,
height: 0.75,
offset_x: 0.5,
offset_y: 0
},
{
width: 0.5,
height: 0.25,
offset_x: 0.5,
offset_y: 0.75
}
]
},
@@ -148,9 +154,15 @@ Kirigami.ScrollablePage {
},
{
width: 0.5,
height: 1,
height: 0.75,
offset_x: 0,
offset_y: 0
},
{
width: 0.5,
height: 0.25,
offset_x: 0,
offset_y: 0.75
}
]
},
-1
View File
@@ -29,7 +29,6 @@
#include <cassert>
#include <memory>
#include <nlohmann/json.hpp>
#include <unistd.h>
#if WIVRN_CHECK_CAPSYSNICE
#include <sys/capability.h>
+1 -1
View File
@@ -44,7 +44,7 @@ Bit depth of the video. 8-bit is supported by all encoders. 10-bit is supported
## `encoders`
A list of encoders to use.
Default value: one encoder per eye
Default value: 3 encoders in order 1/8th, 3/8th and 4/8th of the image.
WiVRn has the ability to split the video in blocks that are processed independently, this may use resources more effectively and reduce latency.
All the provided encoders are put into groups, groups are executed concurrently and items within a group are processed sequentially.

Some files were not shown because too many files have changed in this diff Show More