GPU: opt-in video-memory side for host copies of title buffers #2705
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!2705
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2705"
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?
@MrEjecutor on GitHub · 2026-11-25 18:31 UTC · original
MrEjecutor:card-copies→main· +925 −4 · 4 files · 4 commits · openClaimed in #1633; design and the A/B that led to it are in #407.
What
An opt-in video-memory side for host copies of title buffers. Today every copy is one
Host::shared_buffer(custom heap, write-back,MEMORY_POOL_L0), so every shader read of title buffer data crosses PCIe. WithVICTORY_CARD_COPIES=1:VICTORY_CARD_COPIES_MIN_MB(1) gets a DEFAULT-heap buffer that views, root descriptors and title-address page tables use;Shadow::datastays the system-memory side the CPU reads and writes. Runs of a shared buffer stay single-sided (their card side would be the whole shared buffer).VICTORY_CARD_COPIES_MB(1024) caps the card sides; past it a copy stays single-sided.ExecuteCommandLists, so buffers decay to COMMON between them and promote implicitly as they do now: a copy-up list for every 64 KiB page whose system-memory side is newer (every write intodatamarks its page: refreshes, zero fills, copy-back merges,write_host), the title's lists unchanged, then after their fence a copy-down list for the pages that may hold GPU writes (declared unmarked ranges whole, marked ranges by their marked pages, the title-memory page tables' bits), before the CPU copy-back runs unchanged.Why
On the fork
fxceless/victory-fork, which has a similar card side on by default, an RTX 5060 Ti runs a frame in ~315 ms with it and ~2,084 ms without it; the hair strand constraint solvers and the skinning that feeds ray tracing are what slows down without it (#407).Measured here (RTX 5060 Ti 16 GB, driver 621.24, Windows 11 26200)
Tests: four new GPU tests in
memory.rs(a title write reaches a shader through the card side, first and later; a declared GPU write comes back to title memory; a write through the title-memory page table comes back; a page both the title and the GPU wrote is seen whole by the next submission). Negative controls: with the copy-up removed the two read tests fail, with the copy-down removed the three write tests fail.cargo test -p victory-gpu --lib -- --test-threads=1: 193 pass, 2 fail; the same 2 fail on13f91cawithout this change on this card (dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_views).In the title,
main+ this + #1751 + #1763 (the stack that boots on NVIDIA here), the three programs of #1968 skipped (so the world is black and the strand simulation does not run),VICTORY_GPU_TIMING=1, 600–900 s runs:With the world drawn:
main+ this + #1751 + #1763 + #1906 + #2098 (the last two merged by hand onto currentmain: its 16-byte view-address entries with #1906's dynamic slots and #2098'sview_address; their tests adapted to 16 bytes and passing), nothing skipped, the warnings #1800 rate-limits silenced by log level, one binary, 900 s each, no removal in either:VICTORY_CARD_COPIESunset=1VICTORY_GPU_TIMING)The GPU does a third more draws in less time; the frame barely moves because on
mainthe CPU's preparing and copy-back run before and after each submission, not beside it.Review
@DrDarkDK's point is in
0af0273: a failed copy list or wait ends the run throughfail()before stale data can reach title lists or title memory.Not tested
Other cards; AMD; Linux; a second run of each; the same scene in both runs (draws differ). @desplmfao offered a Linux/NVIDIA run in #407.
AI use: implemented with Codex (gpt-6-luna) from a design reviewed by Codex (gpt-6-sol), then reviewed, fixed, tested and measured with Claude Code (Claude Opus 5.5); checked by mrejecutor. No game data attached.
🤖 Generated with Claude Code
@DrDarkDK on GitHub · 2026-11-25 18:34 UTC · original
If the card copy-down list fails to reset or close,
copy_down_cardsreturns0andHost::executestill runs the usual copy-back. The GPU writes are still in the DEFAULT buffer, so copy-back reads the old staging bytes and the title can be told the submission is complete without seeing those writes. If the fence wait fails after submission, the CPU can also read staging before the download finishes.Could
copy_down_cardsreturn aResultand route failures through the existing GPU failure path before copy-back or the title’s completion writes? A regression could inject a copy-down failure after the test shader writes and check that the title completion write is withheld.AI-assisted with Codex.
@kotekompotek on GitHub · 2026-11-25 18:57 UTC · original
Read the core paths - the design is sound: strict =1 opt-in with a thread-local test override (no env races), cap accounting via reserve/release, the three-ECL split relying on COMMON promotion (legal for buffer copies), copy-down waited on its own fence before CPU copy-back, and download selection keeps the ~800MB/frame whole-range blowup out via marked pages + page-table bits. The negative controls (remove the copy-up -> reads fail, remove copy-down -> writes fail) are the strongest part of the test story.
One ordering question: copy_up_cards submits the ECL, then clear_stale() drops the marks for the copied range. If the CPU writes a stale-marked page in the window between ExecuteCommandLists returning and clear_stale running, and the GPU has already executed the copy by then, that write's mark is cleared without its data ever reaching the card side - the page stays stale on the GPU indefinitely (until another write re-marks it). Narrow window, but real: a write to page X after the copy executes and before clear_stale loses both ways. Clearing the marks before recording the copies, or snapshotting the stale set and clearing only what was snapshotted, would close it - worth a thought while this is still opt-in.
@MrEjecutor on GitHub · 2026-11-25 19:19 UTC · original
@DrDarkDK thanks, agreed: both directions had the same hole.
0af0273makescopy_up_cardsandcopy_down_cardsreturn aResult; a list that does not reset or close, a fence that is not signalled, or a wait that does not returnWAIT_OBJECT_0now goes throughfail()before the title's lists (copy-up) or before any copy-back and the completion writes (copy-down), so neither stale card data nor stale system-memory bytes can reach the title.On the regression test:
fail()ends the process, as it does for a removed device, so an in-process test cannot see the withheld completion write after it. I have not added one; if you want it, I could add a#[cfg(test)]hook that makes the copy-down return an error and checkcopy_down_cards'sResult, or run it as a child process and check the exit. Say which you'd prefer.Not tested: an injected failure (no hook yet);
cargo test -p victory-gpu --lib -- --test-threads=1gives the same 193 pass / 2 pre-existing failures as before, and clippy is clean on the changed code.AI use: Claude Code (Claude Opus 5.5); checked by mrejecutor.
@DrDarkDK on GitHub · 2026-11-25 19:30 UTC · original
Thanks. The failure handling you described resolves my concern in both directions. The explicit
fail()calls are enough for this review.If you add a regression later, I’d prefer a child-process test that also checks a completion sentinel. The exit status alone can’t show whether the completion write happened before the process exited.
AI-assisted with Codex.
@MrEjecutor on GitHub · 2026-11-25 19:42 UTC · original
@kotekompotek thanks for reading it closely. On the ordering question: writes into a copy's system-memory side run on the submitting thread, under the same lock as the copy-up, so I don't think the window can be hit today; but nothing in the code says so, and the fix is free.
185e36ftakes and clears each copy's stale pages under one lock incard_uploads, before the copy-up is recorded; a page marked after that goes up with the next submission.CardCopy::clear_staleis gone.@DrDarkDK thanks; noted on the child-process test if I add one.
Not tested: a concurrent writer (none exists today); the suite gives the same 193 pass / 2 pre-existing failures, clippy clean on the changed code.
AI use: Claude Code (Claude Opus 5.5); checked by mrejecutor.
@fuzeofficlal on GitHub · 2026-11-25 19:55 UTC · original
Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP verification and code review of
185e36f9(on13f91ca):Verification (
rustc 1.98.1MSVC)cargo xtask policy: 184 files ok;cargo clippy --locked -p victory-gpu --all-targets(default &--features diagnostics): 0 warnings.VICTORY_D3D12_WARP=1,--features diagnostics --test-threads=1): 202 passed, 0 failed, 1 ignored (all 4memory::tests::card_*tests pass).VICTORY_CARD_COPIES=1):memory::tests::card_4 passed, 0 failed;shadow::tests8 passed, 0 failed (and default-off keeps existing behavior unchanged).Review & Ecosystem Notes
stale[first..page]inline while holdingstale.lock()insidecard_uploads()in185e36f9cleanly closes the race where a concurrent CPU write between collecting upload regions and clearing stale flags could lose a dirty mark.DEFAULTVRAM + staging DMA works across all GPUs without requiring Resizable BAR and avoids holding per-copy page-bitmap locks across GPU fence waits; pairs naturally with #2120 (ReBAR read-onlyGPU_UPLOADbuffers) once #2705 skips buffers already placed inGPU_UPLOAD. Clean and ready to merge.@MrEjecutor on GitHub · 2026-11-25 20:36 UTC · original
@fuzeofficlal thank you for running it on the pinned toolchain, on WARP and on a 5090; that covers the two things I could not (rustc 1.98.1, and a card other than mine). On #2120: agreed, a copy whose buffer is already placed in
GPU_UPLOADmemory gains nothing from a card side. Whichever of the two lands second should skip those; if #2120 lands first I'll add the check here.Not tested: #2120 together with this.
AI use: Claude Code (Claude Opus 5.5); checked by mrejecutor.
@Marvisak on GitHub · 2026-11-25 22:15 UTC · original · edited 2026-11-26 02:16 UTC
Automated triage for the maintainers.
Merge candidate (recommending a look, not an approval). Thanks for the rebase. This adds an opt-in (
VICTORY_CARD_COPIES=1, exact match, off by default) DEFAULT-heap "card side" for title-buffer copies of at least 1 MB, with a 1 GB cap (reserve_card_bytes/CardBudget), a copy-up list before the title lists and a waited copy-down list before CPU copy-back (Host::copy_up_cards/copy_down_cardsinhost.rs). I read the paths that run with the switch off:Shadow::mark_staleis a no-op without a card side, theBITMAPSmove inshadow.rsis behaviour-neutral, anddefer_memory_bitmap/marked_card_pagesonly run when the switch is on. With it on, copy-up/down failures go throughfail()rather than letting copy-back publish stale bytes, and stale pages are taken and cleared under one lock incard_uploads. Four GPU tests with stated negative controls, plus third-party measurements in the thread; it merges cleanly and CIcheckis passing.It is large (≈925 lines across
host.rs,memory.rs,shadow.rs,switch.rs); this reading covered the switch-off paths and the up/down ordering, not every page-arithmetic path under the switch.Generated by Claude Code
@MrEjecutor on GitHub · 2026-11-25 22:34 UTC · original
Rebased onto
mainatf3578e3(head now7dcc595). What changed in the rebase:shadow.rs:mainsplit the refresh intoupdate_tracked/update_untracked. The card-side stale marks moved with it:copy()marks what it writes (next to the newrefreshedcall), and the zeroed unmapped runs inupdate_trackedare marked too. Every other write into the staging buffer was already marked.host.rs: only the log line and the imports conflicted; both kept.cfc2344) and theNO_OWNERowner sentinel. Behaviour is the same as before the rebase.Checked on an RTX 5060 Ti: the 4 card-copy GPU tests pass. The whole
victory-gpulib suite gives 225 passed, 2 failed. The same 2 fail on plainmainatf3578e3without these commits (descriptor::host::tests::dynamic_slots_are_held_until_released,memory::tests::lists_share_a_table_and_copies_keep_their_views), so they are not from this PR. Clippy's twofetch_updatedeprecation errors inobject.rsand the rustfmt diff invictory-formatsalso come frommainwith a newer toolchain. Not tested: an in-game run after the rebase (the earlier A/B numbers in this PR are from before it).AI use: the rebase, the conflict resolution and the checks above were done with Claude Code.
@moe-miau on GitHub · 2026-11-25 23:25 UTC · original
Per-pipeline data from an RTX 4070 SUPER (12 GB, driver 32.0.16.1742, Windows 11 26300, Ryzen 7 7700X), title 1.0.2.1, Series X profile, diag build, 6-minute runs with scripted Enter presses,
VICTORY_GPU_TIMING=1 VICTORY_D3D12_DRED=1.Tree:
mainf3578e3+ #2464 + #2098 + #2626 + #2628 + #2711 + #2851, with this PR (7dcc595) merged cleanly on top. Off = the same exe withoutVICTORY_CARD_COPIES; on =VICTORY_CARD_COPIES=1. The scenes in the two runs are not identical, so I compare each pipeline's median GPU time per command over the run, for the 89 pipelines timed in both:indirect [compute cfd83392ec9ae408]indirect [compute 3592426e3e9142d8]indirect [compute c519f7a7946e3702]indirect [compute f22a76fcb967ee59]indirect [compute ce30cb330ef34306]indirect [compute c7feccae4e01e454]So the passes that move whole buffers gain 10-90x. Most others are unchanged. The ray-march lighting passes (
c7feccae,8bbcbda6,0184869d, ...) stay slow for an unrelated reason on this stack (their step-length 3D texture is all zeros, so each lane marches to its step cap). No device removal in either run. One run each.AI-assisted (Claude Code). Runs done on my machine.
@ntgata1-dotcom on GitHub · 2026-11-26 07:46 UTC · original
AMD RDNA4 under Wine: card copies off and on, in the title
Setup: RX 9070 XT (RDNA4), RADV / Mesa 26.3, Wine 11.22 with vkd3d-proton 3.1-83 from GE-Proton11-14. Diag builds of this PR merged onto
main63bcca4, with #2428 and the Linux-side changes listed below. Warm shader and pipeline cache, scripted input, the first mission's opening, 5-minute runs. The numbers are means over the 5-second frame lines with 1,000 draws or more (about 42 per run).VICTORY_CARD_COPIESunset=1No fault, device loss or kernel message in either run. This is the same picture as your RTX 5060 Ti numbers: the GPU side moves a little and the frame doesn't, because preparing and copy-back run before and after each submission here too.
Both runs had the same local changes: queues on a worker thread (local, opt-in), #3071, and a wineserver that keeps memory views in a tree. Merged for Wine: #2913, #2919, #2723, #2977, #2703, #1722, #2101, #2249; and #2644 and #454, their switches on.
AI-assisted (Claude Code); numbers from my own runs.
@MrEjecutor on GitHub · 2026-11-26 08:34 UTC · original
Thanks, that is a useful third card. Taken together for whoever reviews this:
So the PR does what it claims on the GPU side on three vendors and stays off by default, but it does not make frames faster on its own while preparing and copy-back are serial with the submission. That limit is in the description; this confirms it on AMD too. No change planned to the PR from this; it stays rebased on
main.Not tested: overlapping preparing or copy-back with the GPU (a separate change).
AI use: this summary was written with Claude Code.
@fuzeofficlal on GitHub · 2026-11-26 09:27 UTC · original · approved these changes
Reviewed
7dcc5954acrosshost.rs,memory.rs,shadow.rs, andswitch.rs, and verified cleanly against currentorigin/main(63bcca43;git merge-tree --write-treereports zero conflicts).Lifecycle and synchronization checks look sound:
Shadowfield drop order releasesbufferbefore_budgetreturns bytes toCARD_ALLOCATED; arena slices stay single-sided; all staging-side mutations (copy(), unmapped zero-fills,copy_back_or_not,copy_back_marked,write_host) mark pages stale, andcard_uploads()drains stale marks under a single lock.shadow::marked_card_pages()andmemory::marked_card_pages()read dirty bitmaps without clearing beforecopy_down_cardsfences, leavingPooledBitmapalive inlist.deferred.afteruntilreset().fail(...)so stale data cannot silently reach title lists or title memory.Verified locally on Windows 11 (RTX 5090 + WARP +
VICTORY_D3D12_DEBUG=1):cargo clippy --workspace --all-targets [--all-features] -- -D warnings: clean;cargo xtask policy:190 files ok.switch::4/4,shadow::10/10, and all 4 newmemory::tests::card_*tests pass on RTX 5090, RTX 5090 + Debug Layer, and WARP + Debug Layer with zero D3D12 Debug Layer errors on the implicitCOMMONtransitions across the threeExecuteCommandListscalls.VICTORY_CARD_COPIES=1(default 1 MiB threshold) +VICTORY_D3D12_DEBUG=1:bindless::3/3,draw::tests::20/20 (includingroot_views_reach_their_copy_and_read_zeros_past_itwith a 4 MiB card-backed source and all 5marked_subpage_uav_*tests),host::tests::+descriptor::host::tests::+pipeline::host::tests::30/31 (only the pre-existing NVIDIA 1M-capdynamic_slots_are_held_until_releasedfailure).--features diagnostics,VICTORY_D3D12_WARP=1):bindless::3/3,draw::tests::20/20,host::tests::+descriptor::host::tests::+pipeline::host::tests::31/31.VICTORY_CARD_COPIES=1 VICTORY_CARD_COPIES_MIN_MB=0 VICTORY_D3D12_DEBUG=1(forcing 64 KiB test shadows onto card sides):shadow::10/10,memory::tests::12/12 on WARP (includinga_submission_that_missed_leaves_the_copies_at_onceon both RTX 5090 and WARP), and all 5marked_subpage_uav_*tests pass with zero Debug Layer issues.Three minor non-blocking follow-ups worth noting:
groupsfence gap underVICTORY_GPU_TIMING=1(host.rs:1497-1567): when diagnosticstiming()is active andrunsis empty,groupsis empty (vec![]), socopy_up_cards(&card_uploads)would submitcommands.upwithout a subsequent fence signal/wait beforecard_uploadsdrops and before the nextcommands.up.begin()resets the allocator. Guardingcopy_up_cardson!groups.is_empty()(or skipping card copies whenruns.is_empty()) closes that edge case.live_cards()scans (host.rs:1508-1514, 1648,shadow.rs:829-831):has_cards()locksCARDS, upgrades every weak pointer into aVec, and immediately drops it — running twice per submission even whenVICTORY_CARD_COPIESis off, and twice back-to-back beforecopy_up_cardswhen on. CheckingCARD_ALLOCATED.load(Ordering::Relaxed) != 0inhas_cards()(and callingcard_uploads()directly whenhas_cards()is true without re-scanning) would make the default-off path lock-free and trim a scan per submission when enabled.stalebitmap (shadow.rs:375): newly committedDEFAULTbuffers withoutD3D12_HEAP_FLAG_CREATE_NOT_ZEROEDare zero-initialized by D3D12 just likeshared_buffer. Startingstaleasvec, unmapped zero-fills, merges, andwrite_hostall callmark_stale) would avoid an initial full-buffer PCIe upload of untouched zero pages when a large heap gets its card side.LGTM.
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.