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) #1295
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/fxceless--victory-fork!1295
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@KainanP on GitHub · 2026-11-26 12:07 UTC · original
KainanP:perf/merge-page-mask→main· +1203 −16 · 4 files · 1 commits · openWhat 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
@HLVM04 on GitHub · 2026-11-26 14:06 UTC · original · edited 2026-11-26 17:26 UTC
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.@CuteBooty on GitHub · 2026-11-26 16:00 UTC · original
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.
55c9076f2atod404dda6d1@KainanP on GitHub · 2026-11-26 17:15 UTC · original
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).
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.