d3d12: keep scenes off title-memory structures the host could not build #406

Closed
gtb-sbe wants to merge 3 commits from upstream-pr/406 into main
gtb-sbe commented 2026-11-28 17:40:21 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by gtb-sbe on 2026-11-28T17:40:21Z.


Follow-up to #320, for two ways a structure in title memory could still end up unbuilt while a scene points at it.

Refused builds

build_destination reserved and published a title-memory structure's storage before the build's inputs were translated. When the build was then refused (#375 refuses index formats the host can't read; an import can fail), the scene's instance fixup still found storage for that address: either nothing had ever been built into it, or it still held the structure the title had just replaced.

  • The storage is now published once the build is recorded, which keeps the record-time order from #320.
  • A refused build in title memory publishes no structure (address 0). Instance fixups then write a null structure address, so the instances that name it are inactive. That is a stand-in: those objects drop out of the scene instead of faulting the GPU or showing stale geometry. It is logged, bounded: acceleration structure build at ... refused (...); scene instances that use it are inactive.

Scratch the host can't reach

In one ProjectScarlett run on my card, 5 BLAS builds were refused with 0x800701e7 (ERROR_INVALID_ADDRESS). Their scratch is title GPU memory with no CPU backing the provider can import; that error comes from XMem's page backing lookup. Scratch in memory the title only reserved was worse: buffer_at has no buffer for uncommitted memory, so the scratch address went to vkd3d-proton raw.

D3D12 leaves scratch contents undefined before and after a build, so nothing has to reach title memory. When the host can't reach the title's scratch, the build now gets private device-local scratch that the list keeps, with a bounded log line. Committed title scratch still goes through the import as before.

Tests

Two new Lanes scenarios, both tracing rays through query.hlsl:

  • ray-tracing-refused-structure: two BLASes in title memory are built and hit; the first is then rebuilt with 8-bit indices, which the provider refuses. The ray onto it must miss and the other must still hit.
    • Without the change: FAIL ... ray onto the refused rebuild: expected instance -1, found 7 (the old triangle stays in the scene).
    • With it: PASS.
  • ray-tracing-reserved-scratch: a BLAS in title memory built with scratch the title only reserved.
    • Without the change: FAIL ... did not finish within 2 seconds, with GPU page faults on the compute and gfx rings and a gfx ring reset.
    • With it: PASS.

The scene-and-ray code they share is a small helper (SceneProbe); ray-tracing-rehydrate is unchanged.

ProjectScarlett

Title 1.0.2.1, offline, 3840x2160. RX 9060 XT, Mesa 26.2.6 RADV, GE-Proton11-14, no preload, this branch before the rebase, on e380da1.

  • Two runs into the story intro. Rehydration built every structure (256 and 222, none skipped), and no build was dropped, refused or given private scratch, so neither stand-in was needed in these runs; the refusals I saw before came from a build without #375, #376 and #394. In one run I classified every scene instance reference at submission: the game submitted 4 scenes at world entry, and all of their references reached built storage.
  • Both runs still ended in a GPU fault a few minutes after world entry, of two different kinds: once on the compute ring at title addresses in the AS allocation, once on the gfx ring at an unmapped native address. The second kind also appeared before #320, when every BLAS was dropped, so I don't think it comes from this area. I haven't found either cause yet.

Checks

RX 9060 XT (RDNA4), Mesa 26.2.6 RADV, kernel 6.18, Proton Experimental, on de6af11 (rebased on 5de0e62).

  • python tuxbox.py check --backend proton --adapter 1002:7590 --proton <Proton Experimental> --prefix <prefix> --windows-dxc <DXC 2026-09-29>: every GPU group passes (115 of 115 gates). The Python tests fail on one test, test_stage_baseline.GuestWatch.test_a_guest_that_died_stops_the_sandbox_instead_of_waiting_out_the_timeout (AssertionError: 0 != 'guest gone'). It fails the same way on 5de0e62 without this branch on my machine, and this branch doesn't touch it.
Summary
  passed   Build the shader compiler (0s)
  FAILED   Python tests (71s)
  passed   Shader compiler tests (1s)
  passed   DXBC tests (0s)
  passed   XG layout tests (13s)
  passed   Storage codec tests (0s)
  passed   D3D12 Windows typecheck (0s)
  passed   Build (50s)
  passed   Lanes and fixtures on the GPU (317s)
  passed   D3D12 regression controls (22s)
  passed   Shader translator on the GPU (94s)
  • python tuxbox.py verify --only lanes-selftest: all 25 scenarios pass. Both new scenarios fail with 5de0e62's own provider, as described above.
  • NVIDIA: not run.

AI use

This branch was made with an AI coding agent (Claude Opus 5.5 via Claude Code, following AGENTS.md). The agent traced the refused builds and the scratch errors in my run logs, wrote both provider changes, the Lanes scenarios and helper, and this description. I reviewed the changes before committing them. The Lanes runs and the checks above ran on my machine.

No title files, shader bytes or logs included.

<!-- greyfinch-sync:brcly/TuxBox:issue:5542909713 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/406). Originally posted by [gtb-sbe](https://github.com/gtb-sbe) on 2026-11-28T17:40:21Z. --- Follow-up to #320, for two ways a structure in title memory could still end up unbuilt while a scene points at it. ## Refused builds `build_destination` reserved and published a title-memory structure's storage before the build's inputs were translated. When the build was then refused (#375 refuses index formats the host can't read; an import can fail), the scene's instance fixup still found storage for that address: either nothing had ever been built into it, or it still held the structure the title had just replaced. - The storage is now published once the build is recorded, which keeps the record-time order from #320. - A refused build in title memory publishes no structure (address 0). Instance fixups then write a null structure address, so the instances that name it are inactive. That is a stand-in: those objects drop out of the scene instead of faulting the GPU or showing stale geometry. It is logged, bounded: `acceleration structure build at ... refused (...); scene instances that use it are inactive`. ## Scratch the host can't reach In one ProjectScarlett run on my card, 5 BLAS builds were refused with `0x800701e7` (`ERROR_INVALID_ADDRESS`). Their scratch is title GPU memory with no CPU backing the provider can import; that error comes from XMem's page backing lookup. Scratch in memory the title only reserved was worse: `buffer_at` has no buffer for uncommitted memory, so the scratch address went to vkd3d-proton raw. D3D12 leaves scratch contents undefined before and after a build, so nothing has to reach title memory. When the host can't reach the title's scratch, the build now gets private device-local scratch that the list keeps, with a bounded log line. Committed title scratch still goes through the import as before. ## Tests Two new Lanes scenarios, both tracing rays through `query.hlsl`: - `ray-tracing-refused-structure`: two BLASes in title memory are built and hit; the first is then rebuilt with 8-bit indices, which the provider refuses. The ray onto it must miss and the other must still hit. - Without the change: `FAIL ... ray onto the refused rebuild: expected instance -1, found 7` (the old triangle stays in the scene). - With it: `PASS`. - `ray-tracing-reserved-scratch`: a BLAS in title memory built with scratch the title only reserved. - Without the change: `FAIL ... did not finish within 2 seconds`, with GPU page faults on the compute and gfx rings and a gfx ring reset. - With it: `PASS`. The scene-and-ray code they share is a small helper (`SceneProbe`); `ray-tracing-rehydrate` is unchanged. ## ProjectScarlett Title 1.0.2.1, offline, 3840x2160. RX 9060 XT, Mesa 26.2.6 RADV, GE-Proton11-14, no preload, this branch before the rebase, on `e380da1`. - Two runs into the story intro. Rehydration built every structure (256 and 222, none skipped), and no build was dropped, refused or given private scratch, so neither stand-in was needed in these runs; the refusals I saw before came from a build without #375, #376 and #394. In one run I classified every scene instance reference at submission: the game submitted 4 scenes at world entry, and all of their references reached built storage. - Both runs still ended in a GPU fault a few minutes after world entry, of two different kinds: once on the compute ring at title addresses in the AS allocation, once on the gfx ring at an unmapped native address. The second kind also appeared before #320, when every BLAS was dropped, so I don't think it comes from this area. I haven't found either cause yet. ## Checks RX 9060 XT (RDNA4), Mesa 26.2.6 RADV, kernel 6.18, Proton Experimental, on `de6af11` (rebased on `5de0e62`). - `python tuxbox.py check --backend proton --adapter 1002:7590 --proton <Proton Experimental> --prefix <prefix> --windows-dxc <DXC 2026-09-29>`: every GPU group passes (115 of 115 gates). The Python tests fail on one test, `test_stage_baseline.GuestWatch.test_a_guest_that_died_stops_the_sandbox_instead_of_waiting_out_the_timeout` (`AssertionError: 0 != 'guest gone'`). It fails the same way on `5de0e62` without this branch on my machine, and this branch doesn't touch it. ```text Summary passed Build the shader compiler (0s) FAILED Python tests (71s) passed Shader compiler tests (1s) passed DXBC tests (0s) passed XG layout tests (13s) passed Storage codec tests (0s) passed D3D12 Windows typecheck (0s) passed Build (50s) passed Lanes and fixtures on the GPU (317s) passed D3D12 regression controls (22s) passed Shader translator on the GPU (94s) ``` - `python tuxbox.py verify --only lanes-selftest`: all 25 scenarios pass. Both new scenarios fail with `5de0e62`'s own provider, as described above. - NVIDIA: not run. ## AI use This branch was made with an AI coding agent (Claude Opus 5.5 via Claude Code, following `AGENTS.md`). The agent traced the refused builds and the scratch errors in my run logs, wrote both provider changes, the Lanes scenarios and helper, and this description. I reviewed the changes before committing them. The Lanes runs and the checks above ran on my machine. No title files, shader bytes or logs included.
brcly commented 2026-11-30 04:12:27 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-30T04:12:27Z.


Heads-up: main just landed a large cleanup (up to e5d2e913), so this PR needs a rebase.

  • Formatting: the whole workspace is now formatted with rustfmt (see the new rustfmt.toml).
  • Lints: every crate denies unwrap(), lossy as casts and undocumented unsafe outside tests.
  • CI: it now also runs cargo fmt --check, rustdoc with warnings denied, and Miri on the providers' unit tests.

The least painful way is to format your branch first, so the rebase only shows real changes:

git fetch origin
git checkout origin/main -- rustfmt.toml
cargo fmt --all && git commit -am "rustfmt"
git rebase origin/main

Then run python tuxbox.py check --no-gpu, which now includes the format step.

If clippy flags something new:

  • A cast: use From for widening, TryFrom for narrowing, and a mask for bit fields.
  • An unwrap(): use ?, or expect with the reason it can't fail.
  • An unsafe block: it needs a // SAFETY: comment.

CONTRIBUTING's "Code checks" section lists the commands. Thanks!

<!-- greyfinch-sync:brcly/TuxBox:comment:7268564369 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/406#issuecomment-7268564369). Originally posted by [brcly](https://github.com/brcly) on 2026-11-30T04:12:27Z. --- Heads-up: main just landed a large cleanup (up to e5d2e913), so this PR needs a rebase. - **Formatting:** the whole workspace is now formatted with rustfmt (see the new `rustfmt.toml`). - **Lints:** every crate denies `unwrap()`, lossy `as` casts and undocumented `unsafe` outside tests. - **CI:** it now also runs `cargo fmt --check`, rustdoc with warnings denied, and Miri on the providers' unit tests. The least painful way is to format your branch first, so the rebase only shows real changes: ```sh git fetch origin git checkout origin/main -- rustfmt.toml cargo fmt --all && git commit -am "rustfmt" git rebase origin/main ``` Then run `python tuxbox.py check --no-gpu`, which now includes the format step. If clippy flags something new: - **A cast:** use `From` for widening, `TryFrom` for narrowing, and a mask for bit fields. - **An `unwrap()`:** use `?`, or `expect` with the reason it can't fail. - **An `unsafe` block:** it needs a `// SAFETY:` comment. CONTRIBUTING's "Code checks" section lists the commands. Thanks!
gtb-sbe commented 2026-12-01 12:39:17 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by gtb-sbe on 2026-12-01T12:39:17Z.


Closing this, since its changes are already on main: #442 (refused builds leave their scene instances inactive) and #443 (private scratch where the host can't reach the title's) landed both commits. The README fix from the last commit is covered too, as the reserved-scratch row appears only once on main. A rebase would leave an empty diff.

Thanks @glovepost for picking them up!

<!-- greyfinch-sync:brcly/TuxBox:comment:7311451726 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/406#issuecomment-7311451726). Originally posted by [gtb-sbe](https://github.com/gtb-sbe) on 2026-12-01T12:39:17Z. --- Closing this, since its changes are already on `main`: #442 (refused builds leave their scene instances inactive) and #443 (private scratch where the host can't reach the title's) landed both commits. The README fix from the last commit is covered too, as the reserved-scratch row appears only once on `main`. A rebase would leave an empty diff. Thanks @glovepost for picking them up!

Pull request closed

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!406
No description provided.