Perf/indexed copyback ranges #1867

Open
VlREX wants to merge 3 commits from upstream-pr/1869 into main
VlREX commented 2026-11-24 23:53:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by VlREX on 2026-11-24T23:53:48Z.


Replace linear precise UAV range scans with a sorted prefix-maximum interval index and binary search. Synthetic lookup comparisons reduced from 6,292,480 to 45,058, excluding index construction. Independently verified with 102,464 JavaScript model queries and 131,072 native C queries, zero mismatches. Four Rust tests included. Native Rust and GPU benchmarks pending. Complementary to #1865. AI-assisted (ChatGPT).

<!-- greyfinch-sync:Marvisak/VIctory:issue:6593856467 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1869). Originally posted by [VlREX](https://github.com/VlREX) on 2026-11-24T23:53:48Z. --- Replace linear precise UAV range scans with a sorted prefix-maximum interval index and binary search. Synthetic lookup comparisons reduced from 6,292,480 to 45,058, excluding index construction. Independently verified with 102,464 JavaScript model queries and 131,072 native C queries, zero mismatches. Four Rust tests included. Native Rust and GPU benchmarks pending. Complementary to #1865. AI-assisted (ChatGPT).
catminou4 commented 2026-11-25 01:07:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T00:32:41Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Indexed copyback ranges (docs+gpu): perf work on the copyback path, pairs with #1816's delivered-bytes accounting.

<!-- greyfinch-sync:Marvisak/VIctory:review:6049696616 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1869#pullrequestreview-6049696616). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T00:32:41Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Indexed copyback ranges (docs+gpu): perf work on the copyback path, pairs with #1816's delivered-bytes accounting.
upipibi commented 2026-11-25 01:07:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-25T00:10:54Z.


Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at b118e79: cargo test -p victory-gpu --locked gives 80 passed, 2 failed, 1 ignored. The two failures are the NVIDIA heap-cap ones main also has (descriptor::host::tests::dynamic_slots_are_held_until_released and memory::tests::lists_share_a_table_and_copies_keep_their_views, #1744), so there is nothing new on this hardware. Not run: a title.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148235094 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1869#issuecomment-7148235094). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-25T00:10:54Z. --- Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at `b118e79`: `cargo test -p victory-gpu --locked` gives 80 passed, 2 failed, 1 ignored. The two failures are the NVIDIA heap-cap ones `main` also has (`descriptor::host::tests::dynamic_slots_are_held_until_released` and `memory::tests::lists_share_a_table_and_copies_keep_their_views`, #1744), so there is nothing new on this hardware. Not run: a title. AI-assisted (Claude Code).
Marvisak commented 2026-11-25 08:06:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T07:26:35Z.


Automated triage for the maintainers.

Needs rebase. This PR no longer merges cleanly into main (conflict in crates/victory-gpu/src/memory.rs). It will be reviewed again once it is rebased.

From the earlier needs-work note, still open: a number from a real frame showing the linear scan costs something (range counts or before/after copy-back ms), a descriptive PR title, and rustfmt on precise_ranges.rs.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7155864576 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1869#issuecomment-7155864576). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T07:26:35Z. --- <!-- victory-triage v1 head=163c39fffb76a0c14db047a12e972d9bdb26ce7b verdict=needs-rebase at=2026-11-25T22:23:30Z --> Automated triage for the maintainers. **Needs rebase.** This PR no longer merges cleanly into `main` (conflict in `crates/victory-gpu/src/memory.rs`). It will be reviewed again once it is rebased. From the earlier needs-work note, still open: a number from a real frame showing the linear scan costs something (range counts or before/after copy-back ms), a descriptive PR title, and rustfmt on `precise_ranges.rs`. --- _Generated by [Claude Code](https://claude.ai/code)_
fuzeofficlal commented 2026-11-25 20:06:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T19:59:41Z.


Reviewed and verified 163c39ff on Windows 11 against main (13f91ca).

Code review

  • AdaptiveRanges cleanly addresses the upfront allocation/sorting overhead on small or early-exit sets: it scans linearly with zero allocation until n >= 8 and comparisons >= n.saturating_mul(32), only building the sorted prefix-max index when the range set actually gets hot. Dropping precise and declared right after the scan also avoids holding the byte_for_byte lock longer than needed.
  • Checked PreciseRanges::overlaps against the prior linear predicate a < to && from < a + len: saturating_add avoids end overflow, from >= to returns false, and partition_point(|&(start, _)| start < to) + prefix max_end > from matches on nested ranges, duplicate starts, zero-length ranges strictly inside a page vs. on boundaries, and saturating ends.

Verification (Windows 11, RTX 5090 + WARP)

  • VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics -- --test-threads=1: 205 passed, 0 failed, 1 ignored (all 7 precise_ranges::tests pass).
  • RTX 5090: precise_ranges::tests 7/7, shadow::tests --test-threads=1 8/8, memory::tests --test-threads=1 4/5 (only the known 13f91ca RTX 5090 1M view-heap failure lists_share_a_table_and_copies_keep_their_views).
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings (default and --features diagnostics): 0 warnings; cargo xtask policy: 185 files ok.
  • Clean git merge-tree against 13f91ca as well as #2172, #2434, #2096, and #562.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7173037893 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1869#issuecomment-7173037893). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T19:59:41Z. --- Reviewed and verified `163c39ff` on Windows 11 against `main` (`13f91ca`). ### Code review - `AdaptiveRanges` cleanly addresses the upfront allocation/sorting overhead on small or early-exit sets: it scans linearly with zero allocation until `n >= 8` and `comparisons >= n.saturating_mul(32)`, only building the sorted prefix-max index when the range set actually gets hot. Dropping `precise` and `declared` right after the scan also avoids holding the `byte_for_byte` lock longer than needed. - Checked `PreciseRanges::overlaps` against the prior linear predicate `a < to && from < a + len`: `saturating_add` avoids end overflow, `from >= to` returns `false`, and `partition_point(|&(start, _)| start < to)` + prefix `max_end > from` matches on nested ranges, duplicate starts, zero-length ranges strictly inside a page vs. on boundaries, and saturating ends. ### Verification (Windows 11, RTX 5090 + WARP) - `VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics -- --test-threads=1`: **205 passed, 0 failed, 1 ignored** (all 7 `precise_ranges::tests` pass). - RTX 5090: `precise_ranges::tests` **7/7**, `shadow::tests --test-threads=1` **8/8**, `memory::tests --test-threads=1` **4/5** (only the known `13f91ca` RTX 5090 1M view-heap failure `lists_share_a_table_and_copies_keep_their_views`). - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings` (default and `--features diagnostics`): **0 warnings**; `cargo xtask policy`: **185 files ok**. - Clean `git merge-tree` against `13f91ca` as well as `#2172`, `#2434`, `#2096`, and `#562`.
crashbashash commented 2026-11-26 11:03:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by crashbashash on 2026-11-26T10:10:03Z.


In-game numbers for the linear search this PR replaces, since the description says native benchmarks are pending.
RX 6800 XT, Linux (Proton, vkd3d-proton), diag build with frame pointers of main 219878a plus our Linux
commits, a save in the prison, perf (cycles:u, call graphs) over 30 s in the world.

The search shows up as memory::bind::closure$2 (the after-run closure that copies back marked pages): 13.6 % and
12.9 % of the submitting thread's samples
in two runs. By source line, 95-97 % of that closure's own samples are the
precise.iter().any(...) line; scanning the bitmap itself is negligible. The list is long because draw.rs pushes a
root UAV's range for every draw or dispatch that binds it, so a list holds many copies of the same few ranges, and
every marked page is compared with all of them.

I tested the same idea in a smaller form on our branch: sort the ranges and merge overlapping or touching ones in
place (the bytes they cover stay the same, so a list that runs again searches the merged list), then a binary search
per page (partition_point; with disjoint sorted ranges only the last one starting before the page's end can overlap
it), with a test against the linear search over random, duplicated, touching and empty ranges. With it the closure
falls to 0.2 % of the thread. Frame times did not move measurably (it is one thread among several; 2 runs
each), so the gain is CPU time on the submitting thread rather than frame rate here.

Either version removes it; no need to change yours for this. Happy to share ours if a smaller diff helps.

AI-assisted (Claude Code). No game data attached.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7188997953 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1869#issuecomment-7188997953). Originally posted by [crashbashash](https://github.com/crashbashash) on 2026-11-26T10:10:03Z. --- In-game numbers for the linear search this PR replaces, since the description says native benchmarks are pending. RX 6800 XT, Linux (Proton, vkd3d-proton), `diag` build with frame pointers of `main` `219878a` plus our Linux commits, a save in the prison, perf (`cycles:u`, call graphs) over 30 s in the world. The search shows up as `memory::bind::closure$2` (the after-run closure that copies back marked pages): **13.6 % and 12.9 % of the submitting thread's samples** in two runs. By source line, 95-97 % of that closure's own samples are the `precise.iter().any(...)` line; scanning the bitmap itself is negligible. The list is long because `draw.rs` pushes a root UAV's range for every draw or dispatch that binds it, so a list holds many copies of the same few ranges, and every marked page is compared with all of them. I tested the same idea in a smaller form on our branch: sort the ranges and merge overlapping or touching ones in place (the bytes they cover stay the same, so a list that runs again searches the merged list), then a binary search per page (`partition_point`; with disjoint sorted ranges only the last one starting before the page's end can overlap it), with a test against the linear search over random, duplicated, touching and empty ranges. With it the closure falls to **0.2 %** of the thread. Frame times did not move measurably (it is one thread among several; 2 runs each), so the gain is CPU time on the submitting thread rather than frame rate here. Either version removes it; no need to change yours for this. Happy to share ours if a smaller diff helps. AI-assisted (Claude Code). No game data attached.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1869:upstream-pr/1869'
git switch 'upstream-pr/1869'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1869'
git switch 'upstream-pr/1869'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1869'
git switch 'upstream-pr/1869'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1869'
git switch 'main'
git merge --squash 'upstream-pr/1869'
git switch 'main'
git merge --ff-only 'upstream-pr/1869'
git switch 'main'
git merge 'upstream-pr/1869'
git push origin 'main'
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
Marvisak/VIctory!1867
No description provided.