Repository navigation
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
Conversation
…k only the bytes a copy changed write_back_titles() runs at the start of the shadow refresh, before ShadowPages::refresh() asks the write watch, so a hot page still carried kClean from the last asking and the title's writes since then were copied over with the older copy. write_back() now asks first (the asking moves into ask_written_locked(), shared with refresh()), holds pages whose mapping changed, that a kernel write may be filling, or that xmem aliases, and copies back only the 256-byte pieces where a copy differs from the title's bytes: a read-only binding writes nothing and its pages stay guarded, and of two copies of the same bytes only the one that differs is written. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the pieces that differ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Merging.
Follow-ups, for whoever takes them:
Thanks @OreoFR. AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2) |
|
@OreoFR, I found the same stale 1. A regression test for the hot-page case, which
2. Three retail boots with this PR on Windows/NVIDIA: RTX 2070 SUPER, 616.56. Build:
These 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 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 Next, I'll rerun with #2306 added, so the faults have sites, and with the submit-phase breakdown. |
|
Follow-up with numbers on the slowdown, from the submit-phase lines of the same boots. AI-assisted (Claude Code).
From 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: |
|
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, 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:
Thanks for the fix. |
…n in the fault handler ShadowPages::write_back copies a window's GPU writes back to the title's pages under the tracker's SRW lock (#2129, and the 256-byte pieces of #2404). It reopens its own guard first, but the page can still be read-only because of another guard (the geometry watch, another view's shadow). The copy then faults, shadow_write_fault asks every tracker over the address, and this one's reopen() took lock_ again on the thread that already held it. SRW locks are not recursive, so the title's submitting thread hung for good: on an RTX 4070 Laptop (NVIDIA 621.40) the main loop froze at 209-309 s with no device loss, and the thread dumps showed the submitting thread inside write_back -> (fault) -> shadow_write_fault -> reopen, waiting on the SRW lock, in four runs. write_back records its thread in writer_ while it holds lock_; reopen() and reopen_range() skip taking the lock on that thread (they run under it). Other threads still wait on the lock as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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, 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 d3d12: a window's GPU writes go back to the title's pages (RT-TITLE-WINDOW-WRITE-BACK) #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 mem probe: a breakdown line of the runtime's Vulkan memory by consumer (RT-MEMORY-BREAKDOWN-AND-SPARSE-ARENA) #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