fix(renderer): a scene-snapshot capture keeps the cold finalize's GPU assembly (stacked on #9684)

Closed
LO
15d ago
+1115-136

Stacked on #9684. Until #9684 merges, this diff includes its commits. Review only the top two commits (a13f096046, e5dc367866).

Problem

In #9684, createBatchedMesh uses the streamed-bucket GPU assembly only when no scene-snapshot capture is armed (!onMerged). The capture needs each final batch's bytes, and only the CPU rebuild produced them. #9728 arms the capture on every primary cold load, so it can store the first-reopen snapshot. On main + #9684 + #9728, every cold bucket would therefore go back through the full merge, quantize and upload, which loses #9684's cold gain (Holter browser-cold 6,029 → 5,622 ms, timed). #9728's timed A/B ran against main without #9684, so it could not show this.

Change

  • While a capture is armed, each streamed fragment keeps the vertex bytes it uploaded: StreamAssembly.keepBytes stores them and record takes them.
  • assemble() passes the capture's sink:
    • the runs' kept bytes, concatenated in GPU-copy order;
    • the rebased indices and the LOD1 indices it already builds.
  • The sink is bound to the same batch id that assemble() publishes, which build() checks at the swap.
  • A run with no kept bytes (a fragment drawn before the capture was armed) rebuilds its bucket, counted as render.finalize.rebuilt.capture.
  • Memory: the bytes are kept only while a capture is armed. They are the quantized record size (12 B/vertex) and are dropped at the swap, by clear() and by device recovery.
  • scene.ts stays at its 4,065-line budget.

Evidence

  • New test, scene-finalize-work.test.ts, "a scene snapshot capture … still assembles, and stores exactly the bytes the GPU draws":
    • every streamed bucket is assembled while capturing, with 0 vertex bytes written by the finalize;
    • the snapshot has one batch per drawn batch;
    • each batch's vertex, index and LOD1 bytes equal the GPU buffer contents;
    • the final batches are identical to a forced full rebuild (assertSameBatches).
  • Fails on #9684's head e8a832fcd8 (throwaway worktree, 4 GiB cap): "every streamed bucket is assembled while capturing". It passes here.
  • The finalize-work tests' rebuild reference now forces the rebuild directly instead of arming a capture.
  • The lifecycle test stub now tracks buffer contents through GPU copies (separate commit, neutral on the old code).
  • Snapshot, lifecycle and finalize-work tests: 25/25. tsc --noEmit for the renderer is clean. The module-size check passes.

šŸ¤– Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Streamed scene batches can now be assembled from previously uploaded geometry, reducing the need to rebuild unchanged content during finalization.
    • Scene snapshots retain the geometry bytes needed to capture batches assembled from streamed fragments.
  • Bug Fixes
    • Unchanged streamed buckets are preserved during regrouping, while buckets that cannot be safely reused follow the full rebuild path.
    • Topology checks can be reused through stream finalization, with edits that affect geometry invalidating the relevant results.