diff --git a/client/application.cpp b/client/application.cpp index 7bd3cc57..70fc14a5 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -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 xr_extensions{ diff --git a/client/configuration.cpp b/client/configuration.cpp index c6b279e7..5dc4fa07 100644 --- a/client/configuration.cpp +++ b/client/configuration.cpp @@ -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; diff --git a/client/hardware.cpp b/client/hardware.cpp index 580e1c98..e3085fbd 100644 --- a/client/hardware.cpp +++ b/client/hardware.cpp @@ -102,9 +102,25 @@ static std::optional 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() { diff --git a/client/hardware.h b/client/hardware.h index 317558da..363a381c 100644 --- a/client/hardware.h +++ b/client/hardware.h @@ -38,7 +38,7 @@ enum class feature using hmd_permissions = magic_enum::containers::array; -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(); diff --git a/client/scenes/input_profile.cpp b/client/scenes/input_profile.cpp index 03476a6e..2fd55b49 100644 --- a/client/scenes/input_profile.cpp +++ b/client/scenes/input_profile.cpp @@ -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); diff --git a/client/scenes/lobby.cpp b/client/scenes/lobby.cpp index 89edcd7f..63de0ea8 100644 --- a/client/scenes/lobby.cpp +++ b/client/scenes/lobby.cpp @@ -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", diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index 283982cc..261bf834 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -217,7 +217,7 @@ std::shared_ptr scenes::stream::create(std::unique_ptrsystem.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> 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()) { diff --git a/client/scenes/stream_defoveator.cpp b/client/scenes/stream_defoveator.cpp index 70bf259a..fd9c3b29 100644 --- a/client/scenes/stream_defoveator.cpp +++ b/client/scenes/stream_defoveator.cpp @@ -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{ diff --git a/client/scenes/stream_tracking.cpp b/client/scenes/stream_tracking.cpp index 5af32684..0b95dfba 100644 --- a/client/scenes/stream_tracking.cpp +++ b/client/scenes/stream_tracking.cpp @@ -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) { diff --git a/client/xr/face_tracker.cpp b/client/xr/face_tracker.cpp index 088870c2..695ebe68 100644 --- a/client/xr/face_tracker.cpp +++ b/client/xr/face_tracker.cpp @@ -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... diff --git a/client/xr/instance.cpp b/client/xr/instance.cpp index b7165430..daad851c 100644 --- a/client/xr/instance.cpp +++ b/client/xr/instance.cpp @@ -100,11 +100,11 @@ static std::pair 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 extensions;