Region epochs are per 64 KiB block, not per 64 MiB (about 2,600 to 400 block walks a world frame) #179
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Belobug--VIctory-Belobug-AMD!179
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-179"
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?
@SPFCChris on GitHub · 2026-11-25 19:33 UTC · original
SPFCChris:perf/block-sized-region-epochs→main· +119 −18 · 2 files · 3 commits · openRead "Measured" before merging: this cuts the work it aims at more than six-fold, but I could not show a frame-time gain beyond run-to-run noise. It is offered as a small step that removes lock traffic, not as a speed-up I can prove.
Second edit: as first posted this change made stale host copies more frequent (stretched triangles for a few seconds in one run). The third commit fixes the hole behind it, which is in
maintoo, and adds a switch that checks the epochs against the walk: see the comment below for the figures. Do not merge the first two commits without the third.Edited after posting: the first version quoted the
copies per framefigures as logged (12,300 and 2,550 watches a frame). Those are about five times too high, see the note under "Measured"; the figures below are corrected. The ratio and everything else stand.Problem
Shadow::update_freekeeps the ranges it found clean, keyed bywatch::region_epoch, and skipswrites_guarded(the walk of the range's blocks underGUARDS) while the epoch stands. A region was 64 MiB. The title writes somewhere in every 64 MiB of its buffers between two checks of the same range, so the fast path missed most of the time: in the world, about 2,600 watches a frame over ranges of which 95 % had not changed, the same big buffers checked several times a frame.Change
A region is one guarded block (64 KiB):
REGION_SHIFT26 becomes 16 by default, and the table grows from 1,024 to 2^20 counters (8 MB of zeroed statics; two regions share a counter only 64 GiB apart, which can only cost a needless walk).VICTORY_EPOCH_SHIFT=26gives the old size back.Why it is still sound: every bump already passes the addresses it concerns (
open_here, the pinned block inguard,title_memory_remapped,title_memory_written,try_open_guarded), and a block lies in exactly one region, so the regions of a written address are those of its whole block. A range's epoch therefore stands exactly as long as none of its blocks was opened, remapped or rewritten, which is what the walk would find. A write through another view of a page opens the guarded view's block by its own address (open), and bumps there. The shift is clamped to at least 16 for that reason.One file,
crates/victory-gpu/src/watch.rs.Measured
Radeon 8060S (Ryzen AI Max+ 395), diag build, Series X profile, opening cutscene, 220 s in the world per run. Same binary,
VICTORY_EPOCH_SHIFT=26against the default, runs alternated. Built ona59f3e5plus #148 (this GPU needs it to draw the world) plus #178.Counters of
copies per frame, per frame, medians over the intervals of 2,500 draws a frame or more, two runs each:A note on those counters, which is a small bug of its own:
Meter::framecallscopystat::log(frames)once every 5 s with the frames of the last second only, while the counters run since the last line, so the line prints them about five times too high (it showed 12,300 and 2,550 watches a frame here). The table recounts them over the frames of the whole interval, from a per-frame time log. I can send the one-line fix separately if wanted.Median frame time of the frames in a band of draws per frame:
One of the two runs is faster than anything before it and the other is not: with single runs differing by this much, that is no proof. The time in watches fell by a third, not by the six-fold of their number (it includes waiting for
GUARDS), so the walks this removes were the cheap ones.Tested
cargo test -p victory-gpu --lib --locked: 114 passed, 0 failed, 4 ignored. One is new,a_write_changes_the_epoch_of_its_block_alone: after a write to one block of a guarded view, the ranges holding that block have a new epoch and the block beside it has not (with 64 MiB regions it fails).cargo clippy -p victory-gpu --all-targets --locked: no warning in the changed code.Not tested
VICTORY_EPOCH_SHIFT=26is the first thing to try.diagnostics; anything past the opening cutscene.AI-assisted (Claude Code); no game data.
🤖 Generated with Claude Code
@KernelSmoker on GitHub · 2026-11-25 20:04 UTC · original
Independent verification on PR head
01709d0(Bazzite Linux 45 x86_64, Rust 1.98.1, Intel Core i9-11900K, GE-Proton 10-34 / Wine 10.0):diagnosticsbuild (noted as untested in the PR):cargo test -p victory-gpu --lib --no-run --locked --offline --target x86_64-pc-windows-gnuandcargo clippy -p victory-gpu --all-targets --locked --offline --target x86_64-pc-windows-gnupassed cleanly with 0 new warnings incrates/victory-gpu/src/watch.rs.--test-threads=1):VICTORY_EPOCH_SHIFTunset → 16 / 64 KiB regions):watch::tests8 passed, 0 failed (includinga_write_changes_the_epoch_of_its_block_alone).VICTORY_EPOCH_SHIFT=26(64 MiB regions):a_write_changes_the_epoch_of_its_block_alonefails as expected (the block beside it: left 2, right 0).REGION_EPOCHSinitial value from1to0keeps the 8 MiB (1 << 20×AtomicU64) static in.bssrather than bloating the binary, andShadow::clean_spans(shadow.rs:720-775) checksHashMap::get(&(from, to)) == Some(&ge)with no zero sentinel, so0is safe.region_epochnow scans ~2,784Acquireloads across 64 KiB buckets (vs 3 at shift=26) — still far cheaper than takingGUARDS, which matches the measured reduction in walks.(No in-game vehicle/world run performed here; this verifies the non-
diagnosticsbuild, clippy, Wine unit tests, and static/epoch review.)@SPFCChris on GitHub · 2026-11-25 22:49 UTC · original
Do not merge this as it stood before commit "Memory mapped anew bumps its regions' epochs…": by itself the change made stale host copies more frequent. I have pushed the fix and a way to check it.
What happened. A run with block-sized regions showed stretched triangles across the screen for a few seconds. To test the epochs directly I added a diagnostics switch,
VICTORY_EPOCH_CHECK=1: whereShadow::update_freefinds a range inclean_spansat the current epoch, it runs the walk all the same and reports ranges in which the walk finds a block written although the epoch stood. Over about four minutes in the world (Radeon 8060S, opening cutscene):VICTORY_EPOCH_SHIFT=26, i.e.main's behaviour)So the hole is in
maintoo, and this PR made it about seven times more frequent, because with 64 MiB regions some other write in the region usually bumps the epoch by accident.The hole.
title_memory_remappedbumped the epochs onlyif changed, that is when it found guarded blocks or noted holes in the range. Butguard's first-encounter path skips a block that is unmapped (check_each) without noting it as a hole. When the title maps memory there later, nothing is guarded and nothing is noted, so no bump: a range holding the block stays known clean, the walk is skipped, and what the title writes into the new memory (no fault, it was never made read-only) does not reach the host copy.The fix bumps the epochs of a remapped range unconditionally (
watch.rs, three lines). The check stays in as a diagnostics switch (shadow.rs); it costs nothing unless set.Still true: I cannot show a frame-time gain for this PR beyond noise, so its case is no stronger than before. The three-line fix is worth having on its own, with or without the smaller regions; say if you would rather have it as a separate PR.
AI-assisted (Claude Code); no game data.
@adrianmjim on GitHub · 2026-11-26 19:40 UTC · original
Tested natively on Windows 11 26300 with an RX 7900 XT (RDNA3, driver 32.0.32029.2010), MSVC and Rust 1.98.1. Head is
847dcbb. I compared it with base000ffddand with main4f62c2a; the PR merges into main cleanly. I could not runVICTORY_EPOCH_CHECK=1in the game because the title is not on this machine. So I checked the hole that commit 3 fixes with a unit test instead.Remap hole, local-only test (not in the PR):
guardtakes thecheck_eachpath. The range is [unmapped][view][unmapped], so the third block is skipped and not noted as a hole.region_epochfor the range. Map a view into the third block, calltitle_memory_viewand thentitle_memory_remapped, and write into the block. There is no fault, because the block was never made read-only.region_epochchanged.Results:
000ffdd(samewatch.rs/shadow.rsas main, 64 MiB regions): fails 5/5, the epoch stays the same.2569aee(first two commits only): fails 5/5. It also fails withVICTORY_EPOCH_SHIFT=26.847dcbb: passes 5/5. It also passes withVICTORY_EPOCH_SHIFT=26.So the hole can be reproduced without the game, and the third commit closes it at both region sizes. Commit 3 has no test of its own, and the existing tests pass without it. I can share this test (about 50 lines, Windows-only like the rest of
watch::tests) if you want it in the PR.Other results:
a_write_changes_the_epoch_of_its_block_alonecopied onto000ffddfails 3/3 ("the block beside it", left 3, right 1). It passes at head.cargo test -p victory-gpu --lib, 70 interleaved runs each of base, head, main, and head merged on main:watch::teststest: 10, 13, 13 and 13 of 70.cargo clippy -p victory-gpu --all-targets --features diagnostics(MSVC): no warning in the changed code.Not tested: frame time or watch counts in game, a release build, and other GPUs.
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.