Repository navigation
d3d12: place a title's packed structures and its scenes for the ray walks - #596
Conversation
|
A data point from another runtime, in case it helps: I ported the unpacker from this stack ( 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: Ahmet-Dedeler/VIctory@434d4c3 Thanks for writing the decoder, it unblocked this. |
|
@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? |
d78a98c to
78f98ad
Compare
8ebc43f to
6ed4c1e
Compare
6ed4c1e to
8d50d71
Compare
There was a problem hiding this comment.
🟡 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
Retain console binding resources through command-list and GPU lifetime · New Clear destination and alias structures when expansion fails · New Refresh console scene data at submission for edited instances · New Withdraw stale destination scenes before unreadable rebuild fallback · New Refresh console descriptors and placements on every execution · New Use root-aware reflection to resolve console bindings · New
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:
- Reads title geometry, expands packed structures, and encodes scenes containing placed structures.
- Resolves scene bindings and supplies the shared buffer and offsets to selected ray walks.
- Adds decoding, allocation and binding tests, plus environment-variable documentation.
| File | Description |
|---|---|
runtime/d3d12/src/tests/device/console_heap.rs |
Tests allocation, growth, retirement and structure ownership. |
runtime/d3d12/src/tests/device/compute_scene.rs |
Tests scene-source lookup through root signatures. |
runtime/d3d12/src/tests/commands/title_geometry.rs |
Tests geometry decoding and title-memory reads. |
runtime/d3d12/src/tests/commands/packed_structure.rs |
Tests packed expansion, transforms and validation. |
runtime/d3d12/src/tests/commands/console.rs |
Tests scene records derived from placed headers. |
runtime/d3d12/src/diagnostics.rs |
Advances buffer retirement tracking at presents. |
runtime/d3d12/src/device/descriptor_paging.rs |
Exposes descriptor lookup in paged arenas. |
runtime/d3d12/src/device/console_heap.rs |
Implements the growing buffer and allocation bookkeeping. |
runtime/d3d12/src/device/compute_scene.rs |
Maps console scenes to title binding locations. |
runtime/d3d12/src/device/blas/scene_view.rs |
Retrieves a scene descriptor’s title address. |
runtime/d3d12/src/device/blas.rs |
Stores and exposes the per-device console heap. |
runtime/d3d12/src/device.rs |
Registers the console-heap module. |
runtime/d3d12/src/commands/recording.rs |
Supplies console bindings during dispatch recording. |
runtime/d3d12/src/commands/compute_bindings.rs |
Resolves scenes and binds console buffers and offsets. |
runtime/d3d12/src/commands/build_raytracing/title_geometry.rs |
Reads indices, positions and geometry transforms. |
runtime/d3d12/src/commands/build_raytracing/rehydrate.rs |
Hooks console expansion into rehydration calls. |
runtime/d3d12/src/commands/build_raytracing/packed_structure.rs |
Expands packed structures into traversal records. |
runtime/d3d12/src/commands/build_raytracing/console.rs |
Handles structure placement, invalidation and scene encoding. |
runtime/d3d12/src/commands/build_raytracing.rs |
Invokes console handling for structure builds. |
runtime/d3d12/Cargo.toml |
Adds the scene-encoding crate dependency. |
docs/ENVIRONMENT.md |
Documents feature, heap-size and walk-selection controls. |
Cargo.lock |
Records the new D3D12 dependency. |
Review effort: Balanced
| } | ||
| text | ||
| }); | ||
| bound.map(|(_, nodes, offsets)| (nodes, Some(offsets))) |
| continue; | ||
| } | ||
| Ok(_) => "the buffer has no room", | ||
| Err(why) => why, |
| ("no instances", Some(Vec::new())) | ||
| } else { | ||
| // SAFETY: as this function's. | ||
| unsafe { instance_records(owner, address, count, indirect) } |
| "console scene #{number} at {destination:#x}: its {count} instance records are in {place}; the scene is not placed" | ||
| )); | ||
| } | ||
| continue; |
| let address = source.and_then(|source| self.scene_address(owner, source, arena)); | ||
| // A place in the buffer is an offset of 32 bits. | ||
| let at = address.and_then(|address| heap.scene_at(address)).and_then(|at| u32::try_from(at).ok()); | ||
| if let Some(at) = at { | ||
| offsets[index] = at; |
| let physical = tuxbox_dxbc::compute_table::bindings(source, 5); | ||
| let signature = tuxbox_dxbc::rootsig::parse_rts0(root).ok(); |
8d50d71 to
6af6ce8
Compare
|
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 |


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 (d3d12: bind a console ray walk that declares only its node buffer #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 xshader: guard inactive-lane loads through flat descriptor bases and BVH node tests #594 and d3d12: keep texture-upload staging out of vkd3d's ReBAR budget #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 d3d12: keep console-format structures for the ray walks in one buffer #586, anddocs/ENVIRONMENT.mdnow says so.717a74c4with d3d12: give a mesh pipeline the index map only where its stages can read it #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 (d3d12: lazy publication gives back a page's protection from deferral time, undoing the title's laterVirtualProtect(Lanestexture-publicationcrashes) #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.