Copies whose shader writes stay on the card: a range taken again with no title write since sends only what changed; VICTORY_CLOBBER_WATCH=1 diagnostics (#1387) #4340
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4340"
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?
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Lyrnc on 2026-11-30T19:04:00Z.
Refs #1387 (closed as older than v2026.11.29.01; a user on an RTX 5080 still sees it on a v2026.11.29-based build: the picture turns white "like a flashbang", then comes back over about 10 s). Same shape as #2259, where it repeats for the whole drive.
What is confirmed: the mechanism below, by reading the code and in unit tests. Not confirmed: that it is what turns the picture white. The white-out was not reproduced here: it needs a night drive, and I have no save for one. So this is a fix of a real fault that fits the report, plus diagnostics that can tie a white-out in a log to an event.
The fault
With
VICTORY_WC_NO_BACK=1, whichvictory playandplay-nvidia.ps1set with a 1 MiB floor, what shaders write in big write-combined copies is never copied back. Only the card's side has it. Any title bytes sent over such a range put the title's older bytes back. Thewc_no_backcomment already accepts that for pages the title writes, because of counters.It also happens where the title wrote nothing:
copy_staletakes a page again whenevercopied[page]is 0 and neitherrangedslot nor the range's memo slot holds the range.copiednotes a page only when one refresh holds all of it. A page that draws read a few hundred bytes at a time (constant views) is never noted, so its ranges count as current only while a slot still holds them.copy()marks all of it to go up. The shaders' bytes in that range go back to what the title last wrote, often its first values.A value a pass carries from frame to frame and adapts over seconds would then jump and adapt back, at no fixed time. That is the shape of #1387 and #2259. Nothing is logged when it happens. The rule is live in the reporters' runs:
9a427c14, which turns the rule off under HW RT. Its play log has 75 copies of 1 to 24 MB under the rule.What changes
Shadow::leavesmarks a copy whose shader writes stay on the card. It runs in the write-combined branches ofgpu_writesandshader_writes, and in theVICTORY_UNIFIED_BACKbranches whenwc_leftis set.Cover: joined ranges and the asking of that write; cleared when the write watch reports a newer write).copy_stale, for such a copy with two sides: the part of a page it would take again goes through the existing dword compare when all of it lies inside those ranges. This is the same compareVICTORY_SEND_CHANGEDuses (take()'s body moved totake_into()). Only dwords where title memory differs from the CPU's side go up.wc_no_backnames, still reaches the card. A test covers it.VICTORY_WC_KEEP_LEFT=0restores the old behaviour.Copies whose shader writes come back are not touched, and neither are single-sided or mapped (
VICTORY_WC_BAR) copies. Cost: for copies under the rule only, and only for the pages a refresh takes (again): one uncontended lock per refresh and a short range lookup per such page. Pages that are current cost nothing more than before (benchmark under Tests). The compare replaces a copy and sends less.Diagnostics:
VICTORY_CLOBBER_WATCH=1(off by default)clobber.rs, oneWARNline per event with the frame:VICTORY_CLOBBER_FRAMESframes (16 unset) and the bytes differ from the CPU's side. The line has the copy, title address, size, range, frames since the write, hashes of the bytes there and of those sent, and the first changed dword.Each kind logs its first 64 events, then every 256th. Off, it costs one relaxed load at those places.
For someone who sees the white-out:
VICTORY_CLOBBER_WATCH=1and note the time it turns white.VICTORY_WC_NO_BACK=0, which leaves no shader writes on the card at all. If the white-outs stop with it, they are this class.Tests
keep_left_tests::a_range_taken_again_without_a_title_write_keeps_what_shaders_left: a partial range of a two-sided copy marked as leaving writes on the card is taken, its slots are taken over (a range in its memo slot is found by search), and it is taken again with no title write. Nothing goes up. A copy whose writes come back is taken whole as before. After a title write of the page it goes up whole once, then nothing again.VICTORY_WC_KEEP_LEFT=0this test fails at the re-take: the whole range goes up. That is the old behaviour.keep_left_tests::a_word_the_title_sets_again_goes_up_although_another_range_was_taken_since(the counter case),a_change_the_write_watch_missed_goes_up_as_its_dwords,a_cover_holds_what_was_taken_since_the_last_write_and_nothing_else.clobber::tests(7): range notes, recency and overlap, the made-again list, read-back jumps, line limits, hash.keep_left_tests::copy_stale_cost_of_the_cover(#[ignore = "benchmark"]):copy_stalein nanoseconds a refresh, for a copy under the rule against one without it. Release, Ryzen 7 9800X3D, at72b3a244: a small range that is current 16 ns (16 without the rule), 1,024 current pages 1,462 ns (1,457), a small range taken again with nothing changed 55 ns (61). Before72b3a244the cover was looked at for every page, current or not: 24 ns and 8,950 ns for the first two.Update (01 Dec): rebased onto main
5fabb46e, and72b3a244looks at the cover only for pages a refresh takes (IRennie74's review). On72b3a244:cargo test --release -p victory-gpu --lib -- keep_left clobber --include-ignoredpasses (the four tests above, the benchmark,clobber::tests).cargo test -p victory-gpu --lib: 1,106 passed, 0 failed, 67 ignored.cargo clippy -p victory-gpu --all-targets -- -D warnings: 5 errors, all inhost/font.rs,host/menu.rsandhost/panel.rsfrom main's F1/F3 panel merge (#4634), none from this PR.What was run before that (RTX 5080, Windows 11, on
84bd61e2):cargo test -p victory-gpu --lib: all pass exceptlist::thin::tests::bindings_record_no_workandshader_cache::tests::every_switch_of_the_translator_is_in_the_key. Both fail the same way without this change.cargo clippy -p victory-gpu --all-targets [--all-features] -- -D warnings: nothing from this change. What is left fails on84bd61e2too:Shadow::rangednever used,seed % 3in a host test,copystat::mbwith all features.cargo xtask policy: only the existingvictory-shader/src/native.rsfinding.VICTORY_WC_KEEP_LEFT=0against the default, ray tracing off) is queued on our bench. It can count how often the old behaviour sends title bytes over shader writes left on the card. It cannot show the night white-out.Not changed here: copies found by address (
by_address, the structure arenas,changes_only). A partial-page re-take withknown == falsegoes up whole there too.Written with AI assistance (Claude Code, Claude Opus 5.5). No game data.
🤖 Generated with Claude Code
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Lyrnc on 2026-11-30T19:04:42Z.
Overlap note: #4294 adds an early return to
copy_stalewhen every page is already taken and nothing was written. If both land, that early return should also note the range in the copy'sCoverfor copies withleftset (cover.entry(page).or_default(), then.written(write)and.took(a, b)per page, as the walk does). Otherwise a range only ever answered by that early return is not in the cover, and its first re-take after its slots are reused goes up whole, as before this change. Both edit the same lines aroundlet last, so git will probably also report a conflict there. (AI-assisted: Claude Code)Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by paales on 2026-11-30T20:52:01Z.
Written by 🤖:
In-game numbers, tested together with #2504 in one build, so the two are not told apart. PC: RTX 5070 Ti 16 GB, Ryzen 9 5900X, 32 GB, Windows 11. Series X, 1440p, DLSS Performance, frame generation off, 30 fps cap. Each run: a new game (settings save, no story save), one A press, the first cutscene for 60 s from its first frame. On this PC the same build's submitting thread took 24 ms a frame in one run and 35 ms in another half an hour later, so only large differences count.
Base:
main84bd61e2with #3918, #1727, #3553, #3043, #4206 (VICTORY_FILL_AHEAD=1), #4138 and #720 (VICTORY_HEAP_WORKER=1). One run each, back to back:I could not measure a gain. One run is not enough to call it a loss on this PC either.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by IRennie74 on 2026-11-30T22:38:11Z.
A cost concern for PCs where the submitting thread is the limit.
VICTORY_WC_KEEP_LEFTis read withtoggled!, so it is on by default, and the launcher'sVICTORY_WC_NO_BACK=1makes most large copiesleft. For those,copy_stalenow holds the cover lock for the whole refresh (shadow.rs:7711) and, for every page in the range, does aBTreeMap::entryplusCover::written/holds/took(7734-7741), including pages that are current and will not be taken;tookscans and rebuilds up to 64 ranges each time. That is work on every refresh, not only on the re-takes it fixes.On a Ryzen 5 5600X with an RTX 3060 our submitting thread is busy 44-54 ms of a 55-58 ms frame, of which refreshes are 11-15 ms, so a few ms there shows directly in the frame. paales' run above (refreshes 12.9 -> 19.4 ms, together with #2504) is confounded but points the same way. Two options:
taken == 0 || write > taken), noting current pages' ranges lazily, at the cost of a little more re-take;asked_for!until it has been measured on a CPU-bound PC.On whether it fixes what it targets: #4376 adds
VICTORY_FLICKER_DETECT=1, which counts A-B-A flicker events a minute at every present (about 59 a minute walking on our combined build). A value that jumps back to its first state and adapts again should show there, soVICTORY_WC_KEEP_LEFT=0against the default with it on gives a number even without the night white-out. We can run that pair on the 3060.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by paales on 2026-11-30T22:42:50Z.
Written by 🤖:
Right, my run measured #2504 and #4340 together (refreshes 12.9 against 19.4 ms a frame, the submitting thread 35.4 against 42.5 ms, RTX 5070 Ti with a Ryzen 9 5900X). I did not measure #4340 alone, so I cannot say which of the two cost what.
asked_for!until a CPU-bound run measures it alone seems the safe default to me.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Lyrnc on 2026-12-01T03:49:29Z.
Bench result: the daytime walk A/B from "What was run", this morning. RTX 5080 16 GB, Ryzen 7 9800X3D, 32 GB RAM, Windows 11. Release build of this PR at
837b45e4, one shared shader cache (warmed first). Series X, 1440p, DLSS Quality, frame generation off, ray tracing off. Same save, a 5-minute scripted walk, 420 s runs,VICTORY_CLOBBER_WATCH=1in both. old =VICTORY_WC_KEEP_LEFT=0, keep = default.No device removed, DRED or "did not close" line in either run. No white-out, as expected in daytime.
What this shows
What it does not show
VICTORY_WC_NO_BACK=0to see whether the watch's counts and the jumps go away with it.VICTORY_UNIFIED_BACK.AI use: Claude Code (Claude Opus 5.5) ran these on our bench queue, parsed the run logs with its own scripts, and wrote this comment.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Lyrnc on 2026-12-01T04:11:39Z.
Thanks @IRennie74, your reading was right, and thanks @paales for the run. On the previous head, every page of every refresh of a copy under the rule went through the cover: the lock, a
BTreeMap::entry,written,holdsandtook, also for pages that were current and would not be taken.Fixed in
72b3a244(your first option): the cover is looked at, and locked, only for pages that are taken (again),taken == 0 || write > taken. Nothing else changes:writeis the page's last write, so the cover learns of title writes in time at the page's next take.keep_left_testspass unchanged.Cost, before and after. A new benchmark,
shadow::keep_left_tests::copy_stale_cost_of_the_cover(#[ignore = "benchmark"]), timescopy_stalefor a copy under the rule against one without it. Release build, Ryzen 7 9800X3D, nanoseconds a refresh:72b3a244So the per-page cost for pages that are current is gone. The take path costs what it did: a lookup on top of a copy or compare of the range. This is a warm-cache best case. In game the map lookups could miss the cache, so the old cost per page was probably higher than 7 ns. That makes the change matter more, not less.
What our bench saw in game (B1's comment above, daytime walk, RTX 5080): the new path fired 11 times in 6 minutes (40 KB compared, 0 sent). The clobber watch counted about 1,300 refreshes a second that sent title bytes over shader writes on pages the title had also written. That is the case
VICTORY_WC_NO_BACK=1accepts on purpose, and this PR doesn't change it. So if the night white-out is that class, the fix is beyond this PR: it's the NO_BACK trade-off, andVICTORY_WC_NO_BACK=0is the test.Default: with the cost on current pages gone, I've left
VICTORY_WC_KEEP_LEFTon. Your A/B (VICTORY_WC_KEEP_LEFT=0against the default withVICTORY_FLICKER_DETECT=1) works as you proposed. Yes please, on the 3060. A third arm withVICTORY_WC_NO_BACK=0would show whether the A-B-A count comes from the NO_BACK class.@paales: your combined run can't separate #2504 from this. With the cover now off the walk over current pages, a run of this PR alone would show whether any of the 6.5 ms of refreshes was it.
Also rebased onto current main. Main's history was rewritten after
0c8c2092, so the PR showed as conflicting. Since the cover is now noted only at takes, #4294's early return no longer needs to touch it. My overlap note above no longer applies; only the textual conflict nearlet lastremains.Checks on
72b3a244(Windows 11, rustc 1.98.1):cargo test --release -p victory-gpu --lib -- keep_left clobber --include-ignoredpasses the fourkeep_left_tests, the benchmark and the sevenclobber::tests.cargo test -p victory-gpu --lib: 1,106 passed, 0 failed, 67 ignored.cargo clippy -p victory-gpu --all-targets -- -D warnings: 5 errors, all inhost/font.rs,host/menu.rsandhost/panel.rsfrom main's F1/F3 panel merge (#4634), none from this PR.AI use: Claude Code (Claude Opus 5.5) made the change, wrote and ran the benchmark and tests, and wrote this.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by albertik322-sudo on 2026-12-01T17:00:21Z.
Positive on a laptop, in the same batch (with #4294, #4493, #4876, #4206). PC: RTX 3070 Laptop 8 GB, i7-11800H, 32 GB RAM, Windows 11. Series S, 1080p output, DLSS Performance, FG x4.
Combined effect of the batch: fixed cost per frame (linear fit of ms vs draws over ~5 min standing still) dropped 47 ms to 25.5 ms, fps median 15.9 to 17.4, copy-back line ~13-18 ms with no growth in copied-back bytes. No missing or wrong surfaces observed in hours of play — the clobber watch catches nothing here.
Laptop note: the related zero-copy-through-BAR experiment (
VICTORY_WC_BAR=1) is a catastrophe on this machine specifically — 1.4 fps, copy-back 700-1300 ms, PCIe writes page by page. MSI GP66 Leopard; the BAR is resizable and the writes are just slow. Keep whatever stays-on-card logic off that path on laptops.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-12-01T18:42:25Z.
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