d3d12: place a title's packed structures and its scenes for the ray walks #596
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/596"
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-11-30T19:21:46Z.
Summary
For #382, the third piece. It wires #536 (the expansion of the packed bottom-level structures) and #586 (the buffer and its places) to the title's calls, so that a translated ray walk reads the title's static structures and its scenes instead of empty ones.
Stacked on #536 and #586: only the last commit is new. It is a draft because the runs below do not hold.
Off by default. Everything here is behind
TUXBOX_CONSOLE_STRUCTURES=1. Without it no line of this PR does anything but return.What it does when it is on:
console::rehydrated): each packed structure is expanded with the triangles the call names, read on the CPU from title memory (title_geometry: indices of either width or in the meshlet coding, positions as three floats or as packed records, the geometry's own transform), and placed in the buffer under the addresses the title knows it by.console::scenes): the title's instance records are read (from an upload buffer or title memory, as an array or as pointers) and given toruntime/bvh-layout'swrite_scene, with the root, the compression word and the bounds each placed structure's header holds. The scene is placed under the address the title builds at and holds the places of the structures it names.console::built): what was placed under that address is forgotten. The structures a title builds while it runs are not written yet, so their instances are left out of the scene.Bindings::console_scenes): for each scene the walk numbers, find where the title binds it, look up the scene placed for that address, and bind the buffer and a block of those offsets in place of the walk's empty buffer. A walk that declares nodes only (#578) gets the buffer and no block. A scene the title has not bound, or that is not placed, stays the scene of no instance.TUXBOX_CONSOLE_WALKS=<digest prefixes>gives the buffer to the listed walk programs only. It is for finding which walk a fault or a wrong picture comes from.In the game
ProjectScarlett 1.0.2.1 offline, GeForce RTX 4070 Ti SUPER 16 GB, 620.73.04, GE-Proton11-14, Core i9-12900K. This stack on
a2650681with #389 ported on top, and the translator ofa2650681.What it does there: the buffer is made, 920 to 1,016 structures are placed when the world starts and about 1,700 ten minutes later, none refused; the main scene is written with some 1,100 of its 3,250 instances; two walks are bound with two scenes each (four when all the title's walks run). A dump of the buffer taken ten minutes into the world, with two walks bound, was walked on the CPU: 2,199,984 rays through the two scenes that held instances, 528,124 hits, none that failed to read what it followed.
What does not hold. With the switch on, six runs of seven lost the GPU (Xid 13) between 2.4 and 19.1 minutes after the first structures; two runs without it went to their limit, 25 and 35 minutes. A run with every walk left on its empty buffer is among the six, and so is one with a 1 MiB buffer where almost nothing is placed. Where the trace lists every command in flight and walks were bound, all of them are draws. The numbers and what they rule out are in the comment on #586.
No picture. In the one static shot I can compare between runs, the picture with two walks bound is the picture without. About 2,050 of the 3,250 instances of the main scene name structures the title builds while it runs, which this PR leaves out. I am not claiming a visible effect.
Do not give every walk the buffer in ProjectScarlett yet. Without
TUXBOX_CONSOLE_WALKSthe title's nine walk programs all get it; the runs above name two or four.Tested
On this stack over
ba8ecae4:cargo fmt --check, clippy and rustdoc with-D warnings: clean.python tuxbox.py check --no-gpu: 12 steps passed; the one that fails is the PythonGuestWatchtest, which fails onmainhere too.scene_publicationtests that ask for a hardware device.a2650681, before #594 and #595; runs on current main come next.December 1
Rebased on
5523fc01. The stack now carries #586's growing buffer (64 MiB, doubling when nothing fits).TUXBOX_CONSOLE_WALKS=a902033a,bd054a51,65f82768,3b375136. With every walk given it the device is lost about 15 s after the walks are bound, six runs of six, in a hit-resolve program dispatched throughExecuteIndirect; the details are in #586, anddocs/ENVIRONMENT.mdnow says so.717a74c4with #617 and those four walks, two runs: one reached its 25-minute limit (1,247 s of the world, 524 frames; a loss is reported 5 s before the launcher's interrupt), the other ended at 247 s on a freed-then-read fault away from the buffer. The run without the switch reached its limit too.5523fc01no run holds on this card, with or without the switch: the title ends on its own access violation after 84 to 579 s of the world (#625). WithTUXBOX_LAZY_PUBLICATION=0the run with the switch ends the same way after 90 s and the one without loses the device after 128 s. So the first condition cannot be shown on today's main here.Everything above this section dates from November 30.
Imported from brcly/TuxBox. Originally posted by Ahmet-Dedeler on 2026-12-01T07:00:43Z.
A data point from another runtime, in case it helps: I ported the unpacker from this stack (
packed_structure,meshlet_indices,packed_positions, andtitle_geometryadapted) into a VIctory branch and ran ProjectScarlett with it on an M5 Max (CrossOver 26.3, D3DMetal 4.0b3). There it does give a picture.The wiring is different from yours. I don't place anything in a buffer of my own. At the rehydration call each structure is expanded and written over its packed bytes in title memory, where the title expects the builder's result, and the title's builder library still makes the dynamic structures and the top levels itself. The title's own walks then read all of it.
One 205 s run in the world (Series X profile, day, outdoors): 1,739 structures (179 MiB) expanded, none refused, no fault. Indirect light in shade is the game's own (soft gradient on shaded walls, no black shade), where before the builder's GPU unpacking left the trees unusable on this host. So the expansion is right on real data as far as a lit picture can show, and your 920 to 1,700 structure counts match what I see.
That may also say something about your "no picture": here the dynamic structures and scenes come from the title's builder, which your PR leaves out for now.
Code, with the source revision named in the commit:
github.com/Ahmet-Dedeler/VIctory@434d4c394aThanks for writing the decoder, it unblocked this.
Imported from brcly/TuxBox. Originally posted by 3kynox on 2026-12-01T09:10:44Z.
@Ahmet-Dedeler thank you. That is the check this decoder was missing: real structures on another runtime and another GPU, none refused, and a picture to judge it by. Your counts agree with mine.
It also explains the "no picture" here better than I had. In TuxBox the title's builder is replaced, so nothing writes the scenes or the structures the title builds while it runs; this PR writes the scenes and the packed structures only. In the main scene that leaves about 2,050 of 3,250 instances out, so a walk sees a third of the world. With your wiring the builder fills in the rest, and you get the light.
So the built structures are what I'm doing next, starting with the meshes in packed positions, whose geometry is final in title memory when the build is called. The meshes in float positions are mostly written by the GPU after the call (with NickStallman's probe from #382, 188 of 191 sampled builds differed between the call and the GPU's turn), so they need another way in.
One question, if you have it at hand: on your side, do the builder's own build and update passes run unchanged for those animated meshes, and is the rehydration batch the only one you had to replace?
Imported from brcly/TuxBox. Originally posted by Copilot on 2026-12-01T17:36:46Z.
Code review location:
runtime/d3d12/src/commands/compute_bindings.rs; line 723The console binding retains only GPU addresses, so a closed or replayed list can read recycled scene/offset data after four completed presents, or a released buffer after growth and 64 presents. Queue fences cover submitted work, not future executions of an existing list. Return a binding lease that retains the actual buffer and pins its offsets, scenes and reachable structures through the command allocator's recording lifetime and GPU completion, for both offsets-based and nodes-only bindings.
Imported from brcly/TuxBox. Originally posted by Copilot on 2026-12-01T17:36:47Z.
Code review location:
runtime/d3d12/src/commands/build_raytracing/console.rs; line 122An expansion error leaves any previous structure named at the destination and alias intact. If either address is reused for unreadable geometry or an unsupported packed form, subsequent scenes resolve it to the old triangles despite the replacement being reported as unplaced. Forget both addresses on expansion failure, matching the allocation-failure path in
heap.structure.Imported from brcly/TuxBox. Originally posted by Copilot on 2026-12-01T17:36:47Z.
Code review location:
runtime/d3d12/src/commands/build_raytracing/console.rs; line 200This snapshots the instance records while recording the build, but upload-backed records may be edited after Close and before each Execute. The existing native path explicitly handles that through
Instances::prepareat submission. For example, changing an instance's transform before Execute updates the native TLAS but leaves this console scene at its original transform, including on subsequent executions of the same list. Please record a console-scene preparation action and refresh its scene/binding data at submission alongside the existing instance fixup.Imported from brcly/TuxBox. Originally posted by Copilot on 2026-12-01T17:36:47Z.
Code review location:
runtime/d3d12/src/commands/build_raytracing/console.rs; line 208If a destination already has a placed scene, an unreadable rebuild takes this branch without removing that scene. This includes the explicitly detected case where the new instance records are GPU-only.
heap.scene_at(destination)consequently keeps returning the previous scene, so later walks traverse obsolete instances instead of the promised empty fallback. Please expose a scene-withdrawal operation onConsoleHeapand invoke it before continuing here, releasing the old scene's structure holds as well.Imported from brcly/TuxBox. Originally posted by Copilot on 2026-12-01T17:36:48Z.
Code review location:
runtime/d3d12/src/commands/compute_bindings.rs; line 699Resolving console sources and placements while recording freezes the dispatch's offsets: rebuilding scene S before submitting the walk leaves it reading S's old placement, and changing a table descriptor from S to T leaves it reading S. Console sources are also absent from
SceneCheck, so descriptor changes are not caught at submission. Resolve both descriptor identities and scene placements in submission order on every execution, including replay, and refresh the dispatch's offsets accordingly.Imported from brcly/TuxBox. Originally posted by Copilot on 2026-12-01T17:36:48Z.
Code review location:
runtime/d3d12/src/device/compute_scene.rs; line 552The root-less
bindingsreader rejects root SRVs and embedded RTS0 chunks, while falling back to the original signature loses reflected mappings where shader registers differ from root registers. Such a walk receives empty scenes despite valid bindings;compute_root_srv_carries_the_shader_registerinruntime/dxbc/src/tests/compute_table.rscovers this register mismatch. Use root-aware reflection withlayout_view, retaining the root-less reader as a fallback.Imported from brcly/TuxBox. Originally posted by copilot-pull-request-reviewer[bot] on 2026-12-01T17:36:48Z.
Review: COMMENTED
🟡 Changes recommended
Active findings identify unsafe binding lifetimes, stale scene and descriptor data on submission or replay, incomplete cleanup after failed rebuilds, and reflection gaps that can yield incorrect or empty scenes.
6 open issues
What changed in this PR
Connects packed-structure expansion and the shared console buffer to TuxBox’s D3D12 build and dispatch paths, allowing translated ray walks to read title geometry and scenes. The feature remains off by default; dynamically built bottom-level structures are not yet populated.
Changes:
runtime/d3d12/src/tests/device/console_heap.rsruntime/d3d12/src/tests/device/compute_scene.rsruntime/d3d12/src/tests/commands/title_geometry.rsruntime/d3d12/src/tests/commands/packed_structure.rsruntime/d3d12/src/tests/commands/console.rsruntime/d3d12/src/diagnostics.rsruntime/d3d12/src/device/descriptor_paging.rsruntime/d3d12/src/device/console_heap.rsruntime/d3d12/src/device/compute_scene.rsruntime/d3d12/src/device/blas/scene_view.rsruntime/d3d12/src/device/blas.rsruntime/d3d12/src/device.rsruntime/d3d12/src/commands/recording.rsruntime/d3d12/src/commands/compute_bindings.rsruntime/d3d12/src/commands/build_raytracing/title_geometry.rsruntime/d3d12/src/commands/build_raytracing/rehydrate.rsruntime/d3d12/src/commands/build_raytracing/packed_structure.rsruntime/d3d12/src/commands/build_raytracing/console.rsruntime/d3d12/src/commands/build_raytracing.rsruntime/d3d12/Cargo.tomldocs/ENVIRONMENT.mdCargo.lockReview effort: Balanced
Imported from brcly/TuxBox. Originally posted by brcly on 2026-12-01T17:44:13Z.
Merged, with #586 just before it, thanks @3kynox. I rebased #596's own commit onto main after #586 went in; the result matches your branch.
Everything here stays behind
TUXBOX_CONSOLE_STRUCTURES=1, so it changes nothing by default. Before it becomes a default, the switch-off control from #586 is still the thing to post: the same build and settings with the switch off, to show whether the remaining device losses come with the structures or without them.