Skip to content

Update named mesh geometry in a native session (#59) - #61

Merged
anxuanng merged 1 commit into
mainfrom
59-update-mesh-geometry
Nov 16, 2026
Merged

anxuanng merged 1 commit into
mainfrom
59-update-mesh-geometry

Conversation

@anxuanng

Copy link
Copy Markdown
Contributor

Closes #59
Part of codepawl/crucible#1786

What changed

session.update now accepts a new triangles table of any length. Meshes are the instances that share a blas_index; the update keeps the set of meshes and the instance count, compares each mesh's triangle corners with the ones its BLAS was built from, builds a new BLAS for each mesh that differs (from one vertex buffer holding only those), keeps the other BLAS, and rebuilds the TLAS. The pipeline, textures, environment and unchanged BLAS stay. It reports changedMeshes, accelerationRebuilt and the seconds.

  • Buffers: the triangle table is uploaded as a new buffer (no reserve, no out-of-bounds writes); cost is one full triangle-table upload plus 36 bytes a triangle of host memory for the comparison.
  • Refused before anything changes (the session keeps rendering the old scene): another set of blas_index values, an instance range outside the table, a triangleCount word that differs from the table, any instance mesh change without a new table.
  • Files: src/host/accel.rs (mesh plan, plan_geometry_update, update_cycles_geometry), src/host/cycles_session.rs, src/host/cycles_update.rs, src/cycles/mod.rs, src/lib.rs, index.mjs, README.

How I checked it

  • node tools/run-cargo-tests.mjs: test result: ok. 142 passed and ok. 23 passed, 0 failed.
  • node --test: tests 201, pass 201, fail 0.
  • New tests/gpu/session-geometry-update.test.mjs (5 tests): frame N from a session updated from frame N-1 equals a fresh traceNative of frame N byte for byte (rgba and depth), for a mesh that shrinks (86 to 84 triangles, shifting the meshes after it), grows, moves with the same count, and a mesh shared by two instances. Against the pre-change addon the same file fails 4 of 5 (mutation check).

Evidence

Cook-level, RTX 3060, 320x240, 4 samples, six 40,000 triangle meshes plus a 4,000 triangle mesh that changes every frame, 8 frames:

route per frame, setup plus render
new session each frame 54 to 129 ms (median about 80 ms)
update about 33 ms, of which update itself is 16.5 ms

At 56,000 triangles a new session already costs only about 17 ms and update 4.5 ms, so Cook's share of the 0.3 to 0.6 s per frame in crucible#1786 is small; crucible's own export of the whole scene each frame (0.12 to 0.15 s in run-video.mjs) is the larger part and is not changed here. With this Cook build the crucible video route for the particle scene changes from new-session to updated for frames 1 to 5 (updateSeconds 0.004 to 0.007 s).

session.update accepts a new triangles table of any length. Meshes (by blas_index) whose triangle corners changed get a new BLAS built from one vertex buffer that holds only them; the other BLAS are kept and the TLAS is rebuilt. Reports changedMeshes. Refuses a changed set of meshes, a range outside the table and a triangleCount that does not match the table.

Closes #59. Part of codepawl/crucible#1786.
@anxuanng
anxuanng merged commit 9fd3f72 into main Nov 16, 2026
4 of 5 checks passed
@anxuanng
anxuanng deleted the 59-update-mesh-geometry branch November 16, 2026 23:23
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.

Native session: update geometry for a few meshes (particles, skinned meshes) without a new session

1 participant