GPU: every region of a tracked range must be the runtime's #2343

Closed
crashbashash wants to merge 2 commits from upstream-pr/2345 into main
crashbashash commented 2026-11-25 11:14:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by crashbashash on 2026-11-25T11:14:17Z.


Summary

runtime_memory decides whether watch::track may guard a range, but it looks only at the range's first page. A range that starts in runtime memory (a write-watched pool, a view or a placeholder) and runs into plain committed memory further in passes, and that memory gets guarded too. A write there from a thread holding the guard lock then never returns, the same deadlock #1849 fixes for free memory. astrosteveo reproduced it with a synthetic test on #1849.

Stacked on #1849: the first commit is #1849 unchanged; please review only the second, f5e46bd.

Change

runtime_memory(start, end, views) walks every region of [start, end) with VirtualQuery. Each region must be what one page had to be before: write-watched, or (with views) a view or placeholder, i.e. neither free nor plain committed private memory. A range with any other region isn't tracked, and is copied whole like any untracked memory. track calls it once, when the copy is made, so the walk doesn't run per submission.

#2237 (mapped image memory) changes the same check and also looks at the first page only. Whichever of the two merges second needs a one-line conflict fix; with this PR, #2237's image rule would hold for every region of the range.

Testing

  • New watch::tests::committed_memory_further_in_is_not_tracked: a two-block reservation with its second block committed. Tracking the reserved block alone works; tracking both is refused (on main it's accepted).
  • End to end, with a throwaway test not included here: track and take that two-block range, then write to the committed block from a thread holding the guard lock. On #1849 alone, the range is tracked, the committed block turns read-only, and the write never returns (3 s timeout). With this commit, the range is refused, the block stays read-write, and the write returns.
  • cargo xwin clippy -p victory-gpu --all-targets [--all-features] --locked -- -D warnings: clean.
  • victory-gpu tests under Wine (GE-Proton11-14, MSVC build): 80 passed, 1 ignored.
  • In the game under Proton (RX 6800 XT, 135 s in the world): no measurable change. 14.3 vs 14.6 MB per stats line copied whole, same frame time. So the title may not hit this case on this setup.

Not tested: Windows.

AI-assisted (Claude Code). No game data attached.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5490249336 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2345). Originally posted by [crashbashash](https://github.com/crashbashash) on 2026-11-25T11:14:17Z. --- ## Summary `runtime_memory` decides whether `watch::track` may guard a range, but it looks only at the range's **first page**. A range that starts in runtime memory (a write-watched pool, a view or a placeholder) and runs into plain committed memory further in passes, and that memory gets guarded too. A write there from a thread holding the guard lock then never returns, the same deadlock #1849 fixes for free memory. astrosteveo reproduced it with a synthetic test on #1849. **Stacked on #1849**: the first commit is #1849 unchanged; please review only the second, `f5e46bd`. ## Change `runtime_memory(start, end, views)` walks every region of `[start, end)` with `VirtualQuery`. Each region must be what one page had to be before: write-watched, or (with `views`) a view or placeholder, i.e. neither free nor plain committed private memory. A range with any other region isn't tracked, and is copied whole like any untracked memory. `track` calls it once, when the copy is made, so the walk doesn't run per submission. #2237 (mapped image memory) changes the same check and also looks at the first page only. Whichever of the two merges second needs a one-line conflict fix; with this PR, #2237's image rule would hold for every region of the range. ## Testing - New `watch::tests::committed_memory_further_in_is_not_tracked`: a two-block reservation with its second block committed. Tracking the reserved block alone works; tracking both is refused (on `main` it's accepted). - End to end, with a throwaway test not included here: track and take that two-block range, then write to the committed block from a thread holding the guard lock. On #1849 alone, the range is tracked, the committed block turns read-only, and the write never returns (3 s timeout). With this commit, the range is refused, the block stays read-write, and the write returns. - `cargo xwin clippy -p victory-gpu --all-targets [--all-features] --locked -- -D warnings`: clean. - `victory-gpu` tests under Wine (GE-Proton11-14, MSVC build): 80 passed, 1 ignored. - In the game under Proton (RX 6800 XT, 135 s in the world): no measurable change. 14.3 vs 14.6 MB per stats line copied whole, same frame time. So the title may not hit this case on this setup. Not tested: Windows. AI-assisted (Claude Code). No game data attached.
DenRakEiw commented 2026-11-25 11:25:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T11:25:22Z.

Review: APPROVED


Verified against origin/main (940d32f):

  • Walking every VirtualQuery region across the tracked range and rejecting MEM_FREE as well as plain committed MEM_PRIVATE regions further inside the range cleanly avoids guarding unrelated heap/free memory.
  • cargo test -p victory-gpu watch::tests: 8/8 passed (including free_memory_is_not_tracked and committed_memory_further_in_is_not_tracked).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 183 files ok.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6056746992 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2345#pullrequestreview-6056746992). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T11:25:22Z. **Review:** APPROVED --- Verified against `origin/main` (`940d32f`): - Walking every VirtualQuery region across the tracked range and rejecting `MEM_FREE` as well as plain committed `MEM_PRIVATE` regions further inside the range cleanly avoids guarding unrelated heap/free memory. - `cargo test -p victory-gpu watch::tests`: 8/8 passed (including `free_memory_is_not_tracked` and `committed_memory_further_in_is_not_tracked`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 183 files ok. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 11:52:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T11:52:00Z.

Review: COMMENTED


Watch: every region of a tracked range must be runtime memory — multi-region walk instead of checking only the range start (free-memory guard, Wine first-4MiB heap note). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Correct hardening of the track() predicate; extends the watch.rs cluster #2236-#2239.

<!-- greyfinch-sync:Marvisak/VIctory:review:6057089996 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2345#pullrequestreview-6057089996). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T11:52:00Z. **Review:** COMMENTED --- Watch: every region of a tracked range must be runtime memory — multi-region walk instead of checking only the range start (free-memory guard, Wine first-4MiB heap note). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Correct hardening of the track() predicate; extends the watch.rs cluster #2236-#2239.
welisonzika14-jpg commented 2026-11-25 13:02:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by welisonzika14-jpg on 2026-11-25T12:25:25Z.


First run on NVIDIA hardware here, as far as I can see. RTX 5070 (Blackwell, driver 621.24), Ryzen 7 5700X, Windows 11, Rust 1.98.1 MSVC, no game files. Head f5e46bd merged onto main 940d32f, cargo test -p victory-gpu -p victory-shader --lib --no-fail-fast.

The PR's new test(s) pass on this card: watch::tests::free_memory_is_not_tracked, watch::tests::committed_memory_further_in_is_not_tracked. The rest is the same as main on this card: the 5 known NVIDIA failures from #1744 (2 view heap cap tests in victory-gpu, 3 in victory-shader), nothing new.

One run, unit tests only, title not run.

Written with AI help (Claude/Kiro); the numbers are from runs on my machine.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7162352166 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2345#issuecomment-7162352166). Originally posted by [welisonzika14-jpg](https://github.com/welisonzika14-jpg) on 2026-11-25T12:25:25Z. --- First run on NVIDIA hardware here, as far as I can see. RTX 5070 (Blackwell, driver 621.24), Ryzen 7 5700X, Windows 11, Rust 1.98.1 MSVC, no game files. Head `f5e46bd` merged onto `main` `940d32f`, `cargo test -p victory-gpu -p victory-shader --lib --no-fail-fast`. The PR's new test(s) pass on this card: `watch::tests::free_memory_is_not_tracked`, `watch::tests::committed_memory_further_in_is_not_tracked`. The rest is the same as `main` on this card: the 5 known NVIDIA failures from #1744 (2 view heap cap tests in `victory-gpu`, 3 in `victory-shader`), nothing new. One run, unit tests only, title not run. Written with AI help (Claude/Kiro); the numbers are from runs on my machine.
Marvisak commented 2026-11-25 16:09:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:30:00Z.


Automated triage for the maintainers.

This pull request still doesn't merge cleanly into main (conflicts in crates/victory-gpu/src/watch.rs), so it gets no content review.

Reply to the author: thanks for the summary. 280b150 ("change tracking guards only the runtime's memory, region by region") is indeed on main, and #1849 is open and merges cleanly. Closing this one in favour of #1849 is up to you or the maintainers; nothing else is needed from you here.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7166937985 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2345#issuecomment-7166937985). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T15:30:00Z. --- <!-- victory-triage v1 head=f5e46bd855fd20fd414503d9dcc9341c020501c9 verdict=needs-rebase at=2026-11-25T15:59:20Z --> Automated triage for the maintainers. This pull request still doesn't merge cleanly into `main` (conflicts in `crates/victory-gpu/src/watch.rs`), so it gets no content review. Reply to the author: thanks for the summary. `280b150` ("change tracking guards only the runtime's memory, region by region") is indeed on `main`, and #1849 is open and merges cleanly. Closing this one in favour of #1849 is up to you or the maintainers; nothing else is needed from you here. --- _Generated by [Claude Code](https://claude.ai/code)_
crashbashash commented 2026-11-25 17:05:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by crashbashash on 2026-11-25T16:49:25Z.


280b150 on main now walks every region of a tracked range, as this PR does, and goes further: instead of refusing the whole range, it tracks the runtime's pages and copies the rest whole at each use. The one thing this PR adds on top of it is leaving free memory out, which is #1849's change, and #1849 is now rebased onto main as that single condition. So this PR has nothing left of its own. I'm happy to close it, or to fold anything from it into #1849 if you'd rather keep something. Your call.

Thanks @DenRakEiw for the review, @catminou4 for the look, and @welisonzika14-jpg for the run on the RTX 5070.

AI-assisted (Claude Code). No game data attached.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7168585482 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2345#issuecomment-7168585482). Originally posted by [crashbashash](https://github.com/crashbashash) on 2026-11-25T16:49:25Z. --- `280b150` on `main` now walks every region of a tracked range, as this PR does, and goes further: instead of refusing the whole range, it tracks the runtime's pages and copies the rest whole at each use. The one thing this PR adds on top of it is leaving free memory out, which is #1849's change, and #1849 is now rebased onto `main` as that single condition. So this PR has nothing left of its own. I'm happy to close it, or to fold anything from it into #1849 if you'd rather keep something. Your call. Thanks @DenRakEiw for the review, @catminou4 for the look, and @welisonzika14-jpg for the run on the RTX 5070. AI-assisted (Claude Code). No game data attached.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2343
No description provided.