d3d12: keep a batch's placed textures until its queue has passed it #646

Closed
Kayotic1337 wants to merge 1 commit from upstream-pr/646 into main
Kayotic1337 commented 2026-12-02 01:20:23 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by Kayotic1337 on 2026-12-02T01:20:23Z.


Possible fix for the TCP read faults in #603. Draft: one game run with the change so far.

Change

A recorded list holds the placed textures it binds directly (placed_reads), but not the ones its programs reach through a descriptor heap. placement::submit gathers those from the heaps' views (views.gather, via Weak::upgrade) to back and order them, then drops them when it returns. Nothing else holds them until the GPU has run the batch. If the title releases such a texture after submitting work that reads it, the image and its tiles are destroyed while that work is still queued or running.

Now each batch keeps its gathered textures until its queue's reader fence reaches the batch's tick (waits::kept::until). Finished batches are released on the next submission. A lost device reports u64::MAX, which releases everything.

  • placement.rs is at its 1,200-line limit, so the logic lives in placement/waits/kept.rs. The call replaces the note_readers line in submit, and until calls note_readers first.
  • Nothing else changes: no new variable, no change to backing or ordering.

Why I think this is the #603 fault

Five runs on main after e40d8052 without the change all ended on a TCP read fault (MAPPING_ERROR: 0x1, vkd3d "currently mapped"), after 681–1,630 s (runs 5, 9, 10, 11, 12 in #603). In each, the fault came within 2–70 ms of a new sparse image being reserved at a VA that had just had another owner. (The "about 2 s" vkd3d prints is its device-loss time; the kernel's page-fault time, converted to vkd3d's clock, is what's within ms.)

For runs 11 and 12 I logged when each unfinished draw was recorded, on vkd3d's clock:

Run 11 Run 12
Unfinished draws recorded 23555.326 s 24906.645 s
Previous owner of the faulting VA released 23556.990 s (a 0x60000 heap) 24907.267 s (a 1024x1024 BC1 placed texture; drop logged 12 µs before vkd3d's UNBIND)
New sparse image reserved there 23557.075 s 24907.349 s
Page fault (kernel, converted) ~23557.078 s ~24907.355 s

So in both, the work that faulted was recorded 0.6–1.7 s before the VA's owner was released, and hadn't finished. The read only faults once the VA is remapped. All of these were mesh draws; MS 4db9a403 was the most common in both, the same program @NickStallman and @DrArroway saw on an RTX 5090 and an RX 6900 XT. In run 11 I couldn't tell what the 0x60000 heap belonged to. I added a render-heap log for run 12, but there the previous owner was a texture, so that question is still open.

Game

RX 9070 XT (1002:7550), Mesa 26.3.1 RADV, GE-Proton11-15, TUXBOX_LAZY_PUBLICATION=0, VKD3D_CONFIG=fault, TUXBOX_TRACE_GPU_FAULT=1, drop log on.

  • With this change (run 13): 2,621 s (43.7 min) without the TCP fault, through the prison and into the next cutscene, further than I had got before. VRAM and RSS were the same as without it (13.6 GB card, 17.5 GB RSS at about 46 min, vs 12.9 / 17.2 GB in run 11 at 22 min), and so was the frame rate.
  • The run then ended on a different fault: an SQC (scalar data) read of address 0 on the compute ring, from a single dispatch, CS a8ffc289. I had that one once before without this change (run 8), so I don't think it's related. It needs its own look.
  • One run only. The game run used the same change on my local branch (2a850114 + #639 + local diagnostics), not this PR's base. Rebasing onto ca7d1bc9 brings in translator changes, which would mean recompiling every shader first.

What this doesn't cover

A texture released between recording and submission is already gone when submit gathers. gather skips it, so this change can't hold it. Whether that happens too, I can't tell yet. My diagnostic now logs each list's submit time, so a fault with this change would show it.

Tests

  • python tuxbox.py check --no-gpu: 13 passed, 0 failed.
  • GPU checks for runtime/d3d12/ (python tuxbox.py check --changed): on RX 9070 XT (1002:7550), Mesa 26.3.1 RADV, GE-Proton11-15:
    Evidence: TuxBox check of 28272d9c9b98, no uncommitted changes, GPU default adapter: 15 passed, 1 failed, 0 not run
    
    The one failure is lanes-selftest-texture-publication, which is #625 (still open). It failed the same way on main (2a850114) without any change of mine yesterday. I didn't rerun it on ca7d1bc9 without this change. All other Lanes scenarios and the D3D12 regression controls pass.
  • No NVIDIA card here.
  • No Lanes scenario: reproducing it needs a title that releases a heap-viewed texture while work that reads it is in flight, and remaps the VA within milliseconds. I haven't written one.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5597853893 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/646). Originally posted by [Kayotic1337](https://github.com/Kayotic1337) on 2026-12-02T01:20:23Z. --- Possible fix for the TCP read faults in #603. **Draft:** one game run with the change so far. ## Change A recorded list holds the placed textures it binds directly (`placed_reads`), but not the ones its programs reach through a descriptor heap. `placement::submit` gathers those from the heaps' views (`views.gather`, via `Weak::upgrade`) to back and order them, then drops them when it returns. Nothing else holds them until the GPU has run the batch. If the title releases such a texture after submitting work that reads it, the image and its tiles are destroyed while that work is still queued or running. Now each batch keeps its gathered textures until its queue's reader fence reaches the batch's tick (`waits::kept::until`). Finished batches are released on the next submission. A lost device reports `u64::MAX`, which releases everything. - `placement.rs` is at its 1,200-line limit, so the logic lives in `placement/waits/kept.rs`. The call replaces the `note_readers` line in `submit`, and `until` calls `note_readers` first. - Nothing else changes: no new variable, no change to backing or ordering. ## Why I think this is the #603 fault Five runs on main after e40d8052 without the change all ended on a TCP read fault (`MAPPING_ERROR: 0x1`, vkd3d "currently mapped"), after 681–1,630 s (runs 5, 9, 10, 11, 12 in #603). In each, the fault came within 2–70 ms of a new sparse image being reserved at a VA that had just had another owner. (The "about 2 s" vkd3d prints is its device-loss time; the kernel's page-fault time, converted to vkd3d's clock, is what's within ms.) For runs 11 and 12 I logged when each unfinished draw was recorded, on vkd3d's clock: | | Run 11 | Run 12 | | --- | --- | --- | | Unfinished draws recorded | 23555.326 s | 24906.645 s | | Previous owner of the faulting VA released | 23556.990 s (a `0x60000` heap) | 24907.267 s (a 1024x1024 BC1 placed texture; drop logged 12 µs before vkd3d's `UNBIND`) | | New sparse image reserved there | 23557.075 s | 24907.349 s | | Page fault (kernel, converted) | ~23557.078 s | ~24907.355 s | So in both, the work that faulted was recorded 0.6–1.7 s before the VA's owner was released, and hadn't finished. The read only faults once the VA is remapped. All of these were mesh draws; `MS 4db9a403` was the most common in both, the same program @NickStallman and @DrArroway saw on an RTX 5090 and an RX 6900 XT. In run 11 I couldn't tell what the `0x60000` heap belonged to. I added a render-heap log for run 12, but there the previous owner was a texture, so that question is still open. ## Game RX 9070 XT (`1002:7550`), Mesa 26.3.1 RADV, GE-Proton11-15, `TUXBOX_LAZY_PUBLICATION=0`, `VKD3D_CONFIG=fault`, `TUXBOX_TRACE_GPU_FAULT=1`, drop log on. - **With this change (run 13): 2,621 s (43.7 min) without the TCP fault**, through the prison and into the next cutscene, further than I had got before. VRAM and RSS were the same as without it (13.6 GB card, 17.5 GB RSS at about 46 min, vs 12.9 / 17.2 GB in run 11 at 22 min), and so was the frame rate. - The run then ended on a different fault: an SQC (scalar data) read of address 0 on the compute ring, from a single dispatch, `CS a8ffc289`. I had that one once before without this change (run 8), so I don't think it's related. It needs its own look. - **One run only.** The game run used the same change on my local branch (`2a850114` + #639 + local diagnostics), not this PR's base. Rebasing onto `ca7d1bc9` brings in translator changes, which would mean recompiling every shader first. ## What this doesn't cover A texture released **between recording and submission** is already gone when `submit` gathers. `gather` skips it, so this change can't hold it. Whether that happens too, I can't tell yet. My diagnostic now logs each list's submit time, so a fault with this change would show it. ## Tests - `python tuxbox.py check --no-gpu`: 13 passed, 0 failed. - GPU checks for `runtime/d3d12/` (`python tuxbox.py check --changed`): on RX 9070 XT (`1002:7550`), Mesa 26.3.1 RADV, GE-Proton11-15: ```text Evidence: TuxBox check of 28272d9c9b98, no uncommitted changes, GPU default adapter: 15 passed, 1 failed, 0 not run ``` The one failure is `lanes-selftest-texture-publication`, which is #625 (still open). It failed the same way on `main` (`2a850114`) without any change of mine yesterday. I didn't rerun it on `ca7d1bc9` without this change. All other Lanes scenarios and the D3D12 regression controls pass. - No NVIDIA card here. - No Lanes scenario: reproducing it needs a title that releases a heap-viewed texture while work that reads it is in flight, and remaps the VA within milliseconds. I haven't written one. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
NickStallman commented 2026-12-02 05:36:32 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-12-02T05:36:32Z.


NVIDIA results for this, as asked: on an RTX 5090 with current main (ca7d1bc9) and default settings, this change lost the device 3 of 3, each about 2.3 minutes in, at world entry (Xid 109). That's the same as main without it.

With read residency off as well as lazy publication or once-per-frame checks, main was clean in 4 of 4 runs without this change. The full table is on #603.

My reading: with read residency on, the textures a batch reaches only through the heap aren't gathered, so this change can't hold them. It may well be right for the gathered case; this test can't separate that. I haven't run it with read residency off yet. I can, if a result for that arm would help.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:comment:7336109012 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/646#issuecomment-7336109012). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-12-02T05:36:32Z. --- NVIDIA results for this, as asked: on an RTX 5090 with current main (`ca7d1bc9`) and default settings, this change lost the device 3 of 3, each about 2.3 minutes in, at world entry (Xid 109). That's the same as main without it. With read residency off as well as lazy publication or once-per-frame checks, main was clean in 4 of 4 runs without this change. The full table is on #603. My reading: with read residency on, the textures a batch reaches only through the heap aren't gathered, so this change can't hold them. It may well be right for the gathered case; this test can't separate that. I haven't run it with read residency off yet. I can, if a result for that arm would help. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1093i3511 commented 2026-12-02 06:56:23 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by 1093i3511 on 2026-12-02T06:56:23Z.


On the SQC fault mentioned in the description (CS a8ffc289): I saw an SQC fault on RDNA2 too, an instruction fetch rather than a scalar data read, from a run without this change. Details in #603: https://github.com/brcly/TuxBox/issues/603#issuecomment-7337581570

<!-- greyfinch-sync:brcly/TuxBox:comment:7337581965 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/646#issuecomment-7337581965). Originally posted by [1093i3511](https://github.com/1093i3511) on 2026-12-02T06:56:23Z. --- On the SQC fault mentioned in the description (`CS a8ffc289`): I saw an SQC fault on RDNA2 too, an instruction fetch rather than a scalar data read, from a run without this change. Details in #603: https://github.com/brcly/TuxBox/issues/603#issuecomment-7337581570
Kayotic1337 commented 2026-12-02 19:24:46 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by Kayotic1337 on 2026-12-02T19:24:46Z.


Closing this: it doesn't prevent the #603 fault.

A second run with the same build as run 13 (64902616, this change plus diagnostics, same settings: TUXBOX_TRACE_GPU_FAULT=1 TUXBOX_LOG_TEXTURE_DROPS=1 TUXBOX_LAZY_PUBLICATION=0 VKD3D_CONFIG=fault, RX 9070 XT) hit the usual TCP read fault after 1224 s: ring 157, MAPPING_ERROR 0x1, vkd3d "Fault address is currently mapped", the same shape as runs 5 and 9–12 on #603. Run 13's 43 minutes without it was most likely luck.

That matches what I tried before opening #603: holding a dropped texture until every queue had passed it didn't stop the fault either. So keeping textures alive longer isn't the fix, and whatever the gap this PR closes is worth on its own, it isn't what causes these faults.

<!-- greyfinch-sync:brcly/TuxBox:comment:7356131697 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/646#issuecomment-7356131697). Originally posted by [Kayotic1337](https://github.com/Kayotic1337) on 2026-12-02T19:24:46Z. --- Closing this: it doesn't prevent the #603 fault. A second run with the same build as run 13 (`64902616`, this change plus diagnostics, same settings: `TUXBOX_TRACE_GPU_FAULT=1 TUXBOX_LOG_TEXTURE_DROPS=1 TUXBOX_LAZY_PUBLICATION=0 VKD3D_CONFIG=fault`, RX 9070 XT) hit the usual TCP read fault after 1224 s: ring 157, `MAPPING_ERROR 0x1`, vkd3d "Fault address is currently mapped", the same shape as runs 5 and 9–12 on #603. Run 13's 43 minutes without it was most likely luck. That matches what I tried before opening #603: holding a dropped texture until every queue had passed it didn't stop the fault either. So keeping textures alive longer isn't the fix, and whatever the gap this PR closes is worth on its own, it isn't what causes these faults.

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