Skip to content

amd-dev: XMemVirtualAlloc GPU heaps go to the sparse windows since 108cbafa (+10 GB peak commit, every amd-dev PR fails pr_check's 1.25x commit rule) #3360

Done

Description

@iggyvilla

Setup

Windows 11, AMD RX 6650 XT (8 GB), 32 GB RAM. One retail title, scripts/smoke.ps1 -Seconds 60,
XCL_PREPARE=0, otherwise default environment, compute pipeline cache warmed with
xcl pso-precompile <game> --used. Every build measured the same way, one run at a time.

The gap

build peak commit frames
main d8bd9a3 15479 MB 1618
merge-base 2c717a0 20312 MB 1615
amd-dev f33df5a 25028 / 25412 MB (two runs) 1429 / 1407

scripts/pr_check.py requires a PR's peak commit to be at most 1.25x main's (19349 MB here), so
every PR against amd-dev fails that line on this machine whatever it changes.

Cause

Commit 108cbaf ("kernelx: decode XMemVirtualAlloc XMemFlags and refine graphics protection
handling") makes xmem_virtual_alloc_flags add MEM_GRAPHICS whenever XMemFlags bit 1 is set.
The title's GPU heaps (four commits, about 4.5 GB in all, with GPU-accessible PAGE_GRAPHICS_*
protections) come through XMemVirtualAlloc with that bit set. With MEM_GRAPHICS they hit
VirtualAlloc's MEM_GRAPHICS -> sparse::alloc branch before they reach the GPU-heap branch that
puts them in the coherent window. So:

  • the heaps are in the sparse windows: video memory for every tile plus the CPU copy. Sparse pools
    reach 4.8 GB by 8 s, 4.4 GB of it never written by the CPU, and the process goes over its video
    memory budget (24 warnings per run);
  • the coherent window is still committed at the size stored from earlier runs (4095 MB) and stays
    empty: the log shows coherent 64/4095 MB, against 3998/4095 MB on the merge-base.

Checks that confirm it: XCL_TRACE_MEM shows the four heaps as "graphics, sparse VRAM" with flags
0x30003000 (MEM_GRAPHICS set). XCL_COHERENT_MB=512 on amd-dev alone gives 21220 MB, so the empty
window accounts for about 4.2 GB of the gap.

Proposed fix

In xmem_virtual_alloc_flags, a commit (MEM_COMMIT) with a GPU-accessible protection
(PAGE_GRAPHICS_GPU_ACCESS) 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. The fix is the draft PR #3369 (close it if
108cbaf's routing was intended):

build peak commit frames
amd-dev f33df5a 25412 MB 1407
amd-dev + fix 13879 MB (14480 MB on an earlier version of the same change) 1666

No device removal or crash. cargo test -p xcl --lib hle::kernelx: 86 passed, 0 failed,
1 ignored.

Open points:

  • Did 108cbaf mean to move the heaps to video memory (GPU speed, or in-world correctness)? The
    coherent window is system memory read over PCIe, which is slow for compute (see D3D12.X: sparse tiles outside the GPU heaps can live in system memory #2987's data), so
    the sparse routing may be faster on a card with room. On an 8 GB card it is not: the sparse
    pools put local video memory over the DXGI budget (about 6.3-6.6 GB here), and the same compute
    dispatches then ran 4-45x slower once WDDM paged (one program 2.7-3.1 ms under budget, 133-365 ms
    over it, in a GPU-timed run on this card) (earlier base, before 108cbaf). So the routing probably wants to depend on the card's video memory budget,
    not be fixed either way. Related: kernelx: XMemVirtualAlloc reads its 4th argument as a flags word #3173, kernelx: XCL_COHERENT_HEAPS=sparse:N puts big GPU heaps in video memory #2009.
    The commit message does not say. If it did, XCL_COHERENT_HEAPS=sparse still gives that routing,
    but then the stored coherent size should follow so that the window is not committed empty.
  • With the fix the window is full: a 596 MB heap and two small ones fall back to write-watched
    plain memory, as on the merge-base. About 157 "retired unified-memory blocks ... given back"
    warnings appear per run.
  • Not tested: in-world rendering (the smoke run stays in the front-end), the full GPU test suite,
    the Series S profile, NVIDIA.

Main is also about 4.8 GB below the merge-base on its own, from changes amd-dev does not have yet.
That part of the gap is not caused by amd-dev.

AI use: Claude Code (Claude Opus 5.5, medium effort, subagent) measured and wrote this; coordinated by Claude Code (Claude Sonnet 5.5); the account owner did not write it.

108cbafa is on amd-dev only (a direct commit, no PR); main and nvidia-dev do not have it, and main's own run is the 15.5 GB above.

Activity

  1. added
    bug
    gpu:amd
    area:memory
    on Nov 29, 2026
  2. raylitebull commented on Nov 29, 2026

    @raylitebull
    Member

    Not intended – 108cbaf was meant to decode the XMemFlags and strip NOCACHE/WRITECOMBINE; routing the committed GPU heaps through MEM_GRAPHICS → sparse::alloc ahead of the coherent-window branch was a side effect (our own runs used XCL_COHERENT_HEAPS=sparse:1024, which hid it). Your diagnosis matches the code. I've merged #3369 on top of amd-dev (10582c4) – thanks!

  3. oni-swr commented on Nov 29, 2026

    @oni-swr
    Contributor

    Paired 90 s menu-only smoke of amd-dev before and after #3369, single run each, so treat the numbers as one sample.

    Setup: RX 7800 XT 16 GB (RDNA3), driver 32.0.31035.1003, Windows 11 build 26200. Release builds, scripts/smoke.ps1-style 90 s guest timer, XCL_PREPARE=0, isolated copy of the shader/driver cache per arm, same title and same settings in both arms. The only code difference between the two commits is #3369 (kernelx.rs, 22 added / 8 removed lines).

    f33df5a (before) 10582c4 (after #3369)
    Peak system commit 51.2 GiB 39.3 GiB
    Peak process commit 23.7 GiB 12.5 GiB
    Peak local VRAM 10.4 GiB 4.0 GiB
    Last logged usage coherent 69/4095 MB, sparse 9220 MB coherent 3999/4095 MB, sparse 7445 MB
    Presents in 90 s 2405 2545
    Device removals / crashes 0 / 0 0 / 0
    "over the budget" warnings 0 0

    So the symptom in this issue reproduces on this card (about 12 GiB more peak commit, and the coherent window almost empty while the sparse windows take the heaps), and #3369 removes it. I saw no over-budget warnings in either arm here: Windows' local budget was 12.4 GiB before the fix versus 15.4 GiB after, with peak usage under it in both. Only the menu was tested, not world load, and nothing on RDNA4 or NVIDIA.

    Thanks to @iggyvilla for the diagnosis.

    AI use: this run and comment were made with Claude Code, Claude Sonnet 5.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:memorybuggpu:amd

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions