Skip to content

xmem: back physical pages with private memory and export backing holds - #258

Draft
DrArroway wants to merge 1 commit into
brcly:mainfrom
DrArroway:feat/xmem-physical-backing
Draft

DrArroway wants to merge 1 commit into
brcly:mainfrom
DrArroway:feat/xmem-physical-backing

Conversation

@DrArroway

Copy link
Copy Markdown
Contributor

Implements the runtime/xmem/ half of #191 so RADV can import XMem physical pages directly via VK_EXT_external_memory_host without hitting libdrm's AMDGPU_GEM_USERPTR_ANONONLY rejection or falling back to the #200 shadow copy. Pairs with #218 (already on main) and #253.

Part of #191

Summary

  • Private anonymous physical backings (MEM_PRIVATE, PAGE_READWRITE):
    • Single CPU views and GPU aliases allocate MEM_PRIVATE pages inside placeholder apertures rather than section views (runtime/xmem/src/physical_pages/private_views.rs, runtime/xmem/src/shared_pages.rs).
    • Mapping a second CPU view of the same token lazily promotes it to SharedSection so existing multi-view CPU aliases remain coherent.
    • Pure GPU aliases (or contiguous ranges with non-contiguous/conflicting backing order) promote unbacked tokens on demand into a shared PrivateArena (VirtualAlloc MEM_PRIVATE).
  • Lifetime holds & deferred unmaps (runtime/xmem/src/physical_pages/backing.rs):
    • Exports TuxBoxAcquirePhysicalBacking, TuxBoxAcquirePhysicalBackingRuns, and TuxBoxReleasePhysicalBacking as PRIVATE symbols in runtime/xmem/xmem.def.
    • Unmapping, remapping, or freeing held backing ranges defers virtual teardown until TuxBoxReleasePhysicalBacking(hold) drops the last reference, keeping imported MEM_PRIVATE host pages valid across live GPU submissions.
  • Unit tests (runtime/xmem/src/tests/physical_backing.rs):
    • Covers private CPU view acquisition + ERROR_NOT_FOUND on foreign memory, held CPU views surviving unmap/free, PrivateArena + conflicting-order BackingRun splitting + ERROR_MORE_DATA, and lazy SharedSection promotion on a second CPU view.

Verification

Tested on RX 6900 XT (1002:73bf), Linux (7.3.6-1-cachyos), GE-Proton11-14 (1795427215), RADV:

  • cargo check --locked --target x86_64-pc-windows-msvc --manifest-path runtime/xmem/Cargo.toml: passed (0 warnings)
  • Wine cargo test --locked --target x86_64-pc-windows-msvc --manifest-path runtime/xmem/Cargo.toml -- --test-threads=1: 4/4 passed (physical_pages::backing::tests)
  • python -m unittest tests.test_repository_hygiene: 5/5 passed
  • tools/check_d3d12_regressions.py --case buffer-remap --adapter 1002:73bf: PASS (4.418s, d3d12-buffer-remap PASS pci=1002:73bf words=768/768 identical=1 replacement=1, null_fallback_enabled: false)
    • Log confirmed TuxBox d3d12_xs: game memory is imported through its XMem backing and three path=imported entries, with zero copied for the GPU messages.
  • Full tuxbox.py check --adapter 1002:73bf: all 10 groups passed:
    • Lanes and fixtures on the GPU: 72/72 passed (170s, including xmem-pages and xmem-scatter)
    • D3D12 regression controls: 19/19 passed (85s)
    • Shader translator on the GPU: 40/40 passed (238s)

@JeffreyBytes

JeffreyBytes commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

ProjectScarlett run on the RX 6700 XT without the preload, as asked on #191. Short version: with this PR's xmem.dll the title hangs during start-up, before the first frame, so I can't say anything yet about the remap.

Setup: RX 6700 XT (1002:73df), Mesa RADV 26.3.1, Linux 7.3.6, GE-Proton11-14, ProjectScarlett 1.0.2.1 offline, shaders prepared, no LD_PRELOAD. Both xmem.dll and d3d12_xs.dll rebuilt and staged for each row.

tree result
main 5c5677b (this PR's base) starts normally on the copy path, 6 presents per 11 s, still running when I stopped it at 240 s
5c5677b + this PR (cd8ad92) exit code 5 after 57.5 s, no present
5c5677b + this PR + #253 (f9b630d) exit code 5 after 64.2 s and 60.6 s (two runs), no present

What the failing runs have in common

  • The title's crash log says Game State: System Init, Frame: 0. The stack is game_scarlett_master.exe+0x2215C35 ← +0x2215ECA, which is the 30 s main-thread watchdog from ProjectScarlett: 30 s main-thread watchdog (exe+0x23CF683) at the story intro from cross-queue label-wait deadlocks #215. So the main thread stopped making progress about 20 to 30 s after launch and the watchdog ended the run.
  • The last line from the provider is the same every time:
    TuxBox d3d12_xs: created pipeline from Xbox slot 86 stream (688 bytes)
    
    On the base commit the next lines are prepared compute shader loaded …, created compute pipeline with 6 reflected FSSM descriptor slots, memory wait trace #1 … and submitted first guest batch. With this PR none of them appear.
  • game memory is imported through its XMem backing is never logged, the host profile is section-import=substituted, and there is no page remap and no rejected submit. It doesn't get as far as an import.

I don't have a stack for the hung thread, only the watchdog's, so I can't say where it is waiting. Since the provider is identical in rows 1 and 2, it is something the title does through XMem between creating that first raster pipeline and its first compute pipeline.

tuxbox.py check was not part of this; I only ran the game. If it helps I can rerun with any tracing you want switched on (for example a log line per XMem export call), or try a branch.

Update, same day: the runs above shared the machine with other GPU tests of mine, so I repeated them with nothing else running (no other Proton guest or compile in any 5 s sample, load below 5), alternating the two trees:

tree result
5c5677b + this PR exit code 5 after 41.3 s, no present
5c5677b normal, 6 presents per 10 s, stopped at 150 s
5c5677b + this PR exit code 5 after 40.9 s, no present

Same crash log and same last provider line. So it is not a load effect: five of five runs with this PR's xmem.dll hang at start-up, and both runs without it don't.

@DrArroway
DrArroway marked this pull request as draft November 26, 2026 18:53
@DrArroway

Copy link
Copy Markdown
Contributor Author

Thanks @JeffreyBytes for running that and catching the System Init hang! We reproduced the exact same 30 s watchdog crash (game_scarlett_master.exe+0x2215C35 right after created pipeline from Xbox slot 86 stream) locally on RX 6900 XT with cd8ad92.

Moving this PR to Draft while we track down the root cause in xmem and verify the fix locally before marking it ready again.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants