Implement visibility mask
This commit is contained in:
@@ -784,6 +784,7 @@ void application::initialize()
|
|||||||
opt_extensions.push_back(XR_KHR_COMPOSITION_LAYER_DEPTH_EXTENSION_NAME);
|
opt_extensions.push_back(XR_KHR_COMPOSITION_LAYER_DEPTH_EXTENSION_NAME);
|
||||||
opt_extensions.push_back(XR_FB_COMPOSITION_LAYER_DEPTH_TEST_EXTENSION_NAME);
|
opt_extensions.push_back(XR_FB_COMPOSITION_LAYER_DEPTH_TEST_EXTENSION_NAME);
|
||||||
opt_extensions.push_back(XR_KHR_COMPOSITION_LAYER_COLOR_SCALE_BIAS_EXTENSION_NAME);
|
opt_extensions.push_back(XR_KHR_COMPOSITION_LAYER_COLOR_SCALE_BIAS_EXTENSION_NAME);
|
||||||
|
opt_extensions.push_back(XR_KHR_VISIBILITY_MASK_EXTENSION_NAME);
|
||||||
|
|
||||||
for (const auto & i: interaction_profiles)
|
for (const auto & i: interaction_profiles)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -69,10 +69,38 @@ static const std::unordered_map<std::string, device_id> device_ids = {
|
|||||||
};
|
};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
static const std::array supported_formats =
|
static const std::array supported_formats = {
|
||||||
{
|
vk::Format::eR8G8B8A8Srgb,
|
||||||
vk::Format::eR8G8B8A8Srgb,
|
vk::Format::eB8G8R8A8Srgb,
|
||||||
vk::Format::eB8G8R8A8Srgb};
|
};
|
||||||
|
|
||||||
|
static from_headset::visibility_mask_changed::masks get_visibility_mask(xr::instance & inst, xr::session & session, int view)
|
||||||
|
{
|
||||||
|
assert(inst.has_extension(XR_KHR_VISIBILITY_MASK_EXTENSION_NAME));
|
||||||
|
static auto xrGetVisibilityMaskKHR = inst.get_proc<PFN_xrGetVisibilityMaskKHR>("xrGetVisibilityMaskKHR");
|
||||||
|
|
||||||
|
from_headset::visibility_mask_changed::masks res{};
|
||||||
|
for (auto [type, mask]: utils::enumerate(res))
|
||||||
|
{
|
||||||
|
XrVisibilityMaskKHR xr_mask{
|
||||||
|
.type = XR_TYPE_VISIBILITY_MASK_KHR,
|
||||||
|
};
|
||||||
|
CHECK_XR(xrGetVisibilityMaskKHR(session, XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO, view, XrVisibilityMaskTypeKHR(type + 1), &xr_mask));
|
||||||
|
mask.vertices.resize(xr_mask.vertexCountOutput);
|
||||||
|
mask.indices.resize(xr_mask.indexCountOutput);
|
||||||
|
xr_mask = {
|
||||||
|
.type = XR_TYPE_VISIBILITY_MASK_KHR,
|
||||||
|
.vertexCapacityInput = uint32_t(mask.vertices.size()),
|
||||||
|
.vertices = mask.vertices.data(),
|
||||||
|
.indexCapacityInput = uint32_t(mask.indices.size()),
|
||||||
|
.indices = mask.indices.data(),
|
||||||
|
};
|
||||||
|
CHECK_XR(xrGetVisibilityMaskKHR(session, XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO, view, XrVisibilityMaskTypeKHR(type + 1), &xr_mask));
|
||||||
|
mask.vertices.resize(xr_mask.vertexCountOutput);
|
||||||
|
mask.indices.resize(xr_mask.indexCountOutput);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_session> network_session, float guessed_fps)
|
std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_session> network_session, float guessed_fps)
|
||||||
{
|
{
|
||||||
@@ -139,6 +167,16 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
|||||||
return info;
|
return info;
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
if (self->instance.has_extension(XR_KHR_VISIBILITY_MASK_EXTENSION_NAME))
|
||||||
|
{
|
||||||
|
for (uint8_t view = 0; view < view_count; ++view)
|
||||||
|
{
|
||||||
|
self->network_session->send_control(from_headset::visibility_mask_changed{
|
||||||
|
.data = get_visibility_mask(self->instance, self->session, view),
|
||||||
|
.view_index = view});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
self->network_thread = utils::named_thread("network_thread", &stream::process_packets, self.get());
|
self->network_thread = utils::named_thread("network_thread", &stream::process_packets, self.get());
|
||||||
|
|
||||||
self->command_buffer = std::move(self->device.allocateCommandBuffers({
|
self->command_buffer = std::move(self->device.allocateCommandBuffers({
|
||||||
|
|||||||
+15
-1
@@ -116,6 +116,20 @@ struct pin_check_3
|
|||||||
crypto::smp::msg3 message;
|
crypto::smp::msg3 message;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct visibility_mask_changed
|
||||||
|
{
|
||||||
|
struct mask
|
||||||
|
{
|
||||||
|
std::vector<XrVector2f> vertices;
|
||||||
|
std::vector<uint32_t> indices;
|
||||||
|
};
|
||||||
|
static const int num_types = 3; // XrVisibilityMaskTypeKHR values
|
||||||
|
using masks = std::array<mask, num_types>;
|
||||||
|
|
||||||
|
masks data;
|
||||||
|
uint8_t view_index;
|
||||||
|
};
|
||||||
|
|
||||||
struct headset_info_packet
|
struct headset_info_packet
|
||||||
{
|
{
|
||||||
uint32_t recommended_eye_width;
|
uint32_t recommended_eye_width;
|
||||||
@@ -273,7 +287,7 @@ struct battery
|
|||||||
bool charging;
|
bool charging;
|
||||||
};
|
};
|
||||||
|
|
||||||
using packets = std::variant<crypto_handshake, pin_check_1, pin_check_3, headset_info_packet, feedback, audio_data, handshake, tracking, trackings, hand_tracking, inputs, timesync_response, battery>;
|
using packets = std::variant<crypto_handshake, pin_check_1, pin_check_3, headset_info_packet, feedback, audio_data, handshake, tracking, trackings, hand_tracking, inputs, timesync_response, battery, visibility_mask_changed>;
|
||||||
} // namespace from_headset
|
} // namespace from_headset
|
||||||
|
|
||||||
namespace to_headset
|
namespace to_headset
|
||||||
|
|||||||
@@ -190,6 +190,32 @@ bool wivrn_hmd::wivrn_hmd_compute_distortion(xrt_device * xdev, uint32_t view_in
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xrt_result_t wivrn_hmd::get_visibility_mask(xrt_device * xdev, xrt_visibility_mask_type type, uint32_t view_index, xrt_visibility_mask ** mask)
|
||||||
|
{
|
||||||
|
static_assert(sizeof(uint32_t) == sizeof(decltype(from_headset::visibility_mask_changed::mask::indices)::value_type));
|
||||||
|
static_assert(sizeof(xrt_vec2) == sizeof(decltype(from_headset::visibility_mask_changed::mask::vertices)::value_type));
|
||||||
|
auto self = (wivrn_hmd *)xdev;
|
||||||
|
type = xrt_visibility_mask_type((unsigned int)type - 1); // enum values start at 1
|
||||||
|
const auto visibility_mask = self->visibility_mask.lock();
|
||||||
|
if (type >= from_headset::visibility_mask_changed::num_types or view_index >= 2 or not(*visibility_mask)[view_index])
|
||||||
|
{
|
||||||
|
*mask = (xrt_visibility_mask *)calloc(1, sizeof(xrt_visibility_mask));
|
||||||
|
return XRT_SUCCESS;
|
||||||
|
}
|
||||||
|
const auto & in_mask = (*(*visibility_mask)[view_index])[int(type)];
|
||||||
|
size_t index_size = in_mask.indices.size() * sizeof(uint32_t);
|
||||||
|
size_t vertex_size = in_mask.vertices.size() * sizeof(xrt_vec2);
|
||||||
|
*mask = (xrt_visibility_mask *)calloc(1, sizeof(xrt_visibility_mask) + index_size + vertex_size);
|
||||||
|
**mask = {
|
||||||
|
.type = type,
|
||||||
|
.index_count = uint32_t(in_mask.indices.size()),
|
||||||
|
.vertex_count = uint32_t(in_mask.vertices.size()),
|
||||||
|
};
|
||||||
|
memcpy(xrt_visibility_mask_get_indices(*mask), in_mask.indices.data(), index_size);
|
||||||
|
memcpy(xrt_visibility_mask_get_vertices(*mask), in_mask.vertices.data(), vertex_size);
|
||||||
|
return XRT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
wivrn_hmd::wivrn_hmd(wivrn::wivrn_session * cnx,
|
wivrn_hmd::wivrn_hmd(wivrn::wivrn_session * cnx,
|
||||||
const from_headset::headset_info_packet & info) :
|
const from_headset::headset_info_packet & info) :
|
||||||
xrt_device{}, cnx(cnx)
|
xrt_device{}, cnx(cnx)
|
||||||
@@ -203,6 +229,7 @@ wivrn_hmd::wivrn_hmd(wivrn::wivrn_session * cnx,
|
|||||||
base->get_tracked_pose = wivrn_hmd_get_tracked_pose;
|
base->get_tracked_pose = wivrn_hmd_get_tracked_pose;
|
||||||
base->get_view_poses = wivrn_hmd_get_view_poses;
|
base->get_view_poses = wivrn_hmd_get_view_poses;
|
||||||
base->get_battery_status = wivrn_hmd_get_battery_status;
|
base->get_battery_status = wivrn_hmd_get_battery_status;
|
||||||
|
base->get_visibility_mask = get_visibility_mask;
|
||||||
base->destroy = wivrn_hmd_destroy;
|
base->destroy = wivrn_hmd_destroy;
|
||||||
name = XRT_DEVICE_GENERIC_HMD;
|
name = XRT_DEVICE_GENERIC_HMD;
|
||||||
device_type = XRT_DEVICE_TYPE_HMD;
|
device_type = XRT_DEVICE_TYPE_HMD;
|
||||||
@@ -409,6 +436,13 @@ void wivrn_hmd::set_foveation_center(std::array<xrt_vec2, 2> center)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wivrn_hmd::update_visibility_mask(const from_headset::visibility_mask_changed & mask)
|
||||||
|
{
|
||||||
|
assert(mask.view_index < 2);
|
||||||
|
auto m = visibility_mask.lock();
|
||||||
|
m->at(mask.view_index) = mask.data;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* Functions
|
* Functions
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "utils/thread_safe.h"
|
||||||
#include "xrt/xrt_device.h"
|
#include "xrt/xrt_device.h"
|
||||||
#include "xrt/xrt_tracking.h"
|
#include "xrt/xrt_tracking.h"
|
||||||
|
|
||||||
@@ -50,10 +51,14 @@ class wivrn_hmd : public xrt_device
|
|||||||
std::array<to_headset::foveation_parameter, 2> foveation_parameters{};
|
std::array<to_headset::foveation_parameter, 2> foveation_parameters{};
|
||||||
from_headset::battery battery{};
|
from_headset::battery battery{};
|
||||||
|
|
||||||
|
thread_safe<std::array<std::optional<from_headset::visibility_mask_changed::masks>, 2>> visibility_mask;
|
||||||
|
|
||||||
wivrn::wivrn_session * cnx;
|
wivrn::wivrn_session * cnx;
|
||||||
|
|
||||||
static bool wivrn_hmd_compute_distortion(xrt_device * xdev, uint32_t view_index, float u, float v, xrt_uv_triplet * result);
|
static bool wivrn_hmd_compute_distortion(xrt_device * xdev, uint32_t view_index, float u, float v, xrt_uv_triplet * result);
|
||||||
|
|
||||||
|
static xrt_result_t get_visibility_mask(xrt_device * xdev, xrt_visibility_mask_type, uint32_t view_index, xrt_visibility_mask **);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
wivrn_hmd(wivrn::wivrn_session * cnx,
|
wivrn_hmd(wivrn::wivrn_session * cnx,
|
||||||
const from_headset::headset_info_packet & info);
|
const from_headset::headset_info_packet & info);
|
||||||
@@ -85,5 +90,7 @@ public:
|
|||||||
{
|
{
|
||||||
return foveation_parameters;
|
return foveation_parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void update_visibility_mask(const from_headset::visibility_mask_changed &);
|
||||||
};
|
};
|
||||||
} // namespace wivrn
|
} // namespace wivrn
|
||||||
|
|||||||
@@ -401,6 +401,18 @@ void wivrn_session::operator()(from_headset::battery && battery)
|
|||||||
hmd.update_battery(battery);
|
hmd.update_battery(battery);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wivrn_session::operator()(from_headset::visibility_mask_changed && mask)
|
||||||
|
{
|
||||||
|
hmd.update_visibility_mask(mask);
|
||||||
|
xrt_session_event event{
|
||||||
|
.mask_change = {
|
||||||
|
.type = XRT_SESSION_EVENT_VISIBILITY_MASK_CHANGE,
|
||||||
|
.view_index = mask.view_index,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
auto result = xrt_session_event_sink_push(&xrt_system.broadcast, &event);
|
||||||
|
}
|
||||||
|
|
||||||
void wivrn_session::operator()(audio_data && data)
|
void wivrn_session::operator()(audio_data && data)
|
||||||
{
|
{
|
||||||
if (audio_handle)
|
if (audio_handle)
|
||||||
|
|||||||
@@ -149,6 +149,7 @@ public:
|
|||||||
void operator()(from_headset::timesync_response &&);
|
void operator()(from_headset::timesync_response &&);
|
||||||
void operator()(from_headset::feedback &&);
|
void operator()(from_headset::feedback &&);
|
||||||
void operator()(from_headset::battery &&);
|
void operator()(from_headset::battery &&);
|
||||||
|
void operator()(from_headset::visibility_mask_changed &&);
|
||||||
void operator()(audio_data &&);
|
void operator()(audio_data &&);
|
||||||
|
|
||||||
void operator()(to_monado::disconnect &&);
|
void operator()(to_monado::disconnect &&);
|
||||||
|
|||||||
@@ -140,7 +140,10 @@ constexpr auto type_name()
|
|||||||
constexpr size_t pos = sv3.rfind("::");
|
constexpr size_t pos = sv3.rfind("::");
|
||||||
constexpr size_t pos2 = pos == std::string_view::npos ? 0 : (pos + 2);
|
constexpr size_t pos2 = pos == std::string_view::npos ? 0 : (pos + 2);
|
||||||
|
|
||||||
constexpr std::string_view sv4 = sv3.substr(pos2);
|
constexpr size_t pos3 = sv3.find_first_of(", ");
|
||||||
|
|
||||||
|
constexpr std::string_view sv4 = sv3.substr(pos2,
|
||||||
|
pos3 == std::string_view::npos ? pos3 : pos3 - pos2);
|
||||||
|
|
||||||
return fixed_string<sv4.size() + 1>(sv4);
|
return fixed_string<sv4.size() + 1>(sv4);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user