feat(viewer): type visibility hides ids on the GPU instead of re-uploading (#10264)

Merged
LO
9d ago
+1563-228

Part of #10264: the type-visibility prerequisite before CPU-geometry release (S4). Internal work, so it carries the unqueued label and claims no issue. Product release stays off.

What changes

Type visibility no longer decides which meshes the scene uploads. That covers the class toggles (spaces, spatial zones, openings, virtual elements, site/terrain, annotations), the Model/Types switch and the analytical/physical modes. Every merged mesh is uploaded once, including the IfcSpace and IfcOpeningElement geometry hidden by default. A toggle only changes which entity ids the viewport hides, through the S2 GPU hide table. Nothing is re-uploaded from the store's CPU arrays.

  • type-hidden-index.ts. For each (geometry class, IFC class) pair, it keeps the global ids of the entities whose meshes carry that pair. Ids are appended per streamed batch, read once from expressId, ifcType, geometryClass and the distinct entityIds; no mesh arrays are kept. A toggle rebuilds the id set; a batch that hides more ids produces a new set (copy-on-write). The verdict is the per-mesh rule the old upload filter applied, evaluated per entity.

  • useFilteredGeometry returns every mesh (sceneGeometry), the existing replacement detection, and typeHidden. The CPU filter and the toggle-driven rebuild are removed.

  • useVisibilityState(typeHidden) folds the type-hidden ids into the derived set the viewport draws, picks, frames and highlights by. This happens in a separate memo, so a batch's new ids don't re-run the structural mask over every entity. The store's hiddenEntities is never written.

  • Cached reopen. A scene snapshot holds every mesh, and adoption paints before the meshes decode. The snapshot now stores the index's buckets (typeIndex in its host data: classes and ids, no geometry). Adoption then:

    • installs the stored index (snapshot-type-index.ts);
    • waits until the viewport has committed the ids it hides under the toggles current at reopen (not at capture), and only then adopts and paints;
    • stops using the stored index once the meshes are published or the load ends. A newer load supersedes an older one.

    A snapshot without a type index is not adopted, and the hit streams instead. The snapshot key drops the type filter.

  • Framing. The camera-fit accumulator folds every mesh:

    • full (clipping and section range) covers every mesh, shown or not;
    • fit and robust (framing) apply the exclusions current at each call, so a class shown mid-stream frames again.

    Frame building extent and the renderable-bounds lookup behind resolveHighlightIds treat type-hidden meshes as absent. Cesium gets the mesh list without them.

  • Point clouds. A type toggle over models without point clouds keeps the previous empty point-cloud list. Before, it re-synced an empty list, which recomputed model bounds and refit the shadows.

Not changed: release, readback and S4 (all still off); the S2 and S3 paths; coldGeometryProvider.

Validation at 4e1f9b8c7b (main merged, 2026-11-20)

  • Queue head 9558b27781 = 68f2b07480 + main at 2d54af0de6 (#11038). Full viewer suite as above; all six required checks pass on 9558b27781. Entry JS with #10880 also merged measures 2,005,258 bytes, within the 2,012,040 ceiling #11042 set (#11066, opened for this, was closed as superseded).
  • Merge-queue batch #11036 (18:38): three visibility-scenarios.e2e.spec.ts tests failed because they asserted that type-hidden entities have no scene owner, while this PR keeps them in the scene and hides them on the GPU. 68f2b07480 asserts "not drawn" instead (renderer visibility); the old spec fails and the new one passes all three locally. Test-only change; the full viewer suite above still applies. The same batch's Viewer E2E smoke (2/8) was killed at its 13-minute cap with 27 tests passed; passing batches today took 9 to 13 minutes on that shard.
  • full viewer suite: 4 shards, 25,064 tests, 0 failed, on 4e1f9b8c7b. Shards 0-2 are from fleet job baa5bb5f. Shard 3 failed there once, in useSymbolicAnnotations.afterLoad.test.tsx:196, a pre-existing load-timing flake this PR does not touch (root cause and fix: #11002). Shard 3 was then rerun on the same head (fleet job auto-bed73e1a): 6,733 tests, 0 failed.
  • Perf ratchet: all metrics within their ceilings on the main merge, after #10852 raised the eager-JS ceiling, so the 6,082-byte overage below is resolved.
  • #10865 merged as aad7a26. Its three files here are byte-identical, so they drop out of this diff on merge.

Evidence at head d50f0de1f7 (merge-base 9e47ef2960)

Real GPU (Pop, NVIDIA lovelace, headed Chromium on a private Xvfb with Vulkan ANGLE, ifc-gpu-check, untimed). All four #10264 specs ran on this head: 24 passed, 2 skipped (the Holter tower fixture is absent), 1 failed: S2 storey-isolation. That failure is the #10853 overlay race: grid and dimension overlays arrive between the A and B captures. With #10861's overlay setting applied temporarily (not committed), the same test passes on this head.

Scenario (gpu-type-visibility)Type-hidden flatBatches and vertex buffers keptShown vs hidden (strong px)Hidden again vs first frameAgainst the visible pieces alone, hide table cleared
C20-Institute, shadows on369yes (45)2,4960 px0 strong / 0 differing
Institute + duplex federation440 (71 in model 2)yes (82)2,9850 px0 / 0
Test-only releaseGeometryData(), classes never shown before369yes2,4960 pxshown frame vs a scene with its CPU copy: 0 / 0
Model/Types switch784 hidden in Typesyes (45)55,6180 px—
Cached reopen: spaces shown at capture, hidden at reopen369—first adopted frame vs capture-time view: 2,036—probed at adoptSceneSnapshot, 0 meshes published: 0 of 369 missing from the hidden set; first frame vs settled frame 0 / 0

In every test, no type-hidden entity was picked, by GPU or CPU raycast.

Unit and behaviour tests

  • type-hidden-index.test.ts (new): across 768 combinations of toggles and modes, the hidden ids equal what the old per-mesh filter dropped. Also covers retypes, copy-on-write streaming, the snapshot metadata round trip, malformed metadata, and the install fences (superseded load, foreign clear, no viewport).
  • sceneSnapshotLoad.typeIndex.test.tsx (new, real Scene): cold stream, capture, stored entry, then adoption with the decode held back. The first paint request already hides what the toggles hide at reopen, for capture/reopen pairs hidden/hidden, shown/hidden and hidden/shown. A toggle inside the window applies; abandoning the load clears it. No metadata, or no viewport, means no adoption.
  • robustFitBoundsAccumulator.excluded.test.ts (new): a hidden 900 m cutter shown mid-stream frames again, full always covers it, and each incremental result equals a full rescan.
  • useGeometryStreaming.meshlessModel.test.tsx (real Scene): a toggle creates no GPU buffer, makes no appendToBatches call and makes no clearFlatGeometryForRebuild call, before and after releaseGeometryData().

Gates

  • Full 4-shard viewer suite at d50f0de1f7 (Pop job 25aa9998, request auto-89abe3ed, IFCLITE_TEST_CHROME_EXECUTABLE set): all four shards exit 0.
    • shard 0: tests 6395, pass 6283, skipped 112
    • shard 1: tests 6402, pass 6295, skipped 107
    • shard 2: tests 5446, pass 5333, skipped 113
    • shard 3: tests 6694, pass 6664, skipped 30
    • total: 24,937 tests, 24,575 passed, 0 failed, 0 cancelled, 362 skipped (fixtures were not fetched on the worker).
  • Earlier head 173f18143d (request auto-f3bbaf42): 24,906 tests, 24,544 passed, 0 failed, 362 skipped.
  • node scripts/pre-handoff.mjs --base 9e47ef2960: all 16 gates pass, including retained-free viewer (1,687 files) and the revert oracle (the change is observed: 37 failures with it reverted). New modules have surgical mutation witnesses, all OBSERVED and restored green: the type-hidden-index.ts view-mode verdict, its incremental add, and the snapshot-type-index.ts stale-load fence.
  • Root pnpm typecheck at d50f0de1f7: exit 0. Pop job bc90c753, request auto-2449fbdf; 24 GiB, 8 GiB heap, Turbo concurrency 1, with the root tail: 148/148 tasks, and all 5,359 test files are in a typecheck program. Two earlier PC requests (auto-03f5e3db, and the bundle A/B auto-e34f0717) ended at launch with ValueError and never ran: the prepared PC checkout was not at this head. Their records are kept unchanged.

Dependencies and limitations

  • Perf ratchet (viewer-eager-js-bytes). CI measures this head's merge commit a4c9899 at 13,473,318 bytes. Today's allowed value is 13,467,236, so it is 6,082 over. #10852 (maintainer-owned, open) sets the ceiling to main's 13,465,340, which allows 13,478,805; this head would pass with 5,487 bytes to spare. No ceiling is changed here. The only writer-only code in the eager bundle is TypeHiddenIndex.metadataOf, a few hundred bytes. The base-vs-head bundle A/B (request auto-e34f0717) never ran (see above), so the split between this change and main's growth is not measured.
  • 2306278404 belongs to #10865 (validated, queued). It shows in this diff until #10865 merges, after which main will be merged in so it drops out naturally.
  • S2 storey-isolation depends on #10861 for overlay-race stability, as shown above.
  • Cost (not measured): a batch that hides more ids builds a new set, O(hidden). The renderer compares and re-sorts its hidden table per change and compares its contents each frame, as for any hide. Spaces and openings keep the set small; the Types view and the structural modes hide most entities.
  • Other limitations:
    • spaces and openings now take GPU memory from the first load;
    • section slider bounds include type-hidden geometry;
    • follow-up (review r4640413144, deferred under the review-round cap): a model with no far outlier tail fits its first camera to the raw shiftedBounds, so types hidden at load can widen that framing. Fix: when exclusions are active and rbEarly.fit is set, fit to it before the shiftedBounds path. Same class (r4646867585): a model whose only meshes are default-hidden spaces frames those hidden meshes at streaming completion; with nothing visible it should keep the default camera;
    • the #10653 caveat still applies to secondary vertex-lane ids;
    • the embed viewer keeps its own filter;
    • inline point clouds are still filtered by class.
  • Test gaps: the structural modes are covered by unit tests only (no public fixture with analytical members). Grid and annotation meshes are not exercised as type-hidden on the GPU.

šŸ¤– Generated with Claude Code