GPU: reuse the matched entry when finding a shadow buffer #3503
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!3503
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3503"
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?
@Venom2054 on GitHub · 2026-11-27 10:59 UTC · original
Venom2054:gpu/one-shadow-range-search→main· +3 −5 · 1 files · 1 commits · openshadow::findsearches the locked buffer registry backwards for the first range that covers the requested bytes. It then looks up the same key again to access its entry. This change uses the mutable entry returned by the first search. The ordering, 64-entry search limit, lock scope, loose-buffer fallback and lazy allocation are unchanged.Measurements. A synthetic CPU comparison over 16,384 registered ranges and 262,144 queries took a median of 116.2 ns per query with the second lookup and 71.7 ns with a single lookup. Separate checks covered 4,053 queries across overlaps, replacement and removal.
In a separate instrumented local renderer, one in 256 actual lookups ran both implementations under the same lock, alternating which ran first. Across 468,270 sampled lookups they agreed on every hit, miss, entry and extent. The two measured scene intervals went from 228.63 to 108.81 ns per lookup and from 234.87 to 108.36 ns per lookup. These measure the CPU registry search. The scene runs differed in texture streaming, so there is no matched whole-frame FPS claim.
Verification on Windows, based on
63bcca4. All 10victory-gpushadow tests passed. GPU crate Clippy (--all-targets --all-features --locked -- -D warnings) andcargo xtask policypassed. The full GPU library suite reported 229 passed, two failed, one ignored on both this revision and the clean base on this machine. The two failures weredescriptor::host::tests::dynamic_slots_are_held_until_releasedandmemory::tests::lists_share_a_table_and_copies_keep_their_views.The production diff is confined to the lookup in
crates/victory-gpu/src/shadow.rs. Implementation and testing were assisted by Codex.@oni-swr on GitHub · 2026-11-27 11:35 UTC · original
Independent WARP/CPU verification (no physical GPU), Windows 11 build 26200, Rust 1.98.1 debug build,
cargo test -p victory-gpu --lib --locked,VICTORY_WARP=1andVICTORY_D3D12_WARP=1, system WARP 10.0.26100.9818, dxil.dll 10.0.19041.5609 on PATH.Commits: base
63bcca4(main), head4e16f01a.Diff read (
crates/victory-gpu/src/shadow.rs:1012-1024, +3/-5):buffers()guardmapis taken before the search and held until the function returns. In the miss branch,drop(map)runs beforeloose(), as before.range_mut(..=(address, usize::MAX)).rev().take(64).find(|(_, e)| e.end >= end)yields the key and&mut Entryof the same element. The old code copied the key out and calledget_mut(&key), which returns that same element, because the lock is held across both steps.key.0is still the start used forlen, the buffer name andShadow::new.(start, resource)).register(inserton the same key replaces the entry) andunregister(remove) are untouched and run under the same mutex, sofindnever sees a stale entry. The oldget_mut(&key)?failure path (Noneon a missing key) cannot occur and is gone.entry.shadow.is_none()and thehost()?early return behave as before. The guard drops on return, and the entry is left unset on failure, as before.Tests,
cargo test -p victory-gpu --lib:63bcca44e16f01aThe 11 tests matching
shadowalso pass on head. The PR's two failures (descriptor::host::tests::dynamic_slots_are_held_until_released,memory::tests::lists_share_a_table_and_copies_keep_their_views) did not reproduce here on either side.Findings: no blockers. One observation: no test calls
finddirectly on overlapping, replaced or removed ranges. The lookup is covered only through the callers' tests, so the PR's 4,053-query check is not in the tree. I did not run clippy orcargo xtask policy, and I did not check the performance numbers, since they need a different setup.AI-assisted (Claude Code / Claude Sonnet 5.5).
@AurumCarlos on GitHub · 2026-11-27 11:50 UTC · original · approved these changes
LGTM.
range_mut(..).rev().take(64).find(..)yields the key and the entry of the element the oldget_mut(&key)looked up again under the same lock, so hits, misses, the 64-entry cap and theloosefallback are unchanged.key.0is still the start used for the length, the name andShadow::new. CI is green, and oni-swr's fullvictory-gpurun matchesmain.One thing for landing order: #2096 (fuzeofficlal, merge candidate) rewrites these same lines. It drops
take(64)for amax_sizebound in a newfind_buffer, but keeps the secondget_mut(&key), so whichever lands second conflicts. If #2096 goes first, the same saving carries over by returning the entry fromfind_buffer(a sketch, not compiled against #2096):with, in
find:github-bot referenced this pull request2026-11-27 14:20:15 +00:00
@futurepro62 on GitHub · 2026-11-27 19:23 UTC · original
NVIDIA full-suite run, to go with the reports above by oni-swr, since none of them names a GPU run. Tested exact head
4e16f01(on its base63bcca4).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 866 passed, 0 failed, 10 ignored.#[test]functions in the diff.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#2571), so without the skip the rest of that crate never reports;dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
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.