perf(watch): lock-free publish via CLEAN/HELD bits, batched cover_run, and zero-VirtualProtect view/page invalidations #3945
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!3945
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3945"
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?
@qlfu on GitHub · 2026-11-30 12:36 UTC · original
qlfu:pr/perf-watch-lockfree-publish-cover→main· +165 −63 · 1 files · 2 commits · closed without mergingSummary
Reduces
GUARDSmutex contention and redundantVirtualProtectsyscalls incrates/victory-gpu/src/watch.rs:publish(): mirrorsGuards::cleanandGuards::heldinto atomicCLEAN/HELDBits(allSeqCst) updated strictly aftercover()completes and cleared ahead ofPUBLISHED.clear.publish()uses aSeqCstDekker recheck instead of acquiringGUARDS(~184 fewerGUARDSmutex acquisitions/frame).VirtualProtectinvalidations onviews_mapped()andtitle_memory_written(pages == true): clearscleanandPUBLISHEDon already-guarded blocks (and aliases) while keeping existing viewsPAGE_READONLY, avoiding RW/ROVirtualProtectchurn while still forcing refresh andcover()on newly mapped views.cover_run& single-lockguard(): coalesces contiguousg.protected && !g.cleanblocks inguard()into onecover(from, to)(VIEWS.read()) call, avoids double-lockingGUARDSon!PROTECTEDentry, and skipsg.alias()inprotect_alias()when an unprotected alias is resting or left alone.open_unlocked(): computestook = done && old != PAGE_READWRITEafter restoring non-RW/RO protections (done = false), preventing failedVirtualProtectcalls from clearingg.protectedinsettle().Verification
cargo test -p victory-gpu --lib --locked -- --test-threads=1 watch::(67 passed, 0 failed) +cargo check -p victory-gpu --all-targets --all-features --locked(exit 0).refreshes10.50 -> 9.45 msmed (11.13 -> 9.88 msmean),prepdown to22.8 ms,copiesdown to11.1 ms,0WARNs /0ERRORs.@qlfu on GitHub · 2026-11-30 15:05 UTC · original · edited 2026-11-30 15:27 UTC
Added word-batched
Bits::set_wordforGuards::mark_cleanso marking contiguous clean blocks emits oneSeqCst fetch_orper 64-block word instead of per block. Verified:cargo check -p victory-gpu --all-targets --all-features --locked+watch::unit tests passed + cleanmerge-treeonto41adb551.@upipibi on GitHub · 2026-12-01 02:43 UTC · original
Race review of #3945 (head
701519a4): it holds. I found no lost write and no crash. Itsopen_unlockedchange also fixes somethingmainstill has.Reading.
publish()withoutGUARDS: it setsPUBLISHED, then checksCLEAN/HELD/BESIDE/unsettledagain (allSeqCst). Every path that takes a block out ofg.cleanorg.heldgoes throughunmark_clean/unmark_held, and where the block may have been published it clearsPUBLISHEDafter the mirror. The exception iscover()(:3313), which un-cleans only blocks noted clean in the same locked pass, beforemark_clean, as onmain. So one of the two sides always sees the other.CLEANis only set bymark_clean, which readsg.cleanaftercover()(protect), so it never runs ahead of the books.took = done && old != PAGE_READWRITEinopen_unlocked: onmain, aVirtualProtectthat fails leavestook = true.settlethen takes a block that is still read-only out ofg.protected. A write there finds nothing to open, and the handler gives up with 0xc0000005. That is the state I traced in #3760, by another way in. This PR closes that way.Stress test. This is the test from my #3760 review: one 16 MiB view, four threads guarding it in a loop,
writing()on another thread, 48 writer threads for 20 s. Debug test build, Ryzen 9 5950X, Windows 11, alternating runs. The PR was tested at its base, since it conflicts withmainnow.41adb551watch::on the PR, 3 runs: 65 passed, 0 failed twice. Once it was 64 passed, 1 failed:ask_rest_falls_back_per_piece_when_touching_unwatched_neighbour, a test-isolation flake onmainthat #4620 fixes. The worst-wait ranges overlap, so I wouldn't read much into them.It conflicts with
maininwatch.rs, so it needs a rebase before it can go in. Thetookline alone would also make a small fix by itself.Tested with the help of Claude Code (Claude Opus 5.5).
@trustno1-coder on GitHub · 2026-12-01 18:47 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