Skip to content

The exact CSG writes a neighbour's face as the last update built it when nothing that can reach the face changed (#281) - #362

Merged
LogicalError merged 1 commit into
mainfrom
feature-exact-face-replay
Nov 19, 2026
Merged

LogicalError merged 1 commit into
mainfrom
feature-exact-face-replay

Conversation

@LogicalError

Copy link
Copy Markdown
Member

Part of #281 (exact speed-ups, item 1: replay faces the edit cannot reach).

When a brush moves, every brush touching it is built again, all its faces, although most of them are nowhere near the moved brush. On bm_c0a0a those neighbours took 85-90% of ExactCSGJob's time in a drag, and the longest of them set its wall time, not the moved brush.

What a face is built from

ExactFaceBuilder.BuildFace reads, for one face: the face's own brush (its exact planes and the face polygon made from them), the brush's routing table, and every touching brush that can reach the face: its planes, the three categories it gives the face's parts, whether it routes and its lookup, in touching order. A touching brush can reach the face unless its bounds miss the face's or one of its planes has every corner of the face strictly outside. One that can't makes no region of the face and has no interval on any line through it, so it adds nothing, and a lookup to it routes as Outside. Having no region is not enough: a brush without a lookup still puts points on the face's lines.

Changes

  • ExactBrush.generation: a brush built again keeps its generation when its planes and corner count are the same (everything the CSG reads of it is made from them), otherwise it takes a new one from the tree's counter (ExactBrushes.SetGeneration, in ExactInputJob, ExactBoundsJob and ExactMergedRebuildJob).
  • ExactFaceCache, by node order: per brush, its generation, its routing table, and per face what it wrote, what it counted and its key: the generation, categories, routing and lookup of each brush that can reach it.
  • ExactCSGJob writes a face from the cache when the brush, its routing table and the face's key are the same, and builds it otherwise. A face routed through the tables of brushes it gives way to (a coplanar tie) is always built. Faces are built into a list first and then written value by value as before, so the stream GenerateSurfaceTrianglesJob reads is unchanged. Nothing is replayed while the exact output is captured for tests.
  • CompactHierarchyManager.BuildEveryFace turns replay off; VerifyReplayedFaces builds every replayed face as well and counts ExactCSGStat.ReplayMismatch, a failure, where the two differ.
  • ContentsTreeHarness.Build(scene, captureExact: false) runs the CSG as outside tests.

Timing

Two drags of each brush on bm_c0a0a, median per frame, main / this branch:

  • ExactCSGJob over the worker threads: large brush 11.3-11.4 / 7.6-7.8 ms, median brush 2.35-2.46 / 2.19-2.22 ms.
  • UpdateTreeMeshes: large brush 13.4-13.5 / 12.9-13.1 ms; median brush within noise (10.8-11.1 / 10.6-10.9 ms).
  • Faces replayed: 1,980 of 7,020 built for the large brush, 358 of 984 for the median one. The rest are faces the moved brush can reach, and the faces of neighbours whose routing table changed.

Memory: the cache holds 9.8 MB on bm_c0a0a (5,755 brushes, 34,378 faces).

Tests

  • ExactFaceReplayTests (12): two trees with the same scene and the same edits, one replaying with every replayed face verified, one building every face; the triangles must be the same. Moves (including through a neighbour and back), operation changes (Additive, Subtractive, Intersecting, in and out of a composite), contents changes, reordering, removing and adding, and random edits; faces must have been replayed.

  • Each fails when the key leaves out the touching brushes' generations, when no brush is taken to reach a face, when the routing tables are not compared, when a brush keeps its generation with other planes, when faces with ties are replayed, or when the categories are left out of the key.

  • Dragging both brushes on bm_c0a0a with VerifyReplayedFaces on: no mismatches.

  • Full EditMode suite: 3193 passed, 2 failed, 5 skipped. The two failures are ChiselSubtractiveWorkflowTests.APillarInARoom_ShadowsTheFloorFromALamp, which fail the same way on main in the project this ran in.

…hen nothing that can reach the face changed (#281)
@LogicalError
LogicalError merged commit 622affc into main Nov 19, 2026
5 checks passed
@LogicalError
LogicalError deleted the feature-exact-face-replay branch November 19, 2026 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant