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

Merged
OreoFR merged 1 commit from upstream-pr/2468 into main 2026-11-27 16:01:56 +00:00
OreoFR commented 2026-11-27 13:41:27 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-27T13:41:27Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5527621360 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2468). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-27T13:41:27Z. --- 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)
OreoFR commented 2026-11-27 13:42:39 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-27T13:42:39Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7219847178 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2468#issuecomment-7219847178). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-27T13:42:39Z. --- 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.
lixonik commented 2026-11-27 15:20:42 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-27T15:20:42Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6090273184 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2468#pullrequestreview-6090273184). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-27T15:20:42Z. **Review:** COMMENTED --- 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.
OreoFR commented 2026-11-27 15:22:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-27T15:22:08Z.


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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7221970255 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2468#issuecomment-7221970255). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-27T15:22:08Z. --- 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 commented 2026-11-27 15:56:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-27T15:56:19Z.


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)
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7222662175 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2468#issuecomment-7222662175). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-27T15:56:19Z. --- 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) ```
Tyrannys commented 2026-11-27 16:08:46 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-27T16:08:46Z.


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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7222910697 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2468#issuecomment-7222910697). Originally posted by [Tyrannys](https://github.com/Tyrannys) on 2026-11-27T16:08:46Z. --- 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).
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
ProjectLeonida/mandy!2468
No description provided.