Linora

0501. Remote drag preview slots in the engine

Status: Accepted (2026-11-27, WP-E0)

Context

A peer’s drag must be visible live without sending ops per frame: drags apply nothing until pointer-up, and presence carries the drag affine (ADR 0007, editor.md). Locally the engine already previews drags on the GPU (u_xf* uniforms applied to selected instances), at zero CPU cost per frame. render-engine.md planned the same for peers: “up to 4 remote affines as uniforms and flag bits per instance selecting the slot”. E0 must keep the render path unchanged: buffer formats, draw calls, chunking and LOD, with bench parity.

Decision

  1. Per instance: byte 1 of the existing 4-byte flags word (allocated for every primitive, unused until now) holds 1 + slot (0 = not in a remote drag). No new buffer and no format change; byte 0 keeps selected/hidden. Two bits would be enough for 4 slots; a whole byte keeps CPU writes trivial.
  2. A second program variant, used only while a slot is live. VS stays the POC vertex shader, byte for byte. VS_REMOTE is the same source plus u_rxMask (bit s = slot s live), u_rxA/u_rxS/u_rxT[4] and one branch after the local drag preview: if the instance is not locally dragged and its slot is live, it gets the same p' = A + (p - A) * S + T transform. The renderer links VS_REMOTE lazily on the first frame with a live slot (one-time compile, a few ms) and draws with it while remoteMask != 0; with no remote drag it draws with the unchanged program, so the default GPU path costs nothing. (A first version used one shader with a uniform-gated branch; headed sweeps hinted at ~0.3 ms more worst-zoom GPU time, so the branch moved into the variant.)
  3. CPU API: Scene.setRemoteSlot(ids, slot) / clearRemoteSlot(slot) write byte 1 and a per-chunk counter cRem (4 B per chunk) and mark those chunks’ flags dirty (one partial flags upload when a drag starts and ends). Renderer.setRemoteXf(slot, affine | null) only sets uniforms: nothing is uploaded per presence update. Engine wraps the three calls.
  4. Culling and LOD: a chunk that holds primitives of a live slot is never culled and never drawn as LOD impostors, the rule local drags already use for partly selected chunks. Big LOD slots copy byte 1 from their primitive.
  5. Precedence: an instance that is locally selected and being dragged ignores its remote slot.
  6. Slot allocation (E1, editor): one slot per dragging peer, at most 4 at once. A fifth simultaneous remote drag shows no preview; its committed ops still arrive.

Alternatives

Consequences