GPU: bound shadow buffer lookup by maximum registered size instead of 64 entries #2096
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2096
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2096"
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?
@fuzeofficlal on GitHub · 2026-11-25 04:49 UTC · original
fuzeofficlal:fix/gpu-shadow-overflow-and-find-906→main· +143 −21 · 1 files · 1 commits · openRefs #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.@Marvisak on GitHub · 2026-11-25 10:36 UTC · original · edited 2026-11-25 11:23 UTC
Automated triage for the maintainers.
Merge candidate.
shadow::findnow scans backwards only fromend - max_size(find_buffer), whereBufferstracks the largest registered length and recomputes it when the largest entry is removed or replaced; a buffer that covers[address, end)must start at or after that bound, so lookups still reach an outer buffer past many smaller ones while misses reachingloose()stop early. The overflow guards and the equal-start tie-breaker are gone. #402 overlaps but currently has merge conflicts; this one merges cleanly. CI passes.On your reply: confirmed in
2f43424, this is what was asked. A minor follow-up, not a blocker:Buffers::removerescans the whole map each time an entry of the maximum size goes, which is O(n) per release if many buffers share that size; a size-count map would make it O(log n).Generated by Claude Code
@fuzeofficlal on GitHub · 2026-11-25 10:51 UTC · original
Updated in
2f434243per triage feedback:find_bufferby the maximum currently registered buffer size (lowest = end.saturating_sub(max_size)over(lowest, 0)..=(address, usize::MAX)), tighteningmax_sizeonunregisterwhen the largest buffer is removed so misses stop early instead of walking the map.u64::MAXoverflow/saturating guards and the equal-start tie-breaker.@DenRakEiw on GitHub · 2026-11-25 04:56 UTC · original · approved these changes
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 on GitHub · 2026-11-25 05:02 UTC · original · reviewed
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.
@Desamodeth on GitHub · 2026-11-26 21:10 UTC · original · reviewed
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:
63bcca43The 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.
@ -790,0 +828,4 @@.max().unwrap_or(0);}}@Desamodeth on GitHub · 2026-11-26 21:10 UTC · original
Keep the bound exact on replacement and removal. This is the size-count variant measured above.
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.