10 kB 157 lines
7e68a437
⋯
xr/CLAUDE.md
download raw history
at main Markdown

c8-xr: Monado and the OpenXR loader, for VR games in XR #

Optional, built by build.sh --xr (before the components: c8 builds its overlay client against the loader's headers) or by hand, xr/build.sh PREFIX [BUILDDIR-SUFFIX]. The desktop builds and runs without it. Why it exists and the whole design: compositor/MONADO-XR.md; how c8 uses it: the Monado path section of compositor/XR.md.

  • Sources (2026-12-04): OpenXR-SDK-Source release-1.1.65 and xrizer v0.6 are shallow git submodules, openxr-sdk/ and xrizer/, upstream's own repos unchanged (so we redistribute none of their code); build.sh runs git submodule update --init --depth 1 -- xr when one isn't checked out. Moving a pin: git -C xr/xrizer fetch --depth 1 origin tag vX && git -C xr/xrizer checkout vX, then commit the submodule. Monado is a shallow submodule too, monado/: our fork on Tangled (monado in the knot, from the first publish, 2026-12-04), branch c8-xreal-one-pro-plus on upstream's v25.1.0, upstream's cylinder fix cherry-picked (its author kept), then ours as one commit, "cont8nuum: glasses driver, one view, scanout correction, sharing", its four parts below (squashed 2026-12-04, the user's call; a later change can be a commit of its own; lowtide's, in UTC; BSL-1.0 like the rest of it). Upstream's history is kept whole. That branch is the fork's default and the one all our Monado work goes on (the user's call, 2026-12-04); its main is only upstream's, never committed to. The submodule follows it (branch in .gitmodules). A change: commit in xr/monado (or the user's own clone, ~/Code/monado-c8), push the branch, then commit the new pointer here. Moving to a newer Monado is a rebase of the branch onto its tag; update deliberately: Monado's driver API isn't stable. Before the fork there were patch files here, applied to a clone in subprojects-src/; a build dir made from that clone is removed by build.sh (cmake won't move a cache to another source dir). It builds each with cmake/ninja into build-openxr/build-monado (+ suffix, ignored) and installs into the prefix with $C8_SUDO. The SDK's Wayland code includes wayland-client.h by its bare name, hence the pkg-config cflags; hello_xr stays in build-openxr/src/tests/hello_xr/ for tests.
  • xrizer (v0.6, the submodule's pin, GPL 3.0, 2026-12-03): OpenVR on OpenXR, SteamVR's games on Monado without SteamVR. Its own cargo xbuild --release (CARGO_TARGET_DIR build-xrizer) makes release/bin/linux64/vrclient.so (a symlink: copied as a file) and bin/version.txt; installed as the user, into PREFIX/share/xrizer when the prefix is in home, else ~/.local/share/xrizer: Steam runs games in a container that sees home but /usr only as /run/host/usr (its README). c8 looks in ~/.local/share first (xrruntime.c find_xrizer). Needs cargo, rust and glslc (shaderc). Tested: builds (4 min the first time), exports VRClientCoreFactory; never yet run by a game. Trap: the user's Steam is the Flatpak, which sees neither ~/.local/share nor /usr/local nor Monado's socket, and loads an OpenXR runtime only if it was built for the Flatpak's runtime (as WiVRn's Flatpak is).
  • "c/cylinder: Fix aspectRatio for compute compositor": upstream's fix (after v25.1.0, cherry-picked with its author) of the compute compositor's cylinder layers, whose height was angle x aspect instead of angle / aspect; c8's charms bar is one. It goes away by itself when the branch is rebased past the fix.
  • One view (ours, 2026-12-02): when both views have the same viewport and field (our driver in the glasses' 2D mode), Monado's renderer composes one view, not two (render_resources.c, r->view_count; the session still has two). Every layer is a full-screen pass per view in its graphics compositor: the background's two equirect layers alone took its GPU time from 2.6 to 8.7 ms a frame, at 90 Hz half the rate. On the glasses (2026-12-02): smooth at 90 with the background on.
  • Scanout (ours, 2026-12-02): rolling-scanout correction in the graphics compositor, which v25.1.0 only has in the compute one. The distortion mesh pass (mesh.vert, its UBO in render_interface.h, filled in comp_render_gfx.c) warps each vertex's row between the scanout-begin pose and the end one by how far down it is (our mesh is the 2x2 "none" one, so it's linear in the row, which a shear is). Only when the device's begin and end poses differ: the driver sets supported.compositor_info again. Without it a turn sheared windows, the bottom trailing the top (90 Hz, frames on time). Trap: v25.1.0's graphics path drops the end pose (chl_frame_state_gfx_set_views gave begin as both), so the first try did nothing but the driver's lower look-ahead, and everything lagged more, the background too (2026-12-02); the commit passes it through (comp_high_level_render.[ch], comp_render.h, comp_renderer.c). On the glasses that build drew nothing but black (2026-12-03, at 120 Hz; with scanout = 0 at 90 Hz the picture came back, still wobbling on turns), not seen nested even with our driver as the head and a turning mock IMU. So c8_scanout_usable (comp_render_gfx.c) leaves a frame unwarped when its poses aren't unit quaternions or are 10 degrees or more apart, and every 450 frames says the most they were apart: a warning with how many went unwarped, else at info (hidden at Monado's default level; nested with XRT_LOG=info, turning 0.6 rad/s at 60 Hz: 0.57). On the glasses with it (2026-12-03): picture back and steady by the user's eye, no warning in the log. [glasses] scanout = 0 turns it off and puts the look-ahead back (aimed at the middle row, as before it).
  • Sharing (ours, 2026-12-03): Monado's picture for c8's screenshots and screen sharing (the lease leaves c8 nothing of the glasses). comp_renderer.c: when C8_SHARE_FD (a SOCK_SEQPACKET end c8 passes at spawn) is set, a thread takes commands ('S' stream, 's' stop, '1' one frame, 'R' c8 took the last) and the debug mirror's sink sends each frame as a memfd (R8G8B8X8, view 0, layers composed, before distortion) with a c8_share_msg (width, height, stride, frame id), one in flight at a time. The mirror only runs while asked (mirroring_to_debug_gui turns off the one-layer fast path). Trap: upstream's blit samples the scratch through its sRGB view, which decodes it and the copy came out dark; it reads the unorm view. Tested nested: Print and grim -o XR-VIEW get Monado's composite.
  • The driver's build (ours): C8_GLASSES_DIR/C8_SRC_DIR cache paths turn on XRT_BUILD_DRIVER_C8_GLASSES (added to AVAILABLE_DRIVERS, which generates xrt_config_drivers.h); drv_c8_glasses is driver/c8_glasses.c plus the compositor's own compositor/src/imu.c (one fusion, two hosts), linked into the targets, and its builder is in target_lists.c.
  • driver/c8_glasses.c (CC0): an HMD for the XREAL glasses' network IMU (reads [glasses] once at Monado's start; ipd sets the 3D mode's eyes, not Monado's fixed 63 mm, since 2026-12-02) (the USB-HID Air family is Monado's own xreal_air). A thread runs a wl_event_loop for imu.c (read, dispatch, 2 ms naps) under a mutex; get_tracked_pose is c8_imu_orientation (OpenXR's axes already) plus the neck model from [glasses] neck, at Monado's time plus ahead_ns ([glasses] latency scaled as glasses.c does, less the refresh and half scan Monado already counts). The display is C8_GLASSES_MODE=WxH@mHz from c8 (default 3840x1080@60): 3840 wide is the 3D mode, an eye each half; narrower is the 2D mode, both views filling the one picture from between the eyes (no eye relation: no depth, but games run, at up to 120 Hz). The refresh is the mode's (a hard 60 on the 2D mode's 120 Hz left Monado a refresh late every frame). get_compositor_info (top-to-bottom over [glasses] scanout or a refresh) is written but supported.compositor_info is false: on the 1 Pro+ in the 2D mode the world swung against every turn with it and held still without (2026-12-02); untried in 3D. So each frame is posed for its middle row (ahead_ns: latency scaled, less the refresh). FOV from [glasses] fov (diagonal); blend modes additive, then opaque. Reads [glasses] fov, tilt, steady, neck, latency and scanout from c8's config.ini; shares glasses-bias with c8 (c8_state_path). The builder claims the head when C8_XR_IMU is set (a test's mock stream) or a USB device 3318:0444/0435/0436/0437 is there. C8_GLASSES_LOG sets its log level.
  • driver/imu-host.h: imu.c's logging through U_LOG_IFL; c8's copy is compositor/src/imu-host.h. imu.c includes it with angle brackets so each build's -I picks its own.

Tested (2026-12-02): both build into .prefix; the driver links into monado-service (13 c8_ symbols), with the Wayland window and direct targets on. In a nested c8 Monado ran with qwerty as the head (no glasses plugged in, so our builder stood aside) and hello_xr -g Vulkan2 started a session on it. Trap: Monado builds without OpenGL ES when GLES3/gl3.h is missing (Mesa-libGLESv3-devel), and then has no XR_KHR_opengl_es_enable, which c8's overlay needs; build.sh stops on XRT_HAVE_OPENGLES off for that. With it, c8's overlay and hello_xr share Monado (XR.md, the Monado path). On the 1 Pro+ (2026-12-02) the builder claims the head, the IMU stream is clean and c8's overlay frames follow the head; never yet through a lease. Monado sat on SIGTERM there too (alone, with our driver): it needed SIGKILL. Since, c8 stops it through its stdin and it ends cleanly (XR.md, the Monado path); SIGTERM is caught by something in it and goes nowhere. First real session (2026-12-02): the lease was granted, but in the 2D mode Monado drew two halves on one picture, a refresh late (60 Hz assumed at 120) and floaty; hence the mode above. Second: tracking held with scanout correction off; edges opened on turns (the overlay's overscan, XR.md).