Skip to content

d3d12: place a title's packed structures and its scenes for the ray walks - #596

Merged
brcly merged 1 commit into
brcly:mainfrom
3kynox:pr-console-wiring
Dec 1, 2026
Merged

brcly merged 1 commit into
brcly:mainfrom
3kynox:pr-console-wiring

Conversation

@3kynox

@3kynox 3kynox commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • At a rehydration call (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.
  • At a top-level build (console::scenes): the title's instance records are read (from an upload buffer or title memory, as an array or as pointers) and given to runtime/bvh-layout's write_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.
  • At a bottom-level build (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.
  • At a walk's dispatch (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.
  • At a present: the clock the buffer's places rest by moves on.

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 a2650681 with #389 ported on top, and the translator of a2650681.

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_WALKS the title's nine walk programs all get it; the runs above name two or four.

Tested

On this stack over ba8ecae4:

December 1

Rebased on 5523fc01. The stack now carries #586's growing buffer (64 MiB, doubling when nothing fits).

Everything above this section dates from November 30.

@Ahmet-Dedeler

Copy link
Copy Markdown

A data point from another runtime, in case it helps: I ported the unpacker from this stack (packed_structure, meshlet_indices, packed_positions, and title_geometry adapted) 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: Ahmet-Dedeler/VIctory@434d4c3

Thanks for writing the decoder, it unblocked this.

@3kynox

3kynox commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

@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?

@3kynox
3kynox force-pushed the pr-console-wiring branch from d78a98c to 78f98ad Compare December 1, 2026 11:49
@3kynox
3kynox force-pushed the pr-console-wiring branch from 8ebc43f to 6ed4c1e Compare December 1, 2026 14:57
@3kynox
3kynox marked this pull request as ready for review December 1, 2026 17:28
Copilot AI balanced review requested due to automatic review settings December 1, 2026 17:28
@3kynox
3kynox force-pushed the pr-console-wiring branch from 6ed4c1e to 8d50d71 Compare December 1, 2026 17:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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:

  • 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;
Comment on lines +695 to +699
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;
Comment on lines +551 to +552
let physical = tuxbox_dxbc::compute_table::bindings(source, 5);
let signature = tuxbox_dxbc::rootsig::parse_rts0(root).ok();
@brcly
brcly force-pushed the pr-console-wiring branch from 8d50d71 to 6af6ce8 Compare December 1, 2026 17:39
@brcly
brcly merged commit 9a19c76 into brcly:main Dec 1, 2026
5 checks passed
@brcly

brcly commented Dec 1, 2026

Copy link
Copy Markdown
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants