From e06611edf5bb05172c8098ae2791a754c79bc316 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 7 May 2026 15:56:17 +0100 Subject: [PATCH] Expose CSG incremental rebuild strategy --- crates/vg_csg/examples/csg_perf_fixture.rs | 16 ++++++++++++++-- crates/vg_csg/src/assembler.rs | 20 ++++++++++++++++++++ docs/research/csg-performance-fixtures.md | 11 ++++++++++- notes/fresh-workspace-handoff.md | 4 +++- state/evidence.jsonl | 1 + state/map.yaml | 2 +- 6 files changed, 49 insertions(+), 5 deletions(-) diff --git a/crates/vg_csg/examples/csg_perf_fixture.rs b/crates/vg_csg/examples/csg_perf_fixture.rs index b6f1bd1..175bf05 100644 --- a/crates/vg_csg/examples/csg_perf_fixture.rs +++ b/crates/vg_csg/examples/csg_perf_fixture.rs @@ -116,6 +116,9 @@ fn run_case(case: PerfCase, mode: PerfMode) { let mut candidate_pairs = 0; let mut rejected_pairs = 0; let mut reused_mesh = false; + let mut used_checkpoint = false; + let mut checkpoint_rebuild_from = None::; + let mut direct_dirty_rebuild = false; for iteration in 0..MEASURE_ITERS { let start = Instant::now(); @@ -127,6 +130,9 @@ fn run_case(case: PerfCase, mode: PerfMode) { candidate_pairs = output.report.candidate_pairs; rejected_pairs = output.report.rejected_pairs; reused_mesh = output.report.reused_mesh; + used_checkpoint = output.report.used_checkpoint; + checkpoint_rebuild_from = output.report.checkpoint_rebuild_from; + direct_dirty_rebuild = output.report.direct_dirty_rebuild; black_box(( triangles, fragments, @@ -134,6 +140,9 @@ fn run_case(case: PerfCase, mode: PerfMode) { candidate_pairs, rejected_pairs, reused_mesh, + used_checkpoint, + checkpoint_rebuild_from, + direct_dirty_rebuild, )); timings.push(elapsed); } @@ -149,7 +158,7 @@ fn run_case(case: PerfCase, mode: PerfMode) { let p95_ns = percentile_ns(&timings, 95); println!( - "{{\"kernel\":\"vg_csg\",\"mode\":\"{}\",\"scenario\":\"{}\",\"brushes\":{},\"iterations\":{},\"warmup_iterations\":{},\"mean_ns\":{},\"min_ns\":{},\"p50_ns\":{},\"p95_ns\":{},\"max_ns\":{},\"triangles\":{},\"fragments\":{},\"warnings\":{},\"candidate_pairs\":{},\"rejected_pairs\":{},\"reused_mesh\":{}}}", + "{{\"kernel\":\"vg_csg\",\"mode\":\"{}\",\"scenario\":\"{}\",\"brushes\":{},\"iterations\":{},\"warmup_iterations\":{},\"mean_ns\":{},\"min_ns\":{},\"p50_ns\":{},\"p95_ns\":{},\"max_ns\":{},\"triangles\":{},\"fragments\":{},\"warnings\":{},\"candidate_pairs\":{},\"rejected_pairs\":{},\"reused_mesh\":{},\"used_checkpoint\":{},\"checkpoint_rebuild_from\":{},\"direct_dirty_rebuild\":{}}}", mode.as_str(), case.name, case.brushes, @@ -165,7 +174,10 @@ fn run_case(case: PerfCase, mode: PerfMode) { warnings, candidate_pairs, rejected_pairs, - reused_mesh + reused_mesh, + used_checkpoint, + checkpoint_rebuild_from.map_or_else(|| "null".to_string(), |index| index.to_string()), + direct_dirty_rebuild ); } diff --git a/crates/vg_csg/src/assembler.rs b/crates/vg_csg/src/assembler.rs index d01e47c..c4f66b4 100644 --- a/crates/vg_csg/src/assembler.rs +++ b/crates/vg_csg/src/assembler.rs @@ -23,6 +23,9 @@ pub struct BuildReport { pub candidate_pairs: usize, pub rejected_pairs: usize, pub reused_mesh: bool, + pub used_checkpoint: bool, + pub checkpoint_rebuild_from: Option, + pub direct_dirty_rebuild: bool, pub warnings: Vec, } @@ -442,6 +445,7 @@ impl Assembler { for brush in &self.compiled { state.apply_compiled_box(brush); } + state.report.direct_dirty_rebuild = true; state.into_output_with_mesh(self.brushes.len(), self.generation, None) } @@ -488,6 +492,10 @@ impl Assembler { } else { (BoxBuildState::default(), 0) }; + if start_index > 0 { + state.report.used_checkpoint = true; + state.report.checkpoint_rebuild_from = Some(start_index); + } let mut checkpoints = (start_index == 0).then(|| vec![BoxBuildState::default()]); @@ -544,6 +552,10 @@ impl Assembler { } else { (GeneralBuildState::default(), 0) }; + if start_index > 0 { + state.report.used_checkpoint = true; + state.report.checkpoint_rebuild_from = Some(start_index); + } let mut checkpoints = (start_index == 0).then(|| vec![GeneralBuildState::default()]); @@ -1300,6 +1312,8 @@ mod tests { let incremental = asm.build_incremental(); let full = asm.rebuild(); + assert!(!incremental.report.used_checkpoint); + assert!(incremental.report.direct_dirty_rebuild); assert_eq!(incremental.mesh.positions, full.mesh.positions); assert_eq!(incremental.mesh.indices, full.mesh.indices); assert_eq!( @@ -1385,6 +1399,9 @@ mod tests { assert_eq!(after.mesh, before.mesh); assert!(after.report.reused_mesh); + assert!(after.report.used_checkpoint); + assert_eq!(after.report.checkpoint_rebuild_from, Some(1)); + assert!(!after.report.direct_dirty_rebuild); assert_eq!(after.report.candidate_pairs, 0); assert_eq!(after.report.rejected_pairs, 1); } @@ -1422,6 +1439,9 @@ mod tests { let incremental = asm.build_incremental(); let full = asm.rebuild(); + assert!(incremental.report.used_checkpoint); + assert_eq!(incremental.report.checkpoint_rebuild_from, Some(12)); + assert!(!incremental.report.direct_dirty_rebuild); assert_eq!(incremental.mesh.positions, full.mesh.positions); assert_eq!(incremental.mesh.indices, full.mesh.indices); assert_eq!( diff --git a/docs/research/csg-performance-fixtures.md b/docs/research/csg-performance-fixtures.md index 3a07a1f..cd8fd02 100644 --- a/docs/research/csg-performance-fixtures.md +++ b/docs/research/csg-performance-fixtures.md @@ -134,7 +134,9 @@ Mesh reuse seam: incremental rebuilds now keep the previous generation's cached mesh and reuse it only when suffix replay proves no geometry was touched. This is intentionally exact and conservative: distant rejected edits can skip mesh emission, while candidate cuts still emit the full output mesh. The report -exposes `reused_mesh` so the fixture and tests do not infer reuse from timing. +exposes `reused_mesh`, `used_checkpoint`, `checkpoint_rebuild_from`, and +`direct_dirty_rebuild` so the fixture and tests do not infer rebuild strategy +from timing. Benchmark correction: `rebuild()` must bypass checkpoint caches. An earlier fixture pass accidentally let the dirty box baseline travel through cached box @@ -217,3 +219,10 @@ replay. The checkpoint path still wins hard for general convex tail edits: and `common_box_chain_64` stays far below full dirty rebuild. Rejected general convex suffixes can expose `reused_mesh:true`; the fixture includes `distant_oriented_cutters_128` for that case. + +Planning counters now expose rebuild strategy. Treat `direct_dirty_rebuild:true` +as a sign the incremental planner deliberately bailed to the direct path. +Treat `used_checkpoint:true` and `checkpoint_rebuild_from` as evidence of a live +suffix replay boundary. Treat `reused_mesh:true` as proof that suffix replay did +not touch geometry and reused the previous output mesh. These fields are part of +the benchmark contract because timings alone already lied once. diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 8540d7f..5caeff7 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -128,7 +128,9 @@ reuse the previous mesh when replay proves no geometry was touched. The report flag is `reused_mesh`. `rebuild()` intentionally bypasses checkpoint caches; box dirty edits currently use the direct builder because the honest baseline is faster than checkpoint replay until real mesh patching exists. The -category-router path is still separate. +category-router path is still separate. Perf records also expose +`used_checkpoint`, `checkpoint_rebuild_from`, and `direct_dirty_rebuild` so +future timing comparisons show which path actually ran. ## Important Invariants diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 045b592..d3464e6 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -70,3 +70,4 @@ {"ts": "2026-05-07T14:14:21+00:00", "type": "implementation", "status": "ok", "note": "Extended vg_csg incremental dirty rebuilds from box-only state to the general convex builder. The cache now tracks a valid prefix boundary so tail edits reuse the checkpoint before the dirty brush without deep-copying stale checkpoint history. Latest smoke fixture shows large tail-edit wins, including rotated_cut_stack_64 dirty mean dropping from about 3.49 ms full rebuild to about 0.42 ms incremental, with parity tests still green."} {"ts": "2026-05-07T14:39:10+00:00", "type": "implementation", "status": "ok", "note": "Added conservative mesh reuse for vg_csg incremental dirty rebuilds. Mutations no longer discard the previous BuildOutput; suffix replay tracks whether geometry was touched, and rejected dirty suffixes reuse the prior mesh exactly. BuildReport exposes reused_mesh and tests cover distant tail edits. Candidate edits still emit the whole mesh."} {"ts": "2026-05-07T14:50:34+00:00", "type": "implementation", "status": "ok", "note": "Corrected vg_csg dirty perf semantics: rebuild now bypasses checkpoint caches, while build populates them. The honest fixture showed box candidate edits are faster through the direct box builder than checkpoint replay, so incremental box dirty edits now fall back to direct unless future mesh patching changes that. Added distant_oriented_cutters_128 to exercise conservative reused_mesh on the general convex path."} +{"ts": "2026-05-07T14:55:58+00:00", "type": "implementation", "status": "ok", "note": "Added explicit rebuild-strategy fields to vg_csg BuildReport and perf JSON: used_checkpoint, checkpoint_rebuild_from, and direct_dirty_rebuild. Tests now pin direct box fallback, general convex checkpoint replay, and reused_mesh for rejected general convex edits so future timings cannot hide which path ran."} diff --git a/state/map.yaml b/state/map.yaml index 1d9dac9..4a3519c 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -110,7 +110,7 @@ data_flow: - If state grows faster than understanding, cut it back. current_status: - summary: VibeGeometry has verified Geometry Script translations for local samples, official Blender demos, and IRCSS French Houses footholds, plus from-scratch Aetheria Bloom and Lucent tether habitat builds. Durable lessons now driving the pipeline: Python orchestrates intent and batching; Geometry Script emits inspectable node groups; source-bound scenes need explicit coordinate contracts before ornament; spin-gravity habitats need ground planes orthogonal to their tether/rotation axis; utility petals, radiators, and solar arrays belong outside pressure glass and may need Citadel-scale presence; large habitat parts need visible load paths across coordinate frames; organic city maps need street fields, irregular parcels, parks, and land-use gradients rather than grids; dense detail must be batched; institutional spaces should model power as surfaces, rails, overlays, thresholds, shader behavior, and camera evidence; and visual acceptance needs domain-facing inspection renders plus verifier checks, not only overview renders. The first reusable `vibegeometry/` helper library now carries coordinate frames, fields, batching, Blender scene primitives, and verifier helpers used by the Bloom and Lucent builds. The Rust crate `vg_csg` now has a RealtimeCSG-shaped API skeleton plus a convex-brush stepping-stone kernel: CSG operation ordinals, branch vocabulary, tree/branch/brush handles, child and operation mutation, exact parity fixtures, ordered assembler compilation, AABB/oriented-box subtraction/intersection via convex plane splitting, crossing polygon category buckets, primitive/solid/tree bounds, additive cylinder/dome/floret primitives, JSONL performance fixtures with stable, dirty, and incremental dirty modes, mesh-array output, stable-generation output caching, dirty prefix checkpoints for general convex builders, conservative mesh reuse for rejected dirty suffixes, tests, clippy, and examples. The `vg_grammar` crate is the Dream Machine authoring layer: semantic solid/void claims with tags compile into flat `vg_csg` brushes or generated CSG tree intent; it supports local frames, oriented claims, deterministic seeded variation, rule composition, and generated gallery chains. Public RealtimeCSG demo/source research points the target away from fragment carving and toward faster polygon classification through boolean trees. A standalone RealtimeCSG C++ P/Invoke bridge now mirrors the managed wrapper surface, verifies a native health cube, extracts generated mesh descriptions, and appends direct native timing records. Current perf pass: `vg_csg` has a fast axis-aligned direct path, cached compiled brush geometry, owned convex splitting, convex containment shortcuts, stable-tree output caching, valid-prefix incremental dirty caching for general convex edits, and a `reused_mesh` report flag; box candidate edits use the direct builder after an honest dirty baseline showed checkpoint replay is slower without real mesh patching. Known graph-tooling blockers remain repeat-zone feedback, repeat Top outputs, foreach zones, and gizmo nodes. + summary: VibeGeometry has verified Geometry Script translations for local samples, official Blender demos, and IRCSS French Houses footholds, plus from-scratch Aetheria Bloom and Lucent tether habitat builds. Durable lessons now driving the pipeline: Python orchestrates intent and batching; Geometry Script emits inspectable node groups; source-bound scenes need explicit coordinate contracts before ornament; spin-gravity habitats need ground planes orthogonal to their tether/rotation axis; utility petals, radiators, and solar arrays belong outside pressure glass and may need Citadel-scale presence; large habitat parts need visible load paths across coordinate frames; organic city maps need street fields, irregular parcels, parks, and land-use gradients rather than grids; dense detail must be batched; institutional spaces should model power as surfaces, rails, overlays, thresholds, shader behavior, and camera evidence; and visual acceptance needs domain-facing inspection renders plus verifier checks, not only overview renders. The first reusable `vibegeometry/` helper library now carries coordinate frames, fields, batching, Blender scene primitives, and verifier helpers used by the Bloom and Lucent builds. The Rust crate `vg_csg` now has a RealtimeCSG-shaped API skeleton plus a convex-brush stepping-stone kernel: CSG operation ordinals, branch vocabulary, tree/branch/brush handles, child and operation mutation, exact parity fixtures, ordered assembler compilation, AABB/oriented-box subtraction/intersection via convex plane splitting, crossing polygon category buckets, primitive/solid/tree bounds, additive cylinder/dome/floret primitives, JSONL performance fixtures with stable, dirty, and incremental dirty modes, mesh-array output, stable-generation output caching, dirty prefix checkpoints for general convex builders, conservative mesh reuse for rejected dirty suffixes, explicit rebuild-strategy report fields, tests, clippy, and examples. The `vg_grammar` crate is the Dream Machine authoring layer: semantic solid/void claims with tags compile into flat `vg_csg` brushes or generated CSG tree intent; it supports local frames, oriented claims, deterministic seeded variation, rule composition, and generated gallery chains. Public RealtimeCSG demo/source research points the target away from fragment carving and toward faster polygon classification through boolean trees. A standalone RealtimeCSG C++ P/Invoke bridge now mirrors the managed wrapper surface, verifies a native health cube, extracts generated mesh descriptions, and appends direct native timing records. Current perf pass: `vg_csg` has a fast axis-aligned direct path, cached compiled brush geometry, owned convex splitting, convex containment shortcuts, stable-tree output caching, valid-prefix incremental dirty caching for general convex edits, and report flags for `reused_mesh`, `used_checkpoint`, `checkpoint_rebuild_from`, and `direct_dirty_rebuild`; box candidate edits use the direct builder after an honest dirty baseline showed checkpoint replay is slower without real mesh patching. Known graph-tooling blockers remain repeat-zone feedback, repeat Top outputs, foreach zones, and gizmo nodes. next_action: Build dirty mesh range patching for candidate edits: track emitted mesh spans for checkpointed CSG states, patch only changed ranges when suffix replay touches geometry, then port the valid-prefix checkpoint model into the compact category-router path without relaxing output parity. remotes: vibegeometry: https://github.com/GameCult/VibeGeometry