Compare commits

...
Author SHA1 Message Date
Vindicus999 fa52f3eae8 Merge remote-tracking branch 'upstream/master' 2025-06-10 11:29:14 +00:00
Sapphire cc8092dd90 Cleanup body tracking 2025-06-10 09:38:49 +02:00
Vindicus999 557a70b28b Merge remote-tracking branch 'upstream/master' 2025-06-09 23:32:12 +00:00
Patrick Nicolas 810d3e9af3 fix newline in ja translation 2025-06-09 19:46:13 +02:00
Vindicus999 b09feca313 Merge remote-tracking branch 'upstream/master' 2025-06-09 17:34:33 +00:00
Patrick Nicolas 09ff9abba8 silence locale error 2025-06-09 19:26:55 +02:00
Patrick Nicolas 24c38e2a02 Move assert in body tracker destructor 2025-06-09 19:26:30 +02:00
mitsuami-megane fedd7917db update ja locale 2025-06-09 18:24:40 +02:00
Patrick Nicolas 18d1619d20 Don't crash on bigger than recommended image 2025-06-09 16:26:56 +02:00
galister b3f3c1c7fc fixed foveation: account for asymmetric v-fov 2025-06-09 16:19:12 +02:00
Vindicus999 340ab47950 Merge remote-tracking branch 'upstream/master' 2025-06-08 17:31:52 +00:00
Sapphire bfd102831e workaround quest runtime bugs 2025-06-08 18:07:23 +02:00
Sapphire 260fdea64a flake: add toktx for android build 2025-06-08 18:07:23 +02:00
Sapphire fd6435e920 flake: avoid unnecessary wrapping 2025-06-08 18:07:23 +02:00
Sapphire 2f9a46ff91 flake: don't strip package 2025-06-08 18:07:23 +02:00
Sapphire 9bb11ae693 Change body tracking tooltip 2025-06-08 18:07:23 +02:00
Sapphire 2fc35832b9 cleanup 2025-06-08 18:07:23 +02:00
Sapphire 7b0cd08060 Disable generic trackers when no poses have been requested on server 2025-06-08 18:07:23 +02:00
Sapphire 7bf24565d9 Set orientation/position tracked bits when valid for FB body tracking
Quest runtime appears to not set these bits even while the orientation
and position are being tracked.
2025-06-08 18:07:23 +02:00
Sapphire 3d468bf8d6 Log when unknown input name is requested for generic trackers 2025-06-08 18:07:23 +02:00
Sapphire ecfda51852 Don't forward shoulder joints 2025-06-08 18:07:23 +02:00
Sapphire 40f02b9404 Add hip tracking toggle for fb body tracking
* Only forward hip joint from FB_body_tracking when lower body is enabled

* Fix body tracking tooltips being too wide
2025-06-08 18:07:23 +02:00
Sapphire 1d6b444ec6 Use separate packet to send generic tracker poses 2025-06-08 18:07:23 +02:00
Sapphire 460fbec06d Quest and Pico body tracking
* Update OpenXR SDK to 1.1.48
2025-06-08 18:07:23 +02:00
Vindicus999 b698a21f13 Merge remote-tracking branch 'upstream/master' 2025-06-07 23:33:27 +00:00
galister e29a08ea2e Revert "bump default eye-tracked scale to 0.4"
This reverts commit f5b6faf327.
2025-06-07 23:22:14 +02:00
galister 0a53801f70 foveation: rework eye convergence; account for asymmetric v-fov 2025-06-07 23:22:14 +02:00
Vindicus999 dc00dace61 Merge remote-tracking branch 'upstream/master' 2025-06-07 11:25:22 +00:00
Patrick Nicolas c55bdc6e89 Drop obsolete foveate shader 2025-06-06 23:15:47 +02:00
galister f5b6faf327 bump default eye-tracked scale to 0.4 2025-06-07 05:58:05 +09:00
galister 695ac2ea04 simulate eye convergence when using eye tracked foveation 2025-06-07 05:55:30 +09:00
galister 7a7fc7aacc The Return of Dynamic Foveation 2025-06-06 20:04:40 +02:00
Patrick Nicolas 64b446c0d8 Rewrite foveation to enforce pixel alignment
foveation now uses integer pixel ratios, and tries to follow the
previous tangent function.
2025-06-06 20:04:40 +02:00
Patrick Nicolas aef8efba8a Drop mipmaps for foveation 2025-06-06 20:04:40 +02:00
Vindicus999 13897152ad Merge remote-tracking branch 'upstream/master' 2025-06-06 17:38:52 +00:00
Patrick Nicolas 5cebea6eda Remove PrivateTmp for wivrn-application
This may break some applications and does not provide useful sandboxing
2025-06-06 13:31:05 +02:00
Vindicus999 b12a96f9ba Merge remote-tracking branch 'upstream/master' 2025-06-06 11:29:05 +00:00
Patrick Nicolas 8233ab052b fix qml registered multiple times warnings 2025-06-06 13:24:22 +02:00
Patrick Nicolas 2f2192f292 Fix qml naming warning 2025-06-06 13:21:21 +02:00
Patrick Nicolas d392d30d1c fix qtdeclarative-6.9.1 crash 2025-06-06 13:15:15 +02:00
59 changed files with 2530 additions and 3711 deletions
+3
View File
@@ -1,12 +1,15 @@
*~
.cxx/
.cache/
.direnv/
.gradle/
_deps/
.idea/
.vscode/
build/
build-*/
**/result
*.so
a.out
+2
View File
@@ -39,12 +39,14 @@
<uses-feature android:name="oculus.software.handtracking" android:required="false" />
<uses-feature android:name="oculus.software.eye_tracking" android:required="false" />
<uses-feature android:name="oculus.software.face_tracking" android:required="false" />
<uses-feature android:name="com.oculus.software.body_tracking" android:required="false" />
<uses-permission android:name="com.magicleap.permission.HAND_TRACKING" />
<uses-permission android:name="com.oculus.permission.HAND_TRACKING" />
<uses-permission android:name="com.oculus.permission.EYE_TRACKING" />
<uses-permission android:name="com.picovr.permission.EYE_TRACKING" />
<uses-permission android:name="com.oculus.permission.FACE_TRACKING" />
<uses-permission android:name="com.picovr.permission.FACE_TRACKING" />
<uses-permission android:name="com.oculus.permission.BODY_TRACKING" />
<!-- Required for XR_FB_render_model -->
<uses-feature android:name="com.oculus.feature.RENDER_MODEL" android:required="false" />
+4 -4
View File
@@ -223,9 +223,9 @@ if (WIVRN_BUILD_CLIENT AND NOT ANDROID)
find_package(Fontconfig REQUIRED)
if (WIVRN_USE_SYSTEM_OPENXR STREQUAL "AUTO")
find_package(OpenXR 1.0.26)
find_package(OpenXR 1.1.48)
elseif(WIVRN_USE_SYSTEM_OPENXR STREQUAL "ON")
find_package(OpenXR 1.0.26 REQUIRED)
find_package(OpenXR 1.1.48 REQUIRED)
endif()
endif()
@@ -264,8 +264,8 @@ FetchContent_Declare(fastgltf EXCLUDE_FROM_ALL SYSTEM URL https://github.co
URL_HASH SHA256=44bcb025dd5cd480236a3bc7a3f8c9a708a801ed773b7859677440d22e0e1e7c)
FetchContent_Declare(glm EXCLUDE_FROM_ALL SYSTEM URL https://github.com/g-truc/glm/archive/refs/tags/1.0.1.tar.gz
URL_HASH SHA256=9f3174561fd26904b23f0db5e560971cbf9b3cbda0b280f04d5c379d03bf234c)
FetchContent_Declare(openxr_loader EXCLUDE_FROM_ALL SYSTEM URL https://github.com/KhronosGroup/OpenXR-SDK/archive/refs/tags/release-1.0.34.tar.gz
URL_HASH SHA256=5fa2fac1b442a31e267ea522799a247e3aff6e6f5a418b1e31c337b8ca835b69)
FetchContent_Declare(openxr_loader EXCLUDE_FROM_ALL SYSTEM URL https://github.com/KhronosGroup/OpenXR-SDK/archive/refs/tags/release-1.1.48.tar.gz
URL_HASH SHA256=c9372992dcdfac643e28796e41d4dbd36c4cdf0388d01fa89245628edae9d411)
FetchContent_Declare(spdlog EXCLUDE_FROM_ALL SYSTEM URL https://github.com/gabime/spdlog/archive/refs/tags/v1.14.1.tar.gz
URL_HASH SHA256=1586508029a7d0670dfcb2d97575dcdc242d3868a259742b69f100801ab4e16b)
FetchContent_Declare(stb EXCLUDE_FROM_ALL SYSTEM URL https://github.com/nothings/stb/archive/013ac3beddff3dbffafd5177e7972067cd2b5083.zip
+29 -1
View File
@@ -31,7 +31,7 @@
#include "wifi_lock.h"
#include "xr/actionset.h"
#include "xr/check.h"
#include "xr/pico_eye_types.h"
#include "xr/meta_body_tracking_fidelity.h"
#include "xr/xr.h"
#include <algorithm>
#include <boost/locale.hpp>
@@ -1041,6 +1041,10 @@ void application::initialize()
opt_extensions.push_back(XR_HTC_PASSTHROUGH_EXTENSION_NAME);
opt_extensions.push_back(XR_HTC_FACIAL_TRACKING_EXTENSION_NAME);
opt_extensions.push_back(XR_FB_FACE_TRACKING2_EXTENSION_NAME);
opt_extensions.push_back(XR_FB_BODY_TRACKING_EXTENSION_NAME);
opt_extensions.push_back(XR_META_BODY_TRACKING_FULL_BODY_EXTENSION_NAME);
opt_extensions.push_back(XR_META_BODY_TRACKING_FIDELITY_EXTENSION_NAME);
opt_extensions.push_back(XR_BD_BODY_TRACKING_EXTENSION_NAME);
opt_extensions.push_back(XR_EXT_PALM_POSE_EXTENSION_NAME);
opt_extensions.push_back(XR_KHR_COMPOSITION_LAYER_DEPTH_EXTENSION_NAME);
opt_extensions.push_back(XR_FB_COMPOSITION_LAYER_DEPTH_TEST_EXTENSION_NAME);
@@ -1141,6 +1145,20 @@ void application::initialize()
htc_face_tracking_lip_supported = htc_face_properties.supportLipFacialTracking;
}
if (utils::contains_all(xr_extensions, std::array{XR_FB_BODY_TRACKING_EXTENSION_NAME, XR_META_BODY_TRACKING_FULL_BODY_EXTENSION_NAME, XR_META_BODY_TRACKING_FIDELITY_EXTENSION_NAME}))
{
XrSystemBodyTrackingPropertiesFB fb_body_properties = xr_system_id.fb_body_tracking_properties();
spdlog::info(" FB body tracking support: {}", (bool)fb_body_properties.supportsBodyTracking);
fb_body_tracking_supported = fb_body_properties.supportsBodyTracking;
}
if (utils::contains(xr_extensions, XR_BD_BODY_TRACKING_EXTENSION_NAME))
{
XrSystemBodyTrackingPropertiesBD bd_body_properties = xr_system_id.bd_body_tracking_properties();
spdlog::info(" PICO body tracking support: {}", (bool)bd_body_properties.supportsBodyTracking);
pico_body_tracking_supported = bd_body_properties.supportsBodyTracking;
}
if (utils::contains(xr_extensions, XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME))
{
spdlog::info(" OpenXR post-processing extension support: true");
@@ -1205,6 +1223,16 @@ void application::initialize()
pico_face_tracker = xr_session.create_pico_face_tracker();
}
if (fb_body_tracking_supported)
{
fb_body_tracker = xr_session.create_fb_body_tracker();
}
if (pico_body_tracking_supported)
{
pico_body_tracker = xr_session.create_pico_body_tracker();
}
vk::CommandPoolCreateInfo cmdpool_create_info;
cmdpool_create_info.queueFamilyIndex = vk_queue_family_index;
cmdpool_create_info.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer;
+26
View File
@@ -21,6 +21,7 @@
#include "configuration.h"
#include "wifi_lock.h"
#include "xr/fb_body_tracker.h"
#include "xr/fb_face_tracker2.h"
#include "xr/hand_tracker.h"
#include "xr/htc_face_tracker.h"
@@ -137,6 +138,11 @@ class application : public singleton<application>
bool pico_face_tracking_supported = false;
xr::pico_face_tracker pico_face_tracker;
bool fb_body_tracking_supported = false;
xr::fb_body_tracker fb_body_tracker;
bool pico_body_tracking_supported = false;
xr::pico_body_tracker pico_body_tracker;
bool eye_gaze_supported = false;
bool openxr_post_processing_supported = false;
@@ -445,6 +451,16 @@ public:
return instance().pico_face_tracking_supported;
}
static bool get_fb_body_tracking_supported()
{
return instance().fb_body_tracking_supported;
}
static bool get_pico_body_tracking_supported()
{
return instance().pico_body_tracking_supported;
}
static bool get_eye_gaze_supported()
{
return instance().eye_gaze_supported;
@@ -485,6 +501,16 @@ public:
return instance().pico_face_tracker;
}
static xr::fb_body_tracker & get_fb_body_tracker()
{
return instance().fb_body_tracker;
}
static xr::pico_body_tracker & get_pico_body_tracker()
{
return instance().pico_body_tracker;
}
static const std::vector<std::string> & get_xr_extensions()
{
return instance().xr_extensions;
+28
View File
@@ -121,6 +121,27 @@ bool configuration::check_feature(feature f) const
return false;
break;
}
break;
case feature::body_tracking:
switch (guess_model())
{
case model::meta_quest_3:
case model::meta_quest_3s:
if (not application::get_fb_body_tracking_supported())
return false;
break;
case model::pico_neo_3:
case model::pico_4:
case model::pico_4s:
case model::pico_4_pro:
case model::pico_4_enterprise:
if (not application::get_pico_body_tracking_supported())
return false;
break;
default:
break;
}
break;
}
}
#ifdef __ANDROID__
@@ -203,6 +224,11 @@ configuration::configuration(xr::system & system)
if (auto val = root["mic_unprocessed_audio"]; val.is_bool())
mic_unprocessed_audio = val.get_bool();
if (auto val = root["fb_lower_body"]; val.is_bool())
fb_lower_body = val.get_bool();
if (auto val = root["fb_hip"]; val.is_bool())
fb_hip = val.get_bool();
if (auto val = root["virtual_keyboard_layout"]; val.is_string())
virtual_keyboard_layout = val.get_string().value();
@@ -325,6 +351,8 @@ void configuration::save()
write_openxr_post_processing(json, openxr_post_processing);
json << ",\"passthrough_enabled\":" << std::boolalpha << passthrough_enabled;
json << ",\"mic_unprocessed_audio\":" << std::boolalpha << mic_unprocessed_audio;
json << ",\"fb_lower_body\":" << std::boolalpha << fb_lower_body;
json << ",\"fb_hip\":" << std::boolalpha << fb_hip;
for (auto & [key, value]: features)
json << "," << key << ":" << std::boolalpha << value;
json << ",\"virtual_keyboard_layout\":" << json_string(virtual_keyboard_layout);
+3
View File
@@ -54,6 +54,9 @@ public:
bool passthrough_enabled = false;
bool mic_unprocessed_audio = false;
bool fb_lower_body = false;
bool fb_hip = true;
// Snapdragon Game Super Resolution
struct sgsr_settings
{
+9
View File
@@ -251,6 +251,15 @@ const char * permission_name(feature f)
return nullptr;
}
__builtin_unreachable();
case feature::body_tracking:
switch (guess_model())
{
case model::meta_quest_3:
case model::meta_quest_3s:
return "com.oculus.permission.BODY_TRACKING";
default:
return nullptr;
}
}
__builtin_unreachable();
}
+1
View File
@@ -50,6 +50,7 @@ enum class feature
hand_tracking,
eye_gaze,
face_tracking,
body_tracking,
};
model guess_model();
+63 -1
View File
@@ -740,6 +740,58 @@ void scenes::lobby::gui_settings()
vibrate_on_hover();
}
{
ImGui::BeginDisabled(not(application::get_fb_body_tracking_supported() or application::get_pico_body_tracking_supported()));
bool enabled = config.check_feature(feature::body_tracking);
if (ImGui::Checkbox(_S("Enable body tracking"), &enabled))
{
config.set_feature(feature::body_tracking, enabled);
config.save();
}
ImGui::EndDisabled();
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
{
if (ImGui::GetItemFlags() & ImGuiItemFlags_Disabled)
{
tooltip(_("This feature is not supported by your headset"));
}
else
{
if (application::get_fb_body_tracking_supported())
tooltip(_("Requires 'Hand and body tracking' to be enabled in the Quest movement tracking settings,\notherwise body data will be guessed from controller and headset positions"));
else if (application::get_pico_body_tracking_supported())
tooltip(_("Uses the Pico Motion Trackers to track body joint positions"));
}
}
vibrate_on_hover();
}
if (application::get_fb_body_tracking_supported())
{
ImGui::BeginDisabled(not config.check_feature(feature::body_tracking));
ImGui::Indent();
if (ImGui::Checkbox(_S("Enable lower body tracking"), &config.fb_lower_body))
{
config.save();
}
vibrate_on_hover();
if (ImGui::IsItemHovered())
tooltip(_("Estimate lower body joint positions using Generative Legs\nRequires 'Hand and body tracking' to be enabled in the Quest movement tracking settings"));
ImGui::BeginDisabled(not config.fb_lower_body);
if (ImGui::Checkbox(_S("Enable hip tracking"), &config.fb_hip))
{
config.save();
}
vibrate_on_hover();
if (ImGui::IsItemHovered())
tooltip(_("Only takes affect with lower body tracking enabled\nMay be desired when using another source of hip tracking"));
ImGui::EndDisabled();
ImGui::Unindent();
ImGui::EndDisabled();
}
ImGui::BeginDisabled(passthrough_supported == xr::system::passthrough_type::no_passthrough);
if (ImGui::Checkbox(_S("Enable video passthrough in lobby"), &config.passthrough_enabled))
{
@@ -1433,6 +1485,16 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
});
}
if (application::get_fb_body_tracking_supported() or application::get_pico_body_tracking_supported())
{
items.push_back({
.f = feature::body_tracking,
.tooltip_enabled = _("Body tracking is enabled"),
.tooltip_disabled = _("Body tracking is disabled"),
.icon_enabled = ICON_FA_PERSON,
});
}
// Get statuses
for (auto & i: items)
{
@@ -1459,7 +1521,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
if (&i != &items.front())
ImGui::SameLine();
auto pos = ImGui::GetCursorPos();
if (ImGui::Button(i.enabled ? i.icon_enabled : i.icon_disabled))
if (ImGui::Button(fmt::format("{}##{}", i.enabled ? i.icon_enabled : i.icon_disabled, i.icon_enabled).c_str()))
{
// button doesn't alter the bool
config.set_feature(i.f, not i.enabled);
+31 -10
View File
@@ -17,6 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "utils/overloaded.h"
#include "xr/fb_body_tracker.h"
#define GLM_FORCE_RADIANS
#include "stream.h"
@@ -224,6 +225,15 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
info.face_tracking = from_headset::face_type::pico;
}
info.num_generic_trackers = 0;
if (config.check_feature(feature::body_tracking))
{
if (application::get_fb_body_tracking_supported())
info.num_generic_trackers = xr::fb_body_tracker::get_whitelisted_joints(config.fb_lower_body, config.fb_hip).size();
else if (application::get_pico_body_tracking_supported())
info.num_generic_trackers = xr::pico_body_tracker::joint_whitelist.size();
}
info.palm_pose = application::space(xr::spaces::palm_left) or application::space(xr::spaces::palm_right);
info.passthrough = self->system.passthrough_supported() != xr::system::passthrough_type::no_passthrough;
info.system_name = std::string(self->system.properties().systemName);
@@ -860,10 +870,16 @@ void scenes::stream::render(const XrFrameState & frame_state)
}
command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 1);
reprojector->set_foveation(foveation);
// Unfoveate the image to the real pose
reprojector->reproject(command_buffer, image_index);
// defoveate the image
auto extents = reprojector->reproject(command_buffer, foveation, image_index);
for (size_t i = 0; i < view_count; ++i)
{
extents[i] = {
.width = std::min(extents[i].width, swapchain.width()),
.height = std::min(extents[i].height, swapchain.height()),
};
}
command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 2);
@@ -908,10 +924,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
.swapchain = swapchain,
.imageRect = {
.offset = {0, 0},
.extent = {
swapchain.width(),
swapchain.height(),
},
.extent = extents[view],
},
.imageArrayIndex = view,
},
@@ -1161,8 +1174,8 @@ void scenes::stream::setup_reprojection_swapchain()
const uint32_t video_width = video_stream_description->width / view_count;
const uint32_t video_height = video_stream_description->height;
uint32_t swapchain_width = video_width / video_stream_description->foveation[0].x.scale;
uint32_t swapchain_height = video_height / video_stream_description->foveation[0].y.scale;
uint32_t swapchain_width = video_stream_description->defoveated_width / view_count;
uint32_t swapchain_height = video_stream_description->defoveated_height;
const configuration::sgsr_settings sgsr = application::get_config().sgsr;
if (sgsr.enabled)
@@ -1189,7 +1202,15 @@ void scenes::stream::setup_reprojection_swapchain()
for (auto & image: swapchain.images())
swapchain_images.push_back(image.image);
reprojector.emplace(device, physical_device, decoder_out_image, 2, swapchain_images, extent, swapchain.format(), *video_stream_description);
reprojector.emplace(
device,
physical_device,
decoder_out_image,
vk::Extent2D{.width = video_width, .height = video_height},
2,
swapchain_images,
extent,
swapchain.format());
}
scene::meta & scenes::stream::get_meta_scene()
+141 -132
View File
@@ -20,30 +20,24 @@
#include "stream_reprojection.h"
#include "application.h"
#include "utils/contains.h"
#include "utils/ranges.h"
#include "vk/allocation.h"
#include "vk/pipeline.h"
#include "vk/shader.h"
#include <array>
#include <glm/glm.hpp>
#include <glm/gtx/quaternion.hpp>
#include <spdlog/spdlog.h>
#include <vk_mem_alloc.h>
#include <vulkan/vulkan_core.h>
#include <vulkan/vulkan_raii.hpp>
namespace
struct stream_reprojection::vertex
{
struct uniform
{
// Foveation parameters
alignas(8) glm::vec2 a;
alignas(8) glm::vec2 b;
alignas(8) glm::vec2 lambda;
alignas(8) glm::vec2 xc;
// output image position
alignas(8) glm::vec2 position;
// input texture coordinates
alignas(8) glm::vec2 uv;
};
} // namespace
const int nb_reprojection_vertices = 128;
struct SgsrSpecializationConstants
{
@@ -52,24 +46,47 @@ struct SgsrSpecializationConstants
float edge_sharpness;
};
void stream_reprojection::ensure_vertices(size_t num_vertices)
{
vk::BufferCreateInfo create_info{
.size = num_vertices * sizeof(vertex) * view_count,
.usage = vk::BufferUsageFlagBits::eVertexBuffer,
.sharingMode = vk::SharingMode::eExclusive,
};
if (create_info.size <= buffer.info().size)
return;
VmaAllocationCreateInfo alloc_info{
.requiredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
};
buffer = buffer_allocation(device, create_info, alloc_info);
vertices_size = num_vertices * sizeof(vertex);
}
stream_reprojection::vertex * stream_reprojection::get_vertices(size_t view)
{
assert(buffer);
return reinterpret_cast<vertex *>(reinterpret_cast<uintptr_t>(buffer.map()) + view * vertices_size);
}
stream_reprojection::stream_reprojection(
vk::raii::Device & device,
vk::raii::PhysicalDevice & physical_device,
vk::Image input_image_,
vk::Extent2D input_extent,
uint32_t view_count,
std::vector<vk::Image> output_images_,
vk::Extent2D extent,
vk::Format format,
const wivrn::to_headset::video_stream_description & description) :
vk::Extent2D output_extent,
vk::Format format) :
view_count(view_count),
device(device),
input_image(input_image_),
input_extent(input_extent),
output_images(std::move(output_images_)),
extent(extent)
output_extent(output_extent)
{
foveation_parameters = description.foveation;
vk::PhysicalDeviceProperties properties = physical_device.getProperties();
vk::SamplerCreateInfo sampler_info{
.magFilter = vk::Filter::eLinear,
.minFilter = vk::Filter::eLinear,
@@ -93,35 +110,12 @@ stream_reprojection::stream_reprojection(
sampler = vk::raii::Sampler(device, sampler_info);
uniform_size = sizeof(uniform) + properties.limits.minUniformBufferOffsetAlignment - 1;
uniform_size = uniform_size - uniform_size % properties.limits.minUniformBufferOffsetAlignment;
vk::BufferCreateInfo create_info{
.size = uniform_size * view_count,
.usage = vk::BufferUsageFlagBits::eUniformBuffer,
.sharingMode = vk::SharingMode::eExclusive,
};
VmaAllocationCreateInfo alloc_info{
.requiredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
};
buffer = buffer_allocation(device, create_info, alloc_info);
// Create VkDescriptorSetLayout
std::array layout_binding{
vk::DescriptorSetLayoutBinding{
.binding = 0,
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
.descriptorCount = 1,
.stageFlags = vk::ShaderStageFlagBits::eFragment,
},
vk::DescriptorSetLayoutBinding{
.binding = 1,
.descriptorType = vk::DescriptorType::eUniformBuffer,
.descriptorCount = 1,
.stageFlags = vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment,
},
vk::DescriptorSetLayoutBinding layout_binding{
.binding = 0,
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
.descriptorCount = 1,
.stageFlags = vk::ShaderStageFlagBits::eFragment,
};
vk::DescriptorSetLayoutCreateInfo layout_info;
@@ -134,10 +128,6 @@ stream_reprojection::stream_reprojection(
.type = vk::DescriptorType::eCombinedImageSampler,
.descriptorCount = (uint32_t)view_count,
},
vk::DescriptorPoolSize{
.type = vk::DescriptorType::eUniformBuffer,
.descriptorCount = (uint32_t)view_count,
},
};
vk::DescriptorPoolCreateInfo pool_info{
@@ -186,13 +176,7 @@ stream_reprojection::stream_reprojection(
.imageLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
};
vk::DescriptorBufferInfo buffer_info{
.buffer = buffer,
.offset = uniform_size * view,
.range = sizeof(uniform),
};
std::array write{
device.updateDescriptorSets(
vk::WriteDescriptorSet{
.dstSet = descriptor_set,
.dstBinding = 0,
@@ -201,17 +185,7 @@ stream_reprojection::stream_reprojection(
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
.pImageInfo = &image_info,
},
vk::WriteDescriptorSet{
.dstSet = descriptor_set,
.dstBinding = 1,
.dstArrayElement = 0,
.descriptorCount = 1,
.descriptorType = vk::DescriptorType::eUniformBuffer,
.pBufferInfo = &buffer_info,
},
};
device.updateDescriptorSets(write, {});
{});
}
// Create renderpass
@@ -248,40 +222,6 @@ stream_reprojection::stream_reprojection(
// Vertex shader
vk::raii::ShaderModule vertex_shader = load_shader(device, "reprojection.vert");
int vertex_specialization_constants[] = {
foveation_parameters[0].x.scale < 1,
foveation_parameters[0].y.scale < 1,
nb_reprojection_vertices,
nb_reprojection_vertices,
};
std::array vertex_specialization_constants_desc{
vk::SpecializationMapEntry{
.constantID = 0,
.offset = 0,
.size = sizeof(int),
},
vk::SpecializationMapEntry{
.constantID = 1,
.offset = sizeof(int),
.size = sizeof(int),
},
vk::SpecializationMapEntry{
.constantID = 2,
.offset = 2 * sizeof(int),
.size = sizeof(int),
},
vk::SpecializationMapEntry{
.constantID = 3,
.offset = 3 * sizeof(int),
.size = sizeof(int),
},
};
vk::SpecializationInfo vertex_specialization_info;
vertex_specialization_info.setMapEntries(vertex_specialization_constants_desc);
vertex_specialization_info.setData<int>(vertex_specialization_constants);
// Fragment shader
std::string fragment_shader_name = "reprojection.frag";
@@ -337,7 +277,6 @@ stream_reprojection::stream_reprojection(
.stage = vk::ShaderStageFlagBits::eVertex,
.module = *vertex_shader,
.pName = "main",
.pSpecializationInfo = &vertex_specialization_info,
},
{
.stage = vk::ShaderStageFlagBits::eFragment,
@@ -346,22 +285,41 @@ stream_reprojection::stream_reprojection(
.pSpecializationInfo = &fragment_specialization_info,
},
},
.VertexBindingDescriptions = {},
.VertexAttributeDescriptions = {},
.VertexBindingDescriptions = {
{
.binding = 0,
.stride = sizeof(vertex),
.inputRate = vk::VertexInputRate::eVertex,
},
},
.VertexAttributeDescriptions = {
{
.location = 0,
.binding = 0,
.format = vk::Format::eR32G32Sfloat,
.offset = offsetof(vertex, position),
},
{
.location = 1,
.binding = 0,
.format = vk::Format::eR32G32Sfloat,
.offset = offsetof(vertex, uv),
},
},
.InputAssemblyState = {{
.topology = vk::PrimitiveTopology::eTriangleList,
.topology = vk::PrimitiveTopology::eTriangleStrip,
}},
.Viewports = {{
.x = 0,
.y = 0,
.width = (float)extent.width,
.height = (float)extent.height,
.width = (float)output_extent.width,
.height = (float)output_extent.height,
.minDepth = 0,
.maxDepth = 1,
}},
.Scissors = {{
.offset = {.x = 0, .y = 0},
.extent = extent,
.extent = output_extent,
}},
.RasterizationState = {{
.polygonMode = vk::PolygonMode::eFill,
@@ -411,8 +369,8 @@ stream_reprojection::stream_reprojection(
vk::FramebufferCreateInfo fb_create_info{
.renderPass = *renderpass,
.width = extent.width,
.height = extent.height,
.width = output_extent.width,
.height = output_extent.height,
.layers = 1,
};
fb_create_info.setAttachments(*output_image_views.back());
@@ -422,28 +380,82 @@ stream_reprojection::stream_reprojection(
}
}
void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer, int destination)
static size_t required_vertices(const wivrn::to_headset::foveation_parameter & p)
{
// strips are constructed like this:
// 0 2 4
// 1 3 5 5*
// there is one such line per value in y
// the last element is repeated to break the line
return (2 * (p.x.size() + 1) + 1) * p.y.size();
}
std::vector<XrExtent2Di> 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");
ensure_vertices(std::max(required_vertices(foveation[0]), required_vertices(foveation[1])));
std::vector<XrExtent2Di> out_extents(view_count, XrExtent2Di{});
for (size_t view = 0; view < view_count; ++view)
{
auto & ubo = *reinterpret_cast<uniform *>(reinterpret_cast<uintptr_t>(buffer.map()) + view * uniform_size);
if (foveation_parameters[view].x.scale < 1)
auto vertices = get_vertices(view);
const auto & [px, py] = foveation[view];
assert(px.size() % 2 == 1);
assert(py.size() % 2 == 1);
const int n_ratio_y = (py.size() - 1) / 2;
const int n_ratio_x = (px.size() - 1) / 2;
for (auto [ix, n_out_x]: utils::enumerate_range(px))
{
ubo.a.x = foveation_parameters[view].x.a;
ubo.b.x = foveation_parameters[view].x.b;
ubo.lambda.x = foveation_parameters[view].x.scale / foveation_parameters[view].x.a;
ubo.xc.x = foveation_parameters[view].x.center;
// number of output pixels per source pixels
const int ratio_x = std::abs(n_ratio_x - int(ix)) + 1;
out_extents[view].width += ratio_x * n_out_x;
}
if (foveation_parameters[view].y.scale < 1)
glm::vec2 in(0), out(0); // pixel coordinates
glm::vec2 in_pixel_size(1. / input_extent.width,
1. / input_extent.height);
glm::vec2 out_pixel_size(2. / output_extent.width,
2. / output_extent.height);
for (auto [iy, n_out_y]: utils::enumerate_range(py))
{
ubo.a.y = foveation_parameters[view].y.a;
ubo.b.y = foveation_parameters[view].y.b;
ubo.lambda.y = foveation_parameters[view].y.scale / foveation_parameters[view].y.a;
ubo.xc.y = foveation_parameters[view].y.center;
// number of output pixels per source pixels
const int ratio_y = std::abs(n_ratio_y - int(iy)) + 1;
out_extents[view].height += ratio_y * n_out_y;
in.x = 0;
out.x = 0;
for (auto [ix, n_out_x]: utils::enumerate_range(px))
{
const int ratio_x = std::abs(n_ratio_x - int(ix)) + 1;
*vertices++ = {
.position = out * out_pixel_size - glm::vec2(1),
.uv = in * in_pixel_size,
};
*vertices++ = {
.position = (out + glm::vec2(0, n_out_y * ratio_y)) * out_pixel_size - glm::vec2(1),
.uv = (in + glm::vec2(0, n_out_y)) * in_pixel_size,
};
in.x += n_out_x;
out.x += n_out_x * ratio_x;
}
*vertices++ = {
.position = out * out_pixel_size - glm::vec2(1),
.uv = in * in_pixel_size,
};
*vertices++ = {
.position = (out + glm::vec2(0, n_out_y * ratio_y)) * out_pixel_size - glm::vec2(1),
.uv = (in + glm::vec2(0, n_out_y)) * in_pixel_size,
};
*vertices++ = {
.position = (out + glm::vec2(0, n_out_y * ratio_y)) * out_pixel_size - glm::vec2(1),
.uv = (in + glm::vec2(0, n_out_y)) * in_pixel_size,
};
in.y += n_out_y;
out.y += n_out_y * ratio_y;
}
}
@@ -473,19 +485,16 @@ void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer, in
.framebuffer = *framebuffers[destination * view_count + view],
.renderArea = {
.offset = {0, 0},
.extent = extent,
.extent = output_extent,
},
};
command_buffer.beginRenderPass(begin_info, vk::SubpassContents::eInline);
command_buffer.bindPipeline(vk::PipelineBindPoint::eGraphics, *pipeline);
command_buffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, *layout, 0, descriptor_sets[view], {});
command_buffer.draw(6 * nb_reprojection_vertices * nb_reprojection_vertices, 1, 0, 0);
command_buffer.bindVertexBuffers(0, vk::Buffer(buffer), vertices_size * view);
command_buffer.draw(required_vertices(foveation[view]), 1, 0, 0);
command_buffer.endRenderPass();
}
}
void stream_reprojection::set_foveation(std::array<wivrn::to_headset::foveation_parameter, 2> foveation)
{
foveation_parameters = foveation;
return out_extents;
}
+14 -11
View File
@@ -26,10 +26,13 @@
class stream_reprojection
{
struct vertex;
const uint32_t view_count;
// Uniform buffer
// Vertex buffer
buffer_allocation buffer;
size_t uniform_size;
size_t vertices_size = 0;
vk::raii::Device & device;
// Graphic pipeline
vk::raii::DescriptorSetLayout descriptor_set_layout = nullptr;
@@ -43,32 +46,32 @@ class stream_reprojection
vk::Image input_image;
std::vector<vk::raii::ImageView> input_image_views;
std::vector<vk::DescriptorSet> descriptor_sets;
vk::Extent2D input_extent;
// Destination images
std::vector<vk::Image> output_images;
std::vector<vk::raii::ImageView> output_image_views;
std::vector<vk::raii::Framebuffer> framebuffers;
vk::Extent2D extent;
vk::Extent2D output_extent;
// Foveation
std::array<wivrn::to_headset::foveation_parameter, 2> foveation_parameters;
void ensure_vertices(size_t num_vertices);
vertex * get_vertices(size_t view);
public:
stream_reprojection(
vk::raii::Device & device,
vk::raii::PhysicalDevice & physical_device,
vk::Image input_image,
vk::Extent2D input_extent,
uint32_t view_count,
std::vector<vk::Image> output_images,
vk::Extent2D extent,
vk::Format format,
const wivrn::to_headset::video_stream_description & description);
vk::Extent2D output_extent,
vk::Format format);
stream_reprojection(const stream_reprojection &) = delete;
void reproject(
std::vector<XrExtent2Di> reproject(
vk::raii::CommandBuffer & command_buffer,
const std::array<wivrn::to_headset::foveation_parameter, 2> & foveation,
int destination);
void set_foveation(std::array<wivrn::to_headset::foveation_parameter, 2> foveation);
};
+59 -1
View File
@@ -232,9 +232,11 @@ void scenes::stream::tracking()
XrTime t0 = instance.now();
XrTime last_hand_sample = t0;
XrTime last_body_sample = t0;
std::vector<from_headset::tracking> tracking;
std::vector<from_headset::tracking> tracking_pool; // pre-allocated objects
std::vector<from_headset::hand_tracking> hands;
std::vector<from_headset::body_tracking> body;
std::vector<XrView> views;
std::vector<from_headset::trackings> merged_tracking;
@@ -258,6 +260,28 @@ void scenes::stream::tracking()
}
}
enum
{
body_none,
body_fb,
body_pico,
} body_tracking = body_none;
if (config.check_feature(feature::body_tracking))
{
if (application::get_fb_body_tracking_supported())
{
body_tracking = body_fb;
// 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
application::get_fb_body_tracker().stop();
application::get_fb_body_tracker().start(config.fb_lower_body, config.fb_hip);
}
else if (application::get_pico_body_tracking_supported())
body_tracking = body_pico;
}
on_interaction_profile_changed({});
while (not exiting)
@@ -266,6 +290,7 @@ void scenes::stream::tracking()
{
tracking.clear();
hands.clear();
body.clear();
XrTime now = instance.now();
if (now < t0)
@@ -335,6 +360,30 @@ void scenes::stream::tracking()
locate_hands(application::get_right_hand(), world_space, t0 + Δt));
}
if (body_tracking != body_none and t0 >= last_body_sample + period and
(Δt == 0 or Δt >= prediction - 2 * period))
{
last_body_sample = t0;
if (control.enabled[size_t(tid::generic_tracker)])
{
auto & body_packet = body.emplace_back(from_headset::body_tracking{
.production_timestamp = t0,
.timestamp = t0 + Δt,
});
switch (body_tracking)
{
case body_none:
__builtin_unreachable();
case body_fb:
body_packet.poses = application::get_fb_body_tracker().locate_spaces(t0 + Δt, world_space);
break;
case body_pico:
body_packet.poses = application::get_pico_body_tracker().locate_spaces(t0 + Δt, world_space);
break;
}
}
}
if (control.enabled[size_t(tid::face)])
{
switch (face_tracking)
@@ -408,7 +457,7 @@ void scenes::stream::tracking()
merged_tracking.back().items.emplace_back(std::move(item));
}
packets.resize(std::max(packets.size(), merged_tracking.size() + hands.size()));
packets.resize(std::max(packets.size(), merged_tracking.size() + hands.size() + body.size()));
size_t packet_count = 0;
for (const auto & i: merged_tracking)
{
@@ -425,6 +474,15 @@ void scenes::stream::tracking()
wivrn_session::stream_socket_t::serialize(packet, i);
}
}
for (const auto & i: body)
{
if (i.poses)
{
auto & packet = packets[packet_count++];
packet.clear();
wivrn_session::stream_socket_t::serialize(packet, i);
}
}
network_session->send_stream(std::span(packets.data(), packet_count));
+4 -45
View File
@@ -21,56 +21,15 @@
#ifdef VERT_SHADER
layout (constant_id = 0) const bool use_foveation_x = false;
layout (constant_id = 1) const bool use_foveation_y = false;
layout (constant_id = 2) const int nb_x = 64;
layout (constant_id = 3) const int nb_y = 64;
layout(set = 0, binding = 1) uniform UniformBufferObject
{
vec2 a;
vec2 b;
vec2 lambda;
vec2 xc;
}
ubo;
layout (location = 0) in vec2 vPosition;
layout (location = 1) in vec2 vUV;
layout(location = 0) out vec2 outUV;
vec2 positions[6] = vec2[](
vec2(0, 0), vec2(1, 0), vec2(0, 1),
vec2(1, 0), vec2(0, 1), vec2(1, 1));
vec2 unfoveate(vec2 uv)
{
uv = 2 * uv - 1;
if (use_foveation_x && use_foveation_y)
{
uv = ubo.lambda * tan(ubo.a * uv + ubo.b) + ubo.xc;
}
else
{
if (use_foveation_x)
{
uv.x = (ubo.lambda * tan(ubo.a * uv + ubo.b) + ubo.xc).y;
}
if (use_foveation_y)
{
uv.y = (ubo.lambda * tan(ubo.a * uv + ubo.b) + ubo.xc).y;
}
}
return uv;
}
void main()
{
vec2 quad_size = 1 / vec2(nb_x, nb_y);
int cell_id = gl_VertexIndex / 6;
vec2 top_left = quad_size * vec2(cell_id % nb_x, cell_id / nb_x);
outUV = top_left + positions[gl_VertexIndex % 6] * quad_size;
gl_Position = vec4(unfoveate(outUV), 0.0, 1.0);
gl_Position = vec4(vPosition, 0.0, 1.0);
outUV = vUV;
}
#endif
+144
View File
@@ -0,0 +1,144 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
*
* 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 "fb_body_tracker.h"
#include "spdlog/spdlog.h"
#include "xr/meta_body_tracking_fidelity.h"
#include "xr/xr.h"
#include <ranges>
#include <openxr/openxr.h>
static_assert(xr::fb_body_tracker::joint_whitelist.size() <= wivrn::from_headset::body_tracking::max_tracked_poses);
std::vector<XrFullBodyJointMETA> xr::fb_body_tracker::get_whitelisted_joints(bool full_body, bool hip)
{
auto whitelisted_joints = std::ranges::filter_view(xr::fb_body_tracker::joint_whitelist, [=](auto joint) {
if (!full_body && (joint == XR_FULL_BODY_JOINT_HIPS_META || joint >= XR_FULL_BODY_JOINT_LEFT_UPPER_LEG_META))
return false;
if (!hip && joint == XR_FULL_BODY_JOINT_HIPS_META)
return false;
return true;
});
return {whitelisted_joints.begin(), whitelisted_joints.end()};
}
xr::fb_body_tracker::fb_body_tracker(instance & inst, session & s) :
s(s)
{
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,
.next = nullptr,
};
create_info.bodyJointSet = full_body
? XR_BODY_JOINT_SET_FULL_BODY_META
: XR_BODY_JOINT_SET_DEFAULT_FB;
CHECK_XR(xrCreateBodyTrackerFB(s, &create_info, &handle));
// Enable IOBT.
CHECK_XR(xrRequestBodyTrackingFidelityMETA(handle, XR_BODY_TRACKING_FIDELITY_HIGH_META));
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)));
}
}
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 (!handle)
return std::nullopt;
assert(xrLocateBodyJointsFB);
XrBodyJointsLocateInfoFB locate_info{
.type = XR_TYPE_BODY_JOINTS_LOCATE_INFO_FB,
.next = nullptr,
.baseSpace = reference,
.time = time,
};
std::array<XrBodyJointLocationFB, XR_FULL_BODY_JOINT_COUNT_META> joints{};
XrBodyJointLocationsFB joint_locations{
.type = XR_TYPE_BODY_JOINT_LOCATIONS_FB,
.next = nullptr,
.jointCount = (uint32_t)(full_body ? XR_FULL_BODY_JOINT_COUNT_META : (XrFullBodyJointMETA)XR_BODY_JOINT_COUNT_FB),
.jointLocations = joints.data(),
};
if (auto res = xrLocateBodyJointsFB(handle, &locate_info, &joint_locations); !XR_SUCCEEDED(res))
{
spdlog::warn("xrLocateBodyJointsFB returned {}", xr::to_string(res));
return std::nullopt;
}
if (!joint_locations.isActive)
{
spdlog::warn("Body tracker is not active.");
return std::nullopt;
}
std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses> poses{};
int num_poses = 0;
for (auto joint: whitelisted_joints)
{
const auto & joint_loc = joints[joint];
wivrn::from_headset::body_tracking::pose pose{
.pose = joint_loc.pose,
.flags = 0,
};
if (joint_loc.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT)
{
pose.flags |= wivrn::from_headset::body_tracking::orientation_valid;
pose.flags |= wivrn::from_headset::body_tracking::orientation_tracked;
}
if (joint_loc.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT)
{
pose.flags |= wivrn::from_headset::body_tracking::position_valid;
pose.flags |= wivrn::from_headset::body_tracking::position_tracked;
}
poses[num_poses++] = pose;
}
return poses;
}
+71
View File
@@ -0,0 +1,71 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
*
* 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 "xr/meta_body_tracking_fidelity.h"
#include <array>
#include <optional>
#include <openxr/openxr.h>
namespace xr
{
class instance;
class session;
class fb_body_tracker
{
XrSession s;
XrBodyTrackerFB handle{};
PFN_xrCreateBodyTrackerFB xrCreateBodyTrackerFB{};
PFN_xrRequestBodyTrackingFidelityMETA xrRequestBodyTrackingFidelityMETA{};
PFN_xrLocateBodyJointsFB xrLocateBodyJointsFB{};
PFN_xrDestroyBodyTrackerFB xrDestroyBodyTrackerFB{};
bool full_body{};
bool hip{};
std::vector<XrFullBodyJointMETA> whitelisted_joints{};
public:
static constexpr std::array joint_whitelist{
XR_FULL_BODY_JOINT_HIPS_META,
XR_FULL_BODY_JOINT_CHEST_META,
XR_FULL_BODY_JOINT_LEFT_ARM_LOWER_META,
XR_FULL_BODY_JOINT_RIGHT_ARM_LOWER_META,
XR_FULL_BODY_JOINT_LEFT_LOWER_LEG_META,
XR_FULL_BODY_JOINT_RIGHT_LOWER_LEG_META,
XR_FULL_BODY_JOINT_LEFT_FOOT_TRANSVERSE_META,
XR_FULL_BODY_JOINT_RIGHT_FOOT_TRANSVERSE_META,
};
static std::vector<XrFullBodyJointMETA> get_whitelisted_joints(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();
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
+87
View File
@@ -0,0 +1,87 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
*
* 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 "pico_body_tracker.h"
#include "spdlog/spdlog.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);
static PFN_xrDestroyBodyTrackerBD xrDestroyBodyTrackerBD{};
XrResult xr::destroy_pico_body_tracker(XrBodyTrackerBD id)
{
return xrDestroyBodyTrackerBD(id);
}
xr::pico_body_tracker::pico_body_tracker(instance & inst, XrBodyTrackerBD h)
{
id = h;
xrLocateBodyJointsBD = inst.get_proc<PFN_xrLocateBodyJointsBD>("xrLocateBodyJointsBD");
}
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)
return std::nullopt;
XrBodyJointsLocateInfoBD locate_info{
.type = XR_TYPE_BODY_JOINTS_LOCATE_INFO_BD,
.next = nullptr,
.baseSpace = reference,
.time = time,
};
std::array<XrBodyJointLocationBD, XR_BODY_JOINT_COUNT_BD> joints{};
XrBodyJointLocationsBD joint_locations{
.type = XR_TYPE_BODY_JOINT_LOCATIONS_BD,
.next = nullptr,
.jointLocationCount = joints.size(),
.jointLocations = joints.data(),
};
if (auto res = xrLocateBodyJointsBD(id, &locate_info, &joint_locations); !XR_SUCCEEDED(res))
{
spdlog::warn("Unable to get body joints: xrLocateBodyJointsBD returned {}", xr::to_string(res));
return std::nullopt;
}
std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses> poses{};
int num_poses = 0;
for (auto joint: joint_whitelist)
{
const auto & joint_loc = joints[joint];
wivrn::from_headset::body_tracking::pose pose{
.pose = joint_loc.pose,
.flags = 0,
};
if (joint_loc.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT)
pose.flags |= wivrn::from_headset::body_tracking::orientation_valid;
if (joint_loc.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT)
pose.flags |= wivrn::from_headset::body_tracking::position_valid;
if (joint_loc.locationFlags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT)
pose.flags |= wivrn::from_headset::body_tracking::orientation_tracked;
if (joint_loc.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT)
pose.flags |= wivrn::from_headset::body_tracking::position_tracked;
poses[num_poses++] = pose;
}
return poses;
}
+55
View File
@@ -0,0 +1,55 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
*
* 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 "utils/handle.h"
#include "wivrn_packets.h"
#include <array>
#include <optional>
#include <openxr/openxr.h>
namespace xr
{
class instance;
XrResult destroy_pico_body_tracker(XrBodyTrackerBD);
class pico_body_tracker : public utils::handle<XrBodyTrackerBD, destroy_pico_body_tracker>
{
PFN_xrLocateBodyJointsBD xrLocateBodyJointsBD{};
public:
static constexpr std::array joint_whitelist{
XR_BODY_JOINT_PELVIS_BD,
XR_BODY_JOINT_LEFT_ELBOW_BD,
XR_BODY_JOINT_RIGHT_ELBOW_BD,
XR_BODY_JOINT_LEFT_KNEE_BD,
XR_BODY_JOINT_RIGHT_KNEE_BD,
XR_BODY_JOINT_LEFT_FOOT_BD,
XR_BODY_JOINT_RIGHT_FOOT_BD,
};
pico_body_tracker() = default;
pico_body_tracker(instance & inst, XrBodyTrackerBD h);
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
+24
View File
@@ -23,7 +23,9 @@
#include "details/enumerate.h"
#include "openxr/openxr.h"
#include "utils/contains.h"
#include "xr/fb_body_tracker.h"
#include "xr/instance.h"
#include "xr/pico_body_tracker.h"
#include "xr/system.h"
#include <ranges>
#include <vulkan/vulkan.h>
@@ -142,6 +144,28 @@ xr::pico_face_tracker xr::session::create_pico_face_tracker()
return {*inst, *this};
}
xr::fb_body_tracker xr::session::create_fb_body_tracker()
{
return {*inst, *this};
}
xr::pico_body_tracker xr::session::create_pico_body_tracker()
{
XrBodyTrackerCreateInfoBD create_info{
.type = XR_TYPE_BODY_TRACKER_CREATE_INFO_BD,
.next = nullptr,
.jointSet = XR_BODY_JOINT_SET_FULL_BODY_JOINTS_BD,
};
XrBodyTrackerBD bt;
auto xrCreateBodyTrackerBD = inst->get_proc<PFN_xrCreateBodyTrackerBD>("xrCreateBodyTrackerBD");
assert(xrCreateBodyTrackerBD);
CHECK_XR(xrCreateBodyTrackerBD(id, &create_info, &bt));
return {*inst, bt};
}
std::vector<vk::Format> xr::session::get_swapchain_formats() const
{
std::vector<vk::Format> formats;
+4
View File
@@ -26,10 +26,12 @@
#include <vulkan/vulkan_raii.hpp>
#include <openxr/openxr.h>
#include "fb_body_tracker.h"
#include "fb_face_tracker2.h"
#include "hand_tracker.h"
#include "htc_face_tracker.h"
#include "passthrough.h"
#include "pico_body_tracker.h"
#include "pico_face_tracker.h"
#include "space.h"
@@ -54,6 +56,8 @@ public:
fb_face_tracker2 create_fb_face_tracker2();
htc_face_tracker create_htc_face_tracker(XrFacialTrackingTypeHTC);
pico_face_tracker create_pico_face_tracker();
fb_body_tracker create_fb_body_tracker();
pico_body_tracker create_pico_body_tracker();
std::vector<vk::Format> get_swapchain_formats() const;
+36
View File
@@ -141,6 +141,42 @@ XrSystemFacialTrackingPropertiesHTC xr::system::htc_face_tracking_properties() c
return face_tracking_prop;
}
XrSystemBodyTrackingPropertiesFB xr::system::fb_body_tracking_properties() const
{
if (!id)
throw std::invalid_argument("this");
XrSystemBodyTrackingPropertiesFB body_tracking_prop{
.type = XR_TYPE_SYSTEM_BODY_TRACKING_PROPERTIES_FB,
};
XrSystemProperties prop{
.type = XR_TYPE_SYSTEM_PROPERTIES,
.next = &body_tracking_prop,
};
CHECK_XR(xrGetSystemProperties(*inst, id, &prop));
return body_tracking_prop;
}
XrSystemBodyTrackingPropertiesBD xr::system::bd_body_tracking_properties() const
{
if (!id)
throw std::invalid_argument("this");
XrSystemBodyTrackingPropertiesBD body_tracking_prop{
.type = XR_TYPE_SYSTEM_BODY_TRACKING_PROPERTIES_BD,
};
XrSystemProperties prop{
.type = XR_TYPE_SYSTEM_PROPERTIES,
.next = &body_tracking_prop,
};
CHECK_XR(xrGetSystemProperties(*inst, id, &prop));
return body_tracking_prop;
}
xr::system::passthrough_type xr::system::passthrough_supported() const
{
if (utils::contains(environment_blend_modes(XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO), XR_ENVIRONMENT_BLEND_MODE_ALPHA_BLEND))
+2
View File
@@ -64,6 +64,8 @@ public:
XrSystemEyeGazeInteractionPropertiesEXT eye_gaze_interaction_properties() const;
XrSystemFaceTrackingProperties2FB fb_face_tracking2_properties() const;
XrSystemFacialTrackingPropertiesHTC htc_face_tracking_properties() const;
XrSystemBodyTrackingPropertiesFB fb_body_tracking_properties() const;
XrSystemBodyTrackingPropertiesBD bd_body_tracking_properties() const;
passthrough_type passthrough_supported() const;
XrGraphicsRequirementsVulkan2KHR graphics_requirements() const;
+39 -11
View File
@@ -220,6 +220,7 @@ struct headset_info_packet
bool palm_pose;
bool passthrough;
face_type face_tracking;
uint32_t num_generic_trackers;
std::vector<video_codec> supported_codecs; // from preferred to least preferred
std::string system_name;
};
@@ -337,6 +338,28 @@ struct hand_tracking
std::optional<std::array<pose, XR_HAND_JOINT_COUNT_EXT>> joints;
};
struct body_tracking
{
inline static const size_t max_tracked_poses = 16;
enum flags : uint8_t
{
orientation_valid = 1 << 0,
position_valid = 1 << 1,
orientation_tracked = 1 << 2,
position_tracked = 1 << 3,
};
struct pose
{
XrPosef pose{};
// maybe add velocity?
uint8_t flags{0};
};
XrTime production_timestamp;
XrTime timestamp;
std::optional<std::array<pose, max_tracked_poses>> poses;
};
struct inputs
{
struct input_value
@@ -399,6 +422,7 @@ using packets = std::variant<
trackings,
derived_pose,
hand_tracking,
body_tracking,
inputs,
timesync_response,
battery,
@@ -439,18 +463,20 @@ struct handshake
int stream_port;
};
struct foveation_parameter_item
{
float center;
float scale;
float a;
float b;
};
struct foveation_parameter
{
foveation_parameter_item x;
foveation_parameter_item y;
// The number of source pixels for each ratio,
// the middle one is 1:1
//
// how to read it:
// 1, 4, 5, 3, 1 means:
// the first output pixel has 3 source pixels
// the 4 that come after have 2 source pixels
// then 5 with 1 source pixel
// 3 with 2 source pixels
// 1 with 3 source pixels
std::vector<uint16_t> x;
std::vector<uint16_t> y;
};
struct audio_stream_description
@@ -490,7 +516,8 @@ struct video_stream_description
uint16_t width;
uint16_t height;
float fps;
std::array<foveation_parameter, 2> foveation;
uint16_t defoveated_width;
uint16_t defoveated_height;
std::vector<item> items;
};
@@ -568,6 +595,7 @@ struct tracking_control
left_hand,
right_hand,
face,
generic_tracker,
battery,
microphone,
+41
View File
@@ -0,0 +1,41 @@
// clang-format off
#pragma once
#include <openxr/openxr.h>
// XR_META_body_tracking_fidelity is a preprocessor guard. Do not pass it to API calls.
#define XR_META_body_tracking_fidelity 1
#define XR_META_body_tracking_fidelity_SPEC_VERSION 1
#define XR_META_BODY_TRACKING_FIDELITY_EXTENSION_NAME "XR_META_body_tracking_fidelity"
static const XrStructureType XR_TYPE_BODY_TRACKING_FIDELITY_STATUS_META = (XrStructureType) 1000284000;
static const XrStructureType XR_TYPE_SYSTEM_PROPERTIES_BODY_TRACKING_FIDELITY_META = (XrStructureType) 1000284001;
typedef enum XrBodyTrackingFidelityMETA {
XR_BODY_TRACKING_FIDELITY_LOW_META = 1,
XR_BODY_TRACKING_FIDELITY_HIGH_META = 2,
XR_BODY_TRACKING_FIDELITY_MAX_ENUM_META = 0x7FFFFFFF
} XrBodyTrackingFidelityMETA;
typedef struct XrSystemPropertiesBodyTrackingFidelityMETA {
XrStructureType type;
void* XR_MAY_ALIAS next;
XrBool32 supportsBodyTrackingFidelity;
} XrSystemPropertiesBodyTrackingFidelityMETA;
// XrBodyTrackingFidelityStatusMETA extends XrBodyJointLocationsFB
typedef struct XrBodyTrackingFidelityStatusMETA {
XrStructureType type;
const void* XR_MAY_ALIAS next;
XrBodyTrackingFidelityMETA fidelity;
} XrBodyTrackingFidelityStatusMETA;
typedef XrResult (XRAPI_PTR *PFN_xrRequestBodyTrackingFidelityMETA)(XrBodyTrackerFB bodyTracker, const XrBodyTrackingFidelityMETA fidelity);
#ifndef XR_NO_PROTOTYPES
#ifdef XR_EXTENSION_PROTOTYPES
XRAPI_ATTR XrResult XRAPI_CALL xrRequestBodyTrackingFidelityMETA(
XrBodyTrackerFB bodyTracker,
const XrBodyTrackingFidelityMETA fidelity);
#endif /* XR_EXTENSION_PROTOTYPES */
#endif /* !XR_NO_PROTOTYPES */
// clang-format on
-1
View File
@@ -301,7 +301,6 @@ Kirigami.ScrollablePage {
onCurrentIndexChanged: partitionner.codec = model[currentIndex].name
delegate: Controls.ItemDelegate {
required property int index
required property string label
required property string name
-1
View File
@@ -25,7 +25,6 @@ class steamApp
{
Q_GADGET
QML_VALUE_TYPE(steamApp)
QML_ELEMENT
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(QString imagePath READ imagePath WRITE setImagePath)
Q_PROPERTY(QString command READ command WRITE setCommand)
+5 -5
View File
@@ -577,19 +577,19 @@ QString wivrn_server::host_path(QString path)
return path;
}
QList<OpenVRCompat> wivrn_server::openVRCompat() const
QList<openVRCompatLib> wivrn_server::openVRCompat() const
{
if (wivrn::is_flatpak())
return {
OpenVRCompat(i18n("xrizer"), "xrizer"),
OpenVRCompat(i18n("Open Composite"), "OpenComposite"),
openVRCompatLib(i18n("xrizer"), "xrizer"),
openVRCompatLib(i18n("Open Composite"), "OpenComposite"),
};
QList<OpenVRCompat> result;
QList<openVRCompatLib> result;
for (auto path: std::ranges::split_view(std::string_view(OVR_COMPAT_SEARCH_PATH), std::string_view(":")))
{
if (std::filesystem::path fs = std::string_view(path); std::filesystem::exists(fs))
result.push_back(OpenVRCompat(QString::fromStdString(fs.string()), QString::fromStdString(fs.string())));
result.push_back(openVRCompatLib(QString::fromStdString(fs.string()), QString::fromStdString(fs.string())));
}
return result;
}
+5 -6
View File
@@ -37,7 +37,6 @@ class headset
{
Q_GADGET
QML_VALUE_TYPE(headset)
QML_ELEMENT
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(QString publicKey READ publicKey WRITE setPublicKey)
Q_PROPERTY(bool hasLastConnection READ hasLastConnection)
@@ -95,7 +94,7 @@ public:
}
};
class OpenVRCompat
class openVRCompatLib
{
Q_GADGET
QML_VALUE_TYPE(openVRCompat)
@@ -107,8 +106,8 @@ class OpenVRCompat
QString m_path;
public:
OpenVRCompat() = default;
OpenVRCompat(QString name, QString path) :
openVRCompatLib() = default;
openVRCompatLib(QString name, QString path) :
m_name(name), m_path(path) {}
// localized name of the compat layer (can be the path)
@@ -199,7 +198,7 @@ public:
Q_INVOKABLE QString host_path(QString path);
// System information
Q_PROPERTY(QList<OpenVRCompat> openVRCompat READ openVRCompat CONSTANT)
Q_PROPERTY(QList<openVRCompatLib> openVRCompat READ openVRCompat CONSTANT)
Status serverStatus() const
{
@@ -315,7 +314,7 @@ public:
return server_output.join("");
}
QList<OpenVRCompat> openVRCompat() const;
QList<openVRCompatLib> openVRCompat() const;
Q_INVOKABLE void disconnect_headset();
Q_INVOKABLE void copy_steam_command();
+20 -5
View File
@@ -5,19 +5,20 @@
outputs = inputs@{ nixpkgs, flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "x86_64-linux" ];
perSystem = { pkgs, ... }: let
perSystem = { lib, pkgs, ... }: let
# Tools used for development work (clangd, clang-format)
devTools = with pkgs; [
clang-tools
gdb
ktx-tools
];
# Extra build inputs not yet in the nixpkgs recipe.
# Should be submitted to nixpkgs on release
extraBuildInputs = with pkgs; [
# XRT_FEATURE_DEBUG_GUI requires SDL2
sdl2-compat
];
package = pkgs.wivrn.overrideAttrs (finalAttrs: oldAttrs: {
package = pkgs.enableDebugging (pkgs.wivrn.overrideAttrs (finalAttrs: oldAttrs: {
src = ./.;
version = "next";
@@ -25,6 +26,8 @@
# We also don't need the check since we read the revision from the monado-rev file.
postUnpack = null;
separateDebugInfo = false;
monado = pkgs.applyPatches {
inherit (oldAttrs.monado) patches postPatch;
# Force a refetch when the monado rev changes.
@@ -39,7 +42,19 @@
};
buildInputs = oldAttrs.buildInputs ++ extraBuildInputs;
});
dontWrapQtApps = true;
preFixup = ''
wrapQtApp "$out/bin/wivrn-dashboard" \
--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ pkgs.vulkan-loader ]}
'';
postFixup = null;
cmakeFlags = (oldAttrs.cmakeFlags or [ ]) ++ [
(lib.cmakeFeature "CMAKE_BUILD_TYPE" "Debug")
];
}));
in {
packages.default = package;
devShells.default = package.overrideAttrs (oldAttrs: {
@@ -47,4 +62,4 @@
});
};
};
}
}
+13 -13
View File
@@ -2,7 +2,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WiVRn-dashboard\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-05-22 03:31+0900\n"
"POT-Creation-Date: 2025-06-09 19:04+0900\n"
"PO-Revision-Date: 2025-04-10 07:14+0900\n"
"Last-Translator: Mitsuami Megane <hello@mitsua.me>\n"
"Language-Team: Japanese <>\n"
@@ -517,22 +517,22 @@ msgstr "H.265"
msgid "AV1"
msgstr "AV1"
#: dashboard/qml/SettingsPage.qml:320
#: dashboard/qml/SettingsPage.qml:319
#, kde-format
msgid "Advanced options"
msgstr "詳細設定"
#: dashboard/qml/SettingsPage.qml:326
#: dashboard/qml/SettingsPage.qml:325
#, kde-format
msgid "Enable debug window"
msgstr "デバッグ・ウィンドウを表示する"
#: dashboard/qml/SettingsPage.qml:333
#: dashboard/qml/SettingsPage.qml:332
#, kde-format
msgid "Enable SteamVR tracked devices support"
msgstr "SteamVR・ライトハウス・トラッキング"
#: dashboard/qml/SettingsPage.qml:336
#: dashboard/qml/SettingsPage.qml:335
#, kde-format
msgid ""
"Allows the use of lighthouse-based controllers and trackers.\n"
@@ -545,44 +545,44 @@ msgstr ""
"すべてのデバイスの電源が入ってからHMDを接続しましょう。\n"
"キャリブレーションはmotocなどのソフトウェアで行います。"
#: dashboard/qml/SettingsPage.qml:344
#: dashboard/qml/SettingsPage.qml:343
#, kde-format
msgid "Custom adb location"
msgstr "特定なADBの場所"
#: dashboard/qml/SettingsPage.qml:355
#: dashboard/qml/SettingsPage.qml:354
#, kde-format
msgid "Adb location:"
msgstr "ADBの場所:"
#: dashboard/qml/SettingsPage.qml:364
#: dashboard/qml/SettingsPage.qml:363
#, kde-format
msgctxt "browse a file to choose the adb binary"
msgid "Browse"
msgstr "検索する"
#: dashboard/qml/SettingsPage.qml:374
#: dashboard/qml/SettingsPage.qml:373
#, kde-format
msgid "Default"
msgstr "デフォルト"
#: dashboard/qml/SettingsPage.qml:388
#: dashboard/qml/SettingsPage.qml:387
#, kde-format
msgctxt "set a custom OpenVR compatibility library"
msgid "Custom"
msgstr "カスタム"
#: dashboard/qml/SettingsPage.qml:393
#: dashboard/qml/SettingsPage.qml:392
#, kde-format
msgid "Disabled"
msgstr "無し"
#: dashboard/qml/SettingsPage.qml:401
#: dashboard/qml/SettingsPage.qml:400
#, kde-format
msgid "OpenVR compatibility library:"
msgstr "OpenVR実装ライブラリー"
#: dashboard/qml/SettingsPage.qml:427
#: dashboard/qml/SettingsPage.qml:426
#, kde-format
msgid "Library path, excluding bin/linux64/vrclient.so"
msgstr "ライブラリーの場所(bin/linux64/vrclient.so 無し)"
+99 -46
View File
@@ -2,7 +2,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WiVRn 0.16\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-04-20 17:32+0900\n"
"POT-Creation-Date: 2025-06-09 19:04+0900\n"
"PO-Revision-Date: 2024-06-20 10:33+0900\n"
"Last-Translator: Mitsuami Megane <hello@mitsua.me>\n"
"Language: Japanese\n"
@@ -171,12 +171,12 @@ msgstr "最低リフレッシュレート"
msgid "Resolution scale"
msgstr "解像度"
#: client/scenes/lobby_gui.cpp:666 client/scenes/lobby_gui.cpp:915
#: client/scenes/lobby_gui.cpp:666 client/scenes/lobby_gui.cpp:967
#, c-format, c++-format
msgid "%d%% - {}x{} per eye"
msgstr "%d%% - 目あたり{}x{}"
#: client/scenes/lobby_gui.cpp:677 client/scenes/lobby_gui.cpp:926
#: client/scenes/lobby_gui.cpp:677 client/scenes/lobby_gui.cpp:978
#, c++-format
msgid "Resolution larger than {}x{} may not be supported by the headset"
msgstr ""
@@ -199,7 +199,8 @@ msgid "Enable hand tracking"
msgstr "ハンドトラッキングを有効する"
#: client/scenes/lobby_gui.cpp:713 client/scenes/lobby_gui.cpp:726
#: client/scenes/lobby_gui.cpp:739 client/scenes/lobby_gui.cpp:751
#: client/scenes/lobby_gui.cpp:739 client/scenes/lobby_gui.cpp:756
#: client/scenes/lobby_gui.cpp:803
msgid "This feature is not supported by your headset"
msgstr "デバイスはこの機能をサポートしていません"
@@ -211,45 +212,89 @@ msgstr "アイトラッキングを有効する"
msgid "Enable face tracking"
msgstr "顔トラッキングを有効する"
#: client/scenes/lobby_gui.cpp:744
#: client/scenes/lobby_gui.cpp:746
msgid "Enable body tracking"
msgstr "ボディラッキングを有効する"
#: client/scenes/lobby_gui.cpp:761
msgid ""
"Requires 'Hand and body tracking' to be enabled in the Quest movement "
"tracking settings,\n"
"otherwise body data will be guessed from controller and headset positions"
msgstr ""
"Quest設定・動きのトラッキング・ジェスチャーコントロールとボディトラッキング"
"を有効する必要がある。\n"
"そうでなければ、トラッキングデータはHMDとコントローラーの情報から推測されることになる。"
#: client/scenes/lobby_gui.cpp:763
msgid "Uses the Pico Motion Trackers to track body joint positions"
msgstr "Pico Motion Trackerによるフルボディトラッキング"
#: client/scenes/lobby_gui.cpp:773
msgid "Enable lower body tracking"
msgstr "下半身トラッキングを有効する"
#: client/scenes/lobby_gui.cpp:779
msgid ""
"Estimate lower body joint positions using Generative Legs\n"
"Requires 'Hand and body tracking' to be enabled in the Quest movement "
"tracking settings"
msgstr ""
"下半身に計算された疑似トラッキングを使用する。\n"
"Quest設定・動きのトラッキング・ジェスチャーコントロールとボディトラッキング"
"を有効する必要がある。"
#: client/scenes/lobby_gui.cpp:782
msgid "Enable hip tracking"
msgstr "腰のトラッキングを有効する"
#: client/scenes/lobby_gui.cpp:788
msgid ""
"Only takes affect with lower body tracking enabled\n"
"May be desired when using another source of hip tracking"
msgstr ""
"下半身トラッキングが有効な場合に使用可能。"
"腰トラッカーを持ってる方は無効にしましょう。"
#: client/scenes/lobby_gui.cpp:796
msgid "Enable video passthrough in lobby"
msgstr "ロビーでパススルーを有効する"
#: client/scenes/lobby_gui.cpp:754
#: client/scenes/lobby_gui.cpp:806
msgid "Show performance metrics"
msgstr "パフォーマンスグラフを表示する"
#: client/scenes/lobby_gui.cpp:758
#: client/scenes/lobby_gui.cpp:810
msgid "Overlay can be toggled by pressing both thumbsticks"
msgstr "両方のサムスティックを同時に押すことで切り替え可能"
#: client/scenes/lobby_gui.cpp:788 client/scenes/lobby_gui.cpp:796
#: client/scenes/lobby_gui.cpp:840 client/scenes/lobby_gui.cpp:848
#: client/scenes/stream_stats.cpp:159
msgid "CPU time"
msgstr "CPU使用時間"
#: client/scenes/lobby_gui.cpp:792
#: client/scenes/lobby_gui.cpp:844
msgid "CPU time [ms]"
msgstr "CPU使用時間、ミリ秒"
#: client/scenes/lobby_gui.cpp:802 client/scenes/lobby_gui.cpp:810
#: client/scenes/lobby_gui.cpp:854 client/scenes/lobby_gui.cpp:862
#: client/scenes/stream_stats.cpp:161
msgid "GPU time"
msgstr "GPU使用時間"
#: client/scenes/lobby_gui.cpp:806
#: client/scenes/lobby_gui.cpp:858
msgid "GPU time [ms]"
msgstr "GPU使用時間、ミリ秒"
#: client/scenes/lobby_gui.cpp:825
#: client/scenes/lobby_gui.cpp:877
msgid "OpenXR post-processing"
msgstr "OpenXRポストエフェクト"
#: client/scenes/lobby_gui.cpp:829
#: client/scenes/lobby_gui.cpp:881
msgid "Supersampling"
msgstr "スーパーサンプリング"
#: client/scenes/lobby_gui.cpp:849
#: client/scenes/lobby_gui.cpp:901
msgid ""
"Reduce flicker for high contrast edges.\n"
"Useful when the input resolution is high compared to the headset display"
@@ -257,11 +302,11 @@ msgstr ""
"コントラストが高い部分のギザギザを低減する。\n"
"ストリームの解像度は、HMDの解像度より高い場合は有用です。"
#: client/scenes/lobby_gui.cpp:854
#: client/scenes/lobby_gui.cpp:906
msgid "Sharpening"
msgstr "シャープ"
#: client/scenes/lobby_gui.cpp:874
#: client/scenes/lobby_gui.cpp:926
msgid ""
"Improve clarity of high contrast edges and counteract blur.\n"
"Useful when the input resolution is low compared to the headset display"
@@ -269,115 +314,123 @@ msgstr ""
"ぼかしを低減し、コントラストが高い部分の鮮明度を向上する。\n"
"ストリームの解像度は、HMDの解像度より低い場合に有用です。"
#: client/scenes/lobby_gui.cpp:883
#: client/scenes/lobby_gui.cpp:935
msgid "Enable Snapdragon Game Super Resolution"
msgstr "Snapdragon Game Super Resolutionを有効する"
#: client/scenes/lobby_gui.cpp:891
#: client/scenes/lobby_gui.cpp:943
msgid ""
"On this headset, this setting has been fully superseded by the native "
"Sharpening setting above.\n"
"Only enable if you know what you're doing."
msgstr ""
"この設定は、使用中のHMDでは非推奨です。"
"OpenXRの方法を使用してください。"
"この設定は、使用中のHMDでは非推奨です。OpenXRの方法を使用してください。"
#: client/scenes/lobby_gui.cpp:893
#: client/scenes/lobby_gui.cpp:945
msgid ""
"Client-side upscaling and sharpening, adds a performance cost on the headset"
msgstr ""
"HMD側のアップスケーリングやシャープニングを使用する場合、要求性能が上がります。"
"HMD側のアップスケーリングやシャープニングを使用する場合、要求性能が上がりま"
"す。"
#: client/scenes/lobby_gui.cpp:911
#: client/scenes/lobby_gui.cpp:963
msgid "Upscaling factor"
msgstr "アップスケーリング係数"
#: client/scenes/lobby_gui.cpp:930
#: client/scenes/lobby_gui.cpp:982
msgid "Use edge direction"
msgstr "エッジ方向を使用する"
#: client/scenes/lobby_gui.cpp:936
#: client/scenes/lobby_gui.cpp:988
msgid "Adds an additional performance cost"
msgstr "HMDに対する要求性能が上がります。"
#: client/scenes/lobby_gui.cpp:941
#: client/scenes/lobby_gui.cpp:993
msgid "Edge threshold"
msgstr "エッジのしきい値"
#: client/scenes/lobby_gui.cpp:948 client/scenes/lobby_gui.cpp:957
#: client/scenes/lobby_gui.cpp:1000 client/scenes/lobby_gui.cpp:1009
#, c++-format
msgid "Recommended: {:.1f}"
msgstr "推奨値:{:.1f}"
#: client/scenes/lobby_gui.cpp:951
#: client/scenes/lobby_gui.cpp:1003
msgid "Edge sharpness"
msgstr "エッジのシャープ"
#: client/scenes/lobby_gui.cpp:1045 client/scenes/lobby_gui.cpp:1691
#: client/scenes/lobby_gui.cpp:1097 client/scenes/lobby_gui.cpp:1753
msgid "Licenses"
msgstr "ライセンス"
#: client/scenes/lobby_gui.cpp:1384
#: client/scenes/lobby_gui.cpp:1436
msgid "Microphone is enabled"
msgstr "マイクは有効です"
#: client/scenes/lobby_gui.cpp:1385
#: client/scenes/lobby_gui.cpp:1437
msgid "Microphone is disabled"
msgstr "マイクは無効です"
#: client/scenes/lobby_gui.cpp:1394
#: client/scenes/lobby_gui.cpp:1446
msgid "Hand tracking is enabled"
msgstr "ハンドトラッキングは有効です"
#: client/scenes/lobby_gui.cpp:1395
#: client/scenes/lobby_gui.cpp:1447
msgid "Hand tracking is disabled"
msgstr "ハンドラッキングは無効です"
#: client/scenes/lobby_gui.cpp:1404
#: client/scenes/lobby_gui.cpp:1456
msgid "Eye tracking is enabled"
msgstr "アイトラッキングは有効です"
#: client/scenes/lobby_gui.cpp:1405
#: client/scenes/lobby_gui.cpp:1457
msgid "Eye tracking is disabled"
msgstr "アイトラッキングは無効です"
#: client/scenes/lobby_gui.cpp:1415 client/scenes/lobby_gui.cpp:1426
#: client/scenes/lobby_gui.cpp:1467 client/scenes/lobby_gui.cpp:1478
msgid "Face tracking is enabled"
msgstr "顔トラッキングは有効です"
#: client/scenes/lobby_gui.cpp:1416 client/scenes/lobby_gui.cpp:1427
#: client/scenes/lobby_gui.cpp:1468 client/scenes/lobby_gui.cpp:1479
msgid "Face tracking is disabled"
msgstr "フェーストラッキングは無効です"
#: client/scenes/lobby_gui.cpp:1444
#: client/scenes/lobby_gui.cpp:1489
msgid "Body tracking is enabled"
msgstr "ボディトラッキングは有効です"
#: client/scenes/lobby_gui.cpp:1490
msgid "Body tracking is disabled"
msgstr "ボディトラッキングは無効です"
#: client/scenes/lobby_gui.cpp:1506
msgid "Add server"
msgstr "サーバーを追加する"
#: client/scenes/lobby_gui.cpp:1673
#: client/scenes/lobby_gui.cpp:1735
msgid "Server list"
msgstr "サーバー"
#: client/scenes/lobby_gui.cpp:1676
#: client/scenes/lobby_gui.cpp:1738
msgid "Settings"
msgstr "設定"
#: client/scenes/lobby_gui.cpp:1679
#: client/scenes/lobby_gui.cpp:1741
msgid "Post-processing"
msgstr "ポストエフェクト"
#: client/scenes/lobby_gui.cpp:1683
#: client/scenes/lobby_gui.cpp:1745
msgid "Debug"
msgstr "デバッグ"
#: client/scenes/lobby_gui.cpp:1688
#: client/scenes/lobby_gui.cpp:1750
msgid "About"
msgstr "WiVRnについて"
#: client/scenes/lobby_gui.cpp:1694
#: client/scenes/lobby_gui.cpp:1756
msgid "Exit"
msgstr "完了"
#: client/scenes/lobby_gui.cpp:1708
#: client/scenes/lobby_gui.cpp:1770
msgid ""
"Press A or X or put your palm up\n"
"to move the main window"
@@ -385,7 +438,7 @@ msgstr ""
"ウィンドウを移動するには、手のひらを上に向けるか、\n"
"AまたはBボタンを押しましょう"
#: client/scenes/lobby_gui.cpp:1710
#: client/scenes/lobby_gui.cpp:1772
msgid "Press A or X to move the main window"
msgstr "AまたはXボタンを押してウィンドウを移動"
@@ -1,4 +1,4 @@
From e18311e2b207f784cdd48ab6faf3834f912a1f8d Mon Sep 17 00:00:00 2001
From 75d2fe061edd2a268ea9f5fbedc90efd8ffea519 Mon Sep 17 00:00:00 2001
From: Patrick Nicolas <patricknicolas@laposte.net>
Date: Tue, 22 Oct 2024 15:23:19 +0200
Subject: [PATCH 01/11] c/multi: early wake of compositor
@@ -1,4 +1,4 @@
From 0b802694d3a46668acbb7962cb6cc9e7634fa519 Mon Sep 17 00:00:00 2001
From 3a8d64c0f569425e2f07b4c2a7803c9bfbc224df Mon Sep 17 00:00:00 2001
From: Patrick Nicolas <patricknicolas@laposte.net>
Date: Tue, 2 Apr 2024 17:14:42 +0200
Subject: [PATCH 02/11] ipc/server: Always listen to stdin
@@ -1,4 +1,4 @@
From 7a53f4a771a8386d659ad03a025447e8193c284c Mon Sep 17 00:00:00 2001
From 1a8f4aada945314ac852b19ce20c2ed0345f5bb2 Mon Sep 17 00:00:00 2001
From: Patrick Nicolas <patricknicolas@laposte.net>
Date: Tue, 8 Oct 2024 22:13:15 +0200
Subject: [PATCH 03/11] Use extern socket fd
@@ -1,4 +1,4 @@
From 018341025bf1ddd2a59e063e7dd972b914ebfbb5 Mon Sep 17 00:00:00 2001
From 2f38475c9b51f2d2e92f2fd3d51dcef6d7a53e83 Mon Sep 17 00:00:00 2001
From: galister <3123227-galister@users.noreply.gitlab.com>
Date: Mon, 19 Aug 2024 18:51:45 +0900
Subject: [PATCH 04/11] c/render: Add storage usage to distortion mesh
@@ -1,4 +1,4 @@
From e7159c1bb460909c7c8fe4d54f2a1513462e24b0 Mon Sep 17 00:00:00 2001
From 15eec19c226eb78cb9bc7ebd0021ab226402245a Mon Sep 17 00:00:00 2001
From: galister <85970-galister@users.noreply.gitlab.freedesktop.org>
Date: Sat, 23 Nov 2024 02:42:12 +0900
Subject: [PATCH 05/11] change environment blend mode selection logic
@@ -1,7 +1,7 @@
From 30eb60e3716c0bb0df118f4b36eb1820c567ee5b Mon Sep 17 00:00:00 2001
From 06497b57fc56d48611ffc9b6f1bd431141097174 Mon Sep 17 00:00:00 2001
From: Patrick Nicolas <patricknicolas@laposte.net>
Date: Wed, 11 Sep 2024 22:56:29 +0200
Subject: [PATCH 07/11] Convert to YCbCr in Monado
Subject: [PATCH 06/11] Convert to YCbCr in Monado
---
src/xrt/compositor/main/comp_renderer.c | 6 +-
@@ -9,16 +9,16 @@ Subject: [PATCH 07/11] Convert to YCbCr in Monado
src/xrt/compositor/render/render_compute.c | 104 +++++++++++++------
src/xrt/compositor/render/render_interface.h | 15 ++-
src/xrt/compositor/render/render_resources.c | 35 +++++--
src/xrt/compositor/shaders/distortion.comp | 55 +++++++---
src/xrt/compositor/shaders/distortion.comp | 62 +++++++----
src/xrt/compositor/util/comp_render.h | 12 ++-
src/xrt/compositor/util/comp_render_cs.c | 41 +++++---
8 files changed, 186 insertions(+), 85 deletions(-)
8 files changed, 186 insertions(+), 92 deletions(-)
diff --git a/src/xrt/compositor/main/comp_renderer.c b/src/xrt/compositor/main/comp_renderer.c
index 89982e654..55aaed69e 100644
index 6df4d2b29..ea581accd 100644
--- a/src/xrt/compositor/main/comp_renderer.c
+++ b/src/xrt/compositor/main/comp_renderer.c
@@ -1009,7 +1009,8 @@ dispatch_compute(struct comp_renderer *r,
@@ -1001,7 +1001,8 @@ dispatch_compute(struct comp_renderer *r,
// Target Vulkan resources..
VkImage target_image = r->c->target->images[r->acquired_buffer].handle;
@@ -28,7 +28,7 @@ index 89982e654..55aaed69e 100644
// Target view information.
struct render_viewport_data views[XRT_MAX_VIEWS];
@@ -1020,7 +1021,8 @@ dispatch_compute(struct comp_renderer *r,
@@ -1012,7 +1013,8 @@ dispatch_compute(struct comp_renderer *r,
comp_render_cs_initial_init( //
&data, // data
target_image, // target_image
@@ -53,7 +53,7 @@ index 876ff8cd9..924b4ea08 100644
/*!
diff --git a/src/xrt/compositor/render/render_compute.c b/src/xrt/compositor/render/render_compute.c
index 131b97066..a9552cf2c 100644
index 27b1953cf..fd04801d4 100644
--- a/src/xrt/compositor/render/render_compute.c
+++ b/src/xrt/compositor/render/render_compute.c
@@ -66,8 +66,8 @@ calc_dispatch_dims_views(const struct render_viewport_data views[XRT_MAX_VIEWS],
@@ -199,7 +199,7 @@ index 131b97066..a9552cf2c 100644
};
vk->vkUpdateDescriptorSets( //
@@ -409,7 +439,8 @@ render_compute_layers(struct render_compute *render,
@@ -395,7 +425,8 @@ render_compute_layers(struct render_compute *render,
VkSampler src_samplers[RENDER_MAX_IMAGES_SIZE],
VkImageView src_image_views[RENDER_MAX_IMAGES_SIZE],
uint32_t num_srcs,
@@ -209,7 +209,7 @@ index 131b97066..a9552cf2c 100644
const struct render_viewport_data *view,
bool do_timewarp)
{
@@ -429,8 +460,10 @@ render_compute_layers(struct render_compute *render,
@@ -415,8 +446,10 @@ render_compute_layers(struct render_compute *render,
src_samplers, //
src_image_views, //
num_srcs, //
@@ -222,7 +222,7 @@ index 131b97066..a9552cf2c 100644
r->compute.ubo_binding, //
ubo, //
VK_WHOLE_SIZE, //
@@ -473,7 +506,8 @@ render_compute_projection_timewarp(struct render_compute *render,
@@ -459,7 +492,8 @@ render_compute_projection_timewarp(struct render_compute *render,
const struct xrt_fov src_fovs[XRT_MAX_VIEWS],
const struct xrt_pose new_poses[XRT_MAX_VIEWS],
VkImage target_image,
@@ -232,7 +232,7 @@ index 131b97066..a9552cf2c 100644
const struct render_viewport_data views[XRT_MAX_VIEWS])
{
assert(render->r != NULL);
@@ -542,8 +576,10 @@ render_compute_projection_timewarp(struct render_compute *render,
@@ -528,8 +562,10 @@ render_compute_projection_timewarp(struct render_compute *render,
r->compute.distortion_binding, //
distortion_samplers, //
r->distortion.image_views, //
@@ -245,7 +245,7 @@ index 131b97066..a9552cf2c 100644
r->compute.ubo_binding, //
r->compute.distortion.ubo.buffer, //
VK_WHOLE_SIZE, //
@@ -581,7 +617,7 @@ render_compute_projection_timewarp(struct render_compute *render,
@@ -567,7 +603,7 @@ render_compute_projection_timewarp(struct render_compute *render,
.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT,
.oldLayout = VK_IMAGE_LAYOUT_GENERAL,
@@ -254,7 +254,7 @@ index 131b97066..a9552cf2c 100644
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.image = target_image,
@@ -607,7 +643,8 @@ render_compute_projection(struct render_compute *render,
@@ -593,7 +629,8 @@ render_compute_projection(struct render_compute *render,
VkImageView src_image_views[XRT_MAX_VIEWS],
const struct xrt_normalized_rect src_norm_rects[XRT_MAX_VIEWS],
VkImage target_image,
@@ -264,7 +264,7 @@ index 131b97066..a9552cf2c 100644
const struct render_viewport_data views[XRT_MAX_VIEWS])
{
assert(render->r != NULL);
@@ -666,8 +703,10 @@ render_compute_projection(struct render_compute *render,
@@ -652,8 +689,10 @@ render_compute_projection(struct render_compute *render,
r->compute.distortion_binding, //
distortion_samplers, //
r->distortion.image_views, //
@@ -277,7 +277,7 @@ index 131b97066..a9552cf2c 100644
r->compute.ubo_binding, //
r->compute.distortion.ubo.buffer, //
VK_WHOLE_SIZE, //
@@ -705,7 +744,7 @@ render_compute_projection(struct render_compute *render,
@@ -691,7 +730,7 @@ render_compute_projection(struct render_compute *render,
.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT,
.oldLayout = VK_IMAGE_LAYOUT_GENERAL,
@@ -286,7 +286,7 @@ index 131b97066..a9552cf2c 100644
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.image = target_image,
@@ -728,7 +767,8 @@ render_compute_projection(struct render_compute *render,
@@ -714,7 +753,8 @@ render_compute_projection(struct render_compute *render,
void
render_compute_clear(struct render_compute *render,
VkImage target_image,
@@ -296,7 +296,7 @@ index 131b97066..a9552cf2c 100644
const struct render_viewport_data views[XRT_MAX_VIEWS])
{
assert(render->r != NULL);
@@ -795,8 +835,10 @@ render_compute_clear(struct render_compute *render,
@@ -781,8 +821,10 @@ render_compute_clear(struct render_compute *render,
r->compute.distortion_binding, //
distortion_samplers, //
r->distortion.image_views, //
@@ -309,7 +309,7 @@ index 131b97066..a9552cf2c 100644
r->compute.ubo_binding, //
r->compute.clear.ubo.buffer, //
VK_WHOLE_SIZE, // ubo_size
@@ -834,7 +876,7 @@ render_compute_clear(struct render_compute *render,
@@ -820,7 +862,7 @@ render_compute_clear(struct render_compute *render,
.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT,
.oldLayout = VK_IMAGE_LAYOUT_GENERAL,
@@ -319,10 +319,10 @@ index 131b97066..a9552cf2c 100644
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.image = target_image,
diff --git a/src/xrt/compositor/render/render_interface.h b/src/xrt/compositor/render/render_interface.h
index aab965e0c..b0e568401 100644
index d5d2bc4cb..2f8ce5287 100644
--- a/src/xrt/compositor/render/render_interface.h
+++ b/src/xrt/compositor/render/render_interface.h
@@ -488,7 +488,8 @@ struct render_resources
@@ -481,7 +481,8 @@ struct render_resources
uint32_t distortion_binding;
//! Writing the image out too.
@@ -332,7 +332,7 @@ index aab965e0c..b0e568401 100644
//! Uniform data binding.
uint32_t ubo_binding;
@@ -1374,7 +1375,8 @@ render_compute_layers(struct render_compute *render,
@@ -1350,7 +1351,8 @@ render_compute_layers(struct render_compute *render,
VkSampler src_samplers[RENDER_MAX_IMAGES_SIZE],
VkImageView src_image_views[RENDER_MAX_IMAGES_SIZE],
uint32_t num_srcs,
@@ -342,7 +342,7 @@ index aab965e0c..b0e568401 100644
const struct render_viewport_data *view,
bool timewarp);
@@ -1390,7 +1392,8 @@ render_compute_projection_timewarp(struct render_compute *render,
@@ -1366,7 +1368,8 @@ render_compute_projection_timewarp(struct render_compute *render,
const struct xrt_fov src_fovs[XRT_MAX_VIEWS],
const struct xrt_pose new_poses[XRT_MAX_VIEWS],
VkImage target_image,
@@ -352,7 +352,7 @@ index aab965e0c..b0e568401 100644
const struct render_viewport_data views[XRT_MAX_VIEWS]);
/*!
@@ -1402,7 +1405,8 @@ render_compute_projection(struct render_compute *render,
@@ -1378,7 +1381,8 @@ render_compute_projection(struct render_compute *render,
VkImageView src_image_views[XRT_MAX_VIEWS],
const struct xrt_normalized_rect src_rects[XRT_MAX_VIEWS],
VkImage target_image,
@@ -362,7 +362,7 @@ index aab965e0c..b0e568401 100644
const struct render_viewport_data views[XRT_MAX_VIEWS]);
/*!
@@ -1411,7 +1415,8 @@ render_compute_projection(struct render_compute *render,
@@ -1387,7 +1391,8 @@ render_compute_projection(struct render_compute *render,
void
render_compute_clear(struct render_compute *render,
VkImage target_image,
@@ -373,7 +373,7 @@ index aab965e0c..b0e568401 100644
diff --git a/src/xrt/compositor/render/render_resources.c b/src/xrt/compositor/render/render_resources.c
index b9b8d4a22..cd9d82072 100644
index ccc6f10cf..5b9addd59 100644
--- a/src/xrt/compositor/render/render_resources.c
+++ b/src/xrt/compositor/render/render_resources.c
@@ -184,14 +184,15 @@ init_mesh_ubo_buffers(struct vk_bundle *vk, struct render_buffer ubo[XRT_MAX_VIE
@@ -455,7 +455,7 @@ index b9b8d4a22..cd9d82072 100644
};
VkDescriptorSetLayoutCreateInfo set_layout_info = {
@@ -601,8 +615,9 @@ render_resources_init(struct render_resources *r,
@@ -539,8 +553,9 @@ render_resources_init(struct render_resources *r,
}
r->compute.src_binding = 0;
r->compute.distortion_binding = 1;
@@ -466,7 +466,7 @@ index b9b8d4a22..cd9d82072 100644
r->compute.layer.image_array_size =
MIN(vk->features.max_per_stage_descriptor_sampled_images, RENDER_MAX_IMAGES_COUNT(r));
@@ -919,7 +934,8 @@ render_resources_init(struct render_resources *r,
@@ -856,7 +871,8 @@ render_resources_init(struct render_resources *r,
ret = create_compute_layer_descriptor_set_layout( //
vk, // vk_bundle
r->compute.src_binding, // src_binding,
@@ -476,7 +476,7 @@ index b9b8d4a22..cd9d82072 100644
r->compute.ubo_binding, // ubo_binding,
r->compute.layer.image_array_size, // source_images_count,
&r->compute.layer.descriptor_set_layout); // out_descriptor_set_layout
@@ -1000,7 +1016,8 @@ render_resources_init(struct render_resources *r,
@@ -937,7 +953,8 @@ render_resources_init(struct render_resources *r,
vk, // vk_bundle
r->compute.src_binding, // src_binding,
r->compute.distortion_binding, // distortion_binding,
@@ -487,7 +487,7 @@ index b9b8d4a22..cd9d82072 100644
&r->compute.distortion.descriptor_set_layout); // out_descriptor_set_layout
VK_CHK_WITH_RET(ret, "create_compute_distortion_descriptor_set_layout", false);
diff --git a/src/xrt/compositor/shaders/distortion.comp b/src/xrt/compositor/shaders/distortion.comp
index 9a09c03db..461aeb4ec 100644
index 08b44d4cf..e1dd1cb58 100644
--- a/src/xrt/compositor/shaders/distortion.comp
+++ b/src/xrt/compositor/shaders/distortion.comp
@@ -18,7 +18,7 @@ layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
@@ -520,7 +520,7 @@ index 9a09c03db..461aeb4ec 100644
vec2 position_to_uv(ivec2 extent, uint ix, uint iy)
{
@@ -124,30 +137,40 @@ mat3x2 source_coord(ivec3 xyv, ivec2 extent)
@@ -104,37 +117,40 @@ vec2 transform_uv(vec2 uv, uint iz)
void main()
{
@@ -545,18 +545,25 @@ index 9a09c03db..461aeb4ec 100644
+ vec2 uv = texture(distortion[iz + 0], dist_uv).xy;
+ vec2 lod = texture(distortion[iz + 2], dist_uv).xy;
- vec2 uv = texture(distortion[iz + 0], dist_uv).xy;
- vec2 lod = texture(distortion[iz + 2], dist_uv).xy;
- vec2 r_uv = texture(distortion[iz + 0], dist_uv).xy;
- vec2 g_uv = texture(distortion[iz + 2], dist_uv).xy;
- vec2 b_uv = texture(distortion[iz + 4], dist_uv).xy;
+ // Do any transformation needed.
+ uv = transform_uv(uv, iz);
- // Do any transformation needed.
- uv = transform_uv(uv, iz);
- r_uv = transform_uv(r_uv, iz);
- g_uv = transform_uv(g_uv, iz);
- b_uv = transform_uv(b_uv, iz);
+ // Sample the source
+ vec3 colour = textureLod(source[iz], uv, mix(lod.x, lod.y, 0.5)).rgb;
- // Sample the source
- vec4 colour = textureLod(source[iz], uv, mix(lod.x, lod.y, 0.5));
- // Sample the source with distorted and chromatic-aberration corrected samples.
- vec4 colour = vec4(
- texture(source[iz], r_uv).r,
- texture(source[iz], g_uv).g,
- texture(source[iz], b_uv).b,
- 1);
+ colour = rgb_to_ycbcr(from_linear_to_srgb(colour));
- // Do colour correction here since there are no automatic conversion in hardware available.
@@ -577,10 +584,10 @@ index 9a09c03db..461aeb4ec 100644
+ imageStore(chroma, ivec2(offset.xy/2 + gl_GlobalInvocationID.xy), vec4(cbcr.x, cbcr.y, 0, 0));
}
diff --git a/src/xrt/compositor/util/comp_render.h b/src/xrt/compositor/util/comp_render.h
index e6fd072be..d0733b650 100644
index 579b91413..ad1b960cd 100644
--- a/src/xrt/compositor/util/comp_render.h
+++ b/src/xrt/compositor/util/comp_render.h
@@ -166,7 +166,8 @@ struct comp_render_dispatch_data
@@ -161,7 +161,8 @@ struct comp_render_dispatch_data
VkImage target_image;
//! Target image view for distortion.
@@ -590,7 +597,7 @@ index e6fd072be..d0733b650 100644
} cs;
};
@@ -432,7 +433,8 @@ comp_render_gfx_dispatch(struct render_gfx *render,
@@ -424,7 +425,8 @@ comp_render_gfx_dispatch(struct render_gfx *render,
static inline void
comp_render_cs_initial_init(struct comp_render_dispatch_data *data,
VkImage target_image,
@@ -600,7 +607,7 @@ index e6fd072be..d0733b650 100644
bool fast_path,
bool do_timewarp)
{
@@ -442,7 +444,8 @@ comp_render_cs_initial_init(struct comp_render_dispatch_data *data,
@@ -434,7 +436,8 @@ comp_render_cs_initial_init(struct comp_render_dispatch_data *data,
data->do_timewarp = do_timewarp;
data->cs.target_image = target_image;
@@ -610,7 +617,7 @@ index e6fd072be..d0733b650 100644
}
/*!
@@ -534,7 +537,8 @@ comp_render_cs_layer(struct render_compute *render,
@@ -522,7 +525,8 @@ comp_render_cs_layer(struct render_compute *render,
const struct xrt_pose *world_pose,
const struct xrt_pose *eye_pose,
const VkImage target_image,
@@ -621,10 +628,10 @@ index e6fd072be..d0733b650 100644
bool do_timewarp);
diff --git a/src/xrt/compositor/util/comp_render_cs.c b/src/xrt/compositor/util/comp_render_cs.c
index fc11a0521..3db6c8d2e 100644
index dbc2fec7e..c06dda63d 100644
--- a/src/xrt/compositor/util/comp_render_cs.c
+++ b/src/xrt/compositor/util/comp_render_cs.c
@@ -430,11 +430,12 @@ crc_clear_output(struct render_compute *render, const struct comp_render_dispatc
@@ -343,11 +343,12 @@ crc_clear_output(struct render_compute *render, const struct comp_render_dispatc
}
@@ -642,7 +649,7 @@ index fc11a0521..3db6c8d2e 100644
}
/*
@@ -480,14 +481,15 @@ crc_distortion_after_squash(struct render_compute *render, const struct comp_ren
@@ -391,14 +392,15 @@ crc_distortion_after_squash(struct render_compute *render, const struct comp_ren
target_viewport_datas[i] = viewport_data;
}
@@ -666,7 +673,7 @@ index fc11a0521..3db6c8d2e 100644
}
/// Fast path
@@ -559,7 +561,8 @@ crc_distortion_fast_path(struct render_compute *render,
@@ -470,7 +472,8 @@ crc_distortion_fast_path(struct render_compute *render,
src_image_views, //
src_norm_rects, //
d->cs.target_image, //
@@ -676,7 +683,7 @@ index fc11a0521..3db6c8d2e 100644
target_viewport_datas); //
} else {
render_compute_projection_timewarp( //
@@ -571,7 +574,8 @@ crc_distortion_fast_path(struct render_compute *render,
@@ -482,7 +485,8 @@ crc_distortion_fast_path(struct render_compute *render,
src_fovs, //
world_poses, //
d->cs.target_image, //
@@ -686,7 +693,7 @@ index fc11a0521..3db6c8d2e 100644
target_viewport_datas); //
}
}
@@ -592,7 +596,8 @@ comp_render_cs_layer(struct render_compute *render,
@@ -503,7 +507,8 @@ comp_render_cs_layer(struct render_compute *render,
const struct xrt_pose *world_pose,
const struct xrt_pose *eye_pose,
const VkImage target_image,
@@ -696,7 +703,7 @@ index fc11a0521..3db6c8d2e 100644
const struct render_viewport_data *target_view,
bool do_timewarp)
{
@@ -749,7 +754,8 @@ comp_render_cs_layer(struct render_compute *render,
@@ -660,7 +665,8 @@ comp_render_cs_layer(struct render_compute *render,
src_samplers, //
src_image_views, //
cur_image, //
@@ -706,7 +713,7 @@ index fc11a0521..3db6c8d2e 100644
target_view, //
do_timewarp); //
}
@@ -785,6 +791,7 @@ comp_render_cs_layers(struct render_compute *render,
@@ -696,6 +702,7 @@ comp_render_cs_layers(struct render_compute *render,
&view->eye_pose, //
view->image, //
view->cs.unorm_view, //
File diff suppressed because it is too large Load Diff
@@ -1,7 +1,7 @@
From d5337b1e4811aef804057e26d67aace90adc36e8 Mon Sep 17 00:00:00 2001
From 2be6264cd7091d593cfec71b7952ff2409ceae4d Mon Sep 17 00:00:00 2001
From: Patrick Nicolas <patricknicolas@laposte.net>
Date: Sun, 3 Nov 2024 13:40:00 +0100
Subject: [PATCH 08/11] store alpha channel in layer 1
Subject: [PATCH 07/11] store alpha channel in layer 1
---
src/xrt/compositor/shaders/clear.comp | 4 ++--
@@ -29,7 +29,7 @@ index 036da401a..db8e5178e 100644
+ imageStore(target, ivec3(offset.x + ix, offset.y + iy, 0), colour);
}
diff --git a/src/xrt/compositor/shaders/distortion.comp b/src/xrt/compositor/shaders/distortion.comp
index 461aeb4ec..237221a54 100644
index e1dd1cb58..9ce46fe6f 100644
--- a/src/xrt/compositor/shaders/distortion.comp
+++ b/src/xrt/compositor/shaders/distortion.comp
@@ -18,7 +18,7 @@ layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
@@ -50,7 +50,7 @@ index 461aeb4ec..237221a54 100644
const mat3 color_space = mat3(
// clang-format off
@@ -142,6 +142,7 @@ void main()
@@ -122,6 +122,7 @@ void main()
ivec2 offset = ivec2(ubo.views[iz].xy);
ivec2 extent = ivec2(ubo.views[iz].zw);
vec2 cbcrs[4];
@@ -58,7 +58,7 @@ index 461aeb4ec..237221a54 100644
for (int k = 0; k < 2; k += 1) {
uint iy = gl_GlobalInvocationID.y * 2 + k;
for (int j = 0; j < 2; j += 1) {
@@ -156,15 +157,16 @@ void main()
@@ -136,15 +137,16 @@ void main()
uv = transform_uv(uv, iz);
// Sample the source
@@ -78,7 +78,7 @@ index 461aeb4ec..237221a54 100644
}
}
}
@@ -172,5 +174,9 @@ void main()
@@ -152,5 +154,9 @@ void main()
return;
}
vec2 cbcr = mix(mix(cbcrs[0], cbcrs[1], 0.5), mix(cbcrs[2], cbcrs[3], 0.5), 0.5);
@@ -1,7 +1,7 @@
From dffeb683c92b6ab2fbbf240817e4087a134d997f Mon Sep 17 00:00:00 2001
From f5f2fafe497c688170e176ee4e47b9d9dce8ab7b Mon Sep 17 00:00:00 2001
From: Patrick Nicolas <patricknicolas@laposte.net>
Date: Wed, 19 Feb 2025 10:13:36 +0100
Subject: [PATCH 09/11] st/oxr: bind to dynamic role's profile
Subject: [PATCH 08/11] st/oxr: bind to dynamic role's profile
---
src/xrt/state_trackers/oxr/oxr_binding.c | 17 +++++++++++++++++
@@ -1,7 +1,7 @@
From 644f84e916d40d6341de91687a3dc9b0eecd13a4 Mon Sep 17 00:00:00 2001
From a906c4d2bc48306a60cd38ceef7dda9d3c7ab0ab Mon Sep 17 00:00:00 2001
From: Patrick Nicolas <patricknicolas@laposte.net>
Date: Thu, 27 Feb 2025 22:45:36 +0100
Subject: [PATCH 10/11] c/main: allow custom pacing app factory
Subject: [PATCH 09/11] c/main: allow custom pacing app factory
---
src/xrt/compositor/main/comp_compositor.c | 10 ++++++----
@@ -1,7 +1,7 @@
From f3dbf64ec2a45ac0e44a5d017b66d12fd8d63e77 Mon Sep 17 00:00:00 2001
From aab3a63932eafc7781d6ebbcbb3e825beb0ef4de Mon Sep 17 00:00:00 2001
From: Patrick Nicolas <patricknicolas@laposte.net>
Date: Sat, 15 Mar 2025 22:19:48 +0100
Subject: [PATCH 11/11] st/oxr: forward 0 refresh rate
Subject: [PATCH 10/11] st/oxr: forward 0 refresh rate
---
src/xrt/state_trackers/oxr/oxr_api_session.c | 6 +-----
@@ -0,0 +1,700 @@
From e3efcbec31cfc515be3316d51d9e65bd51f4fe07 Mon Sep 17 00:00:00 2001
From: Patrick Nicolas <patricknicolas@laposte.net>
Date: Mon, 2 Jun 2025 14:51:11 +0200
Subject: [PATCH 11/11] Replace distortion with pixel-aligned foveation
---
src/xrt/compositor/CMakeLists.txt | 2 +-
src/xrt/compositor/render/render_compute.c | 181 ++-----------------
src/xrt/compositor/render/render_interface.h | 33 ++--
src/xrt/compositor/render/render_resources.c | 71 +-------
src/xrt/compositor/shaders/distortion.comp | 134 ++++----------
src/xrt/compositor/util/comp_render_cs.c | 33 +---
6 files changed, 76 insertions(+), 378 deletions(-)
diff --git a/src/xrt/compositor/CMakeLists.txt b/src/xrt/compositor/CMakeLists.txt
index f1c54ed4d..a2f7ba5cc 100644
--- a/src/xrt/compositor/CMakeLists.txt
+++ b/src/xrt/compositor/CMakeLists.txt
@@ -115,7 +115,7 @@ if(XRT_HAVE_VULKAN)
${SHADER_HEADERS}
render/render_buffer.c
render/render_compute.c
- render/render_distortion.c
+ # render/render_distortion.c implemented in wivrn
render/render_gfx.c
render/render_interface.h
render/render_resources.c
diff --git a/src/xrt/compositor/render/render_compute.c b/src/xrt/compositor/render/render_compute.c
index fd04801d4..5cd5a1726 100644
--- a/src/xrt/compositor/render/render_compute.c
+++ b/src/xrt/compositor/render/render_compute.c
@@ -167,8 +167,8 @@ update_compute_shared_descriptor_set(struct vk_bundle *vk,
VkSampler src_samplers[XRT_MAX_VIEWS],
VkImageView src_image_views[XRT_MAX_VIEWS],
uint32_t distortion_binding,
- VkSampler distortion_samplers[3 * XRT_MAX_VIEWS],
- VkImageView distortion_image_views[3 * XRT_MAX_VIEWS],
+ VkDeviceSize foveation_size,
+ VkBuffer foveation_buffer,
uint32_t target_binding_y,
uint32_t target_binding_cbcr,
VkImageView target_image_view_y,
@@ -186,12 +186,11 @@ update_compute_shared_descriptor_set(struct vk_bundle *vk,
src_image_info[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
}
- VkDescriptorImageInfo distortion_image_info[3 * XRT_MAX_VIEWS];
- for (uint32_t i = 0; i < 3 * view_count; ++i) {
- distortion_image_info[i].sampler = distortion_samplers[i];
- distortion_image_info[i].imageView = distortion_image_views[i];
- distortion_image_info[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
- }
+ VkDescriptorBufferInfo foveation_buffer_info = {
+ .buffer = foveation_buffer,
+ .offset = 0,
+ .range = foveation_size,
+ };
VkDescriptorImageInfo target_image_y_info = {
.imageView = target_image_view_y,
@@ -222,9 +221,9 @@ update_compute_shared_descriptor_set(struct vk_bundle *vk,
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.dstSet = descriptor_set,
.dstBinding = distortion_binding,
- .descriptorCount = 3 * view_count,
- .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
- .pImageInfo = distortion_image_info,
+ .descriptorCount = 1,
+ .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
+ .pBufferInfo = &foveation_buffer_info,
},
{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
@@ -483,146 +482,6 @@ render_compute_layers(struct render_compute *render,
1); // groupCountZ
}
-void
-render_compute_projection_timewarp(struct render_compute *render,
- VkSampler src_samplers[XRT_MAX_VIEWS],
- VkImageView src_image_views[XRT_MAX_VIEWS],
- const struct xrt_normalized_rect src_norm_rects[XRT_MAX_VIEWS],
- const struct xrt_pose src_poses[XRT_MAX_VIEWS],
- const struct xrt_fov src_fovs[XRT_MAX_VIEWS],
- const struct xrt_pose new_poses[XRT_MAX_VIEWS],
- VkImage target_image,
- VkImageView target_image_view_y,
- VkImageView target_image_view_cbcr,
- const struct render_viewport_data views[XRT_MAX_VIEWS])
-{
- assert(render->r != NULL);
-
- struct vk_bundle *vk = vk_from_render(render);
- struct render_resources *r = render->r;
-
-
- /*
- * UBO
- */
-
- struct xrt_matrix_4x4 time_warp_matrix[XRT_MAX_VIEWS];
- for (uint32_t i = 0; i < render->r->view_count; ++i) {
- render_calc_time_warp_matrix( //
- &src_poses[i], //
- &src_fovs[i], //
- &new_poses[i], //
- &time_warp_matrix[i]); //
- }
-
- struct render_compute_distortion_ubo_data *data =
- (struct render_compute_distortion_ubo_data *)r->compute.distortion.ubo.mapped;
- for (uint32_t i = 0; i < render->r->view_count; ++i) {
- data->views[i] = views[i];
- data->pre_transforms[i] = r->distortion.uv_to_tanangle[i];
- data->transforms[i] = time_warp_matrix[i];
- data->post_transforms[i] = src_norm_rects[i];
- }
-
- /*
- * Source, target and distortion images.
- */
-
- VkImageSubresourceRange subresource_range = {
- .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
- .baseMipLevel = 0,
- .levelCount = VK_REMAINING_MIP_LEVELS,
- .baseArrayLayer = 0,
- .layerCount = VK_REMAINING_ARRAY_LAYERS,
- };
-
- vk_cmd_image_barrier_gpu_locked( //
- vk, //
- r->cmd, //
- target_image, //
- 0, //
- VK_ACCESS_SHADER_WRITE_BIT, //
- VK_IMAGE_LAYOUT_UNDEFINED, //
- VK_IMAGE_LAYOUT_GENERAL, //
- subresource_range); //
-
- VkSampler sampler = r->samplers.clamp_to_edge;
- VkSampler distortion_samplers[3 * XRT_MAX_VIEWS];
- for (uint32_t i = 0; i < render->r->view_count; ++i) {
- distortion_samplers[3 * i + 0] = sampler;
- distortion_samplers[3 * i + 1] = sampler;
- distortion_samplers[3 * i + 2] = sampler;
- }
-
- update_compute_shared_descriptor_set( //
- vk, //
- r->compute.src_binding, //
- src_samplers, //
- src_image_views, //
- r->compute.distortion_binding, //
- distortion_samplers, //
- r->distortion.image_views, //
- r->compute.target_binding_y, //
- r->compute.target_binding_cbcr, //
- target_image_view_y, //
- target_image_view_cbcr, //
- r->compute.ubo_binding, //
- r->compute.distortion.ubo.buffer, //
- VK_WHOLE_SIZE, //
- render->shared_descriptor_set, //
- render->r->view_count); //
-
- vk->vkCmdBindPipeline( //
- r->cmd, //
- VK_PIPELINE_BIND_POINT_COMPUTE, // pipelineBindPoint
- r->compute.distortion.timewarp_pipeline); // pipeline
-
- vk->vkCmdBindDescriptorSets( //
- r->cmd, //
- VK_PIPELINE_BIND_POINT_COMPUTE, // pipelineBindPoint
- r->compute.distortion.pipeline_layout, // layout
- 0, // firstSet
- 1, // descriptorSetCount
- &render->shared_descriptor_set, // pDescriptorSets
- 0, // dynamicOffsetCount
- NULL); // pDynamicOffsets
-
-
- uint32_t w = 0, h = 0;
- calc_dispatch_dims_views(views, render->r->view_count, &w, &h);
- assert(w != 0 && h != 0);
-
- vk->vkCmdDispatch( //
- r->cmd, //
- w, // groupCountX
- h, // groupCountY
- 2); // groupCountZ
-
- VkImageMemoryBarrier memoryBarrier = {
- .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
- .srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
- .dstAccessMask = VK_ACCESS_MEMORY_READ_BIT,
- .oldLayout = VK_IMAGE_LAYOUT_GENERAL,
- .newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
- .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
- .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
- .image = target_image,
- .subresourceRange = subresource_range,
- };
-
- vk->vkCmdPipelineBarrier( //
- r->cmd, //
- VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, //
- VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, //
- 0, //
- 0, //
- NULL, //
- 0, //
- NULL, //
- 1, //
- &memoryBarrier); //
-}
-
void
render_compute_projection(struct render_compute *render,
VkSampler src_samplers[XRT_MAX_VIEWS],
@@ -673,22 +532,14 @@ render_compute_projection(struct render_compute *render,
VK_IMAGE_LAYOUT_GENERAL, //
subresource_range); //
- VkSampler sampler = r->samplers.clamp_to_edge;
- VkSampler distortion_samplers[3 * XRT_MAX_VIEWS];
- for (uint32_t i = 0; i < render->r->view_count; ++i) {
- distortion_samplers[3 * i + 0] = sampler;
- distortion_samplers[3 * i + 1] = sampler;
- distortion_samplers[3 * i + 2] = sampler;
- }
-
update_compute_shared_descriptor_set( //
vk, //
r->compute.src_binding, //
src_samplers, //
src_image_views, //
r->compute.distortion_binding, //
- distortion_samplers, //
- r->distortion.image_views, //
+ VK_WHOLE_SIZE, //
+ r->distortion.buffer, //
r->compute.target_binding_y, //
r->compute.target_binding_cbcr, //
target_image_view_y, //
@@ -804,13 +655,9 @@ render_compute_clear(struct render_compute *render,
VkSampler sampler = r->samplers.mock;
VkSampler src_samplers[XRT_MAX_VIEWS];
VkImageView src_image_views[XRT_MAX_VIEWS];
- VkSampler distortion_samplers[3 * XRT_MAX_VIEWS];
for (uint32_t i = 0; i < render->r->view_count; ++i) {
src_samplers[i] = sampler;
src_image_views[i] = r->mock.color.image_view;
- distortion_samplers[3 * i + 0] = sampler;
- distortion_samplers[3 * i + 1] = sampler;
- distortion_samplers[3 * i + 2] = sampler;
}
update_compute_shared_descriptor_set( //
@@ -819,8 +666,8 @@ render_compute_clear(struct render_compute *render,
src_samplers, //
src_image_views, //
r->compute.distortion_binding, //
- distortion_samplers, //
- r->distortion.image_views, //
+ VK_WHOLE_SIZE, //
+ r->distortion.buffer, //
r->compute.target_binding_y, //
r->compute.target_binding_cbcr, //
target_image_view_y, //
diff --git a/src/xrt/compositor/render/render_interface.h b/src/xrt/compositor/render/render_interface.h
index 2f8ce5287..d74ec78dd 100644
--- a/src/xrt/compositor/render/render_interface.h
+++ b/src/xrt/compositor/render/render_interface.h
@@ -74,12 +74,8 @@ extern "C" {
#define RENDER_MAX_LAYER_RUNS_SIZE (XRT_MAX_VIEWS)
#define RENDER_MAX_LAYER_RUNS_COUNT(RENDER_RESOURCES) (RENDER_RESOURCES->view_count)
-//! Distortion image dimension in pixels
-#define RENDER_DISTORTION_IMAGE_DIMENSIONS (128)
-
-//! How many distortion images we have, one for each channel (3 rgb) and per view.
-#define RENDER_DISTORTION_IMAGES_SIZE (3 * XRT_MAX_VIEWS)
-#define RENDER_DISTORTION_IMAGES_COUNT(RENDER_RESOURCES) (3 * RENDER_RESOURCES->view_count)
+//! Foveation buffer dimension in pixels (including past-the end pixel)
+#define RENDER_FOVEATION_BUFFER_DIMENSIONS (4096 + 1)
//! The binding that the layer projection and quad shader have their UBO on.
#define RENDER_BINDING_LAYER_SHARED_UBO 0
@@ -519,9 +515,6 @@ struct render_resources
//! Doesn't depend on target so is static.
VkPipeline pipeline;
- //! Doesn't depend on target so is static.
- VkPipeline timewarp_pipeline;
-
//! Target info.
struct render_buffer ubo;
} distortion;
@@ -543,17 +536,11 @@ struct render_resources
//! Transform to go from UV to tangle angles.
struct xrt_normalized_rect uv_to_tanangle[XRT_MAX_VIEWS];
- //! Backing memory to distortion images.
- VkDeviceMemory device_memories[RENDER_DISTORTION_IMAGES_SIZE];
-
- //! Distortion images.
- VkImage images[RENDER_DISTORTION_IMAGES_SIZE];
+ //! Backing memory to foveation buffers.
+ VkDeviceMemory device_memory;
- //! The views into the distortion images.
- VkImageView image_views[RENDER_DISTORTION_IMAGES_SIZE];
-
- //! Whether distortion images have been pre-rotated 90 degrees.
- bool pre_rotated;
+ //! Foveation buffer.
+ VkBuffer buffer;
} distortion;
};
@@ -1298,6 +1285,14 @@ struct render_compute_distortion_ubo_data
struct xrt_matrix_4x4 transforms[XRT_MAX_VIEWS];
};
+struct render_compute_distortion_foveation_data
+{
+ // For each output pixel: index of the first pixel to read.
+ // contains 1 additional value at the end for past-the end pixel
+ uint32_t x[XRT_MAX_VIEWS * RENDER_FOVEATION_BUFFER_DIMENSIONS];
+ uint32_t y[XRT_MAX_VIEWS * RENDER_FOVEATION_BUFFER_DIMENSIONS];
+};
+
/*!
* Init struct and create resources needed for compute rendering.
*
diff --git a/src/xrt/compositor/render/render_resources.c b/src/xrt/compositor/render/render_resources.c
index 5b9addd59..7d4d9cddb 100644
--- a/src/xrt/compositor/render/render_resources.c
+++ b/src/xrt/compositor/render/render_resources.c
@@ -258,8 +258,8 @@ create_compute_distortion_descriptor_set_layout(struct vk_bundle *vk,
},
{
.binding = distortion_binding,
- .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
- .descriptorCount = 6,
+ .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
+ .descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
},
{
@@ -309,12 +309,6 @@ struct compute_layer_params
uint32_t image_array_size;
};
-struct compute_distortion_params
-{
- uint32_t distortion_texel_count;
- VkBool32 do_timewarp;
-};
-
XRT_CHECK_RESULT static VkResult
create_compute_layer_pipeline(struct vk_bundle *vk,
VkPipelineCache pipeline_cache,
@@ -359,35 +353,15 @@ create_compute_distortion_pipeline(struct vk_bundle *vk,
VkPipelineCache pipeline_cache,
VkShaderModule shader,
VkPipelineLayout pipeline_layout,
- const struct compute_distortion_params *params,
VkPipeline *out_compute_pipeline)
{
-#define ENTRY(ID, FIELD) \
- { \
- .constantID = ID, \
- .offset = offsetof(struct compute_distortion_params, FIELD), \
- sizeof(params->FIELD), \
- }
-
- VkSpecializationMapEntry entries[2] = {
- ENTRY(0, distortion_texel_count),
- ENTRY(1, do_timewarp),
- };
-#undef ENTRY
-
- VkSpecializationInfo specialization_info = {
- .mapEntryCount = ARRAY_SIZE(entries),
- .pMapEntries = entries,
- .dataSize = sizeof(*params),
- .pData = params,
- };
return vk_create_compute_pipeline( //
vk, // vk_bundle
pipeline_cache, // pipeline_cache
shader, // shader
pipeline_layout, // pipeline_layout
- &specialization_info, // specialization_info
+ NULL, // specialization_info
out_compute_pipeline); // out_compute_pipeline
}
@@ -849,9 +823,9 @@ render_resources_init(struct render_resources *r,
struct vk_descriptor_pool_info compute_pool_info = {
.uniform_per_descriptor_count = 1,
// layer images
- .sampler_per_descriptor_count = r->compute.layer.image_array_size + RENDER_DISTORTION_IMAGES_COUNT(r),
+ .sampler_per_descriptor_count = r->compute.layer.image_array_size,
.storage_image_per_descriptor_count = 1,
- .storage_buffer_per_descriptor_count = 0,
+ .storage_buffer_per_descriptor_count = 1,
.descriptor_count = compute_descriptor_count,
.freeable = false,
};
@@ -971,39 +945,16 @@ render_resources_init(struct render_resources *r,
VK_NAME_PIPELINE_LAYOUT(vk, r->compute.distortion.pipeline_layout,
"render_resources compute distortion pipeline layout");
- struct compute_distortion_params distortion_params = {
- .distortion_texel_count = RENDER_DISTORTION_IMAGE_DIMENSIONS,
- .do_timewarp = false,
- };
-
ret = create_compute_distortion_pipeline( //
vk, // vk_bundle
r->pipeline_cache, // pipeline_cache
r->shaders->distortion_comp, // shader
r->compute.distortion.pipeline_layout, // pipeline_layout
- &distortion_params, // params
&r->compute.distortion.pipeline); // out_compute_pipeline
VK_CHK_WITH_RET(ret, "create_compute_distortion_pipeline", false);
VK_NAME_PIPELINE(vk, r->compute.distortion.pipeline, "render_resources compute distortion pipeline");
- struct compute_distortion_params distortion_timewarp_params = {
- .distortion_texel_count = RENDER_DISTORTION_IMAGE_DIMENSIONS,
- .do_timewarp = true,
- };
-
- ret = create_compute_distortion_pipeline( //
- vk, // vk_bundle
- r->pipeline_cache, // pipeline_cache
- r->shaders->distortion_comp, // shader
- r->compute.distortion.pipeline_layout, // pipeline_layout
- &distortion_timewarp_params, // params
- &r->compute.distortion.timewarp_pipeline); // out_compute_pipeline
- VK_CHK_WITH_RET(ret, "create_compute_distortion_pipeline", false);
-
- VK_NAME_PIPELINE(vk, r->compute.distortion.timewarp_pipeline,
- "render_resources compute distortion timewarp pipeline");
-
size_t distortion_ubo_size = sizeof(struct render_compute_distortion_ubo_data);
ret = render_buffer_init( //
@@ -1056,15 +1007,8 @@ render_resources_init(struct render_resources *r,
* Compute distortion textures, not created until later.
*/
- for (uint32_t i = 0; i < RENDER_DISTORTION_IMAGES_COUNT(r); i++) {
- r->distortion.image_views[i] = VK_NULL_HANDLE;
- }
- for (uint32_t i = 0; i < RENDER_DISTORTION_IMAGES_COUNT(r); i++) {
- r->distortion.images[i] = VK_NULL_HANDLE;
- }
- for (uint32_t i = 0; i < RENDER_DISTORTION_IMAGES_COUNT(r); i++) {
- r->distortion.device_memories[i] = VK_NULL_HANDLE;
- }
+ r->distortion.buffer = VK_NULL_HANDLE;
+ r->distortion.device_memory = VK_NULL_HANDLE;
/*
@@ -1141,7 +1085,6 @@ render_resources_fini(struct render_resources *r)
D(DescriptorSetLayout, r->compute.distortion.descriptor_set_layout);
D(Pipeline, r->compute.distortion.pipeline);
- D(Pipeline, r->compute.distortion.timewarp_pipeline);
D(PipelineLayout, r->compute.distortion.pipeline_layout);
D(Pipeline, r->compute.clear.pipeline);
diff --git a/src/xrt/compositor/shaders/distortion.comp b/src/xrt/compositor/shaders/distortion.comp
index 9ce46fe6f..f3be617bd 100644
--- a/src/xrt/compositor/shaders/distortion.comp
+++ b/src/xrt/compositor/shaders/distortion.comp
@@ -7,17 +7,17 @@
#include "srgb.inc.glsl"
-
-// The size of the distortion texture dimensions in texels.
-layout(constant_id = 0) const int distortion_texel_count = 2;
-
-// Should we do timewarp.
-layout(constant_id = 1) const bool do_timewarp = false;
-
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
+#define MAX_DIM 4097
+
layout(set = 0, binding = 0) uniform sampler2D source[2];
-layout(set = 0, binding = 1) uniform sampler2D distortion[6];
+layout(set = 0, binding = 1, std430) buffer restrict Foveation
+{
+ uint x[2*MAX_DIM];
+ uint y[2*MAX_DIM];
+} foveation;
+
layout(set = 0, binding = 2) uniform writeonly restrict image2DArray luma;
layout(set = 0, binding = 3, std140) uniform restrict Config
{
@@ -41,109 +41,40 @@ vec3 rgb_to_ycbcr(vec3 color)
return transpose(color_space) * color + vec3(0, 0.5, 0.5);
}
-vec2 position_to_uv(ivec2 extent, uint ix, uint iy)
-{
- // Turn the index into floating point.
- vec2 xy = vec2(float(ix), float(iy));
-
- // The inverse of the extent of the target image is the pixel size in [0 .. 1] space.
- vec2 extent_pixel_size = vec2(1.0 / float(extent.x), 1.0 / float(extent.y));
-
- // Per-target pixel we move the size of the pixels.
- vec2 dist_uv = xy * extent_pixel_size;
-
- // Emulate a triangle sample position by offset half target pixel size.
- dist_uv = dist_uv + extent_pixel_size / 2.0;
-
-
- // To correctly sample we need to put position (0, 0) in the
- // middle of the (0, 0) texel in the distortion textures. That's why we
- // offset with half the texel size, pushing all samples into the middle
- // of each texels, a kin to a vertex buffer. We need to put uv coord
- // (1, 1) in the middle of the last texel, that pixel is (size - 1)
- // texels away from the first texel. So we need to scale [0 .. 1] to
- // [0 .. size - 1].
-
-#define DIM (float(distortion_texel_count))
-#define STRETCH ((DIM - 1.0) / DIM)
-#define OFFSET (1.0 / (DIM * 2.0))
-
- dist_uv = (dist_uv * STRETCH) + OFFSET;
-
- return dist_uv;
-}
-
-vec2 transform_uv_subimage(vec2 uv, uint iz)
-{
- vec2 values = uv;
-
- // To deal with OpenGL flip and sub image view.
- values.xy = values.xy * ubo.post_transform[iz].zw + ubo.post_transform[iz].xy;
-
- // Ready to be used.
- return values.xy;
-}
-
-vec2 transform_uv_timewarp(vec2 uv, uint iz)
-{
- vec4 values = vec4(uv, -1, 1);
-
- // From uv to tan angle (tangent space).
- values.xy = values.xy * ubo.pre_transform[iz].zw + ubo.pre_transform[iz].xy;
- values.y = -values.y; // Flip to OpenXR coordinate system.
-
- // Timewarp.
- values = ubo.transform[iz] * values;
- values.xy = values.xy * (1.0 / max(values.w, 0.00001));
-
- // From [-1, 1] to [0, 1]
- values.xy = values.xy * 0.5 + 0.5;
-
- // To deal with OpenGL flip and sub image view.
- values.xy = values.xy * ubo.post_transform[iz].zw + ubo.post_transform[iz].xy;
-
- // Done.
- return values.xy;
-}
-
-vec2 transform_uv(vec2 uv, uint iz)
-{
- if (do_timewarp) {
- return transform_uv_timewarp(uv, iz);
- } else {
- return transform_uv_subimage(uv, iz);
- }
-}
-
void main()
{
uint iz = gl_GlobalInvocationID.z;
ivec2 offset = ivec2(ubo.views[iz].xy);
ivec2 extent = ivec2(ubo.views[iz].zw);
- vec2 cbcrs[4];
- vec4 alpha;
+ vec3 cbcra = vec3(0);
for (int k = 0; k < 2; k += 1) {
uint iy = gl_GlobalInvocationID.y * 2 + k;
+ uint ymin = foveation.y[MAX_DIM * iz + iy];
+ uint ymax = foveation.y[MAX_DIM * iz + iy + 1];
+ if (ymin > ymax)
+ {
+ uint tmp = ymin;
+ ymin = ymax;
+ ymax = tmp;
+ }
for (int j = 0; j < 2; j += 1) {
uint ix = gl_GlobalInvocationID.x * 2 + j;
- vec2 dist_uv = position_to_uv(extent, ix, iy);
+ uint xmin = foveation.x[MAX_DIM * iz + ix];
+ uint xmax = foveation.x[MAX_DIM * iz + ix + 1];
- vec2 uv = texture(distortion[iz + 0], dist_uv).xy;
- vec2 lod = texture(distortion[iz + 2], dist_uv).xy;
-
- // Do any transformation needed.
- uv = transform_uv(uv, iz);
-
- // Sample the source
- vec4 colour = textureLod(source[iz], uv, mix(lod.x, lod.y, 0.5));
-
- colour.rgb = rgb_to_ycbcr(from_linear_to_srgb(colour.rgb));
+ vec4 colour = vec4(0);
+ for (uint y = ymin ; y < ymax; y += 1) {
+ for (uint x = xmin ; x < xmax; x += 1) {
+ colour += texelFetch(source[iz], ivec2(x, y), 0);
+ }
+ }
+ colour /= (xmax - xmin) * (ymax - ymin);
+ colour.xyz = rgb_to_ycbcr(from_linear_to_srgb(colour.rgb));
- int i = k * 2 + j;
- cbcrs[i] = colour.yz;
- alpha[i] = colour.a;
+ cbcra.xy += colour.yz;
+ cbcra.z += colour.a;
if (ix < extent.x && iy < extent.y) {
imageStore(luma, ivec3(offset.x + ix, offset.y + iy, 0), vec4(colour.x));
@@ -153,10 +84,7 @@ void main()
if (gl_GlobalInvocationID.x >= extent.x || gl_GlobalInvocationID.y >= extent.y) {
return;
}
- vec2 cbcr = mix(mix(cbcrs[0], cbcrs[1], 0.5), mix(cbcrs[2], cbcrs[3], 0.5), 0.5);
- imageStore(chroma, ivec3(offset.xy/2 + gl_GlobalInvocationID.xy, 0), vec4(cbcr.x, cbcr.y, 0, 0));
-
+ imageStore(chroma, ivec3(offset.xy/2 + gl_GlobalInvocationID.xy, 0), vec4(cbcra.x, cbcra.y, 0, 0) / 4);
+ imageStore(luma, ivec3(offset.xy/2 + gl_GlobalInvocationID.xy, 1), vec4(cbcra.z, 0, 0, 0) / 4);
imageStore(chroma, ivec3(offset.xy/2 + gl_GlobalInvocationID.xy, 1), vec4(0.5, 0.5, 0, 0));
- alpha = vec4(mix(mix(alpha[0], alpha[1], 0.5), mix(alpha[2], alpha[3], 0.5), 0.5));
- imageStore(luma, ivec3(offset.xy/2 + gl_GlobalInvocationID.xy, 1), alpha);
}
diff --git a/src/xrt/compositor/util/comp_render_cs.c b/src/xrt/compositor/util/comp_render_cs.c
index c06dda63d..a4934890f 100644
--- a/src/xrt/compositor/util/comp_render_cs.c
+++ b/src/xrt/compositor/util/comp_render_cs.c
@@ -465,30 +465,15 @@ crc_distortion_fast_path(struct render_compute *render,
world_poses[i] = world_pose;
}
- if (!d->do_timewarp) {
- render_compute_projection( //
- render, //
- src_samplers, //
- src_image_views, //
- src_norm_rects, //
- d->cs.target_image, //
- d->cs.target_unorm_view_y, //
- d->cs.target_unorm_view_cbcr, //
- target_viewport_datas); //
- } else {
- render_compute_projection_timewarp( //
- render, //
- src_samplers, //
- src_image_views, //
- src_norm_rects, //
- src_poses, //
- src_fovs, //
- world_poses, //
- d->cs.target_image, //
- d->cs.target_unorm_view_y, //
- d->cs.target_unorm_view_cbcr, //
- target_viewport_datas); //
- }
+ render_compute_projection( //
+ render, //
+ src_samplers, //
+ src_image_views, //
+ src_norm_rects, //
+ d->cs.target_image, //
+ d->cs.target_unorm_view_y, //
+ d->cs.target_unorm_view_cbcr, //
+ target_viewport_datas); //
}
--
2.49.0
+1 -8
View File
@@ -97,6 +97,7 @@ if (WIVRN_BUILD_SERVER)
driver/wivrn_eye_tracker.cpp
driver/wivrn_fb_face2_tracker.cpp
driver/wivrn_htc_face_tracker.cpp
driver/wivrn_generic_tracker.cpp
driver/wivrn_foveation.cpp
driver/pose_list.cpp
driver/view_list.cpp
@@ -106,8 +107,6 @@ if (WIVRN_BUILD_SERVER)
driver/xrt_cast.cpp
utils/wivrn_vk_bundle.cpp
${WIVRN_SHADER_HEADERS}
)
target_compile_features(wivrn-server PRIVATE cxx_std_20)
target_compile_definitions(wivrn-server PRIVATE VULKAN_HPP_NO_CONSTRUCTORS)
@@ -189,12 +188,6 @@ if (WIVRN_BUILD_SERVER)
target_link_libraries(wivrn-server PUBLIC wivrn-server-dbus)
target_link_libraries(wivrn-server PUBLIC PkgConfig::libnotify)
include(CompileGLSL)
file(GLOB VULKAN_SHADERS CONFIGURE_DEPENDS "shaders/*.glsl")
target_sources(wivrn-server PRIVATE ${VULKAN_SHADERS})
wivrn_compile_glsl(wivrn-server ${VULKAN_SHADERS})
target_link_libraries(
wivrn-server
PRIVATE
-1
View File
@@ -6,4 +6,3 @@ Type=simple
ExecStart=@CMAKE_INSTALL_PREFIX@/bin/wivrn-server --application
Restart=on-failure
RestartSec=0
PrivateTmp=true
+46 -34
View File
@@ -109,6 +109,9 @@ static void destroy_images(struct wivrn_comp_target * cn)
if (cn->images == nullptr)
return;
if (cn->wivrn_bundle)
cn->wivrn_bundle->device.waitIdle();
cn->psc.status = 1;
cn->psc.status.notify_all();
cn->encoder_threads.clear();
@@ -135,7 +138,9 @@ static void create_encoders(wivrn_comp_target * cn)
to_headset::video_stream_description & desc = cn->desc;
desc.width = cn->width;
desc.height = cn->height;
desc.foveation = cn->cnx.set_foveated_size(desc.width, desc.height);
const auto & hmd = cn->cnx.get_hmd().hmd;
desc.defoveated_width = hmd->views[0].display.w_pixels * 2;
desc.defoveated_height = hmd->views[0].display.h_pixels;
std::map<int, std::vector<std::shared_ptr<video_encoder>>> thread_params;
@@ -316,11 +321,8 @@ static bool comp_wivrn_init_post_vulkan(struct comp_target * ct, uint32_t prefer
U_LOG_E("Failed to create video encoder: %s", e.what());
return false;
}
if (cn->cnx.has_dynamic_foveation())
{
cn->foveation_renderer = std::make_unique<wivrn_foveation_renderer>(*cn->wivrn_bundle, cn->command_pool);
}
cn->cnx.set_foveated_size(cn->c->settings.preferred.width, cn->c->settings.preferred.height);
cn->foveation.emplace(*cn->wivrn_bundle, *cn->cnx.get_hmd().hmd);
return true;
}
@@ -609,7 +611,7 @@ static VkResult comp_wivrn_present(struct comp_target * ct,
#endif
auto & view_info = cn->psc.view_info;
view_info.foveation = cn->cnx.get_foveation_parameters();
view_info.foveation = cn->foveation->get_parameters();
view_info.display_time = cn->cnx.get_offset().to_headset(info.predicted_display_time);
if (view_info.alpha != do_alpha)
cn->pacer.reset();
@@ -651,16 +653,47 @@ static void comp_wivrn_flush(struct comp_target * ct)
r->StartFrameCapture(NULL, NULL);
#endif
vk::CommandBuffer cmd;
// apply foveation for current frame
if (cn->cnx.apply_dynamic_foveation())
// foveation renderer already signaled the semaphore; nothing to do
return;
if (cn->c->base.frame_params.one_projection_layer_fast_path)
{
const auto & data = cn->c->base.layer_accum.layers[0].data;
const auto & hmd = cn->cnx.get_hmd().hmd;
xrt_rect rect[] = {data.proj.v[0].sub.rect, data.proj.v[1].sub.rect};
xrt_fov fov[] = {data.proj.v[0].fov, data.proj.v[1].fov};
cmd = cn->foveation->update_foveation_buffer(
ct->c->nr.distortion.buffer,
data.flip_y,
rect,
fov);
}
else
{
const auto & hmd = cn->cnx.get_hmd().hmd;
xrt_rect rect[] = {
{.extent = {
.w = int(hmd->views[0].display.w_pixels),
.h = int(hmd->views[0].display.h_pixels),
}},
{.extent = {
.w = int(hmd->views[1].display.w_pixels),
.h = int(hmd->views[1].display.h_pixels),
}},
};
cmd = cn->foveation->update_foveation_buffer(
ct->c->nr.distortion.buffer,
false,
rect,
hmd->distortion.fov);
}
struct vk_bundle * vk = get_vk(cn);
vk::Semaphore sem(cn->semaphores.present_complete);
vk::SubmitInfo submit_info{
.commandBufferCount = cmd ? 1u : 0,
.pCommandBuffers = &cmd,
.signalSemaphoreCount = 1,
.pSignalSemaphores = &sem,
};
@@ -753,14 +786,14 @@ static xrt_result_t comp_wivrn_request_refresh_rate(struct comp_target * ct, flo
wivrn_comp_target::~wivrn_comp_target()
{
if (wivrn_bundle)
wivrn_bundle->device.waitIdle();
destroy_images(this);
}
static void comp_wivrn_destroy(struct comp_target * ct)
{
delete (struct wivrn_comp_target *)ct;
auto cn = (struct wivrn_comp_target *)ct;
destroy_images(cn);
cn->self = nullptr;
}
static void comp_wivrn_info_gpu(struct comp_target * ct, int64_t frame_id, int64_t gpu_start_ns, int64_t gpu_end_ns, int64_t when_ns)
@@ -800,27 +833,6 @@ void wivrn_comp_target::set_bitrate(int bitrate_bps)
}
}
void wivrn_comp_target::render_dynamic_foveation(std::array<to_headset::foveation_parameter, 2> foveation)
{
assert(foveation_renderer);
vk::Semaphore sem(semaphores.present_complete);
vk::SubmitInfo submit_info{
.commandBufferCount = 1,
.pCommandBuffers = &*foveation_renderer->cmd_buf,
.signalSemaphoreCount = 1,
.pSignalSemaphores = &sem,
};
foveation_renderer->render_distortion_images(foveation, c->nr.distortion.images, c->nr.distortion.image_views);
{
scoped_lock lock(c->base.vk.queue_mutex);
wivrn_bundle->queue.submit(submit_info);
}
}
void wivrn_comp_target::set_refresh_rate(float refresh_rate_hz)
{
U_LOG_I("Refresh rate change from %.0f to %.0f", desc.fps, refresh_rate_hz);
+2 -3
View File
@@ -78,6 +78,7 @@ struct pseudo_swapchain
struct wivrn_comp_target : public comp_target
{
std::shared_ptr<wivrn_comp_target> self;
to_headset::video_stream_description desc{};
wivrn_pacer pacer;
@@ -98,7 +99,7 @@ struct wivrn_comp_target : public comp_target
std::vector<std::shared_ptr<video_encoder>> encoders;
wivrn::wivrn_session & cnx;
std::unique_ptr<wivrn_foveation_renderer> foveation_renderer = nullptr;
std::optional<wivrn_foveation> foveation;
std::atomic<float> requested_refresh_rate;
@@ -109,8 +110,6 @@ struct wivrn_comp_target : public comp_target
void reset_encoders();
void set_bitrate(int bitrate_bps);
void render_dynamic_foveation(std::array<to_headset::foveation_parameter, 2> foveation);
void set_refresh_rate(float);
};
+1
View File
@@ -234,6 +234,7 @@ static input_data map_input(device_id id)
return {WIVRN_CONTROLLER_THUMBREST_FORCE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
case device_id::RIGHT_STYLUS_FORCE:
return {WIVRN_CONTROLLER_STYLUS_FORCE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
default:
break;
}
throw std::range_error("bad input id " + std::to_string((int)id));
+297 -210
View File
@@ -1,6 +1,7 @@
/*
* WiVRn VR streaming
* Copyright (C) 2024 galister <galister@librevr.org>
* 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
@@ -17,6 +18,7 @@
*/
#include "render/render_interface.h"
#include "vk/vk_mini_helpers.h"
#include "wivrn_foveation.h"
@@ -29,218 +31,113 @@
#include <array>
#include <cmath>
#include <map>
#include <ranges>
#include <vulkan/vulkan_raii.hpp>
#include <vulkan/vulkan_structs.hpp>
#include <openxr/openxr.h>
extern const std::map<std::string, std::vector<uint32_t>> shaders;
namespace wivrn
bool render_distortion_images_ensure(struct render_resources * r,
struct vk_bundle * vk,
struct xrt_device * xdev,
bool pre_rotate)
{
const uint32_t dispatch_group_count = RENDER_DISTORTION_IMAGE_DIMENSIONS / 8;
struct FoveationParamsPcs
{
float a[2];
float b[2];
float scale[2];
float center[2];
};
static const std::array pool_sizes =
{
vk::DescriptorPoolSize{
.type = vk::DescriptorType::eStorageImage,
.descriptorCount = 4,
}};
static const std::array<vk::DescriptorSetLayoutBinding, 2> layout_bindings{
vk::DescriptorSetLayoutBinding{.binding = 0,
.descriptorType = vk::DescriptorType::eStorageImage,
.descriptorCount = 1,
.stageFlags = vk::ShaderStageFlagBits::eCompute},
vk::DescriptorSetLayoutBinding{.binding = 1,
.descriptorType = vk::DescriptorType::eStorageImage,
.descriptorCount = 1,
.stageFlags = vk::ShaderStageFlagBits::eCompute},
};
wivrn_foveation_renderer::wivrn_foveation_renderer(wivrn_vk_bundle & vk, vk::raii::CommandPool & cmd_pool) :
vk(vk),
dp(vk.device,
vk::DescriptorPoolCreateInfo{
.flags = vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet,
.maxSets = pool_sizes[0].descriptorCount,
.poolSizeCount = pool_sizes.size(),
.pPoolSizes = pool_sizes.data(),
}),
ds_layout(vk.device, vk::DescriptorSetLayoutCreateInfo{.bindingCount = layout_bindings.size(), .pBindings = layout_bindings.data()})
{
cmd_buf = std::move(vk.device.allocateCommandBuffers(
{.commandPool = *cmd_pool,
.commandBufferCount = 1})[0]);
// Pipeline layout
if (r->distortion.buffer == VK_NULL_HANDLE)
{
vk::PushConstantRange push_constant_range{
.stageFlags = vk::ShaderStageFlagBits::eCompute,
.offset = 0,
.size = sizeof(FoveationParamsPcs),
};
layout = vk.device.createPipelineLayout({
.setLayoutCount = 1,
.pSetLayouts = &*ds_layout,
.pushConstantRangeCount = 1,
.pPushConstantRanges = &push_constant_range,
});
return vk_buffer_init(vk,
sizeof(render_compute_distortion_foveation_data),
VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
&r->distortion.buffer,
&r->distortion.device_memory);
}
// Pipeline
{
auto & spirv = shaders.at("foveate.comp");
vk::raii::ShaderModule shader(vk.device, {
.codeSize = spirv.size() * sizeof(uint32_t),
.pCode = spirv.data(),
});
float one_over_dim = 1.0 / (RENDER_DISTORTION_IMAGE_DIMENSIONS - 1);
vk::SpecializationMapEntry specMapEntry{
.constantID = 0,
.offset = 0,
.size = sizeof(float),
};
vk::SpecializationInfo specInfo{
.mapEntryCount = 1,
.pMapEntries = &specMapEntry,
.dataSize = sizeof(float),
.pData = &one_over_dim,
};
pipeline = vk::raii::Pipeline(vk.device, nullptr, vk::ComputePipelineCreateInfo{
.stage = {
.stage = vk::ShaderStageFlagBits::eCompute,
.module = *shader,
.pName = "main",
.pSpecializationInfo = &specInfo,
},
.layout = *layout,
});
}
std::array<vk::DescriptorSetLayout, 2> layouts = {*ds_layout, *ds_layout};
auto my_ds = vk.device.allocateDescriptorSets({
.descriptorPool = *dp,
.descriptorSetCount = 2,
.pSetLayouts = layouts.data(),
});
ds = {
my_ds[0].release(),
my_ds[1].release(),
};
return true;
}
void wivrn_foveation_renderer::render_distortion_images(std::array<to_headset::foveation_parameter, 2> foveations, const VkImage * images, const VkImageView * image_views)
void render_distortion_images_fini(struct render_resources * r)
{
cmd_buf.reset();
cmd_buf.begin(vk::CommandBufferBeginInfo{});
// images: left position, right position, left derivate, right derivate
std::array<vk::ImageMemoryBarrier, 4> im_barriers;
im_barriers.fill({
.srcAccessMask = vk::AccessFlagBits::eNone,
.dstAccessMask = vk::AccessFlagBits::eMemoryWrite,
.oldLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
.newLayout = vk::ImageLayout::eGeneral,
.subresourceRange = {.aspectMask = vk::ImageAspectFlagBits::eColor,
.baseMipLevel = 0,
.levelCount = 1,
.baseArrayLayer = 0,
.layerCount = 1},
});
for (size_t i = 0; i < im_barriers.size(); ++i)
im_barriers[i].image = vk::Image(images[i]);
cmd_buf.pipelineBarrier(
vk::PipelineStageFlagBits::eTopOfPipe,
vk::PipelineStageFlagBits::eComputeShader,
{},
nullptr,
nullptr,
im_barriers);
// Monado's distortion shader is patched to read red as position and green as derivate
for (int eye = 0; eye < 2; ++eye)
{
// Descriptor set
std::array image_info{
vk::DescriptorImageInfo{
.imageView = vk::ImageView(image_views[eye]),
.imageLayout = vk::ImageLayout::eGeneral,
},
vk::DescriptorImageInfo{
.imageView = vk::ImageView(image_views[eye + 2]),
.imageLayout = vk::ImageLayout::eGeneral,
},
};
vk.device.updateDescriptorSets({
vk::WriteDescriptorSet{
.dstSet = ds[eye],
.dstBinding = 0,
.descriptorCount = 1,
.descriptorType = vk::DescriptorType::eStorageImage,
.pImageInfo = &image_info[0],
},
vk::WriteDescriptorSet{
.dstSet = ds[eye],
.dstBinding = 1,
.descriptorCount = 1,
.descriptorType = vk::DescriptorType::eStorageImage,
.pImageInfo = &image_info[1],
},
},
nullptr);
auto foveation = foveations[eye];
FoveationParamsPcs f_params{
.a = {foveation.x.a, foveation.y.a},
.b = {foveation.x.b, foveation.y.b},
.scale = {foveation.x.scale, foveation.y.scale},
.center = {foveation.x.center, foveation.y.center},
};
cmd_buf.bindPipeline(vk::PipelineBindPoint::eCompute, *pipeline);
cmd_buf.bindDescriptorSets(vk::PipelineBindPoint::eCompute, *layout, 0, ds[eye], {});
cmd_buf.pushConstants<FoveationParamsPcs>(*layout, vk::ShaderStageFlagBits::eCompute, 0, f_params);
cmd_buf.dispatch(dispatch_group_count, dispatch_group_count, 1);
}
for (auto & barrier: im_barriers)
{
barrier.srcAccessMask = vk::AccessFlagBits::eMemoryWrite;
barrier.dstAccessMask = vk::AccessFlagBits::eNone;
barrier.oldLayout = vk::ImageLayout::eGeneral;
barrier.newLayout = vk::ImageLayout::eShaderReadOnlyOptimal;
}
cmd_buf.pipelineBarrier(
vk::PipelineStageFlagBits::eComputeShader,
vk::PipelineStageFlagBits::eBottomOfPipe,
{},
nullptr,
nullptr,
im_barriers);
cmd_buf.end();
auto * vk = r->vk;
D(Buffer, r->distortion.buffer);
DF(Memory, r->distortion.device_memory);
}
xrt_vec2 yaw_pitch(xrt_quat q)
static double foveate(double a, double b, double λ, double c, double x)
{
// In order to save encoding, transmit and decoding time, only a portion of the image is encoded in full resolution.
// on each axis, foveated coordinates are defined by the following formula.
return λ / a * tan(a * x + b) + c;
// a and b are defined such as:
// edges of the image are not moved
// f(-1) = -1
// f( 1) = 1
// the function also enforces pixel ratio 1:1 at fovea
// df⁻¹(x)/dx = 1/scale for x = c
// We then ensure that source and destination pixel grids match by
// rounding to integer pixel ratios: 1:1, 1:2 etc.
// Finally, pixel spans are sorted so that we only have increasing
// ratios going out from the center.
}
static std::tuple<float, float> solve_foveation(float λ, float c)
{
// Compute a and b for the foveation function such that:
// foveate(a, b, scale, c, -1) = -1 (eq. 1)
// foveate(a, b, scale, c, 1) = 1 (eq. 2)
//
// Use eq. 2 to express a as function of b, then replace in eq. 1
// equation that needs to be null is:
auto b = [λ, c](double a) { return atan(a * (1 - c) / λ) - a; };
auto eq = [λ, c](double a) { return atan(a * (1 - c) / λ) + atan(a * (1 + c) / λ) - 2 * a; }; // (eq. 3)
// function starts positive, reaches a maximum then decreases to -∞
double a0 = 0;
// Find a negative value by computing eq(2^n)
double a1 = 1;
while (eq(a1) > 0)
a1 *= 2;
// last computed values for f(a0) and f(a1)
std::optional<double> f_a0;
double f_a1 = eq(a1);
int n = 0;
double a = 0;
while (std::abs(a1 - a0) > 0.0000001 && n++ < 100)
{
if (not f_a0)
{
// use binary search
a = 0.5 * (a0 + a1);
double val = eq(a);
if (val > 0)
{
a0 = a;
f_a0 = val;
}
else
{
a1 = a;
f_a1 = val;
}
}
else
{
// f(a1) is always defined
// when f(a0) is defined, use secant method
a = a1 - f_a1 * (a1 - a0) / (f_a1 - *f_a0);
a0 = a1;
a1 = a;
f_a0 = f_a1;
f_a1 = eq(a);
}
}
return {a, b(a)};
}
static xrt_vec2 yaw_pitch(xrt_quat q)
{
float sine_theta = std::clamp(-2.0f * (q.y * q.z - q.w * q.x), -1.0f, 1.0f);
@@ -258,20 +155,124 @@ xrt_vec2 yaw_pitch(xrt_quat q)
pitch};
}
std::array<xrt_vec2, 2> wivrn_foveation::get_center()
static float angles_to_center(float e, float l, float r)
{
return (e - l) / (r - l) * 2 - 1;
}
static float convergence_angle(float eye_x, float gaze_yaw)
{
const float c = 0.5; // simutaled convergence distance
auto b = c * std::sin(gaze_yaw) - eye_x;
return std::asin(b / c);
}
void fill_param_2d(
float c,
size_t foveated_dim,
size_t source_dim,
std::vector<uint16_t> & out)
{
float scale = float(foveated_dim) / source_dim;
auto [a, b] = solve_foveation(scale, c);
uint16_t last = 0;
std::vector<uint16_t> left; // index 0: 1:1 ratio, then 2:1 etc.
std::vector<uint16_t> right;
for (size_t i = 1; i < foveated_dim; ++i)
{
double u = (i * 2.) / foveated_dim - 1;
auto f = foveate(a, b, scale, c, u);
uint16_t n = std::clamp<uint16_t>((f * 0.5 + 0.5) * source_dim + 0.5, 0, source_dim);
assert(n > last);
size_t count = n - last;
auto & vec = u < c ? left : right;
if (count > vec.size())
vec.resize(count);
vec[count - 1]++;
last = n;
}
assert(last < source_dim);
size_t count = source_dim - last;
if (count > right.size())
right.resize(count);
right[count - 1]++;
count = std::max(left.size(), right.size());
out.clear();
out.resize(count - left.size());
out.insert(out.end(), left.rbegin(), left.rend());
if (not right.empty())
out.back() += right.front();
if (right.size() > 1)
out.insert(out.end(), right.begin() + 1, right.end());
out.resize(count * 2 - 1);
}
namespace wivrn
{
void wivrn_foveation::compute_params(
xrt_rect src[2],
const xrt_fov fovs[2])
{
std::lock_guard lock(mutex);
std::array<xrt_vec2, 2> uvs;
auto e = yaw_pitch(last_gaze);
for (int i = 0; i < 2; i++)
xrt_vec2 tan_center[2]{};
if (gaze.x != 0 or gaze.y != 0 or gaze.z != 0 or gaze.w != 0)
{
uvs[i].x = (e.x - views[i].fov.angleLeft) / (views[i].fov.angleRight - views[i].fov.angleLeft) * 2 - 1 + center_offset[i].x;
uvs[i].y = (e.y - views[i].fov.angleDown) / (views[i].fov.angleUp - views[i].fov.angleDown) * 2 - 1 + center_offset[i].y;
auto e = yaw_pitch(gaze);
for (size_t i = 0; i < 2; ++i)
{
xrt_quat view_quat{
.x = views[i].pose.orientation.x,
.y = views[i].pose.orientation.y,
.z = views[i].pose.orientation.z,
.w = views[i].pose.orientation.w};
auto view = yaw_pitch(view_quat);
auto angle_x = convergence_angle(views[i].pose.position.x, e.x);
tan_center[i].x = angles_to_center(view.x + angle_x, views[i].fov.angleLeft, views[i].fov.angleRight);
tan_center[i].y = angles_to_center(-view.y - e.y, views[i].fov.angleUp, views[i].fov.angleDown);
}
}
return uvs;
for (int i = 0; i < 2; ++i)
{
const auto & fov = fovs[i];
if (foveated_width < src[i].extent.w)
fill_param_2d(tan_center[i].x, foveated_width, src[i].extent.w, params[i].x);
else
params[i].x = {uint16_t(src[i].extent.w)};
if (foveated_height < src[i].extent.h)
{
auto offset_y = (views[i].fov.angleDown + views[i].fov.angleUp) / 2;
fill_param_2d(tan_center[i].y + offset_y, foveated_height, src[i].extent.h, params[i].y);
}
else
params[i].y = {uint16_t(src[i].extent.h)};
}
}
wivrn_foveation::wivrn_foveation(wivrn_vk_bundle & bundle, const xrt_hmd_parts & hmd) :
foveated_width(hmd.screens[0].w_pixels / 2),
foveated_height(hmd.screens[0].h_pixels),
command_pool(bundle.device, vk::CommandPoolCreateInfo{.queueFamilyIndex = bundle.queue_family_index}),
cmd(std::move(bundle.device.allocateCommandBuffers({
.commandPool = command_pool,
.commandBufferCount = 1,
})[0])),
host_buffer(
bundle.device,
{
.size = sizeof(render_compute_distortion_foveation_data),
.usage = vk::BufferUsageFlagBits::eTransferSrc,
},
VmaAllocationCreateInfo{
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT,
.usage = VMA_MEMORY_USAGE_AUTO,
})
{
}
void wivrn_foveation::update_tracking(const from_headset::tracking & tracking, const clock_offset & offset)
@@ -308,16 +309,102 @@ void wivrn_foveation::update_tracking(const from_headset::tracking & tracking, c
return;
xrt_quat qgaze = xrt_cast(pose.pose.orientation);
math_quat_unrotate(&qgaze, &head.value(), &last_gaze);
math_quat_unrotate(&qgaze, &head.value(), &gaze);
break;
}
}
void wivrn_foveation::set_initial_parameters(std::array<to_headset::foveation_parameter, 2> p)
std::array<to_headset::foveation_parameter, 2> wivrn_foveation::get_parameters()
{
std::lock_guard lock(mutex);
return params;
}
center_offset[0] = {p[0].x.center, p[0].y.center};
center_offset[1] = {p[1].x.center, p[1].y.center};
static void fill_ubo(
uint32_t * ubo,
const std::vector<uint16_t> & params,
bool flip,
size_t offset,
size_t size,
int count)
{
assert(params.size() % 2 == 1);
const int n_ratio = (params.size() - 1) / 2;
*ubo = offset;
if (flip)
*ubo += size;
for (auto [i, n]: std::ranges::enumerate_view(params))
{
const int n_source = std::abs(n_ratio - int(i)) + 1;
for (size_t j = 0; j < n; ++j)
{
if (flip)
ubo[1] = ubo[0] - n_source;
else
ubo[1] = ubo[0] + n_source;
++ubo;
--count;
}
}
if (count > 0)
std::fill(ubo + 1, ubo + count + 1, *ubo);
}
template <typename T>
static bool operator==(const T & a, const T & b)
{
static_assert(std::has_unique_object_representations_v<T>);
return std::memcmp(&a, &b, sizeof(T)) == 0;
}
bool operator==(const xrt_quat & a, const xrt_quat & b)
{
return a.x == b.x and a.y == b.y and a.z == b.z and a.w == b.w;
}
bool operator==(const xrt_fov & a, const xrt_fov & b)
{
return a.angle_left == b.angle_left and a.angle_right == b.angle_right and a.angle_up == b.angle_up and a.angle_down == b.angle_down;
}
vk::CommandBuffer wivrn_foveation::update_foveation_buffer(
vk::Buffer target,
bool flip_y,
xrt_rect source[2],
xrt_fov fovs[2])
{
if (not target)
return nullptr;
if (target != gpu_buffer)
{
command_pool.reset();
cmd.begin({});
cmd.copyBuffer(host_buffer, target, vk::BufferCopy{.size = sizeof(render_compute_distortion_foveation_data)});
cmd.end();
}
// Check if the last value is still valid
if (last.flip_y == flip_y and last.src[0] == source[0] and last.src[1] == source[1] and last.fovs[0] == fovs[0])
{
std::lock_guard lock(mutex);
if (last.gaze == gaze)
return nullptr;
}
last = {
.gaze = gaze,
.flip_y = flip_y,
.src = {source[0], source[1]},
.fovs = {fovs[0], fovs[1]},
};
compute_params(source, fovs);
auto ubo = (render_compute_distortion_foveation_data *)host_buffer.map();
for (size_t view = 0; view < 2; ++view)
{
fill_ubo(ubo->x + view * RENDER_FOVEATION_BUFFER_DIMENSIONS, params[view].x, false, source[view].offset.w, source[view].extent.w, foveated_width);
fill_ubo(ubo->y + view * RENDER_FOVEATION_BUFFER_DIMENSIONS, params[view].y, flip_y, source[view].offset.h, source[view].extent.h, foveated_height);
}
return cmd;
}
} // namespace wivrn
+36 -24
View File
@@ -1,6 +1,7 @@
/*
* WiVRn VR streaming
* Copyright (C) 2024 galister <galister@librevr.org>
* 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
@@ -18,50 +19,61 @@
#pragma once
#include "vk/allocation.h"
#include "wivrn_packets.h"
#include "xrt/xrt_defines.h"
#include "xrt/xrt_device.h"
#include <vulkan/vulkan_raii.hpp>
struct render_resources;
namespace wivrn
{
struct clock_offset;
struct wivrn_vk_bundle;
// Calculates the center parameter from the received eye tracking data.
class wivrn_foveation
{
std::mutex mutex;
std::array<xrt_vec2, 2> center_offset = {};
const size_t foveated_width; // per eye
const size_t foveated_height;
std::array<from_headset::tracking::view, 2> views = {};
xrt_quat last_gaze = {};
xrt_quat gaze = {};
std::array<to_headset::foveation_parameter, 2> params;
vk::raii::CommandPool command_pool;
vk::raii::CommandBuffer cmd;
buffer_allocation host_buffer;
vk::Buffer gpu_buffer = nullptr;
// parameters used for last computation
struct P
{
xrt_quat gaze = {};
bool flip_y = false;
xrt_rect src[2] = {};
xrt_fov fovs[2] = {};
};
P last;
void compute_params(
xrt_rect src[2],
const xrt_fov fovs[2]);
public:
wivrn_foveation() {}
wivrn_foveation(wivrn_vk_bundle &, const xrt_hmd_parts &);
void set_initial_parameters(std::array<to_headset::foveation_parameter, 2> p);
void update_tracking(const from_headset::tracking &, const clock_offset &);
std::array<xrt_vec2, 2> get_center();
};
std::array<to_headset::foveation_parameter, 2> get_parameters();
// Renders foveation parameters to Monado's distortion images using a compute shader
class wivrn_foveation_renderer
{
wivrn_vk_bundle & vk;
vk::raii::DescriptorPool dp = nullptr;
vk::raii::DescriptorSetLayout ds_layout = nullptr;
vk::raii::PipelineLayout layout = nullptr;
vk::raii::Pipeline pipeline = nullptr;
std::array<vk::DescriptorSet, 2> ds;
public:
wivrn_foveation_renderer(wivrn_vk_bundle & vk, vk::raii::CommandPool & cmd_pool);
vk::raii::CommandBuffer cmd_buf = nullptr;
void render_distortion_images(std::array<to_headset::foveation_parameter, 2> foveation_arr, const VkImage * images, const VkImageView * image_views);
vk::CommandBuffer update_foveation_buffer(
vk::Buffer target,
bool flip_y,
xrt_rect src[2],
xrt_fov fovs[2]);
};
} // namespace wivrn
+176
View File
@@ -0,0 +1,176 @@
/*
* WiVRn VR streaming
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
*
* 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 "wivrn_generic_tracker.h"
#include "util/u_logging.h"
#include "utils/method.h"
#include "wivrn_session.h"
#include "math/m_api.h"
#include "math/m_eigen_interop.hpp"
#include "math/m_space.h"
#include "math/m_vec3.h"
#include "xrt/xrt_defines.h"
#include "xrt/xrt_results.h"
#include "xrt_cast.h"
#include <chrono>
#include <format>
using namespace xrt::auxiliary::math;
namespace wivrn
{
xrt_space_relation tracker_pose_list::interpolate(const xrt_space_relation & a, const xrt_space_relation & b, float t)
{
xrt_space_relation result;
xrt_space_relation_flags flags = xrt_space_relation_flags(a.relation_flags & b.relation_flags);
m_space_relation_interpolate(const_cast<xrt_space_relation *>(&a), const_cast<xrt_space_relation *>(&b), t, flags, &result);
return result;
}
xrt_space_relation tracker_pose_list::extrapolate(const xrt_space_relation & a, const xrt_space_relation & b, int64_t ta, int64_t tb, int64_t t)
{
float h = (tb - ta) / 1.e9;
xrt_space_relation res = t < ta ? a : b;
xrt_vec3 lin_vel = res.relation_flags & XRT_SPACE_RELATION_LINEAR_VELOCITY_VALID_BIT ? res.linear_velocity : (b.pose.position - a.pose.position) / h;
float dt = (t - tb) / 1.e9;
float dt2_over_2 = dt * dt / 2;
res.pose.position = res.pose.position + lin_vel * dt;
if (res.relation_flags & XRT_SPACE_RELATION_ANGULAR_VELOCITY_VALID_BIT)
{
xrt_vec3 dtheta = res.angular_velocity * dt;
xrt_quat dq;
math_quat_exp(&dtheta, &dq);
map_quat(res.pose.orientation) = map_quat(res.pose.orientation) * map_quat(dq);
}
return res;
}
bool tracker_pose_list::update_tracking(XrTime produced_timestamp, XrTime timestamp, const from_headset::body_tracking::pose & pose, const clock_offset & offset)
{
return add_sample(produced_timestamp, timestamp, convert_pose(pose), offset);
}
std::pair<std::chrono::nanoseconds, xrt_space_relation> tracker_pose_list::get_pose_at(XrTime at_timestamp_ns)
{
return get_at(at_timestamp_ns);
}
static xrt_space_relation_flags convert_flags(uint8_t flags)
{
std::underlying_type_t<xrt_space_relation_flags> out_flags = 0;
if (flags & from_headset::body_tracking::orientation_valid)
out_flags |= XRT_SPACE_RELATION_ORIENTATION_VALID_BIT;
if (flags & from_headset::body_tracking::position_valid)
out_flags |= XRT_SPACE_RELATION_POSITION_VALID_BIT;
if (flags & from_headset::body_tracking::orientation_tracked)
out_flags |= XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT;
if (flags & from_headset::body_tracking::position_tracked)
out_flags |= XRT_SPACE_RELATION_POSITION_TRACKED_BIT;
return xrt_space_relation_flags(out_flags);
}
xrt_space_relation tracker_pose_list::convert_pose(const from_headset::body_tracking::pose & pose)
{
return xrt_space_relation{
.relation_flags = convert_flags(pose.flags),
.pose = xrt_cast(pose.pose),
.linear_velocity = {},
.angular_velocity = {},
};
}
wivrn_generic_tracker::wivrn_generic_tracker(int index, xrt_device * hmd, wivrn_session & cnx) :
xrt_device{
.name = XRT_DEVICE_VIVE_TRACKER,
.device_type = XRT_DEVICE_TYPE_GENERIC_TRACKER,
.hmd = nullptr,
.tracking_origin = hmd->tracking_origin,
.orientation_tracking_supported = true,
.position_tracking_supported = true,
.update_inputs = method_pointer<&wivrn_generic_tracker::update_inputs>,
.get_tracked_pose = method_pointer<&wivrn_generic_tracker::get_tracked_pose>,
.destroy = [](xrt_device *) {},
},
cnx(cnx),
index(index)
{
auto unique_name = std::format("WiVRn Generic Tracker #{}", index + 1);
strlcpy(str, unique_name.c_str(), std::size(str));
strlcpy(serial, unique_name.c_str(), std::size(serial));
pose_input.name = XRT_INPUT_GENERIC_TRACKER_POSE;
pose_input.active = true;
inputs = &pose_input;
input_count = 1;
}
#define XRT_INPUT_NAME_CASE(NAME, VALUE) \
case VALUE: \
return #NAME;
const char * input_name_str(xrt_input_name name)
{
switch (name)
{
XRT_INPUT_LIST(XRT_INPUT_NAME_CASE)
default:
return "Unknown";
}
}
xrt_result_t wivrn_generic_tracker::update_inputs()
{
return XRT_SUCCESS;
}
xrt_result_t wivrn_generic_tracker::get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation * res)
{
std::chrono::nanoseconds extrapolation_time;
if (name == XRT_INPUT_GENERIC_TRACKER_POSE)
{
std::tie(extrapolation_time, *res) = poses.get_pose_at(at_timestamp_ns);
cnx.set_tracker_enabled(index, true);
cnx.add_predict_offset(extrapolation_time);
return XRT_SUCCESS;
}
U_LOG_D("Unknown input name %s", input_name_str(name));
return XRT_ERROR_NOT_IMPLEMENTED;
}
void wivrn_generic_tracker::update_tracking(const from_headset::body_tracking & tracking, const from_headset::body_tracking::pose & pose, const clock_offset & offset)
{
if (!poses.update_tracking(tracking.production_timestamp, tracking.timestamp, pose, offset))
cnx.set_tracker_enabled(index, false);
}
} // namespace wivrn
+61
View File
@@ -0,0 +1,61 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
*
* 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 "history.h"
#include "xrt/xrt_device.h"
namespace wivrn
{
class wivrn_session;
struct clock_offset;
class tracker_pose_list : public history<tracker_pose_list, xrt_space_relation>
{
public:
static xrt_space_relation interpolate(const xrt_space_relation & a, const xrt_space_relation & b, float t);
static xrt_space_relation extrapolate(const xrt_space_relation & a, const xrt_space_relation & b, int64_t ta, int64_t tb, int64_t t);
tracker_pose_list() = default;
bool update_tracking(XrTime produced_timestamp, XrTime timestamp, const from_headset::body_tracking::pose & pose, const clock_offset & offset);
std::pair<std::chrono::nanoseconds, xrt_space_relation> get_pose_at(XrTime at_timestamp_ns);
static xrt_space_relation convert_pose(const wivrn::from_headset::body_tracking::pose &);
};
class wivrn_generic_tracker : public xrt_device
{
tracker_pose_list poses;
xrt_input pose_input;
wivrn_session & cnx;
int index;
public:
using base = xrt_device;
wivrn_generic_tracker(int index, xrt_device * hmd, wivrn_session & cnx);
xrt_result_t update_inputs();
xrt_result_t get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation * out_relation);
void update_tracking(const from_headset::body_tracking & tracking, const from_headset::body_tracking::pose & pose, const clock_offset & offset);
};
} // namespace wivrn
+1 -179
View File
@@ -28,8 +28,6 @@
#include "utils/method.h"
#include "xrt_cast.h"
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <stdio.h>
#include <openxr/openxr.h>
@@ -39,128 +37,6 @@
namespace wivrn
{
static double foveate(double a, double b, double λ, double c, double x)
{
// In order to save encoding, transmit and decoding time, only a portion of the image is encoded in full resolution.
// on each axis, foveated coordinates are defined by the following formula.
return λ / a * tan(a * x + b) + c;
// a and b are defined such as:
// edges of the image are not moved
// f(-1) = -1
// f( 1) = 1
// the function also enforces pixel ratio 1:1 at fovea
// df⁻¹(x)/dx = 1/scale for x = c
}
static double foveate_lod(double a, double b, double /*λ*/, double /*c*/, double x)
{
// derivate of foveate * scale
// bias it to favor sharper image
return std::max(0., log2(1 / (cos(a * x + b) * cos(a * x + b)) - 0.5));
}
static std::tuple<float, float> solve_foveation(float λ, float c)
{
// Compute a and b for the foveation function such that:
// foveate(a, b, scale, c, -1) = -1 (eq. 1)
// foveate(a, b, scale, c, 1) = 1 (eq. 2)
//
// Use eq. 2 to express a as function of b, then replace in eq. 1
// equation that needs to be null is:
auto b = [λ, c](double a) { return atan(a * (1 - c) / λ) - a; };
auto eq = [λ, c](double a) { return atan(a * (1 - c) / λ) + atan(a * (1 + c) / λ) - 2 * a; }; // (eq. 3)
// function starts positive, reaches a maximum then decreases to -∞
double a0 = 0;
// Find a negative value by computing eq(2^n)
double a1 = 1;
while (eq(a1) > 0)
a1 *= 2;
// last computed values for f(a0) and f(a1)
std::optional<double> f_a0;
double f_a1 = eq(a1);
int n = 0;
double a = 0;
while (std::abs(a1 - a0) > 0.0000001 && n++ < 100)
{
if (not f_a0)
{
// use binary search
a = 0.5 * (a0 + a1);
double val = eq(a);
if (val > 0)
{
a0 = a;
f_a0 = val;
}
else
{
a1 = a;
f_a1 = val;
}
}
else
{
// f(a1) is always defined
// when f(a0) is defined, use secant method
a = a1 - f_a1 * (a1 - a0) / (f_a1 - *f_a0);
a0 = a1;
a1 = a;
f_a0 = f_a1;
f_a1 = eq(a);
}
}
return {a, b(a)};
}
bool wivrn_hmd::wivrn_hmd_compute_distortion(xrt_device * xdev, uint32_t view_index, float u, float v, xrt_uv_triplet * result)
{
// u,v are in the output coordinates (sent to the encoder)
// result is in the input coordinates (from the application)
const auto & param = ((wivrn_hmd *)xdev)->foveation_parameters[view_index];
xrt_vec2 out;
xrt_vec2 lod;
if (param.x.scale < 1)
{
u = 2 * u - 1;
out.x = foveate(param.x.a, param.x.b, param.x.scale, param.x.center, u);
lod.x = foveate_lod(param.x.a, param.x.b, param.x.scale, param.x.center, u);
out.x = std::clamp<float>((1 + out.x) / 2, 0, 1);
}
else
{
out.x = u;
lod.x = 0;
}
if (param.y.scale < 1)
{
v = 2 * v - 1;
out.y = foveate(param.y.a, param.y.b, param.y.scale, param.y.center, v);
lod.y = foveate_lod(param.y.a, param.y.b, param.y.scale, param.y.center, v);
out.y = std::clamp<float>((1 + out.y) / 2, 0, 1);
}
else
{
out.y = v;
lod.y = 0;
}
U_LOG_D("distortion parameters: %f %f (%f %f)", lod.x, lod.y, u, v);
result->r = out;
result->g = lod;
result->b = out;
return true;
}
xrt_result_t wivrn_hmd::get_visibility_mask(xrt_visibility_mask_type type, uint32_t view_index, xrt_visibility_mask ** mask)
{
static_assert(sizeof(uint32_t) == sizeof(decltype(from_headset::visibility_mask_changed::mask::indices)::value_type));
@@ -318,14 +194,10 @@ xrt_result_t wivrn_hmd::get_battery_status(bool * out_present,
return XRT_SUCCESS;
}
decltype(wivrn_hmd::foveation_parameters) wivrn_hmd::set_foveated_size(uint32_t width, uint32_t height)
void wivrn_hmd::set_foveated_size(uint32_t width, uint32_t height)
{
assert(width % 2 == 0);
uint32_t eye_width = width / 2;
std::array<double, 2> scale{
double(eye_width) / hmd->views[0].display.w_pixels,
double(height) / hmd->views[0].display.h_pixels,
};
hmd->screens[0].w_pixels = width;
hmd->screens[0].h_pixels = height;
@@ -338,56 +210,6 @@ decltype(wivrn_hmd::foveation_parameters) wivrn_hmd::set_foveated_size(uint32_t
view.viewport.w_pixels = eye_width;
view.viewport.h_pixels = height;
foveation_parameters[i].x.scale = scale[0];
foveation_parameters[i].y.scale = scale[1];
const auto & fov = hmd->distortion.fov[i];
float l = tan(fov.angle_left);
float r = tan(fov.angle_right);
float t = tan(fov.angle_up);
float b = tan(fov.angle_down);
if (scale[0] < 1)
{
float cu = (r + l) / (l - r);
foveation_parameters[i].x.center = cu;
std::tie(foveation_parameters[i].x.a, foveation_parameters[i].x.b) = solve_foveation(scale[0], cu);
}
if (scale[1] < 1)
{
float cv = (t + b) / (t - b);
foveation_parameters[i].y.center = cv;
std::tie(foveation_parameters[i].y.a, foveation_parameters[i].y.b) = solve_foveation(scale[1], cv);
}
}
// Distortion information
compute_distortion = wivrn_hmd_compute_distortion;
hmd->distortion.models = XRT_DISTORTION_MODEL_COMPUTE;
hmd->distortion.preferred = XRT_DISTORTION_MODEL_COMPUTE;
return foveation_parameters;
}
void wivrn_hmd::set_foveation_center(std::array<xrt_vec2, 2> center)
{
for (int i = 0; i < 2; ++i)
{
foveation_parameters[i].x.center = center[i].x;
foveation_parameters[i].y.center = center[i].y;
if (foveation_parameters[i].x.scale < 1)
{
std::tie(foveation_parameters[i].x.a, foveation_parameters[i].x.b) =
solve_foveation(foveation_parameters[i].x.scale, foveation_parameters[i].x.center);
}
if (foveation_parameters[i].y.scale < 1)
{
std::tie(foveation_parameters[i].y.a, foveation_parameters[i].y.b) =
solve_foveation(foveation_parameters[i].y.scale, foveation_parameters[i].y.center);
}
}
}
+2 -12
View File
@@ -44,15 +44,12 @@ class wivrn_hmd : public xrt_device
xrt_hmd_parts hmd_parts{};
view_list views;
std::array<to_headset::foveation_parameter, 2> foveation_parameters{};
from_headset::battery battery{};
thread_safe<std::array<std::optional<from_headset::visibility_mask_changed::masks>, 2>> visibility_mask;
wivrn::wivrn_session * cnx;
static bool wivrn_hmd_compute_distortion(xrt_device * xdev, uint32_t view_index, float u, float v, xrt_uv_triplet * result);
xrt_result_t get_visibility_mask(xrt_visibility_mask_type, uint32_t view_index, xrt_visibility_mask **);
public:
@@ -69,6 +66,8 @@ public:
wivrn_hmd(wivrn::wivrn_session * cnx,
const from_headset::headset_info_packet & info);
void set_foveated_size(uint32_t width, uint32_t height);
xrt_result_t get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation *);
void get_view_poses(const xrt_vec3 * default_eye_relation,
int64_t at_timestamp_ns,
@@ -82,15 +81,6 @@ public:
void update_battery(const from_headset::battery &);
void update_tracking(const from_headset::tracking &, const clock_offset &);
decltype(foveation_parameters) set_foveated_size(uint32_t width, uint32_t height);
void set_foveation_center(std::array<xrt_vec2, 2> center);
std::array<to_headset::foveation_parameter, 2> get_foveation_parameters()
{
return foveation_parameters;
}
void update_visibility_mask(const from_headset::visibility_mask_changed &);
};
} // namespace wivrn
+57 -32
View File
@@ -20,7 +20,6 @@
#include "wivrn_session.h"
#include "accept_connection.h"
#include "configuration.h"
#include "driver/app_pacer.h"
#include "main/comp_compositor.h"
#include "main/comp_main_interface.h"
@@ -35,20 +34,22 @@
#include "wivrn_config.h"
#include "wivrn_eye_tracker.h"
#include "wivrn_fb_face2_tracker.h"
#include "wivrn_foveation.h"
#include "wivrn_generic_tracker.h"
#include "wivrn_htc_face_tracker.h"
#include "wivrn_ipc.h"
#include "wivrn_packets.h"
#include "xrt/xrt_device.h"
#include "xrt/xrt_session.h"
#include <cmath>
#include <algorithm>
#include <chrono>
#include <magic_enum.hpp>
#include <stdexcept>
#include <string.h>
#include <vulkan/vulkan.h>
#if WIVRN_FEATURE_STEAMVR_LIGHTHOUSE
#include "configuration.h"
#include "steamvr_lh_interface.h"
#endif
@@ -88,8 +89,9 @@ struct wivrn_comp_target_factory : public comp_target_factory
static bool create_target(const struct comp_target_factory * ctf, struct comp_compositor * c, struct comp_target ** out_ct)
{
auto self = (wivrn_comp_target_factory *)ctf;
self->session.comp_target = new wivrn_comp_target(self->session, c);
*out_ct = self->session.comp_target;
self->session.comp_target = std::make_shared<wivrn_comp_target>(self->session, c);
self->session.comp_target->self = self->session.comp_target;
*out_ct = self->session.comp_target.get();
return true;
}
};
@@ -117,12 +119,19 @@ void wivrn::tracking_control_t::send(wivrn_connection & connection, bool now)
next_sample += std::chrono::seconds(1);
}
bool wivrn::tracking_control_t::get_enabled(to_headset::tracking_control::id id)
{
std::lock_guard lock(mutex);
return this->enabled[size_t(id)];
}
bool wivrn::tracking_control_t::set_enabled(to_headset::tracking_control::id id, bool enabled)
{
std::lock_guard lock(mutex);
bool changed = enabled != this->enabled[size_t(id)];
if (changed)
U_LOG_I("%s tracking: %s", std::string(magic_enum::enum_name(id)).c_str(), enabled ? "enabled" : "disabled");
if (!changed)
return false;
U_LOG_I("%s tracking: %s", std::string(magic_enum::enum_name(id)).c_str(), enabled ? "enabled" : "disabled");
this->enabled[size_t(id)] = enabled;
return changed;
}
@@ -198,7 +207,6 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
if (get_info().eye_gaze || is_forced_extension("EXT_eye_gaze_interaction"))
{
eye_tracker = std::make_unique<wivrn_eye_tracker>(&hmd);
foveation = std::make_unique<wivrn_foveation>();
static_roles.eyes = eye_tracker.get();
xdevs[xdev_count++] = eye_tracker.get();
}
@@ -217,6 +225,21 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
xdevs[xdev_count++] = htc_face_tracker.get();
}
num_generic_trackers = get_info().num_generic_trackers;
enabled_trackers.fill(false);
if (num_generic_trackers > 0)
{
U_LOG_I("Creating %d generic trackers", num_generic_trackers);
for (int i = 0; i < num_generic_trackers; ++i)
{
auto dev = std::make_unique<wivrn_generic_tracker>(i, &hmd, *this);
xdevs[xdev_count++] = dev.get();
generic_trackers[i] = std::move(dev);
enabled_trackers[i] = true;
}
}
#if WIVRN_FEATURE_SOLARXR
uint32_t num_devs = solarxr_device_create_xdevs(&hmd.tracking_origin, &xdevs[xdev_count], ARRAY_SIZE(xdevs) - xdev_count);
if (num_devs != 0)
@@ -408,8 +431,9 @@ void wivrn_session::operator()(const from_headset::tracking & tracking)
right_hand.update_tracking(tracking, offset);
if (eye_tracker)
eye_tracker->update_tracking(tracking, offset);
if (foveation)
foveation->update_tracking(tracking, offset);
assert(comp_target);
assert(comp_target->foveation);
comp_target->foveation->update_tracking(tracking, offset);
if (fb_face2_tracker)
fb_face2_tracker->update_tracking(tracking, offset);
@@ -430,6 +454,19 @@ void wivrn_session::operator()(from_headset::hand_tracking && hand_tracking)
left_hand.update_hand_tracking(hand_tracking, offset);
right_hand.update_hand_tracking(hand_tracking, offset);
}
void wivrn_session::operator()(from_headset::body_tracking && body_tracking)
{
auto offset = offset_est.get_offset();
for (int i = 0; i < num_generic_trackers; i++)
{
auto pose = body_tracking.poses ? body_tracking.poses->at(i) : from_headset::body_tracking::pose{
.pose = {},
.flags = 0,
};
generic_trackers[i]->update_tracking(body_tracking, pose, offset);
}
}
void wivrn_session::operator()(from_headset::inputs && inputs)
{
auto offset = get_offset();
@@ -476,6 +513,14 @@ void wivrn_session::set_enabled(device_id id, bool enabled)
if (tracking_control.set_enabled(to_tracking_control(id), enabled) and enabled)
tracking_control.send(*connection, true);
}
void wivrn_session::set_tracker_enabled(int index, bool enabled)
{
assert(index < std::size(enabled_trackers));
enabled_trackers[index] = enabled;
bool keep_active = std::ranges::any_of(enabled_trackers, [](bool b) { return b; });
if (tracking_control.set_enabled(to_headset::tracking_control::id::generic_tracker, keep_active))
tracking_control.send(*connection, true);
}
void wivrn_session::operator()(from_headset::feedback && feedback)
{
@@ -620,29 +665,9 @@ xrt_result_t wivrn_session::push_event(const xrt_session_event & event)
return xrt_session_event_sink_push(&xrt_system.broadcast, &event);
}
std::array<to_headset::foveation_parameter, 2> wivrn_session::set_foveated_size(uint32_t width, uint32_t height)
void wivrn_session::set_foveated_size(uint32_t width, uint32_t height)
{
auto p = hmd.set_foveated_size(width, height);
if (foveation)
foveation->set_initial_parameters(p);
return p;
}
bool wivrn_session::apply_dynamic_foveation()
{
if (!foveation)
return false;
hmd.set_foveation_center(foveation->get_center());
comp_target->render_dynamic_foveation(hmd.get_foveation_parameters());
return true;
}
std::array<to_headset::foveation_parameter, 2> wivrn_session::get_foveation_parameters()
{
return hmd.get_foveation_parameters();
hmd.set_foveated_size(width, height);
}
void wivrn_session::dump_time(const std::string & event, uint64_t frame, int64_t time, uint8_t stream, const char * extra)
+15 -11
View File
@@ -33,6 +33,7 @@
#include <memory>
#include <mutex>
#include <thread>
#include <vector>
struct u_system;
struct xrt_space_overseer;
@@ -44,8 +45,7 @@ namespace wivrn
class wivrn_eye_tracker;
class wivrn_fb_face2_tracker;
class wivrn_htc_face_tracker;
class wivrn_foveation;
class wivrn_foveation_renderer;
class wivrn_generic_tracker;
struct audio_device;
struct wivrn_comp_target;
struct wivrn_comp_target_factory;
@@ -82,6 +82,7 @@ public:
}
void send(wivrn_connection & connection, bool now = false);
bool get_enabled(to_headset::tracking_control::id id);
// Return true if value changed
bool set_enabled(to_headset::tracking_control::id id, bool enabled);
};
@@ -109,8 +110,10 @@ class wivrn_session : public xrt_system_devices
std::unique_ptr<wivrn_eye_tracker> eye_tracker;
std::unique_ptr<wivrn_fb_face2_tracker> fb_face2_tracker;
std::unique_ptr<wivrn_htc_face_tracker> htc_face_tracker;
std::unique_ptr<wivrn_foveation> foveation;
wivrn_comp_target * comp_target;
uint32_t num_generic_trackers;
std::array<std::unique_ptr<wivrn_generic_tracker>, from_headset::body_tracking::max_tracked_poses> generic_trackers;
std::array<bool, from_headset::body_tracking::max_tracked_poses> enabled_trackers;
std::shared_ptr<wivrn_comp_target> comp_target;
clock_offset_estimator offset_est;
@@ -143,6 +146,11 @@ public:
return connection->info();
};
wivrn_hmd & get_hmd()
{
return hmd;
}
void add_predict_offset(std::chrono::nanoseconds off)
{
tracking_control.add(off);
@@ -150,6 +158,7 @@ public:
void set_enabled(to_headset::tracking_control::id id, bool enabled);
void set_enabled(device_id id, bool enabled);
void set_tracker_enabled(int index, bool enabled);
void operator()(from_headset::crypto_handshake &&) {}
void operator()(from_headset::pin_check_1 &&) {}
@@ -160,6 +169,7 @@ public:
void operator()(const from_headset::tracking &);
void operator()(from_headset::derived_pose &&);
void operator()(from_headset::hand_tracking &&);
void operator()(from_headset::body_tracking &&);
void operator()(from_headset::inputs &&);
void operator()(from_headset::timesync_response &&);
void operator()(from_headset::feedback &&);
@@ -185,13 +195,7 @@ public:
xrt_result_t push_event(const xrt_session_event &);
std::array<to_headset::foveation_parameter, 2> set_foveated_size(uint32_t width, uint32_t height);
std::array<to_headset::foveation_parameter, 2> get_foveation_parameters();
bool apply_dynamic_foveation();
bool has_dynamic_foveation()
{
return (bool)foveation;
}
void set_foveated_size(uint32_t width, uint32_t height);
void dump_time(const std::string & event, uint64_t frame, int64_t time, uint8_t stream = -1, const char * extra = "");
-3
View File
@@ -288,9 +288,6 @@ void start_server(configuration config)
// there is no need for oversampling.
setenv("XRT_COMPOSITOR_SCALE_PERCENTAGE", "100", false);
// Enable mipmaps for distortion
setenv("XRT_DISTORTION_MIP_LEVELS", "0", false);
// FIXME: synchronization fails on gfx pipeline
setenv("XRT_COMPOSITOR_COMPUTE", "1", true);
-71
View File
@@ -1,71 +0,0 @@
/*
* WiVRn VR streaming
* Copyright (C) 2024 galister <galister@librevr.org>
*
* 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
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
layout(set = 0, binding = 0, rgba8) uniform writeonly restrict image2D target;
layout(set = 0, binding = 1, rgba8) uniform writeonly restrict image2D dtarget;
layout(push_constant) uniform PushConstants
{
vec2 a;
vec2 b;
vec2 scale;
vec2 center;
} pcs;
layout(constant_id = 0) const float one_over_dim = 0.0;
float foveate(float a, float b, float scale, float c, float x) {
return scale / a * tan(a * x + b) + c;
}
float foveate_lod(float a, float b, float scale, float c, float x) {
// derivate foveation and add a bias
return max(0, log2(1 / (cos(a * x + b) * cos(a * x + b)) - 0.5));
}
void main()
{
ivec2 coords = ivec2(gl_GlobalInvocationID.x, gl_GlobalInvocationID.y);
vec2 uv = vec2(
float(coords.x),
float(coords.y)
) * one_over_dim;
vec2 duv = vec2(1.0);
if (pcs.scale.x < 1.0) {
float u = uv.x * 2.0 - 1.0;
float val = foveate(pcs.a.x, pcs.b.x, pcs.scale.x, pcs.center.x, u);
duv.x = foveate_lod(pcs.a.x, pcs.b.x, pcs.scale.x, pcs.center.x, u);
uv.x = clamp((1.0 + val) / 2.0, 0.0, 1.0);
}
if (pcs.scale.y < 1.0) {
float v = uv.y * 2.0 - 1.0;
float val = foveate(pcs.a.y, pcs.b.y, pcs.scale.y, pcs.center.y, v);
duv.y= foveate_lod(pcs.a.y, pcs.b.y, pcs.scale.y, pcs.center.y, v);
uv.y = clamp((1.0 + val) / 2.0, 0.0, 1.0);
}
imageStore(target, coords, vec4(uv.x, uv.y, 0.0, 0.0));
imageStore(dtarget, coords, vec4(duv.x, duv.y, 0.0, 0.0));
}