Skip to content

d3d12: buffer-remap regression control fails on RADV, with host memory imports refused #191

Backlog

Description

@JeffreyBytes

python tuxbox.py check on main at 1f40ee4 fails one of the 17 D3D12 regression controls here. The other 16 pass, including buffer-import and buffer-import-reject. #189 notes the same control failing on an RX 9060 XT, so this looks specific to RADV and not to one card.

Setup. RX 6700 XT (1002:73df), Mesa 26.3.1 RADV, Intel i5-12600K, Linux 7.3.5, Proton Experimental 11.0-20261112.

Result.

d3d12-buffer-remap failed: remap readback differs

What the control's log shows. Twice, immediately before a buffer is placed, vkd3d-proton refuses to import the host memory:

vkd3d_try_allocate_device_memory: Failed to allocate 65536 bytes on memory type 5, vr -1.
vkd3d_try_allocate_device_memory: Failed to allocate 65536 bytes on memory type 10, vr -1.
vkd3d_import_host_memory: Failed to import host memory, hr 0x8007000e.
TuxBox d3d12_xs: buffer backing path=pool_open count=1 source=place_virtual_layout bytes=65536

The second refusal follows page remap replaced imported range 0x37c0000..0x37d0000 ... retired stale GPU import. buffer-import, which passes, logs no refused import.

In ProjectScarlett. A 300 s offline run on the same machine logs the same three lines 131 times.

Not established. I haven't found why the import is refused. One possibility is that the kernel driver only accepts anonymous memory for this kind of import and the remapped pages are a shared section, but that is a guess. I also haven't shown that the refused imports cause anything visible in the title. I'm looking into it and will post what I find.

Activity

  1. Exorion1er commented on Nov 25, 2026

    @Exorion1er
    Contributor

    Your guess is right: amdgpu refuses the import because the pages are a shared mapping. libdrm always asks for anonymous-only memory. With that flag cleared, buffer-remap passes and ProjectScarlett gets past the black screen on my RX 9070 XT.

    Setup. RX 9070 XT (1002:7550), Mesa 26.2.7 RADV, libdrm 2.4.134, Linux 7.3.5 (Fedora 44), Proton Experimental 11.0-20261112, TuxBox 7b22d71.

    XMem backs physical pages with pagefile sections (CreateFileMappingW + MapViewOfFile3 in runtime/xmem/src/shared_pages.rs), and Wine maps those as shared Linux mappings. RADV imports a host pointer through libdrm's amdgpu_create_bo_from_user_mem, which always sets AMDGPU_GEM_USERPTR_ANONONLY. The kernel then rejects any page backed by a file. A small native Vulkan program (no Wine) importing 64 KiB through VK_EXT_external_memory_host gives:

    anonymous private            import=0
    anonymous shared (shmem)     import=-1000072003   (VK_ERROR_INVALID_EXTERNAL_HANDLE)
    memfd shared                 import=-1000072003
    /dev/shm file shared         import=-1000072003
    

    With ANONONLY cleared from the DRM_AMDGPU_GEM_USERPTR ioctl, all four return 0.

    buffer-remap fails here too. With a local change that reports which copy differs, all three copies read zero, including the two taken before the remap:

    remap readback differs: bad old=256 alias=256 current=256; current[0]=00000000 want 98760000 (A=12340000)
    

    So it isn't specific to remapping: on RADV the GPU never sees the contents of a section-backed page, and the buffer reads as zeros.

    In ProjectScarlett this is the black screen. Once the shader preload finishes, the title draws about 22 draws per frame and every draw's readback is zero. The UI vertex shader reads its positions and colors from a constant buffer. If that buffer reads as zeros, every vertex collapses and nothing rasterizes. I haven't traced that buffer to these pages directly, but the UI appears once the imports succeed. The same run logs 131 refused imports.

    The workaround I tested is an LD_PRELOAD library that interposes drmCommandWriteRead and clears the flag on the userptr ioctl only:

    #define _GNU_SOURCE
    #include <dlfcn.h>
    #include <stdint.h>
    #include <stdlib.h>
    #include <libdrm/amdgpu_drm.h>
    int drmCommandWriteRead(int fd, unsigned long index, void *data, unsigned long size) {
        static int (*real)(int, unsigned long, void *, unsigned long);
        if (!real) { void *h = dlopen("libdrm.so.2", RTLD_LAZY); real = h ? dlsym(h, "drmCommandWriteRead") : NULL; if (!real) abort(); }
        if (index == DRM_AMDGPU_GEM_USERPTR && size >= sizeof(struct drm_amdgpu_gem_userptr))
            ((struct drm_amdgpu_gem_userptr *)data)->flags &= ~(uint32_t)AMDGPU_GEM_USERPTR_ANONONLY;
        return real(fd, index, data, size);
    }

    (RTLD_NEXT doesn't work here because the Vulkan loader opens libdrm locally.) With it preloaded:

    • buffer-remap, buffer-import and buffer-layout pass, with no refused imports in the log.
    • ProjectScarlett logs 0 refused imports, down from 131. The first non-black present sample is lit=0.998 mean=(32,32,44), the same value as the Account Picker sample in projectscarlett-startup.json (RTX 4070 Ti SUPER). In my own run it got past the intro video and through the menus.

    This is a workaround, not a fix. As far as I can tell, the anonymous-only restriction is deliberate, because a file-backed page can be truncated while a buffer still holds it. Wine doesn't truncate these sections while they are mapped, but I haven't checked every path. A real fix probably belongs either in how TuxBox gives the GPU access to physical pages on AMD, or in libdrm/Mesa if they would accept an opt-out of ANONONLY. I haven't tried either.

    This probably also explains #39 (RX 9060 XT, black after the same milestone).

  2. gtb-sbe commented on Nov 25, 2026

    @gtb-sbe
    Contributor

    I can reproduce this on an RX 9060 XT (I am OP of #189 actually), and it matches what @Exorion1er found. I have a working branch and will open a PR soon.

    Setup. RX 9060 XT (1002:7590), Mesa 26.2.6 RADV, Linux 6.18.60 (NixOS), Proton Experimental 11.0-20261112, TuxBox 1b32189.

    Cause. Calling DRM_IOCTL_AMDGPU_GEM_USERPTR directly, the kernel accepts private anonymous memory and returns EPERM for shared anonymous, memfd and temp file mappings. Without ANONONLY it accepts all of them. Wine creates these sections with memfd_create.

    The provider cannot notice the refusal. vkd3d-proton falls back to unrelated host-visible memory, reports success and still returns the guest pointer from Map. That is why the control logs imported, even with TUXBOX_REQUIRE_BUFFER_IMPORT=1.

    What the PR will do.

    • Add a small preload that hooks drmCommandWriteRead, like @Exorion1er's. It repeats a userptr request without ANONONLY only after the kernel refused it, so anonymous imports keep the driver's behavior. It does not link libdrm or need its headers.
    • Build and load it automatically on amdgpu hosts, in the launcher and for the regression controls in tuxbox.py check. TUXBOX_AMDGPU_IMPORT=0 turns it off in the launcher.
    • Make the buffer-* controls fail when vkd3d-proton logs a refused import.

    Result. Without the preload buffer-remap fails with two refused imports. With it the control passes (768/768 words, none refused), and the full check passes: 67/67 guest checks, 17/17 regression controls and the translator checks.

    Not established. I have not finished a ProjectScarlett run with this yet. It is still a workaround: an opt-out of ANONONLY in libdrm or Mesa would be the cleaner fix, and I haven't checked @Exorion1er's point about truncated files.

    @JeffreyBytes, you said you were looking into this too. If you already have something different in progress, let me know before I open the PR.

  3. DrArroway commented on Nov 25, 2026

    @DrArroway
    Contributor

    Heads-up @gtb-sbe / @JeffreyBytes: I just opened #200 with a runtime/d3d12-side fix (no LD_PRELOAD or libdrm changes) that detects the silent RADV section refusal once per device and mirrors committed MEM_MAPPED ranges through anonymous VirtualAlloc shadow heaps with chunked pre-submit sync. d3d12-buffer-remap (768/768, identical=1 replacement=1), buffer-import, buffer-import-reject, buffer-layout, and tuxbox.py check (67/67 GPU gates) all pass on RX 6900 XT (1002:73bf).

  4. JeffreyBytes commented on Nov 25, 2026

    @JeffreyBytes
    ContributorAuthor

    Following up on my own "I'm looking into it".

    The preload from @Exorion1er's comment reproduces here on the RX 6700 XT (f489d3c, Linux 7.3.6, Mesa 26.3.1): refused imports go from 131 to 0, the first present samples go from lit=0.000 to lit=0.998 mean=(32,32,44), and buffer-remap passes. So that is three RADV cards with the same cause.

    I'm not working on a fix of my own; #200 and #199 cover it. I tested #200 on this card and posted the results there: the controls pass and the game reached the Account Picker and the intro video, with a large slowdown and a crash in two of three runs.

  5. gtb-sbe commented on Nov 26, 2026

    @gtb-sbe
    Contributor

    Since a preload is not wanted, I measured what ProjectScarlett actually does with the pages amdgpu refuses, to see whether XMem and the provider can fix this alone, without per-submit copies.

    Summary

    • Every refused import is an XMem physical page mapped through a section view. None is the registered page pool, a private copy or other memory.
    • The CPU never uses more than one view of the same page.
    • The GPU does: many pages are mapped at 2 to 8 GPU-attribute addresses, so all of those aliases have to see the same memory.

    If that holds, XMem can back every page with private memory, which amdgpu imports fine, and the provider can point every GPU alias of a page at that one backing. Details below; I'd like to know whether that direction is acceptable before I build it.

    Setup: RX 9060 XT (1002:7590), Mesa 26.2.6 RADV, Linux 6.18.60, Proton Experimental 11.0-20261112, main 1b32189, ProjectScarlett 1.0.2.1 offline. Two runs: 54 minutes from a partly warm cache, then 7 minutes with a warm cache. Both reached the 22-draw state (still black) and gave the same import breakdown. Current main (cb8c38b) leaves XMem and the import paths unchanged. It does change the size of some small texture allocations and defaults to GE-Proton11-14, so individual import sizes may differ there; I have not rerun on it.

    1. What is refused

    An opt-in trace classifies every import whose range contains a section view, i.e. every import amdgpu will refuse, and asks XMem which pages are behind it. Both runs: 131 such imports, the same 131 that vkd3d-proton refused.

    Pages behind the import Imports Size
    XMemMapPhysicalPages view, each page mapped only there 10 282 MiB (includes a 174 MiB import at startup)
    XMemMapPhysicalPages view with GPU attributes (0x2404), each page also mapped at 1 to 7 other such addresses 119 459 MiB
    CopyPageMappings destination 2 3 pages

    The CopyPageMappings destinations are reserved with 0x801 (PAGE_NOACCESS plus a GPU bit), so the console gives the CPU no access there. Marking all 3,020 destination pages PAGE_GUARD confirmed it: no CPU access in 54 minutes. So the aperture is a small part of this, not the cause.

    2. Which views the CPU uses

    A section view under Wine gets Linux page-table entries only once something touches the page through that view. /proc/<pid>/pagemap therefore shows per view whether the CPU used it, without changing protections. Three samples in the 22-draw state, all identical:

    Pages mapped at more than one address 14,967 (65,639 views)
    Used by the CPU through two or more views 0
    Used through exactly one view 3,196, always a plain PAGE_READWRITE view; their registered-pool and aperture views are never touched
    Never used by the CPU 11,771, mostly mapped 2 to 8 times with GPU attributes

    3. What this rules out and what it allows

    • Two CPU views sharing one userptr is impossible on Linux: private pages cannot be mapped twice, and every shareable mapping is file-backed, which ANONONLY refuses. ProjectScarlett does not need it.
    • It does need GPU aliases that agree with each other. Copies per alias cannot give that. @DrArroway, to your question: separate shadows per alias would likely diverge here once the GPU writes through one alias and reads through another. I measured the aliases, not GPU writes through them, so that part is inferred.

    Proposed design (not implemented)

    1. XMem gives each physical page one private backing instead of a section: at its CPU view if it has one, otherwise in memory XMem owns. Wine can commit private memory into an existing placeholder (MEM_REPLACE_PLACEHOLDER), so XMem's address layout stays the same.
    2. All other views of the page become GPU aliases without CPU memory, as the console already does for the CopyPageMappings aperture.
    3. The provider imports the backing instead of the view, so every alias shares the same pages, GPU writes reach the CPU, and nothing is copied per submit.

    This is not an AMD-only path: private memory can be imported on every driver, so with the pipeline separation you mentioned in #16, both vendors would keep the same memory model. NVIDIA should behave as before, but I have not tested it there.

    Limits:

    • A CPU access through an alias would fault, although the console allows it for these attributes. ProjectScarlett never does it; other titles might, so XMem would have to detect and log it.
    • A page that gains or loses its CPU view needs a 64 KiB copy and invalidates its GPU imports.
    • An import is only one heap if its backing is contiguous. For 100 of the 119 alias imports the other views are contiguous, but I have not yet measured the backing itself.
    • Treating the plain PAGE_READWRITE view as the CPU view comes from one title.

    @brcly, since you're holding #200 until there is an agreed approach: is this direction acceptable, or is there a reason XMem must keep sections? If it is, I'd measure backing contiguity next and then start with the 10 single-view imports, which need no aliasing at all.

    Notes

    • With GE-Proton11-14, now the default, vkd3d-proton logs Failed to import host memory only once (SHADERS. #16). Counting imports that contain section views on the provider side works on both Protons; I'd use that for the regression controls.
    • libdrm's opt-out, mesa/drm!367 ("amdgpu: Allow creating userptr BO's from files"), has had no activity since June 2024, and libdrm main still sets ANONONLY unconditionally.
    • Thanks to @Exorion1er for the ANONONLY cause and to @JeffreyBytes for the measurements on the RX 6700 XT.
  6. brcly commented on Nov 26, 2026

    @brcly
    Owner

    Looking for help: let RADV read game memory directly

    main now has a fallback from #200: when the host profile shows the GPU can't read imported game memory, TuxBox copies it. It passes buffer-remap, but GPU writes stay in the copy and copying costs speed. We'd like to replace it with direct imports, without a preload library.

    What we know

    • XMem physical pages are section views (runtime/xmem/src/shared_pages.rs, CreateFileMappingW + MapViewOfFile3), which Wine maps as shared memory.
    • Contributors found that amdgpu refuses to import shared mappings as host pointers, because libdrm requests anonymous memory only. Private anonymous memory is accepted.
    • vkd3d-proton then substitutes other memory and still reports success.
    • Pages need to appear at more than one address. In ProjectScarlett many are mapped at 2 to 8 GPU addresses, while the CPU used only one view of each page (measurement).

    Ideas to test (none proven)

    1. Find what imports. From a Wine process on RADV, try each way of allocating and mapping memory (private, pagefile section, placeholder views) and record which the GPU really reads.
    2. One CPU backing, GPU-side aliases. Back pages with private memory, import each page once, and point every GPU address at that import (placed or reserved resources). Check first whether any title reads a second CPU view.
    3. Private until aliased. Use private memory for pages with a single mapping and sections only for aliased ones. This only helps if enough pages are never aliased, so measure that first.
    4. Upstream. Ask Mesa/libdrm for a supported way to import shared mappings.

    How to tell it works

    • The host profile logs section-import=aliased on RADV with no override.
    • python tuxbox.py check passes on AMD, including buffer-remap, and still passes on NVIDIA.
    • Page remapping still behaves: a GPU write through one address is visible through the others and to the CPU.

    TUXBOX_HOST_PROFILE=section-import=aliased forces direct imports, which reproduces the failure on RADV.

  7. JeffreyBytes commented on Nov 26, 2026

    @JeffreyBytes
    ContributorAuthor

    One data point for "page remapping still behaves", from a long run with direct imports on RADV.

    RX 6700 XT, Mesa 26.3.1, Linux 7.3.6, GE-Proton11-14, cb8c38b, ProjectScarlett offline. To get direct imports I used the ANONONLY preload from earlier in this thread, as a diagnostic only. The run went through the Account Picker, intro video and first-run settings, then loaded for 82 minutes with no failed presents.

    At 96 minutes the title remapped pages under existing imports for the first time. The provider logged 24 lines of page remap replaced imported range … retired stale GPU import (batches=272), and the next submit failed:

    radv/amdgpu: The CS has been rejected, see dmesg for more information (-14).
    d3d12_command_queue_execute: Failed to submit queue(s), vr -4.
    d3d12_device_mark_as_removed: Device … is lost (reason 0x887a0005, "VK_ERROR_DEVICE_LOST").
    

    The game then exited with code 3. buffer-remap passes with the same preload, so the control does not cover this.

    I have not traced it further. My guess is that RADV submits every live buffer with each command stream, so a host-pointer import whose pages were remapped makes the kernel reject the whole submit with EFAULT, even if the provider has already retired that import. If so, any design that imports the title's pages directly on amdgpu needs the old import fully destroyed before the remap, which NVIDIA would not reveal.

  8. DrArroway commented on Nov 26, 2026

    @DrArroway
    Contributor

    Tested @brcly's Ideas #1 and #2 plus @JeffreyBytes's -14 (EFAULT) note using a standalone C++ D3D12 probe on RX 6900 XT (1002:73bf), GE-Proton11-14 (vkd3d-proton 3.2.0), Mesa RADV 26.3.1, TiledResourcesTier = 4, ID3D12Device13.

    Idea #1 — What imports directly (OpenExistingHeapFromAddress1 + GPU copy readback)

    Allocation / mapping Result Notes
    VirtualAlloc(MEM_RESERVE | MEM_COMMIT) aliased GPU→CPU writeback visible directly
    VirtualAlloc2(MEM_RESERVE_PLACEHOLDER) split + MEM_REPLACE_PLACEHOLDER (MEM_PRIVATE) aliased Matches @gtb-sbe's placeholder plan
    VirtualAlloc(... | MEM_WRITE_WATCH) aliased —
    CreateFileMappingW + MapViewOfFile(FILE_MAP_ALL_ACCESS) substituted (00000000) —
    CreateFileMappingW + MapViewOfFile(FILE_MAP_COPY) substituted (00000000) CoW view is still refused
    CreateFileMappingW + MapViewOfFile3(MEM_REPLACE_PLACEHOLDER) substituted (00000000) —

    Idea #2 — One MEM_PRIVATE backing + GPU-side aliases (CreatePlacedResource and CreateReservedResource + UpdateTileMappings)

    • Placed alias on one heap: Two CreatePlacedResource buffers at offset 0 on one MEM_PRIVATE heap share writes cleanly (gpu:match, cpu:match).
    • Reserved buffer across non-contiguous heaps: Created two 2-tile (128 KiB) CreateReservedResource row-major buffers (D3D12_RESOURCE_FLAG_NONE) and mapped tiles across three separate 64 KiB MEM_PRIVATE heaps (A, B, C) and a 2-tile contiguous MEM_PRIVATE heap (D) via queue->UpdateTileMappings:
      • Reads from non-contiguous tiles (A, B) and sub-heap tile offset 1 (D) all match.
      • GPU write to res1 tile 0 (heapA) is immediately visible both on CPU and via res2 tile 1 (second alias of heapA).
      • Remapping res1 tile 0 from heapA → heapC via UpdateTileMappings reads C cleanly with GetDeviceRemovedReason() == S_OK (no VirtualFree/unmap needed).

    (Note: this probe tested CopyBufferRegion on reserved buffers; CBV/SRV/UAV shader access and ALLOW_UNORDERED_ACCESS on reserved buffers still need a quick check.)

    @JeffreyBytes's -14 (EFAULT) reproduction

    • Importing a MEM_PRIVATE page with OpenExistingHeapFromAddress1, keeping that ID3D12Heap alive, calling either VirtualFree(MEM_RELEASE) or VirtualFree(MEM_DECOMMIT), and then submitting a completely unrelated CopyBufferRegion on two ordinary committed buffers reproduces the crash in one submit:
      radv/amdgpu: The CS has been rejected, see dmesg for more information (-14) → VK_ERROR_DEVICE_LOST (0x80004005).
    • So @JeffreyBytes's explanation is spot-on: any direct-import path on RADV has to keep each underlying MEM_PRIVATE backing mapped until its imported ID3D12Heap drops (and remap GPU aliases in-place via UpdateTileMappings or new resources rather than pulling userptr pages out from under a live heap).

    @gtb-sbe, combined with your measurement in #191, CreateReservedResource + UpdateTileMappings also removes the backing-contiguity requirement for those multi-alias imports (and handles remaps cleanly). Happy to test/benchmark if you're already moving forward with the single-CPU-backing xmem side, or collaborate on splitting the xmem + d3d12 pieces once @brcly gives the green light.

  9. Exorion1er commented on Nov 26, 2026

    @Exorion1er
    Contributor

    I opened #218 for the d3d12 side of the "one private backing, GPU-side aliases" direction. Before importing, the provider asks XMem which memory holds a guest range and imports that memory instead. It also keeps the memory held until the native heap is gone, which covers the -14 (EFAULT) crash. The contract for XMem is two exports, documented in backing.rs. Without them nothing changes, so it fits with @gtb-sbe's XMem work rather than overlapping it. Backings that aren't contiguous are left out for now; @DrArroway's reserved-resource probe is the obvious next step there.

    One data point on the copy fallback from #200: on an RX 9070 (1002:7550, Mesa 26.2.7, Proton Experimental, 31dd5a3), ProjectScarlett runs at about 1 fps in the intro without a preload (11 frames in 10 s, every present sample black), against normal speed with the ANONONLY preload. The host profile reports section-import=substituted and the copy path is active.

  10. DrArroway commented on Nov 26, 2026

    @DrArroway
    Contributor

    Follow-up on the CBV/SRV/UAV footnote above (same setup: RX 6900 XT 1002:73bf, GE-Proton11-14, Mesa RADV 26.3.1):

    • CreateReservedResource with D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS and D3D12_RESOURCE_FLAG_NONE across 5 separate 64 KiB MEM_PRIVATE OpenExistingHeapFromAddress1 heaps succeeded (S_OK) and returned valid GetGPUVirtualAddress() values.
    • Descriptor-table SRV/UAV + root CBV (+256): Compute shader read across non-contiguous tiles 0 & 1 of srvRes and wrote across non-contiguous tiles 0 & 1 of uavRes; both CPU pointers and a second reserved buffer aliasing the same destination tiles (swapped) observed the exact results.
    • Root CBV + Root SRV + Root UAV (GetGPUVirtualAddress()): Same result — both CPU and the swapped alias buffer observed the exact shader output.

    Nice work on #218 (@Exorion1er) and #220 (@JeffreyBytes) — happy to help wire up the non-contiguous CreateReservedResource + UpdateTileMappings path on top of #218 if @gtb-sbe's backing-contiguity measurements show it's needed.

  11. JeffreyBytes commented on Nov 26, 2026

    @JeffreyBytes
    ContributorAuthor

    I looked into idea 4 (getting this fixed in Mesa), and I think it can be ruled out. Summary with sources, so nobody has to repeat the search:

    • The flag is not Mesa's. RADV's radv_amdgpu_winsys_bo_from_ptr() calls ac_drm_create_bo_from_user_mem(), which forwards to libdrm's amdgpu_create_bo_from_user_mem(). libdrm hardcodes AMDGPU_GEM_USERPTR_ANONONLY | REGISTER | VALIDATE there (amdgpu/amdgpu_bo.c, since 2015) and no caller can change it. The kernel then returns -EPERM for any VMA with a backing file (amdgpu_ttm_tt_get_user_pages() in amdgpu_ttm.c).
    • The kernel maintainer wants it stricter, not looser. In libdrm issue 89 (opened by RPCS3 for the same problem), Christian König calls anonymous-only "a must have": the GPU can't take write faults, so GPU writes to file-backed pages bypass writeback tracking. He says the kernel should reject every userptr without the flag, and that it only accepts them today because a 2016 revert was lost. He would not accept a libdrm call that drops the flag. libdrm MR 367, which tried, has been open since 2024. A Mesa issue about memfd host-pointer imports was closed this year as a kernel matter, and a recent kernel fix (d577b68) tightened the anonymous-only check further.
    • His suggested route for shared memory is udmabuf on a memfd, imported as a dma-buf. From a Wine guest that would need a Linux fd for the section, so it is a Wine-side change, not something XMem can do alone.

    What this means here:

    1. The ANONONLY preload works through a gap the kernel maintainer intends to close. It is fine as a diagnostic, but it can stop working with any kernel update, and it should not become a default.
    2. Private (anonymous) backing with GPU-side aliases, as in d3d12: import XMem physical pages through their backing #218 plus the XMem side, is the direction that agrees with upstream.
    3. The second hazard is also by design. RADV keeps every allocation, host-pointer imports included, on one global buffer list that goes into every submission (radv_amdgpu_get_bo_list()), and the kernel revalidates each userptr buffer on every submit (amdgpu_cs_parser_bos()). One import whose pages are gone therefore fails all later submits with -EFAULT. That matches the buffer-unmap-alive control, and it confirms that the hold in d3d12: import XMem physical pages through their backing #218 is needed rather than a workaround.

    I read the kernel, libdrm and Mesa sources and the linked threads, but did not test other vendors. From source, i915 and xe have no such file check; I have no information on NVIDIA.

  12. gtb-sbe commented on Nov 26, 2026

    @gtb-sbe
    Contributor

    @DrArroway, here are the backing-contiguity numbers you asked about. Short answer: the non-contiguous path is needed, for 16 of 131 imports (about 37 % of the imported bytes) in ProjectScarlett.

    The model is one private backing per physical page: the page's CPU-used view if it has one, otherwise memory that XMem places. Every other view of the page is a GPU alias. No page was CPU-used through more than one view, so the model fits this title.

    Result: These are the 131 imports that contain section views (741 MiB), up to the 22-draws-per-frame state:

    Imports Count MiB Backing
    CPU-used view is the import itself or one contiguous range 3 174.2 import the CPU view directly
    GPU aliases only, all imports agree on the page order 112 289.3 XMem places each chain of pages contiguously
    GPU aliases only, imports disagree on the page order 16 277.6 CreateReservedResource + UpdateTileMappings, or a copy
    CPU-used views present but not contiguous 0 0

    So no import has scattered CPU memory. The problem is pages that are only GPU aliases.

    Why the 16 conflict: The 128 alias-only imports map 6,208 distinct pages, each at 2-7 GPU addresses. With one backing per page, an import is contiguous only if every import of the same pages lists them in the same order. Most do: the pages form 69 consistent chains, the longest 680 pages, without cycles. But 11 pages have two different successors and 12 have two different predecessors across imports.

    • All 16 are resources the title places at chosen addresses (place_virtual_layout), 3.6-64 MiB each.
    • They exist at the same time: at the end of each run, every page was still mapped where the import saw it. A remap does not separate them.
    • With every conflicting link cut, they split into 65 pieces (2-9 per import). A placement that keeps one side of each conflict needs fewer, so 65 is an upper bound on the tile ranges.
    • The 112 row is worked out from the page orders, not tested with an implementation.

    CPU views don't move: In 20 s rounds over 4-6 min per run, no CPU-used view moved to another address. During loading the title unmaps 4,000-7,000 CPU views within one round, but none of them belongs to a page any import uses. After about one minute the same 3,772 CPU views stay in place. So imports were never retired because a CPU view moved.

    How this was measured:

    • Build: main f3149ab (d3d12: import XMem physical pages through their backing #218 merged; XMem doesn't have the backing exports yet, so imports still use the guest address) plus a local trace branch.
    • Host: RX 9060 XT (1002:7590), Mesa 26.2.6 RADV, Linux 6.18, GE-Proton11-14, warm caches, offline, no preload.
    • Runs: three, each to the 22-draws-per-frame state (Account Picker) and 2-5 min beyond, with the same results.
    • Method: the trace records the physical pages behind every import that contains section views. A census thread reads /proc/<pid>/pagemap every 20 s to see which view of each page the CPU has touched.
    • The runs use TUXBOX_HOST_PROFILE=section-import=aliased, because the d3d12: mirror section-backed imports through anonymous shadow heaps on RADV #200 shadow reads every imported view on the CPU, which would count as CPU use.

    Limits: One title (ProjectScarlett 1.0.2.1), only up to the Account Picker without input; the intro and gameplay may map memory differently. Pagemap presence counts any touch since the view was mapped.

    For comparison: the copy path on this card. Same offline cold start before and after #200:

    main Memory path Average presented fps over the run (mostly loading) Furthest point
    cb8c38b direct import, silently substituted ~174 black screen at the 22-draws-per-frame state
    9b31fd8 copy (#200, section-import=substituted) ~13 Account Picker, then the story intro
    • The Account Picker ignored Enter and the controller while the title was still loading behind it. After the draw count rose, Enter worked.
    • The story intro then plays at about 0.6 fps (6 frames per 10 s), like Exorion1er's ~1 fps on the RX 9070. Then come the first-run settings and the start of loading into the game.
    • In the ~23 minutes after the picker there was no device loss, no exception, no title watchdog, and no import retired by a page remap. I stopped it there, since loading at this frame rate would take hours.
    • That run had one small local change in compute pipeline creation (root-keyed translation first, see dxil-spirv Failed to remap in ProjectScarlett: which bindings cause them (RX 9060 XT) #233). It doesn't touch memory.

    I can rerun this against an XMem implementation of the backing exports, or post the per-import list if that helps.

  13. DrArroway commented on Nov 26, 2026

    @DrArroway
    Contributor

    Thanks @gtb-sbe for measuring the backing contiguity across ProjectScarlett's 131 imports — having those exact counts (16 imports / 277.6 MiB with conflicting page orders, 65 pieces max) settles that the CreateReservedResource + UpdateTileMappings path is needed on top of #218.

    I opened #253 with the d3d12 non-contiguous backing side on top of #218. It keeps TuxBoxAcquirePhysicalBacking + TuxBoxReleasePhysicalBacking unchanged and falls back to an optional third export when TuxBoxAcquirePhysicalBacking fails with ERROR_NOT_SUPPORTED:

    struct BackingRun { UINT64 address; UINT64 bytes; }
    BOOL TuxBoxAcquirePhysicalBackingRuns(UINT64 address, UINT64 bytes, BackingRun* runs, UINT32* count, UINT64* hold);
    

    When exported, d3d12 opens each 64 KiB-aligned run with OpenExistingHeapFromAddress1, maps them onto a CreateReservedResource buffer with synchronous UpdateTileMappings, and holds every piece heap + the XMem hold until all native resources on it are released. Like #218, it stays dormant until xmem.dll adds the backing exports.

  14. DrArroway commented on Nov 26, 2026

    @DrArroway
    Contributor

    Picking up the runtime/xmem/ half of #191 (TuxBoxAcquirePhysicalBacking, TuxBoxAcquirePhysicalBackingRuns, and TuxBoxReleasePhysicalBacking, backed by private anonymous memory + lifetime holds) to pair with #218 and #253.

  15. JeffreyBytes commented on Nov 26, 2026

    @JeffreyBytes
    ContributorAuthor

    @DrArroway, glad you're taking the XMem half. I had scoped it this morning before you picked it up, and three things came out of reading the code that I haven't seen mentioned here. They only matter if aliases other than a page's CPU view stop being mapped for the CPU (the "one private backing, GPU-side aliases" model), so ignore whatever doesn't fit your design.

    1. The provider reads game addresses on the CPU. snapshot_mip in runtime/d3d12/src/device/placement.rs copies texture data with ReadProcessMemory from the guest address. If that address is an alias with no CPU mapping, the read fails quietly and the snapshot is skipped, so it would need to go through the backing as well.
    2. The host profile probes a section view. section_probe decides section-import=aliased|substituted, and on RADV it will keep answering substituted whatever XMem does, because sections still can't be imported. The mirror path (needs_mirror) keys off that, so the profile needs a way to learn that XMem pages now import through their backing.
    3. Two tests assert CPU visibility through a second view. runtime/xmem/guest.c (the 0x2404 / 0x10404 alias cases around the scatter tests) writes through one view and reads through another, and the buffer-remap control reads through the CopyPageMappings destination. @gtb-sbe's census says ProjectScarlett never does this, but the tests do.

    Also, for a moved or freed backing with a hold alive: the contract in #218 says the old range stays mapped and its contents no longer matter. buffer-unmap-alive shows what happens on amdgpu if it doesn't stay mapped, so a variant of that control on XMem pages (remap and free under a live import, later submits still ok) would catch a regression there. I can write that control against your branch if it helps.

    And the offer from #218 stands: once the exports exist I'll run ProjectScarlett on the RX 6700 XT without the preload. The device loss comes two to six minutes in here, so it's a quick yes or no.

  16. DrArroway commented on Nov 26, 2026

    @DrArroway
    Contributor

    @JeffreyBytes PR is up for the runtime/xmem/ half in #258 (feat/xmem-physical-backing). Here is how each point lands against the implementation:

    1. snapshot_mip (ReadProcessMemory): GPU aliases still receive committed MEM_PRIVATE PAGE_READWRITE pages populated when mapped, so ReadProcessMemory at an alias VA continues to succeed without failing.
    2. section_probe / needs_mirror: import.rs already gates mirroring on needs_mirror(...) && contains_mapped_pages(memory, size). Since XMem backings are MEM_PRIVATE (not MEM_MAPPED), RADV skips the d3d12: mirror section-backed imports through anonymous shadow heaps on RADV #200 shadow copy automatically—buffer-remap logs TuxBox d3d12_xs: game memory is imported through its XMem backing and path=imported with no shadow copy—while any lazily promoted SharedSection pages still mirror safely.
    3. Second-view CPU visibility tests: xmem-pages, xmem-scatter (runtime/xmem/guest.c), and buffer-remap all pass (tuxbox.py check on RX 6900 XT 1002:73bf is green across all 10 groups). A second CPU view of a token lazily promotes it to SharedSection for CPU coherence, and CopyPageMappings populates the alias pages.
    4. Held-backing lifetimes: TuxBoxAcquirePhysicalBacking / TuxBoxAcquirePhysicalBackingRuns keep held MEM_PRIVATE views and PrivateArena backings mapped across unmap, remap, and free until TuxBoxReleasePhysicalBacking(hold) drops the last reference (covered by 4 unit tests in runtime/xmem/src/tests/physical_backing.rs).

    Would definitely appreciate your XMem buffer-unmap-alive regression control and an RX 6700 XT ProjectScarlett run against #258 without the preload!

  17. Kayotic1337 commented on Nov 26, 2026

    @Kayotic1337

    A data point from an RDNA 4 card: on current main, buffer-remap passes here, although the host-memory import is still refused once.

    Setup. RX 9070 XT (1002:7550), Mesa RADV 26.3.1, Ryzen 7 9800X3D, Linux 7.3 (CachyOS), GE-Proton11-14, TuxBox main at 68e79b7, Microsoft DXC v1.8.2505.1.

    Result. python tuxbox.py check --proton <GE-Proton11-14> --prefix <fresh prefix> --windows-dxc <dxc x64>: all checks passed. That includes Lanes and fixtures (all guest checks), all 19 D3D12 regression controls (buffer-remap, buffer-import, buffer-import-reject, buffer-unmap-*), and 112/112 translator GPU checks.

    What buffer-remap.log shows. The refusal from the report is still there, once:

    warn:vkd3d-proton:vkd3d_import_host_memory: Failed to import host memory, hr 0x8007000e.
    TuxBox d3d12_xs: buffer backing path=pool_open count=1 source=place_virtual_layout bytes=65536
    

    The control nevertheless passes: the readback matches after the fallback to pool_open. The same refusal also appears once each in root-cbv-window, buffer-unmap-alive and buffer-unmap-released, which pass too.

    Not established. Whether the difference from the report comes from the newer main, from GE-Proton11-14 against Proton Experimental 11.0-20261112, or from the card. I have not run the older commit or Proton Experimental here.

    Related, from another project on the same machine (VIctory forks under Wine + vkd3d-proton, so not TuxBox code). Importing title memory in place worked for private allocations, with GPU and CPU seeing each other's writes. Section-backed / page-pool heaps opened but were not shared: the GPU did not see the CPU's bytes. That is consistent with the guess in the report.

    AI assisted (Claude Code)

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions