watch: extend WRITTEN_EPOCHS for lock-free journal reads and whole-page notes #3756
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!3756
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3756"
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 06:04 UTC · original
ScymicX:perf/watch-journal-lockfree→main· +424 −175 · 1 files · 3 commits · closed without mergingWhat it changes
main already maintains a 3-level lock-free WRITTEN_EPOCHS (PageEpochs) radix table for
othing_new_with/
othing_new_single, while writes, writes_since, sked, parts_written,
othing_new_all, and landed_beside still read and write Journal::written: BTreeMap<usize, u64> under the global JOURNAL mutex. Across 1,500+ watch::writes calls/frame on worker threads, JOURNAL lock contention and BTreeMap traversal/updates add substantial CPU overhead.
This PR extends the existing WRITTEN_EPOCHS table instead of duplicating a second radix structure (enabled by default; VICTORY_JOURNAL_LOCKFREE=0 falls back to Journal::written under JOURNAL):
ote_whole (etch_max + present bit), set_has_parts / clear_has_parts / ny_has_parts, plus a shared scan_present traversal backing collect_range, ny_since (preserving #2795's zero-allocation writes_since path for texture refreshes), and ll_le.
ew_in: update/query WRITTEN_EPOCHS directly when sync_epochs is true, avoiding BTreeMap churn even on sk_ahead/sk_once paths.
How it was tested
Checked for overlap
@Dukestar69 on GitHub · 2026-11-30 06:08 UTC · original · approved these changes
Tested locally merged onto
main(41adb551).crates/victory-gpu/src/watch.rs.cargo test -p victory-gpu --lib watch -- --test-threads=1passed (67 passed; 0 failed, includingparts_tests::page_epochs_checks_single_and_multi_page_rangesandpage_epochs_collect_any_since_and_parts_flags) with 0 new warnings.Solid lock-free
WRITTEN_EPOCHSextension for journal reads and whole-page notes. LGTM.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@ColorC on GitHub · 2026-11-30 08:58 UTC · original
Cross-validation on RTX 5070 Ti + Ryzen 7 9800X3D (Series X 1440p, DLSS Quality + 3x MFG), testing
#3756(VICTORY_JOURNAL_LOCKFREE) together with#3760(VICTORY_WATCH_UNLOCKED_PROTECT) andVICTORY_FAULT_UNLOCKEDvia same-binary toggle A/B at ~10.3k draws/frame:refreshes=0)=1)Notes
refreshesby-6.6 ms(16.2 -> 9.6 ms) and gained+2.52 FPSwith zero stability regressions over 8+ minutes of open-world walking (both raster and DXR 1.1 HW RT).#3756and#3760compose cleanly except for a trivial 1-hunk adjacency inwatch.rswherejournal_lockfree()andunlocked_protect()sit right afterparts_on().Test Setup
--res 1440 --dlss quality --framegen 3 --fps 1000)-C target-cpu=znver5) rebased onmain(41adb551) with a curated local PR stack; all A/B numbers below are same-binary toggle ablations from the exact same restored save (~10.0k–10.4k draws/frame standing scene) after official 1-time warmup.@Yoruiopz on GitHub · 2026-11-30 09:49 UTC · original
I reproduced a lost-watermark race on exact head
88a0f30d. A publisher can reserve epoch W and still be writing radix stamps. A guarded or already-covered query can take a radix snapshot that misses a pending stamp, then return watermark N greater than W. A subsequent writes_since ignores W, even after that stamp becomes visible. A landing can leave PUBLISHED true, so the reader can take that fast path during publication.The deterministic native Windows regression fails on the exact PR logic with “write epoch 2 was hidden by watermark 3.” It passes with this synchronized radix variant. The correction keeps the journal writer guard from ticket reservation through stamp and partial-mask publication, and keeps the read projection and returned watermark in one journal snapshot. The radix index remains available as a process-start opt-in. These are two commits so the regression can be reviewed separately.
On Windows, all 70 watch tests passed in separate runs with VICTORY_JOURNAL_LOCKFREE=0 and =1 after the correction. Gameplay and performance of that corrected variant are unmeasured.
@ScymicX on GitHub · 2026-11-30 14:36 UTC · original
Follow-up commit
2dd01d0addresses the lost-watermark race caught by @Yoruiopz (and thanks @ColorC for the A/B numbers!):EPOCH_GATE): AddedEPOCH_GATE: RwLock<()>(with strict lock orderJOURNAL -> EPOCH_GATE) so publication paths (owner_wrote,ask_ahead,ask_rest,ask_once,wrote,writes_with,landed_beside) serializenext_asking()against lock-freeWRITTEN_EPOCHSreaders (asked,writes_with). A reader can no longer advance its watermark past an in-flight write epoch before the page'sWRITTEN_EPOCHSstore becomes visible.journal_lockfree()fromcrate::toggled!toOnceLock<bool>latched at process start soVICTORY_ABcannot flip between lock-free and locked mid-run.PageEpochs::any_has_parts_iteracrossparts_written,writes_with, andlanded_beside, and addedwatch::parts_tests::epoch_gate_prevents_lost_watermark_during_publication.Verified on
2dd01d0:cargo test --locked -p victory-gpu --lib watch:: -- --test-threads=1: 67 passed, 0 failed (defaultVICTORY_JOURNAL_LOCKFREEON)VICTORY_JOURNAL_LOCKFREE=0(-- --test-threads=1): 67 passed, 0 failedwatch::parts_tests::epoch_gate_prevents_lost_watermark_during_publication(10x loop): 10/10 passedcargo clippy -p victory-gpu --no-deps --all-targets --locked(+--all-features): 0 new warnings inwatch.rscargo xtask policy --staged:1 files ok@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.
@nicolasabosch on GitHub · 2026-11-30 21:52 UTC · original
Tested on an RTX 4070 Laptop 8 GB: no measurable fps difference in this scene (2 runs).
Tested on main
e1251c31with this PR (30d4fe95) merged on top and nothing else changed. Release build, same profile as main.Setup
victory play --series-s --dlss performance --framegen 2, with no fps cap and the window minimized.host:reports, about 200 s. These are real frames, not generated ones.On this laptop, identical main runs differ by up to about 2–2.5 fps, so only an effect of roughly 2–3 fps or more would be visible in this scene. The submit thread's time asking the write watch was 4.4 and 3.8 ms with this PR, against 3.6–4.3 ms on main, so the lock-free journal did not show up in that line here. The fixed-save run (15.85) is just under main's lowest and the other run is inside main's range, so neither stands out from the noise.
Not tested: driving, camera turns, interiors, an image comparison, other GPUs.
@upipibi on GitHub · 2026-12-01 00:04 UTC · original
Race review of #3756 at
30d4fe95, after2dd01d01:EPOCH_GATEcloses the lost-watermark race @Yoruiopz found, on the real reader paths. One gap is in the regression test, not the code:epoch_gate_prevents_lost_watermark_during_publicationtakesepoch_read()itself and never callswrites_withorasked. It still passes with the gate removed fromwrites_with, shown below.Audit (watch.rs line numbers on the head):
next_asking()whose number is stamped runs underepoch_write()until the stamps are in:owner_wrote:229,ask_ahead:1055,ask_once:1280,ask_rest:1461,wrote:1502,writes_with:1786 and :1794,landed_beside:3356 and :3370. All of them takeJOURNALbefore the gate where they take both, so the lock order holds.epoch_read():asked:1614 and :1621,writes_with:1690, :1703, :1718 and :1774.ahead()path returnsahead_asked, read underJOURNALbeforeepoch_read(). That's fine, becauseahead_askedis only assigned underepoch_write(), after every earlier number's stamps.nothing_new_with,nothing_new_single,new_in) compare stamps with numbers the caller already holds and return no new watermark.Test: Yoruiopz's regression (cc9613b9) with its writer changed to follow this PR's protocol (
JOURNAL, thenEPOCH_GATEwritten, then its number), run through the realwrites_withowned path:the test (added to
parts_tests)Results, with this PR merged onto main
7d93ee07(clean merge) and #4620 applied so a known test-isolation flake inwatch::stays out:epoch_gate_prevents_lost_watermark_during_publication, 3 runswatch::in parallel, default (lock-free on), 20 runswatch::withVICTORY_JOURNAL_LOCKFREE=0, 5 runslet _ep = epoch_read();removed from the owned path ofwrites_with(:1703); the test above, 3 runswrite epoch 2 was hidden by watermark 3 (publisher got in: true)epoch_gate_prevents_lost_watermark_during_publication, 3 runsSo the gate is what stops this, and only the test above notices when a reader path loses it. Adding it, or one like it for
asked, would keep a later change from dropping a reader'sepoch_read()unnoticed. 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 all runs above are merged onto main.Tested with the help of Claude Code (Claude Opus 5.5).
@sklzygit on GitHub · 2026-12-01 15:14 UTC · original
I tested head
30d4fe95f0f036aa76a5eaa994c79a0c7190dfa7and found a separate partial-history race in the whole-note fast paths ofwrites_withandlanded_beside.The
any_has_partscheck happens before acquiring the exclusiveEPOCH_GATE. Another writer can install a partial note between that check and the lock. The fast path then callsnote_wholewithout clearing the newly installedJournal::partshistory. A laterparts_writtenquery can report only the earlier partial write, omitting the remaining bytes of the whole-page write.I reproduced this with authored metadata only: own one 64 KiB page, make an initial whole note and record its watermark, then inject a 4 KiB-part note at the actual
landed_besidefast-path gap using a test-only hook. Letlanded_besiderecord all sixteen kernel pages, then queryparts_writtenfrom the saved watermark. Before the fix, the result is[8]; the whole write requires[65535].The local fix is to acquire the exclusive epoch gate before checking for partial history, and retain that guard through whole-note publication. If partial history exists, drop the guard before entering the existing JOURNAL fallback, preserving the documented
JOURNAL -> EPOCH_GATElock order. Apply this to both whole-note fast paths. The deterministic regression and the existing whole/partial-write parity fixture pass after this change.This reports a forced legal concurrency interleaving, not proof that this race caused any particular gameplay artifact. I have not measured an in-game FPS gain from this PR.
Test rig: Ryzen 7 9800X3D, RTX 5080 16 GB, 32 GB RAM, Windows 11, NVIDIA 621.40. The regression is CPU-only and contains no title data. Normal gameplay profile is Series X, 2560x1440 output, 1080p scene, DLSS Quality, 30 FPS base cap, FG/RT off; no game was launched for these tests.
@trustno1-coder on GitHub · 2026-12-01 18:49 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