Skip to content

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

Merged
aslan2142 merged 1 commit into
ProjectLeonida:mainfrom
OreoFR:rt-writeback-tile-reopen
Nov 27, 2026
Merged

aslan2142 merged 1 commit into
ProjectLeonida:mainfrom
OreoFR:rt-writeback-tile-reopen

Conversation

@OreoFR

@OreoFR OreoFR commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

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

… still go back (RT-WRITEBACK-TILE-REOPEN)

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 ProjectLeonida#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
ProjectLeonida#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 ProjectLeonida#2418.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@OreoFR

OreoFR commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

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 lixonik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

OreoFR commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

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 ec91d69 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

OreoFR commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

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)

@aslan2142
aslan2142 merged commit 55bd6f4 into ProjectLeonida:main Nov 27, 2026
6 of 12 checks passed
Tyrannys added a commit to Tyrannys/leonida that referenced this pull request Nov 27, 2026
…ck-same-page-ranges

ubiquitarianism#2468 (RT-WRITEBACK-TILE-REOPEN) took write_back's per-page held decision
before the copies for one range. This branch takes it for all of a tracker's
ranges in one call, so the two are now one snapshot over every range, kept in
ubiquitarianism#2468's host-heap member held_pages_ (sized before lock_ is taken). Both tests
stay: d3d12_title_window_write_back_fault_tile and
d3d12_title_window_write_back_ranges; submit_write takes both va2 and base.

Also from lixonik's review: a run whose pages an earlier range already
reopened (none still kProtected) skips reopen_locked and its VirtualQuery.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Tyrannys

Copy link
Copy Markdown
Contributor

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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants