D3D12.X: leave no free granule next to the driver heap's hole, and no one-granule remake #2991

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

@⁠Prime1997 on GitHub · 2026-11-27 09:20 UTC · original
Prime1997:contrib/uma-groom-boundaries → main · +87 −6 · 1 files · 1 commits · draft

Requested by Prime · project thread

Two boundary cases of #2977's grooming, reported on that PR after it merged (thanks to the reviewer who followed up):

  • In the free stretch that holds the window's hole, the left reservation started at the stretch's base plus the margin. When the stretch begins less than the margin below the hole, the granules between them stay free, and with the hole they make room for a window-sized mapping that starts before the window's address. That stretch is now reserved right up to the hole and from its end; its margin stays at its start only where the part before the hole is longer than the margin.
  • A window of one 64 KiB granule has no margin (half of it rounds to zero granules), so grooming reserved every other free stretch and left the driver no room for its own mappings. Such a window is not remade now and stays the title's memory.

What is in it

  • crates/xcl/src/hle/d3d12x/uma_driver.rs: groom reserves the hole's own stretch up to the hole; groom_margin; remake refuses a one-granule window before releasing it.
  • Test grooming_leaves_no_free_granule_next_to_the_hole (in a process of its own, as the other grooming test): one free granule below a 512 MB hole; a window-sized reservation after grooming lands at the hole. With the old pieces it landed one granule low (0x7ff490740000 for a hole at 0x7ff490750000, checked by running the test against the old code).
  • Test a_one_granule_window_is_left_as_it_is; the two restore tests (failed_write_watch_does_not_release_the_original_window, failed_restore_stops_before_importing_an_unbacked_window) use two granules, since one is not remade now and their failure paths would not be reached.

Tested

  • NVIDIA GeForce RTX 3060 Ti 8 GB (driver 32.0.16.1714), Intel Core i5-10400, Windows 11 26200, rustc 1.100.0; debug tests, release smoke.
  • cargo test --locked --workspace --no-fail-fast -- --test-threads=4 with XCL_DXC_DIR set to DXC 1.9.2609.5: 1457 passed, 3 failed, 47 ignored. The 3 failures are tests that fail on main 623d02e4 itself (1455 passed, 3 failed, 47 ignored there, same command): test_title_draws_with_a_root_signature_under_the_debug_layer, test_title_runs_and_game_folder_is_untouched, test_title_runs_under_the_debug_layer_with_dred.
  • SKIPPED on this adapter: 27 (no wave64: 21, per-lane f16 form refused: 3, no dxc.exe: 1, cannot disable the driver cache (Windows Developer Mode is required): The application requested an operation that depend: 1, no heap windows: 1).

Regression run
A commit of main (b49be183, the last one before the shader preparation of #2555, which prepares every record before the title and does not fit a 60 s run):

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 3060 Ti
title: 419239bf
seconds: 60
exit: 0x0
frames shown: 363 (PresentX 363)
presents per 2 s (last 3): 16 17 16
device removals: 0
crashes: 0
peak commit: 15320 MB

This PR's head (with XCL_PREPARE=0, the switch of #2976):

xcl-smoke v1
commit: a497d8fc0649785bd8a77d9947383a85828a55f8
gpu: NVIDIA GeForce RTX 3060 Ti
title: 419239bf
seconds: 60
exit: 0x0
frames shown: 319 (PresentX 319)
presents per 2 s (last 3): 13 13 13
device removals: 0
crashes: 0
peak commit: 15055 MB

Not tested

  • Either case in a title run: neither was seen in a retail title; the coherent window is 512 MB or more there.
  • AMD (the remake is for NVIDIA), Wine.

AI use
Claude Code (Claude Opus 5.5) wrote the code, ran the suite and the regression runs on the hardware above, and wrote this description; Prime asked for it and owns the account. We coordinate the 8 GB work on the XCL Discord too: https://discord.gg/6B4TykyC4W

🤖 Generated with Claude Code

**@⁠Prime1997** on GitHub · 2026-11-27 09:20 UTC · [original](https://github.com/xcl-dev/xcl/pull/2991) `Prime1997:contrib/uma-groom-boundaries` → `main` · +87 −6 · 1 files · 1 commits · draft <!-- claude-projects-attribution: {"github_login":"Prime1997"} --> _Requested by **Prime** · [project thread](https://claude.ai/code/project/chan_014ndQaTcZS9FWDAjYnDD1nA?thread=cmsg_014ndQaTcZS9FWDAjYnDD1nAWExb2NNMvZydbxWCtgmJcT)_ Two boundary cases of #2977's grooming, reported on that PR after it merged (thanks to the reviewer who followed up): - In the free stretch that holds the window's hole, the left reservation started at the stretch's base plus the margin. When the stretch begins less than the margin below the hole, the granules between them stay free, and with the hole they make room for a window-sized mapping that starts before the window's address. That stretch is now reserved right up to the hole and from its end; its margin stays at its start only where the part before the hole is longer than the margin. - A window of one 64 KiB granule has no margin (half of it rounds to zero granules), so grooming reserved every other free stretch and left the driver no room for its own mappings. Such a window is not remade now and stays the title's memory. **What is in it** - `crates/xcl/src/hle/d3d12x/uma_driver.rs`: `groom` reserves the hole's own stretch up to the hole; `groom_margin`; `remake` refuses a one-granule window before releasing it. - Test `grooming_leaves_no_free_granule_next_to_the_hole` (in a process of its own, as the other grooming test): one free granule below a 512 MB hole; a window-sized reservation after grooming lands at the hole. With the old pieces it landed one granule low (`0x7ff490740000` for a hole at `0x7ff490750000`, checked by running the test against the old code). - Test `a_one_granule_window_is_left_as_it_is`; the two restore tests (`failed_write_watch_does_not_release_the_original_window`, `failed_restore_stops_before_importing_an_unbacked_window`) use two granules, since one is not remade now and their failure paths would not be reached. **Tested** - NVIDIA GeForce RTX 3060 Ti 8 GB (driver 32.0.16.1714), Intel Core i5-10400, Windows 11 26200, rustc 1.100.0; debug tests, release smoke. - `cargo test --locked --workspace --no-fail-fast -- --test-threads=4` with `XCL_DXC_DIR` set to DXC 1.9.2609.5: 1457 passed, 3 failed, 47 ignored. The 3 failures are tests that fail on `main` `623d02e4` itself (`1455` passed, `3` failed, `47` ignored there, same command): `test_title_draws_with_a_root_signature_under_the_debug_layer`, `test_title_runs_and_game_folder_is_untouched`, `test_title_runs_under_the_debug_layer_with_dred`. - SKIPPED on this adapter: 27 (no wave64: 21, per-lane f16 form refused: 3, no dxc.exe: 1, cannot disable the driver cache (Windows Developer Mode is required): The application requested an operation that depend: 1, no heap windows: 1). **Regression run** A commit of `main` (`b49be183`, the last one before the shader preparation of #2555, which prepares every record before the title and does not fit a 60 s run): ``` xcl-smoke v1 commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7 gpu: NVIDIA GeForce RTX 3060 Ti title: 419239bf seconds: 60 exit: 0x0 frames shown: 363 (PresentX 363) presents per 2 s (last 3): 16 17 16 device removals: 0 crashes: 0 peak commit: 15320 MB ``` This PR's head (with `XCL_PREPARE=0`, the switch of #2976): ``` xcl-smoke v1 commit: a497d8fc0649785bd8a77d9947383a85828a55f8 gpu: NVIDIA GeForce RTX 3060 Ti title: 419239bf seconds: 60 exit: 0x0 frames shown: 319 (PresentX 319) presents per 2 s (last 3): 13 13 13 device removals: 0 crashes: 0 peak commit: 15055 MB ``` **Not tested** - Either case in a title run: neither was seen in a retail title; the coherent window is 512 MB or more there. - AMD (the remake is for NVIDIA), Wine. **AI use** Claude Code (Claude Opus 5.5) wrote the code, ran the suite and the regression runs on the hardware above, and wrote this description; Prime asked for it and owns the account. We coordinate the 8 GB work on the XCL Discord too: https://discord.gg/6B4TykyC4W 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Two boundary cases of the grooming #2977 changed (reported on that PR after it merged):

- In the free stretch that holds the window's hole, the left reservation started at the
  stretch's base plus the margin. When the stretch began less than the margin before the hole,
  the granules between its base and the hole stayed free, and with the hole they made room for a
  window-sized mapping one granule before the window's address. Reproduced: with one free
  granule below a 512 MB hole, a window-sized reservation after grooming landed at hole - 64 KiB.
  The stretch that holds the hole is now reserved right up to it and from its end (the margin
  stays at the stretch's start only where the part before the hole is longer).
- A window of one 64 KiB granule has no margin (half of it rounds to zero granules), so grooming
  reserved every other free stretch and left the driver no room. Such a window is not remade
  now (it stays the title's memory); the two restore tests use two granules for that reason.

Tests: grooming_leaves_no_free_granule_next_to_the_hole (fails with the old pieces: the
reservation lands one granule low), a_one_granule_window_is_left_as_it_is.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 10:47:03 +00:00
Author
Owner

@⁠Prime1997 on GitHub · 2026-11-27 09:22 UTC · original

@⁠thehollowedone Pushed this for you.

Plz review.

**@⁠Prime1997** on GitHub · 2026-11-27 09:22 UTC · [original](https://github.com/xcl-dev/xcl/pull/2991#issuecomment-7214612367) @⁠thehollowedone Pushed this for you. Plz review.
Author
Owner

@⁠thehollowedone on GitHub · 2026-11-27 09:32 UTC · original

Independent RTX 3080 Ti check of #2991 head a497d8fc against its current-main parent 623d02e4. I reviewed the UMA change and found no runtime blocker. This is the same two boundary fixes as my #2977 follow-up, so I am not opening a duplicate PR.

Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35), Rust 1.99.1 MSVC, DXC 1.8.2502.11. On the clean PR head, cargo build --offline --locked -j 4 --workspace passed; cargo test --offline --locked -j 4 --workspace --no-fail-fast -- --test-threads=4 ran all 38 test binaries: 1,460 passed, 0 failed, 47 ignored, 25 GPU skip notices. XCL_DXIL_CACHE pointed to a writable temporary directory for this suite. cargo test --offline --locked -j 4 -p xcl --lib hle::d3d12x::uma_driver::tests -- --test-threads=1: 6 passed, 0 failed, 0 ignored, no skips.

I also ran scripts/smoke.ps1 for 60 seconds on clean release builds of the same title, GPU and settings, with XCL_PREPARE=0 on both. These are the script's generated blocks:

main 623d02e4

xcl-smoke v1
commit: 623d02e465a17497a757a4ce867f482b0a6c8f3b
gpu: NVIDIA GeForce RTX 3080 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1330 (PresentX 1330)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14961 MB

#2991 a497d8fc

xcl-smoke v1
commit: a497d8fc0649785bd8a77d9947383a85828a55f8
gpu: NVIDIA GeForce RTX 3080 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1317 (PresentX 1317)
presents per 2 s (last 3): 60 59 61
device removals: 0
crashes: 0
peak commit: 15003 MB

The head showed 99.0% of main's frames and 100.3% of its peak commit, within the PR limits. The blocks do not establish that either rare boundary case occurred in the title run or which screen it reached. Existing shader caches were retained; this is not a controlled cold shader timing result.

One non-blocking test improvement: grooming_leaves_no_free_granule_next_to_the_hole currently asks VirtualAlloc(NULL, LEN) where Windows chose to place the allocation. It can pass even if the wrong address is still available. I tested the more direct assertion below on the exact PR head: 1 passed, 0 failed, 0 ignored, no skip. It requires the allocation one granule before the hole to fail and the intended hole to succeed. The distinctive child exit code also prevents --exact matching zero tests from looking like success.

Test-only diff for the address invariant
diff --git a/crates/xcl/src/hle/d3d12x/uma_driver.rs b/crates/xcl/src/hle/d3d12x/uma_driver.rs
@@ -388,15 +388,17 @@ mod tests {
                 assert_eq!(guard, all);
                 let hole = all + 2 * G;
                 let got = groom(hole, LEN);
-                let p = reserve(0, LEN, 0);
+                let wrong = reserve(hole - G, LEN, 0);
+                assert_eq!(wrong, 0, "a window-sized mapping still fits before the hole");
+                let right = reserve(hole, LEN, 0);
+                assert_eq!(right, hole, "the intended hole is blocked");
                 ungroom(got);
-                for a in [p, guard] {
+                for a in [right, guard] {
                     if a != 0 {
                         VirtualFree(a as *mut c_void, 0, MEM_RELEASE);
                     }
                 }
-                println!("window reservation at {p:#x}, hole {hole:#x}");
-                std::process::exit(if p == hole { 0 } else { 1 });
+                std::process::exit(77);
             }
         }
@@ -405,7 +407,7 @@ mod tests {
             .output()
             .unwrap();
         let transcript = format!("{}{}", String::from_utf8_lossy(&output.stdout), String::from_utf8_lossy(&output.stderr));
-        assert_eq!(output.status.code(), Some(0), "{transcript}");
+        assert_eq!(output.status.code(), Some(77), "{transcript}");
     }

AI use: Codex (GPT-6.2 Sol) reviewed the diff, ran the builds, tests and smoke pair, and drafted this report. Codex (GPT-6.2 Astra) independently reviewed the low-level boundary logic.

**@⁠thehollowedone** on GitHub · 2026-11-27 09:32 UTC · [original](https://github.com/xcl-dev/xcl/pull/2991#issuecomment-7214807291) Independent RTX 3080 Ti check of [#2991 head `a497d8fc`](https://github.com/xcl-dev/xcl/commit/a497d8fc0649785bd8a77d9947383a85828a55f8) against its [current-`main` parent `623d02e4`](https://github.com/xcl-dev/xcl/commit/623d02e465a17497a757a4ce867f482b0a6c8f3b). I reviewed the UMA change and found no runtime blocker. This is the same two boundary fixes as my #2977 follow-up, so I am not opening a duplicate PR. Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35), Rust 1.99.1 MSVC, DXC 1.8.2502.11. On the clean PR head, `cargo build --offline --locked -j 4 --workspace` passed; `cargo test --offline --locked -j 4 --workspace --no-fail-fast -- --test-threads=4` ran all 38 test binaries: **1,460 passed, 0 failed, 47 ignored, 25 GPU skip notices**. `XCL_DXIL_CACHE` pointed to a writable temporary directory for this suite. `cargo test --offline --locked -j 4 -p xcl --lib hle::d3d12x::uma_driver::tests -- --test-threads=1`: **6 passed, 0 failed, 0 ignored, no skips**. I also ran `scripts/smoke.ps1` for 60 seconds on clean release builds of the same title, GPU and settings, with `XCL_PREPARE=0` on both. These are the script's generated blocks: **`main` `623d02e4`** ``` xcl-smoke v1 commit: 623d02e465a17497a757a4ce867f482b0a6c8f3b gpu: NVIDIA GeForce RTX 3080 Ti title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1330 (PresentX 1330) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14961 MB ``` **#2991 `a497d8fc`** ``` xcl-smoke v1 commit: a497d8fc0649785bd8a77d9947383a85828a55f8 gpu: NVIDIA GeForce RTX 3080 Ti title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1317 (PresentX 1317) presents per 2 s (last 3): 60 59 61 device removals: 0 crashes: 0 peak commit: 15003 MB ``` The head showed 99.0% of `main`'s frames and 100.3% of its peak commit, within the PR limits. The blocks do not establish that either rare boundary case occurred in the title run or which screen it reached. Existing shader caches were retained; this is not a controlled cold shader timing result. One **non-blocking test improvement**: `grooming_leaves_no_free_granule_next_to_the_hole` currently asks `VirtualAlloc(NULL, LEN)` where Windows chose to place the allocation. It can pass even if the wrong address is still available. I tested the more direct assertion below on the exact PR head: **1 passed, 0 failed, 0 ignored, no skip**. It requires the allocation one granule before the hole to fail and the intended hole to succeed. The distinctive child exit code also prevents `--exact` matching zero tests from looking like success. <details><summary>Test-only diff for the address invariant</summary> ```diff diff --git a/crates/xcl/src/hle/d3d12x/uma_driver.rs b/crates/xcl/src/hle/d3d12x/uma_driver.rs @@ -388,15 +388,17 @@ mod tests { assert_eq!(guard, all); let hole = all + 2 * G; let got = groom(hole, LEN); - let p = reserve(0, LEN, 0); + let wrong = reserve(hole - G, LEN, 0); + assert_eq!(wrong, 0, "a window-sized mapping still fits before the hole"); + let right = reserve(hole, LEN, 0); + assert_eq!(right, hole, "the intended hole is blocked"); ungroom(got); - for a in [p, guard] { + for a in [right, guard] { if a != 0 { VirtualFree(a as *mut c_void, 0, MEM_RELEASE); } } - println!("window reservation at {p:#x}, hole {hole:#x}"); - std::process::exit(if p == hole { 0 } else { 1 }); + std::process::exit(77); } } @@ -405,7 +407,7 @@ mod tests { .output() .unwrap(); let transcript = format!("{}{}", String::from_utf8_lossy(&output.stdout), String::from_utf8_lossy(&output.stderr)); - assert_eq!(output.status.code(), Some(0), "{transcript}"); + assert_eq!(output.status.code(), Some(77), "{transcript}"); } ``` </details> AI use: Codex (GPT-6.2 Sol) reviewed the diff, ran the builds, tests and smoke pair, and drafted this report. Codex (GPT-6.2 Astra) independently reviewed the low-level boundary logic.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/2991/head:github-bot/gh-2991'
git switch 'github-bot/gh-2991'

Merge

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