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

Merged
3kynox merged 1 commit from upstream-pr/596 into main 2026-12-01 17:44:03 +00:00
3kynox commented 2026-11-30 19:21:46 +00:00 (Migrated from github.com)

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:

  • 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 (#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:

  • 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 Python GuestWatch test, which fails on main here too.
  • The provider's tests under Wine: 516 passed, 8 ignored; the three failures are the scene_publication tests that ask for a hardware device.
  • No AMD run. The NVIDIA runs are the ones above, made on 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).

  • Which walks. In ProjectScarlett give the buffer to the four distant-shadow walks only: 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 through ExecuteIndirect; the details are in #586, and docs/ENVIRONMENT.md now says so.
  • On 717a74c4 with #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.
  • On 5523fc01 no 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). With TUXBOX_LAZY_PUBLICATION=0 the 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.
  • Visible effect. None from these four walks in the scenes the runs reach, checked by alternating the buffer within one run (#586).

Everything above this section dates from November 30.

<!-- greyfinch-sync:brcly/TuxBox:issue:5572151514 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/596). Originally posted by [3kynox](https://github.com/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: - **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 (#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`: - `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 Python `GuestWatch` test, which fails on `main` here too. - The provider's tests under Wine: 516 passed, 8 ignored; the three failures are the `scene_publication` tests that ask for a hardware device. - No AMD run. The NVIDIA runs are the ones above, made on `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). - **Which walks.** In ProjectScarlett give the buffer to the four distant-shadow walks only: `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 through `ExecuteIndirect`; the details are in #586, and `docs/ENVIRONMENT.md` now says so. - **On `717a74c4` with #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. - **On `5523fc01`** no 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). With `TUXBOX_LAZY_PUBLICATION=0` the 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. - **Visible effect.** None from these four walks in the scenes the runs reach, checked by alternating the buffer within one run (#586). Everything above this section dates from November 30.
Ahmet-Dedeler commented 2026-12-01 07:00:43 +00:00 (Migrated from github.com)

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, 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: github.com/Ahmet-Dedeler/VIctory@434d4c394a

Thanks for writing the decoder, it unblocked this.

<!-- greyfinch-sync:brcly/TuxBox:comment:7303540170 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/596#issuecomment-7303540170). Originally posted by [Ahmet-Dedeler](https://github.com/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`, 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: https://github.com/Ahmet-Dedeler/VIctory/commit/434d4c394a5d14faa8d2f281b7231c310dbc5a24 Thanks for writing the decoder, it unblocked this.
3kynox commented 2026-12-01 09:10:44 +00:00 (Migrated from github.com)

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?

<!-- greyfinch-sync:brcly/TuxBox:comment:7306325838 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/596#issuecomment-7306325838). Originally posted by [3kynox](https://github.com/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?
Copilot commented 2026-12-01 17:36:46 +00:00 (Migrated from github.com)

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 723

@@ -606,6 +614,115 @@ impl Bindings {
         Ok(())
     }
 
+    /// The address of the structure the title has bound where `source` says.
+    fn scene_address(
+        &self,
+        owner: &IUnknown,
+        source: SceneSource,
+        arena: Option<&Arc<crate::device::descriptor_paging::Arena>>,
+    ) -> Option<u64> {
+        match source {
+            SceneSource::RootSrv(slot) => match self.compute_args.get(&slot) {
+                Some(Argument::Buffer(BufferView::Srv(address))) => Some(*address),
+                _ => None,
+            },
+            SceneSource::Table { slot, offset } => {
+                let Some(Argument::Table(table)) = self.compute_args.get(&slot) else { return None };
+                let view = match arena.filter(|arena| arena.contains(table.logical.ptr)) {
+                    Some(arena) => arena.view(
+                        usize::try_from(table.logical.ptr).ok()?.checked_add(offset as usize * arena.guest_stride())?,
+                    )?,
+                    // Not a paged table: nothing is leased to read its entry.
+                    None => self
+                        .table_entry(
+                            slot,
+                            offset,
+                            None,
+                            &mut crate::device::descriptor_paging::DescriptorLeases::default(),
+                        )
+                        .ok()?,
+                };
+                // SAFETY: `owner` is the list's controlling guest device.
+                unsafe { crate::device::blas::scene_view_address(owner, view) }
+            }
+        }
+    }
+
+    /// What to bind for the console walk of `root` when console-format
+    /// structures are placed (`device::console_heap`): the buffer, and for a
+    /// walk that declares them the block of offsets of the scenes the title
+    /// has bound. A scene the title has not bound, or that is not placed, is
+    /// the scene of no instance.
+    pub(super) fn console_scenes(
+        &self,
+        guest: &super::List,
+        root: &SceneRoot,
+        arena: Option<&Arc<crate::device::descriptor_paging::Arena>>,
+    ) -> Option<(u64, Option<u64>)> {
+        use crate::device::console_heap::{self, EMPTY_SCENE, SCENES};
+        let declares_offsets = root.bvh.as_ref()?.offsets();
+        if !console_heap::enabled() {
+            return None;
+        }
+        if !console_heap::walks(&root.program.source_hash) {
+            crate::diagnostics::log_once(&root.program.first_console, || {
+                format!(
+                    "console walk {}: not listed in TUXBOX_CONSOLE_WALKS, it keeps its empty buffer",
+                    root.program.source_hash
+                )
+            });
+            return None;
+        }
+        let owner = guest.parent.as_ref()?;
+        // SAFETY: `owner` is the list's controlling guest device.
+        let (heap, device) = unsafe { crate::device::blas::console(owner) };
+        if !declares_offsets {
+            // The walk reaches its nodes from what another pass left it: an
+            // address in the buffer the scenes are in.
+            let nodes = heap.buffer();
+            crate::diagnostics::log_once(&root.program.first_console, || {
+                format!(
+                    "console walk {}: it declares no scene offsets and is given {}",
+                    root.program.source_hash,
+                    if nodes.is_some() { "the buffer alone" } else { "nothing yet: it keeps its empty buffer" }
+                )
+            });
+            return nodes.map(|nodes| (nodes, None));
+        }
+        let mut offsets = [EMPTY_SCENE; SCENES];
+        let mut found = Vec::with_capacity(root.console.len());
+        for (index, source) in root.console.iter().enumerate().take(SCENES) {
+            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;
+            }
+            found.push((*source, address, at));
+        }
+        let bound = heap.bind(device, offsets);
+        crate::diagnostics::log_once(&root.program.first_console, || {
+            let mut text = format!("console walk {}: {} scenes", root.program.source_hash, found.len());
+            for (index, (source, address, at)) in found.iter().enumerate() {
+                text += &match (source, address, at) {
+                    (None, ..) => format!("; scene {index} is not in the title's root"),
+                    (Some(source), None, _) => format!("; scene {index} at {source:?} names no structure"),
+                    (Some(_), Some(address), None) => {
+                        format!("; scene {index} is the title's {address:#x}, which is not placed")
+                    }
+                    (Some(_), Some(address), Some(at)) => {
+                        format!("; scene {index} is the title's {address:#x}, at offset {at:#x}")
+                    }
+                };
+            }
+            if bound.is_none() {
+                text += "; nothing is placed yet, the walk keeps its empty buffer";
+            }
+            text
+        });
+        bound.map(|(_, nodes, offsets)| (nodes, Some(offsets)))

The 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.

<!-- greyfinch-sync:brcly/TuxBox:review-comment:4758281684 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/596#discussion_r4758281684). Originally posted by [Copilot](https://github.com/apps/copilot-pull-request-reviewer) on 2026-12-01T17:36:46Z. **Code review location:** `runtime/d3d12/src/commands/compute_bindings.rs`; line 723 ~~~~diff @@ -606,6 +614,115 @@ impl Bindings { Ok(()) } + /// The address of the structure the title has bound where `source` says. + fn scene_address( + &self, + owner: &IUnknown, + source: SceneSource, + arena: Option<&Arc<crate::device::descriptor_paging::Arena>>, + ) -> Option<u64> { + match source { + SceneSource::RootSrv(slot) => match self.compute_args.get(&slot) { + Some(Argument::Buffer(BufferView::Srv(address))) => Some(*address), + _ => None, + }, + SceneSource::Table { slot, offset } => { + let Some(Argument::Table(table)) = self.compute_args.get(&slot) else { return None }; + let view = match arena.filter(|arena| arena.contains(table.logical.ptr)) { + Some(arena) => arena.view( + usize::try_from(table.logical.ptr).ok()?.checked_add(offset as usize * arena.guest_stride())?, + )?, + // Not a paged table: nothing is leased to read its entry. + None => self + .table_entry( + slot, + offset, + None, + &mut crate::device::descriptor_paging::DescriptorLeases::default(), + ) + .ok()?, + }; + // SAFETY: `owner` is the list's controlling guest device. + unsafe { crate::device::blas::scene_view_address(owner, view) } + } + } + } + + /// What to bind for the console walk of `root` when console-format + /// structures are placed (`device::console_heap`): the buffer, and for a + /// walk that declares them the block of offsets of the scenes the title + /// has bound. A scene the title has not bound, or that is not placed, is + /// the scene of no instance. + pub(super) fn console_scenes( + &self, + guest: &super::List, + root: &SceneRoot, + arena: Option<&Arc<crate::device::descriptor_paging::Arena>>, + ) -> Option<(u64, Option<u64>)> { + use crate::device::console_heap::{self, EMPTY_SCENE, SCENES}; + let declares_offsets = root.bvh.as_ref()?.offsets(); + if !console_heap::enabled() { + return None; + } + if !console_heap::walks(&root.program.source_hash) { + crate::diagnostics::log_once(&root.program.first_console, || { + format!( + "console walk {}: not listed in TUXBOX_CONSOLE_WALKS, it keeps its empty buffer", + root.program.source_hash + ) + }); + return None; + } + let owner = guest.parent.as_ref()?; + // SAFETY: `owner` is the list's controlling guest device. + let (heap, device) = unsafe { crate::device::blas::console(owner) }; + if !declares_offsets { + // The walk reaches its nodes from what another pass left it: an + // address in the buffer the scenes are in. + let nodes = heap.buffer(); + crate::diagnostics::log_once(&root.program.first_console, || { + format!( + "console walk {}: it declares no scene offsets and is given {}", + root.program.source_hash, + if nodes.is_some() { "the buffer alone" } else { "nothing yet: it keeps its empty buffer" } + ) + }); + return nodes.map(|nodes| (nodes, None)); + } + let mut offsets = [EMPTY_SCENE; SCENES]; + let mut found = Vec::with_capacity(root.console.len()); + for (index, source) in root.console.iter().enumerate().take(SCENES) { + 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; + } + found.push((*source, address, at)); + } + let bound = heap.bind(device, offsets); + crate::diagnostics::log_once(&root.program.first_console, || { + let mut text = format!("console walk {}: {} scenes", root.program.source_hash, found.len()); + for (index, (source, address, at)) in found.iter().enumerate() { + text += &match (source, address, at) { + (None, ..) => format!("; scene {index} is not in the title's root"), + (Some(source), None, _) => format!("; scene {index} at {source:?} names no structure"), + (Some(_), Some(address), None) => { + format!("; scene {index} is the title's {address:#x}, which is not placed") + } + (Some(_), Some(address), Some(at)) => { + format!("; scene {index} is the title's {address:#x}, at offset {at:#x}") + } + }; + } + if bound.is_none() { + text += "; nothing is placed yet, the walk keeps its empty buffer"; + } + text + }); + bound.map(|(_, nodes, offsets)| (nodes, Some(offsets))) ~~~~ --- The 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.
Copilot commented 2026-12-01 17:36:47 +00:00 (Migrated from github.com)

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 122

@@ -0,0 +1,242 @@
+//! The title's structure calls, answered with console-format structures for
+//! its ray walks (`device::console_heap`, `TUXBOX_CONSOLE_STRUCTURES`).
+//!
+//! - A rehydration expands each packed structure with the geometry the call
+//!   names (`packed_structure`, `title_geometry`) and places the result.
+//! - A top-level build reads the title's instance records, writes the scene
+//!   over the instances whose structure is placed (`tuxbox_bvh_layout`) and
+//!   places it under the address the title builds at. The scene holds the
+//!   places it names. A walk dispatched later finds it by the address the
+//!   title binds.
+//!
+//! Structures the title builds from geometry while it runs are not placed
+//! yet: their instances are left out of the scene.
+use super::{Entry, packed_structure, title_geometry};
+use crate::device::console_heap::{self, Placed};
+use crate::device::{blas, ray_build};
+use crate::diagnostics::log;
+use std::sync::atomic::{AtomicU64, Ordering};
+use tuxbox_bvh_layout::{Bounds, Instance, Structure, header, write_scene};
+use windows::Win32::Graphics::Direct3D12::*;
+use windows::core::IUnknown;
+
+type Build = D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC;
+
+/// A D3D12 instance record.
+const INSTANCE: usize = Instance::BYTES;
+/// More instances than this are not read: no scene of the title comes near.
+const LIMIT: usize = 1 << 20;
+
+/// Whether the `count`-th of something is worth a line in the log.
+fn told(count: u64) -> bool {
+    count <= 16 || count.is_power_of_two()
+}
+
+/// The `count` instance records at `address`, and where they are kept.
+///
+/// # Safety
+/// `owner` is the list's controlling guest device.
+unsafe fn instance_records(
+    owner: &IUnknown,
+    address: u64,
+    count: usize,
+    indirect: bool,
+) -> (&'static str, Option<Vec<u8>>) {
+    if count > LIMIT {
+        return ("too many to read", None);
+    }
+    let read = |address: u64, out: &mut [u8]| -> Option<&'static str> {
+        // SAFETY: as this function's.
+        if unsafe { super::read_upload(owner, address, out) }.is_ok() {
+            return Some("an upload buffer");
+        }
+        crate::device::read_title_bytes(address, out).then_some("title memory")
+    };
+    let mut records = vec![0u8; count * if indirect { 8 } else { INSTANCE }];
+    let Some(place) = read(address, &mut records) else {
+        // SAFETY: as this function's.
+        let gpu = unsafe { blas::default_instances(owner, address) }.is_ok();
+        return (if gpu { "a buffer only the GPU reads" } else { "memory that cannot be read" }, None);
+    };
+    if !indirect {
+        return (place, Some(records));
+    }
+    let mut out = vec![0u8; count * INSTANCE];
+    for (pointer, record) in records.chunks_exact(8).zip(out.chunks_exact_mut(INSTANCE)) {
+        if read(u64::from_le_bytes(core::array::from_fn(|byte| pointer[byte])), record).is_none() {
+            return ("pointers to memory that cannot be read", None);
+        }
+    }
+    (if place == "title memory" { "pointers in title memory" } else { "pointers in an upload buffer" }, Some(out))
+}
+
+/// The expansion of one entry of a rehydration call.
+///
+/// # Safety
+/// `build` is the title's description, live for the call.
+unsafe fn expanded(build: &Build, alias: u64) -> Result<Vec<u8>, &'static str> {
+    let inputs = &build.Inputs;
+    // SAFETY: the title supplies the descriptions for the duration of the call.
+    if inputs.Type != D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL || !unsafe { ray_build::valid(inputs) }
+    {
+        return Err("inputs that are not valid bottom-level inputs");
+    }
+    let packed = [build.SourceAccelerationStructureData, build.DestAccelerationStructureData, alias]
+        .into_iter()
+        .find_map(title_geometry::structure_at)
+        .ok_or("the structure cannot be read")?;
+    // SAFETY: `ray_build::valid` checked the layout and every pointer.
+    let geometry = unsafe { title_geometry::read(inputs) }?;
+    packed_structure::unpack(
+        &packed,
+        &|index, primitive| title_geometry::corners(&geometry, index, primitive),
+        &|index| title_geometry::transform(&geometry, index),
+    )
+}
+
+/// A rehydration call, before anything else is decided about it.
+///
+/// # Safety
+/// `owner` is the list's controlling guest device; `builds` holds the
+/// title's descriptions for the call, and `addresses` is null or holds as many.
+pub(super) unsafe fn rehydrated(owner: &IUnknown, builds: &[Build], addresses: *const u64) {
+    if !console_heap::enabled() {
+        return;
+    }
+    static CALLS: AtomicU64 = AtomicU64::new(0);
+    static PLACED: AtomicU64 = AtomicU64::new(0);
+    static LEFT: AtomicU64 = AtomicU64::new(0);
+    // SAFETY: as this function's.
+    let (heap, device) = unsafe { blas::console(owner) };
+    let mut placed = 0u64;
+    for (index, build) in builds.iter().enumerate() {
+        // SAFETY: `addresses` is not null here and holds an entry for each build (`# Safety`).
+        let alias = if addresses.is_null() { 0 } else { unsafe { addresses.add(index).read_unaligned() } };
+        // SAFETY: as this function's.
+        let why = match unsafe { expanded(build, alias) } {
+            Ok(bytes) if heap.structure(device, &[build.DestAccelerationStructureData, alias], &bytes) => {
+                placed += 1;
+                continue;
+            }
+            Ok(_) => "the buffer has no room",
+            Err(why) => why,

An 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.

<!-- greyfinch-sync:brcly/TuxBox:review-comment:4758281785 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/596#discussion_r4758281785). Originally posted by [Copilot](https://github.com/apps/copilot-pull-request-reviewer) on 2026-12-01T17:36:47Z. **Code review location:** `runtime/d3d12/src/commands/build_raytracing/console.rs`; line 122 ~~~~diff @@ -0,0 +1,242 @@ +//! The title's structure calls, answered with console-format structures for +//! its ray walks (`device::console_heap`, `TUXBOX_CONSOLE_STRUCTURES`). +//! +//! - A rehydration expands each packed structure with the geometry the call +//! names (`packed_structure`, `title_geometry`) and places the result. +//! - A top-level build reads the title's instance records, writes the scene +//! over the instances whose structure is placed (`tuxbox_bvh_layout`) and +//! places it under the address the title builds at. The scene holds the +//! places it names. A walk dispatched later finds it by the address the +//! title binds. +//! +//! Structures the title builds from geometry while it runs are not placed +//! yet: their instances are left out of the scene. +use super::{Entry, packed_structure, title_geometry}; +use crate::device::console_heap::{self, Placed}; +use crate::device::{blas, ray_build}; +use crate::diagnostics::log; +use std::sync::atomic::{AtomicU64, Ordering}; +use tuxbox_bvh_layout::{Bounds, Instance, Structure, header, write_scene}; +use windows::Win32::Graphics::Direct3D12::*; +use windows::core::IUnknown; + +type Build = D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC; + +/// A D3D12 instance record. +const INSTANCE: usize = Instance::BYTES; +/// More instances than this are not read: no scene of the title comes near. +const LIMIT: usize = 1 << 20; + +/// Whether the `count`-th of something is worth a line in the log. +fn told(count: u64) -> bool { + count <= 16 || count.is_power_of_two() +} + +/// The `count` instance records at `address`, and where they are kept. +/// +/// # Safety +/// `owner` is the list's controlling guest device. +unsafe fn instance_records( + owner: &IUnknown, + address: u64, + count: usize, + indirect: bool, +) -> (&'static str, Option<Vec<u8>>) { + if count > LIMIT { + return ("too many to read", None); + } + let read = |address: u64, out: &mut [u8]| -> Option<&'static str> { + // SAFETY: as this function's. + if unsafe { super::read_upload(owner, address, out) }.is_ok() { + return Some("an upload buffer"); + } + crate::device::read_title_bytes(address, out).then_some("title memory") + }; + let mut records = vec![0u8; count * if indirect { 8 } else { INSTANCE }]; + let Some(place) = read(address, &mut records) else { + // SAFETY: as this function's. + let gpu = unsafe { blas::default_instances(owner, address) }.is_ok(); + return (if gpu { "a buffer only the GPU reads" } else { "memory that cannot be read" }, None); + }; + if !indirect { + return (place, Some(records)); + } + let mut out = vec![0u8; count * INSTANCE]; + for (pointer, record) in records.chunks_exact(8).zip(out.chunks_exact_mut(INSTANCE)) { + if read(u64::from_le_bytes(core::array::from_fn(|byte| pointer[byte])), record).is_none() { + return ("pointers to memory that cannot be read", None); + } + } + (if place == "title memory" { "pointers in title memory" } else { "pointers in an upload buffer" }, Some(out)) +} + +/// The expansion of one entry of a rehydration call. +/// +/// # Safety +/// `build` is the title's description, live for the call. +unsafe fn expanded(build: &Build, alias: u64) -> Result<Vec<u8>, &'static str> { + let inputs = &build.Inputs; + // SAFETY: the title supplies the descriptions for the duration of the call. + if inputs.Type != D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL || !unsafe { ray_build::valid(inputs) } + { + return Err("inputs that are not valid bottom-level inputs"); + } + let packed = [build.SourceAccelerationStructureData, build.DestAccelerationStructureData, alias] + .into_iter() + .find_map(title_geometry::structure_at) + .ok_or("the structure cannot be read")?; + // SAFETY: `ray_build::valid` checked the layout and every pointer. + let geometry = unsafe { title_geometry::read(inputs) }?; + packed_structure::unpack( + &packed, + &|index, primitive| title_geometry::corners(&geometry, index, primitive), + &|index| title_geometry::transform(&geometry, index), + ) +} + +/// A rehydration call, before anything else is decided about it. +/// +/// # Safety +/// `owner` is the list's controlling guest device; `builds` holds the +/// title's descriptions for the call, and `addresses` is null or holds as many. +pub(super) unsafe fn rehydrated(owner: &IUnknown, builds: &[Build], addresses: *const u64) { + if !console_heap::enabled() { + return; + } + static CALLS: AtomicU64 = AtomicU64::new(0); + static PLACED: AtomicU64 = AtomicU64::new(0); + static LEFT: AtomicU64 = AtomicU64::new(0); + // SAFETY: as this function's. + let (heap, device) = unsafe { blas::console(owner) }; + let mut placed = 0u64; + for (index, build) in builds.iter().enumerate() { + // SAFETY: `addresses` is not null here and holds an entry for each build (`# Safety`). + let alias = if addresses.is_null() { 0 } else { unsafe { addresses.add(index).read_unaligned() } }; + // SAFETY: as this function's. + let why = match unsafe { expanded(build, alias) } { + Ok(bytes) if heap.structure(device, &[build.DestAccelerationStructureData, alias], &bytes) => { + placed += 1; + continue; + } + Ok(_) => "the buffer has no room", + Err(why) => why, ~~~~ --- An 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`.
Copilot commented 2026-12-01 17:36:47 +00:00 (Migrated from github.com)

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 200

@@ -0,0 +1,242 @@
+//! The title's structure calls, answered with console-format structures for
+//! its ray walks (`device::console_heap`, `TUXBOX_CONSOLE_STRUCTURES`).
+//!
+//! - A rehydration expands each packed structure with the geometry the call
+//!   names (`packed_structure`, `title_geometry`) and places the result.
+//! - A top-level build reads the title's instance records, writes the scene
+//!   over the instances whose structure is placed (`tuxbox_bvh_layout`) and
+//!   places it under the address the title builds at. The scene holds the
+//!   places it names. A walk dispatched later finds it by the address the
+//!   title binds.
+//!
+//! Structures the title builds from geometry while it runs are not placed
+//! yet: their instances are left out of the scene.
+use super::{Entry, packed_structure, title_geometry};
+use crate::device::console_heap::{self, Placed};
+use crate::device::{blas, ray_build};
+use crate::diagnostics::log;
+use std::sync::atomic::{AtomicU64, Ordering};
+use tuxbox_bvh_layout::{Bounds, Instance, Structure, header, write_scene};
+use windows::Win32::Graphics::Direct3D12::*;
+use windows::core::IUnknown;
+
+type Build = D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC;
+
+/// A D3D12 instance record.
+const INSTANCE: usize = Instance::BYTES;
+/// More instances than this are not read: no scene of the title comes near.
+const LIMIT: usize = 1 << 20;
+
+/// Whether the `count`-th of something is worth a line in the log.
+fn told(count: u64) -> bool {
+    count <= 16 || count.is_power_of_two()
+}
+
+/// The `count` instance records at `address`, and where they are kept.
+///
+/// # Safety
+/// `owner` is the list's controlling guest device.
+unsafe fn instance_records(
+    owner: &IUnknown,
+    address: u64,
+    count: usize,
+    indirect: bool,
+) -> (&'static str, Option<Vec<u8>>) {
+    if count > LIMIT {
+        return ("too many to read", None);
+    }
+    let read = |address: u64, out: &mut [u8]| -> Option<&'static str> {
+        // SAFETY: as this function's.
+        if unsafe { super::read_upload(owner, address, out) }.is_ok() {
+            return Some("an upload buffer");
+        }
+        crate::device::read_title_bytes(address, out).then_some("title memory")
+    };
+    let mut records = vec![0u8; count * if indirect { 8 } else { INSTANCE }];
+    let Some(place) = read(address, &mut records) else {
+        // SAFETY: as this function's.
+        let gpu = unsafe { blas::default_instances(owner, address) }.is_ok();
+        return (if gpu { "a buffer only the GPU reads" } else { "memory that cannot be read" }, None);
+    };
+    if !indirect {
+        return (place, Some(records));
+    }
+    let mut out = vec![0u8; count * INSTANCE];
+    for (pointer, record) in records.chunks_exact(8).zip(out.chunks_exact_mut(INSTANCE)) {
+        if read(u64::from_le_bytes(core::array::from_fn(|byte| pointer[byte])), record).is_none() {
+            return ("pointers to memory that cannot be read", None);
+        }
+    }
+    (if place == "title memory" { "pointers in title memory" } else { "pointers in an upload buffer" }, Some(out))
+}
+
+/// The expansion of one entry of a rehydration call.
+///
+/// # Safety
+/// `build` is the title's description, live for the call.
+unsafe fn expanded(build: &Build, alias: u64) -> Result<Vec<u8>, &'static str> {
+    let inputs = &build.Inputs;
+    // SAFETY: the title supplies the descriptions for the duration of the call.
+    if inputs.Type != D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL || !unsafe { ray_build::valid(inputs) }
+    {
+        return Err("inputs that are not valid bottom-level inputs");
+    }
+    let packed = [build.SourceAccelerationStructureData, build.DestAccelerationStructureData, alias]
+        .into_iter()
+        .find_map(title_geometry::structure_at)
+        .ok_or("the structure cannot be read")?;
+    // SAFETY: `ray_build::valid` checked the layout and every pointer.
+    let geometry = unsafe { title_geometry::read(inputs) }?;
+    packed_structure::unpack(
+        &packed,
+        &|index, primitive| title_geometry::corners(&geometry, index, primitive),
+        &|index| title_geometry::transform(&geometry, index),
+    )
+}
+
+/// A rehydration call, before anything else is decided about it.
+///
+/// # Safety
+/// `owner` is the list's controlling guest device; `builds` holds the
+/// title's descriptions for the call, and `addresses` is null or holds as many.
+pub(super) unsafe fn rehydrated(owner: &IUnknown, builds: &[Build], addresses: *const u64) {
+    if !console_heap::enabled() {
+        return;
+    }
+    static CALLS: AtomicU64 = AtomicU64::new(0);
+    static PLACED: AtomicU64 = AtomicU64::new(0);
+    static LEFT: AtomicU64 = AtomicU64::new(0);
+    // SAFETY: as this function's.
+    let (heap, device) = unsafe { blas::console(owner) };
+    let mut placed = 0u64;
+    for (index, build) in builds.iter().enumerate() {
+        // SAFETY: `addresses` is not null here and holds an entry for each build (`# Safety`).
+        let alias = if addresses.is_null() { 0 } else { unsafe { addresses.add(index).read_unaligned() } };
+        // SAFETY: as this function's.
+        let why = match unsafe { expanded(build, alias) } {
+            Ok(bytes) if heap.structure(device, &[build.DestAccelerationStructureData, alias], &bytes) => {
+                placed += 1;
+                continue;
+            }
+            Ok(_) => "the buffer has no room",
+            Err(why) => why,
+        };
+        let left = LEFT.fetch_add(1, Ordering::Relaxed) + 1;
+        if told(left) {
+            log(&format!(
+                "console structures: the structure at {:#x} is not placed: {why} (#{left})",
+                build.DestAccelerationStructureData
+            ));
+        }
+    }
+    let call = CALLS.fetch_add(1, Ordering::Relaxed) + 1;
+    let total = PLACED.fetch_add(placed, Ordering::Relaxed) + placed;
+    if call <= 8 || call.is_power_of_two() {
+        let (_, _, used) = heap.totals();
+        log(&format!(
+            "console structures: rehydration call #{call} placed {placed} of {} structures ({total} placed and {} left out so far, {} MiB used)",
+            builds.len(),
+            LEFT.load(Ordering::Relaxed),
+            used >> 20
+        ));
+    }
+}
+
+/// The bottom-level builds of a build call. A structure the title builds
+/// from geometry while it runs is not written yet, so whatever was placed
+/// under its address is no longer what the title has there.
+///
+/// # Safety
+/// `owner` is the list's controlling guest device.
+pub(super) unsafe fn built(owner: Option<&IUnknown>, entries: &[Entry]) {
+    let Some(owner) = owner.filter(|_| console_heap::enabled()) else { return };
+    // SAFETY: as this function's.
+    let (heap, _) = unsafe { blas::console(owner) };
+    for entry in entries {
+        if entry.build.Inputs.Type == D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL {
+            heap.forget(entry.build.DestAccelerationStructureData);
+        }
+    }
+}
+
+/// What a scene's instance record takes from a placed structure: its place
+/// and, from its header, its root, the word of its leaf frame and its bounds.
+fn structure(placed: &Placed) -> Structure {
+    let word = |index: usize| u32::from_le_bytes(core::array::from_fn(|byte| placed.header[4 * index + byte]));
+    let bound = |index: usize| f32::from_bits(word(header::BOUNDS + index));
+    Structure {
+        offset: placed.offset,
+        root: word(header::ROOT),
+        compression: word(header::COMPRESSION),
+        bounds: Bounds { min: core::array::from_fn(bound), max: core::array::from_fn(|axis| bound(3 + axis)) },
+    }
+}
+
+/// The top-level builds of a build call, before anything else is decided
+/// about them.
+///
+/// # Safety
+/// `owner` is the list's controlling guest device, and `entries` holds the
+/// title's descriptions for the call.
+pub(super) unsafe fn scenes(owner: Option<&IUnknown>, entries: &[Entry]) {
+    let Some(owner) = owner.filter(|_| console_heap::enabled()) else { return };
+    static SCENES: AtomicU64 = AtomicU64::new(0);
+    // SAFETY: as this function's.
+    let (heap, device) = unsafe { blas::console(owner) };
+    for entry in entries {
+        let build = &entry.build;
+        if build.Inputs.Type != D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL {
+            continue;
+        }
+        let number = SCENES.fetch_add(1, Ordering::Relaxed) + 1;
+        let (destination, count) = (build.DestAccelerationStructureData, build.Inputs.NumDescs as usize);
+        let indirect = build.Inputs.DescsLayout == D3D12_ELEMENTS_LAYOUT_ARRAY_OF_POINTERS;
+        // SAFETY: a top-level build's inputs hold the address of its instances.
+        let address = unsafe { build.Inputs.Anonymous.InstanceDescs };
+        let (place, records) = if count == 0 {
+            ("no instances", Some(Vec::new()))
+        } else {
+            // SAFETY: as this function's.
+            unsafe { instance_records(owner, address, count, indirect) }

This 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::prepare at 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.

<!-- greyfinch-sync:brcly/TuxBox:review-comment:4758281856 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/596#discussion_r4758281856). Originally posted by [Copilot](https://github.com/apps/copilot-pull-request-reviewer) on 2026-12-01T17:36:47Z. **Code review location:** `runtime/d3d12/src/commands/build_raytracing/console.rs`; line 200 ~~~~diff @@ -0,0 +1,242 @@ +//! The title's structure calls, answered with console-format structures for +//! its ray walks (`device::console_heap`, `TUXBOX_CONSOLE_STRUCTURES`). +//! +//! - A rehydration expands each packed structure with the geometry the call +//! names (`packed_structure`, `title_geometry`) and places the result. +//! - A top-level build reads the title's instance records, writes the scene +//! over the instances whose structure is placed (`tuxbox_bvh_layout`) and +//! places it under the address the title builds at. The scene holds the +//! places it names. A walk dispatched later finds it by the address the +//! title binds. +//! +//! Structures the title builds from geometry while it runs are not placed +//! yet: their instances are left out of the scene. +use super::{Entry, packed_structure, title_geometry}; +use crate::device::console_heap::{self, Placed}; +use crate::device::{blas, ray_build}; +use crate::diagnostics::log; +use std::sync::atomic::{AtomicU64, Ordering}; +use tuxbox_bvh_layout::{Bounds, Instance, Structure, header, write_scene}; +use windows::Win32::Graphics::Direct3D12::*; +use windows::core::IUnknown; + +type Build = D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC; + +/// A D3D12 instance record. +const INSTANCE: usize = Instance::BYTES; +/// More instances than this are not read: no scene of the title comes near. +const LIMIT: usize = 1 << 20; + +/// Whether the `count`-th of something is worth a line in the log. +fn told(count: u64) -> bool { + count <= 16 || count.is_power_of_two() +} + +/// The `count` instance records at `address`, and where they are kept. +/// +/// # Safety +/// `owner` is the list's controlling guest device. +unsafe fn instance_records( + owner: &IUnknown, + address: u64, + count: usize, + indirect: bool, +) -> (&'static str, Option<Vec<u8>>) { + if count > LIMIT { + return ("too many to read", None); + } + let read = |address: u64, out: &mut [u8]| -> Option<&'static str> { + // SAFETY: as this function's. + if unsafe { super::read_upload(owner, address, out) }.is_ok() { + return Some("an upload buffer"); + } + crate::device::read_title_bytes(address, out).then_some("title memory") + }; + let mut records = vec![0u8; count * if indirect { 8 } else { INSTANCE }]; + let Some(place) = read(address, &mut records) else { + // SAFETY: as this function's. + let gpu = unsafe { blas::default_instances(owner, address) }.is_ok(); + return (if gpu { "a buffer only the GPU reads" } else { "memory that cannot be read" }, None); + }; + if !indirect { + return (place, Some(records)); + } + let mut out = vec![0u8; count * INSTANCE]; + for (pointer, record) in records.chunks_exact(8).zip(out.chunks_exact_mut(INSTANCE)) { + if read(u64::from_le_bytes(core::array::from_fn(|byte| pointer[byte])), record).is_none() { + return ("pointers to memory that cannot be read", None); + } + } + (if place == "title memory" { "pointers in title memory" } else { "pointers in an upload buffer" }, Some(out)) +} + +/// The expansion of one entry of a rehydration call. +/// +/// # Safety +/// `build` is the title's description, live for the call. +unsafe fn expanded(build: &Build, alias: u64) -> Result<Vec<u8>, &'static str> { + let inputs = &build.Inputs; + // SAFETY: the title supplies the descriptions for the duration of the call. + if inputs.Type != D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL || !unsafe { ray_build::valid(inputs) } + { + return Err("inputs that are not valid bottom-level inputs"); + } + let packed = [build.SourceAccelerationStructureData, build.DestAccelerationStructureData, alias] + .into_iter() + .find_map(title_geometry::structure_at) + .ok_or("the structure cannot be read")?; + // SAFETY: `ray_build::valid` checked the layout and every pointer. + let geometry = unsafe { title_geometry::read(inputs) }?; + packed_structure::unpack( + &packed, + &|index, primitive| title_geometry::corners(&geometry, index, primitive), + &|index| title_geometry::transform(&geometry, index), + ) +} + +/// A rehydration call, before anything else is decided about it. +/// +/// # Safety +/// `owner` is the list's controlling guest device; `builds` holds the +/// title's descriptions for the call, and `addresses` is null or holds as many. +pub(super) unsafe fn rehydrated(owner: &IUnknown, builds: &[Build], addresses: *const u64) { + if !console_heap::enabled() { + return; + } + static CALLS: AtomicU64 = AtomicU64::new(0); + static PLACED: AtomicU64 = AtomicU64::new(0); + static LEFT: AtomicU64 = AtomicU64::new(0); + // SAFETY: as this function's. + let (heap, device) = unsafe { blas::console(owner) }; + let mut placed = 0u64; + for (index, build) in builds.iter().enumerate() { + // SAFETY: `addresses` is not null here and holds an entry for each build (`# Safety`). + let alias = if addresses.is_null() { 0 } else { unsafe { addresses.add(index).read_unaligned() } }; + // SAFETY: as this function's. + let why = match unsafe { expanded(build, alias) } { + Ok(bytes) if heap.structure(device, &[build.DestAccelerationStructureData, alias], &bytes) => { + placed += 1; + continue; + } + Ok(_) => "the buffer has no room", + Err(why) => why, + }; + let left = LEFT.fetch_add(1, Ordering::Relaxed) + 1; + if told(left) { + log(&format!( + "console structures: the structure at {:#x} is not placed: {why} (#{left})", + build.DestAccelerationStructureData + )); + } + } + let call = CALLS.fetch_add(1, Ordering::Relaxed) + 1; + let total = PLACED.fetch_add(placed, Ordering::Relaxed) + placed; + if call <= 8 || call.is_power_of_two() { + let (_, _, used) = heap.totals(); + log(&format!( + "console structures: rehydration call #{call} placed {placed} of {} structures ({total} placed and {} left out so far, {} MiB used)", + builds.len(), + LEFT.load(Ordering::Relaxed), + used >> 20 + )); + } +} + +/// The bottom-level builds of a build call. A structure the title builds +/// from geometry while it runs is not written yet, so whatever was placed +/// under its address is no longer what the title has there. +/// +/// # Safety +/// `owner` is the list's controlling guest device. +pub(super) unsafe fn built(owner: Option<&IUnknown>, entries: &[Entry]) { + let Some(owner) = owner.filter(|_| console_heap::enabled()) else { return }; + // SAFETY: as this function's. + let (heap, _) = unsafe { blas::console(owner) }; + for entry in entries { + if entry.build.Inputs.Type == D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL { + heap.forget(entry.build.DestAccelerationStructureData); + } + } +} + +/// What a scene's instance record takes from a placed structure: its place +/// and, from its header, its root, the word of its leaf frame and its bounds. +fn structure(placed: &Placed) -> Structure { + let word = |index: usize| u32::from_le_bytes(core::array::from_fn(|byte| placed.header[4 * index + byte])); + let bound = |index: usize| f32::from_bits(word(header::BOUNDS + index)); + Structure { + offset: placed.offset, + root: word(header::ROOT), + compression: word(header::COMPRESSION), + bounds: Bounds { min: core::array::from_fn(bound), max: core::array::from_fn(|axis| bound(3 + axis)) }, + } +} + +/// The top-level builds of a build call, before anything else is decided +/// about them. +/// +/// # Safety +/// `owner` is the list's controlling guest device, and `entries` holds the +/// title's descriptions for the call. +pub(super) unsafe fn scenes(owner: Option<&IUnknown>, entries: &[Entry]) { + let Some(owner) = owner.filter(|_| console_heap::enabled()) else { return }; + static SCENES: AtomicU64 = AtomicU64::new(0); + // SAFETY: as this function's. + let (heap, device) = unsafe { blas::console(owner) }; + for entry in entries { + let build = &entry.build; + if build.Inputs.Type != D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL { + continue; + } + let number = SCENES.fetch_add(1, Ordering::Relaxed) + 1; + let (destination, count) = (build.DestAccelerationStructureData, build.Inputs.NumDescs as usize); + let indirect = build.Inputs.DescsLayout == D3D12_ELEMENTS_LAYOUT_ARRAY_OF_POINTERS; + // SAFETY: a top-level build's inputs hold the address of its instances. + let address = unsafe { build.Inputs.Anonymous.InstanceDescs }; + let (place, records) = if count == 0 { + ("no instances", Some(Vec::new())) + } else { + // SAFETY: as this function's. + unsafe { instance_records(owner, address, count, indirect) } ~~~~ --- This 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::prepare` at 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.
Copilot commented 2026-12-01 17:36:47 +00:00 (Migrated from github.com)

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 208

@@ -0,0 +1,242 @@
+//! The title's structure calls, answered with console-format structures for
+//! its ray walks (`device::console_heap`, `TUXBOX_CONSOLE_STRUCTURES`).
+//!
+//! - A rehydration expands each packed structure with the geometry the call
+//!   names (`packed_structure`, `title_geometry`) and places the result.
+//! - A top-level build reads the title's instance records, writes the scene
+//!   over the instances whose structure is placed (`tuxbox_bvh_layout`) and
+//!   places it under the address the title builds at. The scene holds the
+//!   places it names. A walk dispatched later finds it by the address the
+//!   title binds.
+//!
+//! Structures the title builds from geometry while it runs are not placed
+//! yet: their instances are left out of the scene.
+use super::{Entry, packed_structure, title_geometry};
+use crate::device::console_heap::{self, Placed};
+use crate::device::{blas, ray_build};
+use crate::diagnostics::log;
+use std::sync::atomic::{AtomicU64, Ordering};
+use tuxbox_bvh_layout::{Bounds, Instance, Structure, header, write_scene};
+use windows::Win32::Graphics::Direct3D12::*;
+use windows::core::IUnknown;
+
+type Build = D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC;
+
+/// A D3D12 instance record.
+const INSTANCE: usize = Instance::BYTES;
+/// More instances than this are not read: no scene of the title comes near.
+const LIMIT: usize = 1 << 20;
+
+/// Whether the `count`-th of something is worth a line in the log.
+fn told(count: u64) -> bool {
+    count <= 16 || count.is_power_of_two()
+}
+
+/// The `count` instance records at `address`, and where they are kept.
+///
+/// # Safety
+/// `owner` is the list's controlling guest device.
+unsafe fn instance_records(
+    owner: &IUnknown,
+    address: u64,
+    count: usize,
+    indirect: bool,
+) -> (&'static str, Option<Vec<u8>>) {
+    if count > LIMIT {
+        return ("too many to read", None);
+    }
+    let read = |address: u64, out: &mut [u8]| -> Option<&'static str> {
+        // SAFETY: as this function's.
+        if unsafe { super::read_upload(owner, address, out) }.is_ok() {
+            return Some("an upload buffer");
+        }
+        crate::device::read_title_bytes(address, out).then_some("title memory")
+    };
+    let mut records = vec![0u8; count * if indirect { 8 } else { INSTANCE }];
+    let Some(place) = read(address, &mut records) else {
+        // SAFETY: as this function's.
+        let gpu = unsafe { blas::default_instances(owner, address) }.is_ok();
+        return (if gpu { "a buffer only the GPU reads" } else { "memory that cannot be read" }, None);
+    };
+    if !indirect {
+        return (place, Some(records));
+    }
+    let mut out = vec![0u8; count * INSTANCE];
+    for (pointer, record) in records.chunks_exact(8).zip(out.chunks_exact_mut(INSTANCE)) {
+        if read(u64::from_le_bytes(core::array::from_fn(|byte| pointer[byte])), record).is_none() {
+            return ("pointers to memory that cannot be read", None);
+        }
+    }
+    (if place == "title memory" { "pointers in title memory" } else { "pointers in an upload buffer" }, Some(out))
+}
+
+/// The expansion of one entry of a rehydration call.
+///
+/// # Safety
+/// `build` is the title's description, live for the call.
+unsafe fn expanded(build: &Build, alias: u64) -> Result<Vec<u8>, &'static str> {
+    let inputs = &build.Inputs;
+    // SAFETY: the title supplies the descriptions for the duration of the call.
+    if inputs.Type != D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL || !unsafe { ray_build::valid(inputs) }
+    {
+        return Err("inputs that are not valid bottom-level inputs");
+    }
+    let packed = [build.SourceAccelerationStructureData, build.DestAccelerationStructureData, alias]
+        .into_iter()
+        .find_map(title_geometry::structure_at)
+        .ok_or("the structure cannot be read")?;
+    // SAFETY: `ray_build::valid` checked the layout and every pointer.
+    let geometry = unsafe { title_geometry::read(inputs) }?;
+    packed_structure::unpack(
+        &packed,
+        &|index, primitive| title_geometry::corners(&geometry, index, primitive),
+        &|index| title_geometry::transform(&geometry, index),
+    )
+}
+
+/// A rehydration call, before anything else is decided about it.
+///
+/// # Safety
+/// `owner` is the list's controlling guest device; `builds` holds the
+/// title's descriptions for the call, and `addresses` is null or holds as many.
+pub(super) unsafe fn rehydrated(owner: &IUnknown, builds: &[Build], addresses: *const u64) {
+    if !console_heap::enabled() {
+        return;
+    }
+    static CALLS: AtomicU64 = AtomicU64::new(0);
+    static PLACED: AtomicU64 = AtomicU64::new(0);
+    static LEFT: AtomicU64 = AtomicU64::new(0);
+    // SAFETY: as this function's.
+    let (heap, device) = unsafe { blas::console(owner) };
+    let mut placed = 0u64;
+    for (index, build) in builds.iter().enumerate() {
+        // SAFETY: `addresses` is not null here and holds an entry for each build (`# Safety`).
+        let alias = if addresses.is_null() { 0 } else { unsafe { addresses.add(index).read_unaligned() } };
+        // SAFETY: as this function's.
+        let why = match unsafe { expanded(build, alias) } {
+            Ok(bytes) if heap.structure(device, &[build.DestAccelerationStructureData, alias], &bytes) => {
+                placed += 1;
+                continue;
+            }
+            Ok(_) => "the buffer has no room",
+            Err(why) => why,
+        };
+        let left = LEFT.fetch_add(1, Ordering::Relaxed) + 1;
+        if told(left) {
+            log(&format!(
+                "console structures: the structure at {:#x} is not placed: {why} (#{left})",
+                build.DestAccelerationStructureData
+            ));
+        }
+    }
+    let call = CALLS.fetch_add(1, Ordering::Relaxed) + 1;
+    let total = PLACED.fetch_add(placed, Ordering::Relaxed) + placed;
+    if call <= 8 || call.is_power_of_two() {
+        let (_, _, used) = heap.totals();
+        log(&format!(
+            "console structures: rehydration call #{call} placed {placed} of {} structures ({total} placed and {} left out so far, {} MiB used)",
+            builds.len(),
+            LEFT.load(Ordering::Relaxed),
+            used >> 20
+        ));
+    }
+}
+
+/// The bottom-level builds of a build call. A structure the title builds
+/// from geometry while it runs is not written yet, so whatever was placed
+/// under its address is no longer what the title has there.
+///
+/// # Safety
+/// `owner` is the list's controlling guest device.
+pub(super) unsafe fn built(owner: Option<&IUnknown>, entries: &[Entry]) {
+    let Some(owner) = owner.filter(|_| console_heap::enabled()) else { return };
+    // SAFETY: as this function's.
+    let (heap, _) = unsafe { blas::console(owner) };
+    for entry in entries {
+        if entry.build.Inputs.Type == D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL {
+            heap.forget(entry.build.DestAccelerationStructureData);
+        }
+    }
+}
+
+/// What a scene's instance record takes from a placed structure: its place
+/// and, from its header, its root, the word of its leaf frame and its bounds.
+fn structure(placed: &Placed) -> Structure {
+    let word = |index: usize| u32::from_le_bytes(core::array::from_fn(|byte| placed.header[4 * index + byte]));
+    let bound = |index: usize| f32::from_bits(word(header::BOUNDS + index));
+    Structure {
+        offset: placed.offset,
+        root: word(header::ROOT),
+        compression: word(header::COMPRESSION),
+        bounds: Bounds { min: core::array::from_fn(bound), max: core::array::from_fn(|axis| bound(3 + axis)) },
+    }
+}
+
+/// The top-level builds of a build call, before anything else is decided
+/// about them.
+///
+/// # Safety
+/// `owner` is the list's controlling guest device, and `entries` holds the
+/// title's descriptions for the call.
+pub(super) unsafe fn scenes(owner: Option<&IUnknown>, entries: &[Entry]) {
+    let Some(owner) = owner.filter(|_| console_heap::enabled()) else { return };
+    static SCENES: AtomicU64 = AtomicU64::new(0);
+    // SAFETY: as this function's.
+    let (heap, device) = unsafe { blas::console(owner) };
+    for entry in entries {
+        let build = &entry.build;
+        if build.Inputs.Type != D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL {
+            continue;
+        }
+        let number = SCENES.fetch_add(1, Ordering::Relaxed) + 1;
+        let (destination, count) = (build.DestAccelerationStructureData, build.Inputs.NumDescs as usize);
+        let indirect = build.Inputs.DescsLayout == D3D12_ELEMENTS_LAYOUT_ARRAY_OF_POINTERS;
+        // SAFETY: a top-level build's inputs hold the address of its instances.
+        let address = unsafe { build.Inputs.Anonymous.InstanceDescs };
+        let (place, records) = if count == 0 {
+            ("no instances", Some(Vec::new()))
+        } else {
+            // SAFETY: as this function's.
+            unsafe { instance_records(owner, address, count, indirect) }
+        };
+        let Some(records) = records else {
+            if told(number) {
+                log(&format!(
+                    "console scene #{number} at {destination:#x}: its {count} instance records are in {place}; the scene is not placed"
+                ));
+            }
+            continue;

If 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 on ConsoleHeap and invoke it before continuing here, releasing the old scene's structure holds as well.

<!-- greyfinch-sync:brcly/TuxBox:review-comment:4758281902 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/596#discussion_r4758281902). Originally posted by [Copilot](https://github.com/apps/copilot-pull-request-reviewer) on 2026-12-01T17:36:47Z. **Code review location:** `runtime/d3d12/src/commands/build_raytracing/console.rs`; line 208 ~~~~diff @@ -0,0 +1,242 @@ +//! The title's structure calls, answered with console-format structures for +//! its ray walks (`device::console_heap`, `TUXBOX_CONSOLE_STRUCTURES`). +//! +//! - A rehydration expands each packed structure with the geometry the call +//! names (`packed_structure`, `title_geometry`) and places the result. +//! - A top-level build reads the title's instance records, writes the scene +//! over the instances whose structure is placed (`tuxbox_bvh_layout`) and +//! places it under the address the title builds at. The scene holds the +//! places it names. A walk dispatched later finds it by the address the +//! title binds. +//! +//! Structures the title builds from geometry while it runs are not placed +//! yet: their instances are left out of the scene. +use super::{Entry, packed_structure, title_geometry}; +use crate::device::console_heap::{self, Placed}; +use crate::device::{blas, ray_build}; +use crate::diagnostics::log; +use std::sync::atomic::{AtomicU64, Ordering}; +use tuxbox_bvh_layout::{Bounds, Instance, Structure, header, write_scene}; +use windows::Win32::Graphics::Direct3D12::*; +use windows::core::IUnknown; + +type Build = D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC; + +/// A D3D12 instance record. +const INSTANCE: usize = Instance::BYTES; +/// More instances than this are not read: no scene of the title comes near. +const LIMIT: usize = 1 << 20; + +/// Whether the `count`-th of something is worth a line in the log. +fn told(count: u64) -> bool { + count <= 16 || count.is_power_of_two() +} + +/// The `count` instance records at `address`, and where they are kept. +/// +/// # Safety +/// `owner` is the list's controlling guest device. +unsafe fn instance_records( + owner: &IUnknown, + address: u64, + count: usize, + indirect: bool, +) -> (&'static str, Option<Vec<u8>>) { + if count > LIMIT { + return ("too many to read", None); + } + let read = |address: u64, out: &mut [u8]| -> Option<&'static str> { + // SAFETY: as this function's. + if unsafe { super::read_upload(owner, address, out) }.is_ok() { + return Some("an upload buffer"); + } + crate::device::read_title_bytes(address, out).then_some("title memory") + }; + let mut records = vec![0u8; count * if indirect { 8 } else { INSTANCE }]; + let Some(place) = read(address, &mut records) else { + // SAFETY: as this function's. + let gpu = unsafe { blas::default_instances(owner, address) }.is_ok(); + return (if gpu { "a buffer only the GPU reads" } else { "memory that cannot be read" }, None); + }; + if !indirect { + return (place, Some(records)); + } + let mut out = vec![0u8; count * INSTANCE]; + for (pointer, record) in records.chunks_exact(8).zip(out.chunks_exact_mut(INSTANCE)) { + if read(u64::from_le_bytes(core::array::from_fn(|byte| pointer[byte])), record).is_none() { + return ("pointers to memory that cannot be read", None); + } + } + (if place == "title memory" { "pointers in title memory" } else { "pointers in an upload buffer" }, Some(out)) +} + +/// The expansion of one entry of a rehydration call. +/// +/// # Safety +/// `build` is the title's description, live for the call. +unsafe fn expanded(build: &Build, alias: u64) -> Result<Vec<u8>, &'static str> { + let inputs = &build.Inputs; + // SAFETY: the title supplies the descriptions for the duration of the call. + if inputs.Type != D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL || !unsafe { ray_build::valid(inputs) } + { + return Err("inputs that are not valid bottom-level inputs"); + } + let packed = [build.SourceAccelerationStructureData, build.DestAccelerationStructureData, alias] + .into_iter() + .find_map(title_geometry::structure_at) + .ok_or("the structure cannot be read")?; + // SAFETY: `ray_build::valid` checked the layout and every pointer. + let geometry = unsafe { title_geometry::read(inputs) }?; + packed_structure::unpack( + &packed, + &|index, primitive| title_geometry::corners(&geometry, index, primitive), + &|index| title_geometry::transform(&geometry, index), + ) +} + +/// A rehydration call, before anything else is decided about it. +/// +/// # Safety +/// `owner` is the list's controlling guest device; `builds` holds the +/// title's descriptions for the call, and `addresses` is null or holds as many. +pub(super) unsafe fn rehydrated(owner: &IUnknown, builds: &[Build], addresses: *const u64) { + if !console_heap::enabled() { + return; + } + static CALLS: AtomicU64 = AtomicU64::new(0); + static PLACED: AtomicU64 = AtomicU64::new(0); + static LEFT: AtomicU64 = AtomicU64::new(0); + // SAFETY: as this function's. + let (heap, device) = unsafe { blas::console(owner) }; + let mut placed = 0u64; + for (index, build) in builds.iter().enumerate() { + // SAFETY: `addresses` is not null here and holds an entry for each build (`# Safety`). + let alias = if addresses.is_null() { 0 } else { unsafe { addresses.add(index).read_unaligned() } }; + // SAFETY: as this function's. + let why = match unsafe { expanded(build, alias) } { + Ok(bytes) if heap.structure(device, &[build.DestAccelerationStructureData, alias], &bytes) => { + placed += 1; + continue; + } + Ok(_) => "the buffer has no room", + Err(why) => why, + }; + let left = LEFT.fetch_add(1, Ordering::Relaxed) + 1; + if told(left) { + log(&format!( + "console structures: the structure at {:#x} is not placed: {why} (#{left})", + build.DestAccelerationStructureData + )); + } + } + let call = CALLS.fetch_add(1, Ordering::Relaxed) + 1; + let total = PLACED.fetch_add(placed, Ordering::Relaxed) + placed; + if call <= 8 || call.is_power_of_two() { + let (_, _, used) = heap.totals(); + log(&format!( + "console structures: rehydration call #{call} placed {placed} of {} structures ({total} placed and {} left out so far, {} MiB used)", + builds.len(), + LEFT.load(Ordering::Relaxed), + used >> 20 + )); + } +} + +/// The bottom-level builds of a build call. A structure the title builds +/// from geometry while it runs is not written yet, so whatever was placed +/// under its address is no longer what the title has there. +/// +/// # Safety +/// `owner` is the list's controlling guest device. +pub(super) unsafe fn built(owner: Option<&IUnknown>, entries: &[Entry]) { + let Some(owner) = owner.filter(|_| console_heap::enabled()) else { return }; + // SAFETY: as this function's. + let (heap, _) = unsafe { blas::console(owner) }; + for entry in entries { + if entry.build.Inputs.Type == D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL { + heap.forget(entry.build.DestAccelerationStructureData); + } + } +} + +/// What a scene's instance record takes from a placed structure: its place +/// and, from its header, its root, the word of its leaf frame and its bounds. +fn structure(placed: &Placed) -> Structure { + let word = |index: usize| u32::from_le_bytes(core::array::from_fn(|byte| placed.header[4 * index + byte])); + let bound = |index: usize| f32::from_bits(word(header::BOUNDS + index)); + Structure { + offset: placed.offset, + root: word(header::ROOT), + compression: word(header::COMPRESSION), + bounds: Bounds { min: core::array::from_fn(bound), max: core::array::from_fn(|axis| bound(3 + axis)) }, + } +} + +/// The top-level builds of a build call, before anything else is decided +/// about them. +/// +/// # Safety +/// `owner` is the list's controlling guest device, and `entries` holds the +/// title's descriptions for the call. +pub(super) unsafe fn scenes(owner: Option<&IUnknown>, entries: &[Entry]) { + let Some(owner) = owner.filter(|_| console_heap::enabled()) else { return }; + static SCENES: AtomicU64 = AtomicU64::new(0); + // SAFETY: as this function's. + let (heap, device) = unsafe { blas::console(owner) }; + for entry in entries { + let build = &entry.build; + if build.Inputs.Type != D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL { + continue; + } + let number = SCENES.fetch_add(1, Ordering::Relaxed) + 1; + let (destination, count) = (build.DestAccelerationStructureData, build.Inputs.NumDescs as usize); + let indirect = build.Inputs.DescsLayout == D3D12_ELEMENTS_LAYOUT_ARRAY_OF_POINTERS; + // SAFETY: a top-level build's inputs hold the address of its instances. + let address = unsafe { build.Inputs.Anonymous.InstanceDescs }; + let (place, records) = if count == 0 { + ("no instances", Some(Vec::new())) + } else { + // SAFETY: as this function's. + unsafe { instance_records(owner, address, count, indirect) } + }; + let Some(records) = records else { + if told(number) { + log(&format!( + "console scene #{number} at {destination:#x}: its {count} instance records are in {place}; the scene is not placed" + )); + } + continue; ~~~~ --- If 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 on `ConsoleHeap` and invoke it before continuing here, releasing the old scene's structure holds as well.
Copilot commented 2026-12-01 17:36:48 +00:00 (Migrated from github.com)

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 699

@@ -606,6 +614,115 @@ impl Bindings {
         Ok(())
     }
 
+    /// The address of the structure the title has bound where `source` says.
+    fn scene_address(
+        &self,
+        owner: &IUnknown,
+        source: SceneSource,
+        arena: Option<&Arc<crate::device::descriptor_paging::Arena>>,
+    ) -> Option<u64> {
+        match source {
+            SceneSource::RootSrv(slot) => match self.compute_args.get(&slot) {
+                Some(Argument::Buffer(BufferView::Srv(address))) => Some(*address),
+                _ => None,
+            },
+            SceneSource::Table { slot, offset } => {
+                let Some(Argument::Table(table)) = self.compute_args.get(&slot) else { return None };
+                let view = match arena.filter(|arena| arena.contains(table.logical.ptr)) {
+                    Some(arena) => arena.view(
+                        usize::try_from(table.logical.ptr).ok()?.checked_add(offset as usize * arena.guest_stride())?,
+                    )?,
+                    // Not a paged table: nothing is leased to read its entry.
+                    None => self
+                        .table_entry(
+                            slot,
+                            offset,
+                            None,
+                            &mut crate::device::descriptor_paging::DescriptorLeases::default(),
+                        )
+                        .ok()?,
+                };
+                // SAFETY: `owner` is the list's controlling guest device.
+                unsafe { crate::device::blas::scene_view_address(owner, view) }
+            }
+        }
+    }
+
+    /// What to bind for the console walk of `root` when console-format
+    /// structures are placed (`device::console_heap`): the buffer, and for a
+    /// walk that declares them the block of offsets of the scenes the title
+    /// has bound. A scene the title has not bound, or that is not placed, is
+    /// the scene of no instance.
+    pub(super) fn console_scenes(
+        &self,
+        guest: &super::List,
+        root: &SceneRoot,
+        arena: Option<&Arc<crate::device::descriptor_paging::Arena>>,
+    ) -> Option<(u64, Option<u64>)> {
+        use crate::device::console_heap::{self, EMPTY_SCENE, SCENES};
+        let declares_offsets = root.bvh.as_ref()?.offsets();
+        if !console_heap::enabled() {
+            return None;
+        }
+        if !console_heap::walks(&root.program.source_hash) {
+            crate::diagnostics::log_once(&root.program.first_console, || {
+                format!(
+                    "console walk {}: not listed in TUXBOX_CONSOLE_WALKS, it keeps its empty buffer",
+                    root.program.source_hash
+                )
+            });
+            return None;
+        }
+        let owner = guest.parent.as_ref()?;
+        // SAFETY: `owner` is the list's controlling guest device.
+        let (heap, device) = unsafe { crate::device::blas::console(owner) };
+        if !declares_offsets {
+            // The walk reaches its nodes from what another pass left it: an
+            // address in the buffer the scenes are in.
+            let nodes = heap.buffer();
+            crate::diagnostics::log_once(&root.program.first_console, || {
+                format!(
+                    "console walk {}: it declares no scene offsets and is given {}",
+                    root.program.source_hash,
+                    if nodes.is_some() { "the buffer alone" } else { "nothing yet: it keeps its empty buffer" }
+                )
+            });
+            return nodes.map(|nodes| (nodes, None));
+        }
+        let mut offsets = [EMPTY_SCENE; SCENES];
+        let mut found = Vec::with_capacity(root.console.len());
+        for (index, source) in root.console.iter().enumerate().take(SCENES) {
+            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;

Resolving 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.

<!-- greyfinch-sync:brcly/TuxBox:review-comment:4758281949 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/596#discussion_r4758281949). Originally posted by [Copilot](https://github.com/apps/copilot-pull-request-reviewer) on 2026-12-01T17:36:48Z. **Code review location:** `runtime/d3d12/src/commands/compute_bindings.rs`; line 699 ~~~~diff @@ -606,6 +614,115 @@ impl Bindings { Ok(()) } + /// The address of the structure the title has bound where `source` says. + fn scene_address( + &self, + owner: &IUnknown, + source: SceneSource, + arena: Option<&Arc<crate::device::descriptor_paging::Arena>>, + ) -> Option<u64> { + match source { + SceneSource::RootSrv(slot) => match self.compute_args.get(&slot) { + Some(Argument::Buffer(BufferView::Srv(address))) => Some(*address), + _ => None, + }, + SceneSource::Table { slot, offset } => { + let Some(Argument::Table(table)) = self.compute_args.get(&slot) else { return None }; + let view = match arena.filter(|arena| arena.contains(table.logical.ptr)) { + Some(arena) => arena.view( + usize::try_from(table.logical.ptr).ok()?.checked_add(offset as usize * arena.guest_stride())?, + )?, + // Not a paged table: nothing is leased to read its entry. + None => self + .table_entry( + slot, + offset, + None, + &mut crate::device::descriptor_paging::DescriptorLeases::default(), + ) + .ok()?, + }; + // SAFETY: `owner` is the list's controlling guest device. + unsafe { crate::device::blas::scene_view_address(owner, view) } + } + } + } + + /// What to bind for the console walk of `root` when console-format + /// structures are placed (`device::console_heap`): the buffer, and for a + /// walk that declares them the block of offsets of the scenes the title + /// has bound. A scene the title has not bound, or that is not placed, is + /// the scene of no instance. + pub(super) fn console_scenes( + &self, + guest: &super::List, + root: &SceneRoot, + arena: Option<&Arc<crate::device::descriptor_paging::Arena>>, + ) -> Option<(u64, Option<u64>)> { + use crate::device::console_heap::{self, EMPTY_SCENE, SCENES}; + let declares_offsets = root.bvh.as_ref()?.offsets(); + if !console_heap::enabled() { + return None; + } + if !console_heap::walks(&root.program.source_hash) { + crate::diagnostics::log_once(&root.program.first_console, || { + format!( + "console walk {}: not listed in TUXBOX_CONSOLE_WALKS, it keeps its empty buffer", + root.program.source_hash + ) + }); + return None; + } + let owner = guest.parent.as_ref()?; + // SAFETY: `owner` is the list's controlling guest device. + let (heap, device) = unsafe { crate::device::blas::console(owner) }; + if !declares_offsets { + // The walk reaches its nodes from what another pass left it: an + // address in the buffer the scenes are in. + let nodes = heap.buffer(); + crate::diagnostics::log_once(&root.program.first_console, || { + format!( + "console walk {}: it declares no scene offsets and is given {}", + root.program.source_hash, + if nodes.is_some() { "the buffer alone" } else { "nothing yet: it keeps its empty buffer" } + ) + }); + return nodes.map(|nodes| (nodes, None)); + } + let mut offsets = [EMPTY_SCENE; SCENES]; + let mut found = Vec::with_capacity(root.console.len()); + for (index, source) in root.console.iter().enumerate().take(SCENES) { + 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; ~~~~ --- Resolving 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.
Copilot commented 2026-12-01 17:36:48 +00:00 (Migrated from github.com)

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 552

@@ -522,6 +532,62 @@ unsafe fn scene_sources(params: &[D3D12_ROOT_PARAMETER1], layout: &Layout, bvh:
     sources.into_iter().map(|source| source.ok_or_else(|| E_INVALIDARG.into())).collect()
 }
 
+/// Where the title binds each of its scenes, in the order a console walk
+/// numbers them: its raw single-register views by (space, register), as
+/// xshader's `scene_index` counts them.
+///
+/// A program compiled against descriptor tables says itself where each view
+/// lies (`tuxbox_dxbc::compute_table`): the root it runs under gives its
+/// tables one loose range each. A program without that record is looked up
+/// in the root's own ranges.
+pub(crate) fn console_sources(source: &[u8], root: &[u8], guest: &[Binding]) -> Vec<Option<SceneSource>> {
+    use tuxbox_dxbc::compute_table::ROOT_SRV;
+    use tuxbox_dxbc::rootsig::RootParamKind;
+    const SRV_RANGE: u32 = 0;
+    const SRV_PARAMETER: u32 = 3;
+    let mut titles: Vec<(u32, u32)> = guest.iter().filter(|r| r.single()).map(|r| (r.space, r.lower)).collect();
+    titles.sort_unstable();
+    titles.truncate(MAX_SCENES);
+    let physical = tuxbox_dxbc::compute_table::bindings(source, 5);
+    let signature = tuxbox_dxbc::rootsig::parse_rts0(root).ok();

The root-less bindings reader 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_register in runtime/dxbc/src/tests/compute_table.rs covers this register mismatch. Use root-aware reflection with layout_view, retaining the root-less reader as a fallback.

<!-- greyfinch-sync:brcly/TuxBox:review-comment:4758282001 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/596#discussion_r4758282001). Originally posted by [Copilot](https://github.com/apps/copilot-pull-request-reviewer) on 2026-12-01T17:36:48Z. **Code review location:** `runtime/d3d12/src/device/compute_scene.rs`; line 552 ~~~~diff @@ -522,6 +532,62 @@ unsafe fn scene_sources(params: &[D3D12_ROOT_PARAMETER1], layout: &Layout, bvh: sources.into_iter().map(|source| source.ok_or_else(|| E_INVALIDARG.into())).collect() } +/// Where the title binds each of its scenes, in the order a console walk +/// numbers them: its raw single-register views by (space, register), as +/// xshader's `scene_index` counts them. +/// +/// A program compiled against descriptor tables says itself where each view +/// lies (`tuxbox_dxbc::compute_table`): the root it runs under gives its +/// tables one loose range each. A program without that record is looked up +/// in the root's own ranges. +pub(crate) fn console_sources(source: &[u8], root: &[u8], guest: &[Binding]) -> Vec<Option<SceneSource>> { + use tuxbox_dxbc::compute_table::ROOT_SRV; + use tuxbox_dxbc::rootsig::RootParamKind; + const SRV_RANGE: u32 = 0; + const SRV_PARAMETER: u32 = 3; + let mut titles: Vec<(u32, u32)> = guest.iter().filter(|r| r.single()).map(|r| (r.space, r.lower)).collect(); + titles.sort_unstable(); + titles.truncate(MAX_SCENES); + let physical = tuxbox_dxbc::compute_table::bindings(source, 5); + let signature = tuxbox_dxbc::rootsig::parse_rts0(root).ok(); ~~~~ --- The root-less `bindings` reader 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_register` in `runtime/dxbc/src/tests/compute_table.rs` covers this register mismatch. Use root-aware reflection with `layout_view`, retaining the root-less reader as a fallback.
copilot-pull-request-reviewer[bot] commented 2026-12-01 17:36:48 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by copilot-pull-request-reviewer[bot] on 2026-12-01T17:36:48Z.

Review: COMMENTED


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

<!-- greyfinch-sync:brcly/TuxBox:review:6136589763 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/596#pullrequestreview-6136589763). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-12-01T17:36:48Z. **Review:** COMMENTED --- <!-- ccr-overview-v2 --> ### 🟡 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. <details open> <summary><strong>6 open issues</strong></summary> - <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> [Retain console binding resources through command-list and GPU lifetime](https://github.com/brcly/TuxBox/pull/596#discussion_r4758281684) · New - <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> [Clear destination and alias structures when expansion fails](https://github.com/brcly/TuxBox/pull/596#discussion_r4758281785) · New - <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> [Refresh console scene data at submission for edited instances](https://github.com/brcly/TuxBox/pull/596#discussion_r4758281856) · New - <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> [Withdraw stale destination scenes before unreadable rebuild fallback](https://github.com/brcly/TuxBox/pull/596#discussion_r4758281902) · New - <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> [Refresh console descriptors and placements on every execution](https://github.com/brcly/TuxBox/pull/596#discussion_r4758281949) · New - <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> [Use root-aware reflection to resolve console bindings](https://github.com/brcly/TuxBox/pull/596#discussion_r4758282001) · New </details> <details> <summary><strong>What changed in this PR</strong></summary> 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. | </details> <sub>Review effort: Balanced</sub>
brcly commented 2026-12-01 17:44:13 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:brcly/TuxBox:comment:7319769520 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/596#issuecomment-7319769520). Originally posted by [brcly](https://github.com/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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
brcly/TuxBox!596
No description provided.