d3d12: keep a render heap while its guest range is committed #373

Merged
Jerkin42 merged 1 commit from upstream-pr/373 into main 2026-11-28 16:55:02 +00:00
Jerkin42 commented 2026-11-28 05:34:36 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by Jerkin42 on 2026-11-28T05:34:36Z.


Summary

Fixes #323.

A render target that the title places at a guest address through the layout API (slot 133) lives in a device-local render heap. RenderHeaps kept only a Weak per guest range, so releasing the last image there freed the native heap at once. On the console, releasing an image does not free the memory behind it. The title still owns the range and can read it through descriptors it made earlier. #323 shows a shader reading a freed heap's VA 11 minutes later, which loses the device after 15 to 18 minutes of play.

RenderHeaps now holds each heap, and drops one only when no image uses it and no page of its guest range is committed (any_committed, a VirtualQuery walk). As a result, another image placed at the same address also sees the texels left there, as it would in console memory. Heaps that a larger placement replaces are still dropped from the table as before, and the images that use them keep them.

Memory cost: #323 counted 592 render heaps created in a run and only about 10 freed, so keeping the few whose range stays committed costs little. The check runs only over heaps that no image uses, when a new image is placed.

Tested

  • The checks relevant to this change passed (one Lanes case and one regression control that also fail without it, 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. NVIDIA: NickStallman ran the full python tuxbox.py check --adapter 10de:2b85 on ab0751c8, 162 of 162 passed (RTX 5090, driver 620.70.10, GE-Proton11-14), including the regression controls (comment).

New regression control render-heap (d3d12-placement.exe --render-heap):

  1. Place a 256x256 render target at committed guest memory through slot 133, clear it, and release it.
  2. Wait past the provider's descriptor keep-alive.
  3. Fill recycled device memory with eight like-sized heaps cleared red.
  4. Place the same image at the same address and read it back.

On main the second image kept 0 of 65,536 texels (two runs). With this change it keeps all 65,536 (two runs, plus the full check).

I have not run ProjectScarlett with this change: #323's fault takes 15 to 18 minutes from a story save to appear. A run from someone who can reproduce it (the reporter, with VKD3D_CONFIG=fault) would confirm it.

GPU, driver and backend: AMD RX 9060 XT, Mesa RADV 26.1.8, Linux 7.3.1, Proton Experimental (private rootful Xwayland); NVIDIA RTX 5090, 620.70.10, GE-Proton11-14 (run by NickStallman)

Commands run and their results:

python tuxbox.py check --proton ".../Proton - Experimental" --prefix <small check prefix> --windows-dxc <dxc 2505>
  passed   Build the shader compiler
  passed   Python tests
  passed   Shader compiler tests
  passed   DXBC tests
  passed   XG layout tests
  passed   Storage codec tests
  passed   D3D12 Windows typecheck
  passed   Build
  FAILED   Lanes and fixtures on the GPU   (1 FAIL: invalid-route)
  FAILED   D3D12 regression controls       (mesh: word 76 expected 1548 observed 0; render-heap and placement passed)
  passed   Shader translator on the GPU
tools/check_d3d12_regressions.py --case render-heap   main: FAIL "the second image kept 0 of 65536 texels" (2 runs); this branch: PASS kept=65536/65536 (2 runs)
tools/check_d3d12_regressions.py --case mesh          this branch, 6 runs: 5 passed, 1 failed (same word)

invalid-route also fails on plain main here: it checks route-game.exe's exit status and has failed on this machine before. The mesh control places no images at guest addresses. It is intermittent on RADV here (the amplified dispatch's word 76 sometimes reads 0) and fails the same way on branches that don't touch D3D12, as noted on #367 and #368.

Checks

No evidence JSON changes.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5537102283 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/373). Originally posted by [Jerkin42](https://github.com/Jerkin42) on 2026-11-28T05:34:36Z. --- ## Summary Fixes #323. A render target that the title places at a guest address through the layout API (slot 133) lives in a device-local render heap. `RenderHeaps` kept only a `Weak` per guest range, so releasing the last image there freed the native heap at once. On the console, releasing an image does not free the memory behind it. The title still owns the range and can read it through descriptors it made earlier. #323 shows a shader reading a freed heap's VA 11 minutes later, which loses the device after 15 to 18 minutes of play. `RenderHeaps` now holds each heap, and drops one only when no image uses it and no page of its guest range is committed (`any_committed`, a `VirtualQuery` walk). As a result, another image placed at the same address also sees the texels left there, as it would in console memory. Heaps that a larger placement replaces are still dropped from the table as before, and the images that use them keep them. Memory cost: #323 counted 592 render heaps created in a run and only about 10 freed, so keeping the few whose range stays committed costs little. The check runs only over heaps that no image uses, when a new image is placed. ## Tested - [x] The checks relevant to this change passed (one Lanes case and one regression control that also fail without it, see below) - [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. NVIDIA: NickStallman ran the full `python tuxbox.py check --adapter 10de:2b85` on ab0751c8, 162 of 162 passed (RTX 5090, driver 620.70.10, GE-Proton11-14), including the regression controls ([comment](https://github.com/brcly/TuxBox/pull/373#issuecomment-7235220180)). New regression control `render-heap` (`d3d12-placement.exe --render-heap`): 1. Place a 256x256 render target at committed guest memory through slot 133, clear it, and release it. 2. Wait past the provider's descriptor keep-alive. 3. Fill recycled device memory with eight like-sized heaps cleared red. 4. Place the same image at the same address and read it back. On `main` the second image kept 0 of 65,536 texels (two runs). With this change it keeps all 65,536 (two runs, plus the full check). I have not run ProjectScarlett with this change: #323's fault takes 15 to 18 minutes from a story save to appear. A run from someone who can reproduce it (the reporter, with `VKD3D_CONFIG=fault`) would confirm it. GPU, driver and backend: AMD RX 9060 XT, Mesa RADV 26.1.8, Linux 7.3.1, Proton Experimental (private rootful Xwayland); NVIDIA RTX 5090, 620.70.10, GE-Proton11-14 (run by NickStallman) Commands run and their results: ```text python tuxbox.py check --proton ".../Proton - Experimental" --prefix <small check prefix> --windows-dxc <dxc 2505> passed Build the shader compiler passed Python tests passed Shader compiler tests passed DXBC tests passed XG layout tests passed Storage codec tests passed D3D12 Windows typecheck passed Build FAILED Lanes and fixtures on the GPU (1 FAIL: invalid-route) FAILED D3D12 regression controls (mesh: word 76 expected 1548 observed 0; render-heap and placement passed) passed Shader translator on the GPU tools/check_d3d12_regressions.py --case render-heap main: FAIL "the second image kept 0 of 65536 texels" (2 runs); this branch: PASS kept=65536/65536 (2 runs) tools/check_d3d12_regressions.py --case mesh this branch, 6 runs: 5 passed, 1 failed (same word) ``` `invalid-route` also fails on plain `main` here: it checks `route-game.exe`'s exit status and has failed on this machine before. The `mesh` control places no images at guest addresses. It is intermittent on RADV here (the amplified dispatch's word 76 sometimes reads 0) and fails the same way on branches that don't touch D3D12, as noted on #367 and #368. ## Checks No evidence JSON changes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Jerkin42 commented 2026-11-28 05:34:50 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by Jerkin42 on 2026-11-28T05:34:50Z.


I only have an AMD card (RX 9060 XT, RADV), so the NVIDIA half of the checks is still open. If someone with an NVIDIA GPU can run python tuxbox.py check on this branch and post the summary, that would cover the vendor row. Thank you!

<!-- greyfinch-sync:brcly/TuxBox:comment:7234756339 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/373#issuecomment-7234756339). Originally posted by [Jerkin42](https://github.com/Jerkin42) on 2026-11-28T05:34:50Z. --- I only have an AMD card (RX 9060 XT, RADV), so the NVIDIA half of the checks is still open. If someone with an NVIDIA GPU can run `python tuxbox.py check` on this branch and post the summary, that would cover the vendor row. Thank you!
NickStallman commented 2026-11-28 06:19:16 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-28T06:19:16Z.


NVIDIA results for ab0751c8: the full python tuxbox.py check --adapter 10de:2b85 passed, 162 of 162 (RTX 5090, driver 620.70.10, GE-Proton11-14), including the regression controls.

For context, on the same card we saw a device loss about 12 minutes after the story load. We are now running a build with this PR in it, with vkd3d-proton's device-fault reporting, and will post what it shows.

<!-- greyfinch-sync:brcly/TuxBox:comment:7235220180 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/373#issuecomment-7235220180). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-28T06:19:16Z. --- NVIDIA results for `ab0751c8`: the full `python tuxbox.py check --adapter 10de:2b85` passed, 162 of 162 (RTX 5090, driver 620.70.10, GE-Proton11-14), including the regression controls. For context, on the same card we saw a device loss about 12 minutes after the story load. We are now running a build with this PR in it, with vkd3d-proton`'`s device-fault reporting, and will post what it shows.
Jerkin42 commented 2026-11-28 06:22:04 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by Jerkin42 on 2026-11-28T06:22:04Z.


Thank you, @NickStallman! That covers the NVIDIA row; I've added your result to the description.

The device-fault report will be useful either way. On the RX 9060 XT our own long runs were also lost in the story prologue, so if the fault names a heap or a placed resource, I'd like to compare it with ours.

<!-- greyfinch-sync:brcly/TuxBox:comment:7235249453 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/373#issuecomment-7235249453). Originally posted by [Jerkin42](https://github.com/Jerkin42) on 2026-11-28T06:22:04Z. --- Thank you, @NickStallman! That covers the NVIDIA row; I've added your result to the description. The device-fault report will be useful either way. On the RX 9060 XT our own long runs were also lost in the story prologue, so if the fault names a heap or a placed resource, I'd like to compare it with ours.
NickStallman commented 2026-11-28 07:00:03 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-28T07:00:03Z.


Here are the device-fault reports from builds that include this PR, as promised (RTX 5090, 620.70.10, trace-built vkd3d-proton cae8353e with VKD3D_CONFIG=breadcrumbs,fault). None of the faults named a render heap.

  • Two runs with this PR, #320 and #372: both faulted with a ReadInvalid in the title's streaming span. In one run the faulting page held an unresolved BLAS index-buffer address (format 53); in the other it sat 0x1370 bytes after one. The tracker found no allocation there in either run.
  • With raw index addresses removed: the next fault was again in the same span. It was next to rehydrated BLAS destinations that TuxBox refuses (details on #320).
  • One run with those instances made inactive: the ReadInvalid was at 0x6124c7000, inside a 2.2 GB vkd3d allocation (a VkDeviceMemory and a global VkBuffer). That allocation lived 1.8 s and was freed 31 s before the fault; vkd3d called it "very likely use-after-free". It wasn't a render heap: 0 were released in that run, and the largest was 15 MiB. We haven't yet identified which D3D12 object owned it.
<!-- greyfinch-sync:brcly/TuxBox:comment:7235649325 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/373#issuecomment-7235649325). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-28T07:00:03Z. --- Here are the device-fault reports from builds that include this PR, as promised (RTX 5090, 620.70.10, trace-built vkd3d-proton `cae8353e` with `VKD3D_CONFIG=breadcrumbs,fault`). None of the faults named a render heap. - **Two runs with this PR, #320 and #372:** both faulted with a `ReadInvalid` in the title's streaming span. In one run the faulting page held an unresolved BLAS index-buffer address (format 53); in the other it sat 0x1370 bytes after one. The tracker found no allocation there in either run. - **With raw index addresses removed:** the next fault was again in the same span. It was next to rehydrated BLAS destinations that TuxBox refuses (details on #320). - **One run with those instances made inactive:** the `ReadInvalid` was at `0x6124c7000`, inside a 2.2 GB vkd3d allocation (a `VkDeviceMemory` and a global `VkBuffer`). That allocation lived 1.8 s and was freed 31 s before the fault; vkd3d called it "very likely use-after-free". It wasn't a render heap: 0 were released in that run, and the largest was 15 MiB. We haven't yet identified which D3D12 object owned it.
Jerkin42 commented 2026-11-28 07:01:07 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by Jerkin42 on 2026-11-28T07:01:07Z.


Thanks, @NickStallman, that's very helpful, and good to know none of them was a render heap.

  • The first two faults: these line up with the raw format-53 index addresses. #375 (stacked on #320) decodes those streams instead of passing the address through. #376 does the same for the packed R32G32_FLOAT stride-8 positions these builds also use; a host build would otherwise read them as two floats per vertex. If you try them, I'd be interested in whether the next fault moves.
  • The 2.2 GB use-after-free: a guess, not checked. A buffer that size, alive for 1.8 s, sounds like an import of a title-memory range rather than a title heap. If a structure built or published into such an import is still referenced afterwards, for example a BLAS address in a TLAS instance, traversal would read freed memory long after the build list finished. A breadcrumb with the AS address of the instances in the faulting TLAS would tell us whether it points into that range.

On the RX 9060 XT, our latest prologue run (with the two known-bad shaders nulled) went about 6.5 minutes without a fault, but I stopped it there, so that doesn't prove much yet.

<!-- greyfinch-sync:brcly/TuxBox:comment:7235661367 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/373#issuecomment-7235661367). Originally posted by [Jerkin42](https://github.com/Jerkin42) on 2026-11-28T07:01:07Z. --- Thanks, @NickStallman, that's very helpful, and good to know none of them was a render heap. - **The first two faults:** these line up with the raw format-53 index addresses. #375 (stacked on #320) decodes those streams instead of passing the address through. #376 does the same for the packed R32G32_FLOAT stride-8 positions these builds also use; a host build would otherwise read them as two floats per vertex. If you try them, I'd be interested in whether the next fault moves. - **The 2.2 GB use-after-free:** a guess, not checked. A buffer that size, alive for 1.8 s, sounds like an import of a title-memory range rather than a title heap. If a structure built or published into such an import is still referenced afterwards, for example a BLAS address in a TLAS instance, traversal would read freed memory long after the build list finished. A breadcrumb with the AS address of the instances in the faulting TLAS would tell us whether it points into that range. On the RX 9060 XT, our latest prologue run (with the two known-bad shaders nulled) went about 6.5 minutes without a fault, but I stopped it there, so that doesn't prove much yet.
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!373
No description provided.