Repository navigation
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
Conversation
|
In-game numbers for
With 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 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 |
|
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. |
…e mask, one compute pass instead of a copy a run (VICTORY_MERGE_MASK, off) Under flights' shader writes the title's bytes go into a copy in the card's memory run by run (Shadow::merge_under_writes), and each run was a CopyBufferRegion of its own in the sync list plus a hash pass of its own. A page with thousands of runs (up to about 16,000 in fork issue fxceless#1083) exceeds the merge budget (VICTORY_MERGE_RUNS) and the flights are settled instead. - VICTORY_MERGE_MASK=1 (threshold 16), =<n> (threshold n) or alt: a 64 KiB page with more changed ranges than the threshold costs the merge budget one run; in Host::card_before its ranges become one row of a compute pass (card_mask::CARD_MASK) that writes the masked bytes from the CPU side and keeps every other byte of the card side, and the page's piece is hashed once. Byte-exact: the card side ends as the copies leave it. Ranges are still noted one by one (the relay's merge skips them). Not with VICTORY_QUEUE2 uploads. - The merge's card branch is Shadow::card_put_title; a masked page is copied into the CPU side whole and its runs noted under one lock. - Frame log line with the masked pages per frame. - Tests: CPU reference of split + mask apply over random patterns; GPU test (ignored) comparing the card side and its piece hashes against a copy a run for random patterns, both paths on one copy; mask_bench (ignored) timing the submitting thread and the card for 16,384 / 4,096 / 1,024 / 256 / 64 / 16 / 8 / 4 / 2 / 1 runs a page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
55c9076 to
d404dda
Compare
…ORY_CARD_REHASH_RUNS=0 as before, =1 touching pieces joined) With VICTORY_CARD_REHASH_RUNS unset, every range sent up to a copy in the card's memory had a hash pass of its own, so a 64 KiB piece holding 16,384 changed runs (fork issue fxceless#1083) was hashed 16,384 times: 14-15 ms of an RTX 4060 Laptop's time, 362 ms of an Intel UHD's (synthetic, card alone). - Unset (the new default): runs of pieces that share a piece are one pass (Rehash::Sharing), so each piece is hashed once: 0.43 / 36.5 ms for that page. - =1 keeps the touching join (Rehash::Touching). It is not the default because CARD_COMPARE gives a pass's pieces one thread each in a single group: 16 touching pieces with one range each took 179 us of the RTX's time as 16 passes and 266 us as one (Intel 1.15 / 1.23 ms). - =0 is the old pass a range; alt still alternates =1 and =0. - joined_piece_runs takes `touching`; the frame-rate line names the way. Tests: rehash_tests::joined_rehash_leaves_the_hashes_a_pass_a_range_does (GPU, ignored) runs 56 random cases on three copies, one per way, and checks the card bytes and every piece hash are identical across ways, equal to a CPU model of CARD_COMPARE for touched pieces and unchanged for the others (RTX, Intel UHD, WARP; also with VICTORY_CARD_HASH_WIDE=1). rehash_bench (ignored) prints the table. Host::card_sync_timed and Shadow::card_put_runs are test only (card_sync_timed is the same helper as in PR fxceless#1295). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Rebased on
Note for whoever merges: #1298 adds the same test-only helper AI use: Claude Code (Claude Opus 5.5). |
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 on ceb9e1f. 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 on e4245f3: 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(on e4245f3): 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 unmodifiedmaine4245f3 in 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