GPU: bound shadow buffer lookup by maximum registered size instead of 64 entries #2556

Merged
fuzeofficlal merged 1 commit from upstream-pr/2556 into main 2026-11-30 14:12:02 +00:00
fuzeofficlal commented 2026-11-29 14:18:31 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by fuzeofficlal on 2026-11-29T14:18:31Z.


Problem

BUFFERS reverse scans in crates/victory-gpu/src/shadow.rs (lookup, peek, peek_overlapping, extent, in_buffer, and in_place_let_go) stopped after a fixed .take(64) / .take(256) entry cap. When a title registers more than 64 smaller inner buffers inside a larger covering heap/buffer, lookups past those inner buffers missed the covering outer buffer and fell through to loose windows or returned None.

Fix

  • Wrap BUFFERS (RwLock<Buffers>) to track live registration counts per buffer size in sizes: BTreeMap<u64, usize>, keeping max_size() exact in O(log n) across inserts, in-place size replacements, and removals.
  • Replace the fixed .take(64) / .take(256) caps in lookup (both read and write paths), peek, peek_overlapping, extent, in_buffer, and in_place_let_go with a reverse range bounded by max_size() (lowest = end.saturating_sub(max_size)).
  • Switch read-only extent and near from write-locking buffers() to shared buffers_read().
  • Add shadow::buffer_lookup_tests covering lookup (find, extent, in_buffer, peek, peek_overlapping) past 128 inner buffers, max_size() bounding and tightening on unregister, equal-size counts, in-place replacements, and descending removals to empty.

Verification

  • cargo test --locked -p victory-gpu --lib shadow::buffer_lookup_tests -- --test-threads=1 — passed on RTX 5090 and WARP (VICTORY_D3D12_WARP=1).
  • cargo clippy --locked -p victory-gpu --tests — 0 new warnings in shadow.rs.
  • cargo run --quiet --locked -p xtask -- policy --staged — passed.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5551588215 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2556). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-29T14:18:31Z. --- ### Problem `BUFFERS` reverse scans in `crates/victory-gpu/src/shadow.rs` (`lookup`, `peek`, `peek_overlapping`, `extent`, `in_buffer`, and `in_place_let_go`) stopped after a fixed `.take(64)` / `.take(256)` entry cap. When a title registers more than 64 smaller inner buffers inside a larger covering heap/buffer, lookups past those inner buffers missed the covering outer buffer and fell through to loose windows or returned `None`. ### Fix - Wrap `BUFFERS` (`RwLock<Buffers>`) to track live registration counts per buffer size in `sizes: BTreeMap<u64, usize>`, keeping `max_size()` exact in O(log n) across inserts, in-place size replacements, and removals. - Replace the fixed `.take(64)` / `.take(256)` caps in `lookup` (both read and write paths), `peek`, `peek_overlapping`, `extent`, `in_buffer`, and `in_place_let_go` with a reverse range bounded by `max_size()` (`lowest = end.saturating_sub(max_size)`). - Switch read-only `extent` and `near` from write-locking `buffers()` to shared `buffers_read()`. - Add `shadow::buffer_lookup_tests` covering lookup (`find`, `extent`, `in_buffer`, `peek`, `peek_overlapping`) past 128 inner buffers, `max_size()` bounding and tightening on unregister, equal-size counts, in-place replacements, and descending removals to empty. ### Verification - `cargo test --locked -p victory-gpu --lib shadow::buffer_lookup_tests -- --test-threads=1` — passed on RTX 5090 and WARP (`VICTORY_D3D12_WARP=1`). - `cargo clippy --locked -p victory-gpu --tests` — 0 new warnings in `shadow.rs`. - `cargo run --quiet --locked -p xtask -- policy --staged` — passed.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
trustno1-coder/VIctory-NVIDIA!2556
No description provided.