d3d12: write the structures a title builds for the ray walks #623
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/623"
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 3kynox on 2026-12-01T15:04:00Z.
Summary
On main, now that #536, #586 and #596 are merged. Part of #382: the row "dynamic bottom-level structures".
A title builds most of its bottom-level structures while it runs. Main leaves their instances out of the scenes (#596). This writes them, behind the same
TUXBOX_CONSOLE_STRUCTURES=1.console_structure.rs,box_tree.rs). A structure in the console's form from the triangles a build names: one triangle to a leaf, 128-byte box nodes, the parent table. The tree is its own; a walk only needs boxes that hold what is below them. The tests walk it with a CPU port of the traversal (console_walk.rs) and compare with brute force.TUXBOX_CONSOLE_BUILT). By default only those in packed positions, whose geometry is final in title memory when the build is called. A build in float positions is mostly a mesh the GPU writes after the call, so it is left out.latewrites those too, at the call and once more when the GPU is past that frame; that only helps on a host whose GPU works in the title's own memory (section-import=aliased).0andallare for comparing pictures.What it does not do: build from what the GPU wrote on a host that substitutes the import, and pair triangles in a leaf as the console's builder does.
Tested
No Lanes scenario: Lanes builds no console-format structure and has no walk that reads one. The writer, the choice of builds and the overlap rule are covered by unit tests.
GPU, driver and backend: RTX 4070 Ti SUPER 16 GB, 620.73.04, GE-Proton11-14, vkd3d-proton.
The
Evidence:linetuxbox.py checkprints last, one per card (it names the commit it tested; run it on this pull request's head):The one failure is
test_stage_baseline.GuestWatch, which fails on this machine on main too.Commands run and their results:
In ProjectScarlett, one run each.
717a74c4, before this rebase: with packed positions only the main scene holds 765 to 779 of about 2,700 instances; withlate, 2,550 to 2,590 of about 3,250 (of 8,192 builds in float positions read again, 5,777 were written at the second reading and 946 could not be read).5523fc01with this change andlate, before the last rebase: 349 s of the world, then the title's own access violation, which the run without the switch ends on too (#625). The main scene holds 2,109 of 2,818 instances at the end; 4,096 structures written, 53 left out, 1,001 given up under later structures; of 2,048 builds read again, 128 were written at the second reading.About the buffer in
late: in that run it doubled up to its 1,024 MiB limit, with 594 MiB held when the title stopped. That is what the structures in it take, not places left behind: 4,096 built structures were written and 1,001 given up under later ones, beside about 900 rehydrated ones, so some 4,000 structures at about 150 KiB each, in a form that spends about 110 bytes a triangle (a 64-byte leaf, its share of the 128-byte box nodes and its parent entry). A scene that needs more thanTUXBOX_CONSOLE_HEAP_MBloses the structures that find no room, and the log says so.Still open: the structures written at the second reading have not been checked against a reference; the tests check the writer itself against brute force. There is no visible effect to show: see #586 for why. Under Miri the two tests that walk large structures use small ones.
Checks
CI runs the code checks. No evidence JSON changes.
Imported from brcly/TuxBox. Originally posted by Copilot on 2026-12-01T18:39:21Z.
Code review location:
runtime/d3d12/src/commands/build_raytracing/console.rs; line 268In
latemode, this process-wide queue lets a build on device B consume device A's pending rereads using B's heap. That loses A's update and can publish A's geometry into B's heap, since entries carry no owner identity. Keep pending work with its owning device, or key and filter it by device identity with appropriate lifetime handling.Imported from brcly/TuxBox. Originally posted by Copilot on 2026-12-01T18:39:21Z.
Code review location:
runtime/d3d12/src/commands/build_raytracing/console.rs; line 305In
latemode, a failed first read at 0x1400 leaves a zero-digest retry pending even if a newer structure at 0x1000 covers that address. This guard lets the obsolete retry publish if its geometry becomes readable, and its overlap claim then evicts the newer structure. Track pending-build validity independently of successful placement and cancel retries when a newer build overlaps their destination.Imported from brcly/TuxBox. Originally posted by Copilot on 2026-12-01T18:39:21Z.
Code review location:
runtime/d3d12/src/commands/build_raytracing/console.rs; line 305In
latemode, another command-list thread can rebuild this destination after the pending reread is removed fromLATERbut before it publishes. Removing the pending entry cannot cancel that detached work, so the old reread can replace the newer structure despite this existence check. Track a build generation and validate it atomically with publication and rebuild invalidation.Imported from brcly/TuxBox. Originally posted by copilot-pull-request-reviewer[bot] on 2026-12-01T18:39:22Z.
Review: COMMENTED
🟡 Changes recommended
Critical overlap-invalidation and late-mode queue defects can retain overwritten structures, publish geometry to the wrong device, and let obsolete rereads replace or evict newer builds.
4 open issues
What changed in this PR
Extends the opt-in console ray-walk support to structures built from geometry at runtime, advancing #382 beyond the static structures handled by earlier PRs.
Changes:
runtime/d3d12/src/tests/device/console_heap.rsruntime/d3d12/src/tests/commands/console.rsruntime/d3d12/src/tests/commands/console_walk.rsruntime/d3d12/src/tests/commands/console_structure.rsruntime/d3d12/src/tests/commands/box_tree.rsruntime/d3d12/src/device/console_heap.rsruntime/d3d12/src/commands/build_raytracing/title_geometry.rsruntime/d3d12/src/commands/build_raytracing/console.rsruntime/d3d12/src/commands/build_raytracing/console_structure.rsruntime/d3d12/src/commands/build_raytracing/box_tree.rsruntime/d3d12/src/commands/build_raytracing.rsdocs/ENVIRONMENT.mdTUXBOX_CONSOLE_BUILTmodes and limitations.Review effort: Balanced
Imported from brcly/TuxBox. Originally posted by Copilot on 2026-12-01T18:39:22Z.
Code review location:
runtime/d3d12/src/device/console_heap.rs; line 639Overlap invalidation must happen even when the replacement cannot fit in the provider buffer. If the title builds over a structure at another address while the buffer is full, this branch skips
claimand forgets only the replacement's exact destination, leaving the overwritten structure available to later scenes. Apply the claim independently of allocation success.Imported from brcly/TuxBox. Originally posted by 3kynox on 2026-12-01T22:26:19Z.
Code review location:
runtime/d3d12/src/commands/build_raytracing/console.rs; line 268Fixed in
ba24f252: the pending readings now belong to the device's buffer (Reread, kept inconsole_heap.rsunder the buffer's lock), so a build on one device cannot take another's. Test:a_reading_waits_in_its_own_buffer_only_and_only_for_the_last_build_at_its_address.Imported from brcly/TuxBox. Originally posted by 3kynox on 2026-12-01T22:26:21Z.
Code review location:
runtime/d3d12/src/commands/build_raytracing/console.rs; line 305Fixed in
ba24f252: a claim now makes stale every reading pending for a build at an address inside the claimed bytes, whether that build placed a structure or not (Book::claim,Book::stale). Test:a_reading_pending_at_an_address_a_later_structure_covers_is_dropped.Imported from brcly/TuxBox. Originally posted by 3kynox on 2026-12-01T22:26:23Z.
Code review location:
runtime/d3d12/src/commands/build_raytracing/console.rs; line 305Fixed in
ba24f252: each address counts the builds made at it (Book::begun), a reading carries the number of the build it is for, andConsoleHeap::structure_if_currentchecks that number and places the structure in one step under the buffer's lock. A build recorded meanwhile either comes first and makes the reading stale, or comes after and replaces what it placed. Test:a_reading_taken_before_the_title_builds_there_again_is_no_longer_current.Imported from brcly/TuxBox. Originally posted by 3kynox on 2026-12-01T22:26:24Z.
Code review location:
runtime/d3d12/src/device/console_heap.rs; line 639Fixed in
ba24f252: the claim is applied whether or not the new structure finds room (Book::built_over). Test:a_structure_that_finds_no_place_still_gives_up_what_the_title_built_over.