Skip to content

Perf/indexed copyback ranges - #1869

Open
VlREX wants to merge 3 commits into
Marvisak:mainfrom
VlREX:perf/indexed-copyback-ranges
Open

VlREX wants to merge 3 commits into
Marvisak:mainfrom
VlREX:perf/indexed-copyback-ranges

Conversation

@VlREX

@VlREX VlREX commented Nov 24, 2026

Copy link
Copy Markdown

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).

@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown

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).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

@VlREX
VlREX force-pushed the perf/indexed-copyback-ranges branch from 58d3b08 to 5466200 Compare November 25, 2026 18:27
Keep small and lightly queried lists linear; defer sorting until 32 full-scan equivalents. Release the declaration guard before copying pages. Add adaptive transition and reference-equivalence tests. Threshold is a heuristic motivated by the synthetic Windows benchmark, not an in-game measurement.
@fuzeofficlal

Copy link
Copy Markdown
Contributor

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 added a commit to crashbashash/VIctory-proton that referenced this pull request Nov 26, 2026
A list records a root UAV's range for every draw or dispatch that binds it
(`Map::precise`), many copies of a few ranges, and after its run every page
its shaders marked was compared with all of them. In the prison scene that
search was 13 % of the submitting thread's samples (perf, two runs), 95-97 %
of the after-run closure's own time.

The ranges are now sorted and merged in place when the list's run is over
(the bytes they cover stay the same, so a list that runs again searches the
merged list), and each page is looked up with a binary search: of disjoint
ranges in order, only the last one starting before the page's end can
overlap it. The closure falls to 0.2 % of the thread. A test compares the
search with the linear one over random, duplicated, touching and empty
ranges. Upstream PR Marvisak#1869 does the same with an index of its own.
@crashbashash

Copy link
Copy Markdown

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.

crashbashash added a commit to crashbashash/VIctory-proton that referenced this pull request Nov 26, 2026
A list records a root UAV's range for every draw or dispatch that binds it
(`Map::precise`), many copies of a few ranges, and after its run every page
its shaders marked was compared with all of them. In the prison scene that
search was 13 % of the submitting thread's samples (perf, two runs), 95-97 %
of the after-run closure's own time.

The ranges are now sorted and merged in place when the list's run is over
(the bytes they cover stay the same, so a list that runs again searches the
merged list), and each page is looked up with a binary search: of disjoint
ranges in order, only the last one starting before the page's end can
overlap it. The closure falls to 0.2 % of the thread. A test compares the
search with the linear one over random, duplicated, touching and empty
ranges. Upstream PR Marvisak#1869 does the same with an index of its own.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants