GPU: reduce CPU overhead in submission preparation #3096

Open
github-bot wants to merge 1 commit from github-bot/gh-3096 into main AGit
Owner

@⁠maksimkaosipov75-design on GitHub · 2026-11-26 07:45 UTC · original
maksimkaosipov75-design:codex/victory-submit-cpu → main · +47 −32 · 2 files · 1 commits · open

What changed

  • Classify the sorted dirty pages and their sorted unmapped subset in one pass. This replaces a membership scan per page and preserves the clipped copy and zero-fill ranges.
  • Read the per-step timer in release builds only for copy and fill steps, which contribute to the preparation counters. The diagnostics build still times every step.
  • Add a regression test covering unmapped runs, a gap, and partial page boundaries.

Verification

The patch applies cleanly to 63bcca4. A standalone Rust harness built from the before/after functions matched the page runs across 10,000 generated cases and matched deferred-step order and copy byte counts in both build configurations.

On an ARM64 Mac, median synthetic measurements were 3.37 ms to 0.033 ms for classifying 8,192 pages with half unmapped, and 2.54 ms to 0.22 ms for walking 100,000 stubbed deferred steps with 2% copy/fill steps. These timings cover the isolated CPU paths. Windows workspace checks and in-game frame timing are pending.

**@⁠maksimkaosipov75-design** on GitHub · 2026-11-26 07:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/3096) `maksimkaosipov75-design:codex/victory-submit-cpu` → `main` · +47 −32 · 2 files · 1 commits · open ## What changed - Classify the sorted dirty pages and their sorted unmapped subset in one pass. This replaces a membership scan per page and preserves the clipped copy and zero-fill ranges. - Read the per-step timer in release builds only for copy and fill steps, which contribute to the preparation counters. The diagnostics build still times every step. - Add a regression test covering unmapped runs, a gap, and partial page boundaries. ## Verification The patch applies cleanly to `63bcca4`. A standalone Rust harness built from the before/after functions matched the page runs across 10,000 generated cases and matched deferred-step order and copy byte counts in both build configurations. On an ARM64 Mac, median synthetic measurements were 3.37 ms to 0.033 ms for classifying 8,192 pages with half unmapped, and 2.54 ms to 0.22 ms for walking 100,000 stubbed deferred steps with 2% copy/fill steps. These timings cover the isolated CPU paths. Windows workspace checks and in-game frame timing are pending.
Classify sorted page runs in one pass and measure release steps only
when a copy or fill contributes to the preparation counters.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:06:51 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 07:49 UTC · original · approved these changes

Tested locally merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090):

  • cargo test -p victory-gpu watch::tests -- --test-threads=1: all tests passed.
  • cargo test -p victory-gpu shadow::tests -- --test-threads=1: 9 passed, 0 failed.
  • cargo test -p victory-gpu draw::tests -- --test-threads=1: 20 passed, 0 failed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 07:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/3096#pullrequestreview-6070255048) · **approved these changes** Tested locally merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090): - `cargo test -p victory-gpu watch::tests -- --test-threads=1`: all tests passed. - `cargo test -p victory-gpu shadow::tests -- --test-threads=1`: 9 passed, 0 failed. - `cargo test -p victory-gpu draw::tests -- --test-threads=1`: 20 passed, 0 failed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 08:06 UTC · original

Independent Windows verification of #3096 at 0b65499c27d728d2c2834e427ea549a5f63eac48 against its exact parent 63bcca43c6a00a758510398fa43096ce7e4f7df0 (claim: #1633). Head, state and coordination were rechecked just before posting: the head is unchanged, the PR is open, and there is no other report on it besides the existing review.

Setup: Windows 11 Pro 10.0.26200 x64, AMD Ryzen 7 5700X3D, rustc/cargo 1.98.1 (from rust-toolchain.toml), cargo -j 4, separate clean worktrees for parent and head with one shared target dir. No physical GPU was used. The suites below only create a device through warp_adapter() (software), and nothing else here created one, so no dxil.dll was needed.

Existing tests (cargo test -p victory-gpu --lib, --test-threads=1 per module):

suite parent head
watch::tests 15 passed 16 passed (adds page_runs_preserve_missing_pages_gaps_and_partial_bounds)
shadow::tests 9 passed 9 passed
host:: 35 passed 35 passed
draw::tests 20 passed 20 passed
whole lib 231 passed, 1 ignored 232 passed, 1 ignored

Also clean on head: cargo check --features diagnostics --tests, cargo clippy -p victory-gpu --all-targets -D warnings with and without --features diagnostics, and cargo xtask policy (191 files ok).

Page-run classification, old inline loop vs split_page_runs: a local-only harness (not committed, removed afterwards) compared the parent's loop against the new function on 256,196 cases with identical output in all of them:

  • every subset of 10 pages with every unmapped subset of it, each against four ranges (unclipped, clipped on both sides, page-aligned, and one range inside a single page);
  • 20,000 random sorted sets over 400 pages with random unmapped subsets and clipping;
  • named shapes: empty, fully mapped (one copy run, no zero run), fully unmapped with clipped ends (one zero run, no copy run).

In take_split, pages comes from a BTreeSet range, whole is a filter of it, and protect_noting pushes unmapped pages in input order. So the sorted and subset assumptions in the new doc comment hold on the real path.

Deferred-step order: this was not exercised by a running test, because the walk is private and has no unit test. The arms were compared in the diff. Each step still performs its counter, title_written and copy actions in the same order, and the removed continues are equivalent because the match is the last statement of the loop. Both feature configurations compile and pass clippy.

CPU timing (not frame timing): release build, 21 samples per run, 5 runs, each cell the median of the 5 per-run medians (ranges are the per-run medians).

  • 8,192 consecutive pages, every other one unmapped: old 4.6 ms (4.2 to 6.0), new 0.10 ms (0.097 to 0.12).
  • 100,000 stubbed steps, 2% copy/fill, timer placement only: old 3.2 ms (3.19 to 3.27), new 0.15 ms (0.147 to 0.153).

These are isolated CPU loops that mimic the changed code, not the runtime. They say nothing about frame time. The half-unmapped pattern is also a favourable case for the old contains scan.

AI use: Claude Code (Claude Sonnet 5.5) ran the checks, coordinated by Codex (gpt-6.2-sol). Synthetic inputs only; no game files, dumps, shader names or hashes. No source changes and no competing PR. I left source-review commentary to the human reviewers.

**@⁠oni-swr** on GitHub · 2026-11-26 08:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/3096#issuecomment-7186204473) Independent Windows verification of #3096 at `0b65499c27d728d2c2834e427ea549a5f63eac48` against its exact parent `63bcca43c6a00a758510398fa43096ce7e4f7df0` (claim: https://git.gtahub.st/github/Marvisak--VIctory/issues/1633). Head, state and coordination were rechecked just before posting: the head is unchanged, the PR is open, and there is no other report on it besides the existing review. **Setup:** Windows 11 Pro 10.0.26200 x64, AMD Ryzen 7 5700X3D, rustc/cargo 1.98.1 (from `rust-toolchain.toml`), `cargo -j 4`, separate clean worktrees for parent and head with one shared target dir. No physical GPU was used. The suites below only create a device through `warp_adapter()` (software), and nothing else here created one, so no `dxil.dll` was needed. **Existing tests (`cargo test -p victory-gpu --lib`, `--test-threads=1` per module):** | suite | parent | head | |---|---|---| | `watch::tests` | 15 passed | 16 passed (adds `page_runs_preserve_missing_pages_gaps_and_partial_bounds`) | | `shadow::tests` | 9 passed | 9 passed | | `host::` | 35 passed | 35 passed | | `draw::tests` | 20 passed | 20 passed | | whole lib | 231 passed, 1 ignored | 232 passed, 1 ignored | Also clean on head: `cargo check --features diagnostics --tests`, `cargo clippy -p victory-gpu --all-targets -D warnings` with and without `--features diagnostics`, and `cargo xtask policy` (191 files ok). **Page-run classification, old inline loop vs `split_page_runs`:** a local-only harness (not committed, removed afterwards) compared the parent's loop against the new function on 256,196 cases with identical output in all of them: - every subset of 10 pages with every unmapped subset of it, each against four ranges (unclipped, clipped on both sides, page-aligned, and one range inside a single page); - 20,000 random sorted sets over 400 pages with random unmapped subsets and clipping; - named shapes: empty, fully mapped (one copy run, no zero run), fully unmapped with clipped ends (one zero run, no copy run). In `take_split`, `pages` comes from a `BTreeSet` range, `whole` is a filter of it, and `protect_noting` pushes unmapped pages in input order. So the sorted and subset assumptions in the new doc comment hold on the real path. **Deferred-step order:** this was not exercised by a running test, because the walk is private and has no unit test. The arms were compared in the diff. Each step still performs its counter, `title_written` and copy actions in the same order, and the removed `continue`s are equivalent because the match is the last statement of the loop. Both feature configurations compile and pass clippy. **CPU timing (not frame timing):** release build, 21 samples per run, 5 runs, each cell the median of the 5 per-run medians (ranges are the per-run medians). - 8,192 consecutive pages, every other one unmapped: old 4.6 ms (4.2 to 6.0), new 0.10 ms (0.097 to 0.12). - 100,000 stubbed steps, 2% copy/fill, timer placement only: old 3.2 ms (3.19 to 3.27), new 0.15 ms (0.147 to 0.153). These are isolated CPU loops that mimic the changed code, not the runtime. They say nothing about frame time. The half-unmapped pattern is also a favourable case for the old `contains` scan. AI use: Claude Code (Claude Sonnet 5.5) ran the checks, coordinated by Codex (gpt-6.2-sol). Synthetic inputs only; no game files, dumps, shader names or hashes. No source changes and no competing PR. I left source-review commentary to the human reviewers.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 08:20 UTC · original

Automated triage for the maintainers.

Merge candidate. crates/victory-gpu/src/watch.rs: Tracked::take_split now calls split_page_runs, which walks the sorted pages and their unmapped subset together instead of running unmapped.contains once per page. I checked that pages comes from a BTreeSet range and that protect_noting pushes unmapped pages in input order, so the ordering assumption holds. crates/victory-gpu/src/host.rs: the deferred-step walk now reads the timer outside diagnostics builds only for Copy/Fill steps. title_written and the copy_mapped flag stay per kind as before, and the removed continues are equivalent because the match is the loop's last statement. A new unit test covers gaps and clipped ends, and an independent Windows run is posted here.

Optional: a debug_assert! that unmapped is exhausted at the end of split_page_runs would catch a broken ordering assumption, which would otherwise classify an unmapped page as a copy without any error.

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 08:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/3096#issuecomment-7186469651) <!-- victory-triage v1 head=0b65499c27d728d2c2834e427ea549a5f63eac48 verdict=merge-candidate at=2026-11-26T08:17:31Z --> Automated triage for the maintainers. **Merge candidate.** `crates/victory-gpu/src/watch.rs`: `Tracked::take_split` now calls `split_page_runs`, which walks the sorted pages and their unmapped subset together instead of running `unmapped.contains` once per page. I checked that `pages` comes from a `BTreeSet` range and that `protect_noting` pushes unmapped pages in input order, so the ordering assumption holds. `crates/victory-gpu/src/host.rs`: the deferred-step walk now reads the timer outside diagnostics builds only for `Copy`/`Fill` steps. `title_written` and the `copy_mapped` flag stay per kind as before, and the removed `continue`s are equivalent because the `match` is the loop's last statement. A new unit test covers gaps and clipped ends, and an independent Windows run is posted here. Optional: a `debug_assert!` that `unmapped` is exhausted at the end of `split_page_runs` would catch a broken ordering assumption, which would otherwise classify an unmapped page as a copy without any error. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 08:25 UTC · original · approved these changes

Clean, focused optimization in both files:

  • HostList::run_deferred (crates/victory-gpu/src/host.rs): avoids Instant::now() on non-copy/fill steps in non-diagnostics builds while preserving exact step ordering, batch.title_written() semantics, PREPARING totals, and diagnostics counters (Timed, C::RunUs, C::Copies, etc.).
  • split_page_runs (crates/victory-gpu/src/watch.rs): replaces the O(|pages| * |unmapped|) unmapped.contains(&p) scan with a linear strip_prefix pass. The sorted-subset precondition holds because pages is collected from BTreeSet::range, whole preserves order, and protect_noting pushes unmapped pages in that same order. (Optional non-blocking nit: adding debug_assert!(unmapped.is_empty()); at the end of split_page_runs would guard that invariant against future edits.)

Verified locally on Windows 11 (RTX 5090 + WARP):

  • cargo clippy -p victory-gpu --all-targets -- -D warnings (default and --all-features): clean
  • RTX 5090: watch:: (16/16, including the new page_runs_preserve_missing_pages_gaps_and_partial_bounds), shadow:: (9/9), and host:: (34/34; skipping the pre-existing NVIDIA dynamic_slots_are_held_until_released cap failure) all passed
  • WARP (--features diagnostics, VICTORY_D3D12_WARP=1): watch::, shadow::, and host:: 62/62 passed
  • cargo xtask policy: 191 files ok

LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 08:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/3096#pullrequestreview-6070655236) · **approved these changes** Clean, focused optimization in both files: - `HostList::run_deferred` (`crates/victory-gpu/src/host.rs`): avoids `Instant::now()` on non-copy/fill steps in non-`diagnostics` builds while preserving exact step ordering, `batch.title_written()` semantics, `PREPARING` totals, and `diagnostics` counters (`Timed`, `C::RunUs`, `C::Copies`, etc.). - `split_page_runs` (`crates/victory-gpu/src/watch.rs`): replaces the O(|pages| * |unmapped|) `unmapped.contains(&p)` scan with a linear `strip_prefix` pass. The sorted-subset precondition holds because `pages` is collected from `BTreeSet::range`, `whole` preserves order, and `protect_noting` pushes unmapped pages in that same order. (Optional non-blocking nit: adding `debug_assert!(unmapped.is_empty());` at the end of `split_page_runs` would guard that invariant against future edits.) Verified locally on Windows 11 (RTX 5090 + WARP): - `cargo clippy -p victory-gpu --all-targets -- -D warnings` (default and `--all-features`): clean - RTX 5090: `watch::` (16/16, including the new `page_runs_preserve_missing_pages_gaps_and_partial_bounds`), `shadow::` (9/9), and `host::` (34/34; skipping the pre-existing NVIDIA `dynamic_slots_are_held_until_released` cap failure) all passed - WARP (`--features diagnostics`, `VICTORY_D3D12_WARP=1`): `watch::`, `shadow::`, and `host::` 62/62 passed - `cargo xtask policy`: 191 files ok LGTM.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3096/head:github-bot/gh-3096'
git switch 'github-bot/gh-3096'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3096'
git switch 'github-bot/gh-3096'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3096'
git switch 'github-bot/gh-3096'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3096'
git switch 'main'
git merge --squash 'github-bot/gh-3096'
git switch 'main'
git merge --ff-only 'github-bot/gh-3096'
git switch 'main'
git merge 'github-bot/gh-3096'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3096
No description provided.