Skip to content

Scene step D, first part: the light list holds its triangles - #147

Merged
yujiaxu-ops merged 3 commits into
mainfrom
emitters-decoupled
Nov 17, 2026
Merged

yujiaxu-ops merged 3 commits into
mainfrom
emitters-decoupled

Conversation

@yujiaxu-ops

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

Copy link
Copy Markdown
Collaborator

Scene step D, first part (PLAN: emitters off the flattened triangles). No behaviour change intended; it prepares emitting meshes on instances.

What

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 (Tokyo: 1.6 M triangles flattened for it). The light list now has its own world-space copy, the way real-time engines keep one.

  • Table::EmitterTris: one GpuEmitterTri an emitter (v0, e1, e2; its triangle, object, light-tree path code).
  • Kernel: 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).
  • Upkeep: move_emitters rewrites the copies of the emitters the CPU moves; write_emitters writes those that edits make.
  • A particle's emitter is still read where its pass places it. Nothing is placed otherwise yet.

Cost (Metal, 1280x720 at scale 0.75, trace p50, alternating runs)

scene main this
Bistro 7.18 ms 7.29 ms +1.4 %
Zero Day 7.52 7.59 +1.0 %
Bistro crowd 7.25 7.32 +1.0 %
Kabukichō 12.57 12.63 +0.6 %
Tokyo 4.41 4.42 +0.3 %
a scene without emitters 3.245 3.244 0
  • The trace cost (0.07 to 0.10 ms where emitters are sampled) is not attributed. Ruled out: the binding (a typed view of the table times the same) and the record's struct (reading the rows directly times the same).
  • CPU: the crowd's 21,280 moving emitters take 0.2 ms a frame to rewrite (commit 4.88 -> 5.08 ms). A GPU pass is to take this over (next part).
  • Memory: 48 B an emitter (Tokyo +78 MB).

Pictures

  • render-identity against main, 239 outputs: 195 byte-identical, 18 within their own run-to-run spread, 26 differ. Offline ones in the last bits (up to 3.7e-7); a few live ones by a sample that falls otherwise (up to 2.1e-3 of a value); sums within 3e-5.
  • Bistro, Zero Day, Kabukichō, Tokyo, the crowd: within main's own run-to-run difference.
  • Vulkan (RTX 5090): all 26 are byte-identical to main's there, natively and under software traversal, so the differences on Metal are its compiler rounding the new kernel otherwise. 235 outputs: 218 / 219 byte-identical (native / software traversal), the rest within their own spread (two flagged natively were run six more times a side: both builds give the same outputs). cargo test 167 passed there; test-render fails the same five tests as main does on that machine.

Tests

  • cargo test 167 passed, test-render 239 pass.
  • New the_light_list_holds_its_triangles: reads the list and the triangles back from the GPU after a load, a move (with and without a light tree) and in-place edits (a mesh added, changed, removed; a material that starts emitting). Twelve mutants of the upkeep, each caught.

Next

  1. A GPU pass fills the list (the particles' copies, then the instances').
  2. Emitters on instances.

🤖 Generated with Claude Code


Note

Medium Risk
Touches core light sampling, MIS, and live emitter maintenance on the GPU path; behavior is intended unchanged but adds memory, a small trace cost, and Metal-only numerical drift in some outputs.

Overview
Introduces a dedicated Table::EmitterTris light list so emitter sampling no longer depends on emissive geometry living in the main triangles buffer in world space. Each emitter gets a GpuEmitterTri (world-space v0/e1/e2, source triangle id, object index, light-tree path code / move flag).

The emitter CDF now keys entries by emitter list index; triangle x.w stores the emitter entry + 1 (replacing path codes in attributes). The path-tracing kernel (emitter_tri_at, emitter_tri_of, emit_mis, LOD/cull, NEE) reads this table, with a particle exception still sourcing verts from the triangle buffer when placed per frame.

CPU upkeep extends live loading and edits: Prepared builds gpu_emitter_tris, upload/render threads the buffer through, move_emitters rewrites moving emitters, and write_emitters uploads new/changed entries and attribute back-pointers. Heap growth and bind rebinding cover the new section.

Docs (ROADMAP, RUNTIME) and the_light_list_holds_its_triangles GPU readback tests lock the list against triangles after load, moves, and in-place edits.

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

yujiaxu-ops and others added 2 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>
@yujiaxu-ops
yujiaxu-ops merged commit c245315 into main Nov 17, 2026
9 checks passed
@yujiaxu-ops
yujiaxu-ops deleted the emitters-decoupled branch November 17, 2026 07:05
yujiaxu-ops added a commit that referenced this pull request Nov 17, 2026
What moves an emitter after the light list was written is copied into the
list 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 (the crowd's commit back at main's
  level: 4.5 ms in a guarded run, 4.9 to 5.0 with the rewrite).
- The particles': filled after their passes, live and offline, so the kernel
  reads every emitter from the list; its particle case is gone.

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

Pictures: against #147's build 217 of 239 outputs byte-identical, 19 within
their own spread, the two light-sampled particle tests in their last bits; on
Vulkan 219 byte-identical, 17 within, 0 changed.

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

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
yujiaxu-ops added a commit that referenced this pull request Nov 17, 2026
A model's emitting triangles were flattened at every placement (world space,
for light sampling: the reason #147 took away), and a movable or posed model
re-transformed them on the CPU every frame. They stay in the model's mesh now,
as real-time engines have them: a static placement's, a movable model's, a
rigid posed model's moving nodes'. No shader change.

- Flattened a placement: Tokyo 1,800,744 -> 0 triangles, Bistro 20,638 -> 0,
  Zero Day 10,105 -> 4, the crowd's moving nodes 18,400 -> 0.
- One case stays flattened: a triangle that emits with a cutout on exactly its
  vertices goes with the cutout (`flatten_coincident`, for a still placement
  and a rigid node alike; Zero Day has one such pair). In one BLAS the
  decal's pass-through stepped the ray past the emitter. The unbiased check
  on Zero Day is the guard.

Cost and gain (trace p50, main -> this): the crowd 7.38 -> 7.37 ms and its
commit 4.46 -> 3.61 ms; Bistro 7.20 -> 7.13; Zero Day 7.68 -> 7.71; Tokyo
4.45-4.50 -> 4.59-4.62 (+2.9 %: instancing its 1.8 M emitting triangles; the
mechanism is not established). Taken for the standard structure; the way back
is merging still geometry whole, a step of its own.

Tests: `geometry/emitter-model` (analytic); the readback test with a model
still, moved, and posed by a clip; a structural test of the pair rule
(`panel-decal.glb`); mutants caught. Against main the new test alone differs
(last bits); Vulkan agrees, natively and under software traversal.

Left: an instanced object's copies (next), a deforming mesh's emitters, a
model with emitters added in place (still rebuilds).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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