Repository navigation
GPU: bound shadow buffer lookup by maximum registered size instead of 64 entries - #2096
fuzeofficlal wants to merge 1 commit into
Conversation
DenRakEiw
left a comment
There was a problem hiding this comment.
Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):
cargo test -p victory-gpu --lib shadow::— 6 passed, 0 failed (includingoverflowing_ranges_are_rejected_without_panicandfind_scans_past_sixty_four_siblings_and_picks_tightest_equal_start)cargo clippy -p victory-gpu --all-targets— 0 warningscargo xtask policy— ok (183 files ok)
Clean overflow guards on shadow range arithmetic and complete sibling scan in find(). Looks good.
AI-assisted (Gemini 4 Neon).
catminou4
left a comment
There was a problem hiding this comment.
Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.
Shadow range arithmetic overflow-guarded + scan — memory-safety hardening on the shadow-memory path.
|
Automated triage for the maintainers. Merge candidate. On your reply: confirmed in Generated by Claude Code |
8b120e2 to
2f43424
Compare
|
Updated in
|
Desamodeth
left a comment
There was a problem hiding this comment.
The full rescan mentioned in triage is visible in both removal and in-place replacement on 2f434243. With 4,096 equal 4 KiB buffers, removing them one by one visits 8,386,560 remaining entries under the registry mutex. Shrinking all 4,096 at the same keys visits 16,777,216 entries.
CPU time per batch of 4,096 mutations, across two opposite-order runs:
| Workload | main 63bcca43 |
This PR | Suggested size counts |
|---|---|---|---|
| Remove equal 4 KiB registrations | 0.13–0.15 ms | 6.48–6.64 ms | 0.13–0.15 ms |
| Replace each 4 KiB registration with 2 KiB | 0.09–0.10 ms | 13.01–13.21 ms | 0.105–0.106 ms |
| Remove 4,096 distinct sizes, largest first | 0.14–0.15 ms | 6.49–6.53 ms | 0.40–0.42 ms |
The suggestion keeps the PR's exact lookup bound and stores one count per distinct length. The extra live heap requested by the index was 192 B for one length, 2,016 B for 64 lengths and 139,968 B for 4,096 lengths. Registering the all-distinct batch also took 0.34–0.36 ms vs 0.16–0.21 ms here. I tested a single counter for ties too. It fixed the equal-size case, but largest-first removal still took 9.27–9.30 ms.
Isolated Windows x64 registry benchmark, Ryzen 7 9800X3D, rustc 1.98.1 release, production mutex and map operations. Each sample started empty, registered disjoint buffers and performed one hit per buffer before timing mutations. Eleven timed samples per case in each run. Separate allocation-counting binary. Checked exact maxima after 6,000 mixed mutations and 18,000 lookups against an exhaustive reference, including shared start addresses and replacements. The covering buffer beyond 64 siblings is still found. The suggestion applies to this head and to this PR applied over current main. Full crate, D3D12 and in-game frequency were outside this CPU measurement. AI-assisted with Codex.
… 64 entries Replace the fixed .take(64) cap in shadow::find with a scan bounded by the maximum buffer size currently registered in BUFFERS: - Track live registration counts per buffer size in Buffers::sizes (BTreeMap<u64, usize>), maintaining max_size() in O(log n) across inserts, in-place size replacements, and removals without rescanning the full map under the BUFFERS mutex. - Bound the reverse scan in find_buffer using max_size(), allowing lookups to reach a covering outer buffer past more than 64 smaller inner buffers while stopping misses immediately outside max_size(). - Add unit tests covering lookup past 128 inner buffers, max_size() bounding and tightening on unregister, multiple equal max-size buffers, in-place replacements, and descending removals to empty. Refs Marvisak#906.
|
@Desamodeth Thanks for benchmarking those equal-size and descending-removal workloads — the 16x–125x slowdown under the I rebased onto current Added |
2f43424 to
9110467
Compare
Refs #906.
Summary
.take(64)cap inshadow::find(crates/victory-gpu/src/shadow.rs) with a reverse scan bounded by the maximum buffer size currently registered inBUFFERS(lowest = end.saturating_sub(max_size), returningNoneimmediately whenlowest > address).max_sizeonBuffers::insertand recompute it onBuffers::removewhen the previous maximum-size entry is unregistered, so misses reachingloose()stop at the live maximum buffer bound while lookups still reach a covering outer buffer past more than 64 smaller inner buffers.Verification
shadow::tests::find_reaches_covering_buffer_past_many_inner_buffersshadow::tests::find_stops_at_max_size_bound_and_tightens_on_unregistercargo clippy -p victory-gpu --tests --locked -- -D warningsandcargo xtask policy: passed.