Repository navigation
d3d12: write the structures a title builds for the ray walks - #623
Conversation
11327bc to
170f04b
Compare
There was a problem hiding this comment.
🟡 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:
- Adds a console-format structure writer and four-way bounding-box tree, with CPU traversal tests against brute-force triangle intersections.
- Adds build-selection modes, including delayed rereads for GPU-written float positions.
- Tracks overlapping title-memory ranges to retire overwritten structures.
| File | Description |
|---|---|
runtime/d3d12/src/tests/device/console_heap.rs |
Tests overlap retirement and extent bookkeeping. |
runtime/d3d12/src/tests/commands/console.rs |
Tests build modes, position selection, and digests. |
runtime/d3d12/src/tests/commands/console_walk.rs |
Adds CPU traversal helpers for structure validation. |
runtime/d3d12/src/tests/commands/console_structure.rs |
Tests structure layout, geometry handling, and ray hits. |
runtime/d3d12/src/tests/commands/box_tree.rs |
Tests tree coverage, bounds, and determinism. |
runtime/d3d12/src/device/console_heap.rs |
Adds overlap bookkeeping and exposes frame progress. |
runtime/d3d12/src/commands/build_raytracing/title_geometry.rs |
Adds triangle counting and transformed-corner access. |
runtime/d3d12/src/commands/build_raytracing/console.rs |
Wires runtime builds, delayed rereads, and diagnostics. |
runtime/d3d12/src/commands/build_raytracing/console_structure.rs |
Encodes triangles into console-format structures. |
runtime/d3d12/src/commands/build_raytracing/box_tree.rs |
Builds four-way bounding-box trees. |
runtime/d3d12/src/commands/build_raytracing.rs |
Registers the tree and structure-writer modules. |
docs/ENVIRONMENT.md |
Documents TUXBOX_CONSOLE_BUILT modes and limitations. |
Review effort: Balanced
| static LATER: std::sync::Mutex<std::collections::BTreeMap<u64, Later>> = | ||
| std::sync::Mutex::new(std::collections::BTreeMap::new()); |
There was a problem hiding this comment.
Fixed in ba24f252: the pending readings now belong to the device's buffer (Reread, kept in console_heap.rs under 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.
| // Written at the call and given up since: the title has built over it. | ||
| if look.digest != 0 && heap.placed(destination).is_none() { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
Fixed 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.
| // Written at the call and given up since: the title has built over it. | ||
| if look.digest != 0 && heap.placed(destination).is_none() { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
Fixed in ba24f252: each address counts the builds made at it (Book::begun), a reading carries the number of the build it is for, and ConsoleHeap::structure_if_current checks 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.
| if placed.is_some() { | ||
| inner.book.claim(addresses, extent, now); | ||
| } |
There was a problem hiding this comment.
Fixed 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.
a22aa1a to
32c9c3f
Compare
A build in packed positions is written in the console's form from the triangles it names, at the call. One in float positions is left out by default: the GPU mostly writes those after the call. TUXBOX_CONSOLE_BUILT=late writes them too and reads them again once the GPU is past that frame, for a host whose GPU works in the title's own memory. A structure the title builds over is given up, which is what bounds the buffer.
32c9c3f to
ba24f25
Compare

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 (d3d12: lazy publication gives back a page's protection from deferral time, undoing the title's laterVirtualProtect(Lanestexture-publicationcrashes) #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.