Fix #2503: tell GPU write watch before DirectStorage page writes #3037

Closed
github-bot wants to merge 2 commits from gh-pr/3037/head into gh-pr/3037/base
Owner

@⁠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 merging

Fix #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.

**@⁠tharun-37** on GitHub · 2026-11-26 04:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/3037) `tharun-37:fix/directstorage-write-watch` → `main` · +49 −11 · 1 files · 2 commits · closed without merging Fix #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.
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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:27:11 +00:00
github-bot closed this pull request 2026-11-26 06:27:11 +00:00
Author
Owner

@⁠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, fresh Compiling victory-hle .../VIctory-pr3037/... provenance.

  • The two new tests (aliases_empty_query_returns_early, aliases_overflow_saturates_and_skips) — 2/2 pass.
  • Full xmem module (-p victory-hle --lib xmem) — 12/12 pass, including page_windows_cover_one_run_in_place and writes_cross_runs_and_allocations, which exercise the changed write_physical/page_window paths.

Two review points, since this is racing #2504 and #2566 on the same confirmed issue:

  1. No test would catch a revert of the ordering change. Both added tests cover only the aliases() saturating arithmetic. The actual fix — report_written returning live KernelWrite guards taken before the write in write_physical, and held from PageWindow construction to drop — has no test pinning it. A one-line reversal back to an end-of-write report_written(&shown) would pass this suite.
  2. The mid-window-view claim is untested and I can't confirm it from the diff. The guards are taken from shown_at once, at PageWindow construction / before the write_physical copy, and report_written calls kernel_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 xmem fixtures 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).

**@⁠pickles976** on GitHub · 2026-11-26 04:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/3037#issuecomment-7182882457) **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, fresh `Compiling victory-hle .../VIctory-pr3037/...` provenance. - The two new tests (`aliases_empty_query_returns_early`, `aliases_overflow_saturates_and_skips`) — **2/2 pass**. - Full `xmem` module (`-p victory-hle --lib xmem`) — **12/12 pass**, including `page_windows_cover_one_run_in_place` and `writes_cross_runs_and_allocations`, which exercise the changed `write_physical`/`page_window` paths. Two review points, since this is racing #2504 and #2566 on the same confirmed issue: 1. **No test would catch a revert of the ordering change.** Both added tests cover only the `aliases()` saturating arithmetic. The actual fix — `report_written` returning live `KernelWrite` guards taken *before* the write in `write_physical`, and held from `PageWindow` construction to drop — has no test pinning it. A one-line reversal back to an end-of-write `report_written(&shown)` would pass this suite. 2. **The mid-window-view claim is untested and I can't confirm it from the diff.** The guards are taken from `shown_at` once, at `PageWindow` construction / before the `write_physical` copy, and `report_written` calls `kernel_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 `xmem` fixtures 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).
Author
Owner

@⁠pawrenity on GitHub · 2026-11-26 05:04 UTC · original

VERIFY-3037: verified 0bd39bf on 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 from 2921092 is 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 new aliases_* tests.
  • cargo clippy --locked -p victory-hle --all-targets -- -D warnings: clean.
  • Mutation check: I changed write_physical and page_window so they drop the report_written guards right away (the old "tell after" behaviour). xmem still passed 12/12. No test pins the ordering fix.

Regression tests

  • I put only the two new tests onto origin/main 63bcca4. Both pass there, so they do not fail without the fix.
  • Their first assertion does point at a real bug on main. 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 passes allocate() 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 of xmem::aliases passes len = PAGE, so the zero-length case looks unreachable today (from reading the code).

Trial merge onto origin/main 63bcca4

  • Conflicts: crates/victory-hle/src/modules/xmem.rs, 6 regions (report_written, write_physical, PageWindow/Drop, page_window). Merge aborted.
  • I applied the PR's approach to main by hand: report_written returns guards and keeps main's REPORTED hook, guards are taken before the write and held for the window's lifetime, and nothing is reported on drop. Main's page_windows_report_where_the_pages_show_when_done then fails: it reports the old address a instead of b, the address the page was mapped at while the window was open.
  • I also ran #2504's physical_writes_guard_views_before_writing_and_catch_late_mappings against that same port. The armed view's saved-bytes check passes. t2.changed(a2 / PAGE) fails: t2 tracks the page mapped while the window was open, and it is never marked changed.

Defects

  1. 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 a PageWindow is open is never told. This is the second half of #2503, and main already handles it with shown_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.
  2. The two new tests only cover 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)

  • #2504 (4876663, base f3578e3): holds guards from before the write, and keeps main's shown_at(pages) report after the write and on drop. Its test uses real write-watch trackers (exposed through a test-hooks feature) and checks both the saved bytes before the write and the late mapping. On its head, xmem with this PR's two tests added: 17/17 passed.
  • #2566 (ea51877, base 67e8ae1, 78 commits behind main): also opens before and reports late-mapped views afterwards, through a new title_memory_written. On its head, its own xmem tests passed (13). This PR's aliases_empty_query_returns_early panicked there because a view was mapped, which is the main-side bug described above, not a defect in #2566.
  • I could not run #2504's test on this PR's head: the test-hooks export 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 xmem watch tests, a real DirectStorage queue, title data.

AI-assisted (Claude Code).

**@⁠pawrenity** on GitHub · 2026-11-26 05:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/3037#issuecomment-7183152136) VERIFY-3037: verified `0bd39bf` on 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 from 2921092 is 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 new `aliases_*` tests. - `cargo clippy --locked -p victory-hle --all-targets -- -D warnings`: clean. - Mutation check: I changed `write_physical` and `page_window` so they drop the `report_written` guards right away (the old "tell after" behaviour). `xmem` still passed 12/12. No test pins the ordering fix. **Regression tests** - I put only the two new tests onto origin/main `63bcca4`. Both pass there, so they do not fail without the fix. - Their first assertion does point at a real bug on main. `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 passes `allocate()` 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 of `xmem::aliases` passes `len = PAGE`, so the zero-length case looks unreachable today (from reading the code). **Trial merge onto origin/main `63bcca4`** - Conflicts: `crates/victory-hle/src/modules/xmem.rs`, 6 regions (`report_written`, `write_physical`, `PageWindow`/`Drop`, `page_window`). Merge aborted. - I applied the PR's approach to main by hand: `report_written` returns guards and keeps main's `REPORTED` hook, guards are taken before the write and held for the window's lifetime, and nothing is reported on drop. Main's `page_windows_report_where_the_pages_show_when_done` then fails: it reports the old address `a` instead of `b`, the address the page was mapped at while the window was open. - I also ran #2504's `physical_writes_guard_views_before_writing_and_catch_late_mappings` against that same port. The armed view's saved-bytes check passes. `t2.changed(a2 / PAGE)` fails: `t2` tracks the page mapped while the window was open, and it is never marked changed. **Defects** 1. `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 a `PageWindow` is open is never told. This is the second half of #2503, and main already handles it with `shown_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. 2. The two new tests only cover `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) - #2504 (`4876663`, base `f3578e3`): holds guards from before the write, and keeps main's `shown_at(pages)` report after the write and on drop. Its test uses real write-watch trackers (exposed through a `test-hooks` feature) and checks both the saved bytes before the write and the late mapping. On its head, `xmem` with this PR's two tests added: 17/17 passed. - #2566 (`ea51877`, base `67e8ae1`, 78 commits behind main): also opens before and reports late-mapped views afterwards, through a new `title_memory_written`. On its head, its own `xmem` tests passed (13). This PR's `aliases_empty_query_returns_early` panicked there because a view was mapped, which is the main-side bug described above, not a defect in #2566. - I could not run #2504's test on this PR's head: the `test-hooks` export 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 `xmem` watch tests, a real DirectStorage queue, title data. AI-assisted (Claude Code).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 05:17 UTC · original

Automated triage for the maintainers.

Needs rebase. This branch conflicts with current main in crates/victory-hle/src/modules/xmem.rs. It will be reviewed once it is rebased and merges cleanly.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 05:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/3037#issuecomment-7183346990) <!-- victory-triage v1 head=0bd39bf0aa7d9ba74326a0dedeb8125a2f743cb0 verdict=needs-rebase at=2026-11-26T05:22:00Z --> Automated triage for the maintainers. **Needs rebase.** This branch conflicts with current `main` in `crates/victory-hle/src/modules/xmem.rs`. It will be reviewed once it is rebased and merges cleanly. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠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 05:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/3037#issuecomment-7183849289) Rebasing on clean branch without unrelated aliases changes
Author
Owner

@⁠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.

**@⁠tharun-37** on GitHub · 2026-11-26 06:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/3037#issuecomment-7184003930) · edited 2026-11-26 06:01 UTC This PR has been replaced by #3063 (https://git.gtahub.st/github/Marvisak--VIctory/pulls/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

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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!3037
No description provided.