bvh-layout: write console-format scenes and instance records #525
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/525"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-29T20:02:59Z.
Translated ray walks read console-format structures from
t0, space901, which holds only empty scenes (#382). This adds a crate that writes one part of them: a top-level scene from a title's instance array (header, parent table, box nodes, 128-byte instance records). A bottom-level structure is described by its buffer offset, root pointer, compression word and bounds, so this doesn't depend on who writes those. Nothing uses it yet; behaviour does not change.Layout: fields and their use are from the 64 recorded entry points containing
image_bvh_intersect_ray(a pattern count over all of them; the full data flow was followed in one program and parts of two more) and fromtools/reference/blas. Fields no walk was found reading are marked in the source.Tested
15 host unit tests (9 at first), including walks with stacks of 64, 8 and 3 entries against testing every triangle; 10 of 10 mutations of the encoder fail them.
python tuxbox.py check --no-gpu: passed at630b0ab1; at32251491and at89f4678f.lavapipe, a hand-written walk using the repo's node test against a native ray query (local harness, not in this PR): 20 / 300 / 3,140 / 10,000 instances, 60,000 rays each. Hit/miss differs on 0 / 0 / 1 / 1 rays (walk only, unexplained), no other id differs, and the distance differs by more than 1e-4 on 0 / 2 / 1 / 3 hits (largest 6.4e-4).
Inactive instances: an earlier version of this text said they were left out of the comparison. With every 13th instance mask 0 for the encoder, and the inactive ones left out of the native array, the walk and the native query agree on hit or miss except 1 ray each at 3,140 and 10,000 instances (walk only, unexplained). Leaving them in the native array can't be used: llvmpipe's ray query drops the last k instances when k are inactive (a minimal native query with 8 instances shows it).
CPU time: 0.7–0.9 ms for 3,140 instances (588 KB), one core, machine shared.
Full
python tuxbox.py checkof5b783c8d(rebased ontoe5d2e913; main's lint rules; see the rebase note below): RTX 5090 (10de:2b85, 620.70.10) 200 pass, 0 fail; AMD iGPU (1002:13c0, RADV) 199 pass, 0 fail. GE-Proton11-14.Not run: the native RDNA 2 instruction, a translated program over this data, the game. The test walk and the lavapipe walk share one reading of the title's walks, so a common misreading would pass both.
Leaf frames (
32251491): the record's rows now go on into the structure's leaf frame,(v - t) * s, from its compression word; a rotation in the word is refused. The reading of the word is from the written description in Leonida'sdocs/bvh.md(a GPL-3.0 project, credited in the source; no code was copied). 4 new tests failed before the change; 8 of 8 mutations fail. On lavapipe with scaled and moved meshes and mask-0 instances, 60,000 rays at each of 20 / 300 / 3,140 / 10,000 instances: no hit/miss difference, no other id, distance over 1e-4 on 1 / 1 / 1 / 2 hits. The fixture builds its leaves with the same frame code, so this shows the composition, not that the word's meaning is right; only real structures can.Checked against 3kynox's description of real structures (
89f4678f, #382): bit 30 of the root word was missing, bit 31 was taken from the instance instead of the stored rows, and the middle of the bounds was computed in double; all three fixed with tests that failed first (15 tests now). The same lavapipe runs give the same results. Compared on real scenes by 3kynox (afc09595, #382): the same instances of one frame through this encoder and theirs, 4.4 million rays: no ray hits in one and misses in the other, none at another distance; 233 rays name another triangle at the same distance. All 4,048 records have the same transforms, root, page, compression word and marks. Not covered: the short stack and parent table (their walk is a plain stack walk), two instances their writer had left out, and the case where the two differ in one mark (bit 31 with every exponent 0x7f), which that data doesn't have.Rebased onto
e5d2e913(5b783c8d): main's lint rules for new crates are in; narrowing casts are checked, so an offset that overflows its 32-bit field now panics where it wrapped (over half a billion instances,# Panicsonwrite_scene). Tests and the Python checks pass on it; the full GPU checks on5b783c8dare below.Not included: provider wiring and the per-dispatch scene offsets, GPU-written instance records, any bottom-level structure.
Evidence: TuxBox check of
5b783c8dfc, no uncommitted changes, GPU 10de:2b85: 17 passed, 0 failed, 0 not runEvidence: TuxBox check of
5b783c8dfc, no uncommitted changes, GPU 1002:13c0: 17 passed, 0 failed, 0 not run🤖 Generated with Claude Code
Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-30T04:12:20Z.
Heads-up: main just landed a large cleanup (up to
e5d2e913), so this PR needs a rebase.rustfmt.toml).unwrap(), lossyascasts and undocumentedunsafeoutside tests.cargo fmt --check, rustdoc with warnings denied, and Miri on the providers' unit tests.The least painful way is to format your branch first, so the rebase only shows real changes:
Then run
python tuxbox.py check --no-gpu, which now includes the format step.If clippy flags something new:
Fromfor widening,TryFromfor narrowing, and a mask for bit fields.unwrap(): use?, orexpectwith the reason it can't fail.unsafeblock: it needs a// SAFETY:comment.CONTRIBUTING's "Code checks" section lists the commands. Thanks!
Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-30T09:16:46Z.
Merged into main as
2a87b5b4(squashed and credited to you), thanks! I checked it against the new lint rules (deny attribute, workspace lints, tests insrc/tests), ran the 15 host tests and clippy on the current main, and read through your lavapipe and real-scene comparisons. It's a good base for the wiring PR.Pull request closed