Revert to explicit hmd_traits initialization

This commit is contained in:
Patrick Nicolas
2026-05-10 19:11:17 +02:00
committed by xytovl
parent 50a0f1a0ed
commit 1b9b74cce1
11 changed files with 45 additions and 26 deletions
+4 -3
View File
@@ -749,7 +749,7 @@ void application::initialize_vulkan()
instance_extensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
}
if (!strcmp(i.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) and hmd_traits.vk_debug_ext_allowed)
if (!strcmp(i.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) and hmd_traits().vk_debug_ext_allowed)
{
debug_utils_found = true;
instance_extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
@@ -1005,7 +1005,7 @@ void application::initialize_actions()
profile.available = std::ranges::all_of(profile.required_extensions, [&](auto & ext) { return xr_instance.has_extension(ext); }) and
profile.min_version <= api_version;
if (profile.profile_name.ends_with("khr/simple_controller") and not hmd_traits.bind_simple_controller)
if (profile.profile_name.ends_with("khr/simple_controller") and not hmd_traits().bind_simple_controller)
profile.available = false;
if (!profile.available)
@@ -1014,7 +1014,7 @@ void application::initialize_actions()
// Patch profile to add grip_surface or palm_ext
bool add_palms = true;
if (profile.profile_name.ends_with("ext/hand_interaction_ext"))
add_palms = hmd_traits.hand_interaction_grip_surface;
add_palms = hmd_traits().hand_interaction_grip_surface;
if (add_palms)
{
@@ -1185,6 +1185,7 @@ void application::initialize_actions()
void application::initialize()
{
hmd_traits_init();
// LogLayersAndExtensions
assert(!xr_instance);
std::vector<const char *> xr_extensions{
+2 -2
View File
@@ -70,7 +70,7 @@ bool configuration::check_feature(feature f) const
}
}
#ifdef __ANDROID__
return check_permission(hmd_traits.permissions[f]);
return check_permission(hmd_traits().permissions[f]);
#else
return true;
#endif
@@ -81,7 +81,7 @@ void configuration::set_feature(feature f, bool state)
#ifdef __ANDROID__
if (state)
{
request_permission(hmd_traits.permissions[f], [this, f](bool granted) {
request_permission(hmd_traits().permissions[f], [this, f](bool granted) {
{
std::lock_guard lock(mutex);
features[f] = granted;
+19 -5
View File
@@ -102,9 +102,25 @@ static std::optional<bool> env_bool(const char * env_name, const char * android_
return std::nullopt;
}
const hmd_traits_t hmd_traits = [] {
hmd_traits_t traits{};
static hmd_traits_t traits;
#ifndef NDEBUG
static bool initialized = false;
#endif
const hmd_traits_t & hmd_traits()
{
#ifndef NDEBUG
assert(initialized);
#endif
return traits;
}
void hmd_traits_init()
{
#ifndef NDEBUG
assert(not initialized);
initialized = true;
#endif
#ifdef __ANDROID__
const auto device = get_property("ro.product.device");
const auto manufacturer = get_property("ro.product.manufacturer");
@@ -251,9 +267,7 @@ const hmd_traits_t hmd_traits = [] {
traits.panel_width_override,
xr::to_string(traits.max_openxr_api_version),
traits.needs_srgb_conversion);
return traits;
}();
};
std::string model_name()
{
+6 -2
View File
@@ -38,7 +38,7 @@ enum class feature
using hmd_permissions = magic_enum::containers::array<feature, const char *>;
extern const struct hmd_traits_t
struct hmd_traits_t
{
std::string controller_profile = "generic-trigger-squeeze";
const char * controller_ray_model = "assets://ray.glb";
@@ -54,7 +54,11 @@ extern const struct hmd_traits_t
bool discard_frame = true; // can do xrBeginFrame twice to discard the first one
XrViewConfigurationView override_view(XrViewConfigurationView) const;
} hmd_traits;
};
const hmd_traits_t & hmd_traits();
// must be called exactly once
void hmd_traits_init();
std::string model_name();
+1 -1
View File
@@ -306,7 +306,7 @@ input_profile::input_profile(scene & scene, const std::filesystem::path & json_p
else
continue;
auto && [ray_entity, ray_node] = scene.add_gltf(hmd_traits.controller_ray_model, layer_mask_ray);
auto && [ray_entity, ray_node] = scene.add_gltf(hmd_traits().controller_ray_model, layer_mask_ray);
ray_node.name = (std::string)layout.key + "_ray";
spdlog::debug("Created entity {}", ray_node.name);
+2 -2
View File
@@ -1114,7 +1114,7 @@ void scenes::lobby::on_focused()
auto views = system.view_configuration_views(viewconfig);
assert(views.size() == 2); // FIXME
stream_view = hmd_traits.override_view(views[0]);
stream_view = hmd_traits().override_view(views[0]);
width = views[0].recommendedImageRectWidth;
height = views[0].recommendedImageRectHeight;
@@ -1135,7 +1135,7 @@ void scenes::lobby::on_focused()
config.save();
}
const auto & profile = hmd_traits.controller_profile;
const auto & profile = hmd_traits().controller_profile;
input.emplace(
*this,
"assets://controllers/" + profile + "/profile.json",
+4 -4
View File
@@ -217,7 +217,7 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
{
auto view = self->system.view_configuration_views(self->viewconfig)[0];
view = hmd_traits.override_view(view);
view = hmd_traits().override_view(view);
info.render_eye_width = view.recommendedImageRectWidth * config.resolution_scale;
info.render_eye_height = view.recommendedImageRectHeight * config.resolution_scale;
@@ -421,7 +421,7 @@ void scenes::stream::on_focused()
{
gui_status_last_change = instance.now();
const auto & profile = hmd_traits.controller_profile;
const auto & profile = hmd_traits().controller_profile;
input.emplace(
*this,
"assets://controllers/" + profile + "/profile.json",
@@ -684,7 +684,7 @@ void scenes::stream::update_gui_position(xr::spaces controller)
{
std::optional<std::pair<glm::vec3, glm::quat>> aim;
if (hmd_traits.view_locate)
if (hmd_traits().view_locate)
{
aim = application::locate_controller(
application::space(controller),
@@ -934,7 +934,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
}
// Allow the headset to time warp if we are redisplaying a frame
if ((not hmd_traits.discard_frame) or
if ((not hmd_traits().discard_frame) or
std::ranges::any_of(current_blit_handles, [](const auto & h) { return h and h->feedback.times_displayed < 2; }) or
is_gui_interactable())
{
+1 -1
View File
@@ -127,7 +127,7 @@ stream_defoveator::pipeline_t & stream_defoveator::ensure_pipeline(size_t view,
// Fragment shader
auto specialization = make_specialization_constants(
int32_t(alpha),
VkBool32(hmd_traits.needs_srgb_conversion));
VkBool32(hmd_traits().needs_srgb_conversion));
auto fragment_shader = load_shader(device, "reprojection.frag");
vk::pipeline_builder pipeline_info{
+2 -2
View File
@@ -493,7 +493,7 @@ void scenes::stream::tracking()
break;
case wivrn::device_id::EYE_GAZE:
// Eye gaze uses view pose as the origin
if (hmd_traits.view_locate)
if (hmd_traits().view_locate)
tracking.device_poses.push_back(locate_space(item.device, spaces[item.device], spaces[wivrn::device_id::HEAD], tracking.timestamp));
else
{
@@ -754,7 +754,7 @@ void scenes::stream::send_derived_pose()
{
// This may happen if the runtime does not support palm ext
// check if we have a device specific offset
if (not hmd_traits.hand_interaction_grip_surface)
if (not hmd_traits().hand_interaction_grip_surface)
{
switch (target)
{
+2 -2
View File
@@ -45,7 +45,7 @@ xr::face_tracker_type xr::face_tracker_supported(xr::instance & instance, xr::sy
return xr::face_tracker_type::htc;
}
if (hmd_traits.pico_face_tracker)
if (hmd_traits().pico_face_tracker)
{
// The extension used by Pico is not published
// it doesn't even need to be requested...
@@ -85,7 +85,7 @@ xr::face_tracker xr::make_face_tracker(xr::instance & instance, xr::system & sys
properties.supportLipFacialTracking);
}
if (hmd_traits.pico_face_tracker)
if (hmd_traits().pico_face_tracker)
{
// The extension used by Pico is not published
// it doesn't even need to be requested...
+2 -2
View File
@@ -100,11 +100,11 @@ static std::pair<XrVersion, XrInstance> create_instance(XrInstanceCreateInfo & i
XR_API_VERSION_1_0,
})
{
if (version > hmd_traits.max_openxr_api_version)
if (version > hmd_traits().max_openxr_api_version)
{
spdlog::info("skip OpenXR {} due to headset quirk max version {}",
xr::to_string(version),
xr::to_string(hmd_traits.max_openxr_api_version));
xr::to_string(hmd_traits().max_openxr_api_version));
continue;
}
std::vector<const char *> extensions;