Mesh-output determinism¶
The pipeline-level determinism contract for emitted geometry, enforced by a
pinned manifest. It complements the kernel's predicate sign manifest
(rust/geometry/src/kernel/manifest.rs), which pins exact-predicate SIGNS;
this contract pins the actual bytes the pipeline emits.
Native process (and its process_geometry convenience wrapper) and default
browser batches share produce_element_meshes_owned in
rust/processing/src/element/owned_session.rs and the execution.rs boundaries.
The manifest below does not qualify every scheduler, JS encoding, stream or
shard path. The C4-0 native/batch comparison has 22 narrow payload-bound
exceptions in rust/wasm-bindings/src/api/gpu_meshes/batch_parity_expected.json,
not universal byte equality. Retained bundles remain separately qualified.
What is byte-stable¶
Running process_geometry over the synthetic fixture in
ifc_lite_processing::determinism produces, bit-for-bit:
- Per mesh, in emit order:
express_id,geometry_class, position f32 bits, normal f32 bits, triangle indices, and the per-element f64origin. These are hashed into THREE separate per-mesh fields so the cross-target guard can hold each to a different standard:positions_hash(positions) andindices_origin_hash(identity + topology + placement) are byte-identical on every target for every mesh, with no exemption;normals_hashis the only surface allowed the documented trig gap, and only for the curved mesh. This is what makes the "positions are byte-identical cross-target, even for the round column" claim below a test-enforced invariant rather than prose. Emit order itself is part of the contract: entity jobs are processed in file scan order and rayon's ordered collect preserves it, so the mesh list is identical regardless of thread count (verified withRAYON_NUM_THREADS=1). - The three flat prepass wire arrays, which are an EXPLICIT sorted contract since this change (previously an implicit FxHashMap-iteration artifact):
flat_voids(keys, counts, values)sorted by host id, u32 ascending (rust/processing/src/prepass_wire.rs, re-exported fromprepass);flat_material_colors(ids, counts, rgba8)sorted by element id, u32 ascending. Per-host opening lists and per-element colour lists keep their file order.flat_styles_rgba8(ids, rgba8)sorted by id, u32 ascending (ids span geometry, material and element ids across the layered style precedence). Each array carries its own hash and entry count in the manifest (voids_hash,material_colors_hash,styles_hash), so a drift report names the wire surface that diverged.
The mesh_check edge keys (rust/geometry/src/mesh_check) are exact or grid-quantised and
order-independent: a closure verdict does not depend on triangle order or hash iteration order.
The fingerprint (FNV-1a 64, same scheme as the kernel manifest) is pinned in
rust/processing/tests/manifests/mesh_determinism.json together with mesh,
vertex and triangle counts and per-mesh hashes, so a failure identifies WHICH
mesh diverged.
Frozen void-cut order¶
The void-cut stage chain (rust/geometry/src/router/voids/, described in
geometry-pipeline.md) is part of this
contract. Several of its steps do not commute: the first whole-host strategy
to accept decides the host's geometry, the coaxial union changes which
openings the disjoint batch plans, and on an open host the malformed recut and
the flap clip give different meshes in either order. So the order is owned in
exactly one place per stage, and nowhere else:
- stage A: the
strategy::HOST_STAGESarray; - stage B: the statement order of
Execution::cut_in_frame; - stage C: the statement order of
ExactTail::run; - stage D: the statement order of
post::finish.
Reordering, inserting or removing a step there is a geometry and diagnostics
change, never a refactor: it needs output evidence and, if bytes move, the
re-pin below. voids/stage_order_tests.rs turns red when a guarded pair is
swapped or a guarded step is dropped. The same holds for diagnostics order:
each stage records its effects on the owned Execution in this order, a frame
retry discards its own records when rejected, and a terminal stop (an engulfed
host) skips every later opening while the post passes still record the empty
cut.
Extending the chain follows the same rule. A new strategy is one variant or
one call in the place that owns its stage's order, plus one file under
voids/strategy/, plus a stage-order guard in stage_order_tests.rs whose
fixture tells it apart from its neighbours. If any pinned output moves, it
also comes with the re-pin below.
At what settings¶
TessellationQuality::Medium-- the byte-identity density (seerust/geometry/src/tessellation.rs).- Local-frame vertex storage ON. This is the one flag whose DEFAULT differs
per target (
local_frame_enabled()inrust/geometry/src/router/transforms/mod.rs: ON for wasm32, the shipping viewer path; OFF for native unlessIFC_LITE_LOCAL_FRAME=1). The manifest harness equalizes it by forcing the flag ON on every target viaifc_lite_geometry::local_frame_set_enabled_override(Some(true)), so the pinned bytes are the local-frame output (per-element f64origin+ element-local f32 positions). Native default output (absolute f32 coords) is a different, internally deterministic encoding of the same geometry and is NOT what the manifest pins. OpeningFilterMode::Default, default streaming options, no env overrides (IFC_LITE_RECT_FAST,IFC_LITE_DISABLE_DEGENERATE_BACKSTOPetc. unset).
Across which targets¶
- x86_64 native == arm64 native: both assert the SAME manifest file
(
mesh_determinism.json). The arm64 leg runs in.github/workflows/determinism.yml. - wasm32: asserts its own pinned manifest
(
mesh_determinism.wasm32.json), which is byte-identical to the native one EXCEPT the documented trig gap below. A native-side guard test (wasm_manifest_differs_only_in_the_trig_gap) pins that the two files never drift apart beyond that gap, and fails loudly (with unification instructions) if the gap ever closes.
Both legs call the same compute_mesh_manifest() in
rust/processing/src/determinism.rs, so fixture and hashing cannot drift
between targets.
ifc_lite_geometry::math::{v3, mat4} is FMA-free with a pinned operation order (a0*b0 + a1*b1 + a2*b2, left to right; the 4x4 product accumulates from 0.0). Kernel and processing callers rely on that for the pinned manifests, so do not introduce mul_add there.
Known gap: libm trig ULP (wasm32 vs native)¶
Circle tessellation computes profile points with sin/cos. Platform libms
disagree by ~1 ULP on some inputs; f32 rounding absorbs that in positions
(they ARE byte-identical), but the smooth radial side normals of
circular-ish extrusions (extrude_profile in
rust/geometry/src/extrusion.rs) are derived from the f64 profile points, so
near-zero normal components (true value ~0, e.g. sin at the angle pi) keep
the full residue: measured -7.0e-17 native vs -2.1e-17 wasm32 on the fixture
column. Closing this requires deterministic trig (e.g. the pure-Rust libm
crate) in the profile tessellation path -- a separate work item. Until then
the round column's normals_hash is the ONLY divergence between the two pinned
manifests: its positions_hash and indices_origin_hash match native ==
wasm32 (empirically confirmed and asserted per-field by the guard), so a future
change that diverged the curved mesh's POSITIONS across targets would fail the
guard instead of hiding inside a combined per-mesh hash.
What was fixed to get here¶
consolidate_coplanar (rust/geometry/src/csg/consolidate.rs) grouped cut
triangles into plane buckets keyed in an FxHashMap and emitted the output
mesh in bucket iteration order. FxHasher mixes usize-wide chunks, so its
iteration order differs between 64-bit native and 32-bit wasm32: the same
CSG cut emitted the same triangles in a different order per target. The
buckets are now a BTreeMap (Ord-keyed, target-independent iteration; same
pattern as facet_weld's normal buckets), which made every CSG-cut mesh in
the battery byte-identical native == wasm32.
What is NOT covered¶
- Other tessellation tiers (Lowest/Low/High/Highest) are internally deterministic but not cross-tier comparable, and are not pinned.
- Native default (local-frame OFF) output is not pinned; it shares all the same code except the frame subtraction.
- The kernel predicate sign manifest is a separate, existing guarantee; this contract does not replace it and the battery here does not exercise every kernel path (it covers rect-fast cuts; kernel-cut coverage rides the geometry crate's snapshot suite).
- Wire arrays other than voids/material-colors/styles (job lists, entity index payloads) are diagnostics/routing, not geometry, and are not pinned.
Re-pinning¶
An intended geometry change re-pins both files: run
cargo test -p ifc-lite-processing --test mesh_determinism -- --nocapture,
copy the printed actual JSON into mesh_determinism.json, then run
wasm-pack test --node rust/wasm-bindings --test mesh_determinism and copy
its printed actual JSON into mesh_determinism.wasm32.json. The
wasm_manifest_differs_only_in_the_trig_gap guard verifies the pair stays
in lockstep.