D3D12.X: leave no free granule next to the driver heap's hole, and no one-granule remake #2991
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2991"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by Prime1997 on 2026-11-27T09:20:08Z.
Requested by Prime
Two boundary cases of #2977's grooming, reported on that PR after it merged (thanks to the reviewer who followed up):
What is in it
crates/xcl/src/hle/d3d12x/uma_driver.rs:groomreserves the hole's own stretch up to the hole;groom_margin;remakerefuses a one-granule window before releasing it.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 (0x7ff490740000for a hole at0x7ff490750000, checked by running the test against the old code).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
cargo test --locked --workspace --no-fail-fast -- --test-threads=4withXCL_DXC_DIRset to DXC 1.9.2609.5: 1457 passed, 3 failed, 47 ignored. The 3 failures are tests that fail onmain623d02e4itself (1455passed,3failed,47ignored 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.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):This PR's head (with
XCL_PREPARE=0, the switch of #2976):Not tested
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
Imported from ivall/xcl. Originally posted by Prime1997 on 2026-11-27T09:22:53Z.
@thehollowedone Pushed this for you.
Plz review.
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-27T09:32:44Z.
Independent RTX 3080 Ti check of #2991 head
a497d8fcagainst its current-mainparent623d02e4. 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 --workspacepassed;cargo test --offline --locked -j 4 --workspace --no-fail-fast -- --test-threads=4ran all 38 test binaries: 1,460 passed, 0 failed, 47 ignored, 25 GPU skip notices.XCL_DXIL_CACHEpointed 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.ps1for 60 seconds on clean release builds of the same title, GPU and settings, withXCL_PREPARE=0on both. These are the script's generated blocks:main623d02e4#2991
a497d8fcThe 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_holecurrently asksVirtualAlloc(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--exactmatching zero tests from looking like success.Test-only diff for the address invariant
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.
Imported from ivall/xcl. Originally posted by LocranKing on 2026-11-27T13:59:54Z.
Tested PR #2991 (
a497d8fc) on Windows 11 (Ryzen 5 5500, 32 GB RAM, NVIDIA GeForce RTX 3060 Ti 8 GB, driver32.0.16.2140).Unit tests (
uma_driver)Ran
cargo test --locked -p xcl --lib -- uma_driver -- --test-threads=1 --nocaptureona497d8fc:driver_windows_by_default_on_nvidia_outside_wine— oka_one_granule_window_is_left_as_it_is— okfailed_write_watch_does_not_release_the_original_window— okfailed_restore_stops_before_importing_an_unbacked_window— okgrooming_leaves_a_window_under_1_gib_only_its_hole— okgrooming_leaves_no_free_granule_next_to_the_hole— okSmoke check (
180 s,lockhart,XCL_PREPARE=0,XCL_DIRECT_DXIL=all)#2991(a497d8fc): Remapped the coherent window cleanly (D3D12.X: the coherent window at 0x700000000 (512 MB) is a driver CUSTOM write-back L0 heap mapped at its address, write-watched (135 reservations, 0 pages kept, 0 KB, 53 ms)),exit: 0x0,0crashes,0device removals,1240frames (PresentX 1240), peak commit26954 MB, local13864 MB, non-local1852 MB(vsorigin/main06f90c19:1236frames,exit: 0x0, peak commit27336 MB, local14032 MB). Both reached loading (0crashes onuma_driverstartup) under defaultmaintexture settings.Imported from ivall/xcl. Originally posted by bmjask on 2026-11-29T22:46:00Z.
Review: COMMENTED
Critical review of current head
a497d8fc. I found no runtime blocker in the two UMA grooming boundary changes: both close holes that can let a window-sized mapping collide with the driver's reserved range. The branch now conflicts with current main, so the critical next step is a rebase that preserves the updated range arithmetic, followed by tests at both sides of the hole and the one-granule remake case. Existing Windows tests on an earlier main were green, but they do not validate the conflicted merge result. No local Windows run.Imported from ivall/xcl. Originally posted by saintwolf on 2026-11-30T02:16:06Z.
Reviewed and tested current head
700087f3(after themainmerge).Blocking finding from the merge commit (
700087f3)groom_withignores itsheadroomparameter — breaks mixed-segment UMA grooming (crates/xcl/src/hle/d3d12x/uma_driver.rs:125-145):let (least, margin) = (len.min(1 << 30), groom_margin(len));insidegroom_withand usedmargininstead of theheadroomargument (also introducing two compiler warnings:unused variable: headroomat line 125 andunused variable: leastat line 127).remake_mixedonmaincallsgroom_with(base, size, min_seg, (16 << 20).min(min_seg / 4)). For a 512 MiB window with a 64 MiBmin_seg,remake_mixedexpectsheadroom = 16 MiB, butgroom_withnow overrides it withgroom_margin(512 MiB) = 256 MiB, leaving 256 MiB unreserved at the start of every stretch (and reserving nothing in stretches between 64 MiB and 256 MiB), which breaksremake_mixed's placement guarantee.let (least, margin) = ...;, useheadroomdirectly ingroom_with, and havegroom(hole, len)callgroom_with(hole, len, len.min(1 << 30), groom_margin(len)).b + marginregression:mainused((base + 0xFFFF) & !0xFFFF).saturating_add(headroom);700087f3reverted that to uncheckedb + margin. Restoringsaturating_add(headroom)avoids overflow edge cases.Non-blocking notes
maininstead of keeping the700087f3merge commit.@thehollowedone's earlier suggestion ongrooming_leaves_no_free_granule_next_to_the_hole(directly assertingreserve(hole - G, LEN) == 0andreserve(hole, LEN) == holewith a non-zero child exit code) is still worth folding in.Tested locally (
700087f3)32.0.16.2140), AMD Ryzen 7 7800X3D,rustc 1.100.0.cargo test -p xcl --lib hle::d3d12x::uma_driver::tests -- --test-threads=1 --nocapture: 10 passed, 0 failed (with the two newunused_variableswarnings inuma_driver.rs:125,127).AI use
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-30T03:28:40Z.
Agreed with Saintwolf’s current-head review. It identifies two regressions in merge commit
700087f:groom_withignores its caller-providedheadroom, and the checked start-address calculation was replaced with unchecked addition.I prepared and locally tested this candidate against
700087f. It restores the per-stretch headroom contract and saturating address calculation, with a regression covering a 512 MiB window, 64 MiB mixed segments, and 16 MiB headroom.Candidate patch
Focused verification on the exact head:
cargo test --offline --locked -j 4 -p xcl --lib hle::d3d12x::uma_driver::tests -- --test-threads=1 --nocapture— 11 passed, 0 failed, 0 ignored, 0 skipped. The workspace suite and retail smoke were not run on this candidate; this is a focused proposed fix, not a merge-readiness report.AI use: Codex (GPT-6.2 Sol) prepared the candidate and ran the focused test.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:48:59Z.
Review (head
700087f3, diff read, not a merge-check:Build and testandPR descriptionfail, so not built or run here):XCL_UMA_DRIVER=mixed.groom_with(uma_driver.rs~125-143) now ignores itsheadroomargument and usesgroom_margin(len)for the whole window, andleastis unused (CI warns about both).remake_mixed(~483) passes 16 MiB of headroom and now gets up to 256 MiB, so a segment can be mapped outside the window: CI failsmixed_window_keeps_its_bytes_and_the_gpu_sees_every_segmentanda_refused_gpu_upload_segment_becomes_customwith "Map gave 0x1783ca00000, wanted 0x17840b10000", both green on main. Useheadroomfor stretches that don't hold the hole, or give the mixed caller its own margin. The original commita497d8fchad nogroom_with; the merge applied the new margin to the mixed caller too.groom_withstill describesheadroom. The smoke block namesa497d8fc, not the head (whyPR descriptionfails), and the suite results predate the merge.Fine: reserving the hole's stretch right up to the hole while keeping the margin only when the part before it is longer, refusing a one-granule window before it's released, and the subprocess test for that edge case.
AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T17:19:42Z.
Test report (not a merge-check:
, wanted ". Correction to an earlier version of this comment: the same failure also hit #3377 and, once, #3318 (which doesn't touch heaps), and two full runs of main passed, so it is intermittent on this machine and not clearly caused by this PR. A few local runs ofPR descriptionred)base:
b2b1f109d2head:
700087f349merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2902 passed, 2 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: hle::d3d12x::uma_driver::tests::a_refused_gpu_upload_segment_becomes_custom, hle::d3d12x::uma_driver::tests::mixed_window_keeps_its_bytes_and_the_gpu_sees_every_segment
review: not repeated here; my review of this same head is at https://github.com/xcl-dev/xcl/pull/2991#issuecomment-7302167581, and its findings stand. This run adds what reading couldn't: whether the change merges, builds and passes the whole suite on current main.
performance: no smoke run.
assessment: 2 tests failed in this run:
uma_driver::tests::a_refused_gpu_upload_segment_becomes_custom(uma_driver.rs~830) andmixed_window_keeps_its_bytes_and_the_gpu_sees_every_segment(~776), both "remake_mixed: segment 0 (64 MB CUSTOM): Map gavecargo test -p xcl --lib uma_driveron this head would settle it. The rest of the suite passes, and the findings in my review stand.hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T16:17:17Z.
merge-check
base:
16c2fd082ahead:
700087f349merge: clean
build: ok
tests: 3014 passed, 0 failed, 56 ignored; 28 skipped, the same as on main
review: 1 high, 2 medium, 1 nit (below)
performance: 60 s smoke run: 1683 → 1664 frames (98 % of main), peak commit 18505 → 18323 MB, no device removal, no crash
title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 231 s there, 0 device removals, 0 crashes, 2.7 presents/s; run with
XCL_SKIP_CS=95cc13288a27a96e(the NVIDIA hang at the end of loading, #3541) and NVIDIA's 2048 MB shader heap (#2590)verdict: not yet: 1 blocking finding (critical or high, below); also
PR descriptionis redhardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
In short: Two boundary fixes to the UMA driver-heap grooming: no free granule is left next to the hole, and a one-granule window is no longer remade. The head is the same
700087f3as in my earlier review, and the merge of main inside it makes groom_with ignore its headroom argument. That breaks XCL_UMA_DRIVER=mixed and fails two tests in the required CI check, which blocks it.High
700087f3, groom_with (uma_driver.rs ~125-143) computesmargin = groom_margin(len)and never uses itsheadroomargument (leastis unused too; CI warns about both, and the doc comment still describes headroom). remake_mixed (~483) passes 16 MiB of headroom but gets up to 256 MiB, so a segment can be mapped outside the window. The required Build and test check fails mixed_window_keeps_its_bytes_and_the_gpu_sees_every_segment and a_refused_gpu_upload_segment_becomes_custom ("Map gave 0x1783ca00000, wanted 0x17840b10000"). On this run both tests passed on this card; whether they fail depends on where the groomed window lands, so a green local run does not clear this. Useheadroomin groom_with and have groom pass groom_margin(len); thehollowedone's candidate patch on the PR does this and adds a regression test.Medium
700087f3is where the bug above came in. Rebasea497d8fconto main and resolve groom_with by hand.--exactwith a name that matches no test also exits 0. Use a distinct exit code, and assert directly that reserve(hole - G, LEN) fails and reserve(hole, LEN) succeeds (thehollowedone's suggestion).Nit
.saturating_add(headroom)becameb + margin(~141, ~143). No overflow is reachable on x64, but restore it with the fix above.Checked and fine
How this was tested
16c2fd08, thencargo build --workspaceandcargo test --workspace --no-fail-fast -- --test-threads=4.scripts/smoke.ps1: 60 s of a retail title on main16c2fd08and on this merge; presents per 2 s at the end: 60 60 60.XCL_RUN_SECONDS=300and scripted A presses counted from the first frame (XCL_PRESS_BASE=frame, #3712) into the world from an existing save; time in the world is counted from the first in-world draw call to the end of the run.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.