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
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!2404
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2404/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@OreoFR on GitHub · 2026-11-26 21:23 UTC · original
OreoFR:fix/title-writeback-asks-first→main· +93 −44 · 2 files · 2 commits · merged 2026-11-26 21:49 UTCClaimed 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, beforeShadowPages::refresh()asks the write watch. A hot page (write-watched, never guarded) still carrieskCleanfrom 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.reopen_locked) before amemcpyof the whole range. A title thread writing it in between did not fault, and its write was lost.This change keeps the write-back on and does three things:
write_backasks the write watch first. The asking moves intoask_written_locked(), whichrefresh()uses too, so a hot page the title wrote is held.title_memory_mapjournal; nothing goes back when the journal no longer reaches back), pages pinned for a kernel write, and pages xmem maps at another address.docs/d3d12_vulkan.mddescribes the new behaviour.Tested
d3d12_title_vaandd3d12_title_va_shadow(the write-back tests from #2129) pass.tests/test_docs_env_vars.pypasses, andscripts/check_no_game_data.pyis clean on both changed files.mainfac8b4bb9, 600 s, shaders retranslated, write-back on (default):main, and2d43417d4the same apart from #2401): the title faulted at 95-170 s in 5 of 5 runs, each time somewhere else. One run onfac8b4bb9reached the watchdog stop at 186 s first.+0x23cf683), after the title polled a fence value that stopped arriving for about 50 s. The same stop happens withLEONIDA_TITLE_WRITEBACK=0, so it is a separate issue and not part of this change.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
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: runtime only)🤖 Generated with Claude Code
@aslan2142 on GitHub · 2026-11-26 21:49 UTC · original
Merging.
write_backran beforerefresh()asked the write watch, so a write-watched page still counted as clean and the title's newer bytes could be overwritten by an older copy. The write watch is asked first now, an unchanged view is compared in 256-byte pieces and not written, and pages whose mapping changed since the last refresh are held back.main55e2bd9e9+ this PR (46aeaaefa): the Windows suite under Wine (clang-cl + xwin) on the integrated RDNA2 GPU (RADV, Mesa 26.3.1): 425 pass and 23 fail, the same as without the PR; no test changed. The merge is clean and the changed files carry no game data.write-watched 0.0), so on Linux only the 256-byte comparison and the held-back pages apply.Follow-ups, for whoever takes them:
absorbmerges two trackers, the writes due back on that tracker at the next write-back are dropped, with no log line. It needs a counter at least, and a decision whether dropping is right.Thanks @OreoFR.
AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)
@HasiKe on GitHub · 2026-11-26 21:53 UTC · original
@OreoFR, I found the same stale
kCleanorder independently today (#1608) and had a narrower fix: ask inwrite_backonce per pass. Yours covers more, so I dropped mine. Two contributions instead. AI-assisted (Claude Code).1. A regression test for the hot-page case, which
d3d12_title_vadoes not reach today. It is in commitc9c73f48con HasiKe/leonida:writeback-hot-test: 2 files,runtime/test/d3d12_title_va_test.cppandruntime/CMakeLists.txt. Cherry-pick it if you want it.d3d12_placed_write_back_hot. It runs the placed-buffer write-back check over aMEM_WRITE_WATCHreservation recorded withtitle_write_watch::add.mainfac8b4bb9: 0/64 words survive (line 645: kept_hot == kElements).d3d12_placed_write_backstill passes too.2. Three retail boots with this PR on Windows/NVIDIA: RTX 2070 SUPER, 616.56. Build:
mainfac8b4bb9+ this PR only. Play-folder recipe: warm caches, gate on,LEONIDA_GEOMETRY_REMAP_RELEASE=1,LEONIDA_HEAP_MIRROR=1,LEONIDA_DEVICE_FAULT=2. 600 s each; the input script enters the world at 314 s.int30xc0000005at about 150 sThese are not a clean A/B against my earlier tables. This build lacks #2306, so there is no fault site in the crash log, and it lacks #2233/#2275/#2365. Both failures came before the world, where my earlier faults at 80-160 s also came on plain
main. So I can't tell yet whether the remaining CPU fault is a second cause or this build's base.One thing stood out: all three boots ran at 6-14 submissions/s and about 3-7 frames/s. My stack without this PR ran the same recipe at 110-175 submissions/s and 55-88 frames/s. Could the 256-byte comparison over every reached range be that expensive per submission? The
shadowscolumn of the submit-phase lines would show it.Next, I'll rerun with #2306 added, so the faults have sites, and with the submit-phase breakdown.
@HasiKe on GitHub · 2026-11-26 21:53 UTC · original
Follow-up with numbers on the slowdown, from the submit-phase lines of the same boots. AI-assisted (Claude Code).
shadowstime per submission (max)main+ #2365 #2233 #2275 #2276 #2306, without this PR, both switches1mainfac8b4bb9+ this PR, same switchesFrom about 210 s on, the shadow refresh costs about 25 times as much per submission, and the frame rate drops with it. The other phases stay where they were:
heaps0.5 ms,textures16 ms, up from 2.4 ms. So the 256-byte comparison, or the asking per range, scales with something that grows during the load: the number of reached ranges, or the write-watched bytes. The old unconditional copy did not grow like that. Asking once per tracker per write-back pass, instead of once perwrite_backcall, was enough in my narrower version to keep the cost flat. That may be the cheap part of it here too.@HasiKe on GitHub · 2026-11-26 22:29 UTC · original
Correction to my slowdown numbers above: they do not hold up as a cost of this PR. AI-assisted (Claude Code).
I ran the same recipe again: RTX 2070 SUPER, NVIDIA 616.56, warm caches, gate on,
LEONIDA_GEOMETRY_REMAP_RELEASE=1,LEONIDA_HEAP_MIRROR=1,LEONIDA_DEVICE_FAULT=2, 600 s. The build was mergedmaine5a7c8942(this PR, the same commits I tested before) plus #2365 #2233 #2275 #2276 #2306. In all three bootsshadowsstayed at 2.1-2.5 ms per submission through 300 s (0.25-0.30 ms in one boot), the same as without this PR.So the 56 ms in the earlier boots came from something about that build or the scene it ended up in, not from this change by itself. Sorry for the noise.
What this build does show, three of three boots:
int3. That is a different problem; I'm on it.Thanks for the fix.