0507. Frame clipping by instance ranges and scissor rectangles
Status: Proposed (2026-11-28, EN2), requested by ED1 for the frame tool (CLIP_CONTENT on by default, as in Figma). Not implemented in wave 3 (scope held at the wave-3 goals); a tested prototype of this design existed and can be rebuilt from this record. Until then CLIP_CONTENT renders unclipped.
Context
A frame with CLIP_CONTENT (NodeFlag.CLIP) must clip everything below it to its box, rotation included. Hit tests and marquee must skip the clipped-away parts, so a click never lands on hidden overflow. Constraints:
- no per-node memory (ADR 0024);
- the default draw path must not change (bench scenes and parity have no clipping frames);
- the GPU budget is the frame budget.
One idea was a clip id in spare flag bits plus a clip-rect table read by the fragment shader. That adds per-instance work for every instance on the default path.
Decision
- A clipping frame’s descendants are one contiguous instance range in paint order (pre-order):
[own end, subtree end). DocSync keeps the list of clipping frames, updated from created, deleted and VISIBILITY-changed nodes (clipContent is a VISIBILITY prop). It is a few entries, nothing per node.
- Clip segments (
clip.ts, ClipState), rebuilt only when the scene, the selection or the clip list changed:
- each visible, laid-out frame gives its range and world box;
- nested frames intersect their boxes with the enclosing ones and cut the enclosing range into pieces;
- the result is sorted, non-overlapping segments
[start, end) -> box.
- Drawing. With segments present, the renderer splits each run of real instances at segment edges and draws the parts inside a segment with
gl.scissor set to the box in device pixels. While a drag preview moves a selected clipping frame, its box moves by the same affine. The shader and the instance format do not change. Without clipping frames, draw takes the unchanged path.
- LOD. A chunk whose clipped instances may reach outside their box (its bounds exceed the box) is never drawn as impostors, because impostors cannot be scissored per instance. Chunks fully inside their box keep LOD.
- Queries.
hitTest drops instances of a segment when the point is outside its box. queryRect clips each instance’s bounds by its box first; chunks with clipped content that may overflow take the per-instance path instead of the owners-only one.
- Not yet: rotated clipping frames. A frame whose own rotation or an ancestor’s is not 0 is drawn and hit unclipped: a scissor is axis-aligned. A shader variant with a clip quad (like
VS_REMOTE, used only for those draws) is the follow-up.
Alternatives
- Clip id in the flags word plus a clip table read in the fragment shader: per-instance work and a texture fetch on the default path. Rejected.
- Stencil clipping: needs a stencil buffer (the context has none: +4 B per device pixel) and one stencil pass per clipping frame. Kept for rotated frames if the shader variant proves slower.
Consequences
- Each visible clipped segment costs one more draw call per pass. A design with hundreds of visible clipping frames adds hundreds of draw calls, which is cheap next to millions of instances.
- Chunks whose overflowing content is clipped are drawn at full detail when zoomed out.
- Bench scenes are unaffected: the generators set no CLIP, so no segments exist and the draw path is the same.