KernelX: batch contiguous scatter unmap home-page commits #1184

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

@⁠TG0000 on GitHub · 2026-11-24 12:56 UTC · original
TG0000:perf/scatter-unmap-home-runs → main · +178 −3 · 2 files · 1 commits · open

XMemMapPhysicalPagesScatter takes each unmapped page home on its own: one VirtualAlloc, one VirtualQuery and, in a sparse window, one UpdateTileMappings + Signal per 64 KiB page. A retail game unmaps 4136 and then 6720 pages in two calls while it loads, and the homes of each call are one run of neighbours. The parts of a call that only unmap now commit their homes ahead in runs.

What is in it

  • kernelx.rs: commit_homes_ahead, for at most 1024 pages (64 MiB) at a time. Homes already committed go page by page as before; a call that fails part way gives back the homes no page went to. Mapping pages is unchanged.
  • kernelx/lazy.rs: is_marked.
  • Three tests. Removing the state check, the lazy check or the give-back makes one of them fail (the state check: an access violation).

Tested

  • RX 6800, driver 32.0.21045.29003; Ryzen 9 5900X; Windows 11 Pro 26300; Rust 1.100.0 MSVC. Debug tests; release smoke runs.
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 741 passed, 3 failed, 41 ignored. The same 3 fail on clean main 47efa2e (738 passed, 3 failed, 41 ignored): placed_title_textures_share_vram_and_preserve_pixels reads zero in a 3D mip (#1028 describes it), and transitions_apply_when_their_list_is_submitted and d32s8_targets_take_their_own_size_of_video_memory find the mutex it poisoned. The test output had no SKIPPED lines, but captured output of passing tests is not shown.
  • The two calls in the title, with a timer around them (two 30 s runs each, order main, PR, PR, main; other builds were running on the PC during them):
main main PR PR
4136 pages 1539 ms 1393 ms 196 ms 258 ms
6720 pages 1689 ms 1342 ms 183 ms 281 ms
last video-memory arena before the first menu, s after start 20.2 20.8 18.5 19.3
  • The two smoke runs below reach that last point at 21.0 s (main) and 19.5 s (PR). It is load time only: the menu's frame rate is the title's 30 fps in both, and frames shown are the same within noise.

Regression run

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: AMD Radeon RX 6800
title: retail-title-1.0.2.1
seconds: 45
exit: 0x0
frames shown: 1031 (PresentX 1031)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15103 MB

PR:

xcl-smoke v1
commit: 3b54c24f571b27b55a6b3053db094c513b6c44ca
gpu: AMD Radeon RX 6800
title: retail-title-1.0.2.1
seconds: 45
exit: 0x0
frames shown: 1029 (PresentX 1029)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15106 MB

Not tested

  • NVIDIA, Intel, Wine, past the first menus; a quiet PC for the timings.
  • Unmapping through XMemMapPhysicalPages without a page array, and scatters that map and unmap in one part, still go page by page.
  • #495 and #934 change lines next to these and will need a small manual merge.

AI use

  • Claude Code in T3 Code with Claude Opus 5.5 profiled the title, wrote the change and the tests, ran everything above and wrote this description.
**@⁠TG0000** on GitHub · 2026-11-24 12:56 UTC · [original](https://github.com/xcl-dev/xcl/pull/1184) `TG0000:perf/scatter-unmap-home-runs` → `main` · +178 −3 · 2 files · 1 commits · open `XMemMapPhysicalPagesScatter` takes each unmapped page home on its own: one `VirtualAlloc`, one `VirtualQuery` and, in a sparse window, one `UpdateTileMappings` + `Signal` per 64 KiB page. A retail game unmaps 4136 and then 6720 pages in two calls while it loads, and the homes of each call are one run of neighbours. The parts of a call that only unmap now commit their homes ahead in runs. **What is in it** - `kernelx.rs`: `commit_homes_ahead`, for at most 1024 pages (64 MiB) at a time. Homes already committed go page by page as before; a call that fails part way gives back the homes no page went to. Mapping pages is unchanged. - `kernelx/lazy.rs`: `is_marked`. - Three tests. Removing the state check, the lazy check or the give-back makes one of them fail (the state check: an access violation). **Tested** - RX 6800, driver 32.0.21045.29003; Ryzen 9 5900X; Windows 11 Pro 26300; Rust 1.100.0 MSVC. Debug tests; release smoke runs. - `cargo test --workspace --no-fail-fast -- --test-threads=4`: 741 passed, 3 failed, 41 ignored. The same 3 fail on clean main 47efa2e (738 passed, 3 failed, 41 ignored): `placed_title_textures_share_vram_and_preserve_pixels` reads zero in a 3D mip (#1028 describes it), and `transitions_apply_when_their_list_is_submitted` and `d32s8_targets_take_their_own_size_of_video_memory` find the mutex it poisoned. The test output had no SKIPPED lines, but captured output of passing tests is not shown. - The two calls in the title, with a timer around them (two 30 s runs each, order main, PR, PR, main; other builds were running on the PC during them): | | main | main | PR | PR | |---|---|---|---|---| | 4136 pages | 1539 ms | 1393 ms | 196 ms | 258 ms | | 6720 pages | 1689 ms | 1342 ms | 183 ms | 281 ms | | last video-memory arena before the first menu, s after start | 20.2 | 20.8 | 18.5 | 19.3 | - The two smoke runs below reach that last point at 21.0 s (main) and 19.5 s (PR). It is load time only: the menu's frame rate is the title's 30 fps in both, and frames shown are the same within noise. **Regression run** main: ``` xcl-smoke v1 commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3 gpu: AMD Radeon RX 6800 title: retail-title-1.0.2.1 seconds: 45 exit: 0x0 frames shown: 1031 (PresentX 1031) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15103 MB ``` PR: ``` xcl-smoke v1 commit: 3b54c24f571b27b55a6b3053db094c513b6c44ca gpu: AMD Radeon RX 6800 title: retail-title-1.0.2.1 seconds: 45 exit: 0x0 frames shown: 1029 (PresentX 1029) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15106 MB ``` **Not tested** - NVIDIA, Intel, Wine, past the first menus; a quiet PC for the timings. - Unmapping through `XMemMapPhysicalPages` without a page array, and scatters that map and unmap in one part, still go page by page. - #495 and #934 change lines next to these and will need a small manual merge. **AI use** - Claude Code in T3 Code with Claude Opus 5.5 profiled the title, wrote the change and the tests, ran everything above and wrote this description.
XMemMapPhysicalPagesScatter takes each unmapped page home on its own: one
VirtualAlloc, one VirtualQuery and, in a sparse window, one
UpdateTileMappings and one Signal per 64 KiB page. A retail game unmaps
4136 and then 6720 pages in two calls while it loads, and the homes of
each call are one run of neighbours: 2.7-3.2 s in those two calls, the
larger part in the tile mappings.

The parts of a call that only unmap (1024 pages, 64 MiB, at a time) now
commit their homes ahead, a run of neighbouring pages per VirtualAlloc and
per sparse::committed. Homes that are committed already, or cannot be,
still go page by page, and a call that fails part way gives back the homes
no page went to. The two calls take 0.4-0.5 s.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:46:20 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 13:14 UTC · original

Independent verification on current main 384f7f7 (branch already contains it — clean).

Machine: Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug.

  • cargo test -p xcl --lib kernelx: 35 passed, 0 failed, 1 ignored — includes the new a_scatter_that_unmaps_commits_homes_in_runs covering the batched home-page commits.

AI use: test runs by Devin (Cognition, SWE-2); no code changes.

**@⁠DavidM1911** on GitHub · 2026-11-24 13:14 UTC · [original](https://github.com/xcl-dev/xcl/pull/1184#issuecomment-7132549851) Independent verification on current `main` `384f7f7` (branch already contains it — clean). **Machine:** Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug. - `cargo test -p xcl --lib kernelx`: **35 passed, 0 failed, 1 ignored** — includes the new `a_scatter_that_unmaps_commits_homes_in_runs` covering the batched home-page commits. AI use: test runs by Devin (Cognition, SWE-2); no code changes.
Author
Owner

@⁠fromthemoonx on GitHub · 2026-11-24 14:30 UTC · original

Whole-suite NVIDIA run, to go with the kernelx run above.

Tested

  • NVIDIA GeForce RTX 3060 12 GB, driver 32.0.16.1088; AMD Ryzen 7 5700X; native Windows 11 Pro 26H2 (build 26300.9974), Graphics Tools (D3D12 debug layer) installed; rustc 1.100.0 stable-x86_64-pc-windows-msvc
  • Exact head 3b54c24f571b27b55a6b3053db094c513b6c44ca (on its base 47efa2e), cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4:
    • debug: 744 passed, 0 failed, 41 ignored. The three tests that fail in your RX 6800 runs pass here, as on main.
    • release (cargo build --release --workspace first): 744 passed, 0 failed, 41 ignored
  • Merged onto current main 930e8b4 (no conflict), debug: 754 passed, 0 failed, 41 ignored
  • Two checks of the new tests:
    • Without the lazy check (.filter(|_| !lazy::is_marked(at)) removed), a_scatter_that_unmaps_commits_homes_in_runs fails with left: 2, right: 4.
    • Without commit_homes_ahead being called (main's page-by-page path), a_scatter_that_unmaps_commits_homes_in_runs and a_home_another_page_is_mapped_at_is_not_committed_ahead fail.
    • I did not try your state check or give-back mutations.
  • hle::kernelx tests, 10 runs: 10 of 10 passed (34 passed, 1 ignored each)
  • D3D12 debug layer: on the merged tree, the e2e test title logs the same debug-layer error and warning ids as main 930e8b4. At the head itself it also logs id 538, which is #958, fixed on main since your base.
  • SKIPPED (no wave64 on this adapter): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware

Not tested

  • The load-time saving: no retail title here, and the PR ships no benchmark, so I measured no timings.

AI use

  • Claude Code (Claude Opus 5.5) ran the builds, tests and the two checks on the machine above, and wrote this report from the output.
**@⁠fromthemoonx** on GitHub · 2026-11-24 14:30 UTC · [original](https://github.com/xcl-dev/xcl/pull/1184#issuecomment-7134493239) Whole-suite NVIDIA run, to go with the `kernelx` run above. **Tested** - NVIDIA GeForce RTX 3060 12 GB, driver 32.0.16.1088; AMD Ryzen 7 5700X; native Windows 11 Pro 26H2 (build 26300.9974), Graphics Tools (D3D12 debug layer) installed; rustc 1.100.0 `stable-x86_64-pc-windows-msvc` - **Exact head `3b54c24f571b27b55a6b3053db094c513b6c44ca`** (on its base `47efa2e`), `cargo build --workspace`, then `cargo test --workspace --no-fail-fast -- --test-threads=4`: - debug: **744 passed, 0 failed, 41 ignored**. The three tests that fail in your RX 6800 runs pass here, as on `main`. - release (`cargo build --release --workspace` first): **744 passed, 0 failed, 41 ignored** - **Merged onto current `main` `930e8b4`** (no conflict), debug: **754 passed, 0 failed, 41 ignored** - Two checks of the new tests: - Without the lazy check (`.filter(|_| !lazy::is_marked(at))` removed), `a_scatter_that_unmaps_commits_homes_in_runs` fails with `left: 2, right: 4`. - Without `commit_homes_ahead` being called (`main`'s page-by-page path), `a_scatter_that_unmaps_commits_homes_in_runs` and `a_home_another_page_is_mapped_at_is_not_committed_ahead` fail. - I did not try your state check or give-back mutations. - `hle::kernelx` tests, 10 runs: **10 of 10 passed** (34 passed, 1 ignored each) - D3D12 debug layer: on the merged tree, the e2e test title logs the same debug-layer error and warning ids as `main` `930e8b4`. At the head itself it also logs id 538, which is #958, fixed on `main` since your base. - SKIPPED (no wave64 on this adapter): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware` **Not tested** - The load-time saving: no retail title here, and the PR ships no benchmark, so I measured no timings. **AI use** - Claude Code (Claude Opus 5.5) ran the builds, tests and the two checks on the machine above, and wrote this report from the output.
Author
Owner

@⁠JoaoPauluu on GitHub · 2026-11-24 14:34 UTC · original

A run on Linux under Wine.

Tested

  • RTX 3060 12 GB (NVIDIA 620.70.06, 32-lane waves), i5-10400F, 16 GB, CachyOS (kernel 7.3.3), Proton Experimental 11.0-20261112 with the patched vkd3d-proton 3.1 from #257, DXC 1.9.2609.5. Release, cross-built for x86_64-pc-windows-gnu. 3b54c24 as it is (based on 47efa2e), no uncommitted changes. The lib test binary runs under Wine, one test per process (--exact). The commit and decommit calls under kernelx are Wine's here.
  • hle::kernelx::tests::a_home_another_page_is_mapped_at_is_not_committed_ahead: ok, no SKIPPED.
  • hle::kernelx::tests::a_scatter_refused_part_way_gives_its_homes_back: ok, no SKIPPED.
  • hle::kernelx::tests::a_scatter_that_unmaps_commits_homes_in_runs: ok, no SKIPPED.

Not tested

  • whether the new tests fail without the change on this stack; the rest of the suite on this head; a retail title; native Windows.

AI use

  • Claude Code (Claude Opus 5.5) built the head, ran the tests and wrote this report. The account owner asked for test reports to be posted and has not reviewed this one.
**@⁠JoaoPauluu** on GitHub · 2026-11-24 14:34 UTC · [original](https://github.com/xcl-dev/xcl/pull/1184#issuecomment-7134608556) A run on Linux under Wine. **Tested** - RTX 3060 12 GB (NVIDIA 620.70.06, 32-lane waves), i5-10400F, 16 GB, CachyOS (kernel 7.3.3), Proton Experimental 11.0-20261112 with the patched vkd3d-proton 3.1 from #257, DXC 1.9.2609.5. Release, cross-built for `x86_64-pc-windows-gnu`. `3b54c24` as it is (based on `47efa2e`), no uncommitted changes. The lib test binary runs under Wine, one test per process (`--exact`). The commit and decommit calls under kernelx are Wine's here. - `hle::kernelx::tests::a_home_another_page_is_mapped_at_is_not_committed_ahead`: **ok**, no SKIPPED. - `hle::kernelx::tests::a_scatter_refused_part_way_gives_its_homes_back`: **ok**, no SKIPPED. - `hle::kernelx::tests::a_scatter_that_unmaps_commits_homes_in_runs`: **ok**, no SKIPPED. **Not tested** - whether the new tests fail without the change on this stack; the rest of the suite on this head; a retail title; native Windows. **AI use** - Claude Code (Claude Opus 5.5) built the head, ran the tests and wrote this report. The account owner asked for test reports to be posted and has not reviewed this one.
Author
Owner

@⁠thehollowedone on GitHub · 2026-11-25 10:09 UTC · original · edited 2026-11-25 10:31 UTC

Independent Windows run on 3b54c24. Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35), Rust 1.99.1 MSVC, DXC 1.8.2502.11.

cargo build --workspace --offline --locked -j 4 passed. cargo test --workspace --offline --locked --no-fail-fast -j 4 -- --nocapture --test-threads=4 finished with 744 passed, 0 failed, 41 ignored, including two wave64 runtime skips in Cargo’s pass count.

A synthetic release fixture timed only XMemMapPhysicalPagesScatter on the native D3D12 sparse backing. Both paths ran in the same binary, with a test-only switch disabling the ahead-of-time commits for the page-by-page control. Each case used four samples per path in alternating order, with fresh mappings and validation outside the timed interval.

Pages Page by page, median (range) Batched, median (range) Median speedup
4,136 351.2 ms (335.4–358.4) 131.7 ms (130.9–137.0) 2.67×
6,720 618.6 ms (593.7–632.0) 216.4 ms (212.4–229.5) 2.86×

The batched path issued five and seven ahead-of-time commit ranges respectively. Both paths copied every page back and verified exact markers at the first and last word of each page across all 16 samples. cargo test --release --offline --locked -j 4 -p xcl --lib local_scatter_home_batch_timing -- --nocapture --test-threads=1 passed 1 of 1 without skips. These timings cover the synthetic unmap call.

Retail startup follow-up. I used one release binary built from main 568e7db with 3b54c24 applied and the same local guards and timing hooks in both arms. The control disabled only the ahead-of-time commits. Both runs started offline from separate copies of the same profile and cache seed, with no input. Each call completed successfully.

Pages Page by page Batched Speedup
4,136 375.2 ms 148.2 ms 2.53×
6,720 367.1 ms 146.9 ms 2.50×

One startup run per arm, page-by-page first. The implicit driver cache was uncontrolled. Both calls happened after the first frame. The comparison measures time inside those calls and leaves whole-load time and frame pacing unverified.

AI use: Codex (GPT-6, exact variant unspecified) wrote the scratch fixture and timing hook, ran the tests and drafted this report.

**@⁠thehollowedone** on GitHub · 2026-11-25 10:09 UTC · [original](https://github.com/xcl-dev/xcl/pull/1184#issuecomment-7159312832) · edited 2026-11-25 10:31 UTC Independent Windows run on [3b54c24](https://github.com/xcl-dev/xcl/commit/3b54c24f571b27b55a6b3053db094c513b6c44ca). Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35), Rust 1.99.1 MSVC, DXC 1.8.2502.11. `cargo build --workspace --offline --locked -j 4` passed. `cargo test --workspace --offline --locked --no-fail-fast -j 4 -- --nocapture --test-threads=4` finished with **744 passed, 0 failed, 41 ignored**, including two wave64 runtime skips in Cargo’s pass count. A synthetic release fixture timed only `XMemMapPhysicalPagesScatter` on the native D3D12 sparse backing. Both paths ran in the same binary, with a test-only switch disabling the ahead-of-time commits for the page-by-page control. Each case used four samples per path in alternating order, with fresh mappings and validation outside the timed interval. | Pages | Page by page, median (range) | Batched, median (range) | Median speedup | |---:|---:|---:|---:| | 4,136 | 351.2 ms (335.4–358.4) | 131.7 ms (130.9–137.0) | 2.67× | | 6,720 | 618.6 ms (593.7–632.0) | 216.4 ms (212.4–229.5) | 2.86× | The batched path issued five and seven ahead-of-time commit ranges respectively. Both paths copied every page back and verified exact markers at the first and last word of each page across all 16 samples. `cargo test --release --offline --locked -j 4 -p xcl --lib local_scatter_home_batch_timing -- --nocapture --test-threads=1` passed 1 of 1 without skips. These timings cover the synthetic unmap call. **Retail startup follow-up.** I used one release binary built from [main 568e7db](https://github.com/xcl-dev/xcl/commit/568e7db7729c8fa6c8f0f4b32d798faaf11462bb) with [3b54c24](https://github.com/xcl-dev/xcl/commit/3b54c24f571b27b55a6b3053db094c513b6c44ca) applied and the same local guards and timing hooks in both arms. The control disabled only the ahead-of-time commits. Both runs started offline from separate copies of the same profile and cache seed, with no input. Each call completed successfully. | Pages | Page by page | Batched | Speedup | |---:|---:|---:|---:| | 4,136 | 375.2 ms | 148.2 ms | 2.53× | | 6,720 | 367.1 ms | 146.9 ms | 2.50× | One startup run per arm, page-by-page first. The implicit driver cache was uncontrolled. Both calls happened after the first frame. The comparison measures time inside those calls and leaves whole-load time and frame pacing unverified. AI use: Codex (GPT-6, exact variant unspecified) wrote the scratch fixture and timing hook, ran the tests and drafted this report.
This pull request has changes conflicting with the target branch.
  • crates/xcl/src/hle/kernelx.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1184'
git switch 'github-bot/gh-1184'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1184'
git switch 'github-bot/gh-1184'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1184'
git switch 'main'
git merge --squash 'github-bot/gh-1184'
git switch 'main'
git merge --ff-only 'github-bot/gh-1184'
git switch 'main'
git merge 'github-bot/gh-1184'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.