Card copies: pages with many changed runs go up as the page and a byte mask, one compute pass instead of a copy a run (VICTORY_MERGE_MASK, off) #1292
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1295"
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 fxceless/victory-fork. Originally posted by KainanP on 2026-11-26T12:07:09Z.
What it changes
Off by default. Without
VICTORY_MERGE_MASK, the copies are recorded exactly as before.Under flights' shader writes,
Shadow::merge_under_writesputs the title's bytes into a copy in the card's memory run by run. InHost::card_before, each run became its ownCopyBufferRegion. WithVICTORY_CARD_REHASH_RUNSunset (the default), each run also got its own hash pass over its 64 KiB piece. A page that the title rewrites with a few bytes changed here and there has thousands of runs: up to about 16,000 in @MKmajster's profile in #1083. That page goes over theVICTORY_MERGE_RUNSbudget (512 by default), and the flights are settled instead. #1083 measured 1.3–1.5 such settles a frame, 27–35 ms of the submitting thread on an RTX 3070. Raising the cap made that frame slower (199 ms against 162–173 ms): more copies, the same settles.With
VICTORY_MERGE_MASK=1(or=<n>for another threshold, oraltto switch on and off every 20 s):card_before, the ranges of such a page become one row of a small compute pass (card_mask::CARD_MASK), with one thread per dword. Each thread reads the copy's CPU side, where the copies would have copied from, and writes only the bytes its mask names. It keeps the other bytes of the card side, which may be a flight's writes. A partly masked dword is read and written back on the card. The pass runs on the queue behind every flight and ahead of the submission's lists, as the copies do, so no other writer races it.dirtyandsent, so the relay's merge skips exactly the same bytes as before. A page with 16 ranges or fewer is still copied range by range.VICTORY_QUEUE2uploads, whose bytes land packed. It is also not used for a copy whose start or size is not 4-aligned, or when the 1 MiB+ upload buffer for the masks cannot be made. In each of these cases the old path runs.Shadow::card_put_title. A masked page is copied into the CPU side whole, which is exact because outside its runs the bytes are already equal, and its runs are noted under one lock.Synthetic benchmark (
card_mask::gpu::mask_bench,#[ignore])Method.
shadow::register, with shader writes declared once so the card keeps its piece hashes, as for a copy under flights.card_put_titleper page. This is the merge's part, minus reading title memory, which is the same for both paths.Host::card_beforewith no lists.Instant.maine4245f3(after the rebase); the earlier numbers were onceb9e1f. Single cells moved by up to about 25 %; no conclusion changed.Hardware. RTX 4060 Laptop (driver 32.0.16.1047), Intel UHD Graphics 8086:a78b (31.0.101.5445, selected with a local adapter hook that is not part of this PR), WARP (
--features diagnostics,VICTORY_D3D12_WARP=1). Release build.Default settings (
VICTORY_CARD_REHASH_RUNSunset). The cells give the submitting thread / the card, in µs per page:With
VICTORY_CARD_REHASH_RUNS=1(hash passes joined), the copies' card time is much lower. The submitting thread still pays for each copy:With
VICTORY_CARD_HASH_WIDE=1(e4245f3's group-a-piece hash, which itsaltmeasured at -10 ms of card a frame),VICTORY_CARD_REHASH_RUNSunset. Every hash pass is cheaper, so the copies' card time drops too. The submitting thread is unchanged:Crossover:
VICTORY_CARD_REHASH_RUNS=1), the copies stay cheaper at 16 runs and below (47 vs 87 µs at 16; with the wide hash too, 35 vs 63 µs).VICTORY_MERGE_MASK=<n>changes it.Full tables, including 2 and 4 runs, are in the test output:
cargo test --release -p victory-gpu --lib card_mask::gpu::mask_bench -- --ignored --nocapture, withMASK_BENCH_RUNS,MASK_BENCH_PAGESandMASK_BENCH_ROUNDSto vary it.Correctness
card_mask::gpu::masked_pages_leave_the_bytes_the_copies_would(#[ignore], GPU). Runs 48 random cases on one copy. Each case:card_before.Thresholds 1, 16, 300 and off alternate, so both paths run on the same copy.
Results. Passes on the RTX 4060, the Intel UHD and WARP, with
VICTORY_CARD_SYNC_BATCH0 and 1 (re-run one4245f3: 48 cases, 193 masked pages each).Mutation checks. A shader that writes whole dwords fails at case 0. Leaving the masked page out of the rehash also fails.
CPU tests.
card_mask::testscompares the split and the mask apply with plain copies for 400 random cases, including title buffers that start off a block edge and short copies.Existing test.
host::tests::two_dirty_card_buffers_reach_readback_in_the_same_submissionpasses with the mask off and on, in both sync modes.Suite.
cargo test -p victory-gpu(one4245f3): 224 passed on RTX and on Intel.--features diagnostics --test-threads=1, release: 240 passed; 3profile::testsfail (deep_stacks_are_cut_not_lost,the_sampler_finds_threads_and_writes_its_files,time_goes_to_the_function_that_spent_it). The same three fail on unmodifiedmaine4245f3in the same build, and this PR does not touchprofile.maintoo (5 of 8 runs here), with the same tests in flight.cargo clippy -p victory-gpu --all-targets [--all-features] -- -D warnings: clean.card_mask.rspassesrustfmt --check, and the lines changed inhost.rsandshadow.rsadd no new rustfmt differences.What is not measured
dirty, and with the relay insent. Neither the frame nor the relay thread's merge (card_merge_relayscans those lists) is measured.VICTORY_QUEUE2(excluded).Request for an A/B
@MKmajster, @CuteBooty: you have the scenes from #1083. Could you run your opening scene with
VICTORY_MERGE_MASK=alt? It switches on and off every 20 s and logs each change. Please compare the frame log's "merge gave up … for more changed runs than VICTORY_MERGE_RUNS leaves" count, the settles, and the frame time between the on and off halves. The new line "card copies' pages that went up with a mask per frame" shows how many pages took the path. A row withVICTORY_MERGE_MASK=64would also help place the threshold.AI use: written with Claude Code (Claude Opus 5.5). It read the code paths, wrote the change and tests, and ran the benchmarks and test suites on the hardware above. No game data was used.
🤖 Generated with Claude Code
Imported from fxceless/victory-fork. Originally posted by HLVM04 on 2026-11-26T14:06:50Z.
In-game numbers for
VICTORY_MERGE_MASK=1. They come from separate runs, not analtrun. Setup: RTX 5070 Ti, Ryzen 7 9800X3D, Windows 11, Series S profile. The tree is fork main0b0074eplus several open PRs and local changes, with this PR merged on top. Each figure is the in-world steady frame time after 135 s.MERGE_DEFER, which holds over-budget merges until the next submission)VICTORY_MERGE_MASK=1MERGE_DEFERoff, no maskMERGE_DEFERoff +VICTORY_MERGE_MASK=1With the mask, preparing rises from about 34 to about 50 ms a frame. Earlier on this tree, the run cap was hit by about 60,000 runs of 3 bytes a frame. Deferring those merges removed the "changed under shader writes" settles here (101 → 91 ms median at the time), and raising
VICTORY_MERGE_RUNSto 65536 was slower (119 ms).Limits: our card is not the bottleneck (CPU-bound), there are only 1–3 runs per setting, and we didn't split the extra preparing time between the mask's recording and its per-page hash.
Edit (2026-11-26), correction on our base: the local
MERGE_DEFERin the base row made draws read stale bytes (over-budget title changes under shader-written ranges landed a submission late; with ray tracing on, the main character's skin draw lost its geometry), so that row is not a correct baseline and the deferral shouldn't be copied. Our replacement merges every run at once and joins nearby runs (gap of 64 bytes); it is as fast on our stack (in-world ~45–46 ms) and correct with ray tracing on. Exact merging without the gap was ~300 ms a frame. The mask figures above were not re-measured against it.Imported from fxceless/victory-fork. Originally posted by CuteBooty on 2026-11-26T16:00:39Z.
RTX 3070 8 GB: raising the run cap cut the settles by three quarters and did not clearly change the frame
Not a test of this PR: my tree does not have it. A data point on whether the run cap is where the time goes, next to HLVM04's numbers. Same exe, Series S, Ryzen 5 3600, town; the only change is my cap on merged runs raised to 4096:
On this machine every settle "for title memory changed under shader writes" was a run-cap settle, so the cap is the right thing to count, but removing most of them moved the frame by less than run-to-run noise in either direction. Limits: one short run each (3 to 12 five-second samples per band), and the machine was not quiet during the second.
My rule stays: I would port this only if a longer run shows the run cap costing more than a few ms here.
Imported from fxceless/victory-fork. Originally posted by KainanP on 2026-11-26T17:15:53Z.
Rebased on
maine4245f3(nowd404dda).Conflict.
host.rsonly:e4245f3addedHost::make_card_compare_wideat the same place as this PR'sHost::make_card_mask. Both functions are kept as they were; nothing else changed.e4245f3's changes and the mask. The mask does not pick the hash form: the masked page's piece is rehashed with whatever compare the submission uses (
compare_pso, includingVICTORY_CARD_HASH_WIDE=alt).VICTORY_DIRTY_4Knarrows only the CPU refresh of write-watched pages (copy_stale). The changed runscard_beforesends up still come from the byte compare, so the runs per 64 KiB page, the page size and the threshold of 16 stay as they were.Tests on
e4245f3. The GPU test (48 random cases) passes on RTX 4060, Intel UHD and WARP, withVICTORY_CARD_SYNC_BATCH0 and 1.cargo test -p victory-gpu: 224 passed on RTX and on Intel. On WARP (diagnostics, serial), 3profile::testsfail, and the same 3 fail on unmodifiede4245f3. clippy-D warningsis clean with and without--all-features.mask_bench re-run (median of 15 rounds, 9 on WARP). The tables in the description are updated, and there is a new one with
VICTORY_CARD_HASH_WIDE=1. At 16,384 runs a page, copy a run → mask, submitting thread / card, µs:The wide hash cuts the copies' card time, but each run still costs a copy on the submitting thread, so the gain on that thread is the same as before.
Note for whoever merges: #1298 adds the same test-only helper
Host::card_sync_timed. Whichever of the two lands second should drop its copy.AI use: Claude Code (Claude Opus 5.5).
Imported from fxceless/victory-fork. Originally posted by Filip722 on 2026-11-26T20:17:23Z.
Same-process Series S prison checkpoint comparison on the RTX 5060 Laptop 8 GB, Intel Core 7 240H, Bazzite 44, NVIDIA 615.78.08, GE-Proton11-14 and vkd3d-proton 3.2.0. Base was
52ac4ecwith #257 and the local Proton compatibility stack. Both arms used the same executable and warm caches. I measured three settled 18-second windows each with VICTORY_MERGE_MASK=alt.For this build I routed the mask's HLSL through the existing DXC fallback from #20 so the runtime shader used the same compiler path as the other Proton helpers.
Assisted by Codex (GPT-6.2-Sol High).
Imported from fxceless/victory-fork. Originally posted by KainanP on 2026-11-27T10:44:39Z.
@Filip722, thank you for the same-process A/B. It answers the question this PR was waiting on.
What it shows. The mask did what it was built for: a median 35.9 masked pages a frame, and the run-cap fallbacks went from a median 5 per sample to 0 in all 46 enabled samples. The frame didn't follow, though. 4.516 FPS enabled vs 4.587 disabled is no gain, and if anything slightly worse. On that machine the submitting thread was either not limited by those settles, or the mask's dispatch and its extra barriers cost about what the settles did. CuteBooty's RTX 3070 result above points the same way: removing most run-cap settles moved the frame by less than noise.
One question. Host copy-back medians were 132.0 ms with the mask and 109.4 ms without. Does that difference hold up across the three windows, or swap between them? With
altthe mode flips every 20 s, so enabled and disabled phases can land on different parts of the checkpoint. I don't see a mechanism in the mask for a bigger copy-back. It doesn't change which pieces are compared or fetched, only how the changed bytes go up. So if it's reproducible, I'd like to understand it before anything else.DXC routing (#20). Thanks for routing the mask's HLSL through #20's fallback.
make_card_maskcallsD3DCompiledirectly, like the other run-time helpers, so it won't build under Proton without that. #20 is still open. Do you want the mask routed throughdxc::compilehere once #20 lands, or should I fold the change in now on top of #20's branch?Rebased on
main9a9091d(now609d6be).maingainedVICTORY_MASKED_PATCH(on by default) andVICTORY_PATCH_LEANin the meantime. Both patch busy pages on the card with byte masks, so most of what this PR did for the run cap is now onmainby default. In the merge, a page the mask takes (cost 1, within whatVICTORY_MERGE_RUNSleaves) goes up with the mask. Every other page goes exactly as onmain: a run each, or a masked patch past the cap or when lean. Patches are still recorded before the copies and the mask.Flight::cardis now boxed, because the plan's mask buffer pushedLate::Runover clippy'slarge_enum_variant. Your base (52ac4ec) predatesVICTORY_MASKED_PATCH, so your numbers compare the mask with settles, not withmain's patch.Tests on
609d6be(RTX 4060 Laptop, Intel UHD, WARP):masked_pages_leave_the_bytes_the_copies_would: 48 random cases, 193 masked pages, every byte checked against a copy a run) passes on RTX, Intel UHD and WARP, withVICTORY_CARD_SYNC_BATCH0 and 1. On the first run after the rebase it failed on every adapter, but only on the piece-hash check; the bytes were right. The cause:mainmadeCARD_COMPARE_WIDE(a group a piece) the default in0a40a00, and the test's CPU hash reference was still the thread-a-piece form. The reference now followscard_hash_wide().cargo test -p victory-gpu --lib: 244 passed on RTX in 3 of 4 runs and on Intel UHD in 4 of 5 runs. The other RTX run had one failure ininplace::tests::warp_a_title_buffer_in_place_shows_its_bytes_at_its_offset(itsVirtualFreedecommit returned 0), and the other Intel run exited silently after 93 tests with no panic. This PR touches neither area, and both passed on rerun.profile::testsfail that failed on unmodifiedmaine4245f3last time (I did not rerunmain9a9091don WARP). With those skipped, 255 passed.-D warningsis clean with and without--all-features(mainis clean too).It stays off by default (
VICTORY_MERGE_MASKunset). Given this result andmain's own masked patch, I'm fine with closing it if you prefer, @fxceless. It would only be worth keeping if a measurement shows it beatingVICTORY_PATCH_LEANon pages under the cap.AI use: Claude Code (Claude Opus 5.5).
Imported from fxceless/victory-fork. Originally posted by KainanP on 2026-11-27T15:35:29Z.
Closing this:
main5dbf5ce(the VIctory-NVIDIA tree) covers the same problem in its own way, and it is on by default.VICTORY_UNDER_WORDS: bytes the title changed under flights' writes go up as whole words. These are offset/value pairs that oneSCATTERdispatch stores per copy, not aCopyBufferRegionper run.merge_page_under_writes, only runs that are still copies of their own count against the run cap (512, or 4,096 with card steps). A page with thousands of word-sized runs therefore no longer runs out of the budget and settles the flights. That is what the mask was for: it took the per-run cost off the submitting thread, and it made a busy page cost the budget one run.The pass also reads the submission's own snapshot of the bytes (
send::Own), not the CPU side ascard_maskdid, so a port of this PR would also be a step back on ordering. Thank you @Filip722, @HLVM04 and @CuteBooty for the measurements.AI use: Claude Code (Claude Opus 5.5).
Pull request closed