Skip to content

bvh-layout: give instance records their entry in the scene's parent table - #673

Open
3kynox wants to merge 1 commit into
brcly:mainfrom
3kynox:pr-scene-instance-parents
Open

3kynox wants to merge 1 commit into
brcly:mainfrom
3kynox:pr-scene-instance-parents

Conversation

@3kynox

@3kynox 3kynox commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Summary

What was wrong. A console ray walk keeps 16 nodes per lane. Once that overflowed and is empty, it climbs through the structure's parent table. write_scene gave an entry in that table to box nodes only. But a walk can climb from an instance record too: one the ray's mask leaves out is never entered, so when it was the last node, the walk looks the record up in the scene's own table, past its end. It then takes a box node's child pointer or a float of its bounds for a node pointer.

What that does. A node pointer names a 64-byte block in its upper 29 bits, and the translated walks use the low 32 bits of the byte offset. So a float from 0.5 up to 2 reads as an offset in the last 128 MiB under 4 GiB from the scene. The walks' root SRV has no bounds. Four device losses with TUXBOX_CONSOLE_STRUCTURES=1 and walk fb8e97e0 in flight read addresses there, above the newest structures buffer. A fifth had the same walk in flight, at an address whose memory had been freed. That is consistent with this defect, not proof of it. Other values land just above the buffer or inside it. Inside, the ray ends early, or goes round until the walk's own limit of 65,536 steps.

The change. The table covers the instance records as well, 8 bytes more for each instance in the scene. A record keeps its own parent word, which a walk reads when it comes back from a structure. Nothing changes with the switch off, and no shader is recompiled.

The writer came with #525, whose description says its comparison on real scenes didn't cover the short stack and the parent table (that comparison was mine, with a plain stack walk). I found no reason there for leaving the records out of the table. @NickStallman, tell me if there was one.

The test's walk climbed from an instance through the record's word, which is why it agreed with the writer. It now climbs through the table, as the programs do.

Tested

  • The checks relevant to this change passed (two fail, and fail the same way on 106120ca without the change, see below)
  • Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below
  • Where the table calls for AMD and NVIDIA, they passed on both. Otherwise, say which vendor still needs to run them: AMD. I have no such card. The table has no row for runtime/bvh-layout, which only the D3D12 provider uses.

GPU, driver and backend: RTX 4070 Ti SUPER 16 GB, NVIDIA 620.73.04, vkd3d-proton (Proton Experimental), Intel CPU.

Evidence: TuxBox check of 4eaa28ce2df3, no uncommitted changes, GPU default adapter: 15 passed, 2 failed, 0 not run
python tuxbox.py check --proton "Proton - Experimental" --prefix PREFIX --windows-dxc DXC/bin/x64
  FAILED   Python tests: test_a_guest_that_died_stops_the_sandbox_instead_of_waiting_out_the_timeout
  FAILED   Lanes and fixtures on the GPU: lanes-selftest-queue-page-mappings
  passed   the other 15, with the D3D12 regression controls and the shader translator on the GPU

No Lanes scenario: the writer's own tests cover it without a GPU. Without the change, walks_find_what_testing_every_triangle_finds reads outside its buffer and trees_are_whole finds the first instance's entry missing.

On real scenes, on the CPU. In two buffers I had dumped from the game with this writer (November 30), 1,309 of 1,309 and 1,108 of 1,108 instance entries were wrong. I then walked the first one with my own C version of the short-stack walk, 1.98 billion random rays of up to 10,000 units from near the instances:

entries as written entries of the instances in place
rays whose stack overflowed 1,086,557 1,086,557
rays given a wrong parent 21 0
rays that went round to the step limit 3 0
rays that read outside a 512 MiB buffer 1 (at 0xf9……) 0

It is rare, and my rays are not the title's: this says it can happen on its scenes, not how often it does.

In the game. Thirteen runs with the switch on and this change, on 6d4f1cd7 with #647 rather than this branch's head. Nine walks served, the hit-shading programs running with the change of #670, default settings (ten of the runs also had the diagnostic of #567). The loss with that walk in flight didn't come back. That says little: before the change it came after 194 to 763 s of world, and only five of the thirteen runs got past 194 s, because other losses ended them first.

Other losses ended all thirteen. Twelve read memory of a texture that had ended, as in #603, and one read an address that had been bound again 3 s before. No walk was in flight. In the three pairs of my off/on control with this change (the one asked for on #586), the device was lost in three runs of three with the switch on and in one of three with it off, so the nine-walk control is still not met.

The switch stays off by default. The line of docs/ENVIRONMENT.md that says only four walks can be served stays too, until that control is met.

Checks

No evidence JSON changes.

Copilot AI balanced review requested due to automatic review settings December 3, 2026 12:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Missing AMD validation, remaining device losses, and an unmet in-game toggle leave cross-vendor and runtime risks in the GPU ray walks requiring human review.

No open issues 🎉

What changed in this PR

Fixes console-format scene traversal by giving instance records parent-table entries, so short-stack walks can safely climb from masked-out instances.

Changes:

  • Expands and populates the parent table for instance records.
  • Updates traversal tests to use and validate those entries.
  • Clarifies when walks use the table versus the record’s own parent word.
File Description
runtime/​bvh-layout/​src/​tests/​scene.rs Checks instance parent entries and uses them during traversal.
runtime/​bvh-layout/​src/​scene.rs Allocates and writes parent-table entries for instances.
runtime/​bvh-layout/​src/​lib.rs Documents the two instance-parent lookup paths.

Review effort: Balanced

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants