GPU: title memory copies are brought up to date again after a title write #2238

Open
denkencar-sketch wants to merge 1 commit from upstream-pr/2240 into main
denkencar-sketch commented 2026-11-25 08:31:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by denkencar-sketch on 2026-11-25T08:31:58Z.


Summary

A list that reads title memory through a view heap's page table queues one Step::Memory(heap) (memory::prepare, which brings every host copy up to date): memory::bind calls defer_memory once, at the list's first title-memory draw, and State::memory_map returns its cached map after that without asking again. A buffer range (defer_refresh) or a heap's views (defer_heap) is queued again after a step that writes title memory, because defer_copy and defer clear Deferred::refreshed. Step::Memory was not, so a draw recorded after an in-list copy into a title buffer read the copy's old bytes through the page table.

Change

  • HostList::defer_memory queues Step::Memory once until a title write, keyed in refreshed like defer_heap (the key is (heap, usize::MAX, 1), apart from buffer ranges and defer_heap's (ptr, usize::MAX, 0)).
  • State::memory_map calls defer_memory on its cached path too, which is a no-op unless a title write cleared the key.

Testing

host::batch::title_memory_is_refreshed_again_after_a_title_write: two defer_memory calls queue one step, after a defer_copy the next ones queue one more, another heap queues its own. On main the first assertion fails (two steps, not one). cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings is clean.

Not tried: a run in the game, or a list that actually draws after such a copy (the test covers the queueing, and memory_map's cached path is only read, not run). modules::dstorage::tests::a_page_list_filled_after_its_request_starts fails now and then on main too (5 of 20 runs of cargo test -p victory-hle --lib); it is unrelated.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5487858600 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2240). Originally posted by [denkencar-sketch](https://github.com/denkencar-sketch) on 2026-11-25T08:31:58Z. --- ## Summary A list that reads title memory through a view heap's page table queues one `Step::Memory(heap)` (`memory::prepare`, which brings every host copy up to date): `memory::bind` calls `defer_memory` once, at the list's first title-memory draw, and `State::memory_map` returns its cached map after that without asking again. A buffer range (`defer_refresh`) or a heap's views (`defer_heap`) is queued again after a step that writes title memory, because `defer_copy` and `defer` clear `Deferred::refreshed`. `Step::Memory` was not, so a draw recorded after an in-list copy into a title buffer read the copy's old bytes through the page table. ## Change - `HostList::defer_memory` queues `Step::Memory` once until a title write, keyed in `refreshed` like `defer_heap` (the key is `(heap, usize::MAX, 1)`, apart from buffer ranges and `defer_heap`'s `(ptr, usize::MAX, 0)`). - `State::memory_map` calls `defer_memory` on its cached path too, which is a no-op unless a title write cleared the key. ## Testing `host::batch::title_memory_is_refreshed_again_after_a_title_write`: two `defer_memory` calls queue one step, after a `defer_copy` the next ones queue one more, another heap queues its own. On `main` the first assertion fails (two steps, not one). `cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings` is clean. Not tried: a run in the game, or a list that actually draws after such a copy (the test covers the queueing, and `memory_map`'s cached path is only read, not run). `modules::dstorage::tests::a_page_list_filled_after_its_request_starts` fails now and then on `main` too (5 of 20 runs of `cargo test -p victory-hle --lib`); it is unrelated. AI-assisted.
DenRakEiw commented 2026-11-25 08:42:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T08:42:32Z.

Review: APPROVED


Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --lib title_memory_is_refreshed_again_after_a_title_write — passed on RTX 5090
  • cargo clippy -p victory-gpu --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean fix ensuring title memory copies are refreshed again after subsequent title writes. Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6054308263 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2240#pullrequestreview-6054308263). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T08:42:32Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC): - `cargo test -p victory-gpu --lib title_memory_is_refreshed_again_after_a_title_write` — passed on RTX 5090 - `cargo clippy -p victory-gpu --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean fix ensuring title memory copies are refreshed again after subsequent title writes. Looks good. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 08:48:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T08:48:35Z.

Review: COMMENTED


Title memory copies are brought up to date again after a step that wrote title memory; defer_memory deduped via refreshed set. 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. Pairs with #2235 (page-table retry) — both close title-memory freshness holes.

<!-- greyfinch-sync:Marvisak/VIctory:review:6054381609 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2240#pullrequestreview-6054381609). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T08:48:35Z. **Review:** COMMENTED --- Title memory copies are brought up to date again after a step that wrote title memory; defer_memory deduped via refreshed set. 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. Pairs with #2235 (page-table retry) — both close title-memory freshness holes.
MamaLeVrai commented 2026-11-25 10:07:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MamaLeVrai on 2026-11-25T09:13:32Z.


Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present, so the hardware-only shader checks run. I merged this PR's head c11fb18d into main 940d32f in a throwaway tree (no conflict). cargo clippy --workspace --all-targets --locked -- -D warnings: clean; the same with --all-features: clean. cargo test --workspace --locked: 702 passed, 0 failed, 10 ignored, two runs (main alone on the same machine: 701 passed, 0 failed, 10 ignored). The title was not run, so this says nothing about in-game effect. No game data.

AI-assisted (Claude Code); no game data.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7158042737 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2240#issuecomment-7158042737). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-25T09:13:32Z. --- Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present, so the hardware-only shader checks run. I merged this PR's head `c11fb18d` into `main` `940d32f` in a throwaway tree (no conflict). `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean; the same with `--all-features`: clean. `cargo test --workspace --locked`: 702 passed, 0 failed, 10 ignored, two runs (`main` alone on the same machine: 701 passed, 0 failed, 10 ignored). The title was not run, so this says nothing about in-game effect. No game data. AI-assisted (Claude Code); no game data.
Marvisak commented 2026-11-25 14:07:22 +00:00 (Migrated from github.com)

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


Automated triage for the maintainers.

Merge candidate (a recommendation to look, not an approval). Rebased onto current main with the same change. HostList::defer_memory (crates/victory-gpu/src/host.rs) now queues Step::Memory(heap) only when the key (heap, usize::MAX, 1) is new in Deferred::refreshed. defer_copy and defer clear that set, as they already do for defer_refresh/defer_heap. State::memory_map (draw.rs) now also calls it on its cached path, so a draw recorded after an in-list title write brings the page-table copies up to date again. Before, only the first title-memory draw did. The key cannot collide with buffer ranges or with defer_heap's (.., usize::MAX, 0). The test title_memory_is_refreshed_again_after_a_title_write checks the queueing; as the description says, no draw after such a copy was run.

The branch merges cleanly. CI: check passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7163888061 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2240#issuecomment-7163888061). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T13:30:57Z. --- <!-- victory-triage v1 head=88bbc7a1c392c37e62e7bb87acbc39879dab0b74 verdict=merge-candidate at=2026-11-26T01:22:11Z --> Automated triage for the maintainers. **Merge candidate** (a recommendation to look, not an approval). Rebased onto current `main` with the same change. `HostList::defer_memory` (`crates/victory-gpu/src/host.rs`) now queues `Step::Memory(heap)` only when the key `(heap, usize::MAX, 1)` is new in `Deferred::refreshed`. `defer_copy` and `defer` clear that set, as they already do for `defer_refresh`/`defer_heap`. `State::memory_map` (`draw.rs`) now also calls it on its cached path, so a draw recorded after an in-list title write brings the page-table copies up to date again. Before, only the first title-memory draw did. The key cannot collide with buffer ranges or with `defer_heap`'s `(.., usize::MAX, 0)`. The test `title_memory_is_refreshed_again_after_a_title_write` checks the queueing; as the description says, no draw after such a copy was run. The branch merges cleanly. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
fuzeofficlal commented 2026-11-26 19:27:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T19:27:47Z.

Review: APPROVED


Reviewed and verified 88bbc7a1c392c37e62e7bb87acbc39879dab0b74 merged onto origin/main (63bcca43c6a00a758510398fa43096ce7e4f7df0) on Windows 11 x64 (RTX 5090 + Microsoft WARP, Rust 1.98.1 MSVC).

Code Audit

  • HostList::defer_memory (crates/victory-gpu/src/host.rs:2118-2124) deduplicates Step::Memory(heap) in Deferred::refreshed using (heap, usize::MAX, 1), which is strictly disjoint from both buffer-range keys (shadow_ptr, addr, len) and defer_heap's (viewed_ptr, usize::MAX, 0).
  • Title-memory write paths (defer_copy and defer) clear Deferred::refreshed (while host/upload-only defer_fill/defer_host do not), so calling list.defer_memory(heap) on the cached path of State::memory_map (crates/victory-gpu/src/draw.rs:491-497) is a zero-step no-op until a title write occurs, and queues exactly one fresh Step::Memory(heap) afterward.

Local Verification

  • cargo xtask policy — pass.
  • cargo clippy --locked -p victory-gpu --all-targets -- -D warnings (default and --all-features) — 0 warnings.
  • cargo test --locked -p victory-gpu --lib batch:: (RTX 5090 and WARP) — all passed, including title_memory_is_refreshed_again_after_a_title_write.
  • Additional end-to-end GPU execution probe in a single HostList: bound title memory (memory::bind), queued list.defer_copy writing 0xDEAD_BEEF into write-watched title memory, called list.defer_memory again, executed the list via host.execute, and verified the host shadow copy read back 0xDEAD_BEEF with zero debug-layer messages on both RTX 5090 and WARP.
  • Also verified a 4-way co-merge with #2223, #2276, and #2279 on 63bcca43c6a0 builds and passes all targeted GPU tests cleanly on RTX 5090 and WARP.

Looks good to merge.

<!-- greyfinch-sync:Marvisak/VIctory:review:6079533271 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2240#pullrequestreview-6079533271). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T19:27:47Z. **Review:** APPROVED --- Reviewed and verified `88bbc7a1c392c37e62e7bb87acbc39879dab0b74` merged onto `origin/main` (`63bcca43c6a00a758510398fa43096ce7e4f7df0`) on Windows 11 x64 (RTX 5090 + Microsoft WARP, Rust 1.98.1 MSVC). ### Code Audit - `HostList::defer_memory` (`crates/victory-gpu/src/host.rs:2118-2124`) deduplicates `Step::Memory(heap)` in `Deferred::refreshed` using `(heap, usize::MAX, 1)`, which is strictly disjoint from both buffer-range keys `(shadow_ptr, addr, len)` and `defer_heap`'s `(viewed_ptr, usize::MAX, 0)`. - Title-memory write paths (`defer_copy` and `defer`) clear `Deferred::refreshed` (while host/upload-only `defer_fill`/`defer_host` do not), so calling `list.defer_memory(heap)` on the cached path of `State::memory_map` (`crates/victory-gpu/src/draw.rs:491-497`) is a zero-step no-op until a title write occurs, and queues exactly one fresh `Step::Memory(heap)` afterward. ### Local Verification - `cargo xtask policy` — pass. - `cargo clippy --locked -p victory-gpu --all-targets -- -D warnings` (default and `--all-features`) — 0 warnings. - `cargo test --locked -p victory-gpu --lib batch::` (RTX 5090 and WARP) — all passed, including `title_memory_is_refreshed_again_after_a_title_write`. - Additional end-to-end GPU execution probe in a single `HostList`: bound title memory (`memory::bind`), queued `list.defer_copy` writing `0xDEAD_BEEF` into write-watched title memory, called `list.defer_memory` again, executed the list via `host.execute`, and verified the host shadow copy read back `0xDEAD_BEEF` with zero debug-layer messages on both RTX 5090 and WARP. - Also verified a 4-way co-merge with `#2223`, `#2276`, and `#2279` on `63bcca43c6a0` builds and passes all targeted GPU tests cleanly on RTX 5090 and WARP. Looks good to merge.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2240:upstream-pr/2240'
git switch 'upstream-pr/2240'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/2240'
git switch 'upstream-pr/2240'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2240'
git switch 'upstream-pr/2240'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2240'
git switch 'main'
git merge --squash 'upstream-pr/2240'
git switch 'main'
git merge --ff-only 'upstream-pr/2240'
git switch 'main'
git merge 'upstream-pr/2240'
git push origin 'main'
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!2238
No description provided.