Linora

0505. TRANSFORM baked on the GPU

Status: Accepted (2026-11-28, EN2). Works with DC2’s TRANSFORM op (shared/src/ops.ts, ADR 0103) and ChangeSet.transforms.

Context

A move of a large selection used to be one SET per root. Above 200K roots the editor refused it, and each committed move re-derived every chunk it touched (~0.45 s for 5M shapes). DC2 added TRANSFORM { ids, dx, dy }, a parent-space translation of many roots. The change feed reports it as transforms: { roots, dx, dy }[], in apply order, with the roots and their descendants left out of changed. The goal is a commit without per-node derivation, right after the drag’s GPU preview.

Decision

  1. Bake first, on old positions. DocSync.apply handles transforms before anything else in the change set, so the instance positions are still the ones on the GPU. If the same change set also moves nodes (STRUCTURE), every transform is re-derived instead.
  2. Instance ranges. Each root’s subtree is the range [primStart, subtreeEnd). Ranges are sorted (unless the roots already come in paint order) and merged when they touch. An overlap means a root inside another root’s subtree, which must move twice, so it is re-derived. A root under a rotated ancestor is also re-derived: its parent-space delta is not the page delta.
  3. Transform feedback. Renderer.bakeTranslate runs VS_BAKE over the instances, one point each with the rasterizer off. It writes each instance’s 10 words back with (dx, dy) added to its centre: through an 8 MB temporary buffer, then copyBufferSubData. The program is compiled and linked when the renderer is created; Chrome links it in the GPU process, so the first bake does not block (it cost ~50 ms when linked on first use).
  4. Chunk metadata.
    • Chunks the ranges cover completely: render and geometric bounds shift by (dx, dy) (padded by f32 rounding), and their LOD slots are translated in the same pass. Nothing is derived.
    • Chunks covered in part: their bounds take both places, and they wait for re-derivation (ADR 0503), because their LOD groups mix moved and unmoved instances.
  5. Scattered selections. With more than 256 merged ranges (a marquee over random shapes), the bake moves instances whose flags have the selected bit instead, over the whole buffers. This applies only when the roots are exactly the selection and no flag pass is pending; otherwise the transform is re-derived.
  6. Small transforms are re-derived. Under 64 chunks of instances, the deferred re-derive is exact and cheap, and keeps chunk bounds tight.

Measured (Chrome, node tools/bench/gpu-check.ts --big)

| Case | doc.apply | engine CPU | GL calls | |—|—:|—:|—:| | 30 pages + 300K shapes, every top-level node (ranges) | 8.6 ms | 8.7 ms | 0.4 ms | | every other shape of 300K, selected (selection flags) | 2.4 ms | 5.2 ms | 0.06 ms | | 5M shapes, every shape | 455 ms | 58 ms | 0.1 ms |

The re-derive it replaces costs ~0.45 s (5M shapes) or ~0.41 s (website) of CPU.

Alternatives

Consequences