shadow: lock-free AtomicU64 landing bitmap and word-scanned take_landed #3753
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!3753
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3753"
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?
@ScymicX on GitHub · 2026-11-30 05:59 UTC · original
ScymicX:perf/landed-atomic-bitmap→main· +136 −1 · 1 files · 2 commits · openWhat it changes
Once a shadow buffer receives any GPU->CPU landing (self.landing == true), every subsequent Shadow::take of known pages goes through Shadow::take_landed. Previously this acquired self.landings: Mutex<Vec>, walked the range 4 KiB page by 4 KiB page, and split even unlanded runs into <= 64 KiB (PAGE) pieces.
This PR adds a lock-free landings_atomic: OnceLock<Box<[AtomicU64]>> bitmap (enabled by default, VICTORY_LANDED_FAST=0 restores the legacy Mutex<Vec> path):
oted runs at PAGE so TITLE scratch memory stays bounded) and clears only inspected full KERNEL_PAGE bits atomically with etch_and(!clear_mask, Ordering::AcqRel), preserving partial-page bits and concurrent
ote_landing updates in the same word.
How it was tested
Checked for overlap
ote_landing / ake_landed).
@Dukestar69 on GitHub · 2026-11-30 06:09 UTC · original · approved these changes
Tested locally merged onto
main(41adb551).crates/victory-gpu/src/shadow.rs.cargo test -p victory-gpu --lib shadow::passed (73 passed; 0 failed; 5 ignored, includinglanding_tests::take_landed_fast_path_and_multi_word_runsandtake_batches_dirty_runs_for_whole_and_diff_paths) with 0 new warnings.Clean lock-free
AtomicU64landing bitmap and word-scannedtake_landed. LGTM.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@mstrmoos on GitHub · 2026-11-30 19:22 UTC · original
Picked onto our branch with #3753, #3756, #3760, #3881, #3832, #3858 and four that have since merged (#3818, #3850, #3874, #3871). #3760 needed a hand merge on top of the others.
All of victory-gpu's and victory-shader's tests passed. On the RTX 5080 16 GB, Ryzen 7 9800X3D, Windows 11, Series X profile, same save and 90 s bench route each run, the frame median went from 40.4 to 39.1 ms for the whole set. I didn't measure the PRs one by one, so this is evidence of no regression rather than this PR's own gain. Screenshots looked clean.
@upipibi on GitHub · 2026-12-01 00:04 UTC · original
Race review of #3753 (head
858497ad): the lock-free bitmap holds. I found no interleaving where it skips an upload that the mutex path would send. One small note about A/B builds is at the end.Why it holds (line numbers on the head):
take_landedbuildsclear_maskper word only from whole pages inside its own[from, to), then callsfetch_and(!clear_mask)(shadow.rs:7681-7697). A 64-page word covers 256 KiB and a refresh part is 64 KiB, so parts on different threads do share words. Each part clears only its own bits.note_landingof a page whose bit is already set, landing between theloadand thefetch_and. That note is cleared.land_cardcallsnote_landingonly afterland::piecehas put the bytes in (shadow.rs:8336-8341). This take reads title memory after itsfetch_and(copy_mapped, :7727), so it still sees those bytes. The only effect is that the next take of that page usesself.copy, the same path as withVICTORY_LAND_ECHOoff: an extra upload, never a missed one. In every interleaving, the bits set here are a subset of what the mutex version would hold.fetch_or(Release)innote_landingpairs withload(Acquire)intake_landed, so a take that sees a bit also sees the bytes landed before it.Test: a stress test with two threads on one word. One thread notes and takes pages 0..32 eight times a round; the other notes pages 32..64 one by one. After each round, all bits 32..64 must still be set. That's 2,000 rounds per run.
the test (added to
landing_tests)7d93ee07,shadow::landing_testsfetch_and(!clear_mask)replaced bystore(word & !clear_mask)(a read-modify-write that isn't atomic), 3 runsround 0: a note of pages 32..64 was lost), 1 passedThe negative control shows the test does catch a lost note. Setup: Ryzen 9 5950X, Windows 11, CPU-only tests. The head alone doesn't build the lib tests (E0061 at host.rs:20302, which isn't in this PR's diff), so I tested it merged onto current main, which merges cleanly.
A/B note:
landed_fast()usestoggled!. In diagnostics orabbuilds withVICTORY_ABnamingVICTORY_LANDED_FAST, it can flip while the title runs (switch.rs:24). Notes then go to one bitmap while takes read the other. After an on → off → on cycle, the atomic bitmap still holds bits from the first "on" stretch that the mutex path never cleared, so a page can be compared as landed when it was last landed long ago. This affects only an A/B of this switch. Latching it once with aOnceLock<bool>, as #3756 did for its switch, avoids that.Tested with the help of Claude Code (Claude Opus 5.5).
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.