Repository navigation
feat(mode_switch): one-call ModeSwitch::step() for every platform; document the 2D/3D transition contract - #73
Merged
Conversation
…cument the 2D<->3D contract
The runtime switches a rendering mode in one frame and never eases the stereo
disparity (that is app content), so every app has to sequence its own ramp.
dxr::ModeSwitch already did that, but the per-frame glue that turns V / 0-8
presses into request() + update() + the PFN call lived only in
XrSessionUpdateModeSwitch, which takes the Windows-only XrSessionManager. The
macOS legs (runtime cube_handle_* apps, the modelviewer demo) hand-copied it,
and several apps on every platform never wired it at all.
- mode_switch.h is now header-only and adds ModeSwitch::step(dt, requestedMode,
modeCount, modeViewCounts, currentMode, steadyIpd) -> {ipd, fire, mode} and
ModeSwitch::cycleTarget(). step() owns the "current on-screen ipd" rule that
fixed the first-press snap (4307382) and suppresses a no-op fire, so callers
cannot re-introduce either bug. kModeSwitchDefaultDurationS names the shared
0.18 s ramp.
- Header-only means it is reachable through displayxr::rules: Android legs and
engine ports can use it without linking displayxr_common_lib.
- XrSessionUpdateModeSwitch is now a thin Windows wrapper over step(); same
behaviour.
- README: "Smooth 2D<->3D transitions" — what the runtime does vs what the app
must do, the ramp/request ordering, wiring for Windows and for every other
leg, and which mode changes are not app-eased.
- tests/common_smoke.cpp: step() routing, idle steady, absolute/cycle requests,
out-of-range and no-op requests, null view-count table, and the fresh
first-press 3D->2D case (verified to fail against the pre-4307382 rule).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dfattal
force-pushed
the
feat/mode-switch-all-platforms
branch
from
October 12, 2026 03:23
5d71fdb to
735e606
Compare
dfattal
marked this pull request as ready for review
October 12, 2026 03:25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
David: "ease 2D<->3D transitions (mode switching) the same way we do on Windows; that's valid for all apps and should be clear in displayxr-common."
What Windows does today is entirely app-side: the runtime switches a rendering mode in one frame (atlas recipe, DP weave-vs-flat, lens all follow the mode the moment it lands, ADR-028) and never ramps the stereo disparity. The only runtime aid is the one-frame #615 eye-set guard. The Leia plug-in has no fade on any platform either. The smooth transition the Windows cube apps show is
dxr::ModeSwitch(this repo), driven byXrSessionUpdateModeSwitch().That glue takes the Windows-only
XrSessionManager, so the non-Windows legs could not call it: the runtime's macOScube_handle_*apps and the modelviewer demo hand-copied ~40 lines each, and several apps on every platform (all the zones apps,cube_handle_vk_linux) never wired it. The contract was also written nowhere in this repo.What
mode_switch.his header-only and gainsModeSwitch::step(dt, requestedMode, modeCount, modeViewCounts, currentMode, steadyIpd) -> {ipd, fire, mode}plusModeSwitch::cycleTarget().step()is the glue every platform now shares. It applies the "ramp from the on-screen ipd" rule that fixed the first-press snap (4307382) and drops a fire for the mode the runtime is already in, so a caller cannot re-introduce either bug.kModeSwitchDefaultDurationS(0.18 s) names the shared ramp.mode_switch.cppis gone.displayxr::rules, so Android legs and engine ports can include it without linkingdisplayxr_common_lib.XrSessionUpdateModeSwitchis now a thin Windows wrapper overstep()with the same behaviour.mode_switch.h), every app, every platform" covers: what the runtime does and does not do, the ramp/request ordering table, wiring for Windows and for every other leg, the inputs (wherecurrentMode/modeViewCounts/steadyIpdcome from), and the mode changes an app cannot ease (runtime-owned V in hosted/legacy apps, the shell's Ctrl+V, agent requests).tests/common_smoke.cpp):step()routing, idle steady value, cycle and absolute requests, out-of-range and same-mode requests, a null view-count table, and a fresh sequencer's first 3D->2D. I mutation-checked the last one: revertingstep()to the pre-4307382 rule fails it.Consumers
cube_handle_{metal,vk,gl}apps switch from their inline copies tostep(), and the macOS zones apps adopt it. A new advisory linter rule, INV-2.9, flags apps that request modes without the sequencer. That PR pins this branch's commit and must be re-pinned to the release tag before it merges, so this PR merges and tags first.step()is an optional follow-up.Doc companion: DisplayXR/displayxr-leia-plugin#331 (no arm of the plug-in fades; the transition is app-side).
Testing
cteston macOS: 5/5 pass, including the newstep()cases.DXR_TEST_MODE_TOGGLE_S). 3D->2D ramps the disparity from 1 to 0 over about 0.18 s and requests 2D on the landing frame. 2D->3D requests on the first frame (ipd about 0.01) and ramps back to 1. Both checked for Metal, Vulkan (vk_native), GL and the four zones apps.🤖 Generated with Claude Code