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

Open
3kynox wants to merge 1 commit from upstream-pr/673 into main
3kynox commented 2026-12-03 12:36:19 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by 3kynox on 2026-12-03T12:36:19Z.


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 passed (run by @JeffreyBytes, below); NVIDIA has the two failures above, which 106120ca has too. 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

AMD, run by @JeffreyBytes on a Radeon RX 6700 XT (1002:73df), Mesa 26.3.1 RADV, GE-Proton11-15, full check (their comment):

Evidence: TuxBox check of 4eaa28ce2df3, no uncommitted changes, GPU default adapter: 17 passed, 0 failed, 0 not run

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.

<!-- greyfinch-sync:brcly/TuxBox:issue:5626615266 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/673). Originally posted by [3kynox](https://github.com/3kynox) on 2026-12-03T12:36:19Z. --- ## 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) - [x] 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 passed (run by @JeffreyBytes, below); NVIDIA has the two failures above, which `106120ca` has too. 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. ```text Evidence: TuxBox check of 4eaa28ce2df3, no uncommitted changes, GPU default adapter: 15 passed, 2 failed, 0 not run ``` ```text 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 ``` AMD, run by @JeffreyBytes on a Radeon RX 6700 XT (1002:73df), Mesa 26.3.1 RADV, GE-Proton11-15, full check ([their comment](https://github.com/brcly/TuxBox/pull/673#issuecomment-7382160244)): ```text Evidence: TuxBox check of 4eaa28ce2df3, no uncommitted changes, GPU default adapter: 17 passed, 0 failed, 0 not run ``` 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-pull-request-reviewer[bot] commented 2026-12-03 12:38:40 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by copilot-pull-request-reviewer[bot] on 2026-12-03T12:38:40Z.

Review: COMMENTED


🔵 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

<!-- greyfinch-sync:brcly/TuxBox:review:6169968489 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/673#pullrequestreview-6169968489). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-12-03T12:38:40Z. **Review:** COMMENTED --- <!-- ccr-overview-v2 --> ### 🔵 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** 🎉 <details> <summary><strong>What changed in this PR</strong></summary> 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. | </details> <sub>Review effort: Balanced</sub>
JeffreyBytes commented 2026-12-03 14:51:48 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by JeffreyBytes on 2026-12-03T14:51:48Z.


AMD run on the head (4eaa28ce). RX 6700 XT 12 GB (1002:73df), Mesa 26.3.1 RADV, GE-Proton11-15, full check:

Evidence: TuxBox check of 4eaa28ce2df3, no uncommitted changes, GPU default adapter: 17 passed, 0 failed, 0 not run

Main 106120ca on the same card and prefix, right before it, also passed 17 of 17. The kernel log had no amdgpu faults or resets during either run. I didn't run the game on it.

<!-- greyfinch-sync:brcly/TuxBox:comment:7382160244 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/673#issuecomment-7382160244). Originally posted by [JeffreyBytes](https://github.com/JeffreyBytes) on 2026-12-03T14:51:48Z. --- AMD run on the head (4eaa28ce). RX 6700 XT 12 GB (`1002:73df`), Mesa 26.3.1 RADV, GE-Proton11-15, full check: ```text Evidence: TuxBox check of 4eaa28ce2df3, no uncommitted changes, GPU default adapter: 17 passed, 0 failed, 0 not run ``` Main `106120ca` on the same card and prefix, right before it, also passed 17 of 17. The kernel log had no amdgpu faults or resets during either run. I didn't run the game on it.
3kynox commented 2026-12-03 16:17:00 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by 3kynox on 2026-12-03T16:17:00Z.


Thanks @JeffreyBytes. I've added your AMD run to the description.

<!-- greyfinch-sync:brcly/TuxBox:comment:7384576821 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/673#issuecomment-7384576821). Originally posted by [3kynox](https://github.com/3kynox) on 2026-12-03T16:17:00Z. --- Thanks @JeffreyBytes. I've added your AMD run to the description.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/673:upstream-pr/673'
git switch 'upstream-pr/673'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/673'
git switch 'upstream-pr/673'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/673'
git switch 'upstream-pr/673'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/673'
git switch 'main'
git merge --squash 'upstream-pr/673'
git switch 'main'
git merge --ff-only 'upstream-pr/673'
git switch 'main'
git merge 'upstream-pr/673'
git push origin 'main'
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!673
No description provided.