HLE: DirectStorage page-destination writes tell the GPU write watch only after writing #2503

Open
opened 2026-11-26 05:07:38 +00:00 by github-bot · 2 comments
Owner

@⁠BastienRodz on GitHub · 2026-11-25 14:57 UTC · original

What happens

DirectStorage page-destination requests write into physical pages through our own views of them (xmem::page_window and xmem::write_physical). The GPU write watch cannot see those writes, because its guards are on the title's views of the same pages. xmem tells the watch only after writing: report_written calls drop(victory_gpu::kernel_will_write(page, PAGE)) at the end of write_physical and in PageWindow::drop, for the title views it found before the write.

kernel_will_write (watch::writing) is meant to come before the write. It saves an armed page's bytes before they change (changed(.., save = true)). Called afterwards, it saves the bytes DirectStorage just wrote. If a submission has that page armed for marked writes, copy_back_marked then compares the copy against those new bytes, takes the copy's old bytes for the GPU's, and puts them back over the streamed data.

A title view mapped over the pages while a PageWindow is open is not in the list taken before the write, so it is never told and its copy misses the write.

Expected

watch.rs on writing: "Before our own write into title memory [at, at + len) through the kernel (which does not fault into our handler) or another write the guards do not see: opens its guarded blocks, marks them changed and keeps them open while the result lives." The title's views of the destination pages should be opened before the write and held until it is done, as ReadFile, fread and DirectStorage's address destinations already do. Views mapped meanwhile should be told too.

Where

crates/victory-hle/src/modules/xmem.rs: report_written, write_physical, PageWindow, page_window, used by dstorage.rs (into_destination) for page destinations.

AI-assisted (Gemini 4 Neon found it, Claude Code reviewed and verified it); synthetic test only, no game data.

**@⁠BastienRodz** on GitHub · 2026-11-25 14:57 UTC · [original](https://github.com/Marvisak/VIctory/issues/2503) ### What happens DirectStorage page-destination requests write into physical pages through our own views of them (`xmem::page_window` and `xmem::write_physical`). The GPU write watch cannot see those writes, because its guards are on the title's views of the same pages. `xmem` tells the watch only after writing: `report_written` calls `drop(victory_gpu::kernel_will_write(page, PAGE))` at the end of `write_physical` and in `PageWindow::drop`, for the title views it found before the write. `kernel_will_write` (`watch::writing`) is meant to come before the write. It saves an armed page's bytes before they change (`changed(.., save = true)`). Called afterwards, it saves the bytes DirectStorage just wrote. If a submission has that page armed for marked writes, `copy_back_marked` then compares the copy against those new bytes, takes the copy's old bytes for the GPU's, and puts them back over the streamed data. A title view mapped over the pages while a `PageWindow` is open is not in the list taken before the write, so it is never told and its copy misses the write. ### Expected `watch.rs` on `writing`: "Before our own write into title memory `[at, at + len)` through the kernel (which does not fault into our handler) or another write the guards do not see: opens its guarded blocks, marks them changed and keeps them open while the result lives." The title's views of the destination pages should be opened before the write and held until it is done, as `ReadFile`, `fread` and DirectStorage's address destinations already do. Views mapped meanwhile should be told too. ### Where `crates/victory-hle/src/modules/xmem.rs`: `report_written`, `write_physical`, `PageWindow`, `page_window`, used by `dstorage.rs` (`into_destination`) for page destinations. AI-assisted (Gemini 4 Neon found it, Claude Code reviewed and verified it); synthetic test only, no game data.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:07:38 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 18:51 UTC · original · edited 2026-11-25 21:46 UTC

Automated triage for the maintainers.

The first half is confirmed in main (61bfc77), in crates/victory-hle/src/modules/xmem.rs:

  • write_physical copies the bytes through its own views first, and only then calls report_written.
  • PageWindow calls report_written from Drop, after DirectStorage has decoded into it.
  • report_written runs drop(victory_gpu::kernel_will_write(page, PAGE)) for each title view.

So the watch's "before the write" step comes after the bytes have already landed. An armed page then saves the new bytes as its "before" bytes.

The second half does not match the code as stated. PageWindow looks up the title views with shown_at(&self.pages) when it is dropped, not when it opens, so a view mapped while the window is open is reported. It is reported with the same wrong order, though: if it was armed mid-window, the end-of-write report saves the streamed bytes as its "before" bytes too.

Two open PRs: #2504 and #2566. A review above (by reading, not run) finds that #2504 opens only the views present when the write begins and keeps the end-of-write report_written, so a view mapped and armed mid-window keeps the problem; #2566 covers both cases (it marks views mapped meanwhile as written, without saving). It also suggests a test that arms the mid-window view and checks nothing was saved, which fails on main and on #2504. The two PRs touch the same functions and conflict.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 18:51 UTC · [original](https://github.com/Marvisak/VIctory/issues/2503#issuecomment-7171492627) · edited 2026-11-25 21:46 UTC <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-25T19:02:21Z at=2026-11-25T22:01:00Z --> Automated triage for the maintainers. The first half is confirmed in main (61bfc77), in `crates/victory-hle/src/modules/xmem.rs`: - `write_physical` copies the bytes through its own views first, and only then calls `report_written`. - `PageWindow` calls `report_written` from `Drop`, after DirectStorage has decoded into it. - `report_written` runs `drop(victory_gpu::kernel_will_write(page, PAGE))` for each title view. So the watch's "before the write" step comes after the bytes have already landed. An armed page then saves the new bytes as its "before" bytes. The second half does not match the code as stated. `PageWindow` looks up the title views with `shown_at(&self.pages)` when it is dropped, not when it opens, so a view mapped while the window is open is reported. It is reported with the same wrong order, though: if it was armed mid-window, the end-of-write report saves the streamed bytes as its "before" bytes too. Two open PRs: #2504 and #2566. A review above (by reading, not run) finds that #2504 opens only the views present when the write begins and keeps the end-of-write `report_written`, so a view mapped and armed mid-window keeps the problem; #2566 covers both cases (it marks views mapped meanwhile as written, without saving). It also suggests a test that arms the mid-window view and checks nothing was saved, which fails on main and on #2504. The two PRs touch the same functions and conflict. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Kajanos on GitHub · 2026-11-25 19:02 UTC · original

Review of the two fix PRs (main 13f91ca), by reading the code:

  • #2504 fixes only the views present when the write begins. It keeps main's end-of-write report_written (kernel_will_write, save = true, after the bytes landed), so a view mapped during a PageWindow still has the original problem: a tracker that takes the page there mid-window (take clears it, since that address is not busy) and arms it gets the streamed bytes saved as its "before" bytes at the end report. copy_back_marked then takes the copy's stale bytes for shader writes and writes them over the streamed data. #2504's own test has this shape (t2 mapped and taken mid-window) but does not arm t2, so it cannot see it.
  • #2566 covers both halves: views present at the start are opened before the write and held, and views mapped meanwhile are marked with the new title_memory_written (no save). copy_back_marked then hits the "nothing saved, changed" path and keeps title memory. Its a_write_reported_after_the_fact_saves_nothing does not tell the two apart, though: the earlier drop(writing(..)) already marked the page, so kernel_will_write would not save there either. A test like #2504's end-to-end one, with t2.arm(..) after the mid-window take and assert!(t2.saved(..).is_none()), would; it fails on #2504 and on main.
  • The two conflict (same functions). I'd take #2566 plus that test.

AI-assisted (Claude Code). Reasoning only; tests not run (no Windows host).

**@⁠Kajanos** on GitHub · 2026-11-25 19:02 UTC · [original](https://github.com/Marvisak/VIctory/issues/2503#issuecomment-7171736903) Review of the two fix PRs (main 13f91ca), by reading the code: - #2504 fixes only the views present when the write begins. It keeps main's end-of-write `report_written` (`kernel_will_write`, save = true, after the bytes landed), so a view mapped during a `PageWindow` still has the original problem: a tracker that takes the page there mid-window (`take` clears it, since that address is not busy) and arms it gets the streamed bytes saved as its "before" bytes at the end report. `copy_back_marked` then takes the copy's stale bytes for shader writes and writes them over the streamed data. #2504's own test has this shape (`t2` mapped and taken mid-window) but does not arm `t2`, so it cannot see it. - #2566 covers both halves: views present at the start are opened before the write and held, and views mapped meanwhile are marked with the new `title_memory_written` (no save). `copy_back_marked` then hits the "nothing saved, changed" path and keeps title memory. Its `a_write_reported_after_the_fact_saves_nothing` does not tell the two apart, though: the earlier `drop(writing(..))` already marked the page, so `kernel_will_write` would not save there either. A test like #2504's end-to-end one, with `t2.arm(..)` after the mid-window take and `assert!(t2.saved(..).is_none())`, would; it fails on #2504 and on main. - The two conflict (same functions). I'd take #2566 plus that test. AI-assisted (Claude Code). Reasoning only; tests not run (no Windows host).
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory#2503
No description provided.