[PR #2404] [MERGED] d3d12: the title write-back asks the write watch first and copies back only the bytes a copy changed (RT-TITLE-WRITEBACK-STALE-BYTES) #2404

Closed
opened 2026-11-26 22:26:07 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2404
Author: @OreoFR
Created: 11/26/2026
Status: ✅ Merged
Merged: 11/26/2026
Merged by: @aslan2142

Base: main ← Head: fix/title-writeback-asks-first


📝 Commits (2)

  • 0894ecd d3d12: the title write-back asks the write watch first and copies back only the bytes a copy changed
  • 46aeaae docs: the title write-back asks the write watch first and writes only the pieces that differ

📊 Changes

2 files changed (+93 additions, -44 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+6 -3)
📝 runtime/shims/d3d12_vulkan_device.cpp (+87 -41)

📄 Description

Claimed in the coordination issue as: RT-TITLE-WRITEBACK-STALE-BYTES (released to me by @DadaCap)

What and why

Since #2350 (which brings #2129, the title write-back), the story load crashes on Windows/NVIDIA. The title faults at a different place on every run: null writes, a non-pointer read, its own int3. Turning the write-back off removes these faults, but it is still needed for #1537.

The cause is in ShadowPages::write_back (runtime/shims/d3d12_vulkan_device.cpp):

  • write_back_titles() runs at the start of the shadow refresh, before ShadowPages::refresh() asks the write watch. A hot page (write-watched, never guarded) still carries kClean from the last asking. Every write the title made to it since the last submission was therefore copied over with the older shadow. Hot pages are the ones the title writes most.
  • A guarded page was opened (reopen_locked) before a memcpy of the whole range. A title thread writing it in between did not fault, and its write was lost.
  • Every binding reached was copied back whole, read-only ones too (a V# has no read/write bit). Where two copies covered the same bytes, the last one won.

This change keeps the write-back on and does three things:

  • write_back asks the write watch first. The asking moves into ask_written_locked(), which refresh() uses too, so a hot page the title wrote is held.
  • It holds pages whose mapping changed since the last refresh (from the title_memory_map journal; nothing goes back when the journal no longer reaches back), pages pinned for a kernel write, and pages xmem maps at another address.
  • It compares in 256-byte pieces and writes only those where the copy differs from the title's bytes. A read-only view writes nothing and its pages stay guarded. Of two copies of the same bytes, only the one that differs is written.

docs/d3d12_vulkan.md describes the new behaviour.

Tested

  • d3d12_title_va and d3d12_title_va_shadow (the write-back tests from #2129) pass. tests/test_docs_env_vars.py passes, and scripts/check_no_game_data.py is clean on both changed files.
  • Retail story load on main fac8b4bb9, 600 s, shaders retranslated, write-back on (default):
    • before (main, and 2d43417d4 the same apart from #2401): the title faulted at 95-170 s in 5 of 5 runs, each time somewhere else. One run on fac8b4bb9 reached the watchdog stop at 186 s first.
    • with this change: no title fault in the load. 52 KiB went back in 313 s, against about 26 MiB by 186 s before.
  • The run then stops at 313 s on the title's hang watchdog (+0x23cf683), after the title polled a fence value that stopped arriving for about 50 s. The same stop happens with LEONIDA_TITLE_WRITEBACK=0, so it is a separate issue and not part of this change.
  • Likely the random faults of #2396 (left open: that run may also meet the watchdog stop above). Others: nicoco23 (RTX 5070) and HasiKe (RTX 2070 SUPER, in #1608) see the random faults go away with LEONIDA_TITLE_WRITEBACK=0.

GPUs tested: NVIDIA GeForce RTX 4070 Laptop 8 GB, driver 621.40, Windows 11.

AI-assisted: yes (Claude Code, Claude Opus 5.5)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: runtime only)

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2404 **Author:** [@OreoFR](https://github.com/OreoFR) **Created:** 11/26/2026 **Status:** ✅ Merged **Merged:** 11/26/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `fix/title-writeback-asks-first` --- ### 📝 Commits (2) - [`0894ecd`](https://github.com/ubiquitarianism/leonida/commit/0894ecd1747e22cd501f7811d57326c37241a03b) d3d12: the title write-back asks the write watch first and copies back only the bytes a copy changed - [`46aeaae`](https://github.com/ubiquitarianism/leonida/commit/46aeaaefab2b2818436606fc7ac02528e1659fa6) docs: the title write-back asks the write watch first and writes only the pieces that differ ### 📊 Changes **2 files changed** (+93 additions, -44 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+6 -3) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+87 -41) </details> ### 📄 Description Claimed in the coordination issue as: [RT-TITLE-WRITEBACK-STALE-BYTES](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7203622380) (released to me by @DadaCap) ### What and why Since #2350 (which brings #2129, the title write-back), the story load crashes on Windows/NVIDIA. The title faults at a different place on every run: null writes, a non-pointer read, its own `int3`. Turning the write-back off removes these faults, but it is still needed for #1537. The cause is in `ShadowPages::write_back` (`runtime/shims/d3d12_vulkan_device.cpp`): - `write_back_titles()` runs at the start of the shadow refresh, before `ShadowPages::refresh()` asks the write watch. A hot page (write-watched, never guarded) still carries `kClean` from the last asking. Every write the title made to it since the last submission was therefore copied over with the older shadow. Hot pages are the ones the title writes most. - A guarded page was opened (`reopen_locked`) before a `memcpy` of the whole range. A title thread writing it in between did not fault, and its write was lost. - Every binding reached was copied back whole, read-only ones too (a V# has no read/write bit). Where two copies covered the same bytes, the last one won. This change keeps the write-back on and does three things: - `write_back` asks the write watch first. The asking moves into `ask_written_locked()`, which `refresh()` uses too, so a hot page the title wrote is held. - It holds pages whose mapping changed since the last refresh (from the `title_memory_map` journal; nothing goes back when the journal no longer reaches back), pages pinned for a kernel write, and pages xmem maps at another address. - It compares in 256-byte pieces and writes only those where the copy differs from the title's bytes. A read-only view writes nothing and its pages stay guarded. Of two copies of the same bytes, only the one that differs is written. `docs/d3d12_vulkan.md` describes the new behaviour. ### Tested - `d3d12_title_va` and `d3d12_title_va_shadow` (the write-back tests from #2129) pass. `tests/test_docs_env_vars.py` passes, and `scripts/check_no_game_data.py` is clean on both changed files. - Retail story load on `main` `fac8b4bb9`, 600 s, shaders retranslated, write-back on (default): - before (`main`, and `2d43417d4` the same apart from #2401): the title faulted at 95-170 s in 5 of 5 runs, each time somewhere else. One run on `fac8b4bb9` reached the watchdog stop at 186 s first. - with this change: no title fault in the load. 52 KiB went back in 313 s, against about 26 MiB by 186 s before. - The run then stops at 313 s on the title's hang watchdog (`+0x23cf683`), after the title polled a fence value that stopped arriving for about 50 s. The same stop happens with `LEONIDA_TITLE_WRITEBACK=0`, so it is a separate issue and not part of this change. - Likely the random faults of #2396 (left open: that run may also meet the watchdog stop above). Others: nicoco23 (RTX 5070) and HasiKe (RTX 2070 SUPER, in #1608) see the random faults go away with `LEONIDA_TITLE_WRITEBACK=0`. GPUs tested: NVIDIA GeForce RTX 4070 Laptop 8 GB, driver 621.40, Windows 11. AI-assisted: yes (Claude Code, Claude Opus 5.5) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: runtime only) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 changed title from [PR #2404] d3d12: the title write-back asks the write watch first and copies back only the bytes a copy changed (RT-TITLE-WRITEBACK-STALE-BYTES) to [PR #2404] [MERGED] d3d12: the title write-back asks the write watch first and copies back only the bytes a copy changed (RT-TITLE-WRITEBACK-STALE-BYTES) 2026-11-26 22:51:09 +01:00
4ld0 closed this issue 2026-11-26 22:51:09 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#2404
No description provided.