Skip to content

Make the OpenXR session again after a loss instead of quitting - #79

Open
feimos-dev wants to merge 10 commits into
mainfrom
session-lifecycle
Open

feimos-dev wants to merge 10 commits into
mainfrom
session-lifecycle

Conversation

@feimos-dev

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

Copy link
Copy Markdown
Owner

Session restarts go through one place, and a lost session comes back instead of telling the game to quit.

Restarts

  • XrBackend::RebuildSession(reason) covers the first Submit (game's device), the game's inputs and a loss. It holds the session lock and never runs mid-frame: if the game has a frame open, that frame is ended first.
  • After a rebuild, what the game set comes back. Eye compositors are made again at the next Submit. The skybox is shown again from the game's texture (kept until ClearSkyboxOverride). Overlays drop their stale swapchains and remake them from their textures.
  • Readers that skipped the session lock now take it: the play area (GetLiveCollisionBoundsInfo's source), the submitted pose, the IPD, the eye-in-head rotation and the proximity check in GetControllerState. The interaction-profile query (the info set) runs only under the session lock, so it can't race a thread making the game's actions.
  • Fewer restarts: legacy input actions and the info set aren't attached until the game's device is known (XrBackend::InputsMayAttach). That means the first Submit, or 2 s without any Submit for a game that never submits. A manifest loaded before the first Submit therefore costs no extra restart. A game that asks for legacy input gets it in place of the info set, with no restart between them.

Loss

  • LOSS_PENDING, XR_ERROR_SESSION_LOST, a failed rebuild, and EXITING without STOPPING first are all treated as a loss. Instance loss is mapped the same way here; remaking the instance is in the stacked PR.
  • On a loss: the session is destroyed, the headset and controllers get VREvent_TrackedDeviceDeactivated, and they report disconnected with TrackingResult_Uninitialized. xrGetSystem is tried at once, then about once a second, forever. When the session is made again by any path, the devices get VREvent_TrackedDeviceActivated, and SetupSession binds the game's actions to it.
  • While the session is lost there is no input restart and no first-Submit device switch. The switch happens at the first Submit after recovery.
  • Where the retry runs:
    • Games: between their frames.
    • Helper programs (overlay and headless sessions): from their own loop. The loop only tries the session lock (SessionWrapper::try_lock), because a thread holding it may be stopping the loop. The loop and its thread are kept through the rebuild.
  • A loss never sends VREvent_Quit or VREvent_DriverRequestedQuit. Only the user quitting from the runtime does (EXITING after STOPPING). A loss also clears STOPPING, so a later EXITING isn't taken for a quit.

Tests

  • Stand-in runtime: a scripted LOSS_PENDING really loses the session. It fires once per process, the session's calls then answer XR_ERROR_SESSION_LOST, and loss_unavailable_ms keeps xrGetSystem failing for that long. A scripted EXITING on a running session behaves like a user quit (STOPPING, then EXITING after xrEndSession). The dump counts sessions created and lost, and action attaches.
  • xr_failures scripts:
Script Situation Expected
lost system back at once no quit, Deactivated then Activated, one loss, a third session
lost_unavailable back after the 1 s retry same as lost
lost_before_submit loss before the game's first Submit game's device used after recovery
lost_input game had actions loaded actions attached to the recovered session
lost_overlay overlay app (new case overlay-app-loss) loads a manifest during the loss as lost, and the overlay drawn again
  • Unit tests for the state outcome and the retry pacing.

All CI jobs pass, Windows and Linux. The baselines didn't change.

Not covered here: rebuilding the instance after XR_ERROR_INSTANCE_LOST (in the stacked PR). Headless sessions take the same loop path as overlay sessions but weren't run, since on Linux a background app gets a scene session.

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