bvh-layout: give instance records their entry in the scene's parent table #673
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/673"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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_scenegave 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=1and walkfb8e97e0in 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
106120cawithout the change, see below)106120cahas too. The table has no row forruntime/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.
AMD, run by @JeffreyBytes on a Radeon RX 6700 XT (1002:73df), Mesa 26.3.1 RADV, GE-Proton11-15, full check (their comment):
No Lanes scenario: the writer's own tests cover it without a GPU. Without the change,
walks_find_what_testing_every_triangle_findsreads outside its buffer andtrees_are_wholefinds 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:
0xf9……)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
6d4f1cd7with #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.mdthat says only four walks can be served stays too, until that control is met.Checks
No evidence JSON changes.
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:
Review effort: Balanced
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:Main
106120caon 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.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.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.