GPU: account for delivered bytes in bulk copyback #1816
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1816
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@aycow on GitHub · 2026-11-24 22:58 UTC · original
aycow:fix/bulk-copyback-protection-70564ae→main· +154 −37 · 2 files · 5 commits · openWhat 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.
ccfb02996e' into maintenance/pr1816-ccfb029 3971ed8280f3578e386e' into maint/78ed-1816 7f65c841e2@DesertGamer on GitHub · 2026-11-24 23:07 UTC · original
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.
@aycow on GitHub · 2026-11-24 23:11 UTC · original
@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.
@aycow on GitHub · 2026-11-25 01:02 UTC · original · edited 2026-11-25 01:10 UTC
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 CI@Melow-code on GitHub · 2026-11-25 01:22 UTC · original
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.)
@Marvisak on GitHub · 2026-11-25 06:30 UTC · original · edited 2026-11-26 01:19 UTC
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
@aycow on GitHub · 2026-11-25 16:57 UTC · original
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.@catminou4 on GitHub · 2026-11-24 23:03 UTC · original · reviewed
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.
@Melow-code on GitHub · 2026-11-24 23:07 UTC · original · reviewed
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?
@Melow-code on GitHub · 2026-11-25 23:55 UTC · original · approved these changes
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.@fuzeofficlal on GitHub · 2026-11-26 16:40 UTC · original · approved these changes
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.