fix(gpu): recheck uncommitted blocks before skipping writes #514

Closed
jeremygold02 wants to merge 2 commits from upstream-pr/514 into main
jeremygold02 commented 2026-11-24 04:21:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T04:21:54Z.


Dependency and scope

This follow-up is stacked on #464 at 41af42e. The additional change is the single commit 8540a0e. It keeps the sparse-memory copy optimization and fixes two ways it can miss ordinary writes.

#185 also exercises a partially committed range in its broader shadow-copy implementation. This patch targets the Guards::absent cache introduced by #464 and inherited by #490.

After a failed attempt to guard a 64 KiB block, #464 queries its first address. A section can have a reserved first page and a committed, writable 4 KiB page farther into that same block. Marking the entire block absent makes a later write to the committed page invisible to the journal. An ordinary page commit after the first refresh can also go unnoticed if it does not go through the runtime's physical-view remap hook.

The change requires the queried uncommitted region to cover the entire block. Before skipping a previously absent block, the next refresh rechecks the region. Adjacent absent blocks use the same query result for that pass. A failed query or partial coverage leaves the block eligible to be reported dirty.

Windows verification

  • The new regression test uses a reserved section with a committed 4 KiB page inside the second block and commits another page inside the third block after an initial refresh. On #464 the guard omits both dirty pages. With this change it reports both. An independent journal test also confirmed that a later ordinary commit in a private reservation is detected without a runtime notification.
  • The existing whole-placeholder test still skips unchanged pages and detects an explicitly notified remap.
  • Confirmed the effect in the production shadow refresh path on a physical RTX 5070. Two registered 4 KiB buffers held seed bytes 0x19 and 0x27. After the guest wrote 0xA6 and 0xB7, submission through Host::execute left both mapped D3D12 shadows at their seed values on #464. With this commit both host shadows contained the new bytes. The synthetic submissions contained no draws or dispatches.
  • In a synthetic scan with a committed 64 KiB prefix and a stable 16 MiB reserved tail, main reported 256 redundant dirty blocks per repeat. Both #464 and this branch reported zero. Median journal scan times were 47.60 µs on main, 4.19–4.33 µs on #464 and 8.32–8.76 µs on this branch. These timings cover the journal only.
  • The full watch module passed 40 serial runs and 40 four-threaded runs on each revision, with three tests on #464 and four on this branch. Formatting for the changed file and strict library Clippy passed. Clippy with test targets reports the same existing undocumented unsafe block in host.rs on #464 and on this branch.

The focused test command is cargo test -p victory-gpu --lib watch::tests:: -- --test-threads=1.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6574551948 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/514). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T04:21:54Z. --- ## Dependency and scope This follow-up is stacked on #464 at `41af42e`. The additional change is the single commit [`8540a0e`](https://github.com/jeremygold02/VIctory/commit/8540a0ec34234ed35700dd98ce338402f507855e). It keeps the sparse-memory copy optimization and fixes two ways it can miss ordinary writes. #185 also exercises a partially committed range in its broader shadow-copy implementation. This patch targets the `Guards::absent` cache introduced by #464 and inherited by #490. After a failed attempt to guard a 64 KiB block, #464 queries its first address. A section can have a reserved first page and a committed, writable 4 KiB page farther into that same block. Marking the entire block absent makes a later write to the committed page invisible to the journal. An ordinary page commit after the first refresh can also go unnoticed if it does not go through the runtime's physical-view remap hook. The change requires the queried uncommitted region to cover the entire block. Before skipping a previously absent block, the next refresh rechecks the region. Adjacent absent blocks use the same query result for that pass. A failed query or partial coverage leaves the block eligible to be reported dirty. ## Windows verification - The new regression test uses a reserved section with a committed 4 KiB page inside the second block and commits another page inside the third block after an initial refresh. On #464 the guard omits both dirty pages. With this change it reports both. An independent journal test also confirmed that a later ordinary commit in a private reservation is detected without a runtime notification. - The existing whole-placeholder test still skips unchanged pages and detects an explicitly notified remap. - Confirmed the effect in the production shadow refresh path on a physical RTX 5070. Two registered 4 KiB buffers held seed bytes `0x19` and `0x27`. After the guest wrote `0xA6` and `0xB7`, submission through `Host::execute` left both mapped D3D12 shadows at their seed values on #464. With this commit both host shadows contained the new bytes. The synthetic submissions contained no draws or dispatches. - In a synthetic scan with a committed 64 KiB prefix and a stable 16 MiB reserved tail, main reported 256 redundant dirty blocks per repeat. Both #464 and this branch reported zero. Median journal scan times were 47.60 µs on main, 4.19–4.33 µs on #464 and 8.32–8.76 µs on this branch. These timings cover the journal only. - The full watch module passed 40 serial runs and 40 four-threaded runs on each revision, with three tests on #464 and four on this branch. Formatting for the changed file and strict library Clippy passed. Clippy with test targets reports the same existing undocumented unsafe block in `host.rs` on #464 and on this branch. The focused test command is `cargo test -p victory-gpu --lib watch::tests:: -- --test-threads=1`.
desplmfao commented 2026-11-24 06:55:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by desplmfao on 2026-11-24T04:36:39Z.


Ran this in the world on NVIDIA / Linux, in case that helps (it was tested on Windows only).

RTX 5080, CachyOS, proton-cachyos (vkd3d-proton 3.2.0), Series X 1.0.2.1, diagnostics build of main d2a4bae + this (with #464) + #515, #185, #436, #462, #440, #493 (+#336), #259, #177, #151, story mode by VICTORY_KEYS. One run, 7.5 min, about 6 min in the world: no GPU fault or hang, nothing in crashes.log, no visible corruption beyond what this stack already has (most draws are still dropped here). Unwatched whole copies per world frame were 1–81 MB, down from 0.1–0.8 GB with #464 alone in the same stack, though #515's second commit changed in the same step, so that is not this PR's effect alone.

AI-assisted (Claude Code); numbers from the run's log.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7122176941 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/514#issuecomment-7122176941). Originally posted by [desplmfao](https://github.com/desplmfao) on 2026-11-24T04:36:39Z. --- Ran this in the world on NVIDIA / Linux, in case that helps (it was tested on Windows only). RTX 5080, CachyOS, proton-cachyos (vkd3d-proton 3.2.0), Series X 1.0.2.1, diagnostics build of `main` `d2a4bae` + this (with #464) + #515, #185, #436, #462, #440, #493 (+#336), #259, #177, #151, story mode by `VICTORY_KEYS`. One run, 7.5 min, about 6 min in the world: no GPU fault or hang, nothing in `crashes.log`, no visible corruption beyond what this stack already has (most draws are still dropped here). Unwatched whole copies per world frame were 1–81 MB, down from 0.1–0.8 GB with #464 alone in the same stack, though #515's second commit changed in the same step, so that is not this PR's effect alone. AI-assisted (Claude Code); numbers from the run's log.
Raxstreams commented 2026-11-24 06:55:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Raxstreams on 2026-11-24T05:00:32Z.


Tested the partly committed view-block change in a Windows integration build alongside #515. All nine watch tests passed, including writes_in_partly_committed_view_blocks_are_reported and unmapped_blocks_are_reported_once_until_mapped. I have no isolated frame-time measurement for this patch.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7122537741 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/514#issuecomment-7122537741). Originally posted by [Raxstreams](https://github.com/Raxstreams) on 2026-11-24T05:00:32Z. --- Tested the partly committed view-block change in a Windows integration build alongside #515. All nine watch tests passed, including writes_in_partly_committed_view_blocks_are_reported and unmapped_blocks_are_reported_once_until_mapped. I have no isolated frame-time measurement for this patch.
mercuryVM commented 2026-11-24 13:01:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T12:18:36Z.

Review: APPROVED


Tested 8540a0e (on top of #464) on Windows 11, RTX 5070, MSVC: cargo test -p victory-gpu -- --test-threads=1 45 passed, including writes_in_partly_committed_view_blocks_are_reported. Clippy's 1 warning is the existing one in host.rs.

  • The fix matches the failure: a block cached as absent is skipped only while one VirtualQuery still shows its region MEM_RESERVE/MEM_FREE. A block that has since been committed by an ordinary VirtualAlloc(MEM_COMMIT), which raises no runtime remap notification, is reopened and copied, so its writes are no longer lost.
  • uncommitted_until reuses one query for the following blocks of the same region, which keeps the optimisation that #464 was after.
  • title_memory_remapped also clears absent in the remapped range, so a remap can't leave a stale "unmapped" entry.
  • The rest of the test diff is rustfmt reflow of existing assertions.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6039059458 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/514#pullrequestreview-6039059458). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T12:18:36Z. **Review:** APPROVED --- Tested 8540a0e (on top of #464) on Windows 11, RTX 5070, MSVC: `cargo test -p victory-gpu -- --test-threads=1` 45 passed, including `writes_in_partly_committed_view_blocks_are_reported`. Clippy's 1 warning is the existing one in host.rs. - The fix matches the failure: a block cached as `absent` is skipped only while one `VirtualQuery` still shows its region `MEM_RESERVE`/`MEM_FREE`. A block that has since been committed by an ordinary `VirtualAlloc(MEM_COMMIT)`, which raises no runtime remap notification, is reopened and copied, so its writes are no longer lost. - `uncommitted_until` reuses one query for the following blocks of the same region, which keeps the optimisation that #464 was after. - `title_memory_remapped` also clears `absent` in the remapped range, so a remap can't leave a stale "unmapped" entry. - The rest of the test diff is rustfmt reflow of existing assertions. AI-assisted (Claude Code).
neonbyte1 commented 2026-11-24 17:04:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-24T16:29:19Z.


Measured on Linux: RTX 5090 (620.73.04), Wine 11.22 with the wineserver view-tree patch from #340, vkd3d-proton from GE-Proton11-14. Prologue, about 3,100 draws per frame; medians over about 55 world summary lines per run.

Base: main@ffe310e plus #190, #217, #347, #322, #454, #493, #579, #177, #259 and #542.
After: the same base plus this PR (which includes #464), #388, and #1217. #1217 only fixes how copies is timed.

Per world frame Before After
Frame time 324.9 ms (3.1 fps) 255.8 ms (3.9 fps)
CPU preparation 159.4 ms 88.5 ms
MB unmapped 351.9 5.8
Fallbacks 1,331 135
Watches (count / time) 1,661 / 8.8 ms 1,600 / 7.6 ms
GPU 108.3 ms 108.2 ms
  • Where the gain comes from: reads of unmapped blocks almost disappear. The rest of the frame is unchanged.
  • Merging: applying it on top of a tree that has the saturating_add fix in title_memory_remapped needs a three-line conflict resolution in watch.rs: keep at.saturating_add(len) in the new range.
  • Tests: all watch:: tests pass under Wine, including the new partly-committed-view and unmapped-block ones.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7137743423 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/514#issuecomment-7137743423). Originally posted by [neonbyte1](https://github.com/neonbyte1) on 2026-11-24T16:29:19Z. --- Measured on Linux: RTX 5090 (620.73.04), Wine 11.22 with the wineserver view-tree patch from #340, vkd3d-proton from GE-Proton11-14. Prologue, about 3,100 draws per frame; medians over about 55 world summary lines per run. **Base:** `main@ffe310e` plus #190, #217, #347, #322, #454, #493, #579, #177, #259 and #542. **After:** the same base plus this PR (which includes #464), #388, and #1217. #1217 only fixes how `copies` is timed. | Per world frame | Before | After | |---|---|---| | Frame time | 324.9 ms (3.1 fps) | 255.8 ms (3.9 fps) | | CPU preparation | 159.4 ms | 88.5 ms | | MB unmapped | 351.9 | 5.8 | | Fallbacks | 1,331 | 135 | | Watches (count / time) | 1,661 / 8.8 ms | 1,600 / 7.6 ms | | GPU | 108.3 ms | 108.2 ms | - **Where the gain comes from:** reads of unmapped blocks almost disappear. The rest of the frame is unchanged. - **Merging:** applying it on top of a tree that has the `saturating_add` fix in `title_memory_remapped` needs a three-line conflict resolution in `watch.rs`: keep `at.saturating_add(len)` in the new `range`. - **Tests:** all `watch::` tests pass under Wine, including the new partly-committed-view and unmapped-block ones. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-24 23:04:14 +00:00

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!514
No description provided.