GPU: pool title-memory dirty bitmaps, write page tables directly, and skip zero bitmap words #1865

Manually merged
github merged 1 commit from gh-pr/1865/head into gh-pr/1865/base 2026-11-26 04:46:59 +00:00
Owner

@⁠nathanbzrr on GitHub · 2026-11-24 23:46 UTC · original
nathanbzrr:gpu/memory-bitmap-pool-and-table-perf → main · +297 −47 · 1 files · 1 commits · merged 2026-11-25 21:52 UTC

Summary

  • Pool dirty-page bitmaps (crates/victory-gpu/src/memory.rs): Add BITMAP_POOL (capped at BITMAP_POOL_CAP = 64), Bitmap::acquire(), and PooledBitmap RAII guard keeping each list's 256 KiB shared dirty-page bitmap owned across defer_missed and defer_after until HostList::reset or Drop. On drop, PooledBitmap scans for and clears any stray non-zero words before returning the buffer to the pool (and drops overflow buffers outside the pool lock).
  • Write page tables directly (write_table): Build level1 in stack memory ([0u32; LEVEL1]), shrink per-entry tracking from Option<(usize, bool)> / Option<usize> to compact owner: Vec<u32> with NO_OWNER = u32::MAX, guard start.checked_add(len) against overflow, and write level-1 and level-2 dwords sequentially into the mapped upload buffer (out) using as_chunks_mut::<2>() without reading write-combined memory.
  • Fast dirty-bitmap scanning: Rewrite has_missed to iterate set bits via trailing_zeros() and bits &= bits - 1, and skip *mark == 0 words in defer_after without dirtying cache lines.
  • Tests: Add table_skips_overflowing_and_out_of_range_copies, has_missed_checks_block_zero_out_of_range_unowned_and_owned, and bitmap_pool_reuses_and_zeroes_across_resets, and serialize GPU tests in memory::tests with gpu_test_lock().

Verification

  • cargo clippy --workspace --all-targets -- -D warnings: passed (exit 0)
  • cargo clippy --workspace --all-targets --all-features -- -D warnings: passed (exit 0)
  • cargo test -p victory-gpu memory --locked: 11 passed; 0 failed; 0 ignored; 71 filtered out
  • cargo test -p victory-gpu --all-features memory --locked: 11 passed; 0 failed; 0 ignored; 74 filtered out
  • VICTORY_WARP=1 cargo test -p victory-gpu memory --locked: 11 passed; 0 failed; 0 ignored; 71 filtered out
  • cargo test --workspace --locked: all workspace crates passed (victory: 1, victory-core: 11, victory-formats: 23/4 ignored, victory-game: 15, victory-gpu: 81/1 ignored, victory-hle: 97 + 2 integration, victory-loader: 22 + 3 integration, victory-pe: 7, victory-pipeline: 4, victory-shader: 209/2 ignored, xtask: 4)
  • git diff --cached --name-only: crates/victory-gpu/src/memory.rs
  • cargo run -p xtask -- policy --staged: asset policy: 1 files ok
**@⁠nathanbzrr** on GitHub · 2026-11-24 23:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/1865) `nathanbzrr:gpu/memory-bitmap-pool-and-table-perf` → `main` · +297 −47 · 1 files · 1 commits · merged 2026-11-25 21:52 UTC ## Summary - **Pool dirty-page bitmaps (`crates/victory-gpu/src/memory.rs`)**: Add `BITMAP_POOL` (capped at `BITMAP_POOL_CAP = 64`), `Bitmap::acquire()`, and `PooledBitmap` RAII guard keeping each list's 256 KiB shared dirty-page bitmap owned across `defer_missed` and `defer_after` until `HostList::reset` or `Drop`. On drop, `PooledBitmap` scans for and clears any stray non-zero words before returning the buffer to the pool (and drops overflow buffers outside the pool lock). - **Write page tables directly (`write_table`)**: Build `level1` in stack memory (`[0u32; LEVEL1]`), shrink per-entry tracking from `Option<(usize, bool)>` / `Option<usize>` to compact `owner: Vec<u32>` with `NO_OWNER = u32::MAX`, guard `start.checked_add(len)` against overflow, and write level-1 and level-2 dwords sequentially into the mapped upload buffer (`out`) using `as_chunks_mut::<2>()` without reading write-combined memory. - **Fast dirty-bitmap scanning**: Rewrite `has_missed` to iterate set bits via `trailing_zeros()` and `bits &= bits - 1`, and skip `*mark == 0` words in `defer_after` without dirtying cache lines. - **Tests**: Add `table_skips_overflowing_and_out_of_range_copies`, `has_missed_checks_block_zero_out_of_range_unowned_and_owned`, and `bitmap_pool_reuses_and_zeroes_across_resets`, and serialize GPU tests in `memory::tests` with `gpu_test_lock()`. ## Verification - `cargo clippy --workspace --all-targets -- -D warnings`: passed (exit 0) - `cargo clippy --workspace --all-targets --all-features -- -D warnings`: passed (exit 0) - `cargo test -p victory-gpu memory --locked`: `11 passed; 0 failed; 0 ignored; 71 filtered out` - `cargo test -p victory-gpu --all-features memory --locked`: `11 passed; 0 failed; 0 ignored; 74 filtered out` - `VICTORY_WARP=1 cargo test -p victory-gpu memory --locked`: `11 passed; 0 failed; 0 ignored; 71 filtered out` - `cargo test --workspace --locked`: all workspace crates passed (`victory`: 1, `victory-core`: 11, `victory-formats`: 23/4 ignored, `victory-game`: 15, `victory-gpu`: 81/1 ignored, `victory-hle`: 97 + 2 integration, `victory-loader`: 22 + 3 integration, `victory-pe`: 7, `victory-pipeline`: 4, `victory-shader`: 209/2 ignored, `xtask`: 4) - `git diff --cached --name-only`: `crates/victory-gpu/src/memory.rs` - `cargo run -p xtask -- policy --staged`: `asset policy: 1 files ok`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:46:58 +00:00
github manually merged commit f9b27fdfa0 into gh-pr/1865/base 2026-11-26 04:46:59 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 00:10 UTC · original

Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at b58ed3c: cargo test -p victory-gpu --locked gives 79 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).

**@⁠upipibi** on GitHub · 2026-11-25 00:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/1865#issuecomment-7148235719) Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at `b58ed3c`: `cargo test -p victory-gpu --locked` gives 79 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).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 07:18 UTC · original · edited 2026-11-25 20:20 UTC

Automated triage for the maintainers.

Merge candidate. The verdict is unchanged.

Since the last review (c87e403 → f9b27fd): this is a rebase onto current main (13f91ca). The only changes to the patch, which I checked with a range-diff:

  • It adopts main's new Layout::bits field: the defer_after destructure uses .., and the has_missed test fills bits.
  • a_submission_that_missed_leaves_the_copies_at_once now also takes gpu_test_lock.

The substance is the same and still reads correct to me.

  • In crates/victory-gpu/src/memory.rs, the 256 KiB dirty bitmaps come from a pool capped at 64 entries (Bitmap::acquire / PooledBitmap), and the pool is zeroed before reuse.
  • write_table writes the page table straight into the mapped upload buffer and builds level-1 on the stack. It now also skips copies whose end would overflow.
  • owner becomes u32 with NO_OWNER, and the bitmap scans skip zero words.

The earlier minor points still stand, none blocking:

  • marks.fill(0) in PooledBitmap::drop.
  • No timings are given.
  • Draw tests that call memory::bind without gpu_test_lock could still make bitmap_pool_reuses_and_zeroes_across_resets flaky, because the test assumes LIFO reuse of the global pool.

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 07:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/1865#issuecomment-7155714392) · edited 2026-11-25 20:20 UTC <!-- victory-triage v1 head=f9b27fdfa0eced1f4948739c7b8646aa032945d2 verdict=merge-candidate at=2026-11-25T20:18:54Z --> Automated triage for the maintainers. **Merge candidate.** The verdict is unchanged. **Since the last review (`c87e403` → `f9b27fd`):** this is a rebase onto current `main` (`13f91ca`). The only changes to the patch, which I checked with a range-diff: - It adopts `main`'s new `Layout::bits` field: the `defer_after` destructure uses `..`, and the `has_missed` test fills `bits`. - `a_submission_that_missed_leaves_the_copies_at_once` now also takes `gpu_test_lock`. The substance is the same and still reads correct to me. - In `crates/victory-gpu/src/memory.rs`, the 256 KiB dirty bitmaps come from a pool capped at 64 entries (`Bitmap::acquire` / `PooledBitmap`), and the pool is zeroed before reuse. - `write_table` writes the page table straight into the mapped upload buffer and builds level-1 on the stack. It now also skips copies whose end would overflow. - `owner` becomes `u32` with `NO_OWNER`, and the bitmap scans skip zero words. The earlier minor points still stand, none blocking: - `marks.fill(0)` in `PooledBitmap::drop`. - No timings are given. - Draw tests that call `memory::bind` without `gpu_test_lock` could still make `bitmap_pool_reuses_and_zeroes_across_resets` flaky, because the test assumes LIFO reuse of the global pool. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠tumbubu on GitHub · 2026-11-25 21:34 UTC · original

f9b27fd in the world on an RX 7900 XT (RDNA3): the bitmap scan this PR rewrites is about 8% of the submission thread's wall time on main, and absent with this PR. Tests: 198 passed.

  • Setup: AMD Radeon RX 7900 XT, driver 32.0.31036.15, Windows 11 Pro 26300.
  • Builds: diag builds (--profile diag --features diagnostics) of main 13f91ca and of this PR, which is 13f91ca plus f9b27fd.
  • Runs: warm shader cache and pipeline library, 180 s each, Enter every 3 s from 8 s to 47 s, VICTORY_LOG=info.

Where the time goes. I sampled with VICTORY_STACKS, a dump every 0.25 s from 105 s to 175 s, in the world. A dump of 96 threads takes about 1 s, so that came to 74 dumps on main and 47 here. I symbolised victory.exe frames from the build's PDB. The thread that runs queue::pump → Host::execute is the busy one. The title's threads are waiting in almost every dump.

submission thread main this PR
busy (not in a wait) 46 of 74 24 of 46
leaf in memory::bind's defer_missed closure (the old (0..32).filter scan) 6 0
leaf in ZwReadVirtualMemory (refresh copies, not touched here) 9 11
  • If the closure still held its 8% share, 0 hits in 46 samples would come up about 2% of the time.
  • A standalone copy of the old and new scans, over a 513-block bitmap with four marked pages, takes 775 µs and 14 µs per call (rustc -O, Ryzen host). The main samples are consistent with roughly 80 such scans in a ~760 ms frame.

Frame lines (world: frame-rate lines under 10 fps with at least 500 draws):

run fps ms/frame preparing on the GPU copying back draws/frame
main, 3 runs 1.53 / 1.54 / 1.66 918 / 760 / 712 379 / 414 / 409 199 / 202 / 178 93 / 107 / 86 3913 / 3535 / 4370
this PR, 2 runs 1.72 / 1.83 686 / 685 373 / 366 194 / 191 91 / 91 3782 / 3723
  • The frame times favour the PR. But main alone ranges from 712 to 918 ms here, so I do not claim a frame-level number. The samples are the measurement.
  • One main run, the 712 ms one, had VICTORY_SHADER_LOOP_LIMIT=4096, which only changes shaders.
  • Two of the runs above were sampled, and sampling slows them.
  • No device removal and no new warnings in either run.

Tests. cargo test --locked -p victory-gpu --lib -- --test-threads=1 on this PR: 198 passed, 0 failed, 1 ignored. That includes the three new tests, on hardware.

AI-assisted (Claude Code); every run was on this machine. Only timings and VIctory's own function names are posted, no game files.

**@⁠tumbubu** on GitHub · 2026-11-25 21:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/1865#issuecomment-7175256160) **`f9b27fd` in the world on an RX 7900 XT (RDNA3): the bitmap scan this PR rewrites is about 8% of the submission thread's wall time on `main`, and absent with this PR. Tests: 198 passed.** - **Setup:** AMD Radeon RX 7900 XT, driver 32.0.31036.15, Windows 11 Pro 26300. - **Builds:** diag builds (`--profile diag --features diagnostics`) of `main` `13f91ca` and of this PR, which is `13f91ca` plus `f9b27fd`. - **Runs:** warm shader cache and pipeline library, 180 s each, Enter every 3 s from 8 s to 47 s, `VICTORY_LOG=info`. **Where the time goes.** I sampled with `VICTORY_STACKS`, a dump every 0.25 s from 105 s to 175 s, in the world. A dump of 96 threads takes about 1 s, so that came to 74 dumps on `main` and 47 here. I symbolised `victory.exe` frames from the build's PDB. The thread that runs `queue::pump` → `Host::execute` is the busy one. The title's threads are waiting in almost every dump. | submission thread | `main` | this PR | |---|---:|---:| | busy (not in a wait) | 46 of 74 | 24 of 46 | | leaf in `memory::bind`'s `defer_missed` closure (the old `(0..32).filter` scan) | **6** | **0** | | leaf in `ZwReadVirtualMemory` (refresh copies, not touched here) | 9 | 11 | - If the closure still held its 8% share, 0 hits in 46 samples would come up about 2% of the time. - A standalone copy of the old and new scans, over a 513-block bitmap with four marked pages, takes 775 µs and 14 µs per call (`rustc -O`, Ryzen host). The `main` samples are consistent with roughly 80 such scans in a ~760 ms frame. **Frame lines** (world: frame-rate lines under 10 fps with at least 500 draws): | run | fps | ms/frame | preparing | on the GPU | copying back | draws/frame | |---|---:|---:|---:|---:|---:|---:| | `main`, 3 runs | 1.53 / 1.54 / 1.66 | 918 / 760 / 712 | 379 / 414 / 409 | 199 / 202 / 178 | 93 / 107 / 86 | 3913 / 3535 / 4370 | | this PR, 2 runs | 1.72 / 1.83 | 686 / 685 | 373 / 366 | 194 / 191 | 91 / 91 | 3782 / 3723 | - The frame times favour the PR. But `main` alone ranges from 712 to 918 ms here, so I do not claim a frame-level number. The samples are the measurement. - One `main` run, the 712 ms one, had `VICTORY_SHADER_LOOP_LIMIT=4096`, which only changes shaders. - Two of the runs above were sampled, and sampling slows them. - No device removal and no new warnings in either run. **Tests.** `cargo test --locked -p victory-gpu --lib -- --test-threads=1` on this PR: 198 passed, 0 failed, 1 ignored. That includes the three new tests, on hardware. AI-assisted (Claude Code); every run was on this machine. Only timings and VIctory's own function names are posted, no game files.
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!1865
No description provided.