D3D12.X: XMemVirtualAlloc GPU heaps go to the coherent window again #3369

Merged
iggyvilla merged 1 commit from upstream-pr/3369 into amd-dev 2026-11-29 12:27:08 +00:00
iggyvilla commented 2026-11-29 10:43:15 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by iggyvilla on 2026-11-29T10:43:15Z.


Refs #3360.

If 108cbafa routed these heaps to the sparse windows on purpose, please close this PR (see the open question in #3360). I could not tell from its commit message, so this is the fix for the case where it was not intended.

108cbafa ("kernelx: decode XMemVirtualAlloc XMemFlags and refine graphics protection handling") makes xmem_virtual_alloc_flags add MEM_GRAPHICS to every XMemVirtualAlloc that has the XMemFlags graphics bit. The title's GPU heaps (four commits, about 4.4 GB, with GPU-accessible PAGE_GRAPHICS_* protections) then take the MEM_GRAPHICS -> sparse::alloc branch of VirtualAlloc and never reach the GPU-heap branch that puts them in the coherent window. On an 8 GB card that is video memory for every tile plus the CPU's copy (over the DXGI budget, with warnings), while the coherent window, still committed at its size stored from earlier runs, stays almost empty (64 of 4095 MB used; 3998 of 4095 MB before the commit). Peak commit in the 60 s smoke goes from 20.3 GB (merge-base 2c717a04) to 25 GB, which is why every PR measured on the new amd-dev fails pr_check.py's 1.25x commit rule.

What is in it

  • kernelx.rs: xmem_virtual_alloc_flags takes the protection; a commit (MEM_COMMIT) with a GPU-accessible PAGE_GRAPHICS_* protection and only the XMemFlags graphics bit gets no MEM_GRAPHICS, so it takes the GPU-heap path again (coherent window, or the sparse windows with XCL_COHERENT_HEAPS=sparse). Reservations, PAGE_GRAPHICS_NOACCESS-only commits and legacy XALLOC_ATTRIBUTES memory types keep MEM_GRAPHICS, and the rest of 108cbafa is unchanged.
  • Test asserts for the new cases in the existing XMemFlags test.

Tested
AMD RX 6650 XT 8 GB, Ryzen 7 5700X, Windows 11, rustc 1.100.0, head 23d0f365.

  • cargo test --lib hle::kernelx -- --test-threads=1: 86 passed, 0 failed, 1 ignored.
  • 60 s smoke on the unmodified amd-dev f33df5a7: peak commit 25,028 MB (1,429 frames; a second run 25,412 MB, 1,407 frames). With this change: 13,569 MB, 1,662 frames, no device removals, no crashes (blocks below).
  • The earlier version of the same change measured 14,480 MB and 1,667 frames.

Regression run
Both 60 s runs with scripts/smoke.ps1 -Seconds 60, XCL_PREPARE=0, same title and card, compute pipeline cache warmed with xcl pso-precompile --used. First main d8bd9a38, then this PR's head.

xcl-smoke v1
commit: d8bd9a38204667f3ca7dd9eeffcc2f1c937b07b0
gpu: AMD Radeon RX 6650 XT
title: 1778c2d9
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 15479 MB
xcl-smoke v1
commit: 23d0f365d06af6301fbf688787c59efb8d78bdf9
gpu: AMD Radeon RX 6650 XT
title: 1778c2d9
seconds: 60
exit: 0x0
frames shown: 1662 (PresentX 1662)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 13569 MB

Not tested

  • In-world rendering: the smoke runs stay in the front-end, so whether the heaps in the coherent window (read by the GPU over PCIe) cost GPU time in the world, against the sparse windows' video memory, is not measured here. On cards with room in video memory the sparse routing may well be faster; this PR is the safe choice for 8 GB cards, and a budget-dependent choice may be better (see #3360).
  • The full GPU test suite, the Series S profile, NVIDIA and other AMD cards.
  • A 157-per-run "retired unified-memory blocks given back early" warning appears with this change; it does not exist on the merge-base, so I have not checked whether it matters.

AI use

  • Claude Code (Claude Opus 5.5, medium effort, subagent) found the cause, wrote the fix and ran the measurements; the commit was re-made cleanly and the smoke blocks re-run by Claude Code (Claude Sonnet 5.5), which coordinated and wrote this text. The account owner did not write the code or this text.
<!-- greyfinch-sync:ivall/xcl:issue:5549936298 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3369). Originally posted by [iggyvilla](https://github.com/iggyvilla) on 2026-11-29T10:43:15Z. --- Refs #3360. **If `108cbafa` routed these heaps to the sparse windows on purpose, please close this PR** (see the open question in #3360). I could not tell from its commit message, so this is the fix for the case where it was not intended. `108cbafa` ("kernelx: decode XMemVirtualAlloc XMemFlags and refine graphics protection handling") makes `xmem_virtual_alloc_flags` add `MEM_GRAPHICS` to every `XMemVirtualAlloc` that has the XMemFlags graphics bit. The title's GPU heaps (four commits, about 4.4 GB, with GPU-accessible `PAGE_GRAPHICS_*` protections) then take the `MEM_GRAPHICS` -> `sparse::alloc` branch of `VirtualAlloc` and never reach the GPU-heap branch that puts them in the coherent window. On an 8 GB card that is video memory for every tile plus the CPU's copy (over the DXGI budget, with warnings), while the coherent window, still committed at its size stored from earlier runs, stays almost empty (64 of 4095 MB used; 3998 of 4095 MB before the commit). Peak commit in the 60 s smoke goes from 20.3 GB (merge-base `2c717a04`) to 25 GB, which is why every PR measured on the new `amd-dev` fails `pr_check.py`'s 1.25x commit rule. **What is in it** - `kernelx.rs`: `xmem_virtual_alloc_flags` takes the protection; a commit (`MEM_COMMIT`) with a GPU-accessible `PAGE_GRAPHICS_*` protection and only the XMemFlags graphics bit gets no `MEM_GRAPHICS`, so it takes the GPU-heap path again (coherent window, or the sparse windows with `XCL_COHERENT_HEAPS=sparse`). Reservations, `PAGE_GRAPHICS_NOACCESS`-only commits and legacy `XALLOC_ATTRIBUTES` memory types keep `MEM_GRAPHICS`, and the rest of `108cbafa` is unchanged. - Test asserts for the new cases in the existing XMemFlags test. **Tested** AMD RX 6650 XT 8 GB, Ryzen 7 5700X, Windows 11, `rustc 1.100.0`, head `23d0f365`. - `cargo test --lib hle::kernelx -- --test-threads=1`: 86 passed, 0 failed, 1 ignored. - 60 s smoke on the unmodified `amd-dev` `f33df5a7`: peak commit 25,028 MB (1,429 frames; a second run 25,412 MB, 1,407 frames). With this change: 13,569 MB, 1,662 frames, no device removals, no crashes (blocks below). - The earlier version of the same change measured 14,480 MB and 1,667 frames. **Regression run** Both 60 s runs with `scripts/smoke.ps1 -Seconds 60`, `XCL_PREPARE=0`, same title and card, compute pipeline cache warmed with `xcl pso-precompile --used`. First `main` `d8bd9a38`, then this PR's head. ``` xcl-smoke v1 commit: d8bd9a38204667f3ca7dd9eeffcc2f1c937b07b0 gpu: AMD Radeon RX 6650 XT title: 1778c2d9 seconds: 60 exit: 0x0 frames shown: 1618 (PresentX 1618) presents per 2 s (last 3): 60 61 60 device removals: 0 crashes: 0 peak commit: 15479 MB ``` ``` xcl-smoke v1 commit: 23d0f365d06af6301fbf688787c59efb8d78bdf9 gpu: AMD Radeon RX 6650 XT title: 1778c2d9 seconds: 60 exit: 0x0 frames shown: 1662 (PresentX 1662) presents per 2 s (last 3): 60 60 61 device removals: 0 crashes: 0 peak commit: 13569 MB ``` **Not tested** - In-world rendering: the smoke runs stay in the front-end, so whether the heaps in the coherent window (read by the GPU over PCIe) cost GPU time in the world, against the sparse windows' video memory, is not measured here. On cards with room in video memory the sparse routing may well be faster; this PR is the safe choice for 8 GB cards, and a budget-dependent choice may be better (see #3360). - The full GPU test suite, the Series S profile, NVIDIA and other AMD cards. - A 157-per-run "retired unified-memory blocks given back early" warning appears with this change; it does not exist on the merge-base, so I have not checked whether it matters. **AI use** - Claude Code (Claude Opus 5.5, medium effort, subagent) found the cause, wrote the fix and ran the measurements; the commit was re-made cleanly and the smoke blocks re-run by Claude Code (Claude Sonnet 5.5), which coordinated and wrote this text. The account owner did not write the code or this text.
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
xcl-dev/xcl!3369
No description provided.