Revert "Merge branch 'master' of https://github.com/Vindicus999/WiVRn"
This reverts commit6212dccc2b, reversing changes made to80e31b642a.
This commit is contained in:
@@ -23,14 +23,12 @@
|
||||
#include "encoder/video_encoder.h"
|
||||
#include "util/u_logging.h"
|
||||
#include "utils/scoped_lock.h"
|
||||
#include "wivrn_config.h"
|
||||
#include "wivrn_foveation.h"
|
||||
|
||||
#include "main/comp_compositor.h"
|
||||
#include "math/m_space.h"
|
||||
#include "xrt_cast.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <vulkan/vulkan.hpp>
|
||||
#include <vulkan/vulkan_core.h>
|
||||
@@ -60,9 +58,6 @@ std::vector<const char *> wivrn_comp_target::wanted_device_extensions = {
|
||||
#ifdef VK_KHR_video_encode_queue
|
||||
VK_KHR_VIDEO_ENCODE_QUEUE_EXTENSION_NAME,
|
||||
#endif
|
||||
#ifdef VK_KHR_video_maintenance1
|
||||
VK_KHR_VIDEO_MAINTENANCE_1_EXTENSION_NAME,
|
||||
#endif
|
||||
#ifdef VK_KHR_video_encode_h264
|
||||
VK_KHR_VIDEO_ENCODE_H264_EXTENSION_NAME,
|
||||
#endif
|
||||
@@ -193,51 +188,56 @@ static VkResult create_images(struct wivrn_comp_target * cn, vk::ImageUsageFlags
|
||||
|
||||
cn->images = U_TYPED_ARRAY_CALLOC(struct comp_target_image, cn->image_count);
|
||||
|
||||
vk::StructureChain image_info{
|
||||
vk::ImageCreateInfo{
|
||||
.flags = vk::ImageCreateFlagBits::eExtendedUsage | vk::ImageCreateFlagBits::eMutableFormat,
|
||||
.imageType = vk::ImageType::e2D,
|
||||
.format = format,
|
||||
.extent = {
|
||||
.width = cn->width,
|
||||
.height = cn->height,
|
||||
.depth = 1,
|
||||
},
|
||||
.mipLevels = 1,
|
||||
.arrayLayers = 2, // colour then alpha
|
||||
.samples = vk::SampleCountFlagBits::e1,
|
||||
.tiling = vk::ImageTiling::eOptimal,
|
||||
.usage = flags | vk::ImageUsageFlagBits::eStorage | vk::ImageUsageFlagBits::eTransferSrc,
|
||||
.sharingMode = vk::SharingMode::eExclusive,
|
||||
},
|
||||
vk::ImageFormatListCreateInfo{
|
||||
.viewFormatCount = formats.size(),
|
||||
.pViewFormats = formats.data(),
|
||||
},
|
||||
};
|
||||
#if WIVRN_USE_VULKAN_ENCODE
|
||||
if (
|
||||
vk->features.video_maintenance_1 and
|
||||
std::ranges::any_of(
|
||||
cn->settings,
|
||||
[](const auto & item) { return item.encoder_name == encoder_vulkan //
|
||||
and item.offset_x == 0 and item.offset_y == 0; }))
|
||||
{
|
||||
image_info.get().flags |= vk::ImageCreateFlagBits::eVideoProfileIndependentKHR;
|
||||
image_info.get().usage |= vk::ImageUsageFlagBits::eVideoEncodeSrcKHR;
|
||||
}
|
||||
auto [video_profiles, encoder_flags] = video_encoder::get_create_image_info(cn->settings);
|
||||
|
||||
vk::VideoProfileListInfoKHR video_profile_list{
|
||||
.profileCount = uint32_t(video_profiles.size()),
|
||||
.pProfiles = video_profiles.data(),
|
||||
};
|
||||
#endif
|
||||
|
||||
cn->psc.images.resize(cn->image_count);
|
||||
for (uint32_t i = 0; i < cn->image_count; i++)
|
||||
{
|
||||
vk::ImageFormatListCreateInfo formats_info{
|
||||
.viewFormatCount = formats.size(),
|
||||
.pViewFormats = formats.data(),
|
||||
};
|
||||
|
||||
#if WIVRN_USE_VULKAN_ENCODE
|
||||
if (video_profile_list.profileCount)
|
||||
formats_info.pNext = &video_profile_list;
|
||||
#endif
|
||||
|
||||
auto & image = cn->psc.images[i].image;
|
||||
image = image_allocation(
|
||||
device,
|
||||
image_info.get(),
|
||||
{.usage = VMA_MEMORY_USAGE_AUTO},
|
||||
std::format("comp target image {}", i));
|
||||
device, {
|
||||
.pNext = &formats_info,
|
||||
.flags = vk::ImageCreateFlagBits::eExtendedUsage | vk::ImageCreateFlagBits::eMutableFormat,
|
||||
.imageType = vk::ImageType::e2D,
|
||||
.format = format,
|
||||
.extent = {
|
||||
.width = cn->width,
|
||||
.height = cn->height,
|
||||
.depth = 1,
|
||||
},
|
||||
.mipLevels = 1,
|
||||
.arrayLayers = 2, // colour then alpha
|
||||
.samples = vk::SampleCountFlagBits::e1,
|
||||
.tiling = vk::ImageTiling::eOptimal,
|
||||
.usage = flags
|
||||
#if WIVRN_USE_VULKAN_ENCODE
|
||||
| encoder_flags
|
||||
#endif
|
||||
| vk::ImageUsageFlagBits::eStorage | vk::ImageUsageFlagBits::eTransferSrc,
|
||||
.sharingMode = vk::SharingMode::eExclusive,
|
||||
},
|
||||
{
|
||||
.usage = VMA_MEMORY_USAGE_AUTO,
|
||||
});
|
||||
cn->images[i].handle = image;
|
||||
cn->wivrn_bundle->name(vk::Image(image), "comp target image");
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < cn->image_count; i++)
|
||||
@@ -483,6 +483,20 @@ static void comp_wivrn_present_thread(std::stop_token stop_token, wivrn_comp_tar
|
||||
|
||||
auto res = vk.device.waitForFences(*cn->psc.fence, true, UINT64_MAX);
|
||||
|
||||
// Update encoder status, release image
|
||||
if ((cn->psc.status &= ~status_bit) == 0)
|
||||
{
|
||||
cn->psc.status.notify_all();
|
||||
for (auto & img: cn->psc.images)
|
||||
{
|
||||
if (img.status == pseudo_swapchain::status_t::encoding)
|
||||
{
|
||||
img.status = pseudo_swapchain::status_t::free;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
for (auto & encoder: encoders)
|
||||
@@ -499,20 +513,6 @@ static void comp_wivrn_present_thread(std::stop_token stop_token, wivrn_comp_tar
|
||||
{
|
||||
// Ignore errors
|
||||
}
|
||||
|
||||
// Update encoder status, release image
|
||||
if ((cn->psc.status &= ~status_bit) == 0)
|
||||
{
|
||||
cn->psc.status.notify_all();
|
||||
for (auto & img: cn->psc.images)
|
||||
{
|
||||
if (img.status == pseudo_swapchain::status_t::encoding)
|
||||
{
|
||||
img.status = pseudo_swapchain::status_t::free;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,8 +37,6 @@
|
||||
namespace wivrn
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
enum wivrn_controller_input_index
|
||||
{
|
||||
WIVRN_CONTROLLER_INPUT_INVALID = -1,
|
||||
@@ -100,7 +98,7 @@ struct input_data
|
||||
xrt_device_type device;
|
||||
};
|
||||
|
||||
input_data map_input(device_id id)
|
||||
static input_data map_input(device_id id)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
@@ -249,18 +247,18 @@ input_data map_input(device_id id)
|
||||
return {WIVRN_CONTROLLER_INPUT_INVALID, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_UNKNOWN};
|
||||
}
|
||||
|
||||
xrt_binding_input_pair simple_input_binding[] = {
|
||||
static xrt_binding_input_pair simple_input_binding[] = {
|
||||
{XRT_INPUT_SIMPLE_SELECT_CLICK, XRT_INPUT_TOUCH_TRIGGER_VALUE},
|
||||
{XRT_INPUT_SIMPLE_MENU_CLICK, XRT_INPUT_TOUCH_MENU_CLICK},
|
||||
{XRT_INPUT_SIMPLE_GRIP_POSE, XRT_INPUT_TOUCH_GRIP_POSE},
|
||||
{XRT_INPUT_SIMPLE_AIM_POSE, XRT_INPUT_TOUCH_AIM_POSE},
|
||||
};
|
||||
|
||||
xrt_binding_output_pair simple_output_binding[] = {
|
||||
static xrt_binding_output_pair simple_output_binding[] = {
|
||||
{XRT_OUTPUT_NAME_SIMPLE_VIBRATION, XRT_OUTPUT_NAME_TOUCH_HAPTIC},
|
||||
};
|
||||
|
||||
xrt_binding_input_pair index_input_binding[] = {
|
||||
static xrt_binding_input_pair index_input_binding[] = {
|
||||
{XRT_INPUT_INDEX_SYSTEM_CLICK, XRT_INPUT_TOUCH_SYSTEM_CLICK},
|
||||
{XRT_INPUT_INDEX_SYSTEM_TOUCH, XRT_INPUT_INDEX_SYSTEM_TOUCH},
|
||||
{XRT_INPUT_INDEX_A_CLICK, XRT_INPUT_TOUCH_A_CLICK},
|
||||
@@ -282,11 +280,11 @@ xrt_binding_input_pair index_input_binding[] = {
|
||||
{XRT_INPUT_INDEX_AIM_POSE, XRT_INPUT_TOUCH_AIM_POSE},
|
||||
};
|
||||
|
||||
xrt_binding_output_pair index_output_binding[] = {
|
||||
static xrt_binding_output_pair index_output_binding[] = {
|
||||
{XRT_OUTPUT_NAME_INDEX_HAPTIC, XRT_OUTPUT_NAME_TOUCH_HAPTIC},
|
||||
};
|
||||
|
||||
xrt_binding_input_pair focus3_input_binding[] = {
|
||||
static xrt_binding_input_pair focus3_input_binding[] = {
|
||||
{XRT_INPUT_VIVE_FOCUS3_X_CLICK, XRT_INPUT_TOUCH_X_CLICK},
|
||||
{XRT_INPUT_VIVE_FOCUS3_Y_CLICK, XRT_INPUT_TOUCH_Y_CLICK},
|
||||
{XRT_INPUT_VIVE_FOCUS3_MENU_CLICK, XRT_INPUT_TOUCH_MENU_CLICK},
|
||||
@@ -307,11 +305,11 @@ xrt_binding_input_pair focus3_input_binding[] = {
|
||||
{XRT_INPUT_VIVE_FOCUS3_AIM_POSE, XRT_INPUT_TOUCH_AIM_POSE},
|
||||
};
|
||||
|
||||
xrt_binding_output_pair focus3_output_binding[] = {
|
||||
static xrt_binding_output_pair focus3_output_binding[] = {
|
||||
{XRT_OUTPUT_NAME_VIVE_FOCUS3_HAPTIC, XRT_OUTPUT_NAME_TOUCH_HAPTIC},
|
||||
};
|
||||
|
||||
xrt_binding_input_pair touch_pro_input_binding[] = {
|
||||
static xrt_binding_input_pair touch_pro_input_binding[] = {
|
||||
{XRT_INPUT_TOUCH_PRO_X_CLICK, XRT_INPUT_TOUCH_X_CLICK},
|
||||
{XRT_INPUT_TOUCH_PRO_X_TOUCH, XRT_INPUT_TOUCH_X_TOUCH},
|
||||
{XRT_INPUT_TOUCH_PRO_Y_CLICK, XRT_INPUT_TOUCH_Y_CLICK},
|
||||
@@ -339,13 +337,13 @@ xrt_binding_input_pair touch_pro_input_binding[] = {
|
||||
{XRT_INPUT_TOUCH_PRO_STYLUS_FORCE, XRT_INPUT_TOUCH_PRO_STYLUS_FORCE},
|
||||
};
|
||||
|
||||
xrt_binding_output_pair touch_pro_output_binding[] = {
|
||||
static xrt_binding_output_pair touch_pro_output_binding[] = {
|
||||
{XRT_OUTPUT_NAME_TOUCH_PRO_HAPTIC, XRT_OUTPUT_NAME_TOUCH_HAPTIC},
|
||||
{XRT_OUTPUT_NAME_TOUCH_PRO_HAPTIC_THUMB, XRT_OUTPUT_NAME_TOUCH_PRO_HAPTIC_THUMB},
|
||||
{XRT_OUTPUT_NAME_TOUCH_PRO_HAPTIC_TRIGGER, XRT_OUTPUT_NAME_TOUCH_PRO_HAPTIC_TRIGGER},
|
||||
};
|
||||
|
||||
xrt_binding_input_pair touch_plus_input_binding[] = {
|
||||
static xrt_binding_input_pair touch_plus_input_binding[] = {
|
||||
{XRT_INPUT_TOUCH_PLUS_X_CLICK, XRT_INPUT_TOUCH_X_CLICK},
|
||||
{XRT_INPUT_TOUCH_PLUS_X_TOUCH, XRT_INPUT_TOUCH_X_TOUCH},
|
||||
{XRT_INPUT_TOUCH_PLUS_Y_CLICK, XRT_INPUT_TOUCH_Y_CLICK},
|
||||
@@ -372,11 +370,11 @@ xrt_binding_input_pair touch_plus_input_binding[] = {
|
||||
{XRT_INPUT_TOUCH_PLUS_TRIGGER_SLIDE, XRT_INPUT_TOUCH_PRO_TRIGGER_SLIDE},
|
||||
};
|
||||
|
||||
xrt_binding_output_pair touch_plus_output_binding[] = {
|
||||
static xrt_binding_output_pair touch_plus_output_binding[] = {
|
||||
{XRT_OUTPUT_NAME_TOUCH_PLUS_HAPTIC, XRT_OUTPUT_NAME_TOUCH_HAPTIC},
|
||||
};
|
||||
|
||||
xrt_binding_input_pair pico_neo3_input_binding[] = {
|
||||
static xrt_binding_input_pair pico_neo3_input_binding[] = {
|
||||
{XRT_INPUT_PICO_NEO3_X_CLICK, XRT_INPUT_TOUCH_X_CLICK},
|
||||
{XRT_INPUT_PICO_NEO3_X_TOUCH, XRT_INPUT_TOUCH_X_TOUCH},
|
||||
{XRT_INPUT_PICO_NEO3_Y_CLICK, XRT_INPUT_TOUCH_Y_CLICK},
|
||||
@@ -399,11 +397,11 @@ xrt_binding_input_pair pico_neo3_input_binding[] = {
|
||||
{XRT_INPUT_PICO_NEO3_B_TOUCH, XRT_INPUT_TOUCH_B_TOUCH},
|
||||
};
|
||||
|
||||
xrt_binding_output_pair pico_neo3_output_binding[] = {
|
||||
static xrt_binding_output_pair pico_neo3_output_binding[] = {
|
||||
{XRT_OUTPUT_NAME_PICO_NEO3_HAPTIC, XRT_OUTPUT_NAME_TOUCH_HAPTIC},
|
||||
};
|
||||
|
||||
xrt_binding_input_pair pico4_input_binding[] = {
|
||||
static xrt_binding_input_pair pico4_input_binding[] = {
|
||||
{XRT_INPUT_PICO4_X_CLICK, XRT_INPUT_TOUCH_X_CLICK},
|
||||
{XRT_INPUT_PICO4_X_TOUCH, XRT_INPUT_TOUCH_X_TOUCH},
|
||||
{XRT_INPUT_PICO4_Y_CLICK, XRT_INPUT_TOUCH_Y_CLICK},
|
||||
@@ -426,11 +424,11 @@ xrt_binding_input_pair pico4_input_binding[] = {
|
||||
{XRT_INPUT_PICO4_MENU_CLICK, XRT_INPUT_TOUCH_MENU_CLICK},
|
||||
};
|
||||
|
||||
xrt_binding_output_pair pico4_output_binding[] = {
|
||||
static xrt_binding_output_pair pico4_output_binding[] = {
|
||||
{XRT_OUTPUT_NAME_PICO4_HAPTIC, XRT_OUTPUT_NAME_TOUCH_HAPTIC},
|
||||
};
|
||||
|
||||
xrt_binding_profile wivrn_binding_profiles[] = {
|
||||
static xrt_binding_profile wivrn_binding_profiles[] = {
|
||||
{
|
||||
.name = XRT_DEVICE_SIMPLE_CONTROLLER,
|
||||
.inputs = simple_input_binding,
|
||||
@@ -482,10 +480,13 @@ xrt_binding_profile wivrn_binding_profiles[] = {
|
||||
},
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
struct xrt_space_relation_csv_header
|
||||
{};
|
||||
} // namespace
|
||||
|
||||
std::ostream & operator<<(std::ostream & out, const xrt_space_relation_csv_header &)
|
||||
static std::ostream & operator<<(std::ostream & out, const xrt_space_relation_csv_header &)
|
||||
{
|
||||
for (auto [value, name]: magic_enum::enum_entries<xrt_space_relation_flags>())
|
||||
{
|
||||
@@ -502,7 +503,44 @@ std::ostream & operator<<(std::ostream & out, const xrt_space_relation_csv_heade
|
||||
out << "avx,avy,avz";
|
||||
return out;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
static std::ostream & operator<<(std::ostream & out, const xrt_space_relation & rel)
|
||||
{
|
||||
const auto & pos = rel.pose.position;
|
||||
const auto & o = rel.pose.orientation;
|
||||
const auto & v = rel.linear_velocity;
|
||||
const auto & av = rel.angular_velocity;
|
||||
for (const auto & [value, name]: magic_enum::enum_entries<xrt_space_relation_flags>())
|
||||
{
|
||||
if (value and value != XRT_SPACE_RELATION_BITMASK_ALL)
|
||||
out << bool(rel.relation_flags & value) << ',';
|
||||
}
|
||||
out << pos.x << ',' << pos.y << ',' << pos.z << ',';
|
||||
out << o.w << ',' << o.x << ',' << o.y << ',' << o.z << ',';
|
||||
out << v.x << ',' << v.y << ',' << v.z << ',';
|
||||
out << av.x << ',' << av.y << ',' << av.z;
|
||||
return out;
|
||||
}
|
||||
|
||||
static std::mutex tracking_dump_mutex;
|
||||
static std::ofstream & tracking_dump()
|
||||
{
|
||||
static auto res = [] {
|
||||
std::ofstream res;
|
||||
if (auto wivrn_dump = std::getenv("WIVRN_DUMP_TRACKING"))
|
||||
{
|
||||
res.open(wivrn_dump);
|
||||
res << "device_id,"
|
||||
"now_ns,"
|
||||
"timestamp_ns,"
|
||||
"extrapolation_ns,"
|
||||
"receive/get,"
|
||||
<< xrt_space_relation_csv_header{} << std::endl;
|
||||
}
|
||||
return res;
|
||||
}();
|
||||
return res;
|
||||
}
|
||||
|
||||
wivrn_controller::wivrn_controller(int hand_id,
|
||||
xrt_device * hmd,
|
||||
@@ -722,8 +760,9 @@ xrt_result_t wivrn_controller::get_tracked_pose(xrt_input_name name, int64_t at_
|
||||
return XRT_ERROR_INPUT_UNSUPPORTED;
|
||||
}
|
||||
cnx->add_predict_offset(extrapolation_time);
|
||||
if (auto out = tracking_dump())
|
||||
if (auto & out = tracking_dump())
|
||||
{
|
||||
std::lock_guard lock{tracking_dump_mutex};
|
||||
auto device = [&] {
|
||||
switch (name)
|
||||
{
|
||||
@@ -734,12 +773,12 @@ xrt_result_t wivrn_controller::get_tracked_pose(xrt_input_name name, int64_t at_
|
||||
assert(false);
|
||||
__builtin_unreachable();
|
||||
} }();
|
||||
*out->lock() << magic_enum::enum_name(device) << ','
|
||||
<< os_monotonic_get_ns() << ','
|
||||
<< at_timestamp_ns << ','
|
||||
<< extrapolation_time.count() << ','
|
||||
<< "g,"
|
||||
<< *res << std::endl;
|
||||
out << magic_enum::enum_name(device) << ','
|
||||
<< os_monotonic_get_ns() << ','
|
||||
<< at_timestamp_ns << ','
|
||||
<< extrapolation_time.count() << ','
|
||||
<< "g,"
|
||||
<< *res << std::endl;
|
||||
;
|
||||
}
|
||||
return XRT_SUCCESS;
|
||||
@@ -793,19 +832,19 @@ void wivrn_controller::update_tracking(const from_headset::tracking & tracking,
|
||||
cnx->set_enabled(grip.device, false);
|
||||
if (not palm.update_tracking(tracking, offset))
|
||||
cnx->set_enabled(palm.device, false);
|
||||
if (auto out = tracking_dump(); out and offset)
|
||||
if (auto & out = tracking_dump(); out and offset)
|
||||
{
|
||||
auto locked = out->lock();
|
||||
std::lock_guard lock{tracking_dump_mutex};
|
||||
auto now = os_monotonic_get_ns();
|
||||
for (const auto & pose: tracking.device_poses)
|
||||
{
|
||||
if (pose.device == aim.device or pose.device == grip.device or pose.device == palm.device)
|
||||
*locked << magic_enum::enum_name(pose.device) << ','
|
||||
<< now << ','
|
||||
<< offset.from_headset(tracking.timestamp) << ','
|
||||
<< tracking.timestamp - tracking.production_timestamp << ','
|
||||
<< "r,"
|
||||
<< pose_list::convert_pose(pose) << std::endl;
|
||||
out << magic_enum::enum_name(pose.device) << ','
|
||||
<< now << ','
|
||||
<< offset.from_headset(tracking.timestamp) << ','
|
||||
<< tracking.timestamp - tracking.production_timestamp << ','
|
||||
<< "r,"
|
||||
<< pose_list::convert_pose(pose) << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -856,44 +895,4 @@ void wivrn_controller::reset_history()
|
||||
aim.reset();
|
||||
palm.reset();
|
||||
}
|
||||
|
||||
thread_safe<std::ofstream> * wivrn_controller::tracking_dump()
|
||||
{
|
||||
static std::unique_ptr<thread_safe<std::ofstream>> res = [] {
|
||||
if (auto wivrn_dump = std::getenv("WIVRN_DUMP_TRACKING"))
|
||||
{
|
||||
U_LOG_I("Controller tracking dump enabled: %s", wivrn_dump);
|
||||
std::ofstream res;
|
||||
res.open(wivrn_dump);
|
||||
res << "device_id,"
|
||||
"now_ns,"
|
||||
"timestamp_ns,"
|
||||
"extrapolation_ns,"
|
||||
"receive/get,"
|
||||
<< xrt_space_relation_csv_header{} << std::endl;
|
||||
|
||||
return std::make_unique<thread_safe<std::ofstream>>(std::move(res));
|
||||
}
|
||||
return std::unique_ptr<thread_safe<std::ofstream>>();
|
||||
}();
|
||||
return res.get();
|
||||
}
|
||||
} // namespace wivrn
|
||||
|
||||
std::ostream & operator<<(std::ostream & out, const xrt_space_relation & rel)
|
||||
{
|
||||
const auto & pos = rel.pose.position;
|
||||
const auto & o = rel.pose.orientation;
|
||||
const auto & v = rel.linear_velocity;
|
||||
const auto & av = rel.angular_velocity;
|
||||
for (const auto & [value, name]: magic_enum::enum_entries<xrt_space_relation_flags>())
|
||||
{
|
||||
if (value and value != XRT_SPACE_RELATION_BITMASK_ALL)
|
||||
out << bool(rel.relation_flags & value) << ',';
|
||||
}
|
||||
out << pos.x << ',' << pos.y << ',' << pos.z << ',';
|
||||
out << o.w << ',' << o.x << ',' << o.y << ',' << o.z << ',';
|
||||
out << v.x << ',' << v.y << ',' << v.z << ',';
|
||||
out << av.x << ',' << av.y << ',' << av.z;
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -23,9 +23,7 @@
|
||||
|
||||
#include "hand_joints_list.h"
|
||||
#include "pose_list.h"
|
||||
#include "utils/thread_safe.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
@@ -66,10 +64,5 @@ public:
|
||||
void update_hand_tracking(const from_headset::hand_tracking &, const clock_offset &);
|
||||
|
||||
void reset_history();
|
||||
|
||||
static thread_safe<std::ofstream> * tracking_dump();
|
||||
};
|
||||
|
||||
} // namespace wivrn
|
||||
|
||||
std::ostream & operator<<(std::ostream & out, const xrt_space_relation & rel);
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
#include "render/render_interface.h"
|
||||
#include "vk/vk_mini_helpers.h"
|
||||
|
||||
#include "wivrn_foveation.h"
|
||||
|
||||
@@ -43,13 +44,22 @@ bool render_distortion_images_ensure(struct render_resources * r,
|
||||
bool pre_rotate)
|
||||
{
|
||||
if (r->distortion.buffer == VK_NULL_HANDLE)
|
||||
r->distortion.buffer = wivrn::wivrn_foveation::instance().get_gpu_buffer();
|
||||
{
|
||||
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);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void render_distortion_images_fini(struct render_resources * r)
|
||||
{
|
||||
r->distortion.buffer = VK_NULL_HANDLE;
|
||||
auto * vk = r->vk;
|
||||
D(Buffer, r->distortion.buffer);
|
||||
DF(Memory, r->distortion.device_memory);
|
||||
}
|
||||
|
||||
// a, b: parameters computed by solve_foveation
|
||||
@@ -310,34 +320,20 @@ wivrn_foveation::wivrn_foveation(wivrn_vk_bundle & bundle, const xrt_hmd_parts &
|
||||
.commandPool = *command_pool,
|
||||
.commandBufferCount = 1,
|
||||
})[0])),
|
||||
gpu_buffer(
|
||||
host_buffer(
|
||||
bundle.device,
|
||||
{
|
||||
.size = sizeof(render_compute_distortion_foveation_data),
|
||||
.usage = vk::BufferUsageFlagBits::eTransferDst | vk::BufferUsageFlagBits::eStorageBuffer,
|
||||
.usage = vk::BufferUsageFlagBits::eTransferSrc,
|
||||
},
|
||||
VmaAllocationCreateInfo{
|
||||
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT,
|
||||
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT,
|
||||
.usage = VMA_MEMORY_USAGE_AUTO,
|
||||
},
|
||||
"foveation storage buffer")
|
||||
})
|
||||
{
|
||||
if (not(gpu_buffer.properties() & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT))
|
||||
{
|
||||
host_buffer = buffer_allocation(
|
||||
bundle.device,
|
||||
{
|
||||
.size = gpu_buffer.info().size,
|
||||
.usage = vk::BufferUsageFlagBits::eTransferSrc,
|
||||
},
|
||||
{
|
||||
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT,
|
||||
.usage = VMA_MEMORY_USAGE_AUTO_PREFER_HOST,
|
||||
},
|
||||
"foveation staging buffer");
|
||||
}
|
||||
bundle.name(command_pool, "foveation command pool");
|
||||
bundle.name(cmd, "foveation command buffer");
|
||||
bundle.name(vk::Buffer(host_buffer), "foveation staging buffer");
|
||||
}
|
||||
|
||||
void wivrn_foveation::update_tracking(const from_headset::tracking & tracking, const clock_offset & offset)
|
||||
@@ -393,7 +389,7 @@ std::array<to_headset::foveation_parameter, 2> wivrn_foveation::get_parameters()
|
||||
}
|
||||
|
||||
static void fill_ubo(
|
||||
std::span<uint32_t> ubo,
|
||||
uint32_t * ubo,
|
||||
const std::vector<uint16_t> & params,
|
||||
bool flip,
|
||||
size_t offset,
|
||||
@@ -402,9 +398,9 @@ static void fill_ubo(
|
||||
{
|
||||
assert(params.size() % 2 == 1);
|
||||
const int n_ratio = (params.size() - 1) / 2;
|
||||
ubo[0] = offset;
|
||||
*ubo = offset;
|
||||
if (flip)
|
||||
ubo[0] += size;
|
||||
*ubo += size;
|
||||
for (auto [i, n]: std::ranges::enumerate_view(params))
|
||||
{
|
||||
const int n_source = std::abs(n_ratio - int(i)) + 1;
|
||||
@@ -415,12 +411,12 @@ static void fill_ubo(
|
||||
ubo[1] = ubo[0] - n_source;
|
||||
else
|
||||
ubo[1] = ubo[0] + n_source;
|
||||
ubo = ubo.subspan(1);
|
||||
++ubo;
|
||||
--count;
|
||||
}
|
||||
}
|
||||
if (not ubo.empty())
|
||||
std::ranges::fill(ubo, ubo[0]);
|
||||
if (count > 0)
|
||||
std::fill(ubo + 1, ubo + count + 1, *ubo);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@@ -438,11 +434,6 @@ static 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::Buffer wivrn_foveation::get_gpu_buffer()
|
||||
{
|
||||
return gpu_buffer;
|
||||
}
|
||||
|
||||
vk::CommandBuffer wivrn_foveation::update_foveation_buffer(
|
||||
vk::Buffer target,
|
||||
bool flip_y,
|
||||
@@ -452,6 +443,14 @@ vk::CommandBuffer wivrn_foveation::update_foveation_buffer(
|
||||
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
|
||||
std::lock_guard lock(mutex);
|
||||
if (last.flip_y == flip_y //
|
||||
@@ -468,15 +467,6 @@ vk::CommandBuffer wivrn_foveation::update_foveation_buffer(
|
||||
)
|
||||
return nullptr;
|
||||
|
||||
assert(target == gpu_buffer);
|
||||
if (host_buffer)
|
||||
{
|
||||
command_pool.reset();
|
||||
cmd.begin({});
|
||||
cmd.copyBuffer(host_buffer, target, vk::BufferCopy{.size = sizeof(render_compute_distortion_foveation_data)});
|
||||
cmd.end();
|
||||
}
|
||||
|
||||
last = {
|
||||
.gaze = gaze,
|
||||
.flip_y = flip_y,
|
||||
@@ -488,7 +478,7 @@ vk::CommandBuffer wivrn_foveation::update_foveation_buffer(
|
||||
|
||||
compute_params(source, fovs);
|
||||
|
||||
auto ubo = host_buffer ? host_buffer.data<render_compute_distortion_foveation_data>() : gpu_buffer.data<render_compute_distortion_foveation_data>();
|
||||
auto ubo = (render_compute_distortion_foveation_data *)host_buffer.map();
|
||||
for (size_t view = 0; view < 2; ++view)
|
||||
{
|
||||
bool flip = false;
|
||||
@@ -505,7 +495,7 @@ vk::CommandBuffer wivrn_foveation::update_foveation_buffer(
|
||||
offset = source[view].offset.w;
|
||||
extent = source[view].extent.w;
|
||||
}
|
||||
fill_ubo(std::span(ubo->x + view * RENDER_FOVEATION_BUFFER_DIMENSIONS, RENDER_FOVEATION_BUFFER_DIMENSIONS), params[view].x, flip, offset, extent, foveated_width);
|
||||
fill_ubo(ubo->x + view * RENDER_FOVEATION_BUFFER_DIMENSIONS, params[view].x, flip, offset, extent, foveated_width);
|
||||
|
||||
if (source[view].extent.h < 0)
|
||||
{
|
||||
@@ -519,10 +509,8 @@ vk::CommandBuffer wivrn_foveation::update_foveation_buffer(
|
||||
offset = source[view].offset.h;
|
||||
extent = source[view].extent.h;
|
||||
}
|
||||
fill_ubo(std::span(ubo->y + view * RENDER_FOVEATION_BUFFER_DIMENSIONS, RENDER_FOVEATION_BUFFER_DIMENSIONS), params[view].y, flip, offset, extent, foveated_height);
|
||||
fill_ubo(ubo->y + view * RENDER_FOVEATION_BUFFER_DIMENSIONS, params[view].y, flip, offset, extent, foveated_height);
|
||||
}
|
||||
if (host_buffer)
|
||||
return *cmd;
|
||||
return nullptr;
|
||||
return *cmd;
|
||||
}
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#include "xrt/xrt_defines.h"
|
||||
#include "xrt/xrt_device.h"
|
||||
|
||||
#include "utils/singleton.h"
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
|
||||
struct render_resources;
|
||||
@@ -35,7 +34,7 @@ namespace wivrn
|
||||
struct clock_offset;
|
||||
struct wivrn_vk_bundle;
|
||||
|
||||
class wivrn_foveation : public singleton<wivrn_foveation>
|
||||
class wivrn_foveation
|
||||
{
|
||||
std::mutex mutex;
|
||||
|
||||
@@ -54,8 +53,8 @@ class wivrn_foveation : public singleton<wivrn_foveation>
|
||||
|
||||
vk::raii::CommandPool command_pool;
|
||||
vk::raii::CommandBuffer cmd;
|
||||
buffer_allocation gpu_buffer;
|
||||
buffer_allocation host_buffer;
|
||||
vk::Buffer gpu_buffer = nullptr;
|
||||
|
||||
// parameters used for last computation
|
||||
struct P
|
||||
@@ -82,8 +81,6 @@ public:
|
||||
void update_foveation_center_override(const from_headset::override_foveation_center &);
|
||||
std::array<to_headset::foveation_parameter, 2> get_parameters();
|
||||
|
||||
vk::Buffer get_gpu_buffer();
|
||||
|
||||
vk::CommandBuffer update_foveation_buffer(
|
||||
vk::Buffer target,
|
||||
bool flip_y,
|
||||
|
||||
@@ -148,8 +148,7 @@ xrt_result_t wivrn_generic_tracker::get_tracked_pose(xrt_input_name name, int64_
|
||||
{
|
||||
std::tie(extrapolation_time, *res) = poses.get_pose_at(at_timestamp_ns);
|
||||
|
||||
active = true;
|
||||
cnx.update_tracker_enabled();
|
||||
cnx.set_tracker_enabled(index, true);
|
||||
cnx.add_predict_offset(extrapolation_time);
|
||||
return XRT_SUCCESS;
|
||||
}
|
||||
@@ -161,9 +160,6 @@ xrt_result_t wivrn_generic_tracker::get_tracked_pose(xrt_input_name name, int64_
|
||||
void wivrn_generic_tracker::update_tracking(const from_headset::body_tracking & tracking, const from_headset::body_tracking::pose & pose, const clock_offset & offset)
|
||||
{
|
||||
if (!poses.update_tracking(tracking.production_timestamp, tracking.timestamp, pose, offset))
|
||||
{
|
||||
active = false;
|
||||
cnx.update_tracker_enabled();
|
||||
}
|
||||
cnx.set_tracker_enabled(index, false);
|
||||
}
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -45,7 +45,6 @@ class wivrn_generic_tracker : public xrt_device
|
||||
{
|
||||
tracker_pose_list poses;
|
||||
xrt_input pose_input;
|
||||
std::atomic_bool active = false;
|
||||
|
||||
wivrn_session & cnx;
|
||||
int index;
|
||||
@@ -58,10 +57,5 @@ public:
|
||||
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);
|
||||
|
||||
bool is_active()
|
||||
{
|
||||
return active;
|
||||
}
|
||||
};
|
||||
} // namespace wivrn
|
||||
} // namespace wivrn
|
||||
@@ -31,13 +31,13 @@
|
||||
#include <numbers>
|
||||
#include <optional>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "xrt/xrt_defines.h"
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
enum wivrn_hand_interaction_input_index
|
||||
{
|
||||
WIVRN_HAND_INTERACTION_INPUT_INVALID = -1,
|
||||
@@ -73,7 +73,7 @@ struct input_data
|
||||
xrt_device_type device;
|
||||
};
|
||||
|
||||
input_data map_input(device_id id)
|
||||
static input_data map_input(device_id id)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
@@ -134,7 +134,7 @@ input_data map_input(device_id id)
|
||||
return {WIVRN_HAND_INTERACTION_INPUT_INVALID, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_UNKNOWN};
|
||||
}
|
||||
|
||||
xrt_binding_input_pair hand_interaction_input_binding[] = {
|
||||
static xrt_binding_input_pair hand_interaction_input_binding[] = {
|
||||
{XRT_INPUT_HAND_GRIP_POSE, XRT_INPUT_HAND_GRIP_POSE},
|
||||
{XRT_INPUT_HAND_AIM_POSE, XRT_INPUT_HAND_AIM_POSE},
|
||||
{XRT_INPUT_HAND_PINCH_POSE, XRT_INPUT_HAND_PINCH_POSE},
|
||||
@@ -147,13 +147,7 @@ xrt_binding_input_pair hand_interaction_input_binding[] = {
|
||||
{XRT_INPUT_HAND_GRASP_READY, XRT_INPUT_HAND_GRASP_READY},
|
||||
};
|
||||
|
||||
xrt_binding_input_pair simple_input_binding[] = {
|
||||
{XRT_INPUT_SIMPLE_SELECT_CLICK, XRT_INPUT_HAND_PINCH_VALUE},
|
||||
{XRT_INPUT_SIMPLE_GRIP_POSE, XRT_INPUT_HAND_GRIP_POSE},
|
||||
{XRT_INPUT_SIMPLE_AIM_POSE, XRT_INPUT_HAND_AIM_POSE},
|
||||
};
|
||||
|
||||
xrt_binding_profile wivrn_binding_profiles[] = {
|
||||
static xrt_binding_profile wivrn_binding_profiles[] = {
|
||||
{
|
||||
.name = XRT_DEVICE_EXT_HAND_INTERACTION,
|
||||
.inputs = hand_interaction_input_binding,
|
||||
@@ -161,16 +155,64 @@ xrt_binding_profile wivrn_binding_profiles[] = {
|
||||
.outputs = nullptr,
|
||||
.output_count = 0,
|
||||
},
|
||||
{
|
||||
.name = XRT_DEVICE_SIMPLE_CONTROLLER,
|
||||
.inputs = simple_input_binding,
|
||||
.input_count = std::size(simple_input_binding),
|
||||
.outputs = nullptr,
|
||||
.output_count = 0,
|
||||
},
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
struct xrt_space_relation_csv_header
|
||||
{};
|
||||
} // namespace
|
||||
|
||||
static std::ostream & operator<<(std::ostream & out, const xrt_space_relation_csv_header &)
|
||||
{
|
||||
for (auto [value, name]: magic_enum::enum_entries<xrt_space_relation_flags>())
|
||||
{
|
||||
if (value and value != XRT_SPACE_RELATION_BITMASK_ALL)
|
||||
{
|
||||
name = name.substr(strlen("XRT_SPACE_RELATION_"));
|
||||
name = name.substr(0, name.size() - strlen("_BIT"));
|
||||
out << name << ",";
|
||||
}
|
||||
}
|
||||
out << "x,y,z,";
|
||||
out << "qw,qx,qy,qz";
|
||||
return out;
|
||||
}
|
||||
|
||||
static std::ostream & operator<<(std::ostream & out, const xrt_space_relation & rel)
|
||||
{
|
||||
const auto & pos = rel.pose.position;
|
||||
const auto & o = rel.pose.orientation;
|
||||
for (const auto & [value, name]: magic_enum::enum_entries<xrt_space_relation_flags>())
|
||||
{
|
||||
if (value and value != XRT_SPACE_RELATION_BITMASK_ALL)
|
||||
out << bool(rel.relation_flags & value) << ',';
|
||||
}
|
||||
out << pos.x << ',' << pos.y << ',' << pos.z << ',';
|
||||
out << o.w << ',' << o.x << ',' << o.y << ',' << o.z;
|
||||
return out;
|
||||
}
|
||||
|
||||
static std::mutex tracking_dump_mutex;
|
||||
static std::ofstream & tracking_dump()
|
||||
{
|
||||
static auto res = [] {
|
||||
std::ofstream res;
|
||||
if (auto wivrn_dump = std::getenv("WIVRN_DUMP_TRACKING"))
|
||||
{
|
||||
res.open(wivrn_dump);
|
||||
res << "device_id,"
|
||||
"now_ns,"
|
||||
"timestamp_ns,"
|
||||
"extrapolation_ns,"
|
||||
"receive/get,"
|
||||
<< xrt_space_relation_csv_header{} << std::endl;
|
||||
}
|
||||
return res;
|
||||
}();
|
||||
return res;
|
||||
}
|
||||
|
||||
wivrn_hand_interaction::wivrn_hand_interaction(int hand_id,
|
||||
xrt_device * hmd,
|
||||
wivrn::wivrn_session * cnx) :
|
||||
@@ -355,8 +397,9 @@ xrt_result_t wivrn_hand_interaction::get_tracked_pose(xrt_input_name name, int64
|
||||
return XRT_ERROR_INPUT_UNSUPPORTED;
|
||||
}
|
||||
cnx->add_predict_offset(extrapolation_time);
|
||||
if (auto out = wivrn_controller::tracking_dump())
|
||||
if (auto & out = tracking_dump())
|
||||
{
|
||||
std::lock_guard lock{tracking_dump_mutex};
|
||||
auto device = [&] {
|
||||
switch (name)
|
||||
{
|
||||
@@ -369,12 +412,12 @@ xrt_result_t wivrn_hand_interaction::get_tracked_pose(xrt_input_name name, int64
|
||||
assert(false);
|
||||
__builtin_unreachable();
|
||||
} }();
|
||||
*out->lock() << magic_enum::enum_name(device) << ','
|
||||
<< os_monotonic_get_ns() << ','
|
||||
<< at_timestamp_ns << ','
|
||||
<< extrapolation_time.count() << ','
|
||||
<< "g,"
|
||||
<< *res << std::endl;
|
||||
out << magic_enum::enum_name(device) << ','
|
||||
<< os_monotonic_get_ns() << ','
|
||||
<< at_timestamp_ns << ','
|
||||
<< extrapolation_time.count() << ','
|
||||
<< "g,"
|
||||
<< *res << std::endl;
|
||||
;
|
||||
}
|
||||
return XRT_SUCCESS;
|
||||
@@ -412,19 +455,19 @@ void wivrn_hand_interaction::update_tracking(const from_headset::tracking & trac
|
||||
cnx->set_enabled(pinch_ext.device, false);
|
||||
if (not poke_ext.update_tracking(tracking, offset))
|
||||
cnx->set_enabled(poke_ext.device, false);
|
||||
if (auto out = wivrn_controller::tracking_dump(); out and offset)
|
||||
if (auto & out = tracking_dump(); out and offset)
|
||||
{
|
||||
std::lock_guard lock{tracking_dump_mutex};
|
||||
auto now = os_monotonic_get_ns();
|
||||
auto locked = out->lock();
|
||||
for (const auto & pose: tracking.device_poses)
|
||||
{
|
||||
if (pose.device == aim.device or pose.device == grip.device or pose.device == palm.device)
|
||||
*locked << magic_enum::enum_name(pose.device) << ','
|
||||
<< now << ','
|
||||
<< offset.from_headset(tracking.timestamp) << ','
|
||||
<< tracking.timestamp - tracking.production_timestamp << ','
|
||||
<< "r,"
|
||||
<< pose_list::convert_pose(pose) << std::endl;
|
||||
out << magic_enum::enum_name(pose.device) << ','
|
||||
<< now << ','
|
||||
<< offset.from_headset(tracking.timestamp) << ','
|
||||
<< tracking.timestamp - tracking.production_timestamp << ','
|
||||
<< "r,"
|
||||
<< pose_list::convert_pose(pose) << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include "util/u_builders.h"
|
||||
#include "util/u_logging.h"
|
||||
#include "util/u_system.h"
|
||||
#include "utils/load_icon.h"
|
||||
#include "utils/scoped_lock.h"
|
||||
|
||||
#include "audio/audio_setup.h"
|
||||
@@ -172,12 +171,6 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
|
||||
throw;
|
||||
}
|
||||
|
||||
(*this)(from_headset::get_application_list{
|
||||
.language = get_info().language,
|
||||
.country = get_info().country,
|
||||
.variant = get_info().variant,
|
||||
});
|
||||
|
||||
static_roles.head = xdevs[xdev_count++] = &hmd;
|
||||
|
||||
if (hmd.supported.face_tracking)
|
||||
@@ -240,31 +233,24 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
|
||||
xdevs[xdev_count++] = htc_face_tracker.get();
|
||||
}
|
||||
|
||||
auto num_generic_trackers = get_info().num_generic_trackers;
|
||||
generic_trackers.reserve(num_generic_trackers);
|
||||
num_generic_trackers = get_info().num_generic_trackers;
|
||||
enabled_trackers.fill(false);
|
||||
if (num_generic_trackers > 0)
|
||||
{
|
||||
if (num_generic_trackers > from_headset::body_tracking::max_tracked_poses)
|
||||
{
|
||||
U_LOG_W("reported generic trackers %d larger than maximum %lu",
|
||||
num_generic_trackers,
|
||||
from_headset::body_tracking::max_tracked_poses);
|
||||
num_generic_trackers = from_headset::body_tracking::max_tracked_poses;
|
||||
}
|
||||
if (num_generic_trackers + xdev_count > std::size(xdevs))
|
||||
{
|
||||
U_LOG_W("Too many generic trackers: %d, only %lu will be active",
|
||||
num_generic_trackers,
|
||||
std::size(xdevs) - xdev_count);
|
||||
num_generic_trackers = std::size(xdevs) - xdev_count;
|
||||
}
|
||||
U_LOG_I("Creating %d generic trackers", num_generic_trackers);
|
||||
|
||||
if (num_generic_trackers > generic_trackers.size())
|
||||
throw std::out_of_range(
|
||||
std::format("{} generic trackers is larger than maximum {}",
|
||||
num_generic_trackers,
|
||||
generic_trackers.size()));
|
||||
|
||||
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.push_back(std::move(dev));
|
||||
generic_trackers[i] = std::move(dev);
|
||||
enabled_trackers[i] = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -549,10 +535,12 @@ void wivrn_session::operator()(from_headset::body_tracking && body_tracking)
|
||||
{
|
||||
auto offset = offset_est.get_offset();
|
||||
|
||||
assert(generic_trackers.size() <= from_headset::body_tracking::max_tracked_poses);
|
||||
for (int i = 0; i < generic_trackers.size(); i++)
|
||||
for (int i = 0; i < num_generic_trackers; i++)
|
||||
{
|
||||
auto pose = body_tracking.poses ? (*body_tracking.poses)[i] : from_headset::body_tracking::pose{};
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -617,10 +605,12 @@ 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::update_tracker_enabled()
|
||||
void wivrn_session::set_tracker_enabled(int index, bool enabled)
|
||||
{
|
||||
bool active = std::ranges::any_of(generic_trackers, [](auto & t) { return t->is_active(); });
|
||||
if (tracking_control.set_enabled(to_headset::tracking_control::id::generic_tracker, active) and active)
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -746,48 +736,15 @@ void wivrn_session::operator()(from_headset::get_application_list && request)
|
||||
.country = std::move(request.country),
|
||||
.variant = std::move(request.variant),
|
||||
};
|
||||
|
||||
auto apps = list_applications();
|
||||
|
||||
for (const auto & [id, app]: apps)
|
||||
for (auto && [id, app]: list_applications())
|
||||
{
|
||||
response.applications.emplace_back(
|
||||
std::move(id),
|
||||
// FIXME: use locale
|
||||
app.name.at(""));
|
||||
app.name.at(""),
|
||||
app.image);
|
||||
}
|
||||
send_control(std::move(response));
|
||||
|
||||
for (const auto & [id, app]: apps)
|
||||
{
|
||||
if (app.icon_path)
|
||||
{
|
||||
try
|
||||
{
|
||||
const auto & icons = load_icon(*app.icon_path);
|
||||
|
||||
if (icons.empty())
|
||||
continue;
|
||||
|
||||
const auto & largest_icon = std::ranges::max(icons, [](const wivrn::icon & a, const wivrn::icon & b) {
|
||||
if (a.bpp < b.bpp)
|
||||
return true;
|
||||
if (a.bpp > b.bpp)
|
||||
return false;
|
||||
return a.width * a.height < b.width * b.height;
|
||||
});
|
||||
|
||||
send_control(to_headset::application_icon{
|
||||
.id = id,
|
||||
.image = largest_icon.png_data,
|
||||
});
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
U_LOG_W("Error loading icon %s: %s", app.icon_path->c_str(), e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wivrn_session::operator()(const from_headset::start_app & request)
|
||||
|
||||
@@ -105,8 +105,6 @@ class wivrn_session : public xrt_system_devices
|
||||
.gamepad = -1,
|
||||
};
|
||||
|
||||
tracking_control_t tracking_control;
|
||||
|
||||
wivrn_hmd hmd;
|
||||
wivrn_controller left_controller;
|
||||
int32_t left_controller_index;
|
||||
@@ -119,13 +117,19 @@ 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::vector<std::unique_ptr<wivrn_generic_tracker>> generic_trackers;
|
||||
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_mutex comp_target_mutex;
|
||||
wivrn_comp_target * comp_target;
|
||||
|
||||
clock_offset_estimator offset_est;
|
||||
|
||||
// prediction offset and enabled tracking to configure client
|
||||
tracking_control_t tracking_control;
|
||||
std::mutex tracking_control_mutex;
|
||||
|
||||
std::mutex csv_mutex;
|
||||
std::ofstream feedback_csv;
|
||||
|
||||
@@ -165,7 +169,7 @@ public:
|
||||
|
||||
void set_enabled(to_headset::tracking_control::id id, bool enabled);
|
||||
void set_enabled(device_id id, bool enabled);
|
||||
void update_tracker_enabled();
|
||||
void set_tracker_enabled(int index, bool enabled);
|
||||
|
||||
void operator()(from_headset::crypto_handshake &&) {}
|
||||
void operator()(from_headset::pin_check_1 &&) {}
|
||||
|
||||
Reference in New Issue
Block a user