Fix #2503: tell GPU write watch before DirectStorage page writes #3037
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3037
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/3037/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?
@tharun-37 on GitHub · 2026-11-26 04:33 UTC · original
tharun-37:fix/directstorage-write-watch→main· +49 −11 · 1 files · 2 commits · closed without mergingFix #2503: tell GPU write watch before DirectStorage page writes
write_physical and PageWindow called kernel_will_write (watch::writing) after writing through our own views. The watch must be told before the write so it saves the page's original bytes and keeps the guarded blocks open during the write.
Now report_written returns Writing guards that stay alive during the write, and PageWindow holds them until dropped. Views mapped while a PageWindow is open are also covered since the watch is told before the write begins.
Fixes #2503.
Attribution: This PR was created with Opencode, using decompiled GTA VI (\cyberleek) function index from D:\Codings\GTA VI\Decompiled\ to guide the DirectStorage/XMem memory pattern analysis.
@pickles976 on GitHub · 2026-11-26 04:45 UTC · original
Wine cross-check: all tests pass; the ordering fix itself ships without a regression test. Head
0bd39bf0aa7d9ba74326a0dedeb8125a2f743cb0, Linux + Wine 11.0 (vkd3d-proton 3.2.0, NVIDIA 590.48.1, RTX 4060 Laptop), wrapper-injected--locked --target x86_64-pc-windows-msvc, one test thread, freshCompiling victory-hle .../VIctory-pr3037/...provenance.aliases_empty_query_returns_early,aliases_overflow_saturates_and_skips) — 2/2 pass.xmemmodule (-p victory-hle --lib xmem) — 12/12 pass, includingpage_windows_cover_one_run_in_placeandwrites_cross_runs_and_allocations, which exercise the changedwrite_physical/page_windowpaths.Two review points, since this is racing #2504 and #2566 on the same confirmed issue:
aliases()saturating arithmetic. The actual fix —report_writtenreturning liveKernelWriteguards taken before the write inwrite_physical, and held fromPageWindowconstruction to drop — has no test pinning it. A one-line reversal back to an end-of-writereport_written(&shown)would pass this suite.shown_atonce, atPageWindowconstruction / before thewrite_physicalcopy, andreport_writtencallskernel_will_write(page, PAGE)per title-view address. A view mapped over the same physical page at a fresh guest address mid-window is not in that list. The description says such views are covered "since the watch is told before the write begins"; a guard scoped to the old address does not obviously extend to the new one. The same mid-window take-and-arm shape Kajanos raised on #2504 is worth one test here regardless: map a view mid-window,take+ arm it, drop the window, run the marked copy-back, and assert the streamed bytes survive.Verified scope: CPU-side
xmemfixtures under Wine; no GPU fixture, no title data, no DirectStorage queue run. Local logs:.compat-runtime/logs/verify-pr3037-wine-aliases.log,verify-pr3037-wine-xmem.log. AI-assisted verification and report (OpenAI Codex).@pawrenity on GitHub · 2026-11-26 05:04 UTC · original
VERIFY-3037: verified
0bd39bfon NVIDIA GeForce RTX 4070, Windows 11. The tests pass on the PR's own base. But the branch conflicts with current main, and if the conflicts are settled the way the PR does it, main's late-mapping fix from2921092is lost. #2504 covers #2503 more fully.On the PR head (base
940d32f)cargo test --locked -p victory-hle: 145 lib tests passed, 0 failed.xmem: 12/12, including the two newaliases_*tests.cargo clippy --locked -p victory-hle --all-targets -- -D warnings: clean.write_physicalandpage_windowso they drop thereport_writtenguards right away (the old "tell after" behaviour).xmemstill passed 12/12. No test pins the ordering fix.Regression tests
63bcca4. Both pass there, so they do not fail without the fix.aliases(at, 0)panics with "range start is greater than range end in BTreeMap" when a view is mapped. I checked this with a separate test that maps a page and queries it with len 0: it panics on main and passes on this head. The PR's own test passesallocate()page numbers as addresses. It only reaches the panic when another test has left a view mapped, so whether it catches the bug depends on test order. On main, the only caller ofxmem::aliasespasseslen = PAGE, so the zero-length case looks unreachable today (from reading the code).Trial merge onto origin/main
63bcca4crates/victory-hle/src/modules/xmem.rs, 6 regions (report_written,write_physical,PageWindow/Drop,page_window). Merge aborted.report_writtenreturns guards and keeps main'sREPORTEDhook, guards are taken before the write and held for the window's lifetime, and nothing is reported on drop. Main'spage_windows_report_where_the_pages_show_when_donethen fails: it reports the old addressainstead ofb, the address the page was mapped at while the window was open.physical_writes_guard_views_before_writing_and_catch_late_mappingsagainst that same port. The armed view's saved-bytes check passes.t2.changed(a2 / PAGE)fails:t2tracks the page mapped while the window was open, and it is never marked changed.Defects
crates/victory-hle/src/modules/xmem.rs:672(page_window) and:622(write_physical): the title views are looked up once, before the write, and nothing reports after it. A view mapped while aPageWindowis open is never told. This is the second half of #2503, and main already handles it withshown_at(&self.pages)on drop. The description says these views are covered, but the test results above show they are not. The fix needs both: guards taken before the write, and a lookup after it.aliases()arithmetic, which is not related to #2503. Neither fails on origin/main as written.Compared with the other PRs for #2503 (I checked xmem only)
4876663, basef3578e3): holds guards from before the write, and keeps main'sshown_at(pages)report after the write and on drop. Its test uses real write-watch trackers (exposed through atest-hooksfeature) and checks both the saved bytes before the write and the late mapping. On its head,xmemwith this PR's two tests added: 17/17 passed.ea51877, base67e8ae1, 78 commits behind main): also opens before and reports late-mapped views afterwards, through a newtitle_memory_written. On its head, its ownxmemtests passed (13). This PR'saliases_empty_query_returns_earlypanicked there because a view was mapped, which is the main-side bug described above, not a defect in #2566.test-hooksexport does not exist on this base. The cross-check above ran against the port onto main instead.Not tested: GPU fixtures beyond the CPU-side
xmemwatch tests, a real DirectStorage queue, title data.AI-assisted (Claude Code).
@Marvisak on GitHub · 2026-11-26 05:17 UTC · original
Automated triage for the maintainers.
Needs rebase. This branch conflicts with current
mainincrates/victory-hle/src/modules/xmem.rs. It will be reviewed once it is rebased and merges cleanly.Generated by Claude Code
@tharun-37 on GitHub · 2026-11-26 05:50 UTC · original
Rebasing on clean branch without unrelated aliases changes
@tharun-37 on GitHub · 2026-11-26 06:00 UTC · original · edited 2026-11-26 06:01 UTC
This PR has been replaced by #3063 (#3063).
Same fix (#2503: tell GPU write watch before DirectStorage page writes), rebased on clean upstream/main with unrelated aliases changes removed, and with both pre-write guards and post-write current-view reporting included per reviewer feedback.
Pull request closed