d3d12: a write-back's later runs in a tile its faulting copy reopened still go back (RT-WRITEBACK-TILE-REOPEN) #2468

Manually merged
github merged 1 commit from github-bot/gh-2468 into main 2026-11-27 16:16:04 +00:00 AGit
Owner

@⁠OreoFR on GitHub · 2026-11-27 13:41 UTC · original
OreoFR:rt-writeback-tile-reopen → main · +48 −9 · 3 files · 1 commits · merged 2026-11-27 16:01 UTC

Item: RT-WRITEBACK-TILE-REOPEN. Depends on: none (follows #2418).

The bug (EVIDENCE: READ IN CODE, runtime/shims/d3d12_vulkan_device.cpp at the base commit f5c3ea2e0): ShadowPages::write_back decided inside its loop whether each page's GPU result goes back (held(), lines 449-460). When a copy faults on another guard (a geometry watch cell), shadow_write_fault reopens the whole 64 KiB tile and calls reopen_range on the writing tracker (line 1534). On the write-back's own thread that runs under the lock #2418 lets it reuse (lines 880-887), and it clears kClean, and kProtected through reopen_locked, across the tile. The later runs in that tile then read as written by the title, so their GPU results are dropped from a batch that is already off the queue, and the next forward copy writes the title's older bytes over them. The #2418 test missed this because it has only one run per tile.

The fix: the per-page decision is taken for the whole range before the first copy, into a host-heap vector the tracker keeps (it allocates under lock_, as the tracker's other containers already do). A page the title wrote before the write-back (not guarded and not clean after the asking) is still held, so the title's words still win.

Test: d3d12_title_window_write_back_fault_tile (d3d12_title_va_test --window-writeback-fault-tile) is the #2418 fault case with a second dispatch on the third page of the tile and a title write on the second page. That gives the write-back three runs: [page 0] faults, [page 1] is the title's and is held, [page 2] must go back. EVIDENCE: MEASURED, 3 runs each:

  • base f5c3ea2e0: fails 3/3, 0 of 64 words on page 2 go back
  • with the fix: passes 3/3, 64 of 64 go back
  • in both, the title's word on page 1 is kept

Other checks: d3d12_title_va, d3d12_title_va_shadow, d3d12_geometry_views, d3d12_title_window_cap, d3d12_title_window_write_back, d3d12_title_window_write_back_fault, d3d12_placed_write_back and d3d12_shadow_keep_refill(_off) pass. Of the 208 ctest tests matching d3d12_|shadow|title|write_watch|geometry, two failed:

  • d3d12_queue_wait_timeout timed out under -j 4 and passes when run alone.
  • d3d12_set_descriptor_heaps also fails on the base commit without this change, so it is unrelated.

check_no_game_data.py and the tests/test_docs_* checks pass.

Touches the slot-133 write-back, which #2464 lists under the performance rewrite: @⁠aslan2142 feel free to fold it into your rewrite instead of merging it.

Found by DadaCap's review.

GPUs tested: profile M, RTX 4070 Laptop 8 GB, NVIDIA 621.40, Windows 11 (unit tests only, no game run).

AI-assisted (Claude Code).

🤖 Generated with Claude Code

**@⁠OreoFR** on GitHub · 2026-11-27 13:41 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2468) `OreoFR:rt-writeback-tile-reopen` → `main` · +48 −9 · 3 files · 1 commits · merged 2026-11-27 16:01 UTC Item: RT-WRITEBACK-TILE-REOPEN. Depends on: none (follows #2418). **The bug** (EVIDENCE: READ IN CODE, `runtime/shims/d3d12_vulkan_device.cpp` at the base commit `f5c3ea2e0`): `ShadowPages::write_back` decided inside its loop whether each page's GPU result goes back (`held()`, lines 449-460). When a copy faults on another guard (a geometry watch cell), `shadow_write_fault` reopens the whole 64 KiB tile and calls `reopen_range` on the writing tracker (line 1534). On the write-back's own thread that runs under the lock #2418 lets it reuse (lines 880-887), and it clears `kClean`, and `kProtected` through `reopen_locked`, across the tile. The later runs in that tile then read as written by the title, so their GPU results are dropped from a batch that is already off the queue, and the next forward copy writes the title's older bytes over them. The #2418 test missed this because it has only one run per tile. **The fix:** the per-page decision is taken for the whole range before the first copy, into a host-heap vector the tracker keeps (it allocates under `lock_`, as the tracker's other containers already do). A page the title wrote before the write-back (not guarded and not clean after the asking) is still held, so the title's words still win. **Test:** `d3d12_title_window_write_back_fault_tile` (`d3d12_title_va_test --window-writeback-fault-tile`) is the #2418 fault case with a second dispatch on the third page of the tile and a title write on the second page. That gives the write-back three runs: [page 0] faults, [page 1] is the title's and is held, [page 2] must go back. EVIDENCE: MEASURED, 3 runs each: - base `f5c3ea2e0`: fails 3/3, 0 of 64 words on page 2 go back - with the fix: passes 3/3, 64 of 64 go back - in both, the title's word on page 1 is kept **Other checks:** `d3d12_title_va`, `d3d12_title_va_shadow`, `d3d12_geometry_views`, `d3d12_title_window_cap`, `d3d12_title_window_write_back`, `d3d12_title_window_write_back_fault`, `d3d12_placed_write_back` and `d3d12_shadow_keep_refill(_off)` pass. Of the 208 ctest tests matching `d3d12_|shadow|title|write_watch|geometry`, two failed: - `d3d12_queue_wait_timeout` timed out under `-j 4` and passes when run alone. - `d3d12_set_descriptor_heaps` also fails on the base commit without this change, so it is unrelated. `check_no_game_data.py` and the `tests/test_docs_*` checks pass. Touches the slot-133 write-back, which #2464 lists under the performance rewrite: @⁠aslan2142 feel free to fold it into your rewrite instead of merging it. Found by DadaCap's review. GPUs tested: profile M, RTX 4070 Laptop 8 GB, NVIDIA 621.40, Windows 11 (unit tests only, no game run). AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
ShadowPages::write_back decided page by page, inside its loop, whether a page's GPU result goes back. A copy
that faults on another guard (a geometry watch cell) makes the handler reopen the whole 64 KiB tile on the
write-back's own thread (reopen_range, under the lock #2418 lets it reuse), which clears kClean and kProtected
there. The runs after it in the tile then read as written by the title: their GPU results were dropped from
a batch already taken off the queue, and the next forward copy put the title's older bytes over them.

The decision is now taken for every page of the range before the first copy, into a host-heap vector the
tracker keeps. A page the title wrote before the write-back (not guarded and not clean after the asking)
is still held, so the title's words win as before.

Test: d3d12_title_window_write_back_fault_tile (d3d12_title_va_test --window-writeback-fault-tile), the
#2418 fault case with a second dispatch on the third page of the tile and a title write on the second.
Found by DadaCap's review of #2418.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 13:55:15 +00:00
Author
Owner

@⁠OreoFR on GitHub · 2026-11-27 13:42 UTC · original

Known limit, for the record: the held decision is taken once per write_back call. If one batch has two separate ranges in the same 64 KiB tile and the first one's copy faults, the second call still sees that tile as title-written. Not covered by this PR or its test. EVIDENCE: READ IN CODE.

**@⁠OreoFR** on GitHub · 2026-11-27 13:42 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2468#issuecomment-7219847178) Known limit, for the record: the held decision is taken once per `write_back` call. If one batch has two separate ranges in the same 64 KiB tile and the first one's copy faults, the second call still sees that tile as title-written. Not covered by this PR or its test. EVIDENCE: READ IN CODE.
Author
Owner

@⁠lixonik on GitHub · 2026-11-27 15:20 UTC · original · reviewed

Reviewed and tested at f380834f9 (merged cleanly onto main ec91d695c).

The fix is clean and minimal: storing held_pages_ in leonida::host_heap::vector avoids process-heap allocation under lock_ (safe against fault-handler deadlock), and d3d12_title_window_write_back_fault_tile reproduces and verifies the exact failure mode.

Coordination note: #2470 touches the same lines in runtime/CMakeLists.txt, runtime/shims/d3d12_vulkan_device.cpp, and runtime/test/d3d12_title_va_test.cpp to batch all ranges per tracker into one write_back() call with a single held_pages snapshot (which also covers the multi-range-in-one-tile limit noted above). Combining #2468's host_heap held_pages_ member and --window-writeback-fault-tile test with #2470's batched write_back() would resolve both together without conflict.

Verified locally on Windows 11 (MSVC 19.44.35230.0, Ninja Release, NVIDIA GeForce RTX 5070, driver 610.88, Vulkan 1.4.341; note VK_LAYER_KHRONOS_validation is not installed locally so Vulkan validation layers did not run):

  • d3d12_title_window_write_back, d3d12_title_window_write_back_fault, d3d12_title_window_write_back_fault_tile (64/64 words on page 2 returned, title's word on page 1 kept), d3d12_placed_write_back: 4/4 passed
  • scripts/check_no_game_data.py and git diff --check: clean

No findings.

AI-assisted.

**@⁠lixonik** on GitHub · 2026-11-27 15:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2468#pullrequestreview-6090273184) · **reviewed** Reviewed and tested at `f380834f9` (merged cleanly onto `main` `ec91d695c`). The fix is clean and minimal: storing `held_pages_` in `leonida::host_heap::vector` avoids process-heap allocation under `lock_` (safe against fault-handler deadlock), and `d3d12_title_window_write_back_fault_tile` reproduces and verifies the exact failure mode. Coordination note: `#2470` touches the same lines in `runtime/CMakeLists.txt`, `runtime/shims/d3d12_vulkan_device.cpp`, and `runtime/test/d3d12_title_va_test.cpp` to batch all ranges per tracker into one `write_back()` call with a single `held_pages` snapshot (which also covers the multi-range-in-one-tile limit noted above). Combining `#2468`'s `host_heap` `held_pages_` member and `--window-writeback-fault-tile` test with `#2470`'s batched `write_back()` would resolve both together without conflict. Verified locally on Windows 11 (MSVC 19.44.35230.0, Ninja Release, NVIDIA GeForce RTX 5070, driver 610.88, Vulkan 1.4.341; note `VK_LAYER_KHRONOS_validation` is not installed locally so Vulkan validation layers did not run): - `d3d12_title_window_write_back`, `d3d12_title_window_write_back_fault`, `d3d12_title_window_write_back_fault_tile` (64/64 words on page 2 returned, title's word on page 1 kept), `d3d12_placed_write_back`: 4/4 passed - `scripts/check_no_game_data.py` and `git diff --check`: clean No findings. AI-assisted.
Author
Owner

@⁠OreoFR on GitHub · 2026-11-27 15:22 UTC · original

Thanks @⁠lixonik. Agreed on #2470: they fit together (this PR's host_heap held_pages_ member and tile-fault test, #2470's one write_back() per tracker). Whichever lands second, I'll rebase this one onto it and keep both tests. A game-run regression A/B (main ec91d695c vs + this PR, RTX 4070 Laptop 8 GB) is queued and will be posted here as RUN blocks. AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠OreoFR** on GitHub · 2026-11-27 15:22 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2468#issuecomment-7221970255) Thanks @⁠lixonik. Agreed on #2470: they fit together (this PR's `host_heap` `held_pages_` member and tile-fault test, #2470's one `write_back()` per tracker). Whichever lands second, I'll rebase this one onto it and keep both tests. A game-run regression A/B (main ec91d695c vs + this PR, RTX 4070 Laptop 8 GB) is queued and will be posted here as RUN blocks. AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠OreoFR on GitHub · 2026-11-27 15:56 UTC · original

Game-run regression A/B for @⁠aslan2142's request. Same build recipe, shader pack, settings and caches in both arms; only this PR differs. AI-assisted (Claude Code, Claude Opus 5.5).

RUN regA | 2026-11-27 | OreoFR | AI-assisted: Claude Code (Claude Opus 5.5)
BASE:        main ec91d695c | shaders: main translation + #2447 (one-lane) pack
MACHINE:     RTX 4070 Laptop 8 GB, laptop (profile M) | NVIDIA 621.40 | Windows 11 | 40 GB
RECIPE:      documented + DEVIATIONS: ASYNC_PIPELINES=1 ASYNC_MIN_BYTES=1048576 VALUE_WAIT_TIMEOUT_MS=30000 MAP_READBACK=1 DEVICE_TYPE=6 PIPELINE_PREWARM_ORDER=1 DEVICE_FAULT=1 | precompile: partial journal
OS/DRIVER:   TdrDelay 60
TARGET:      regression check | PREDICTED: world reached, no loss
MEASURED:    world (first indirect draw) ~223 s | 600 s | 8,990 submissions | last >=1 fps window at 223 s
END:         time limit
CACHES:      warm | RUN 1 of 1
INSTRUMENTS: device fault checkpoints, thread stacks at 230/280/330/380 s
VERDICT:     held

RUN regB | same, BASE: main ec91d695c + this PR (f380834f9)
MEASURED:    world ~243 s | 600 s | 9,382 submissions | last >=1 fps window at 250 s
END:         time limit | 0 device lost, 0 exceptions (regA: 0 / 0)
             gpu-stall lines 11 (regA 10), device-stall 3 (regA 2)
VERDICT:     no regression seen (n=1 each; the display stop after world entry is the same known stop in both arms)
**@⁠OreoFR** on GitHub · 2026-11-27 15:56 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2468#issuecomment-7222662175) Game-run regression A/B for @⁠aslan2142's request. Same build recipe, shader pack, settings and caches in both arms; only this PR differs. AI-assisted (Claude Code, Claude Opus 5.5). ``` RUN regA | 2026-11-27 | OreoFR | AI-assisted: Claude Code (Claude Opus 5.5) BASE: main ec91d695c | shaders: main translation + #2447 (one-lane) pack MACHINE: RTX 4070 Laptop 8 GB, laptop (profile M) | NVIDIA 621.40 | Windows 11 | 40 GB RECIPE: documented + DEVIATIONS: ASYNC_PIPELINES=1 ASYNC_MIN_BYTES=1048576 VALUE_WAIT_TIMEOUT_MS=30000 MAP_READBACK=1 DEVICE_TYPE=6 PIPELINE_PREWARM_ORDER=1 DEVICE_FAULT=1 | precompile: partial journal OS/DRIVER: TdrDelay 60 TARGET: regression check | PREDICTED: world reached, no loss MEASURED: world (first indirect draw) ~223 s | 600 s | 8,990 submissions | last >=1 fps window at 223 s END: time limit CACHES: warm | RUN 1 of 1 INSTRUMENTS: device fault checkpoints, thread stacks at 230/280/330/380 s VERDICT: held RUN regB | same, BASE: main ec91d695c + this PR (f380834f9) MEASURED: world ~243 s | 600 s | 9,382 submissions | last >=1 fps window at 250 s END: time limit | 0 device lost, 0 exceptions (regA: 0 / 0) gpu-stall lines 11 (regA 10), device-stall 3 (regA 2) VERDICT: no regression seen (n=1 each; the display stop after world entry is the same known stop in both arms) ```
github manually merged commit 55bd6f4f1b into main 2026-11-27 16:16:04 +00:00
Author
Owner

@⁠Tyrannys on GitHub · 2026-11-27 16:08 UTC · original

For anyone following the write-back path: #2470 (RT-TITLE-WRITEBACK-SAME-PAGE-RANGES, 73N1X's finding in #1608) builds on this PR. This PR's per-page held snapshot, taken before the copies, was the right fix for the tile reopen. #2470 takes the same snapshot across all of a tracker's finished ranges in one write_back call, because disjoint ranges on one guarded page were still handed over one call at a time, and the first range that differed reopened the page for the rest. #2470 keeps this PR's held_pages_ member and its --window-writeback-fault-tile test as they are. Thanks @⁠OreoFR. AI-assisted (Claude Code).

**@⁠Tyrannys** on GitHub · 2026-11-27 16:08 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2468#issuecomment-7222910697) For anyone following the write-back path: #2470 (RT-TITLE-WRITEBACK-SAME-PAGE-RANGES, 73N1X's finding in #1608) builds on this PR. This PR's per-page `held` snapshot, taken before the copies, was the right fix for the tile reopen. #2470 takes the same snapshot across all of a tracker's finished ranges in one `write_back` call, because disjoint ranges on one guarded page were still handed over one call at a time, and the first range that differed reopened the page for the rest. #2470 keeps this PR's `held_pages_` member and its `--window-writeback-fault-tile` test as they are. Thanks @⁠OreoFR. AI-assisted (Claude Code).
This discussion has been locked. Commenting is limited to contributors.
No description provided.