Repository navigation
Conversation
…ACK) Co-authored-by: borosf <borosf@users.noreply.github.com>
Co-authored-by: borosf <borosf@users.noreply.github.com>
…s them Co-authored-by: borosf <borosf@users.noreply.github.com>
Co-authored-by: borosf <borosf@users.noreply.github.com>
Co-authored-by: borosf <borosf@users.noreply.github.com>
Dukestar69
left a comment
There was a problem hiding this comment.
Verified on RTX 5090 & WARP against origin/main (63bcca4):
cargo test -p victory-gpu --lib shadow:: -- --test-threads=1: 11/11 passed on RTX 5090 and WARP (includingmarked_pages_leave_the_submission_and_go_back_at_their_first_access).cargo test -p victory-gpu --lib watch:: -- --test-threads=1: 15/15 passed.cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 20/20 passed on RTX 5090.cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.
Clean opt-in VICTORY_LAZY_COPY_BACK mechanism deferring marked-page copy-backs until first CPU access.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal
left a comment
There was a problem hiding this comment.
The single-threaded synthetic test passes on Windows 11 (shadow:: + watch:: 26/26 on RTX 5090; VICTORY_LAZY_COPY_BACK=1 15/15 on RTX 5090 and WARP; Clippy and cargo xtask policy clean), and deferring unneeded copy-backs is an interesting direction for FIND-33. However, deep review of watch.rs and shadow.rs found several serious correctness and performance issues that make this unsafe even under opt-in use and regress the default-off fast path:
1. Multithreaded / drain crash (EXCEPTION_CONTINUE_SEARCH) and stale-read window (watch.rs:367-398, 425-440, 1068-1075, shadow.rs:91-111)
lazy_page,take_lazy, andtake_all_lazyall remove pages fromg.lazyand releaseGUARDSbefore unsealingPAGE_NOACCESS. If any other thread accesses a page while it is being serviced (especially duringtake_all_lazy, which removes every sealed page up front before looping over them one by one), it faults onPAGE_NOACCESS, callslazy_pagewhich now returnsNone, hitsif r.ExceptionInformation[0] == READ { return EXCEPTION_CONTINUE_SEARCH; }, and crashes the process with an unhandled access violation.- In addition,
copy_back_onecallsrepaged(page / PAGE)(PAGE_NOACCESS->PAGE_READONLY) beforecopy.copy_back_marked(page)writes the GPU's bytes into title memory. Between those two calls, any concurrent reader succeeds without faulting and observes stale pre-GPU bytes. - Both require keeping a per-page in-flight/servicing state (so concurrent faulted threads wait until the page's GPU bytes have actually landed, and only then unseal to
PAGE_READONLY— or write through an alias / side view before flipping protection).
2. ReadProcessMemory (host::copy_mapped) and VirtualQuery (texture::committed) silently zero/skip PAGE_NOACCESS pages without firing VEH (host.rs:2499-2510, texture.rs:752-777)
host::copy_mapped(Step::Copy/Step::Fill) readssrcusingReadProcessMemory(GetCurrentProcess(), ...). BecauseReadProcessMemoryis a kernel syscall, hitting aPAGE_NOACCESSpage returnsERROR_PARTIAL_COPY(false) without delivering a VEH exception, andcopy_mapped's fallback fills the destination with zeros.copy_mappedonly callswatch::writingondst(whentitle_dstis true) and never drainssrc.texture::committed(texture.rs:765-768) explicitly rejectsPAGE_NOACCESS(info.Protect & (PAGE_NOACCESS | PAGE_GUARD) != 0), soStaging::refresh_nowsilently skips uploading any texture overlapping a sealed page rather than faulting it back.
3. title_memory_aliased calls forget_lazy instead of draining pending GPU writes (watch.rs:1024-1035)
forget_lazy drops the ledger entry and flips protection back to PAGE_READONLY without calling service_lazy. Unlike title_memory_remapped or retake, mapping a second alias view of a live physical page does not invalidate the GPU writes waiting in g.lazy — calling forget_lazy silently discards those writes permanently for both views. Those pages must be drained (service_lazy) before installing the alias.
4. Default-off performance regression: lazy_armed() locks GUARDS on every Shadow::update (watch.rs:362-364, shadow.rs:555, watch.rs:816)
lazy_armed() currently acquires the global GUARDS mutex (guards().lazy.iter().next().is_some()), and is called at the top of Shadow::update before if self.clean() { return 0; } (as well as in copy_back_page, copy_back_or_not, and watch::writing). That defeats the lock-free fast path even when VICTORY_LAZY_COPY_BACK is off (the default). Tracking the armed count in an AtomicUsize (checked before locking GUARDS) keeps the default-off / empty path lock-free.
5. VEH allocation / re-entrancy & README.md table placement
on_writeallocates a heapVec(vec![(copy, at / PAGE)]) inside the Vectored Exception Handler; switching to a single-page helper (service_lazy_one(©, at / PAGE)) avoids unnecessary heap allocation in the fault path (and note the general re-entrancy risk of acquiringShadow::beforeinside VEH if any path ever reads title memory while holdingself.before).README.md:220addsVICTORY_LAZY_COPY_BACK=1inside the--features victory-gpu/diagnosticstable, even thoughlazy_on()is active in all builds.
|
Automated triage for the maintainers. Needs work. This adds
Also, the README row is a paragraph of rationale. Please cut it to one line saying what the switch does. CI: Generated by Claude Code |
…it drained Co-authored-by: borosf <borosf@users.noreply.github.com>
Co-authored-by: borosf <borosf@users.noreply.github.com>
|
All five points are addressed at the new head
Hardware verify (Arc B580, Windows 11): On the measurement criterion: if/when a card that sustains a world run measures the diagnostics frame-time medians with the switch on vs off at matching draw counts, the mechanism should show most marked pages skipping copy-back entirely (a page never CPU-read gets one |
|
Measurement at
(Two runs each, same process, the eager cases first so that no sealed page is ever read by an eager copy.) The arming is fully engaged, not falling back: 2,250 pages sealed a frame, 0 refused by the guard state, 0 by the host. And the pages still go back — 2,062 serviced a frame at 0 % reads, 2,344 at 50 % — because One correction to the description while I am here: So this fails the measurement criterion, as I noted in my last comment it might: closing as a null result on measurement alone. Default behaviour is untouched either way — with the switch off |
Summary
Shadow::copy_back_markedbrings every page its shaders marked as written back into title memory — on the card that is 60–127 ms a frame, 95 % of it waiting (FIND-33: the snapshot's pages fetched, and the waits around them; the host-side merge is 2.4–2.9 ms, the write 0.4–0.5 ms). The world marks ~2,250 pages a frame; most are never read by title code before a later pass overwrites them.VICTORY_LAZY_COPY_BACK=1(opt-in, off by default — behavior is unchanged without it), a marked page leaves the submission sealed no-access. The first read faults that one page back; the first write faults it back and then lands as the title's own over it (the merge happens underneath, as eager copy-back would have); a page nothing touched is written by the next submission's copy-back and never holds the critical path.watch): sealed pages holding their copy alive, and the vectored handler — which today services write faults — also taking read faults on those pages, servicing exactly one page each time. Arming is oneVirtualProtectper run of pages.Shadow::update,copy_back,copy_back_page), writes the guards do not see drain before they mark (watch::writing— kernel reads, DirectStorage), and remaps, retakes and new aliases drop the wait and unseal (title_memory_remapped,retake,title_memory_aliased). In-process reads of a sealed page fault into the handler and service transparently.Verification
-D warnings,cargo test --workspace --locked); with the switch off the suite is unchanged.marked_pages_leave_the_submission_and_go_back_at_their_first_accessdrives the real fault handler on the Intel Arc B580: the submission leaves pages sealed (asserted viaVirtualQuery, arming counters(3, 0, 0)— sealed, none refused), aread_volatilefaults the GPU's byte back and the page is guarded again, awrite_volatilemerges underneath and lands on top, an untouched page is written by the next copy-back, and the ledger ends empty.cargo clippy -p victory-gpu --all-targets --locked -- -D warningsclean;cargo test -p victory-gpu --lib --lockedgreen except the two known Intel heap-cap failures (Test report: RTX 5070 (Blackwell), Windows 11, 70564ae: 471 passed, 5 failed, 7 ignored (4 from the 1,000,000 view heap cap) #1744) pristine main also fails.claiming: FIND-33 — lazy copy-back on read (marked pages go back at their first access), the 95 %-wait copy-back stall (#1633 comment, per the ledger)