Skip to content

Make the OpenXR instance again when the runtime loses it - #82

Open
feimos-dev wants to merge 14 commits into
session-lifecyclefrom
session-instance-loss
Open

feimos-dev wants to merge 14 commits into
session-lifecyclefrom
session-instance-loss

Conversation

@feimos-dev

@feimos-dev feimos-dev commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

This builds on the session-loss handling in the base branch. A runtime whose service dies answers XR_ERROR_INSTANCE_LOST (Monado does this and never sends LOSS_PENDING). The game, or a helper program, now keeps running and the instance is made again once the runtime is back.

  • Detection: the instance is marked lost along with its session when any of these happen:

    • xrPollEvent or a frame call answers XR_ERROR_INSTANCE_LOST.
    • An INSTANCE_LOSS_PENDING event arrives.
    • xrGetSystem answers XR_ERROR_INSTANCE_LOST while a lost session waits.

    The devices are deactivated as for a session loss, and no quit is sent.

  • Recovery, tried at once and then about once a second, forever. It runs between a game's frames, or from a helper program's own loop:

    • BaseInput forgets its action handles (they belonged to the old instance). Until the new session exists, the game's SetActionManifestPath and legacy input calls only record what to load, so nothing is made on a dead instance.
    • The lost session is ended.
    • DrvOpenXR::RemakeInstance destroys the old instance and makes a new one with the same extensions, keeping it across tries while the headset isn't there yet. It sets up the function pointers, system and views again. The old function table is not freed, so a thread outside the session lock can't read freed memory.
    • PumpEvents skips while another thread holds the session lock exclusively.
    • The graphics requirements of the session's binding are asked again after every recovered system. For Vulkan the device xrGetVulkanGraphicsDeviceKHR names is also checked.
    • The subaction paths and the generic trackers' XDev list are made again on the new instance.
    • After the session is rebuilt, BaseInput looks its paths up again (subaction paths, input handles' device paths, hand profiles). It makes the actions and bindings again from the manifest that was loaded, or the one the game set meanwhile, falling back to legacy input if that fails.
  • Stand-in runtime: { "type": "instance_lost" } loses the instance once per process. xrPollEvent and the frame, session and system calls then answer XR_ERROR_INSTANCE_LOST until xrDestroyInstance, and xrCreateInstance fails for loss_unavailable_ms. Each instance hands out different path atoms, as a real runtime's do. The library is kept loaded (-z nodelete on Linux; pinned on Windows), because the loader unloads a runtime once its last instance is destroyed. The dump keeps its loss, session and attach counts across instances.

  • xr_failures:

Script Situation Expected
instance_lost game; runtime gone for 300 ms, first remake fails, next succeeds no quit, Deactivated then Activated, two instances, three sessions
instance_lost_overlay overlay app; its own loop remakes the instance as instance_lost
instance_lost_input game with a manifest manifest's actions made and attached again on the new instance

Linux x64: unit tests, stand-in runtime tests, hard stops and scripts/ci/conformance-linux.sh x64 all pass. The Linux baselines didn't change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants