Skip to content

Commit

Permalink
experimental: steamvr-lh support
Browse files Browse the repository at this point in the history
  • Loading branch information
galister committed Aug 30, 2024
1 parent 8503e34 commit 91f2650
Show file tree
Hide file tree
Showing 10 changed files with 553 additions and 72 deletions.
26 changes: 8 additions & 18 deletions client/scenes/stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses

self->network_session->send_control(info);

self->update_local_floor(self->instance.now());
self->network_thread = utils::named_thread("network_thread", &stream::process_packets, self.get());

self->command_buffer = std::move(self->device.allocateCommandBuffers({
Expand Down Expand Up @@ -186,6 +185,9 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
.queryCount = size_gpu_timestamps,
});

XrPosef offset{{0, 0, 0, 1}, {0, 0, 0}};
self->stage = self->session.create_reference_space(XR_REFERENCE_SPACE_TYPE_STAGE, offset);

return self;
}

Expand Down Expand Up @@ -709,7 +711,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
XrCompositionLayerProjection layer{
.type = XR_TYPE_COMPOSITION_LAYER_PROJECTION,
.layerFlags = 0,
.space = local_floor,
.space = stage,
.viewCount = (uint32_t)layer_view.size(),
.views = layer_view.data(),
};
Expand Down Expand Up @@ -1001,22 +1003,10 @@ scene::meta & scenes::stream::get_meta_scene()
return m;
}

void scenes::stream::update_local_floor(XrTime when)
{
xr::space local = session.create_reference_space(XR_REFERENCE_SPACE_TYPE_LOCAL);
xr::space stage = session.create_reference_space(XR_REFERENCE_SPACE_TYPE_STAGE);

XrSpaceLocation location{
.type = XR_TYPE_SPACE_LOCATION,
};
xrLocateSpace(stage, local, when, &location);

XrPosef offset{{0, 0, 0, 1}, {location.pose.position.x, location.pose.position.y, 0}};
std::lock_guard lock(local_floor_mutex);
local_floor = session.create_reference_space(XR_REFERENCE_SPACE_TYPE_LOCAL, offset);
}

void scenes::stream::on_reference_space_changed(XrReferenceSpaceType space, XrTime when)
{
update_local_floor(when);
if (space == XrReferenceSpaceType::XR_REFERENCE_SPACE_TYPE_LOCAL)
{
local_dirty = true;
}
}
8 changes: 4 additions & 4 deletions client/scenes/stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "stream_reprojection.h"
#include "wivrn_client.h"
#include "wivrn_packets.h"
#include <atomic>
#include <mutex>
#include <shared_mutex>
#include <thread>
Expand Down Expand Up @@ -78,8 +79,8 @@ class stream : public scene_impl<stream>, public std::enable_shared_from_this<st
std::unique_ptr<wivrn_session> network_session;
std::atomic<bool> exiting = false;
std::thread network_thread;
std::mutex local_floor_mutex;
xr::space local_floor;
xr::space stage;
std::atomic<bool> local_dirty = false;
std::atomic<std::chrono::nanoseconds::rep> tracking_prediction_offset;
std::optional<std::thread> tracking_thread;

Expand Down Expand Up @@ -132,7 +133,7 @@ class stream : public scene_impl<stream>, public std::enable_shared_from_this<st
void on_focused() override;
void on_unfocused() override;

void operator()(to_headset::handshake &&){};
void operator()(to_headset::handshake &&) {};
void operator()(to_headset::video_stream_data_shard &&);
void operator()(to_headset::haptics &&);
void operator()(to_headset::timesync_query &&);
Expand Down Expand Up @@ -226,7 +227,6 @@ class stream : public scene_impl<stream>, public std::enable_shared_from_this<st

void accumulate_metrics(XrTime predicted_display_time, const std::vector<std::shared_ptr<shard_accumulator::blit_handle>> & blit_handles, const gpu_timestamps & timestamps);
XrCompositionLayerQuad plot_performance_metrics(XrTime predicted_display_time);
void update_local_floor(XrTime when);
void on_reference_space_changed(XrReferenceSpaceType space, XrTime) override;
};
} // namespace scenes
16 changes: 10 additions & 6 deletions client/scenes/stream_tracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "application.h"
#include "stream.h"
#include "utils/ranges.h"
#include "wivrn_packets.h"
#include <spdlog/spdlog.h>
#include <thread>

Expand Down Expand Up @@ -156,7 +157,7 @@ void scenes::stream::tracking()
auto filter_jobj = jni::new_object<"android/content/IntentFilter">(filter_jstr);

XrTime next_battery_check = 0;
const XrDuration battery_check_interval = 5'000'000'000; // 5s
const XrDuration battery_check_interval = 60'000'000'000; // 60s
#endif
std::vector<std::pair<device_id, XrSpace>> spaces = {
{device_id::HEAD, application::view()},
Expand Down Expand Up @@ -214,13 +215,16 @@ void scenes::stream::tracking()
j.fov = i.fov;
}

packet.flags = flags;
packet.view_flags = flags;

packet.state_flags = 0;
if (local_dirty.exchange(false))
packet.state_flags = xrt::drivers::wivrn::from_headset::tracking::recentered;

packet.device_poses.clear();
std::lock_guard lock(local_floor_mutex);
for (auto [device, space]: spaces)
{
packet.device_poses.push_back(locate_space(device, space, local_floor, t0 + Δt));
packet.device_poses.push_back(locate_space(device, space, stage, t0 + Δt));
}

t.pause();
Expand All @@ -230,13 +234,13 @@ void scenes::stream::tracking()
if (application::get_hand_tracking_supported())
{
hands.hand = xrt::drivers::wivrn::from_headset::hand_tracking::left;
hands.joints = locate_hands(application::get_left_hand(), local_floor, hands.timestamp);
hands.joints = locate_hands(application::get_left_hand(), stage, hands.timestamp);
t.pause();
network_session->send_stream(hands);
t.resume();

hands.hand = xrt::drivers::wivrn::from_headset::hand_tracking::right;
hands.joints = locate_hands(application::get_right_hand(), local_floor, hands.timestamp);
hands.joints = locate_hands(application::get_right_hand(), stage, hands.timestamp);
t.pause();
network_session->send_stream(hands);
t.resume();
Expand Down
9 changes: 8 additions & 1 deletion common/wivrn_packets.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ struct tracking
position_tracked = 1 << 5
};

enum state_flags : uint8_t
{
recentered = 1 << 0,
};

struct pose
{
device_id device;
Expand All @@ -147,7 +152,9 @@ struct tracking

XrTime production_timestamp;
XrTime timestamp;
XrViewStateFlags flags;
XrViewStateFlags view_flags;

uint8_t state_flags;

std::array<view, 2> views;
std::vector<pose> device_poses;
Expand Down
Loading

0 comments on commit 91f2650

Please sign in to comment.