GPU: account for delivered bytes in bulk copyback #1814
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1816"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by aycow on 2026-11-24T22:58:50Z.
What changed
Count bytes delivered during bulk GPU copyback. The normal case keeps upstream's single kernel copy with no upfront protection query. On partial delivery, retry only the undelivered tail in upstream's 64 KiB and 4 KiB pieces. Computed-address copyback, declared-write snapshots, and GPU-marked pages now acknowledge a full tracked span only after complete delivery.
This revision scopes the PR to delivery accounting and keeps the existing write-first protection policy. Guard-specific protection and exact changed-byte reconciliation stay separate.
Verification
The title-copy tests verify delivered bytes over committed blocks, an unmapped hole, a read-only destination, and an unaligned span. The shadow tests verify partial delivery and dirty tracking for computed, declared and GPU-marked writes. Two title-copy tests and all 11 shadow tests passed locally, with the shadow suite run on the default hardware adapter and WARP. Strict GPU diagnostics Clippy passed.
The fixture checks correctness. Title frame time remains unmeasured. AI-assisted with OpenAI Codex.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T23:03:26Z.
Review: COMMENTED
Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.
Delivered bytes accounted in protected bulk copyback: 20K gpu diff on copyback accounting. Windows-only.
Imported from Marvisak/VIctory. Originally posted by Melow-code on 2026-11-24T23:07:37Z.
Review: COMMENTED
The VirtualQuery walk is the right approach for protected pages. Concern: a guard page set between VirtualQuery and the write makes that span fail permanently — is retry on guard faults planned, or is the skip intentional?
Imported from Marvisak/VIctory. Originally posted by DesertGamer on 2026-11-24T23:07:06Z.
VIctory V2: community PRs, merged and tested
Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch.
Where it stands today: launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1).
⚠️ Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk.
Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help:
https://DesertGamer/VIctory-V2
Unofficial community fork of Marvisak/VIctory, GPL-3.0.
Imported from Marvisak/VIctory. Originally posted by aycow on 2026-11-24T23:11:50Z.
@ruipedro-pinheiro The skip in your review is intentional. A failed kernel write can consume the one-shot
PAGE_GUARDbit. A second write could then succeed against the same bytes and bypass the protection that blocked the first attempt. The writer makes one attempt for that span, excludes the failed span from its confirmed byte count, and leaves the watched page dirty. That dirty mark lets the next refresh see current title memory. It does not queue an old GPU write for retry after protection or mapping changes.I reran the four Windows protection tests at
4398fcb. All passed, includinga_guard_added_after_query_is_never_retried, which installs the guard after the region query and verifies the byte is preserved. ReviewAI-assisted using Codex.
Imported from Marvisak/VIctory. Originally posted by aycow on 2026-11-25T01:02:39Z.
Merged upstream
42363abinto the PR ata688849. The copyback path retains the protected-region walk and confirmed-byte accounting and uses main’sReadProcessMemorykernel copy from #322. Strict diagnostics Clippy, all four active protection tests (including the protection-change case), and all four shadow tests on the default hardware adapter and WARP passed. GitHub reports a clean merge.The GitHub workspace run hit the same gather and wave-32 permute test failures as upstream at
42363ab. Upstream CIImported from Marvisak/VIctory. Originally posted by Melow-code on 2026-11-25T01:22:08Z.
Reviewed the PR's own commit (
4398fcb, above the merge of main).The design is right: count what WriteProcessMemory actually delivered, walk stable protection spans once instead of the fixed 64K/4K split, and acknowledge a watched page only when the delivery is complete, so a partial copy keeps the page dirty and the next copyback retries it. The no-retry rule for failed spans is the correct one — a failed write can already clear PAGE_GUARD, so re-querying after a failure would trust a stale region.
Two non-blocking points:
for_mapped_write_regionsbreaks silently when VirtualQuery fails; the uncounted tail keeps the pages dirty, which is safe, but a debug log line would make a kernel failure visible instead of looking like a quiet short copyback.done == ncheck counts a region only when the whole region landed. A region that delivered half its bytes is not retried (per the no-retry rule) and not counted, so the page stays dirty and the next copyback walks it again — correct, just worth a comment for the next reader, since the old code would have retried it.The two fixtures cover both watched and unwatched shadows with a READONLY page in the middle; the protection is applied after the write-watch lease is dropped, which is the right ordering.
Nothing blocking. (Review written with DeepSeek V4 Pro, OpenCode.)
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T06:30:15Z.
Automated triage for the maintainers.
Merge candidate (re-checked on
7f65c84). The new head only merges currentmaininto0e56f5f, and the PR's own diff is unchanged.write_mappedincrates/victory-gpu/src/host.rsstill tries the whole span with oneReadProcessMemoryand noVirtualQuery. It returns the bytes delivered, and on a partial copy it retries only the undelivered tail in 64 KiB, then 4 KiB pieces.In
shadow.rs,copy_back_page,copy_back's declared-write loop andcopy_back_markedmark a page as taken or synced only when it was fully delivered. The remaining caller inlist.rsignores the count, as before. The tests cover an unmapped hole, a read-only block, an unaligned span, and partial delivery for watched, unwatched and GPU-marked copies.CI: passing (
check).Generated by Claude Code
[PR #1816] GPU: account for delivered bytes in protected bulk copybackto [PR #1816] GPU: account for delivered bytes in bulk copybackImported from Marvisak/VIctory. Originally posted by aycow on 2026-11-25T16:57:54Z.
Addressed the write-first feedback at
0e56f5f. A complete bulk write takes one kernel call with no destination preflight. The returned byte count lets fallback resume at the first undelivered byte. On current main, GPU-marked copyback now also keeps a partially delivered page dirty. The title-copy tests and 11 shadow tests passed, including a partially writable marked page. I narrowed the PR description to delivery accounting and separated the guard-specific work.Imported from Marvisak/VIctory. Originally posted by Melow-code on 2026-11-25T23:55:37Z.
Review: APPROVED
Re-checked at
7f65c84. The write-first path is back, so my earlier VirtualQuery concern no longer applies. Delivery accounting is correct:write_mappedresumes at the first undelivered byte, and the three copy-back sites keep a page dirty until the whole span lands. LGTM — nit only: thewrite_mappeddoc sentence ("as a protection query for each copy cost 39 ms") needs a reword.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T16:40:03Z.
Review: APPROVED
Verified
7f65c841e2b60f6a3f8d4f599ac600d30bbce1efmerged cleanly onto63bcca43on Windows 11 with both an RTX 5090 (VICTORY_D3D12_DEBUG=1) and WARP (--features diagnostics,VICTORY_D3D12_DEBUG=1).Code review
copy_in_kernel(crates/victory-gpu/src/host.rs:2529-2539) andwrite_mapped(host.rs:2544-2562) preserve the single-call write-first fast path without upfrontVirtualQuery, guardlen == 0 || base.checked_add(len).is_none(), cap kernel-reported progress withdone.min(len), and fall back in 64 KiB then 4 KiB pieces only over the undelivered tail[base + first, base + len).copy_back_page(crates/victory-gpu/src/shadow.rs:203-238),copy_back_or_not(shadow.rs:447-468), andcopy_back_marked(shadow.rs:530-540) — now return actual delivered byte counts and callt.taken(...)only when the full span landed (or whenmerge_writebackfound no title-side change needed and reconciledhostin-place), keeping partially delivered pages dirty so the next refresh sees current title memory.Verification
cargo xtask policy:191 files ok.cargo clippy --locked -p victory-gpu --all-targets -- -D warnings(default and--all-features): clean.VICTORY_D3D12_DEBUG=1:shadow:: host::title_copies::15 passed, 0 failed.--features diagnostics+VICTORY_D3D12_DEBUG=1:shadow:: host::title_copies::15 passed, 0 failed.len == 0andusize::MAXwraparound guards, an unaligned[2048..10240)write crossing[RW | RO | RW]4 KiB OS pages (delivering exactly 4,096 bytes and leaving the RO page intact), and a watched declaredcopy_backpartial delivery (60 KiB -> stays dirty) followed by restoringPAGE_READWRITE, refreshing, and full 64 KiB delivery clearing dirty: passed on both adapters.(Minor non-blocking pre-existing note:
for_piecesathost.rs:2570computes(at / step + 1) * step, which could overflow if a synthetic pointer lay in the top 64 KiB ofusize::MAX, though unreachable for user-mode Windows addresses.)View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.