Skip to content

Units: in-place edits under software traversal (a two-level tree); hello world in Chrome 0.84 ms a frame a body moves (was 16.7) - #21

Merged
yujiaxu-ops merged 16 commits into
mainfrom
sw-two-level
Nov 11, 2026
Merged

yujiaxu-ops merged 16 commits into
mainfrom
sw-two-level

Conversation

@yujiaxu-ops

@yujiaxu-ops yujiaxu-ops commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

What

Software traversal edits in place. ROADMAP § 6 step 7b, design A of the note agreed before it: the still scene stays the one flat tree it was; a model instance stays an instance, a unit, with its mesh's tree in model space, found through a top tree walked after the still one. A browser has no ray queries, so this is the browser's path; natively it is THREERT_HWRT=0.

  • renderer/src/units.rs: mesh trees (relocatable: child indices count from the root), the top tree (median splits, rebuilt whole when a unit is added, moved or removed, as the TLAS is), where they sit in the node buffer, and the checks made on the CPU wherever a tree is written.
  • renderer/shaders/trace_units.wgsl: the unit walk, spliced into software traversal by a source feature (F_UNITS) for scenes that have units. pathtrace.wgsl is not edited. No new binding: the merged layout still has 8 storage buffers; the top tree's root and the unit count travel in two free words of the frame's parameters, a unit's tree root and shadow flag in two free words of the instance record.
  • gpu::Top (the TLAS or the units): move_instances, update_instanced and edit_geometry are one path under both traversals. In place now under software traversal: a unit moves; an instance of a known mesh is added or removed; a new mesh is added; a mesh changes (a voxel edit); a mesh is removed.
  • Where units are used: a live session and a browser (the wasm build), by default. An offline render (threert-render render) under software traversal flattens every instance as before this PR, kernel and bytes main's, with nothing set. THREERT_UNITS=1 gives an offline render units; THREERT_UNITS=0 flattens a session too (the A/B).
  • A native kernel with units has the loop guard with nothing set (65,536; THREERT_LOOP_GUARD=0 takes it out). A native kernel without units has none by default, as before: no existing byte changes. A stop does what it did: an offline render fails, a session logs it (guard in the frame log), test-render fails the run.

What it costs (the next item's work, "Open" 1)

Software traversal, live, 1280 × 720 traced at half, Apple M5 Pro, the loop guard on in both columns:

scene the trace, units / flat frame GPU, units / flat 60 Hz (16.7 ms)
hello world (natively) 1.40–1.42 / 1.01–1.04 ms: +37 % in Chrome 6.59 / 6.60 ms (its trace 2.55 / 2.08) held by both
the voxel level (10,459 units) 7.85 / 4.58 ms: +71 % 11.2 / 7.9 ms held by both
Kabukichō (352 units) 13.88 / 12.01 ms: +16 % 17.18 / 15.35 ms missed with units (a frame every 17.2–17.5 ms; flat 16.65)
  • Against what main's session runs on Kabukichō under software traversal with nothing set (flat, no guard: 14.11 ms of GPU a frame), the default now (units, the guard) is 3.1 ms a frame more, 1.2 of it the guard as measured on the flat kernel.
  • Nothing of the unit walk is tuned: a median-split top tree, every unit's ray transformed, every ray enters the top tree.
  • Offline renders pay nothing: they are flat, and main's bytes.

What it buys

  • In Chrome a frame in which a body moves costs the page 0.84 ms, was 16.7, and none rebuilds the scene.
  • The voxel level's triangle data is 311 MiB, was 2,098; an explosion 2.5–4.5 ms in place, was 6.9–7.9 s.

Not run (outside the GPU runs agreed for this step; each is asked for before it is made)

  • A kernel with units without the loop guard, anywhere.
  • A catalog scene with units, offline (THREERT_UNITS=1) or live, except Kabukichō: instancing (1,000 units), khronos-*, zero-day, zero-day-animated (3,991 overlapping units), Bistro.
  • V4: explosions on the voxel level until the edit room is full.
  • V5: a pile of debris (overlap where it is worst).
  • Anything but hello world in a browser.

For the other line

  • Hardware traversal (your default): nothing changed. The kernel's and the live passes' sources are main's (the_default_sources_are_untouched: SHA-256 for both traversals and every combination of source features); prepare takes no new branch under it; its layouts and buffers are as they were.
  • Offline renders under software traversal: nothing changed either. Instances are flattened as before, the kernel is main's, the catalog's 23 bundles are byte-identical to main with nothing set about units.
  • Live sessions under software traversal (THREERT_HWRT=0, or a browser): a scene with model instances now keeps them as units, its kernel gets one extra call (trace_units) after the still walk, and natively that kernel has the loop guard. Kabukichō live: frame GPU 17.2 ms where main's is 14.1 (trace +16 % for units, +11 % for the guard), triangle data 55 MiB instead of 634, first frame 1.55 s instead of 3.3. THREERT_UNITS=0 is main's kernel; THREERT_LOOP_GUARD=0 takes the guard out.
  • Yours, found here, not fixed here (ROADMAP "Known issues"): under software traversal 23 of the 170 atomic tests fail on main's build (the list below); under hardware traversal the offline renders of Bistro's three bundles and Zero Day's two are not the same bytes twice.

Measured (Apple M5 Pro; natively THREERT_HWRT=0 with THREERT_LOOP_GUARD=65536; "flat" = THREERT_UNITS=0; live views 1280 × 720 traced at half; other applications held part of the GPU; made while an offline render had units by default too)

Hello world in Chrome 157 (tools/web-hello.ts --frames), ms p50 / p95:

units before (flat)
a frame in which a body moves: the page's time 0.84 / 1.07 16.73 / 17.99
of it the commit 0.08 / 0.10 16.49 / 17.68 (the rebuild)
frames that rebuilt the scene 0 of 1,173 295 of about 1,180
a click that adds a box: commit first 31.6 (one rebuild, into the kernel with units), then 0.79, 0.73, 0.64 18.5–24.1
the trace, still / a body moves 2.55 / 2.66 2.08 / 1.72
frame GPU, still / a body moves 6.59 / 6.73 6.60 / 6.15

The scripted test passes at 640 × 360 and 1280 × 720, report and clicks the native run's number for number; it now checks that no frame rebuilds the scene and only the first box's click does.

Hello world natively: tools/physics-hello.ts passes under software traversal, the two checks that failed there among them (commits rebuild, in place × 4). A frame in which a body moves: commit 0.02 ms (flat 8.65); a click's commit 0.25–0.35 ms (9.1–9.6). The trace 1.40–1.42 ms against 1.01–1.04.

The voxel level (10,459 units of 6,410 meshes; flattened 13.2 M triangles):

units flat
triangle data 310.9 MiB 2,098.2 MiB
trees built at load 333 ms 5,378 ms
first frame after 5.2 s 11.6 s
an explosion (0.5–4 m) 2.5–4.5 ms, in place 6.9–7.9 s (the scene rebuilt)
still frame: the trace 7.85 ms 4.58 ms
still frame: GPU 11.2 ms 7.9 ms

Kabukichō (352 units of 19 meshes):

units flat
live, guard on: frame GPU / the trace 17.18 / 13.88 ms 15.35 / 12.01 ms
offline 64 spp: the trace (units: now THREERT_UNITS=1) 394.8 ms 336.2 ms
triangle data 55.0 MiB 634.1 MiB
first frame, second launch 1.55 s 3.3 s

The guard and the merged layout on Kabukichō (flat, main's kernel; frame GPU / the trace): as written 14.11 / 10.78; merged 14.29 / 10.91; with the guard 15.35 / 12.01; merged with the guard 15.66 / 12.28. The guard: +1.23 ms of trace (11 %). The merged layout: +0.13 ms.

The atomic tests under software traversal (the first whole run on this machine; a family a command, guard on; made while offline tests had units too): 147 of 170 pass, as written and merged alike. The 23 that fail fail on main's build too, with the same values:

  • particles, which software traversal does not draw (docs/MATERIAL_FUNCTIONS.md: they need ray queries), 20 tests: particles/count-zero, particles/emissive-spark, particles/emissive-spark-nominal, particles/emissive-unsampled, particles/follow-emitter, particles/hidden-in-place-live, particles/instance-data, particles/lit-normal, particles/lit-orientation, particles/motion-repose, particles/node-custom, particles/quad-placement, particles/shown-in-place-live; gpu-particles/beside-particles, gpu-particles/plane, gpu-particles/voxels, gpu-particles/voxels-live, gpu-particles/voxels-side; translucent/depth, translucent/order.
  • volume/lighting, volume/lighting-offline (6 for 1). Main's, on this basis: both measure one translucent particle in a closed cube with one 6-nit wall behind it (their features are particles, translucency); without the particle the region is the wall. (This PR's text before called these two unexplained by a missing feature; that was wrong: they are the same missing particles.)
  • surface/windows (0.3934 for 0.4234). Main's, on this basis: the scene is one plane with the library's facade windows and no instance, so nothing of this PR is in its kernel (the source is main's byte for byte), and main's build reads the same 0.3934 in both layouts. Its cause was not looked for.

The last three are in ROADMAP "Known issues" now, as the other line's.

Full tables: docs/RUNTIME.md "Software traversal with units", "Measured".

What the GPU runs found (both fixed, each with a CPU test)

  • A scene of units alone drew a mesh's first triangle at the origin. The still tree over no triangle is a leaf of triangle 0, which with units is a mesh's first, in model space. Found on the first GPU run (the picture was darker towards the origin; the CPU tests' scenes all had a ground). The leaf now gets a triangle of its own, without area.
  • A mesh written again in place kept its units' old boxes. voxel/cut-falls-live: a falling part was cut off at the box it had before it fell. Found by the atomic suite. A unit's box is now its mesh's tree's bounds, read when the top tree is built.
  • Also fixed: a scene of still models had no room for a second copy (software traversal's room does not grow); under the merged layout an emitter added in place died in wgpu validation (the grown buffer lost a usage flag).
  • tools/test-render.ts now fails a run in which the loop guard stopped a live test's frames (it only printed it).
  • Seen, not changed: the in-place rewrite of a mesh with the same triangle count leaves meshes[k].lo/hi stale, under both traversals (object entry size, pick bounds). It is main's behaviour; changing it changes hardware traversal.

Why the loops end

Every index the walk reads is checked on the CPU where it is written: a child index is greater than its parent's and inside its tree's range, a leaf's triangles inside its mesh's and at most 16, a top leaf's record a unit's. A tree that fails is not uploaded; the scene is rebuilt. Room not yet used holds leaves that end, not zeros. The stack is 64 entries (18 for the top tree: 2^18 units; 46 for a mesh's; a deeper SAH tree is rebuilt by median splits). The CPU tests transcribe the two walks from the shaders line for line and run random scenes under random edits against brute force. In every GPU run the guard stopped nothing.

Tier: R1

The renderer's library changed; hardware traversal, every offline render and every scene without instances are unchanged. No existing shader file changed.

Merge gate (run again on the defaults as they are now; perf smoke and the hardware catalog not run again, as agreed)

  • Current with main: head f45708e, main a707e1c, behind_by 0.

  • npm run typecheck: pass. npm test: 127 / 127.

  • CPU: the sources handed to wgpu with nothing set are main's hashes (the_default_sources_are_untouched); an offline render of a scene with instances has no unit, no F_UNITS, and the flattened scene's triangle and node bytes (an_offline_render_has_no_units_unless_told); a kernel with units has the guard at 65,536 with nothing set, none at THREERT_LOOP_GUARD=0, and naga validates it (a_kernel_with_units_has_the_loop_guard).

  • cargo test --release (renderer): 78 passed, 2 ignored, the five that open the GPU among them.

  • Byte identity against main a707e1c, software traversal, THREERT_UNITS not set (offline, 320 × 180, 4 spp, HDR and PNG): 23 / 23. Both builds ran with THREERT_LOOP_GUARD=65536, as every GPU run of this step; that the kernel without the guard is main's too is the hashes' test, not a render.

  • Hello world natively with nothing set but THREERT_HWRT=0 (tools/physics-hello.ts: units and the guard by default): every check; commits rebuild, in place × 4; 812 of 823 frames' kernel has the guard (the eleven before the first box have a kernel without units), guard count 0.

  • test:render (hardware traversal): 170 / 170. One value moved: volume/lighting 1.006 (was 1.019, alone again 1.015; a live test with the radiance cache, passing at each).

  • Chrome, the scripted test once: every check; guard count 0 in 826 frames; no frame rebuilt the scene; the report the native run's number for number.

  • Hardware traversal's catalog, from the head before (0eaf44a; hardware traversal is untouched since): 18 / 23. bistro, bistro-slice, bistro-district, zero-day, zero-day-animated differ from main in 1,884 / 133 / 80 / 9,507 / 8,850 of 57,600 pixels; main against main on the same five: 1,782 / 1,095 / 125 / 7,988 / 10,426. The same order of magnitude: these five do not repeat on one build under hardware traversal (ROADMAP "Known issues": the new entry with these figures, and hardware traversal's ties between coincident surfaces).

  • Perf smoke, from the head before: the tool's verdict was FAIL, three times; read as this machine's spread with both builds alternating (A = main, B = branch):

    order build still moving drive GPU p50 / p95
    1 branch 10.46 7.76 7.80 / 8.18
    2 main 7.84 7.68 7.96 / 10.77
    3 main 8.28 7.77 11.03 / 11.92
    4 branch 8.00 7.80 9.32 / 10.41
    5 branch 7.82 8.26 7.79 / 8.15
    6 main 7.82 9.21 7.86 / 8.29

    Every figure sits at one of two levels, about 7.8 and 9–11 ms, on both builds. Why the machine has two levels I have not established.

  • GPU runs: one process under a lock, smallest first, with the loop guard, nothing killed, nothing retried; all returned; the one batch (byteid.ts) was first shown to stop at a render that must fail (the guard at 16). The list and each result: out/web-probe/gpu-runs-b.md (beside the checkout). One slip: after the last doc change I ran the library's tests with a filter that matched nothing, so the five tests that open the GPU ran outside the lock script (78 passed in 3.5 s; nothing left behind).

Open

  1. The still frame's cost (the table at the top): an SAH top tree, and units whose transform is the identity walked without transforming the ray, are the first things to try. Until then a session that only stands still is cheaper flattened (THREERT_UNITS=0), at its memory and load time.
  2. The runs not made (the list at the top).
  3. The edit room and the tree ranges do not grow under software traversal: an edit that finds them full rebuilds the scene (seen: 1,100 instances into room for 1,024).
  4. Still a rebuild under software traversal: procedural objects, posed models, rigid groups' poses; a scene with more than 2^18 instances is flattened.
  5. Whether all of native software traversal has the loop guard by default (not this PR's); what hung on 2026-11-11 is still not confirmed.

🤖 Generated with Claude Code

yujiaxu-ops and others added 16 commits November 11, 2026 12:45
…versal (units, a top tree after the still scene's)

Co-Authored-By: Claude <noreply@anthropic.com>
…lk (trace_units.wgsl) and its transcription against brute force

renderer/src/units.rs: a mesh's tree (SAH as the still scene's, median splits when deeper than the stack
allows), the top tree (median splits, one unit a leaf), the checks a tree passes before it is written (children
after their parent and inside the tree, every node reached once, leaves inside their mesh, depth), where trees
go in the node buffer (first fit, runs joined when trees go). Room holds leaves that end.
renderer/shaders/trace_units.wgsl: the walk (not yet spliced into any kernel).
Tests, no GPU: the walk transcribed statement for statement (with a check that the statements are still the
shader's), every read bounds-checked and every iteration counted, over 12 random scenes under 568 random edits
(meshes and units added, moved, removed, overlapping, emptied): the closest hit is brute force's to the bit, any-hit
walks find something exactly when there is something; broken trees are refused.

Co-Authored-By: Claude <noreply@anthropic.com>
…raversal; the kernel's source gets the unit walk by a source feature (WIP: edits in place not wired yet; nothing run on a GPU)

prepare (software traversal): a tree for each instanced mesh that keeps its shape, its pool triangles in the tree's
order with their cutout flag, the trees and the top tree after the still tree's nodes with room (FILL), each
unit's record with its tree's root and shadow flag; meshes that deform are still flattened; THREERT_UNITS=0
flattens everything as before. gpu.rs: F_UNITS (kernel_source splices shaders/trace_units.wgsl into the software
traversal and calls it after the still scene's walk; pathtrace.wgsl is not edited), Uploaded::units, Top (the TLAS
or the units, for edits), retop, write_tree. Tests (CPU, naga): the splice is inside the software traversal only and
comes out again leaving the file; the merged layout with units is valid WGSL with 8 storage buffers; the loop guard
opens the unit walk's loops.

Co-Authored-By: Claude <noreply@anthropic.com>
…nced and edit_geometry go through gpu::Top (the TLAS or the units); a scene with units is the flattened scene to every ray, on the CPU (WIP: nothing run on a GPU)

Co-Authored-By: Claude <noreply@anthropic.com>
… record names a tree that is gone or sits past the kernel's records; freed trees are filled with leaves that end; the units' words move to Params.motion.z/.w (.y is render --signals'); an instance of a deforming mesh is no unit and rebuilds; the first instanced mesh of a scene without units says so (WIP: nothing run on a GPU)

Co-Authored-By: Claude <noreply@anthropic.com>
…L.md's browser statements); a scene with more instances than a top tree holds is flattened, as before (WIP: nothing run on a GPU)

Co-Authored-By: Claude <noreply@anthropic.com>
…h's); binned SAH over the catalog's large models is 35 and 42 deep, which 30 sent to median splits (WIP: nothing run on a GPU)

Co-Authored-By: Claude <noreply@anthropic.com>
…triangle without area (the empty tree's leaf named triangle 0, which there is a mesh's first, in model space: seen on the first GPU run, geometry/instanced darker towards the origin); a CPU test of such a scene, with rays through the origin

Co-Authored-By: Claude <noreply@anthropic.com>
…ftware traversal's room does not grow: a second copy of a still model rebuilt the scene); the grown emitter buffer keeps its usage (the merged layout copies the tables each frame: an emitter added in place died in wgpu validation); refused-room reasons name software traversal

Found by the single edit tests on the GPU, software traversal with the guard, one command each.

Co-Authored-By: Claude <noreply@anthropic.com>
…he guarded ones alone for a kernel not yet run unguarded)

Co-Authored-By: Claude <noreply@anthropic.com>
…box's click does: a check (Chrome: a frame in which a body moves 0.84 ms of page time, was 16.7; a click's box 0.6-0.8 ms, was 18-24)

Co-Authored-By: Claude <noreply@anthropic.com>
…n when the top tree is built (a mesh written again where it was kept the bounds it had: voxel/cut-falls-live under software traversal, a part that fell 0.2 m cut off at its old box; found by the atomic suite); a CPU test. test-render: a live test's frames the loop guard stopped fail the run

Co-Authored-By: Claude <noreply@anthropic.com>
…', 'Measured'; ROADMAP step 7b's status, acceptance and open points; VOXEL's browser statement): hello world in Chrome 0.84 ms a frame a body moves (16.7), the voxel level 310.9 MiB and 2.5-4.5 ms an explosion (2,098 MiB, 7 s), a still frame's trace 16-71 % longer than flattened, the guard 11 % of Kabukichō's trace

Co-Authored-By: Claude <noreply@anthropic.com>
…tware traversal offline flattens as before units unless THREERT_UNITS=1: the reference render and the catalog's byte gate keep main's kernel and bytes with nothing set); a native kernel with units has the loop guard with nothing set (65,536; THREERT_LOOP_GUARD=0 takes it out; a kernel without units as before)

Co-Authored-By: Claude <noreply@anthropic.com>
…rsal with units': where units are used, what a still frame costs, what was not run; ROADMAP step 7b: the two decisions, the cost table as the first open point, the runs not made one by one; Known issues: the 23 atomic tests that fail under software traversal on main, hardware traversal's five bundles that do not repeat); the frame log's guard is null while the scene's kernel has none

Co-Authored-By: Claude <noreply@anthropic.com>
@yujiaxu-ops
yujiaxu-ops merged commit dc37081 into main Nov 11, 2026
9 checks passed
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.

1 participant