GPU: batch page-table rebuilds by region and owner #3232

Open
github-bot wants to merge 3 commits from github-bot/gh-3232 into main AGit
Owner

@⁠yumaste on GitHub · 2026-11-26 13:53 UTC · original
yumaste:perf/page-table-block-fill → main · +151 −16 · 1 files · 3 commits · open

Problem

When title-memory copies change, the GPU page table is rebuilt. The builder used to recalculate the region and update ownership one 64 KiB page at a time for each copy, including large overlapping windows. It then looked up the same descriptor and base address separately for every page in a run.

Change

Allocate level-two blocks in the existing order, then fill each copy's whole pages in bulk within each 256 MiB region. Partial edge pages still claim only unowned entries. Emit runs of identical page owners with one descriptor lookup per run. Ownership, offsets, null entries and the table's block limit stay the same. The GPU mapping is only written.

Synthetic benchmark

Windows x64, Core Ultra 9 275HX, Rust 1.98.1 with -C opt-level=3. Medians of 20 interleaved runs of both builders. Timings include construction and emission of the page table into cached CPU memory. D3D12 synchronization, descriptor creation, and title execution are outside the measurement.

Synthetic input Main This PR
4,700 short copies 1.10 ms 1.12 ms
4,700 short copies + 24 windows of 174 MiB 1.15 ms 1.10 ms
15,000 short copies + 64 windows of 174 MiB 1.42 ms 1.25 ms
15,000 short copies + 48 overlapping multi-region windows 6.95 ms 1.71 ms
Overlap stress at the 512-block limit 73.57 ms 14.13 ms

The last two rows deliberately use 8 to 10 GiB virtual windows to stress repeated ownership updates. The short copies span 1 to 16 pages across 64 regions. The 174 MiB rows show the smaller gain with shorter windows.

Validation

  • The baseline and new builder produced identical block mappings, owner indexes and emitted dwords in the benchmark cases and 40 mixed randomized cases, including limit, overflow and unaligned cases.
  • Added a deterministic boundary regression and a seeded 40-case regression against a per-page reference. It compares region mapping, page owners and emitted dwords and includes an explicit capacity-limit case.
  • WARP victory-gpu library suite with diagnostics: 247 passed, 1 ignored. Strict Clippy and cargo xtask policy passed.

Coordination claim. No game files used. AI-assisted (Codex).

**@⁠yumaste** on GitHub · 2026-11-26 13:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/3232) `yumaste:perf/page-table-block-fill` → `main` · +151 −16 · 1 files · 3 commits · open ## Problem When title-memory copies change, the GPU page table is rebuilt. The builder used to recalculate the region and update ownership one 64 KiB page at a time for each copy, including large overlapping windows. It then looked up the same descriptor and base address separately for every page in a run. ## Change Allocate level-two blocks in the existing order, then fill each copy's whole pages in bulk within each 256 MiB region. Partial edge pages still claim only unowned entries. Emit runs of identical page owners with one descriptor lookup per run. Ownership, offsets, null entries and the table's block limit stay the same. The GPU mapping is only written. ## Synthetic benchmark Windows x64, Core Ultra 9 275HX, Rust 1.98.1 with `-C opt-level=3`. Medians of 20 interleaved runs of both builders. Timings include construction and emission of the page table into cached CPU memory. D3D12 synchronization, descriptor creation, and title execution are outside the measurement. | Synthetic input | Main | This PR | | --- | ---: | ---: | | 4,700 short copies | 1.10 ms | 1.12 ms | | 4,700 short copies + 24 windows of 174 MiB | 1.15 ms | 1.10 ms | | 15,000 short copies + 64 windows of 174 MiB | 1.42 ms | 1.25 ms | | 15,000 short copies + 48 overlapping multi-region windows | 6.95 ms | 1.71 ms | | Overlap stress at the 512-block limit | 73.57 ms | 14.13 ms | The last two rows deliberately use 8 to 10 GiB virtual windows to stress repeated ownership updates. The short copies span 1 to 16 pages across 64 regions. The 174 MiB rows show the smaller gain with shorter windows. ## Validation - The baseline and new builder produced identical block mappings, owner indexes and emitted dwords in the benchmark cases and 40 mixed randomized cases, including limit, overflow and unaligned cases. - Added a deterministic boundary regression and a seeded 40-case regression against a per-page reference. It compares region mapping, page owners and emitted dwords and includes an explicit capacity-limit case. - WARP `victory-gpu` library suite with diagnostics: 247 passed, 1 ignored. Strict Clippy and `cargo xtask policy` passed. [Coordination claim](https://git.gtahub.st/github/Marvisak--VIctory/issues/1633). No game files used. AI-assisted (Codex).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 13:59:25 +00:00
Author
Owner

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

Verified on RTX 5090 & WARP against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib memory:: -- --test-threads=1 --skip lists_share_a_table_and_copies_keep_their_views: 8/8 passed on RTX 5090 and WARP (including page_ownership_at_region_boundaries).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly batches page-table rebuilds by region and owner.

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

**@⁠Dukestar69** on GitHub · 2026-11-26 14:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/3232#pullrequestreview-6075515421) · **approved these changes** Verified on RTX 5090 & WARP against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib memory:: -- --test-threads=1 --skip lists_share_a_table_and_copies_keep_their_views`: 8/8 passed on RTX 5090 and WARP (including `page_ownership_at_region_boundaries`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly batches page-table rebuilds by region and owner. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠AurumCarlos on GitHub · 2026-11-26 14:07 UTC · original · reviewed

I walked the new fill against the per-page loop on main, and I believe it's equivalent:

  • Whole pages: page p was whole when p << 16 >= start && (p + 1) << 16 <= end, i.e. ceil(start / 64K) <= p < end >> 16. That's exactly first_whole..past_whole, clamped to the region, so fill(k) takes the same pages, overriding larger copies as before.
  • Partial pages: a copy has at most two (head and tail), and the clamps put the head at entries[0] only in the region that holds start, and the tail at entries[last] only in the region that holds end. I checked the corners: two partial pages in adjacent regions with no whole page between them (2 * REGION - 7, 14), both edges in one page (head set, tail skipped since whole_end == past), and an aligned start with an unaligned end in the same page (head skipped, tail set). Each partial page is claimed once, and only if it's free, as before.
  • Blocks: they're allocated in the same order (per copy, ascending regions), and the full path still skips just that region. last_block stays below LEVEL1, since end <= 1 << 40.
  • Emission: chunk_by + fill writes the same [pair, start] / [null, 0] per entry.

The new regression pins those corners nicely. One suggestion: the description mentions that the old and new builders produced identical tables in 40 randomized cases, including limit, overflow and unaligned ones. That check is the strongest evidence here, and it would be worth committing: for example, keep the old per-page loop as a test-only reference and compare (blocks, owner) over a seeded generator. That way a future change to the bulk path gets checked against the simple definition, not just against the hand-picked rows.

**@⁠AurumCarlos** on GitHub · 2026-11-26 14:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/3232#pullrequestreview-6075517321) · **reviewed** I walked the new fill against the per-page loop on `main`, and I believe it's equivalent: - **Whole pages**: page `p` was whole when `p << 16 >= start && (p + 1) << 16 <= end`, i.e. `ceil(start / 64K) <= p < end >> 16`. That's exactly `first_whole..past_whole`, clamped to the region, so `fill(k)` takes the same pages, overriding larger copies as before. - **Partial pages**: a copy has at most two (head and tail), and the clamps put the head at `entries[0]` only in the region that holds `start`, and the tail at `entries[last]` only in the region that holds `end`. I checked the corners: two partial pages in adjacent regions with no whole page between them (`2 * REGION - 7, 14`), both edges in one page (head set, tail skipped since `whole_end == past`), and an aligned start with an unaligned end in the same page (head skipped, tail set). Each partial page is claimed once, and only if it's free, as before. - **Blocks**: they're allocated in the same order (per copy, ascending regions), and the `full` path still skips just that region. `last_block` stays below `LEVEL1`, since `end <= 1 << 40`. - **Emission**: `chunk_by` + `fill` writes the same `[pair, start]` / `[null, 0]` per entry. The new regression pins those corners nicely. One suggestion: the description mentions that the old and new builders produced identical tables in 40 randomized cases, including limit, overflow and unaligned ones. That check is the strongest evidence here, and it would be worth committing: for example, keep the old per-page loop as a test-only reference and compare `(blocks, owner)` over a seeded generator. That way a future change to the bulk path gets checked against the simple definition, not just against the hand-picked rows.
Author
Owner

@⁠yumaste on GitHub · 2026-11-26 14:22 UTC · original · edited 2026-11-26 14:24 UTC

I added the seeded per-page reference test in 32b656e. It compares the block map, owners, and emitted dwords over 40 seeded cases, including an explicit capacity-limit case plus invalid and partial ranges. The CI Clippy job flagged chunks_exact in the test. fd98bfa uses as_chunks and checks the remainder. Both Clippy profiles and the regression pass locally.

**@⁠yumaste** on GitHub · 2026-11-26 14:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/3232#issuecomment-7194729637) · edited 2026-11-26 14:24 UTC I added the seeded per-page reference test in `32b656e`. It compares the block map, owners, and emitted dwords over 40 seeded cases, including an explicit capacity-limit case plus invalid and partial ranges. The CI Clippy job flagged `chunks_exact` in the test. `fd98bfa` uses `as_chunks` and checks the remainder. Both Clippy profiles and the regression pass locally.
Author
Owner

@⁠Desamodeth on GitHub · 2026-11-26 18:31 UTC · original · reviewed

CPU-only A/B of write_table on 63bcca43 vs fd98bfaf. The overlap speedup survives writing to Windows PAGE_WRITECOMBINE memory (confirmed with VirtualQuery). Ryzen 7 9800X3D, rustc 1.98.1 MSVC, -C opt-level=3. Median milliseconds per rebuild, 30 interleaved samples per version after warm-up:

Synthetic copies main PR
4,700 short copies, 1–16 pages across 64 regions 0.628 0.654
Same + 24 windows of 174 MiB 0.660 0.645
15,000 short copies + 48 overlapping 8 GiB virtual windows 5.580 1.118
32,768 adjacent pages, one distinct owner per page 0.205 0.300

A second process with the memory modes in reverse order reproduced the two extremes (5.576 → 1.158 ms and 0.172 → 0.265 ms). An isolation run keeping the PR ownership pass but restoring the main emitter still showed both effects. I’d keep the one-owner-per-page case alongside the overlap benchmark when tuning the builder.

The block list, page owners, written length and all emitted bytes matched in all four cases with both cached and write-combined output. Timing includes an sfence after the writes. Synthetic CPU memory only; no D3D12 calls, game data or frame-rate measurement. AI-assisted with Codex.

**@⁠Desamodeth** on GitHub · 2026-11-26 18:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/3232#pullrequestreview-6079006939) · **reviewed** CPU-only A/B of `write_table` on `63bcca43` vs `fd98bfaf`. The overlap speedup survives writing to Windows `PAGE_WRITECOMBINE` memory (confirmed with `VirtualQuery`). Ryzen 7 9800X3D, rustc 1.98.1 MSVC, `-C opt-level=3`. Median milliseconds per rebuild, 30 interleaved samples per version after warm-up: | Synthetic copies | main | PR | |---|---:|---:| | 4,700 short copies, 1–16 pages across 64 regions | 0.628 | 0.654 | | Same + 24 windows of 174 MiB | 0.660 | 0.645 | | 15,000 short copies + 48 overlapping 8 GiB virtual windows | 5.580 | 1.118 | | 32,768 adjacent pages, one distinct owner per page | 0.205 | 0.300 | A second process with the memory modes in reverse order reproduced the two extremes (5.576 → 1.158 ms and 0.172 → 0.265 ms). An isolation run keeping the PR ownership pass but restoring the main emitter still showed both effects. I’d keep the one-owner-per-page case alongside the overlap benchmark when tuning the builder. The block list, page owners, written length and all emitted bytes matched in all four cases with both cached and write-combined output. Timing includes an `sfence` after the writes. Synthetic CPU memory only; no D3D12 calls, game data or frame-rate measurement. AI-assisted with Codex.
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/3232/head:github-bot/gh-3232'
git switch 'github-bot/gh-3232'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3232'
git switch 'github-bot/gh-3232'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3232'
git switch 'github-bot/gh-3232'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3232'
git switch 'main'
git merge --squash 'github-bot/gh-3232'
git switch 'main'
git merge --ff-only 'github-bot/gh-3232'
git switch 'main'
git merge 'github-bot/gh-3232'
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!3232
No description provided.