HLE: DirectStorage page writes are opened before the bytes land #2566
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!2566
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@Calvix2k on GitHub · 2026-11-25 15:56 UTC · original
Calvix2k:codex/hle-dstorage-writes-before→main· +127 −16 · 3 files · 1 commits · openFixes #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.@Vedoxdev123 on GitHub · 2026-11-25 16:09 UTC · original
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.@oni-swr on GitHub · 2026-11-25 16:12 UTC · original
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.
@Marvisak on GitHub · 2026-11-25 19:19 UTC · original · edited 2026-11-25 22:15 UTC
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
@brainbudt on GitHub · 2026-11-25 21:08 UTC · original
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.ea51877ec8to89a4b63df5@Calvix2k on GitHub · 2026-11-26 18:50 UTC · original
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.
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.