Skip to content

The light list keeps its own order: the tree and the CDF name its emitters - #151

Merged
yujiaxu-ops merged 11 commits into
mainfrom
emitter-list-order
Nov 17, 2026
Merged

yujiaxu-ops merged 11 commits into
mainfrom
emitter-list-order

Conversation

@yujiaxu-ops

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

Copy link
Copy Markdown
Collaborator

Prerequisite of emitters on instances (scene step D). Follows #150. No behaviour change.

What

prepare reordered the light list by the light tree's leaf order, and code downstream took a tree entry to be its emitter's position in the list. The list now keeps its own order; the tree and the CDF name its emitters by index (as the slot for emitters added in place already did):

  • emitter_order(tris, tree): the CDF's order (the tree's leaf order, then the rest); emitter_cdf(tris, order, ..).
  • LightTree::refit_moving asks for an emitter's vertices by the emitter, not by the tree entry.
  • write_emitters uses the one ordering rule with or without the slot.

So an instance's emitters can be a run of the list, found from a hit by "the instance's first entry + the triangle's index among the mesh's emitters" (next).

Checked

  • render-identity against Scene step D, second part: the light list is filled on the GPU #150's build, 239 outputs: 219 byte-identical, 20 within their own spread, 0 changed.
  • cargo test 168 passed, test-render 239 pass (with main merged in).
  • Owed: a timing (the list's records are now in triangle order, not leaf order); the machine was busy.
  • Review (Bugbot): the tree's moving-refit test did not test the lookup (its movers lay in the list's order). Its movers are out of order now, and a lookup by the tree entry fails it.

🤖 Generated with Claude Code


Note

Medium Risk
Touches core light sampling (CDF, tree refit, live emitter updates) across load and edit paths; intended to be behavior-preserving but errors in index mapping would skew MIS.

Overview
The emitter list (emitter_tris) no longer gets permuted to match the light tree’s leaf order. Tree-related metadata is applied in place: in_tree and per-emitter path codes are keyed by stable list index, and LightTree::refit_moving resolves geometry via emitter index rather than assuming tree entry equals list position.

CDF construction is decoupled from list ordering through new emitter_order(tris, tree) (tree emitters in leaf order, then the rest in list order) and a changed emitter_cdf(tris, order, …) that indexes into the unchanged list. Live paths (prepare, write_emitters, per-frame CDF refresh, async emitter worker, identity checks) all use this shared ordering rule instead of ad-hoc permutations or iter().enumerate().

Reviewed by Cursor Bugbot for commit 7f0b75c. Bugbot is set up for automated code reviews on this repo. Configure here.

yujiaxu-ops and others added 9 commits November 17, 2026 04:55
Light sampling read an emitter's triangle from the triangles' table as world
space, so whatever emits had to be stored there in world space (flattened, or
a mesh of its own written in world space). The list now has its own copy, the
way real-time engines keep a light list: `Table::EmitterTris`, one
`GpuEmitterTri` an emitter (v0, e1, e2 in world space; its triangle, object
and light-tree path code). The kernel's emitter sampling, light LOD, cull and
`emit_mis` read it. A CDF entry names its emitter; a triangle's attributes
name its emitter entry (x.w, where the path code was).

The copies follow what moves (`move_emitters`: the emitters the CPU moves) and
what edits make (`write_emitters`). A particle's is still read where its pass
places it. Nothing is placed otherwise yet.

Cost: 48 B an emitter; the trace +0.07 to 0.10 ms where emitters are sampled
(Bistro 7.18 -> 7.29 ms, Tokyo 4.41 -> 4.42, none without emitters), not
attributed; 0.2 ms of CPU a frame for the crowd's 21,280 moving emitters, which
a GPU pass is to take over. Pictures: big scenes within main's own run-to-run
difference; 26 of the suite's 239 outputs differ in their last bits.

Test: `the_light_list_holds_its_triangles` reads the list and the triangles
back from the GPU after a load, a move and in-place edits.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
What moves an emitter after the list was written is copied into it by a pass
(`emitter_fill.wgsl`, what real-time engines call preparing the lights): a run
of the list an invocation row, each emitter's rows taken again from its
triangle.

- The emitters of the triangles the CPU reposes: filled after a commit that
  moved them, in place of the CPU's rewrite (0.2 ms a frame on the crowd).
- The particles': filled after their passes, so the kernel reads every emitter
  from the list; its particle case (`emitter_tri_of`) is gone.

`EmitterRuns` at prepare, `gpu::EmitterFills` a scene (with hardware ray
tracing), the pipeline made once.

Test: the readback test covers particles (collapsed as loaded, placed after a
frame) and the movers through the pass.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…tters

prepare no longer reorders the list by the light tree's leaf order; the CDF's
order is the tree's then the rest (`emitter_order`), and an entry names its
emitter by index, as the slot for emitters added in place already did. So an
instance's emitters can be a run of the list (next).

No picture changes (render-identity: 219 byte-identical, 20 within their own
spread).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit f45f814. Configure here.

Comment thread renderer/src/ltree.rs
};
let order = t.order.clone();
let vs: Vec<[[f32; 3]; 3]> = (0..n as usize).map(|k| if tris[order[k] as usize].moves { moved(k) } else { [[0.0; 3]; 3] }).collect();
t.refit_moving(&|k| vs[k]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test checks vertices by wrong index

Low Severity

vs is now indexed by emitter, but the assertion still uses tree-entry k (vs[k] while walking t.code[k]). After refit_moving looks up vertices through self.order, this only stays true when leaf order is identity, so a real miss on the new lookup would not fail here.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f45f814. Configure here.

yujiaxu-ops and others added 2 commits November 17, 2026 15:25
…list's order

The test's movers lay along x in the list's order, so their leaf order was the
list's and an entry was its emitter: a lookup by the wrong index read the same
vertices and passed (found by review). They are placed out of order now, the
test asserts the orders differ, and reads each entry's vertices by its
emitter. A lookup by the tree entry fails it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@yujiaxu-ops
yujiaxu-ops changed the base branch from emitters-gpu-fill to main November 17, 2026 08:02
@yujiaxu-ops
yujiaxu-ops merged commit 2f47e9a into main Nov 17, 2026
9 checks passed
@yujiaxu-ops
yujiaxu-ops deleted the emitter-list-order branch November 17, 2026 08:19
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