gpu: lazy GPU_OWNED copy-back (PAGE_NOACCESS trap + dedicated COPY-queue readback, VICTORY_GPU_OWNED) #4527
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!4527
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-4526"
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?
@shiman1901 on GitHub · 2026-11-30 21:56 UTC · original
shiman1901:perf/gpu-owned-lazy-copyback→main· +2465 −13 · 8 files · 1 commits · closed without mergingWhat this is
A lazy copy-back for title buffers that live in the card's memory. Today a submission that
declares shader writes to a card-side copy brings its bytes back eagerly, even when the
title's CPU never reads them before the shaders overwrite them again. With
VICTORY_GPU_OWNED=1the bytes stay on the card and come back on the first CPU access.Opt-in (
VICTORY_GPU_OWNED=1, also throughVICTORY_AB=15,VICTORY_GPU_OWNED); off, it isone cached string test and no vectored handler is installed.
How it works
Shadow::gpu_writes/Shadow::shader_writes, for a copy with a card side(
card.is_some(), not mapped, not in place), deferStep::GpuOwnedinstead ofStep::GpuWrite— no snapshot, no eager copy.Step::GpuOwnedis split into 64 KiB blocks; a block whole inside thecopy, not demoted and with no pending shader write of ours is pushed to
Batch::gpu_owned. The rest falls back to the old eager path.ExecuteCommandLists,gpu_owned::armmakes those blocksPAGE_NOACCESS(VirtualProtect, all views of the page frominplace::pages_of, atmost 8) and publishes the fence value the submission is about to signal — so a
fault that arrives while the lists are still being sent waits for the card, not for the
submitting thread. The guards' bit is released first (
watch::release_for_gpu_owned).per-block mutex (an 8-thread storm makes one readback, not eight), waits for the
published fence on the direct queue, copies 64 KiB from
Shadow::bufferinto a permanentREADBACKstaging buffer on a dedicated COPY queue (CopyBufferRegion,Signal,wait), gives the page its old protection back, copies the bytes into title memory (every
view sees them) and into the copy's CPU side, and returns
EXCEPTION_CONTINUE_EXECUTION.A partial write therefore lands on bytes brought up to date first: zero clobber.
armsees thesame copy and only replaces its fence slot (0
VirtualProtect). A block that faultedthrough its own copy once is demoted and copied back eagerly, so a block written every
frame is not trapped every frame.
Shadow::let_go_idlesweeps blocks idle for 300 frames(and everything when the A/B switch turns the feature off), so windows can still be let go.
Integration points:
watch::guard/kernel_writing/title_memory_*,copy_mapped,Shadow::update_ranges/nothing_new*(a copy skips its own owned blocks, refreshes itsgaps, and other copies' owned blocks are materialized first).
Attribution
The dedicated COPY-queue readback transport is adapted from CHZM-SiliconFuse
(Apache-2.0), by shiman1901, contributed here under this repository's license (GPL-3.0).
Apache-2.0 and GPL-3.0 are compatible in this direction.
Measured on the real box (honest scope)
Standalone D3D12 + VEH proof (
gpu_owned_poc.cpp, MinGW GCC 16.2,-std=c++20 -O2 -static), RTX 3060 12 GB, Windows 11 build 26300, not an in-game measurement:0xA5block[16..20] = 0xDEADBEEF, other 65 532 bytes0xA5Timing of the same 100 frames: full synthetic frame 3.572–3.610 ms -> 1.525–1.534 ms
(2.33–2.37x); copy-back alone 2.107–2.158 ms -> 0.093 ms (22.7–23.1x). The full
frame is dominated by writing 16 MiB to VRAM, which both paths do; the copy-back is the
part this change removes.
Related: tracking item #2415, Item 1 (lazy read-back from the card).
Files
crates/victory-gpu/src/gpu_owned.rs(new, ~900 lines with 5 Windows unit tests),lib.rs,watch.rs,shadow.rs,host.rs, and one exhaustive-match arm inhost/card_steps.rs.Tests:
BlockBits, thePendingFencepublish/drop paths, a realVirtualAlloc+PAGE_NOACCESS+ VEH read fault and partial write zero-clobber, an 8-threadsingle-readback storm, and the owned/demoted bits.
CC @dyshay @burber @meonline42 @nikitronick-crypto @Texbirds
@Texbirds on GitHub · 2026-11-30 22:15 UTC · original
Really awesome to see Track 1 (
PAGE_NOACCESS+ dedicatedCOPY-queue readback + per-block mutex storm dedup + adaptive demotion) built out so cleanly, @shiman1901!Did a pass over
gpu_owned.rs,watch.rs, andhost.rsand spotted 3 concurrency/safety edge cases worth tightening before in-game A/B runs:release_for_gpu_ownedis only called onblock, not all alias views (gpu_owned.rs,arm_one):arm_onecollectsviews = inplace::pages_of(address)and setsPAGE_NOACCESSon everyviewin&views, but only callswatch::release_for_gpu_owned(block)on the canonical block. If any other alias view inviewscurrently haswatch'sPROTECTEDbit set (PAGE_READONLY),VirtualProtectsavesold = PAGE_READONLYwhile leavingwatch'sPROTECTEDbit out of sync withPAGE_NOACCESS. Callingwatch::release_for_gpu_owned(view / BLOCK)for everyviewin&viewskeeps both layers consistent.pending.publish(fence)is called insidearm()beforeExecuteCommandLists/Signal:In
host.rs,let _gpu_owned = gpu_owned::arm(..., fence)runs beforeExecuteCommandListsandqueue.Signal(fence), yetarm()callspending.publish(fence)immediately before returningSome(pending). That defeatsPendingFence'sDropsafety net: ifExecuteCommandListsorSignalever fails (signalled == false/ device removal), any faulting thread has already seenSome(fence)and blocks inwait_host(fence)instead of waking cleanly onPendingFence::drop. ReturningPendingFenceunpublished fromarm()and callingpending.publish(fence)right afterSignalsucceeds closes that hang path.unreserve(aliases)beforecopy_nonoverlappinginread_back(multi-thread visibility window):Because
read_backrestoresPAGE_READWRITEon all views before copying the 64 KiB from the staging buffer intoat, another title thread that didn't fault yet can read stale pre-GPU bytes — or write bytes thatcopy_nonoverlappingthen clobbers — during that 64 KiB copy window. For section-view memory that already has a separate host mapping, writing through the host alias before callingunreserve(aliases)closes that window cleanly (for private allocations without a second view, worth documenting as a known window or keeping an eye on it under multi-threaded title soak).Super clean architecture overall — happy to test this on my RTX 3080 Ti (12 GB) once those are squared away!
69e7990a95to85a28b7e77@shiman1901 on GitHub · 2026-11-30 22:32 UTC · original
Thanks for the thorough review @Texbirds — all 3 catches are fixed in
85a28b7e, along with a few extra edge cases we caught during a line-by-line pass:Alias guards (arm_one): watch::release_for_gpu_owned(view / BLOCK) now runs on every alias view in &views, and any block whose prior protection was already PAGE_NOACCESS is rolled back and skipped instead of saving PAGE_NOACCESS as old.
Two-phase PendingFence (arm + host.rs): arm(items) now returns an unpublished PendingFence; note_submitted_fence + publish run strictly after self.queue.Signal succeeds on all 3 submit paths (send_published, late, sync), so PendingFence::drop cleanly wakes waiters if submission or signaling fails.
Section-view write visibility (read_back): when inplace::beside(at, BLOCK) returns a separate host mapping, the 64 KiB readback is now written through beside while all title VAs remain PAGE_NOACCESS, and unreserve(aliases) runs afterward — closing the multi-thread visibility window for section views. (The private-allocation fallback without a second view ensures PAGE_READWRITE before copy_nonoverlapping and restores exact old, documented inline.)
Additional fixes in
85a28b7e:Shadow::sync_from_gpu_owned: fixed self.changed(off, off + n) (was passing raw title address instead of relative offset) and moved sync_from_gpu_owned ahead of watch::wrote on write faults so section-view retry writes stay strictly newer than copied[page].
Shadow::shader_writes: routed writable subranges after gpu_ro_skip() into defer_gpu_owned and guaranteed self.written.store(true) (previously !gpu_ro_skip() skipped UAV writes by default).
Shadow::block_ready_for_gpu_owned & run_deferred: removed the overly broad !card.dirty.is_empty() reject and added the required whole_write || copied[page] != 0 completeness check so partial writes into already-uploaded blocks are eligible while uncopied partial blocks stay eager.
materialize_block: demote on both read and write faults (if demote) so mixed CPU+GPU blocks don't fault every frame.
Shadow::update_ranges: subtract self.pending ranges from free_gaps as well.
CI (
85a28b7e) reports 0 errors / 0 warnings across all 6 of our files (still failing only on the 3 pre-existing lints on main: lower.rs:114, shadow.rs:7346, host.rs:5098, which prevented the test step from running).Ready for a spin on your 3080 Ti whenever you have a moment! Useful quick checks:
cargo test -p victory-gpu gpu_owned (runs the 5 Windows/VEH unit tests).
VICTORY_GPU_OWNED=1 (visual/stability check + GPU_OWNED: blocks left on the card log line, then VICTORY_AB=15,VICTORY_GPU_OWNED and/or VICTORY_GPU_OWNED=1 + VICTORY_SUBMIT_FRAMES=2).
@Texbirds on GitHub · 2026-11-30 22:34 UTC · original
That was fast —
85a28b7elooks super clean! Usinginplace::besideto write section-view readbacks while all title VAs remainPAGE_NOACCESSis especially slick, and great catch onsync_from_gpu_ownedpassing the raw address instead of relative offset.Confirmed those 3 CI clippy/dead-code errors are pre-existing on
main(0 warnings in your 6 files). I'll pull85a28b7eand runcargo test -p victory-gpu gpu_ownedplus aVICTORY_GPU_OWNED=1/VICTORY_ABpass on my RTX 3080 Ti and post the results here!@IRennie74 on GitHub · 2026-11-30 22:39 UTC · original
Some notes from reading the diff. These are about where the waits land, not about correctness of the trap itself.
materialize_blockwaits forsignal.max(LATEST_SUBMITTED_FENCE)(gpu_owned.rs:617). A block armed by submission N that the CPU touches after N+1 was sent waits for N+1 to finish on the card. The entry's own slot is already replaced when a later submission re-arms it (arm_one), so waiting for the slot alone looks sufficient. On a Ryzen 5 5600X + RTX 3060, the card runs about one frame (34-38 ms) behind the submitting thread, so the difference is close to a whole card frame per fault.copy_mapped(host.rs:14638-14640),Shadow::update_rangesviaensure_for_shadow(shadow.rs:7119) andguard()(watch.rs:3287) all callmaterialize_blocksynchronously, and that blocks on the host fence. On that PC the submitting thread is the frame's wall (busy 44-54 ms of a 55-58 ms frame), and the card already idles 14-21 ms a frame waiting for it. A fence wait added there shows up directly in the frame time. A count of materializations by caller (fault / copy / refresh / guard) and their wait time on the frame line would show how often that happens in game.INFINITEwaits inside the vectored handler (wait_host,gpu_owned.rs:513-526). If any list in the armed submission waits on a fence that a title CPU thread signals, and that same thread faults on an owned block first, neither side can progress. A bounded wait that falls back to the eager path, or not arming blocks for submissions that contain such waits, would rule this out.pending.publish(*submitted)runs when!groups.is_empty()without checking that theSignals succeeded (host.rsaround:10691). The other two paths checksignalled.is_ok(). On a failed signal, faulting threads wait forever instead of being woken byPendingFence::drop.(The two earlier review points about publishing before
ExecuteCommandListsand releasing only the canonical block both look handled in the current head:publishfollowsSignal, andrelease_for_gpu_ownedruns for every view.)Happy to A/B it on the 3060 once in-game numbers exist. The standalone PoC times the readback, but not where the waits land in a real frame.
@Texbirds on GitHub · 2026-11-30 22:41 UTC · original
Ran
cargo test --locked -p victory-gpu -- gpu_ownedon exact head85a28b7e(Windows 11 x64, Ryzen 9 5900X, RTX 3080 Ti 12 GB) — 4 passed, 2 failed (5/6with--test-threads=1), and we caught two concrete issues:concurrent_faults_on_same_block_serialize_single_readbackfails ~20% of the time (2/10 isolated runs,left: 7, right: 8):This directly reproduces the multi-thread visibility window on private allocations without a
besideview: Thread 1 faults and restoresPAGE_READWRITEbefore filling all 64 KiB, so one of the other 7 threads reads the page without faulting during that window and sees stale0x00bytes.inplace::besidepath closes this cleanly for section-view pages (writing throughbesidewhile title VAs stayPAGE_NOACCESS), so for production it may be worth restrictingGPU_OWNEDto blocks with abesidemapping (or backing private pools with a second view) rather than exposing private allocations to this race under multi-threaded title reads.drop_range_clears_owned_and_demotedfails deterministically (gpu_owned.rs:1063):any_in()fast-paths onhas_any()(ACTIVE_COUNT > 0), but the test setsOWNED_BITSdirectly without bumpingACTIVE_COUNT, soany_in()always returnsfalse.The other 4 unit tests (
block_bits_set_clear_and_range_scan,veh_read_fault_and_partial_write_zero_clobber,pending_fence_drop_guard_unblocks_waiter,pending_fence_publish_and_wait) all passed cleanly.85a28b7e77to981bf2392f981bf2392fto99558945dd@Marsietiss on GitHub · 2026-11-30 23:22 UTC · original
I am porting this to another tree (Mangrove) behind a switch to get in-game numbers on an RTX 5080: faults a frame by read and write, time per fault split into waiting and copying, bytes not copied back, and a picture check on faces. A census I ran today says why it matters there: of 25.6 MB a frame of copy-back, 15.1 MB lands in the title's large private write-combined allocation and 10.8 MB in section pages shown at three or more title addresses, so nothing is reachable by landing in place as I had designed it, while protect-and-land-on-touch covers both (numbers in #4516). Two things I am building in from the reviews here: the wait is on the block's own fence with a bound and an eager fallback, and the block is filled through a side view before its protection is restored. One more to check on your side, found in our older lazy code and possibly not present in yours: if a write-guard pass re-protects pages after the landing path has opened them, a title write in between can be overwritten by the landing copy. I will post results here when the first run is judged.
@shiman1901 on GitHub · 2026-11-30 23:22 UTC · original
Thanks both @Texbirds and @IRennie74 — every catch from both reviews is fixed in
99558945:From @Texbirds (live test run on 5900X + 3080 Ti):
concurrent_faults_on_same_block_serialize_single_readback): productionGPU_OWNEDis now restricted to blocks with a separate host view (inplace::beside(block, BLOCK).is_some()), checked both inShadow::block_ready_for_gpu_owned(so private blocks stay on eager copy-back fromrun_deferredand are counted inno_beside) and inarm_one.copy_outwrites all 64 KiB throughbesidewhile every title VA remainsPAGE_NOACCESS, issuesfence(Ordering::Release), and only then callsunreserve(aliases). The VEH/concurrency unit tests now use a real two-view anonymousCreateFileMappingW+MapViewOfFilemapping (titleVA +besideRW view) and run 10 rounds × 8 concurrent threads asserting8/8threads see all 64 KiB and1readback per round.drop_range_clears_owned_and_demoted+ parallel test isolation: addedTEST_LOCKacross all global-state tests so default multi-threadedcargo testpasses without--test-threads=1, and updateddrop_range_clears_owned_and_demotedto bumpACTIVE_COUNTsoany_in()exercises the realhas_any()fast path. (Also tighteneddrop_range(at, 0)so zero-length frees clearfirst..first+1instead of an empty range, and guardedarm_one's rollback decrement withentry.gone.swap.)From @IRennie74 (wait placement & edge cases):
3. Removed global
LATEST_SUBMITTED_FENCEwait:materialize_blocknow waits only on the block entry's own fence slot (matchingrelay_card_back'sCOPY-queue wait model; re-arming already replaces the slot), avoiding ~1-frame stalls behind unrelated newer submissions.4. Per-caller materialization & wait-time telemetry: tagged every call site with
Caller(FaultRead,FaultWrite,CopyMapped,Refresh,Guard,Kernel,ReArm,Sweep) and added per-caller counts plusno_beside,timeouts,wait_ms, anddma_msto the periodicGPU_OWNED:log line so any submitting-thread stall is immediately visible in game logs.5. Bounded waits (no
INFINITEinside VEH or readback): replacedINFINITEwaits inPendingFence::wait_submitted,wait_host, andReadbackEngine::copywithWAIT_TIMEOUT_MS = 2_000plusGetCompletedValue() == u64::MAXdevice-removed checks; on timeout or device removal, the block is unprotected, removed, and demoted back to eager without hanging.6. Grouped
syncsubmissionSignalcheck (host.rs):pending.publish(*submitted)now runs only if!groups.is_empty() && signal_error.is_none(), soPendingFence::dropcleanly wakes any waiter on signal failure.CI (
99558945) reports 0 errors / 0 warnings across all 6 changed files (still only the 3 pre-existing lints onmain). Ready for a re-run ofcargo test --locked -p victory-gpu -- gpu_owned(should be 6/6 in parallel now) and the first in-gameVICTORY_GPU_OWNED=1check whenever you're ready!@MrDenn on GitHub · 2026-11-30 23:28 UTC · original
Hardware RT is probably where this pays most, and I can test it in game once the edge cases @Texbirds raised are settled.
With
VICTORY_HW_RT=1on v2026.11.30.03 (RTX 5080 16 GB, Ryzen 7 9700X, Series X 1440p, DLSS Performance), copy-back grows from 10–15 MB to 89–97 MB fetched a frame, and relay landing from ~10 ms to ~30 ms. AVICTORY_LAND_READScensus in that mode found the title touched 3–4 read and 5–16 written pages a frame out of 7,500–9,500 watched, with 63 % of the watched MiB never touched by the title. A staticVICTORY_LAND_LEAVElist of 128 MB took fetches to 39 MB and the submitting thread from 52 to 40 ms a frame. Details are in #2415.That census also contains a trap a static list cannot handle and this PR can. Two low-memory ranges (
0x3300000+0x400000,0x7700000+0x200000) were untouched for 12 minutes, but leaving them on the card gave dark spots in shadows at one place indoors. A first-touch fault with a readback, as here, should cover exactly that case.Once the fixes are in, I'd run
VICTORY_AB=30,VICTORY_GPU_OWNED(or 60 s phases) with RT on, walking and driving, and report:If there's a specific route or counter you want, tell me.
Measurements from my own PC; written with an AI assistant (Claude).
@shiman1901 on GitHub · 2026-11-30 23:29 UTC · original
Thanks for the
#4515census numbers and the race check @Marsietiss — super useful data!Coverage of your 25.6 MB/frame split in
99558945:inplace::beside(inplace.rs:1096) only checkscover_inon the queried range and does not reject pages with 3+ title views (as long asviews.len() <= MOST_VIEWS = 8).beside == None), so99558945deliberately keeps it on eager copy-back (counted underno_beside) to avoid the multi-thread visibility window @Texbirds reproduced. Covering that 1.3 GB private WC allocation with a second view (or your#4515rules) looks like the obvious Phase 2 once we have real in-game numbers on the section-view half.Write-guard re-protect race check:
99558945,arm_onecallswatch::release_for_gpu_ownedon every view before settingPAGE_NOACCESS,copy_outwrites all 64 KiB throughbeside+fence(Release)beforeunreserve(aliases)restoresPAGE_READWRITE, andwatch::guard()hitsgpu_owned::any_in->materialize_block->entry.block_lock, so a guard pass cannot re-protect the block until the landing copy finishes.materialize_blockline-by-line just now did turn up two small tightenings I'll fold into the next commit (holding off for a moment so I don't move99558945while @Texbirds builds it): movingsync_from_gpu_ownedahead ofcopy_out/unreservesoshadow.dataalso updates while all title VAs stayPAGE_NOACCESS, and clearingOWNED_BITSon the!copiedtimeout/device-removed fallback branch (gpu_owned.rs:736).Really looking forward to your RTX 5080 fault/wait/face-check numbers from Mangrove!
@Texbirds on GitHub · 2026-11-30 23:29 UTC · original
Re-tested
99558945on Windows 11 x64 (Ryzen 9 5900X, RTX 3080 Ti 12 GB) — 100% green:cargo test --locked -p victory-gpu -- gpu_owned(default parallel): 6 passed, 0 failed (0.05s).concurrent_faults_on_same_block_serialize_single_readback(200 rounds × 8 concurrent threads): 20/20 passed, 0 failures.Restricting
GPU_OWNEDto blocks with a separatebesideview +fence(Ordering::Release)beforeunreservecompletely eliminated that multi-thread stale-read window, and @IRennie74's bounded waits + per-block fence + per-caller telemetry make this super clean to profile in-game. Looking forward to seeing the first in-gameVICTORY_GPU_OWNED=1/VICTORY_ABnumbers (and @Marsietiss's RTX 5080 run)!@shiman1901 on GitHub · 2026-11-30 23:30 UTC · original
Huge thanks for the re-test @Texbirds — 6/6 parallel and 20/20 (200 × 8-thread rounds) clean on
99558945is awesome confirmation.@MrDenn —
99558945already has all of @Texbirds's and @IRennie74's review fixes in and just passed @Texbirds's 20×8-thread stress test above, so it's ready to build and test right now!A
VICTORY_HW_RT=1+VICTORY_AB=30,VICTORY_GPU_OWNEDrun on your 5080 (with a stop at that exact indoor shadow spot where staticVICTORY_LAND_LEAVEleft dark spots) is honestly the best possible real-world test for this PR.For counters/lines to include in your report, the periodic
GPU_OWNED:line has the exact breakdown we need:armedvsno_beside: tells us immediately how much of the 89–97 MB/frame HW RT copy-back lives in section views (covered in99558945) vs private allocations without a second host view (left eager for safety; ifno_besideis a large share under HW RT, that tells us Phase 2 needs a second view for private allocations).faults (read / write)anddemoted: whether the fault rate settles to ~0 after warmup and whether those two indoor shadow ranges fault once and render cleanly.sync (copy / refresh / guard / kernel / rearm / sweep)+wait_ms/dma_ms+timeouts: answers @IRennie74's question about whether the submitting thread ever blocks on a fence wait.And if you also get a chance to check
VICTORY_GPU_OWNED=1alongsideVICTORY_SUBMIT_FRAMES=2after the baseline A/B, curious whether removing eager copy-back lets 2 frames in flight overlap cleanly under HW RT. Thanks for testing!@Marsietiss on GitHub · 2026-11-30 23:31 UTC · original
Thanks, that settles the coverage question, and @MrDenn's read census (3-4 read and 5-16 written pages a frame out of 7,500-9,500 watched) is the number I was missing: faults should be rare.
For the private half I am going to start looking into dark magic practices, literally. The 1.3 GB private write-combined allocation has no second view, so the candidates are all a bit unholy: giving it a section backing at allocation so a side view exists (and paying for write tracking some other way), holding the title's other threads for the microseconds of a fill, or opening it in place as card memory and never landing at all. Card tests of the third are running on the 5080 now, and I am going through the GDK documentation, headers and samples for anything that says which of these a title could notice. I will post what survives.
On the dark shadow spots in ranges nobody touched: my guess is a reader that is not a title CPU touch, so our port counts the layer's own readers of owned blocks separately (refresh, compare, guards, kernel copies). If that count is not zero at that place indoors, that is the reader.
@Marsietiss on GitHub · 2026-11-30 23:59 UTC · original
One thing from a deeper read of the GDK documentation that bears directly on the handler here (full list in #4516): the CPU may rely on GPU-written memory only after the title's own completion signal for that work. So a thread that touches an owned block is owed only the flights whose completion the layer has already signalled, and those are done on the card. That suggests the fault path never needs to wait on a fence at all: read back at once for signalled work, and treat a touch of a block whose writer has not been signalled as a read the console does not define (serve the last signalled contents). No wait, no timeout, no deadlock class, as long as completion is never signalled before the layer could serve a fault. A counter for 'faults whose last writer is still running' would show how often the case even occurs; I expect under 1 %. Two more from the same read: fill before a first CPU write as well as a read (a store can read the line first), and never defer the GPU-uncached memory class. And for 3+ address pages: the page-mapping copies change GPU page tables only, so only CPU-reachable addresses need arming.
@Marsietiss on GitHub · 2026-12-01 00:13 UTC · original · edited 2026-12-01 00:22 UTC
First in-game attempt with this PR as published (head
99558945on tag v2026.11.30.02, built unchanged, RTX 5080 16 GB + Ryzen 9 9950X3D, 32 GB RAM, Windows 11, Series S mode, own empty cache). No valid numbers yet.Correction (edited): I first wrote here that memory stopped the run and that our tree runs the same mode at about 7.5 GB. That was wrong: 7.5 GB was our working set, not our commit. Our own log shows 27-28 GB private for our build in that mode, so this build's 23.7 GB private is not higher than ours, and I cannot blame memory for the difference. What I can say:
VICTORY_GPU_OWNED=1, about two minutes into the world. The machine was short of physical memory at the time (1-2 GB available, about 280 pages/s, the log'shost memory pressurewarning at frame 4), other work was running on it, and 60-120 pipelines were still being made on a cache that was only partly warm. So the cause is open: paging, pipelines, or the owned path. TheGPU_OWNED:line never printed (see below), so I have no fault counts. I will repeat it on a quiet machine with a warm cache, eager first, then owned, and report both.play-nvidia.ps1hasVICTORY_WC_NO_BACK=1: write-combined copies of 1 MiB and more are not copied back at all. So in that configuration there is almost nothing left for this PR to save, and my number said nothing about it. For the record, the eager run on the warm cache: 33-34 fps, 29-30 ms a frame, median 28.7 ms, 4,200-5,000 draws a frame, 0 pipelines being made. The comparison that means something is full copy-back (VICTORY_WC_NO_BACK=0) eager against owned; I am running that next and will post both.VICTORY_AB=30,VICTORY_GPU_OWNEDcannot work with this head. The COPY queue and readback buffer are created only if the switch is on when the device is created, and an A/B run starts in phase 0 with it off. In each on phase blocks are then armed and come back without the card's bytes (the log saysa block came back without a COPY queue; its bytes stay as they were), so the comparison is meaningless and the picture can break. Separate owned and eager runs are needed, or create the queue whenever the A/B list names the switch. Related: if the queue cannot be created the warning says copies stay eager, but blocks are still armed.Also: the
GPU_OWNED:line prints only on frames divisible by 300 with an armed submission, so at low frame rates it never appears; a time-based print would help testers.Separately from testing your build: we are porting this to Mangrove behind a switch, with a count mode, credited to you and to the reviewers here. Results go here and in #4516.
99558945ddtodee205c41bdee205c41bto4ea303fdd0@shiman1901 on GitHub · 2026-12-01 01:09 UTC · original
Huge thanks for the first in-game 5080 attempt and the GDK notes @Marsietiss — seeing copy-back drop to 0.6–1.3 MB/frame (vs ~25 MB eager) right out of the gate is awesome, and catching the
VICTORY_ABinit bug + frame-300 logging saved everyone a lot of wasted runs!All of those findings — plus a real
VICTORY_SUBMIT_SPLITconcurrency bug we caught during review — are now fixed in4ea303fd(rebased cleanly onto7d93ee0, full CI is 100% green: Clippy,--all-features, and all 2,723 workspace tests including all 6gpu_ownedtests):VICTORY_AB=30,VICTORY_GPU_OWNEDnow works end-to-end:init()only stores(device, fence)(zero D3D12 objects created while off), andensure_engine()lazily builds the dedicatedCOPYqueue + 64 KiB staging buffer on the first ON phase.ready()requireson() && !land::reads::on() && ensure_engine(), so no block is ever armed if the queue isn't ready.GPU_OWNED:log line: prints every 5 s from botharm()andsweep_idle()whenever there is activity (no longer tied toframe % 300).in_flightfault counter: counts faults wherehost_fence.GetCompletedValue() < signalright beforewait_host, directly testing your< 1%GDK prediction in the 5 s log while keeping the bounded fence wait for D3D12 state safety.PAGE_GRAPHICS_NOCACHE(0x4_0000) viaPROTECTIONS(WRITE_COMBINED0x400remains allowed).PAGE_NOACCESS) alias views on 3+ address pages:arm_onenow skips extra alias views that are alreadyPAGE_NOACCESSinstead of aborting the block (only CPU-reachable views are armed/restored).VICTORY_SUBMIT_SPLIT+copy_lockdeadlock fix: movedgpu_owned::arm()onto the submitting thread right beforeHandoff(passingpending_gpu_owned: Option<PendingFence>tosend_published, which only callspublish(h.fence)afterSignal), soarm()can never race with FrameN+1'sShadow::copy_staleholdingcopy_lock.sync_from_gpu_owned+watch::wroteahead ofcopy_out/unreservesoshadow.dataupdates while all title VAs stayPAGE_NOACCESS, clearedOWNED_BITSon the!copiedtimeout/fallback branch, and scopedtest_faulttoTEST_ACTIVEso fullcargo test --workspaceruns clean.@Marsietiss @MrDenn —
4ea303fdis ready for a cleanVICTORY_AB=30,VICTORY_GPU_OWNEDrun (both regular andVICTORY_HW_RT=1) with the 5 sGPU_OWNED:telemetry line now active!@Marsietiss on GitHub · 2026-12-01 01:15 UTC · original
Thanks for the quick turnaround. One correction so nobody builds on it: please do not count the 0.6-1.3 MB/frame as a saving by this PR. I withdrew that in my edited comment above (point 2). The eager run of the same build in the same scene read 0.8 MB, because that launch set had
VICTORY_WC_NO_BACK=1. There is still no valid in-game number from me forVICTORY_GPU_OWNED.What I have measured since, on our port in another tree (its rules are stricter than yours, so it does not predict your result): in count mode on the 5080, Series S, 32 lists, it would hold 0 blocks in every line of the run. The refusals were mostly "another copy covers one of its addresses" (2,400-3,000 blocks a frame), "private or more than 8 addresses" (about 2,800) and "written since the last asking" (1,100-1,800). Reading the code, I think most of that last group is an over-strict test of ours (an address with no copy over it is never asked, so it never counts as clean), not the title writing. I am adding a counter that splits it by cause before saying more.
Two things worth checking against your
armed/no_besidecounts: how many refusals come from a second copy over the same page, and how many from pages at 9 or more addresses. In my census 416 of about 2,700 in-scope section pages a second were at 9-64 addresses, so the cap of 8 views leaves those on the eager path.When I run
4ea303fd, it will be eager against owned withVICTORY_WC_NO_BACK=0, warm cache, quiet machine.@MrDenn on GitHub · 2026-12-01 01:17 UTC · original
First in-game runs with
VICTORY_HW_RT=1, on99558945(built before4ea303fdwas pushed). Mostly bug reports for that head, plus one coverage number that matters for HW RT. I'll repeat this on4ea303fdwhen I can.Setup: RTX 5080 16 GB (driver 621.40), Ryzen 7 9700X, 32 GB DDR5-6400, Windows 11 24H2. v2026.11.30.03 (
e1251c31) + this PR at99558945+ #4248, release build with--features ab. Series X, native 1440p, DLSS Performance,VICTORY_HW_RT=1,VICTORY_RELAY=2, warm cache, noVICTORY_LAND_LEAVE.VICTORY_AB=30,VICTORY_GPU_OWNED,VICTORY_GUARD_FIRST. Two runs: about 6 and 3 minutes of gameplay.1. A 142-second stall in the first owned phase
In run 1, the first phase with the switch on fell during the load into the world and produced one frame of 142,038 ms. The log has 69 ×
a block's submission never published its fence; the block goes back to the eager path, 2 s apart, and the firstGPU_OWNED:line readstimeouts=69 wait_ms=138031.8. This fits the A/B start-up problem @Marsietiss described (an on phase without what arming needs), althoughcame back without a COPY queuenever appeared in my log. Run 2 had no timeouts.2. Under HW RT almost nothing qualifies (
no_beside)Sums over all
GPU_OWNED:lines:If
no_besidecounts per block per arm whilearmedcounts new blocks, the ratio overstates it. Still, with HW RT on, the bulk of the 89–97 MB/frame copy-back here seems to sit in memory without a second view. So the private-allocation phase is where HW RT would gain. Title faults are rare, as the census predicted. Our own refresh and guard paths bring back far more blocks than the title does.3. Frame time by phase (direction only, 1–3 phases each)
Mean ms per frame, gameplay phases at 6–9k draws:
In run 1, BLAS prep per frame was higher in the owned phases: 20.7 and 18.0 ms against 8.5 and 7.6 ms. Run 2 is mixed (9.2 ms owned-only, 2.6 ms with both). It could be BLAS prep reading owned geometry on the CPU, but I haven't confirmed that.
4. Picture
Run 1 had no visible problems. Run 2, with the same build and launcher, showed dark patches in ray-traced shadows indoors, worse than anything I saw before. It also logged 11
a wait for a memory value was not met at a presentwarnings, all within the first owned phase. I can't tie the patches to phases, and given the A/B start-up issue on this head, I wouldn't read much into it until a4ea303fdrun.A correction to my #2415 comment: these dark patches showed up here with no leave list at all. So I no longer think the two low-memory ranges caused the ones I saw with
VICTORY_LAND_LEAVE.Next: the same route on
4ea303fd, once with A/B and once as separate eager and owned runs, with the 5 sGPU_OWNED:line andin_flight.(Analysis done with Claude Code.)
@shiman1901 on GitHub · 2026-12-01 01:26 UTC · original
Massive thanks for the real in-game telemetry @MrDenn and the honest correction @Marsietiss — those
GPU_OWNED:counters just paid for themselves immediately!69 × 2 s) stall found: that wasn't the A/BCOPY-queue init bug — it's a self-deadlock insidearm()itself! When two overlappingShadows declare the same 64 KiB block in the samearm(&items)call, the first arms the block with the submission's still-unpublishedPendingFence, and a few iterations later the second hitsarm_one'selse { materialize_block(..., Caller::ReArm) }and waits the full 2,000 ms timeout on its own thread's unpublishedPendingFence(69 overlapping blocks = 138 s). Easy 3-line fix (dedupitemsby block inarm()keeping the last writer + never wait on ownslot) — I'll push that before you spend time re-running4ea303f!199/18and177/30over whole runs!).VICTORY_HW_RT=1, the bulk of the 89–97 MB/frame copy-back sits inno_beside(6.28M/4.98Mskips) — confirming @Marsietiss's census that private allocations are where the big HW RT win lives.guard(4,106/4,352) andrefresh(1,813/1,574) paths are materializing (and demoting!) ~30× more blocks than the title CPU does, matching @Marsietiss's "another copy covers one of its addresses" count and @dyshay's note about internal readers.I'll push the
arm()same-submission dedup fix (and checkMOST_VIEWS/ internal-reader demotion) next so4ea303fdoesn't hit that 2 s × N stall on your next run. Thanks again for the crisp numbers!@MrDenn on GitHub · 2026-12-01 01:51 UTC · original
@shiman1901 thanks, that diagnosis fits. The first
GPU_OWNED:line of my99558945run 1 hasrearm=69next totimeouts=69andwait_ms=138031.8, so every timeout was aReArmwait. I'd already run4ea303fdbefore your reply, so here is that result as a check for the dedup fix.4ea303fdreproduces it, and doesn't recover. Build: v2026.11.30.03 (e1251c31) + only4ea303fd(cherry-picked cleanly; the branch's new base changes the translator), release with--features ab. RTX 5080 16 GB, Ryzen 7 9700X, Series X 1440p, DLSS Performance,VICTORY_HW_RT=1, warm cache, no leave list,VICTORY_AB=30,VICTORY_GPU_OWNED.frame_timeslines stopped and no frame was presented again.a block's submission never published its fence, every 2.0 s, 15 times, until I closed the game after about 35 s. NoGPU_OWNED:stat line came out, so there are no counters for this head.On
99558945the same stall ended after 69 waits. Here it kept going, so on this head the scene seems to keep handingarm()overlapping blocks. Once the dedup fix is pushed I'll rerun this exact setup.A correction to my previous comment. I wrote that the dark shadow patches appeared without a leave list, so the two low ranges probably weren't the cause. Since then:
VICTORY_LAND_LEAVE, loaded and played with no picture problems. The leave run used all 16 ranges, including the two low ones.So the patches I reported look like stale bytes, not a general HW RT problem, and probably not the low ranges.
What's at stake under HW RT on this PC. The same release, same settings, back to back, short runs (2.6 and 3.0 min of play) on different routes:
A lazy path that covers what the leave list covers, plus the private memory it can't, should be worth at least that.
@Marsietiss: my counters only give
no_beside, so I can't split refusals into "second copy over the page" against "9+ addresses". If a counter for that lands with the fix, I'll include it in the rerun.(Analysis done with Claude Code.)
@Marsietiss on GitHub · 2026-12-01 02:06 UTC · original
@MrDenn @shiman1901 something that may help with the stale-looking shadow patches. An independent code review of our own land-on-touch port tonight found these ways a held block goes stale. They come from reading our code, none has been seen in a game run, and I have not checked your head for them, so please treat them as things to look for:
On the stall, our send step takes the block's slot with a try-lock and sends a busy block to the late path, so it never waits on a fence. That may be a simpler shape than dedup: an overlapping block becomes late instead of waiting.
@MrDenn for splitting refusals: the first two counts I would add are "another copy covers an address of this page" and "page at 9 or more addresses". In our count run the first was 2,400-3,000 blocks a frame. I will report our next split here once it is measured.
4ea303fdd0to5592660778@Marsietiss on GitHub · 2026-12-01 02:57 UTC · original
Update from our side, in case it helps the next heads of this PR.
559266077against4ea303fd(not the code line by line): the block dedup inarm()(last declaration wins), keeping and waking replaced slots, and the extra refusal counters for blocks at more addresses than the view cap and GPU-uncached pages are what MrDenn's 142 s stall asked for. I have not built or run it.Both exist on the eager path as well. A held block that the title reuses after one of these has no completion signal behind it. Suggested test: a held block, a flight that never finishes, a null-event wait; after it returns, the block must be brought back or the title's reuse refused.
5592660778to7afc5dd2587afc5dd258tob92e818831b92e818831toc98eb22781@shiman1901 on GitHub · 2026-12-01 11:04 UTC · original
Massive thanks @MrDenn and @Marsietiss — your live 5080 repro + stale-byte checklist caught every remaining bug, and all of them are now fixed in
c98eb227:1. Eliminated the 2 s × N
arm()self-deadlock (a block's submission never published its fence):arm()now iteratesitems.iter().rev()(last writer wins) tracking all armed blocks and their alias views inseen_blocks, checksArc::ptr_eq(&f, slot)before takingblock_lockor callingmaterialize_block(..., Caller::ReArm), and passes superseded slots intoPendingFence::adoptso they wake cleanly on publish/drop.2. Eliminated
Caller::Guard = 4,106stalls and HW RT geometry drops (hwrt.rs):watch::guard()now skipsGPU_OWNEDblocks cleanly viais_owned/owned_word(keepingwrites()returningSomesoMemory::possiblenever poisonsrefused).hwrt::readable_lenandhwrt::read_geometriesnow materialize overlapping blocks viaCaller::Hwrt.MOST_VIEWSfrom8→64and addedmany_views,uncached,hwrt,texture, andexternalcounters to the 5 sGPU_OWNED:log line.3. Closed all 5 stale-byte traps (flickering dark spots / overexposure):
block_ready_for_gpu_ownednow unconditionally requirescopied[block / PAGE - start / PAGE] != 0(also fixed an off-by-one for unalignedself.start;copy_staleonly stamps a 64 KiBcopiedslot when the whole 64 KiB block was copied). More importantly,read_backno longer blindlymemcpys 64 KiB:Shadow::merge_from_gpu_ownednow diff-merges 4 KiBKERNEL_PAGEby 4 KiBKERNEL_PAGEagainstself.data, writing only GPU-changed bytes throughbeside(leaving untouched bytes/CPU writes intact) and returning the exact 16-bitchanged_maskmatchingwatch::PARTS/VICTORY_PAGE_PARTS=1.writes_since+ unconditional journal update):arm()notifiesdescriptor::host::remapped_rangeson the submitting thread (outside VEH) for all armed blocks/aliases;watch::writes_sincematerializes overlappingGPU_OWNEDblocks (Caller::Texture); andwatch::note_gpu_owned_landedunconditionally updatesLANDED+JOURNAL/WRITTEN_EPOCHS(nois_kept()guard!) and returns(now, prev)sostamp_gpu_owned_pagesonly advancescopiedwhenprev <= cur(matchinglanded_beside— overlappingShadow Balways refreshes, unrefreshed CPU writes are never swallowed, andShadow Adoesn't echo).VICTORY_NEW_BATCH=1/Shadow::new_look): added theall_owned_by/any_in_rangegate toShadow::new_lookso batchednothing_new_allnever skips a refresh on a block owned by anotherShadow, and closed acopy_lockself-deadlock window inShadow::update_ranges.gpu_owned::on_external_write(at, len)at the very top of bothwatch::title_memory_written(beforemode & 4 == 0) andwatch::stream_written(before!light()): full-block overwrites unreserve/discard without readback so stale GPU bytes never overwrite fresh DirectStorage loads, partial overlaps skip-merge around the external range, and ranges > 4096 blocks iterateENTRIESso saturated lengths never hang.wait_hostnow distinguishes device-removed (u64::MAX) from genuine GPU progress (up to 5 × 2 s windows whilecompleted > prev, failing early only on zero progress for 2 s and loggingat/shadow_id/value/completed), and addedunpublished_fence_drop_or_timeout_unprotects_and_demotes(8 unit tests total).Note:
c98eb227still keepsbeside-only safety (so private WC allocations stay eager inno_besidefor Phase 2 — getting section-viewGPU_OWNED100% stall-free and artifact-free first). CI Clippy confirms 0 errors / 0 warnings across all 8 changed files in bothlibandlib test(only the 5 unrelated F1-menu Clippy lints currently onmain5fabb46e). Ready for a clean re-test whenever you have a moment!@Marsietiss on GitHub · 2026-12-01 11:05 UTC · original · edited 2026-12-01 11:20 UTC
Thanks for going through all of them, and for the 64-view change and the diff-merge in
merge_from_gpu_owned.I have not run
c98eb227yet and won't promise a date, my test queue is full today. When I do, I'll use the RTX 5080 and the setup I used before, and I'll report counts (held blocks, the refusal reasons,Caller::*stalls) and what the picture does, including if it holds nothing.Two questions I'd like to check there, not findings:
copied[...] != 0). Does that raise the refusals for blocks that a copy covers only in part, and is that visible in the 5 s line?wait_host, up to 5 windows of 2 s while progress is seen: what happens to the title thread that waits on the fence meanwhile, does the title's own wait limit (about 2 s on some paths) run out first?@shiman1901 on GitHub · 2026-12-01 11:18 UTC · original
Thanks @Marsietiss — no rush at all, whenever it fits your queue! Quick answers to your two questions:
copied[...] != 0refusals & telemetry: blocks only partly covered by a copy are already rejected earlier byblock < start || block_end > end(andcopy_staleonly stamps a 64 KiBcopiedslot when the whole 64 KiB block was copied). Removing the!whole_writebypass can increase rejections for whole-inside-copy blocks that were never uploaded from CPU first (copied[idx] == 0, e.g. GPU-initialized UAVs). Right now those early rejections aren't broken out on the 5 sGPU_OWNED:line (onlyno_beside,many_views, anduncachedare) — happy to add anuncopied=counter in the next pass ifarmeddrops noticeably on your 5080 run.wait_host: inside VEH, the faulting title thread is suspended inside our handler (not running its own wait loop), though another title thread waiting on that thread or on a GPU fence could hit a ~2 s timeout if the card genuinely stalls > 2 s. Normal in-flight frames finish in ~30–60 ms (well inside window 1); the extra windows only trigger if the fence is visibly advancing (completed > prev, e.g. heavy shader compile) and logslow to reach a block's fence, still waitingon the very first 2 s mark so any real stall is immediately visible and tunable.@Ondra97 on GitHub · 2026-12-01 15:07 UTC · original
On head
c98eb227, I reproduced an alias-unmap bug inGPU_OWNED. When one title view of an owned physical page is unmapped,drop_rangeremoves the entry for every alias and clears its ownership bits, but a surviving view remainsPAGE_NOACCESS. Its next CPU access has no handler entry. A Windows regression with two title views and a separate host view fails on the PR head (PAGE_NOACCESS1 vsPAGE_READWRITE4). A local fix materializes GPU bytes before removing the entry when any alias survives. The test verifies both restored protection and updated bytes; all 9gpu_ownedtests and targeted Clippy pass. This is synthetic validation; I have not run the game. I can share the one-file diff.c98eb22781to66b4b14b6a@shiman1901 on GitHub · 2026-12-01 16:26 UTC · original
Great catch @Ondra97 — fixed in
66b4b14balong with a 9th unit test (unmapping_one_alias_materializes_and_unprotects_surviving_view):drop_rangewith surviving aliases (gpu_owned.rs): entries overlapping the dropped range[first, last)are now partitioned intosurviving(at least one alias view lies outsidefirst..last) andgone(all views lie insidefirst..last). Forsurvivingentries,drop_rangecallsmaterialize_block(canonical, true, false, Caller::Sweep)before removal — writing the card's bytes throughbeside, restoring the saved protection (PAGE_READWRITE) on surviving views viaunreserve, and demoting the surviving view to eager — and then clearsOWNED_BITS/DEMOTED_BITSon the unmapped rangefirst..last.view1,view2) + a separate host view (beside) over one 64 KiB section, arms both title views asPAGE_NOACCESS, callsdrop_range(view1, BLOCK), and assertsVirtualQuery(view2).Protect == PAGE_READWRITE (4)and all 64 KiB read throughview2match the materialized pattern (0x7B).CI Clippy (
66b4b14b) confirms 0 errors / 0 warnings across all 8 files inlibandlib test(only the 5 unrelated F1-menu lints currently onmain5fabb46e).@trustno1-coder on GitHub · 2026-12-01 18:38 UTC · original
Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.
Pull request closed