HLE: DirectStorage page writes are opened before the bytes land #2564
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2566"
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?
Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-25T15:56:32Z.
Fixes #2503.
The failure
xmemtold the write watch about DirectStorage's page-destination writes only after writing:report_writtencalledkernel_will_writeand dropped it at once, at the end ofwrite_physicaland inPageWindow::drop.watch::writingsaves an armed page's bytes before it changes, so reporting after the write saved the bytes DirectStorage had just written. A marked copy-back then compared the copy against those bytes, took the copy's old bytes for the GPU's, and put them back over the streamed data. A title view mapped over the pages while aPageWindowwas open was not in the list at all, so its tracker missed the write.What the change does
write_physicalopens the title views showing the bytes (write_before→kernel_will_write) before it copies, and drops them when it is done.PageWindowopens them when it is created and holds them until it drops: the decode runs with the pages opened, marked changed, and an armed page keeps what was there before it.victory_gpu::title_memory_written, a new function inwatch.rsthat marks the page changed without saving bytes — reading them then would keep the write instead of what it replaced.Tests
a_window_opens_the_title_views_before_its_bytes: the view is opened when the window is created (a test-only hook records it), and it is not reported again at drop. Before the change nothing was opened and the view was reported at drop.page_windows_report_where_the_pages_show_when_done: a view mapped during the window is still told; thewrite_physicalhalf now asserts that the existing view is opened and nothing is reported afterwards.a_write_reported_after_the_fact_saves_nothing(watch.rs): the bytes kept for an armed page are the ones from before the write, not the ones the write left.cargo test -p victory-hle --lib: 147 passed.cargo test -p victory-gpu --features diagnostics --lib: 198 passed, 1 ignored, plus the known placed-view failure on a runtime withoutID3D12Device10(#1999, identical onmain). Clippy-D warningsclean on both.The new
title_memory_writtenis exported next tokernel_will_write; it is the "write already happened" half of the pair, and it keeps saved bytes.Imported from Marvisak/VIctory. Originally posted by Vedoxdev123 on 2026-11-25T16:09:16Z.
Tested on Windows with AMD Ryzen 5 5600X + NVIDIA GeForce RTX 4060 (AI-assisted):
cargo test -p victory-gpu --lib-> 194 passed; 2 failed; 1 ignored (up from192 passed; 3 failedonmain; new tests pass andviews_bound_while_another_slot_gets_its_texture_do_not_waitpasses).Only the 2 known 1,000,000 view heap cap tests (
dynamic_slots_are_held_until_releasedandlists_share_a_table_and_copies_keep_their_viewsfrom #1744) remain.Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T16:12:06Z.
Independent verification (software WARP only)
ea51877ec80881c007999fd07b937bc6ebd9c0b3(checked out detached)67e8ae1401df112248aed36d0024483181b718b7; read-onlygit merge-tree --write-tree origin/main <head>merges cleanly (exit 0); GitHub reports MERGEABLE.VICTORY_D3D12_WARP=1withVICTORY_DXILpointing at the Windows SDK 10.0.26100dxil.dll. Default features, no extra test flags.Commands and results
cargo test --locked -p victory-hlecargo test --locked -p victory-gpucargo test --locked -p victory-hle --lib xmem,cargo test --locked -p victory-gpu --lib a_write_reported_aftera_window_opens_the_title_views_before_its_bytesandpage_windows_report_where_the_pages_show_when_done); integration tests 1 + 1 passed.a_write_reported_after_the_fact_saves_nothingpasses). The placed-view failure the description mentions does not appear on WARP.Review: Looks correct. Views are opened (
kernel_will_write) before the bytes land and held to the end, so an armed page keeps its pre-write bytes. Views mapped meanwhile are told afterwards with the newtitle_memory_written, which marks changed without saving.report_newskips addresses already held, so nothing is reported twice. Inpage_windowthe view is mapped before the guards open, so theNonereturn leaves no guard behind. No regressions seen in the two crates. Nit only:told/heldordering inPageWindow::droprelies onheldbeing dropped beforereport_new, which the code does explicitly.Review and verification by Claude Code (Claude Sonnet 5.5), AI-assisted; no game files, dumps, shader names or hashes involved.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T19:19:22Z.
Automated triage for the maintainers.
Needs rebase. This PR no longer merges cleanly into
main:mainhas moved since the last triage, and the branch now conflicts incrates/victory-gpu/src/watch.rs. It will be reviewed again once it is rebased onto currentmain.Previous verdict for this head: merge candidate.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by brainbudt on 2026-11-25T21:08:34Z.
Independently verified
ea51877merged onto13f91ca(and combined with #2553; both merge orders produce the same tree and pass Windows 11 DirectStorage/xmem/watch tests and MSVC workspacecargo check --tests).Opening existing views before the write fixes the original pre-image ordering, but one remaining race reproduced on Windows 11:
crates/victory-hle/src/modules/xmem.rs:696-705): Opening a window on an unmapped physical page, mapping a new title view, taking/arming its tracker, and writing through the window leaves the tracker clean until drop—so a marked GPU copy-back in that interval can overwrite the streamed bytes with stale host bytes. Making the new mapping participate in the active physical write (or deferring copy-back until reported) plus a regression covering the pre-drop interval would close this gap.crates/victory-gpu/src/watch.rs:1225-1246): Changing the end-of-write notification tosave=truestill passes the new GPU watch test; making that report the first change after take-and-arm catches the mutation.Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-26T18:50:07Z.
The rebase is up (current head pushed against today's main). The late-mapped-view race you describe is not something this change tries to solve - it is the same interval from the other side, a view mapped after the window opened.
Two ways to take it: either you open it as an issue with the test you used, and whoever picks up the view-tracking work fixes it there, or I fold the case into this PR. I would prefer the issue unless you think the fix belongs in the same place as the write pre-image ordering - then say so and I will do it here.
Imported from Marvisak/VIctory. Originally posted by playcations on 2026-11-27T06:28:45Z.
Independent CPU-only regression on current head
89a4b63df5e75252cb58202fdf81f0ca03474161, addressing the mutation gap identified above.The fixture maps one pagefile section twice but registers only the reader with the watch. It takes/arms that reader while clean, writes
0x22through the unregistered private mapping, then reports the completed write. It requires the reader to see0x22, become dirty, and have no saved pre-image.drop(writing(at, PAGE)): fails,saved == Some(34)instead ofNone.63bcca43c6a00a758510398fa43096ce7e4f7df0with the same fixture using its existingdrop(writing(...))route: fails at that same assertion, for the same saved byte.Thus the regression distinguishes the saving and non-saving notifications; unlike the existing test, no earlier
writingcall has already saved/marked the page. The full synthetic test below can be added insidewatch::tests:Environment: Ubuntu 26.04.1, Wine 11.22 Staging, Rust 1.98.1 Windows/MSVC target via cargo-xwin. Only this exact watch test was run; the container exposed no GPU and mounted no game data. This checks the real watch/Windows mapping APIs under Wine, not native Windows acceptance, the full PageWindow integration path, or the separately deferred interval before window drop. No cross-crate test API or runtime implementation changes. AI-assisted with Codex GPT-6.1 Sol; fixture and captured failures reviewed.
Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-27T07:23:21Z.
Independent CPU-only verification of PR #2566 (
DirectStorage: open title views before bytes / writes reported after the fact save nothing).CARGO_TARGET_DIR(D:\Victory-Contrib\target-2566-verify),CARGO_BUILD_JOBS=2.89a4b63df5e75252cb58202fdf81f0ca03474161, merge base63bcca43c6a00a758510398fa43096ce7e4f7df0.target-2566-watchwas stale and gave a false0 tests(compiled in 0.06s). A fresh target dir rebuilt in 2m07s and ran the tests correctly.cargo test --locked -p victory-gpu --lib -- watch::tests::a_write_reported_after_the_fact_saves_nothing --exact --test-threads=1 --quiet->1 passed; 0 failed; 232 filtered.cargo test --locked -p victory-hle --lib -- modules::xmem::tests::a_window_opens_the_title_views_before_its_bytes --exact --test-threads=1 --quiet->1 passed; 0 failed; 152 filtered.git grep -Ffor both new test names on base63bcca4returned no hits (tests absent on base).git diff --check 63bcca4 HEADexit 0 (clean).git diff --checkflagged new blank lines at EOF inapps/victory/src/translate.rs:899andcrates/victory-shader/src/emit/validator.rs:419.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.