bvh, d3d12: rehydrate console structures as host builds (stacked on #376) #394

Merged
NickStallman merged 10 commits from upstream-pr/394 into main 2026-11-28 14:41:16 +00:00
NickStallman commented 2026-11-28 11:20:06 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-28T11:20:06Z.


Stacked on #376, which is stacked on #375 and #320; review those first. The last two commits are new here: a merge of main (b426c1aa; #376 is on cf0a0824) and the rehydration.

Fault. ProjectScarlett streams its bottom-level structures in the console's dehydrated form and calls XboxBvhBuilder::RehydrateRaytracingAccelerationStructureBatched2X on them, 16 per call and at least 256 per scene. TuxBox's builder answers E_NOTIMPL (#320 logs them), so nothing is built at those addresses and the scene's instances name console node data (#232). We said on #320 that we'd provide this.

Change.

  • Rehydration becomes a host build. The host can't traverse console nodes, but each entry names the geometry its structure was made from. The builder hands the call to the provider (TuxBoxRehydrateAccelerationStructures, found with GetProcAddress), which records a host build of that geometry. It reuses #320's title-memory storage, #375's index decode and #376's position decode. Leonida's docs/bvh.md (3.1 and 4a) says the leaves follow the index buffer's primitive order, so the host build reports the same GeometryIndex and PrimitiveIndex. Only the facts are used; no code is taken from it.
    • The host structure goes to private storage published under the title's address. It claims the title's own extent, 64 * (nodes + 1) bytes from the console header, as the range a later structure must overlap to release it. Using the host's result size would release neighbours the title packs 256 bytes apart.
    • The provider allocates the scratch and ignores the in-place source.
    • Geometry that can't be read when the call is recorded is decoded at submission into uploads the recorded build already names. If it still can't be read then, the geometry is built empty. A late meshlet decode names at most 65,536 vertices, the most its 16-bit lists can reach; the title's vertex count can be far larger.
    • An entry that can't be built is left out on its own. Under TUXBOX_LOG the first 64 skips are logged with their reason and HRESULT, then every power of two.
  • Geometry is read through XMem's backing. The title maps a physical page at one address for its CPU and, through the queue, at another for the GPU, and it names the GPU address in the call. XMem gives that address a private copy of the page made when it was mapped, and later CPU writes don't reach it. In an earlier run, all 480 rehydrated structures were left empty with "indices do not decode", and every console header read as zero. The decoders and the header read now use read_guest_bytes, the read placed textures use, which reaches the memory the CPU wrote. That function came to main in db70b21d, after #376's base, hence the merge.
  • Packed-position strides. In one run every logged skip (64 of 64) was geometry (0x800701e7), ERROR_INVALID_ADDRESS from XMem. Alongside them the title gave R32G32_FLOAT geometries StrideInBytes 0x8008, which read as bytes runs an import into pages it never mapped. #376 now reads that stride through its low 14 bits (a474745), so this PR carries no fix of its own; its late position decode at submission keeps the stride masked, as #376's decoder takes it. Confirmed in game: decoding the 36 logged packed geometries at stride 8 put 1,124 of 1,124 vertices inside the structure header's scene bounds, while at 0x8008 every range ran into unmapped pages; with the mask the run logged 84 rehydrations and 0 skips.

Effect in ProjectScarlett (RTX 5090, 620.70.10, an integration build with these commits, before the stride mask, TUXBOX_LOG=1): by the 16th call, 205 of 256 structures were built from geometry read when the call was recorded. None were left for submission, and 51 were skipped, all for 0x800701e7. Before the backing read, none had geometry. With the mask (a later run), 84 rehydrations were logged and none skipped.

Test.

  • Lanes ray-tracing-rehydrate rehydrates two console structures 256 bytes apart, in separate submissions. Their geometry is synthetic format-53 indices and quantized positions, and one structure's geometry is written only after its call. Everything is in physical pages named by an address mapped for the GPU before anything was written. A ray query through a scene of both must report the expected instance, geometry and primitive.
    • Without the provider entry, the builder answers E_NOTIMPL and the scenario fails.
    • With the backing read removed, it fails with "indices do not decode".
  • Unit tests:
    • tests/commands/rehydrate.rs: header words, and the extents from node counts.
    • #376's tests/commands/packed_positions.rs covers the 14-bit stride.

Tested

  • The checks relevant to this change passed
  • 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

GPU, driver and backend:

  • RTX 5090 (10de:2b85), NVIDIA 620.70.10
  • AMD Raphael iGPU (1002:13c0), Mesa RADV 26.0.8
  • both on GE-Proton11-14

Commands run and their results:

python tuxbox.py check --adapter 10de:2b85 --proton GE-Proton11-14 --prefix PREFIX --windows-dxc DXC/bin/x64
python tuxbox.py check --adapter 1002:13c0 --proton GE-Proton11-14 --prefix PREFIX --windows-dxc DXC/bin/x64
  both cards: all 11 steps passed, including Lanes and fixtures on the GPU
  (ray-tracing-rehydrate, ray-tracing-builder and ray-tracing-guest-memory PASS),
  D3D12 regression controls and Shader translator on the GPU

python tuxbox.py check --no-gpu
  passed   Build the shader compiler, Python tests, Shader compiler tests, DXBC tests,
           XG layout tests, Storage codec tests, D3D12 Windows typecheck

tuxbox-d3d12 unit tests (cargo xwin test, run under Wine)
  237 passed, 2 failed: memory_wait gpu_compute_and_direct_mid_list_wait_replays_bound_state and
  allocation r9g9b9e5_uav_gpu_roundtrip_and_negative_control, both GPU tests that could not load
  d3dcompiler_47.dll in the scratch prefix

Checks

No evidence JSON changes.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5539579168 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/394). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-28T11:20:06Z. --- **Stacked on #376, which is stacked on #375 and #320**; review those first. The last two commits are new here: a merge of `main` (b426c1aa; #376 is on cf0a0824) and the rehydration. **Fault.** ProjectScarlett streams its bottom-level structures in the console's dehydrated form and calls `XboxBvhBuilder::RehydrateRaytracingAccelerationStructureBatched2X` on them, 16 per call and at least 256 per scene. TuxBox's builder answers `E_NOTIMPL` (#320 logs them), so nothing is built at those addresses and the scene's instances name console node data (#232). We said on #320 that we'd provide this. **Change.** - **Rehydration becomes a host build.** The host can't traverse console nodes, but each entry names the geometry its structure was made from. The builder hands the call to the provider (`TuxBoxRehydrateAccelerationStructures`, found with `GetProcAddress`), which records a host build of that geometry. It reuses #320's title-memory storage, #375's index decode and #376's position decode. Leonida's docs/bvh.md (3.1 and 4a) says the leaves follow the index buffer's primitive order, so the host build reports the same `GeometryIndex` and `PrimitiveIndex`. Only the facts are used; no code is taken from it. - The host structure goes to private storage published under the title's address. It claims the title's own extent, `64 * (nodes + 1)` bytes from the console header, as the range a later structure must overlap to release it. Using the host's result size would release neighbours the title packs 256 bytes apart. - The provider allocates the scratch and ignores the in-place source. - Geometry that can't be read when the call is recorded is decoded at submission into uploads the recorded build already names. If it still can't be read then, the geometry is built empty. A late meshlet decode names at most 65,536 vertices, the most its 16-bit lists can reach; the title's vertex count can be far larger. - An entry that can't be built is left out on its own. Under `TUXBOX_LOG` the first 64 skips are logged with their reason and HRESULT, then every power of two. - **Geometry is read through XMem's backing.** The title maps a physical page at one address for its CPU and, through the queue, at another for the GPU, and it names the GPU address in the call. XMem gives that address a private copy of the page made when it was mapped, and later CPU writes don't reach it. In an earlier run, all 480 rehydrated structures were left empty with "indices do not decode", and every console header read as zero. The decoders and the header read now use `read_guest_bytes`, the read placed textures use, which reaches the memory the CPU wrote. That function came to `main` in db70b21d, after #376's base, hence the merge. - **Packed-position strides.** In one run every logged skip (64 of 64) was `geometry (0x800701e7)`, `ERROR_INVALID_ADDRESS` from XMem. Alongside them the title gave R32G32_FLOAT geometries `StrideInBytes` 0x8008, which read as bytes runs an import into pages it never mapped. #376 now reads that stride through its low 14 bits (a474745), so this PR carries no fix of its own; its late position decode at submission keeps the stride masked, as #376's decoder takes it. **Confirmed in game:** decoding the 36 logged packed geometries at stride 8 put 1,124 of 1,124 vertices inside the structure header's scene bounds, while at 0x8008 every range ran into unmapped pages; with the mask the run logged 84 rehydrations and 0 skips. **Effect in ProjectScarlett** (RTX 5090, 620.70.10, an integration build with these commits, before the stride mask, `TUXBOX_LOG=1`): by the 16th call, 205 of 256 structures were built from geometry read when the call was recorded. None were left for submission, and 51 were skipped, all for `0x800701e7`. Before the backing read, none had geometry. With the mask (a later run), 84 rehydrations were logged and none skipped. **Test.** - Lanes `ray-tracing-rehydrate` rehydrates two console structures 256 bytes apart, in separate submissions. Their geometry is synthetic format-53 indices and quantized positions, and one structure's geometry is written only after its call. Everything is in physical pages named by an address mapped for the GPU before anything was written. A ray query through a scene of both must report the expected instance, geometry and primitive. - Without the provider entry, the builder answers `E_NOTIMPL` and the scenario fails. - With the backing read removed, it fails with "indices do not decode". - Unit tests: - `tests/commands/rehydrate.rs`: header words, and the extents from node counts. - #376's `tests/commands/packed_positions.rs` covers the 14-bit stride. ## Tested - [x] The checks relevant to this change passed - [x] Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below - [x] Where the table calls for AMD and NVIDIA, they passed on both GPU, driver and backend: - RTX 5090 (10de:2b85), NVIDIA 620.70.10 - AMD Raphael iGPU (1002:13c0), Mesa RADV 26.0.8 - both on GE-Proton11-14 Commands run and their results: ```text python tuxbox.py check --adapter 10de:2b85 --proton GE-Proton11-14 --prefix PREFIX --windows-dxc DXC/bin/x64 python tuxbox.py check --adapter 1002:13c0 --proton GE-Proton11-14 --prefix PREFIX --windows-dxc DXC/bin/x64 both cards: all 11 steps passed, including Lanes and fixtures on the GPU (ray-tracing-rehydrate, ray-tracing-builder and ray-tracing-guest-memory PASS), D3D12 regression controls and Shader translator on the GPU python tuxbox.py check --no-gpu passed Build the shader compiler, Python tests, Shader compiler tests, DXBC tests, XG layout tests, Storage codec tests, D3D12 Windows typecheck tuxbox-d3d12 unit tests (cargo xwin test, run under Wine) 237 passed, 2 failed: memory_wait gpu_compute_and_direct_mid_list_wait_replays_bound_state and allocation r9g9b9e5_uav_gpu_roundtrip_and_negative_control, both GPU tests that could not load d3dcompiler_47.dll in the scratch prefix ``` ## Checks No evidence JSON changes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1093i3511 commented 2026-11-28 12:50:10 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by 1093i3511 on 2026-11-28T12:50:10Z.


I've tested this PR as it is (head 928abca, which already contains main b426c1a) on RDNA2. Rehydration works there, and the page faults from #320 alone are gone.

Setup: RX 6600 (1002:73ff, 8 GB), Ryzen 5 5600, 32 GB RAM + 34 GB swap, Mesa RADV 26.3.1, Linux 7.3.6, GE-Proton11-14, Microsoft DXC 1.9.2609. ProjectScarlett 1.0.2.1, offline, 3840x2160, no preload, warm shader caches. D3D12 provider sha256 d811700d…ede0e9e33, XboxBvhBuilder.dll f9d957b9…. tuxbox.py check --no-gpu passes.

Rehydration

TuxBox d3d12_xs: rehydration call #1: 16 structures, 16 built from geometry read when recorded, 0 with geometry left for submission, 0 skipped
...
TuxBox d3d12_xs: rehydration call #6: 2 structures, 2 built from geometry read when recorded, 0 with geometry left for submission, 0 skipped

There were 6 calls with 74 structures, all built at record time, none skipped. Two guest-memory pools were created, and private storage peaked at 64 MiB. No Failed to place destAccelerationStructure.

Same card, three builds

All runs reach world entry: the title sets mission 0x98c85f2a, and the run ends a few frames later.

build dropped builds rehydration kernel page faults ending
main b426c1a, 2 runs 379 / 315 not logged 0 gfx ring timeout, 4 frames after the mission start
main + #320 0 256 refused (E_NOTIMPL) 10 (ring 24, TCP, PERMISSION_FAULTS: 0x3) compute ring timeout, then gfx ring timeout, 6 frames after
this branch 0 74 built, 0 skipped 0 gfx ring timeout, 6 frames after

With #320 alone, the run had gfxhub page faults on a compute ring, as reported on #320. With this branch there are none. That fits the reading on #232 that the faults come from scenes naming structures that were never built. It's one run per build.

What still ends the run

The same gfx ring timeout as on main, without any fault:

amdgpu: ring gfx_0.0.0 timeout, signaled seq=1032487, emitted seq=1032489
amdgpu: Ring gfx_0.0.0 reset succeeded
amdgpu: [drm] device wedged, but no recovery needed

The device was lost about 31 s after the last rehydration call, by vkd3d's timestamps. The title then stopped with exit code 3 at frame 1,743. Since this ending appears both with every BLAS dropped (main) and with all of them built (this branch), I don't think the structures cause it.

Other things in the log:

  • 16 skipped draws pipeline has no paged descriptor layout: its root indexes the resource heap directly (guest caller 0x4e33f98, the same caller as in #232's list), and 1 skipped compute dispatch (0x248cbc1).
  • Memory per the process's amdgpu counters near the end: about 14.5 GB requested VRAM, 7.0 GB resident in VRAM, 11.0 GB in GTT. That's the same as on main.

I can add #373 on top next, which was part of the build that reached the opening scene on #232, and report back.

<!-- greyfinch-sync:brcly/TuxBox:comment:7239500185 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/394#issuecomment-7239500185). Originally posted by [1093i3511](https://github.com/1093i3511) on 2026-11-28T12:50:10Z. --- I've tested this PR as it is (head 928abca, which already contains `main` b426c1a) on RDNA2. Rehydration works there, and the page faults from #320 alone are gone. **Setup:** RX 6600 (`1002:73ff`, 8 GB), Ryzen 5 5600, 32 GB RAM + 34 GB swap, Mesa RADV 26.3.1, Linux 7.3.6, GE-Proton11-14, Microsoft DXC 1.9.2609. ProjectScarlett 1.0.2.1, offline, 3840x2160, no preload, warm shader caches. D3D12 provider sha256 `d811700d…ede0e9e33`, `XboxBvhBuilder.dll` `f9d957b9…`. `tuxbox.py check --no-gpu` passes. ## Rehydration ```text TuxBox d3d12_xs: rehydration call #1: 16 structures, 16 built from geometry read when recorded, 0 with geometry left for submission, 0 skipped ... TuxBox d3d12_xs: rehydration call #6: 2 structures, 2 built from geometry read when recorded, 0 with geometry left for submission, 0 skipped ``` There were 6 calls with 74 structures, all built at record time, none skipped. Two guest-memory pools were created, and private storage peaked at 64 MiB. No `Failed to place destAccelerationStructure`. ## Same card, three builds All runs reach world entry: the title sets mission `0x98c85f2a`, and the run ends a few frames later. | build | dropped builds | rehydration | kernel page faults | ending | | --- | ---: | --- | ---: | --- | | `main` b426c1a, 2 runs | 379 / 315 | not logged | 0 | gfx ring timeout, 4 frames after the mission start | | `main` + #320 | 0 | 256 refused (`E_NOTIMPL`) | 10 (ring 24, TCP, `PERMISSION_FAULTS: 0x3`) | compute ring timeout, then gfx ring timeout, 6 frames after | | this branch | 0 | **74 built, 0 skipped** | **0** | gfx ring timeout, 6 frames after | With #320 alone, the run had gfxhub page faults on a compute ring, as reported on #320. With this branch there are none. That fits the reading on #232 that the faults come from scenes naming structures that were never built. It's one run per build. ## What still ends the run The same gfx ring timeout as on `main`, without any fault: ```text amdgpu: ring gfx_0.0.0 timeout, signaled seq=1032487, emitted seq=1032489 amdgpu: Ring gfx_0.0.0 reset succeeded amdgpu: [drm] device wedged, but no recovery needed ``` The device was lost about 31 s after the last rehydration call, by vkd3d's timestamps. The title then stopped with exit code 3 at frame 1,743. Since this ending appears both with every BLAS dropped (`main`) and with all of them built (this branch), I don't think the structures cause it. Other things in the log: - 16 skipped draws `pipeline has no paged descriptor layout: its root indexes the resource heap directly` (guest caller `0x4e33f98`, the same caller as in #232's list), and 1 skipped compute dispatch (`0x248cbc1`). - Memory per the process's amdgpu counters near the end: about 14.5 GB requested VRAM, 7.0 GB resident in VRAM, 11.0 GB in GTT. That's the same as on `main`. I can add #373 on top next, which was part of the build that reached the opening scene on #232, and report back.
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!394
No description provided.