Revert "Merge branch 'master' of https://github.com/Vindicus999/WiVRn"
This reverts commit6212dccc2b, reversing changes made to80e31b642a.
This commit is contained in:
+102
-132
@@ -383,18 +383,9 @@ void scenes::lobby::connect(const configuration::server_data & data)
|
||||
data.manual);
|
||||
}
|
||||
|
||||
std::optional<glm::vec3> scenes::lobby::check_recenter_gesture(xr::spaces space, const std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> & joints)
|
||||
std::optional<glm::vec3> scenes::lobby::check_recenter_gesture(const std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT> & joints)
|
||||
{
|
||||
if (recentering_context and std::get<0>(*recentering_context) != space)
|
||||
return std::nullopt;
|
||||
|
||||
if (not joints)
|
||||
{
|
||||
recentering_context.reset();
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
const auto & palm = (*joints)[XR_HAND_JOINT_PALM_EXT].first;
|
||||
const auto & palm = joints[XR_HAND_JOINT_PALM_EXT].first;
|
||||
const auto & o = palm.pose.orientation;
|
||||
const auto & p = palm.pose.position;
|
||||
glm::quat q{o.w, o.x, o.y, o.z};
|
||||
@@ -402,130 +393,102 @@ std::optional<glm::vec3> scenes::lobby::check_recenter_gesture(xr::spaces space,
|
||||
|
||||
if (glm::dot(q * glm::vec3(0, 1, 0), glm::vec3(0, -1, 0)) > constants::lobby::recenter_cosangle_min)
|
||||
{
|
||||
recentering_context.emplace(space, glm::vec3{}, 0);
|
||||
return v + glm::vec3(0, constants::lobby::recenter_distance_up, 0) + q * glm::vec3(0, 0, -constants::lobby::recenter_distance_front);
|
||||
}
|
||||
|
||||
recentering_context.reset();
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<glm::vec3> scenes::lobby::check_recenter_action(XrTime predicted_display_time, glm::vec3 head_position)
|
||||
{
|
||||
xr::spaces controller;
|
||||
glm::vec3 recenter_position;
|
||||
float recenter_distance;
|
||||
std::optional<std::pair<glm::vec3, glm::quat>> aim;
|
||||
glm::vec3 offset_position;
|
||||
glm::quat offset_orientation;
|
||||
|
||||
if (recentering_context)
|
||||
if (application::read_action_bool(recenter_left_action).value_or(std::pair{0, false}).second)
|
||||
{
|
||||
controller = std::get<0>(*recentering_context);
|
||||
bool state;
|
||||
switch (controller)
|
||||
{
|
||||
case xr::spaces::aim_left:
|
||||
state = application::read_action_bool(recenter_left_action).value_or(std::pair{0, false}).second;
|
||||
break;
|
||||
|
||||
case xr::spaces::aim_right:
|
||||
state = application::read_action_bool(recenter_right_action).value_or(std::pair{0, false}).second;
|
||||
break;
|
||||
|
||||
default:
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (not state)
|
||||
{
|
||||
recentering_context.reset();
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
else if (auto state = application::read_action_bool(recenter_left_action); state and state->second)
|
||||
controller = xr::spaces::aim_left;
|
||||
else if (auto state = application::read_action_bool(recenter_right_action); state and state->second)
|
||||
controller = xr::spaces::aim_right;
|
||||
else
|
||||
return std::nullopt;
|
||||
|
||||
auto aim = application::locate_controller(application::space(controller), application::space(xr::spaces::world), predicted_display_time);
|
||||
|
||||
if (not aim)
|
||||
{
|
||||
// The controller cannot be located
|
||||
recentering_context.reset();
|
||||
return std::nullopt;
|
||||
aim = application::locate_controller(application::space(xr::spaces::aim_left), application::space(xr::spaces::world), predicted_display_time);
|
||||
std::tie(offset_position, offset_orientation) = input->offset[xr::spaces::aim_left];
|
||||
}
|
||||
|
||||
// Handle controller offset
|
||||
auto [offset_position, offset_orientation] = input->offset[controller];
|
||||
aim->first = aim->first + glm::mat3_cast(aim->second * offset_orientation) * offset_position;
|
||||
aim->second = aim->second * offset_orientation;
|
||||
|
||||
if (not recentering_context)
|
||||
if (application::read_action_bool(recenter_right_action).value_or(std::pair{0, false}).second)
|
||||
{
|
||||
// First frame of recentering
|
||||
imgui_context::controller_state state{
|
||||
.active = true,
|
||||
.aim_position = aim->first,
|
||||
.aim_orientation = aim->second,
|
||||
};
|
||||
aim = application::locate_controller(application::space(xr::spaces::aim_right), application::space(xr::spaces::world), predicted_display_time);
|
||||
std::tie(offset_position, offset_orientation) = input->offset[xr::spaces::aim_right];
|
||||
}
|
||||
|
||||
imgui_ctx->compute_pointer_position(state);
|
||||
if (aim)
|
||||
{
|
||||
// Handle controller offset
|
||||
aim->first = aim->first + glm::mat3_cast(aim->second * offset_orientation) * offset_position;
|
||||
aim->second = aim->second * offset_orientation;
|
||||
|
||||
if (state.pointer_position) // TODO: check that the pointer is inside an imgui window
|
||||
if (not gui_recenter_position or not gui_recenter_distance)
|
||||
{
|
||||
auto M = glm::mat3_cast(imgui_ctx->layers()[0].orientation);
|
||||
// First frame where the recenter action is active
|
||||
imgui_context::controller_state state{
|
||||
.active = true,
|
||||
.aim_position = aim->first,
|
||||
.aim_orientation = aim->second,
|
||||
};
|
||||
|
||||
// Pointer position in world
|
||||
glm::vec3 world_pointer_position = imgui_ctx->rw_from_vp(*state.pointer_position);
|
||||
imgui_ctx->compute_pointer_position(state);
|
||||
|
||||
// Pointer position in GUI
|
||||
recenter_position = glm::transpose(M) * (world_pointer_position - imgui_ctx->layers()[0].position);
|
||||
recenter_distance = glm::length(state.aim_position - world_pointer_position);
|
||||
if (state.pointer_position) // TODO: check that the pointer is inside an imgui window
|
||||
{
|
||||
auto M = glm::mat3_cast(imgui_ctx->layers()[0].orientation);
|
||||
|
||||
// Pointer position in world
|
||||
glm::vec3 world_pointer_position = imgui_ctx->rw_from_vp(*state.pointer_position);
|
||||
|
||||
// Pointer position in GUI
|
||||
gui_recenter_position = glm::transpose(M) * (world_pointer_position - imgui_ctx->layers()[0].position);
|
||||
gui_recenter_distance = glm::length(state.aim_position - world_pointer_position);
|
||||
}
|
||||
else
|
||||
{
|
||||
gui_recenter_position = glm::vec3(0, 0, 0);
|
||||
gui_recenter_distance = constants::lobby::recenter_action_distance;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use the center of the GUI if the controller points outside of the GUI
|
||||
recenter_position = glm::vec3(0, 0, 0);
|
||||
recenter_distance = constants::lobby::recenter_action_distance;
|
||||
}
|
||||
// Subsequent frames: find the GUI position that gives the correct world pointer position
|
||||
glm::vec3 controller_direction = -glm::column(glm::mat3_cast(aim->second), 2);
|
||||
glm::vec3 wanted_world_pointer_position = aim->first + controller_direction * *gui_recenter_distance;
|
||||
|
||||
recentering_context.emplace(controller, recenter_position, recenter_distance);
|
||||
return std::nullopt;
|
||||
// I'm sure there's an analytical solution but I can't be bothered to write it so
|
||||
// let's use a gradient descent instead
|
||||
auto f = [&](glm::vec3 new_gui_position) {
|
||||
auto q = compute_gui_orientation(head_position, new_gui_position);
|
||||
auto M = glm::mat3_cast(q); // plane-to-world transform
|
||||
|
||||
glm::vec3 world_pointer_position = new_gui_position + M * *gui_recenter_position;
|
||||
|
||||
return world_pointer_position - wanted_world_pointer_position;
|
||||
};
|
||||
|
||||
// One step is usually enough, the solution will continuously improve in the next frames
|
||||
glm::vec3 gui_position = imgui_ctx->layers()[0].position;
|
||||
float eps = 0.01;
|
||||
glm::vec3 obj = f(gui_position);
|
||||
glm::vec3 obj_dx = (f(gui_position + glm::vec3(eps, 0, 0)) - obj) / eps;
|
||||
glm::vec3 obj_dy = (f(gui_position + glm::vec3(0, eps, 0)) - obj) / eps;
|
||||
glm::vec3 obj_dz = (f(gui_position + glm::vec3(0, 0, eps)) - obj) / eps;
|
||||
|
||||
glm::mat3 jacobian{obj_dx, obj_dy, obj_dz};
|
||||
|
||||
gui_position -= glm::inverse(jacobian) * obj;
|
||||
|
||||
return gui_position;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Subsequent frames: find the GUI position that gives the correct world pointer position
|
||||
std::tie(controller, recenter_position, recenter_distance) = *recentering_context;
|
||||
|
||||
glm::vec3 controller_direction = -glm::column(glm::mat3_cast(aim->second), 2);
|
||||
glm::vec3 wanted_world_pointer_position = aim->first + controller_direction * recenter_distance;
|
||||
|
||||
// I'm sure there's an analytical solution but I can't be bothered to write it so
|
||||
// let's use a gradient descent instead
|
||||
auto f = [&](glm::vec3 new_gui_position) {
|
||||
auto q = compute_gui_orientation(head_position, new_gui_position);
|
||||
auto M = glm::mat3_cast(q); // plane-to-world transform
|
||||
|
||||
glm::vec3 world_pointer_position = new_gui_position + M * recenter_position;
|
||||
|
||||
return world_pointer_position - wanted_world_pointer_position;
|
||||
};
|
||||
|
||||
// One step is usually enough, the solution will continuously improve in the next frames
|
||||
glm::vec3 gui_position = imgui_ctx->layers()[0].position;
|
||||
float eps = 0.01;
|
||||
glm::vec3 obj = f(gui_position);
|
||||
glm::vec3 obj_dx = (f(gui_position + glm::vec3(eps, 0, 0)) - obj) / eps;
|
||||
glm::vec3 obj_dy = (f(gui_position + glm::vec3(0, eps, 0)) - obj) / eps;
|
||||
glm::vec3 obj_dz = (f(gui_position + glm::vec3(0, 0, eps)) - obj) / eps;
|
||||
|
||||
glm::mat3 jacobian{obj_dx, obj_dy, obj_dz};
|
||||
|
||||
gui_position -= glm::inverse(jacobian) * obj;
|
||||
|
||||
return gui_position;
|
||||
gui_recenter_position.reset();
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<glm::vec3> scenes::lobby::check_recenter_gui(glm::vec3 head_position, glm::quat head_orientation)
|
||||
@@ -649,24 +612,26 @@ void scenes::lobby::render(const XrFrameState & frame_state)
|
||||
if (!new_gui_position and head_position)
|
||||
new_gui_position = check_recenter_action(frame_state.predictedDisplayTime, head_position->first);
|
||||
|
||||
if (left_hand and right_hand)
|
||||
if (application::get_hand_tracking_supported())
|
||||
{
|
||||
auto left = left_hand->locate(world_space, frame_state.predictedDisplayTime);
|
||||
auto right = right_hand->locate(world_space, frame_state.predictedDisplayTime);
|
||||
auto left = application::get_left_hand().locate(world_space, frame_state.predictedDisplayTime);
|
||||
auto right = application::get_right_hand().locate(world_space, frame_state.predictedDisplayTime);
|
||||
|
||||
hand_model::apply(world, left, right);
|
||||
|
||||
if (left and xr::hand_tracker::check_flags(*left, XR_SPACE_LOCATION_POSITION_TRACKED_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT, 0))
|
||||
{
|
||||
hide_left_controller = true;
|
||||
if (!new_gui_position)
|
||||
new_gui_position = check_recenter_gesture(*left);
|
||||
}
|
||||
|
||||
if (right and xr::hand_tracker::check_flags(*right, XR_SPACE_LOCATION_POSITION_TRACKED_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT, 0))
|
||||
{
|
||||
hide_right_controller = true;
|
||||
|
||||
if (not new_gui_position)
|
||||
new_gui_position = check_recenter_gesture(xr::spaces::palm_left, left);
|
||||
|
||||
if (not new_gui_position)
|
||||
new_gui_position = check_recenter_gesture(xr::spaces::palm_right, right);
|
||||
if (!new_gui_position)
|
||||
new_gui_position = check_recenter_gesture(*right);
|
||||
}
|
||||
}
|
||||
|
||||
if (head_position && new_gui_position)
|
||||
@@ -798,7 +763,7 @@ void scenes::lobby::on_focused()
|
||||
// assert(std::ranges::all_of(views, [height](const XrViewConfigurationView & view) { return view.recommendedImageRectHeight == height; }));
|
||||
|
||||
renderer.emplace(device, physical_device, queue, commandpool);
|
||||
loader.emplace(device, physical_device, queue, queue_family_index, renderer->get_default_material());
|
||||
loader.emplace(device, physical_device, queue, application::queue_family_index(), renderer->get_default_material());
|
||||
|
||||
lobby_entity = load_gltf("ground.gltf", layer_lobby).first;
|
||||
|
||||
@@ -835,6 +800,12 @@ void scenes::lobby::on_focused()
|
||||
xyz_axes_right_controller = load_gltf("xyz-arrows.glb", layer_controllers).first;
|
||||
#endif
|
||||
|
||||
if (application::get_hand_tracking_supported())
|
||||
{
|
||||
hand_model::add_hand(*this, XR_HAND_LEFT_EXT, "left-hand.glb", layer_controllers);
|
||||
hand_model::add_hand(*this, XR_HAND_RIGHT_EXT, "right-hand.glb", layer_controllers);
|
||||
}
|
||||
|
||||
recenter_left_action = get_action("recenter_left").first;
|
||||
recenter_right_action = get_action("recenter_right").first;
|
||||
|
||||
@@ -856,18 +827,20 @@ void scenes::lobby::on_focused()
|
||||
.haptic_output = get_action("right_haptic").first,
|
||||
},
|
||||
};
|
||||
|
||||
if (system.hand_tracking_supported())
|
||||
if (auto & hand = application::get_left_hand())
|
||||
{
|
||||
left_hand = session.create_hand_tracker(XR_HAND_LEFT_EXT);
|
||||
right_hand = session.create_hand_tracker(XR_HAND_RIGHT_EXT);
|
||||
hand_model::add_hand(*this, XR_HAND_LEFT_EXT, "left-hand.glb", layer_controllers);
|
||||
hand_model::add_hand(*this, XR_HAND_RIGHT_EXT, "right-hand.glb", layer_controllers);
|
||||
imgui_inputs.push_back({.hand = &*left_hand});
|
||||
imgui_inputs.push_back({.hand = &*right_hand});
|
||||
imgui_inputs.push_back(
|
||||
{
|
||||
.hand = &hand,
|
||||
});
|
||||
}
|
||||
if (auto & hand = application::get_right_hand())
|
||||
{
|
||||
imgui_inputs.push_back(
|
||||
{
|
||||
.hand = &hand,
|
||||
});
|
||||
}
|
||||
|
||||
face_tracker = xr::make_face_tracker(instance, system, session);
|
||||
|
||||
// 0.4mm / pixel
|
||||
std::vector<imgui_context::viewport> vps{
|
||||
@@ -969,9 +942,6 @@ void scenes::lobby::on_unfocused()
|
||||
world.clear(); // Must be cleared before the renderer so that the descriptor sets are freed before their pools
|
||||
|
||||
input.reset();
|
||||
left_hand.reset();
|
||||
right_hand.reset();
|
||||
face_tracker.emplace<std::monostate>();
|
||||
|
||||
loader.reset();
|
||||
renderer.reset();
|
||||
|
||||
+4
-14
@@ -29,9 +29,7 @@
|
||||
#include "wivrn_config.h"
|
||||
#include "wivrn_discover.h"
|
||||
#include "wivrn_packets.h"
|
||||
#include "xr/face_tracker.h"
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
@@ -67,11 +65,6 @@ class lobby : public scene_impl<lobby>
|
||||
|
||||
std::optional<imgui_context> imgui_ctx;
|
||||
|
||||
std::optional<xr::hand_tracker> left_hand;
|
||||
std::optional<xr::hand_tracker> right_hand;
|
||||
|
||||
xr::face_tracker face_tracker;
|
||||
|
||||
std::string selected_item;
|
||||
std::unique_ptr<asset> license;
|
||||
|
||||
@@ -101,10 +94,8 @@ class lobby : public scene_impl<lobby>
|
||||
|
||||
XrAction recenter_left_action = XR_NULL_HANDLE;
|
||||
XrAction recenter_right_action = XR_NULL_HANDLE;
|
||||
// std::optional<glm::vec3> gui_recenter_position;
|
||||
// std::optional<float> gui_recenter_distance;
|
||||
// Which controller is used for recentering, position of the pointed point in the GUI, in GUI axes, and distance between the controller and the pointed point during recentering
|
||||
std::optional<std::tuple<xr::spaces, glm::vec3, float>> recentering_context;
|
||||
std::optional<glm::vec3> gui_recenter_position;
|
||||
std::optional<float> gui_recenter_distance;
|
||||
bool recenter_gui = true;
|
||||
void move_gui(glm::vec3 head_position, glm::vec3 new_gui_position);
|
||||
|
||||
@@ -129,7 +120,6 @@ class lobby : public scene_impl<lobby>
|
||||
ImTextureID about_picture;
|
||||
ImTextureID default_icon;
|
||||
std::unordered_map<std::string, ImTextureID> app_icons;
|
||||
std::optional<XrTime> timestamp_start_application;
|
||||
|
||||
virtual_keyboard keyboard;
|
||||
|
||||
@@ -146,7 +136,7 @@ class lobby : public scene_impl<lobby>
|
||||
void draw_features_status(XrTime predicted_display_time);
|
||||
void gui_connecting(locked_notifiable<pin_request_data> & request);
|
||||
void gui_enter_pin(locked_notifiable<pin_request_data> & request);
|
||||
void gui_connected(XrTime predicted_display_time);
|
||||
void gui_connected();
|
||||
void gui_server_list();
|
||||
void gui_new_server();
|
||||
void gui_settings();
|
||||
@@ -162,7 +152,7 @@ class lobby : public scene_impl<lobby>
|
||||
void connect(const configuration::server_data & data);
|
||||
std::unique_ptr<wivrn_session> connect_to_session(wivrn_discover::service service, bool manual_connection);
|
||||
|
||||
std::optional<glm::vec3> check_recenter_gesture(xr::spaces space, const std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> & joints);
|
||||
std::optional<glm::vec3> check_recenter_gesture(const std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT> & joints);
|
||||
std::optional<glm::vec3> check_recenter_action(XrTime predicted_display_time, glm::vec3 head_position);
|
||||
std::optional<glm::vec3> check_recenter_gui(glm::vec3 head_position, glm::quat head_orientation);
|
||||
|
||||
|
||||
+34
-68
@@ -34,13 +34,11 @@
|
||||
#include "utils/overloaded.h"
|
||||
#include "utils/ranges.h"
|
||||
#include "version.h"
|
||||
#include "xr/body_tracker.h"
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <imspinner.h>
|
||||
#include <ranges>
|
||||
#include <spdlog/fmt/fmt.h>
|
||||
#include <string>
|
||||
@@ -247,7 +245,6 @@ void scenes::lobby::gui_connecting(locked_notifiable<pin_request_data> & pin_req
|
||||
if (next_scene)
|
||||
{
|
||||
current_tab = tab::connected;
|
||||
timestamp_start_application.reset();
|
||||
ImGui::CloseCurrentPopup();
|
||||
return;
|
||||
}
|
||||
@@ -378,7 +375,7 @@ void scenes::lobby::gui_enter_pin(locked_notifiable<pin_request_data> & pin_requ
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
}
|
||||
|
||||
void scenes::lobby::gui_connected(XrTime predicted_display_time)
|
||||
void scenes::lobby::gui_connected()
|
||||
{
|
||||
if (not next_scene)
|
||||
{
|
||||
@@ -403,17 +400,14 @@ void scenes::lobby::gui_connected(XrTime predicted_display_time)
|
||||
|
||||
auto apps = next_scene->get_applications();
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {20, 20});
|
||||
if (apps->empty())
|
||||
if (apps->applications.empty())
|
||||
{
|
||||
CenterTextHV(_("Start an application on the server to start streaming."));
|
||||
}
|
||||
else
|
||||
{
|
||||
bool app_starting = timestamp_start_application and (predicted_display_time - *timestamp_start_application < 10'000'000'000);
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {20, 0});
|
||||
ImGui::BeginDisabled(app_starting);
|
||||
ImGui::BeginChild("Main", ImGui::GetWindowSize() - ImGui::GetCursorPos() - ImVec2(0, disconnect_size.y + 80), 0, app_starting ? ImGuiWindowFlags_NoScrollWithMouse : 0);
|
||||
ImGui::BeginChild("Main", ImGui::GetWindowSize() - ImGui::GetCursorPos() - ImVec2(0, disconnect_size.y + 80), 0);
|
||||
|
||||
ImGui::Indent(20);
|
||||
if (server_name.empty())
|
||||
@@ -432,7 +426,7 @@ void scenes::lobby::gui_connected(XrTime predicted_display_time)
|
||||
ImGui::Indent((usable_window_width - icon_line_width) / 2);
|
||||
|
||||
auto t0 = std::chrono::steady_clock::now();
|
||||
for (const auto [index, app]: utils::enumerate(*apps))
|
||||
for (const auto [index, app]: utils::enumerate(apps->applications))
|
||||
{
|
||||
ImTextureID texture = [&]() -> ImTextureID {
|
||||
if (app.image.empty())
|
||||
@@ -463,11 +457,8 @@ void scenes::lobby::gui_connected(XrTime predicted_display_time)
|
||||
}();
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, 0);
|
||||
if (icon(app.name + "##" + app.id, texture, {256, 256}, ImGuiButtonFlags_PressedOnClickRelease, {icon_width, 0}))
|
||||
{
|
||||
timestamp_start_application = predicted_display_time;
|
||||
if (icon(app.name + "##" + app.id, texture, {256, 256}, 0, {icon_width, 0}))
|
||||
next_scene->start_application(app.id);
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
ImGui::PopStyleColor(); // ImGuiCol_Button
|
||||
|
||||
@@ -479,7 +470,7 @@ void scenes::lobby::gui_connected(XrTime predicted_display_time)
|
||||
std::vector<std::pair<std::string, ImTextureID>> to_be_removed;
|
||||
for (const auto & [app_id, app_icon]: app_icons)
|
||||
{
|
||||
if (not std::ranges::contains(*apps, app_id, &scenes::stream::app::id))
|
||||
if (not std::ranges::contains(apps->applications, app_id, &to_headset::application_list::application::id))
|
||||
to_be_removed.emplace_back(app_id, app_icon);
|
||||
}
|
||||
for (const auto & [app_id, app_icon]: to_be_removed)
|
||||
@@ -490,26 +481,12 @@ void scenes::lobby::gui_connected(XrTime predicted_display_time)
|
||||
|
||||
ScrollWhenDragging();
|
||||
ImGui::EndChild();
|
||||
ImGui::EndDisabled();
|
||||
|
||||
if (app_starting)
|
||||
{
|
||||
ImGui::SetCursorPos(ImGui::GetWindowSize() / 2 - ImVec2{200, 200} - ImGui::GetStyle().FramePadding);
|
||||
ImSpinner::SpinnerAng("App starting spinner",
|
||||
200, // Radius
|
||||
40, // Thickness
|
||||
ImColor{1.f, 1.f, 1.f, 1.f}, // Colour
|
||||
ImColor{1.f, 1.f, 1.f, 0.f}, // Background
|
||||
6, // Velocity
|
||||
0.75f * 2 * M_PI // Angle
|
||||
);
|
||||
}
|
||||
|
||||
ImGui::PopStyleVar(); // ImGuiStyleVar_WindowPadding
|
||||
}
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
ImGui::SetCursorPos(ImGui::GetWindowSize() - disconnect_size - ImVec2{50, 50});
|
||||
ImGui::SetCursorPosX(ImGui::GetWindowSize().x - disconnect_size.x - 50);
|
||||
ImGui::SetCursorPosY(ImGui::GetWindowSize().y - disconnect_size.y - 50);
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.2f, 0.2f, 0.40f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.8f, 0.2f, 0.2f, 1.00f));
|
||||
@@ -890,7 +867,7 @@ void scenes::lobby::gui_settings()
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
{
|
||||
ImGui::BeginDisabled(not system.hand_tracking_supported());
|
||||
ImGui::BeginDisabled(not application::get_hand_tracking_supported());
|
||||
bool enabled = config.check_feature(feature::hand_tracking);
|
||||
if (ImGui::Checkbox(_S("Enable hand tracking"), &enabled))
|
||||
{
|
||||
@@ -914,7 +891,7 @@ void scenes::lobby::gui_settings()
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
{
|
||||
ImGui::BeginDisabled(std::holds_alternative<std::monostate>(face_tracker));
|
||||
ImGui::BeginDisabled(not application::get_face_tracking_supported());
|
||||
bool enabled = config.check_feature(feature::face_tracking);
|
||||
if (ImGui::Checkbox(_S("Enable face tracking"), &enabled))
|
||||
{
|
||||
@@ -926,9 +903,8 @@ void scenes::lobby::gui_settings()
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
}
|
||||
|
||||
auto body_tracker = system.body_tracker_supported();
|
||||
{
|
||||
ImGui::BeginDisabled(body_tracker == xr::body_tracker_type::none);
|
||||
ImGui::BeginDisabled(not application::get_body_tracking_supported());
|
||||
bool enabled = config.check_feature(feature::body_tracking);
|
||||
if (ImGui::Checkbox(_S("Enable body tracking"), &enabled))
|
||||
{
|
||||
@@ -943,14 +919,19 @@ void scenes::lobby::gui_settings()
|
||||
}
|
||||
else
|
||||
{
|
||||
if (body_tracker == xr::body_tracker_type::fb)
|
||||
imgui_ctx->tooltip(_("Requires 'Hand and body tracking' to be enabled in the Quest movement tracking settings,\notherwise body data will be guessed from controller and headset positions"));
|
||||
std::visit(utils::overloaded{
|
||||
[](auto &) {},
|
||||
[this](xr::fb_body_tracker &) {
|
||||
imgui_ctx->tooltip(_("Requires 'Hand and body tracking' to be enabled in the Quest movement tracking settings,\notherwise body data will be guessed from controller and headset positions"));
|
||||
},
|
||||
},
|
||||
application::get_body_tracker());
|
||||
}
|
||||
}
|
||||
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
}
|
||||
if (body_tracker == xr::body_tracker_type::fb)
|
||||
if (std::holds_alternative<xr::fb_body_tracker>(application::get_body_tracker()))
|
||||
{
|
||||
ImGui::BeginDisabled(not config.check_feature(feature::body_tracking));
|
||||
ImGui::Indent();
|
||||
@@ -976,7 +957,7 @@ void scenes::lobby::gui_settings()
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
|
||||
ImGui::BeginDisabled(system.passthrough_supported() == xr::passthrough_type::none);
|
||||
ImGui::BeginDisabled(passthrough_supported == xr::system::passthrough_type::no_passthrough);
|
||||
if (ImGui::Checkbox(_S("Enable video passthrough in lobby"), &config.passthrough_enabled))
|
||||
{
|
||||
setup_passthrough();
|
||||
@@ -987,13 +968,6 @@ void scenes::lobby::gui_settings()
|
||||
imgui_ctx->tooltip(_("This feature is not supported by your headset"));
|
||||
ImGui::EndDisabled();
|
||||
|
||||
{
|
||||
ImGui::Checkbox(_S("Enable in-stream window"), &config.enable_stream_gui);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered())
|
||||
imgui_ctx->tooltip(_("Enables the configuration window to be shown while the game is streaming.\nIf enabled, the window is activated by pressing both thumbsticks."));
|
||||
}
|
||||
|
||||
ImGui::PopStyleVar(); // ImGuiStyleVar_ItemSpacing
|
||||
}
|
||||
|
||||
@@ -1308,12 +1282,12 @@ void scenes::lobby::gui_first_run()
|
||||
item{
|
||||
.f = feature::face_tracking,
|
||||
.text = _S("Enable face tracking?"),
|
||||
.supported = not std::holds_alternative<std::monostate>(face_tracker),
|
||||
.supported = application::get_face_tracking_supported(),
|
||||
},
|
||||
item{
|
||||
.f = feature::body_tracking,
|
||||
.text = _S("Enable body tracking?"),
|
||||
.supported = system.body_tracker_supported() != xr::body_tracker_type::none,
|
||||
.supported = application::get_body_tracking_supported(),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1643,22 +1617,11 @@ static auto face_weights()
|
||||
return res;
|
||||
}
|
||||
|
||||
static const char * get_face_icon(XrTime predicted_display_time, xr::face_tracker & face_tracker)
|
||||
static const char * get_face_icon(XrTime predicted_display_time)
|
||||
{
|
||||
static const auto w = face_weights();
|
||||
wivrn::from_headset::tracking::fb_face2 expression;
|
||||
const char * result = nullptr;
|
||||
std::visit(utils::overloaded{
|
||||
[](std::monostate &) {},
|
||||
[&](xr::htc_face_tracker &) { result = ICON_FA_FACE_SMILE_WINK; },
|
||||
[&](auto & ft) {
|
||||
ft.get_weights(predicted_display_time, expression);
|
||||
},
|
||||
},
|
||||
face_tracker);
|
||||
|
||||
if (result)
|
||||
return result;
|
||||
std::get<xr::fb_face_tracker2>(application::get_face_tracker()).get_weights(predicted_display_time, expression);
|
||||
|
||||
if (not expression.is_valid)
|
||||
return ICON_FA_FACE_MEH;
|
||||
@@ -1701,7 +1664,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
|
||||
.icon_disabled = ICON_FA_MICROPHONE_SLASH,
|
||||
});
|
||||
|
||||
if (system.hand_tracking_supported())
|
||||
if (application::get_hand_tracking_supported())
|
||||
{
|
||||
items.push_back({
|
||||
.f = feature::hand_tracking,
|
||||
@@ -1722,18 +1685,21 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
|
||||
});
|
||||
}
|
||||
|
||||
if (not std::holds_alternative<std::monostate>(face_tracker))
|
||||
if (application::get_face_tracking_supported())
|
||||
{
|
||||
const char * icon_enabled = std::holds_alternative<xr::fb_face_tracker2>(application::get_face_tracker())
|
||||
? get_face_icon(predicted_display_time)
|
||||
: ICON_FA_FACE_KISS_WINK_HEART;
|
||||
items.push_back({
|
||||
.f = feature::face_tracking,
|
||||
.tooltip_enabled = _("Face tracking is enabled"),
|
||||
.tooltip_disabled = _("Face tracking is disabled"),
|
||||
.icon_enabled = get_face_icon(predicted_display_time, face_tracker),
|
||||
.icon_enabled = icon_enabled,
|
||||
.icon_disabled = ICON_FA_FACE_MEH_BLANK,
|
||||
});
|
||||
}
|
||||
|
||||
if (system.body_tracker_supported() != xr::body_tracker_type::none)
|
||||
if (application::get_body_tracking_supported())
|
||||
{
|
||||
items.push_back({
|
||||
.f = feature::body_tracking,
|
||||
@@ -1807,7 +1773,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
|
||||
if (*status.charge > 0.995)
|
||||
icon_nr = 5;
|
||||
else
|
||||
icon_nr = instance.now() / 500'000'000 % 5;
|
||||
icon_nr = application::now() / 500'000'000 % 5;
|
||||
}
|
||||
else
|
||||
icon_nr = std::round((*status.charge) * 4);
|
||||
@@ -1924,7 +1890,7 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 10);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {10, 10});
|
||||
ImGui::Begin("WiVRn", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
|
||||
gui_connected(predicted_display_time);
|
||||
gui_connected();
|
||||
ImGui::End();
|
||||
ImGui::PopStyleVar(3); // ImGuiStyleVar_WindowPadding, ImGuiStyleVar_FrameRounding, ImGuiStyleVar_FramePadding
|
||||
}
|
||||
@@ -2036,7 +2002,7 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
|
||||
|
||||
if (not is_gui_visible(*imgui_ctx, predicted_display_time))
|
||||
{
|
||||
if (system.hand_tracking_supported())
|
||||
if (application::get_hand_tracking_supported())
|
||||
display_recentering_tip(*imgui_ctx, _("Press the grip button or put your palm up\nto move the main window"));
|
||||
else
|
||||
display_recentering_tip(*imgui_ctx, _("Press the grip button to move the main window"));
|
||||
|
||||
+101
-77
@@ -17,9 +17,11 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "constants.h"
|
||||
#include "xr/body_tracker.h"
|
||||
#include "xr/face_tracker.h"
|
||||
#include "utils/overloaded.h"
|
||||
#include "xr/fb_body_tracker.h"
|
||||
#include "xr/fb_face_tracker2.h"
|
||||
#include "xr/htc_body_tracker.h"
|
||||
#include "xr/pico_body_tracker.h"
|
||||
#include "xr/space.h"
|
||||
#include <glm/gtc/matrix_access.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
@@ -40,7 +42,6 @@
|
||||
#include "utils/ranges.h"
|
||||
#include "vk/pipeline.h"
|
||||
#include "vk/shader.h"
|
||||
#include "vk/specialization_constants.h"
|
||||
#include "wivrn_packets.h"
|
||||
#include <algorithm>
|
||||
#include <mutex>
|
||||
@@ -188,11 +189,7 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
||||
self->network_session = std::move(network_session);
|
||||
|
||||
self->network_session->send_control([&]() {
|
||||
from_headset::headset_info_packet info{
|
||||
.language = application::get_messages_info().language,
|
||||
.country = application::get_messages_info().country,
|
||||
.variant = application::get_messages_info().variant,
|
||||
};
|
||||
from_headset::headset_info_packet info{};
|
||||
|
||||
auto view = self->system.view_configuration_views(self->viewconfig)[0];
|
||||
view = override_view(view, guess_model());
|
||||
@@ -254,42 +251,39 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
||||
|
||||
if (config.check_feature(feature::face_tracking))
|
||||
{
|
||||
switch (self->system.face_tracker_supported())
|
||||
{
|
||||
case xr::face_tracker_type::none:
|
||||
info.face_tracking = from_headset::face_type::none;
|
||||
break;
|
||||
case xr::face_tracker_type::fb:
|
||||
case xr::face_tracker_type::pico:
|
||||
info.face_tracking = from_headset::face_type::fb2;
|
||||
break;
|
||||
case xr::face_tracker_type::htc:
|
||||
info.face_tracking = from_headset::face_type::htc;
|
||||
break;
|
||||
}
|
||||
info.face_tracking = std::visit(utils::overloaded{
|
||||
[](std::monostate &) {
|
||||
return from_headset::face_type::none;
|
||||
},
|
||||
[](xr::fb_face_tracker2 &) {
|
||||
return from_headset::face_type::fb2;
|
||||
},
|
||||
[](xr::htc_face_tracker &) {
|
||||
return from_headset::face_type::htc;
|
||||
},
|
||||
[](xr::pico_face_tracker &) {
|
||||
return from_headset::face_type::fb2;
|
||||
},
|
||||
},
|
||||
application::get_face_tracker());
|
||||
}
|
||||
|
||||
info.num_generic_trackers = 0;
|
||||
if (config.check_feature(feature::body_tracking))
|
||||
{
|
||||
switch (self->system.body_tracker_supported())
|
||||
{
|
||||
case xr::body_tracker_type::none:
|
||||
break;
|
||||
case xr::body_tracker_type::fb:
|
||||
info.num_generic_trackers = xr::fb_body_tracker::get_whitelisted_joints(config.fb_lower_body, config.fb_hip).size();
|
||||
break;
|
||||
case xr::body_tracker_type::htc:
|
||||
info.num_generic_trackers = application::get_generic_trackers().size();
|
||||
break;
|
||||
case xr::body_tracker_type::pico:
|
||||
info.num_generic_trackers = xr::pico_body_tracker::joint_whitelist.size();
|
||||
break;
|
||||
}
|
||||
info.num_generic_trackers = std::visit(utils::overloaded{
|
||||
[&](std::monostate &) {
|
||||
return size_t(0);
|
||||
},
|
||||
[&](auto & b) {
|
||||
return b.count();
|
||||
},
|
||||
},
|
||||
application::get_body_tracker());
|
||||
}
|
||||
|
||||
info.palm_pose = application::space(xr::spaces::palm_left) or application::space(xr::spaces::palm_right);
|
||||
info.passthrough = self->system.passthrough_supported() != xr::passthrough_type::none;
|
||||
info.passthrough = self->system.passthrough_supported() != xr::system::passthrough_type::no_passthrough;
|
||||
info.system_name = std::string(self->system.properties().systemName);
|
||||
|
||||
audio::get_audio_description(info);
|
||||
@@ -317,6 +311,15 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const auto & info = application::get_messages_info();
|
||||
self->network_session->send_control(from_headset::get_application_list{
|
||||
.language = info.language,
|
||||
.country = info.country,
|
||||
.variant = info.variant,
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
const auto & config = application::get_config();
|
||||
self->override_foveation_enable = config.override_foveation_enable;
|
||||
@@ -360,7 +363,7 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
||||
{
|
||||
self->haptics_actions.emplace(id, haptics_action{
|
||||
.action = action.first,
|
||||
.path = self->instance.string_to_path(path),
|
||||
.path = application::string_to_path(path),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -391,7 +394,7 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
||||
|
||||
void scenes::stream::on_focused()
|
||||
{
|
||||
gui_status_last_change = instance.now();
|
||||
gui_status_last_change = application::now();
|
||||
|
||||
auto views = system.view_configuration_views(viewconfig);
|
||||
// stream_view = override_view(views[0], guess_model());
|
||||
@@ -399,7 +402,7 @@ void scenes::stream::on_focused()
|
||||
height = views[0].recommendedImageRectHeight;
|
||||
|
||||
renderer.emplace(device, physical_device, queue, commandpool);
|
||||
loader.emplace(device, physical_device, queue, queue_family_index, renderer->get_default_material());
|
||||
loader.emplace(device, physical_device, queue, application::queue_family_index(), renderer->get_default_material());
|
||||
|
||||
std::string profile = controller_name();
|
||||
input.emplace(
|
||||
@@ -467,11 +470,8 @@ void scenes::stream::on_focused()
|
||||
swapchain_imgui,
|
||||
std::vector{vp});
|
||||
|
||||
if (application::get_config().enable_stream_gui)
|
||||
{
|
||||
plots_toggle_1 = get_action("plots_toggle_1").first;
|
||||
plots_toggle_2 = get_action("plots_toggle_2").first;
|
||||
}
|
||||
plots_toggle_1 = get_action("plots_toggle_1").first;
|
||||
plots_toggle_2 = get_action("plots_toggle_2").first;
|
||||
recenter_left = get_action("recenter_left").first;
|
||||
recenter_right = get_action("recenter_right").first;
|
||||
foveation_pitch = get_action("foveation_pitch").first;
|
||||
@@ -494,8 +494,6 @@ void scenes::stream::on_unfocused()
|
||||
loader.reset();
|
||||
renderer.reset();
|
||||
clear_swapchains();
|
||||
left_hand.reset();
|
||||
right_hand.reset();
|
||||
|
||||
imgui_ctx.reset();
|
||||
swapchain_imgui = xr::swapchain();
|
||||
@@ -526,16 +524,16 @@ void scenes::stream::push_blit_handle(shard_accumulator * decoder, std::shared_p
|
||||
{
|
||||
if (decoder != decoders[stream].decoder.get())
|
||||
return;
|
||||
handle->feedback.received_from_decoder = instance.now();
|
||||
handle->feedback.received_from_decoder = application::now();
|
||||
std::swap(handle, decoders[stream].latest_frames[handle->feedback.frame_index % decoders[stream].latest_frames.size()]);
|
||||
}
|
||||
|
||||
if (state_ != state::streaming and std::ranges::all_of(decoders, [](accumulator_images & i) {
|
||||
return i.alpha() or not i.empty();
|
||||
return i.alpha() or not i.frames().empty();
|
||||
}))
|
||||
{
|
||||
state_ = state::streaming;
|
||||
spdlog::info("Stream scene ready at t={}", instance.now());
|
||||
spdlog::info("Stream scene ready at t={}", application::now());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -550,14 +548,15 @@ bool scenes::stream::accumulator_images::alpha() const
|
||||
return decoder->desc().channels == wivrn::to_headset::video_stream_description::channels_t::alpha;
|
||||
}
|
||||
|
||||
bool scenes::stream::accumulator_images::empty() const
|
||||
std::vector<uint64_t> scenes::stream::accumulator_images::frames() const
|
||||
{
|
||||
std::vector<uint64_t> result;
|
||||
for (const auto & frame: latest_frames)
|
||||
{
|
||||
if (frame)
|
||||
return false;
|
||||
result.push_back(frame->feedback.frame_index);
|
||||
}
|
||||
return true;
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<shard_accumulator::blit_handle>> scenes::stream::common_frame(XrTime display_time)
|
||||
@@ -767,15 +766,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
}
|
||||
|
||||
if (state_ == state::stalled)
|
||||
{
|
||||
network_session->send_control(from_headset::get_application_list{
|
||||
.language = application::get_messages_info().language,
|
||||
.country = application::get_messages_info().country,
|
||||
.variant = application::get_messages_info().variant,
|
||||
});
|
||||
|
||||
application::pop_scene();
|
||||
}
|
||||
|
||||
assert(swapchain);
|
||||
for (auto & i: decoders)
|
||||
@@ -808,19 +799,51 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
|
||||
const auto & description = i.decoder->desc();
|
||||
vk::Extent2D image_size = i.decoder->image_size();
|
||||
std::array useful_size{
|
||||
float(description.width) / image_size.width,
|
||||
float(description.height) / image_size.height,
|
||||
};
|
||||
spdlog::info("useful size: {}x{} with buffer {}x{}",
|
||||
description.width,
|
||||
description.height,
|
||||
image_size.width,
|
||||
image_size.height);
|
||||
|
||||
auto vert_constants = make_specialization_constants(
|
||||
float(description.width) / image_size.width,
|
||||
float(description.height) / image_size.height);
|
||||
std::array specialization_constants_desc{
|
||||
vk::SpecializationMapEntry{
|
||||
.constantID = 0,
|
||||
.offset = 0,
|
||||
.size = sizeof(float),
|
||||
},
|
||||
vk::SpecializationMapEntry{
|
||||
.constantID = 1,
|
||||
.offset = sizeof(float),
|
||||
.size = sizeof(float),
|
||||
}};
|
||||
|
||||
auto frag_constants = make_specialization_constants(
|
||||
VkBool32(need_srgb_conversion(guess_model())),
|
||||
VkBool32(i.alpha()));
|
||||
vk::SpecializationInfo vert_specialization_info;
|
||||
vert_specialization_info.setMapEntries(specialization_constants_desc);
|
||||
vert_specialization_info.setData<float>(useful_size);
|
||||
|
||||
std::array<VkBool32, 2> constants = {
|
||||
need_srgb_conversion(guess_model()),
|
||||
i.alpha(),
|
||||
};
|
||||
std::array frag_specialization_constant_desc = {
|
||||
vk::SpecializationMapEntry{
|
||||
.constantID = 0,
|
||||
.offset = 0,
|
||||
.size = sizeof(constants[0]),
|
||||
},
|
||||
vk::SpecializationMapEntry{
|
||||
.constantID = 1,
|
||||
.offset = sizeof(constants[0]),
|
||||
.size = sizeof(constants[1]),
|
||||
},
|
||||
};
|
||||
vk::SpecializationInfo frag_specialization_info;
|
||||
frag_specialization_info.setMapEntries(frag_specialization_constant_desc);
|
||||
frag_specialization_info.setData<VkBool32>(constants);
|
||||
|
||||
// Create graphics pipeline
|
||||
vk::raii::ShaderModule vertex_shader = load_shader(device, "stream.vert");
|
||||
@@ -838,13 +861,13 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
.stage = vk::ShaderStageFlagBits::eVertex,
|
||||
.module = *vertex_shader,
|
||||
.pName = "main",
|
||||
.pSpecializationInfo = vert_constants,
|
||||
.pSpecializationInfo = &vert_specialization_info,
|
||||
},
|
||||
{
|
||||
.stage = vk::ShaderStageFlagBits::eFragment,
|
||||
.module = *fragment_shader,
|
||||
.pName = "main",
|
||||
.pSpecializationInfo = frag_constants,
|
||||
.pSpecializationInfo = &frag_specialization_info,
|
||||
}},
|
||||
.VertexBindingDescriptions = {},
|
||||
.VertexAttributeDescriptions = {},
|
||||
@@ -930,7 +953,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
if (not blit_handle or not *i.blit_pipeline)
|
||||
continue;
|
||||
|
||||
blit_handle->feedback.blitted = instance.now();
|
||||
blit_handle->feedback.blitted = application::now();
|
||||
if (blit_handle->feedback.blitted - blit_handle->feedback.received_from_decoder > 1'000'000'000)
|
||||
state_ = stream::state::stalled;
|
||||
++blit_handle->feedback.times_displayed;
|
||||
@@ -979,10 +1002,6 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
uint16_t x_offset = 0;
|
||||
for (auto & out: decoder_output)
|
||||
{
|
||||
vk::Extent2D decoder_out_size{
|
||||
.width = decoder_out_image.info().extent.width,
|
||||
.height = decoder_out_image.info().extent.height,
|
||||
};
|
||||
command_buffer.beginRenderPass(
|
||||
{
|
||||
.renderPass = *blit_render_pass,
|
||||
@@ -1291,7 +1310,10 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript
|
||||
}
|
||||
|
||||
// Create outputs for the decoders
|
||||
decoder_out_size = vk::Extent2D{video_width, video_height};
|
||||
{
|
||||
decoder_out_format = vk::Format::eA8B8G8R8SrgbPack32;
|
||||
|
||||
vk::ImageCreateInfo image_info{
|
||||
.flags = vk::ImageCreateFlags{},
|
||||
.imageType = vk::ImageType::e2D,
|
||||
@@ -1315,7 +1337,7 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript
|
||||
vk::ImageViewCreateInfo image_view_info{
|
||||
.image = vk::Image{decoder_out_image},
|
||||
.viewType = vk::ImageViewType::e2D,
|
||||
.format = image_info.format,
|
||||
.format = vk::Format::eA8B8G8R8SrgbPack32,
|
||||
.components = {},
|
||||
.subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
@@ -1339,8 +1361,8 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript
|
||||
.renderPass = *blit_render_pass,
|
||||
.attachmentCount = 1,
|
||||
.pAttachments = &*output.image_view,
|
||||
.width = image_info.extent.width,
|
||||
.height = image_info.extent.height,
|
||||
.width = decoder_out_size.width,
|
||||
.height = decoder_out_size.height,
|
||||
.layers = 1,
|
||||
});
|
||||
}
|
||||
@@ -1365,7 +1387,7 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript
|
||||
spdlog::info("Creating decoder size {}x{} offset {},{}", item.width, item.height, item.offset_x, item.offset_y);
|
||||
|
||||
decoders.push_back(accumulator_images{
|
||||
.decoder = std::make_unique<shard_accumulator>(device, physical_device, instance, item, description.fps, shared_from_this(), stream_index),
|
||||
.decoder = std::make_unique<shard_accumulator>(device, physical_device, item, description.fps, shared_from_this(), stream_index),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1407,6 +1429,8 @@ void scenes::stream::setup_reprojection_swapchain(uint32_t swapchain_width, uint
|
||||
device,
|
||||
physical_device,
|
||||
decoder_out_image,
|
||||
vk::Extent2D{.width = video_width, .height = video_height},
|
||||
2,
|
||||
swapchain_images,
|
||||
extent,
|
||||
swapchain.format());
|
||||
|
||||
+7
-15
@@ -48,13 +48,6 @@ public:
|
||||
};
|
||||
static const size_t image_buffer_size = 3;
|
||||
|
||||
struct app
|
||||
{
|
||||
std::string id;
|
||||
std::string name;
|
||||
std::vector<std::byte> image;
|
||||
};
|
||||
|
||||
private:
|
||||
static const size_t view_count = 2;
|
||||
|
||||
@@ -67,12 +60,12 @@ private:
|
||||
vk::DescriptorSet descriptor_set = nullptr;
|
||||
vk::raii::PipelineLayout blit_pipeline_layout = nullptr;
|
||||
vk::raii::Pipeline blit_pipeline = nullptr;
|
||||
// latest frames, rolling buffer
|
||||
// latest frames from oldest to most recent
|
||||
std::array<std::shared_ptr<wivrn::shard_accumulator::blit_handle>, image_buffer_size> latest_frames;
|
||||
|
||||
std::shared_ptr<wivrn::shard_accumulator::blit_handle> frame(uint64_t id) const;
|
||||
bool alpha() const;
|
||||
bool empty() const;
|
||||
std::vector<uint64_t> frames() const;
|
||||
};
|
||||
|
||||
wifi_lock::wifi wifi;
|
||||
@@ -84,9 +77,9 @@ private:
|
||||
std::unique_ptr<wivrn_session> network_session;
|
||||
std::atomic<bool> exiting = false;
|
||||
std::thread network_thread;
|
||||
thread_safe<to_headset::tracking_control> tracking_control{};
|
||||
std::mutex tracking_control_mutex;
|
||||
to_headset::tracking_control tracking_control{};
|
||||
std::array<std::atomic<interaction_profile>, 2> interaction_profiles; // left and right hand
|
||||
std::atomic<bool> interaction_profile_changed = false;
|
||||
std::atomic<bool> recenter_requested = false;
|
||||
std::atomic<XrDuration> display_time_phase = 0;
|
||||
std::atomic<XrDuration> display_time_period = 0;
|
||||
@@ -100,6 +93,8 @@ private:
|
||||
vk::raii::DescriptorPool blit_descriptor_pool = nullptr;
|
||||
vk::raii::RenderPass blit_render_pass = nullptr;
|
||||
|
||||
vk::Extent2D decoder_out_size;
|
||||
vk::Format decoder_out_format;
|
||||
image_allocation decoder_out_image;
|
||||
|
||||
struct renderpass_output
|
||||
@@ -130,8 +125,6 @@ private:
|
||||
|
||||
std::optional<audio> audio_handle;
|
||||
|
||||
std::optional<xr::hand_tracker> left_hand;
|
||||
std::optional<xr::hand_tracker> right_hand;
|
||||
std::optional<input_profile> input;
|
||||
static inline const uint32_t layer_controllers = 1 << 0;
|
||||
static inline const uint32_t layer_rays = 1 << 1;
|
||||
@@ -183,7 +176,7 @@ private:
|
||||
std::vector<std::shared_ptr<wivrn::shard_accumulator::blit_handle>> current_blit_handles;
|
||||
|
||||
// Last application list received from server
|
||||
thread_safe<std::vector<app>> applications;
|
||||
thread_safe<to_headset::application_list> applications;
|
||||
|
||||
stream();
|
||||
|
||||
@@ -209,7 +202,6 @@ public:
|
||||
void operator()(to_headset::video_stream_description &&);
|
||||
void operator()(to_headset::refresh_rate_change &&);
|
||||
void operator()(to_headset::application_list &&);
|
||||
void operator()(to_headset::application_icon &&);
|
||||
void operator()(audio_data &&);
|
||||
|
||||
void push_blit_handle(wivrn::shard_accumulator * decoder, std::shared_ptr<wivrn::shard_accumulator::blit_handle> handle);
|
||||
|
||||
@@ -389,14 +389,8 @@ void scenes::stream::gui_performance_metrics()
|
||||
|
||||
ImPlot::PopStyleColor(5);
|
||||
{
|
||||
ImGui::Text(
|
||||
"%s",
|
||||
fmt::format(
|
||||
_F("Estimated motion to photons latency: {}ms"),
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
tracking_control.lock()->max_offset)
|
||||
.count())
|
||||
.c_str());
|
||||
std::lock_guard lock(tracking_control_mutex);
|
||||
ImGui::Text("%s", fmt::format(_F("Estimated motion to photons latency: {}ms"), std::chrono::duration_cast<std::chrono::milliseconds>(tracking_control.max_offset).count()).c_str());
|
||||
|
||||
if (is_gui_interactable())
|
||||
ImGui::Text("%s", _S("Press the grip button to move the window"));
|
||||
@@ -423,12 +417,7 @@ void scenes::stream::gui_compact_view()
|
||||
f(_S("Upload"), 8 * compact_bandwidth_tx * 1e-6, "Mbit/s");
|
||||
f(_S("CPU time"), compact_cpu_time * 1000, "ms");
|
||||
f(_S("GPU time"), compact_gpu_time * 1000, "ms");
|
||||
f(_S("Motion to photon latency"),
|
||||
std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
tracking_control.lock()->max_offset)
|
||||
.count() *
|
||||
1e-3f,
|
||||
"ms");
|
||||
f(_S("Motion to photon latency"), std::chrono::duration_cast<std::chrono::microseconds>(tracking_control.max_offset).count() * 1e-3f, "ms");
|
||||
ImGui::EndTable();
|
||||
}
|
||||
}
|
||||
@@ -626,8 +615,6 @@ static glm::vec4 compute_ray_limits(const XrPosef & pose, float margin = 0)
|
||||
|
||||
void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicted_display_period)
|
||||
{
|
||||
if (not(plots_toggle_1 and plots_toggle_2))
|
||||
return;
|
||||
bool interactable = true;
|
||||
XrSpace world_space = application::space(xr::spaces::world);
|
||||
auto views = session.locate_views(viewconfig, predicted_display_time, world_space).second;
|
||||
@@ -645,19 +632,6 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
break;
|
||||
}
|
||||
imgui_ctx->set_controllers_enabled(interactable);
|
||||
if (interactable)
|
||||
{
|
||||
if (system.hand_tracking_supported())
|
||||
{
|
||||
left_hand = session.create_hand_tracker(XR_HAND_LEFT_EXT);
|
||||
right_hand = session.create_hand_tracker(XR_HAND_RIGHT_EXT);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
left_hand.reset();
|
||||
right_hand.reset();
|
||||
}
|
||||
|
||||
if (gui_status != last_gui_status)
|
||||
{
|
||||
@@ -889,10 +863,10 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
bool hide_left_controller = false;
|
||||
bool hide_right_controller = false;
|
||||
|
||||
if (left_hand and right_hand)
|
||||
if (application::get_hand_tracking_supported())
|
||||
{
|
||||
auto left = left_hand->locate(world_space, predicted_display_time);
|
||||
auto right = right_hand->locate(world_space, predicted_display_time);
|
||||
auto left = application::get_left_hand().locate(world_space, predicted_display_time);
|
||||
auto right = application::get_right_hand().locate(world_space, predicted_display_time);
|
||||
|
||||
if (left and xr::hand_tracker::check_flags(*left, XR_SPACE_LOCATION_POSITION_TRACKED_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT, 0))
|
||||
hide_left_controller = true;
|
||||
|
||||
@@ -111,26 +111,8 @@ void scenes::stream::operator()(to_headset::application_list && apps)
|
||||
std::ranges::sort(apps.applications, [](auto & l, auto & r) {
|
||||
return una::casesens::collate_utf8(l.name, r.name) < 0;
|
||||
});
|
||||
|
||||
auto locked = applications.lock();
|
||||
|
||||
locked->clear();
|
||||
locked->reserve(apps.applications.size());
|
||||
for (const auto & i: apps.applications)
|
||||
{
|
||||
locked->push_back(app{
|
||||
.id = std::move(i.id),
|
||||
.name = std::move(i.name),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void scenes::stream::operator()(to_headset::application_icon && icon)
|
||||
{
|
||||
auto locked = applications.lock();
|
||||
|
||||
if (auto it = std::ranges::find(*locked, icon.id, &app::id); it != locked->end())
|
||||
it->image = std::move(icon.image);
|
||||
*locked = std::move(apps);
|
||||
}
|
||||
|
||||
void scenes::stream::start_application(std::string appid)
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#include "vk/allocation.h"
|
||||
#include "vk/pipeline.h"
|
||||
#include "vk/shader.h"
|
||||
#include "vk/specialization_constants.h"
|
||||
#include <array>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
@@ -38,7 +37,13 @@ struct stream_reprojection::vertex
|
||||
alignas(8) glm::vec2 position;
|
||||
// input texture coordinates
|
||||
alignas(8) glm::vec2 uv;
|
||||
int32_t shading_rate;
|
||||
};
|
||||
|
||||
struct SgsrSpecializationConstants
|
||||
{
|
||||
VkBool32 use_edge_direction;
|
||||
float edge_threshold;
|
||||
float edge_sharpness;
|
||||
};
|
||||
|
||||
void stream_reprojection::ensure_vertices(size_t num_vertices)
|
||||
@@ -69,16 +74,16 @@ stream_reprojection::vertex * stream_reprojection::get_vertices(size_t view)
|
||||
stream_reprojection::stream_reprojection(
|
||||
vk::raii::Device & device,
|
||||
vk::raii::PhysicalDevice & physical_device,
|
||||
image_allocation & input_image,
|
||||
vk::Image input_image_,
|
||||
vk::Extent2D input_extent,
|
||||
uint32_t view_count,
|
||||
std::vector<vk::Image> output_images_,
|
||||
vk::Extent2D output_extent,
|
||||
vk::Format format) :
|
||||
view_count(input_image.info().arrayLayers),
|
||||
view_count(view_count),
|
||||
device(device),
|
||||
input_extent{
|
||||
.width = input_image.info().extent.width,
|
||||
.height = input_image.info().extent.height,
|
||||
},
|
||||
input_image(input_image_),
|
||||
input_extent(input_extent),
|
||||
output_images(std::move(output_images_)),
|
||||
output_extent(output_extent)
|
||||
{
|
||||
@@ -139,7 +144,7 @@ stream_reprojection::stream_reprojection(
|
||||
vk::ImageViewCreateInfo iv_info{
|
||||
.image = input_image,
|
||||
.viewType = vk::ImageViewType::e2D,
|
||||
.format = input_image.info().format,
|
||||
.format = vk::Format::eA8B8G8R8SrgbPack32,
|
||||
.components = {
|
||||
.r = vk::ComponentSwizzle::eIdentity,
|
||||
.g = vk::ComponentSwizzle::eIdentity,
|
||||
@@ -214,30 +219,50 @@ stream_reprojection::stream_reprojection(
|
||||
|
||||
renderpass = vk::raii::RenderPass(device, renderpass_info.get());
|
||||
|
||||
const auto & vk_device_extensions = application::get_vk_device_extensions();
|
||||
bool fragment_shading_rate = false;
|
||||
if (utils::contains(vk_device_extensions, VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME) and
|
||||
utils::contains(vk_device_extensions, VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME))
|
||||
{
|
||||
const auto & [prop, rate_prop] = physical_device.getProperties2<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceFragmentShadingRatePropertiesKHR>();
|
||||
const auto & [feat, fragment_feat] = physical_device.getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceFragmentShadingRateFeaturesKHR>();
|
||||
fragment_shading_rate = rate_prop.fragmentShadingRateNonTrivialCombinerOps and
|
||||
fragment_feat.primitiveFragmentShadingRate and
|
||||
fragment_feat.attachmentFragmentShadingRate;
|
||||
}
|
||||
|
||||
// Vertex shader
|
||||
vk::raii::ShaderModule vertex_shader = load_shader(device, fragment_shading_rate ? "reprojection_vsr.vert" : "reprojection.vert");
|
||||
vk::raii::ShaderModule vertex_shader = load_shader(device, "reprojection.vert");
|
||||
|
||||
// Fragment shader
|
||||
std::string fragment_shader_name = "reprojection.frag";
|
||||
|
||||
const configuration::sgsr_settings & sgsr = application::get_config().sgsr;
|
||||
auto sgsr_specialization = make_specialization_constants(
|
||||
VkBool32(sgsr.use_edge_direction),
|
||||
float(sgsr.edge_threshold / 255.f),
|
||||
float(sgsr.edge_sharpness));
|
||||
vk::SpecializationInfo fragment_specialization_info;
|
||||
SgsrSpecializationConstants fragment_specialization_constants;
|
||||
std::vector<vk::SpecializationMapEntry> fragment_specialization_constants_desc;
|
||||
const configuration::sgsr_settings sgsr = application::get_config().sgsr;
|
||||
if (sgsr.enabled)
|
||||
{
|
||||
fragment_shader_name = "reprojection_sgsr.frag";
|
||||
|
||||
vk::raii::ShaderModule fragment_shader = load_shader(device, sgsr.enabled ? "reprojection_sgsr.frag" : "reprojection.frag");
|
||||
fragment_specialization_constants = {
|
||||
.use_edge_direction = sgsr.use_edge_direction,
|
||||
.edge_threshold = float(sgsr.edge_threshold / 255.0),
|
||||
.edge_sharpness = sgsr.edge_sharpness,
|
||||
};
|
||||
|
||||
fragment_specialization_constants_desc = {
|
||||
vk::SpecializationMapEntry{
|
||||
.constantID = 0,
|
||||
.offset = offsetof(SgsrSpecializationConstants, use_edge_direction),
|
||||
.size = sizeof(fragment_specialization_constants.use_edge_direction),
|
||||
},
|
||||
vk::SpecializationMapEntry{
|
||||
.constantID = 1,
|
||||
.offset = offsetof(SgsrSpecializationConstants, edge_threshold),
|
||||
.size = sizeof(fragment_specialization_constants.edge_threshold),
|
||||
},
|
||||
vk::SpecializationMapEntry{
|
||||
.constantID = 2,
|
||||
.offset = offsetof(SgsrSpecializationConstants, edge_sharpness),
|
||||
.size = sizeof(fragment_specialization_constants.edge_sharpness),
|
||||
},
|
||||
};
|
||||
|
||||
fragment_specialization_info.setMapEntries(fragment_specialization_constants_desc);
|
||||
fragment_specialization_info.setDataSize(sizeof(fragment_specialization_constants));
|
||||
fragment_specialization_info.setPData(&fragment_specialization_constants);
|
||||
}
|
||||
|
||||
vk::raii::ShaderModule fragment_shader = load_shader(device, fragment_shader_name);
|
||||
|
||||
// Create graphics pipeline
|
||||
vk::PipelineLayoutCreateInfo pipeline_layout_info;
|
||||
@@ -245,7 +270,7 @@ stream_reprojection::stream_reprojection(
|
||||
|
||||
layout = vk::raii::PipelineLayout(device, pipeline_layout_info);
|
||||
|
||||
vk::pipeline_builder pipeline_info_builder{
|
||||
vk::pipeline_builder pipeline_info{
|
||||
.flags = {},
|
||||
.Stages = {
|
||||
{
|
||||
@@ -257,7 +282,7 @@ stream_reprojection::stream_reprojection(
|
||||
.stage = vk::ShaderStageFlagBits::eFragment,
|
||||
.module = *fragment_shader,
|
||||
.pName = "main",
|
||||
.pSpecializationInfo = sgsr.enabled ? sgsr_specialization.info() : nullptr,
|
||||
.pSpecializationInfo = &fragment_specialization_info,
|
||||
},
|
||||
},
|
||||
.VertexBindingDescriptions = {
|
||||
@@ -280,12 +305,6 @@ stream_reprojection::stream_reprojection(
|
||||
.format = vk::Format::eR32G32Sfloat,
|
||||
.offset = offsetof(vertex, uv),
|
||||
},
|
||||
{
|
||||
.location = 2,
|
||||
.binding = 0,
|
||||
.format = vk::Format::eR32Sint,
|
||||
.offset = offsetof(vertex, shading_rate),
|
||||
},
|
||||
},
|
||||
.InputAssemblyState = {{
|
||||
.topology = vk::PrimitiveTopology::eTriangleStrip,
|
||||
@@ -318,48 +337,6 @@ stream_reprojection::stream_reprojection(
|
||||
.subpass = 0,
|
||||
};
|
||||
|
||||
vk::GraphicsPipelineCreateInfo pipeline_info(pipeline_info_builder);
|
||||
|
||||
// Variable fragment shading
|
||||
std::array combiner{
|
||||
vk::FragmentShadingRateCombinerOpKHR::eMax,
|
||||
vk::FragmentShadingRateCombinerOpKHR::eMax,
|
||||
};
|
||||
vk::PipelineFragmentShadingRateStateCreateInfoKHR shading{
|
||||
.fragmentSize = vk::Extent2D{1, 1},
|
||||
.combinerOps = combiner,
|
||||
};
|
||||
if (fragment_shading_rate)
|
||||
{
|
||||
pipeline_info.pNext = &shading;
|
||||
|
||||
spdlog::info("Available fragment shading rates:");
|
||||
for (const auto rate: physical_device.getFragmentShadingRatesKHR())
|
||||
{
|
||||
if (rate.sampleCounts & vk::SampleCountFlagBits::e1)
|
||||
{
|
||||
spdlog::info("\tfragment size: {}x{}", rate.fragmentSize.width, rate.fragmentSize.height);
|
||||
int flags = 0;
|
||||
if (rate.fragmentSize.width == 4)
|
||||
flags |= 8;
|
||||
else if (rate.fragmentSize.width == 2)
|
||||
flags |= 4;
|
||||
if (rate.fragmentSize.height == 4)
|
||||
flags |= 2;
|
||||
else if (rate.fragmentSize.height == 2)
|
||||
flags |= 1;
|
||||
for (int y = std::bit_width(rate.fragmentSize.height) - 1; y < 3; ++y)
|
||||
{
|
||||
for (int x = std::bit_width(rate.fragmentSize.width) - 1; x < 3; ++x)
|
||||
{
|
||||
if (fragment_sizes[x][y] == 0)
|
||||
fragment_sizes[x][y] = flags;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pipeline = vk::raii::Pipeline(device, application::get_pipeline_cache(), pipeline_info);
|
||||
|
||||
// Create image views and framebuffers
|
||||
@@ -413,21 +390,6 @@ static size_t required_vertices(const wivrn::to_headset::foveation_parameter & p
|
||||
return (2 * (p.x.size() + 1) + 1) * p.y.size();
|
||||
}
|
||||
|
||||
int32_t stream_reprojection::shading_rate(int pixels_x, int pixels_y)
|
||||
{
|
||||
int x = 0;
|
||||
if (pixels_x >= 2)
|
||||
x = 1;
|
||||
if (pixels_x >= 4)
|
||||
x = 2;
|
||||
int y = 0;
|
||||
if (pixels_y >= 2)
|
||||
y = 1;
|
||||
if (pixels_y >= 4)
|
||||
y = 2;
|
||||
return fragment_sizes[x][y];
|
||||
}
|
||||
|
||||
void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer,
|
||||
const std::array<wivrn::to_headset::foveation_parameter, 2> & foveation,
|
||||
int destination)
|
||||
@@ -463,12 +425,10 @@ void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer,
|
||||
*vertices++ = {
|
||||
.position = out * out_pixel_size - glm::vec2(1),
|
||||
.uv = in * in_pixel_size,
|
||||
.shading_rate = shading_rate(ratio_x, ratio_y),
|
||||
};
|
||||
*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,
|
||||
.shading_rate = shading_rate(ratio_x, ratio_y),
|
||||
};
|
||||
in.x += n_out_x;
|
||||
out.x += n_out_x * ratio_x;
|
||||
|
||||
@@ -41,15 +41,9 @@ class stream_reprojection
|
||||
vk::raii::RenderPass renderpass = nullptr;
|
||||
vk::raii::Pipeline pipeline = nullptr;
|
||||
|
||||
// Allowed sizes for variable shading rate
|
||||
// indices are for x, y
|
||||
// 0 is 1 pixel
|
||||
// 1 is 2 or 3 pixels
|
||||
// 2 is 4 pixels or more
|
||||
int32_t fragment_sizes[3][3] = {};
|
||||
|
||||
// Source image
|
||||
vk::raii::Sampler sampler = nullptr;
|
||||
vk::Image input_image;
|
||||
std::vector<vk::raii::ImageView> input_image_views;
|
||||
std::vector<vk::DescriptorSet> descriptor_sets;
|
||||
vk::Extent2D input_extent;
|
||||
@@ -63,13 +57,13 @@ class stream_reprojection
|
||||
void ensure_vertices(size_t num_vertices);
|
||||
vertex * get_vertices(size_t view);
|
||||
|
||||
int32_t shading_rate(int pixels_x, int pixels_y);
|
||||
|
||||
public:
|
||||
stream_reprojection(
|
||||
vk::raii::Device & device,
|
||||
vk::raii::PhysicalDevice & physical_device,
|
||||
image_allocation & input_image,
|
||||
vk::Image input_image,
|
||||
vk::Extent2D input_extent,
|
||||
uint32_t view_count,
|
||||
std::vector<vk::Image> output_images,
|
||||
vk::Extent2D output_extent,
|
||||
vk::Format format);
|
||||
|
||||
@@ -21,10 +21,7 @@
|
||||
#include "stream.h"
|
||||
#include "utils/overloaded.h"
|
||||
#include "wivrn_packets.h"
|
||||
#include "xr/body_tracker.h"
|
||||
#include "xr/face_tracker.h"
|
||||
#include "xr/fb_body_tracker.h"
|
||||
#include "xr/to_string.h"
|
||||
#include <magic_enum.hpp>
|
||||
#include <ranges>
|
||||
#include <spdlog/spdlog.h>
|
||||
@@ -380,6 +377,7 @@ void scenes::stream::tracking()
|
||||
std::vector<from_headset::tracking> tracking;
|
||||
std::vector<from_headset::tracking> tracking_pool; // pre-allocated objects
|
||||
std::vector<from_headset::hand_tracking> hands;
|
||||
std::array<bool, 2> should_skip_simple_controllers{};
|
||||
std::vector<from_headset::body_tracking> body;
|
||||
std::vector<XrView> views;
|
||||
|
||||
@@ -387,14 +385,31 @@ void scenes::stream::tracking()
|
||||
std::vector<serialization_packet> packets;
|
||||
|
||||
const bool hand_tracking = config.check_feature(feature::hand_tracking);
|
||||
std::optional<xr::hand_tracker> left_hand;
|
||||
std::optional<xr::hand_tracker> right_hand;
|
||||
|
||||
const bool face_tracking = config.check_feature(feature::face_tracking);
|
||||
xr::face_tracker face_tracker;
|
||||
auto & face_tracker = application::get_face_tracker();
|
||||
if (face_tracking)
|
||||
{
|
||||
// We can't start the face tracking on application initialisation like we do for
|
||||
// other face trackers due to a Pico runtime bug where face tracking freezes when
|
||||
// the headset is taken off or the application is quit.
|
||||
if (auto * face_pico = std::get_if<xr::pico_face_tracker>(&face_tracker))
|
||||
face_pico->start();
|
||||
}
|
||||
|
||||
const bool body_tracking = config.check_feature(feature::body_tracking);
|
||||
xr::body_tracker body_tracker;
|
||||
auto & body_tracker = application::get_body_tracker();
|
||||
if (body_tracking)
|
||||
{
|
||||
if (auto * body_fb = std::get_if<xr::fb_body_tracker>(&body_tracker))
|
||||
{
|
||||
// TODO maybe handle reconnection better, if the settings are changed since
|
||||
// last connection to running server, the tracker count will mismatch and
|
||||
// stuff might break
|
||||
body_fb->stop();
|
||||
body_fb->start(config.fb_lower_body, config.fb_hip);
|
||||
}
|
||||
}
|
||||
|
||||
locate_spaces_functor locate_spaces{instance, world_space};
|
||||
|
||||
@@ -418,50 +433,11 @@ void scenes::stream::tracking()
|
||||
timer t(instance);
|
||||
int samples = 0;
|
||||
|
||||
auto control = *tracking_control.lock();
|
||||
bool interaction_profile_changed = this->interaction_profile_changed.exchange(false);
|
||||
|
||||
if (control.enabled[size_t(tid::left_hand)])
|
||||
to_headset::tracking_control control;
|
||||
{
|
||||
if (not left_hand and system.hand_tracking_supported())
|
||||
left_hand = session.create_hand_tracker(XR_HAND_LEFT_EXT);
|
||||
std::lock_guard lock(tracking_control_mutex);
|
||||
control = tracking_control;
|
||||
}
|
||||
else
|
||||
left_hand.reset();
|
||||
|
||||
if (control.enabled[size_t(tid::right_hand)])
|
||||
{
|
||||
if (not right_hand and system.hand_tracking_supported())
|
||||
right_hand = session.create_hand_tracker(XR_HAND_RIGHT_EXT);
|
||||
}
|
||||
else
|
||||
right_hand.reset();
|
||||
|
||||
if (face_tracking and control.enabled[size_t(tid::face)])
|
||||
{
|
||||
if (std::holds_alternative<std::monostate>(face_tracker))
|
||||
face_tracker = xr::make_face_tracker(instance, system, session);
|
||||
}
|
||||
else
|
||||
face_tracker.emplace<std::monostate>();
|
||||
|
||||
if (body_tracking and control.enabled[size_t(tid::generic_tracker)])
|
||||
{
|
||||
if (std::holds_alternative<std::monostate>(body_tracker))
|
||||
body_tracker = xr::make_body_tracker(
|
||||
instance,
|
||||
system,
|
||||
session,
|
||||
application::get_generic_trackers(),
|
||||
config.fb_lower_body,
|
||||
config.fb_hip);
|
||||
}
|
||||
else
|
||||
body_tracker.emplace<std::monostate>();
|
||||
|
||||
if (interaction_profile_changed)
|
||||
if (auto htc = std::get_if<xr::htc_body_tracker>(&body_tracker))
|
||||
htc->update_active();
|
||||
|
||||
XrDuration prediction = std::clamp<XrDuration>(control.max_offset.count(), 0, 80'000'000);
|
||||
auto period = std::max<XrDuration>(display_time_period.load(), 1'000'000);
|
||||
@@ -493,9 +469,9 @@ void scenes::stream::tracking()
|
||||
(Δt == 0 or Δt >= prediction - 2 * period))
|
||||
{
|
||||
last_hand_sample = t0;
|
||||
if (left_hand)
|
||||
if (control.enabled[size_t(tid::left_hand)])
|
||||
{
|
||||
auto joints = locate_hands(*left_hand, world_space, t0 + Δt);
|
||||
auto joints = locate_hands(application::get_left_hand(), world_space, t0 + Δt);
|
||||
hands.emplace_back(
|
||||
t0,
|
||||
t0 + Δt,
|
||||
@@ -503,9 +479,9 @@ void scenes::stream::tracking()
|
||||
joints);
|
||||
}
|
||||
|
||||
if (right_hand)
|
||||
if (control.enabled[size_t(tid::right_hand)])
|
||||
{
|
||||
auto joints = locate_hands(*right_hand, world_space, t0 + Δt);
|
||||
auto joints = locate_hands(application::get_right_hand(), world_space, t0 + Δt);
|
||||
hands.emplace_back(
|
||||
t0,
|
||||
t0 + Δt,
|
||||
@@ -522,33 +498,37 @@ void scenes::stream::tracking()
|
||||
}
|
||||
locate_spaces.resolve(session, t0 + Δt, packet.device_poses);
|
||||
|
||||
std::visit(utils::overloaded{
|
||||
[](std::monostate &) {},
|
||||
[&](auto & b) {
|
||||
if (t0 >= last_body_sample + period and
|
||||
(Δt == 0 or Δt >= prediction - 2 * period))
|
||||
{
|
||||
last_body_sample = t0;
|
||||
if (control.enabled[size_t(tid::generic_tracker)])
|
||||
if (body_tracking)
|
||||
std::visit(utils::overloaded{
|
||||
[](std::monostate &) {},
|
||||
[&](auto & b) {
|
||||
if (t0 >= last_body_sample + period and
|
||||
(Δt == 0 or Δt >= prediction - 2 * period))
|
||||
{
|
||||
body.push_back(from_headset::body_tracking{
|
||||
.production_timestamp = t0,
|
||||
.timestamp = t0 + Δt,
|
||||
.poses = b.locate_spaces(t0 + Δt, world_space),
|
||||
});
|
||||
last_body_sample = t0;
|
||||
if (control.enabled[size_t(tid::generic_tracker)])
|
||||
{
|
||||
body.push_back(from_headset::body_tracking{
|
||||
.production_timestamp = t0,
|
||||
.timestamp = t0 + Δt,
|
||||
.poses = b.locate_spaces(t0 + Δt, world_space),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
body_tracker);
|
||||
},
|
||||
},
|
||||
body_tracker);
|
||||
|
||||
std::visit(utils::overloaded{
|
||||
[](std::monostate &) {},
|
||||
[&](auto & ft) {
|
||||
ft.get_weights(t0 + Δt, packet.face.emplace<typename std::remove_reference_t<decltype(ft)>::packet_type>());
|
||||
},
|
||||
},
|
||||
face_tracker);
|
||||
if (face_tracking && control.enabled[size_t(tid::face)])
|
||||
{
|
||||
std::visit(utils::overloaded{
|
||||
[](std::monostate &) {},
|
||||
[&](auto & ft) {
|
||||
ft.get_weights(t0 + Δt, packet.face.emplace<typename std::remove_reference_t<decltype(ft)>::packet_type>());
|
||||
},
|
||||
},
|
||||
face_tracker);
|
||||
}
|
||||
}
|
||||
catch (const std::system_error & e)
|
||||
{
|
||||
@@ -649,17 +629,20 @@ void scenes::stream::tracking()
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
if (auto * face_pico = std::get_if<xr::pico_face_tracker>(&face_tracker))
|
||||
face_pico->stop();
|
||||
}
|
||||
|
||||
void scenes::stream::operator()(to_headset::tracking_control && packet)
|
||||
{
|
||||
auto locked = tracking_control.lock();
|
||||
std::lock_guard lock(tracking_control_mutex);
|
||||
auto m = size_t(to_headset::tracking_control::id::microphone);
|
||||
if (audio_handle)
|
||||
audio_handle->set_mic_state(packet.enabled[m]);
|
||||
|
||||
*locked = packet;
|
||||
locked->min_offset = std::min(locked->min_offset, locked->max_offset);
|
||||
tracking_control = packet;
|
||||
tracking_control.min_offset = std::min(tracking_control.min_offset, tracking_control.max_offset);
|
||||
}
|
||||
|
||||
static device_id derived_from(device_id target)
|
||||
@@ -680,7 +663,6 @@ static device_id derived_from(device_id target)
|
||||
|
||||
void scenes::stream::on_interaction_profile_changed(const XrEventDataInteractionProfileChanged &)
|
||||
{
|
||||
interaction_profile_changed = true;
|
||||
std::array path = {
|
||||
"/user/hand/left",
|
||||
"/user/hand/right",
|
||||
|
||||
Reference in New Issue
Block a user