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

Open
opened 2026-11-26 06:37:21 +00:00 by github-bot · 8 comments
Owner

@⁠JeffreyBytes on GitHub · 2026-11-25 19:13 UTC · original

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.

**@⁠JeffreyBytes** on GitHub · 2026-11-25 19:13 UTC · [original](https://github.com/brcly/TuxBox/issues/191) `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.** ```text 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: ```text 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:37:21 +00:00
Author
Owner

@⁠Exorion1er on GitHub · 2026-11-25 19:52 UTC · original

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).

**@⁠Exorion1er** on GitHub · 2026-11-25 19:52 UTC · [original](https://github.com/brcly/TuxBox/issues/191#issuecomment-7172874407) 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: ```text 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: ```text 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: ```c #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).
Author
Owner

@⁠gtb-sbe on GitHub · 2026-11-25 21:00 UTC · original

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.

**@⁠gtb-sbe** on GitHub · 2026-11-25 21:00 UTC · [original](https://github.com/brcly/TuxBox/issues/191#issuecomment-7174494049) 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.
Author
Owner

@⁠DrArroway on GitHub · 2026-11-25 21:24 UTC · original

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).

**@⁠DrArroway** on GitHub · 2026-11-25 21:24 UTC · [original](https://github.com/brcly/TuxBox/issues/191#issuecomment-7175044760) 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`).
Author
Owner

@⁠JeffreyBytes on GitHub · 2026-11-25 21:55 UTC · original

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.

**@⁠JeffreyBytes** on GitHub · 2026-11-25 21:55 UTC · [original](https://github.com/brcly/TuxBox/issues/191#issuecomment-7175710505) 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.
Author
Owner

@⁠gtb-sbe on GitHub · 2026-11-26 00:32 UTC · original

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 (#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.
**@⁠gtb-sbe** on GitHub · 2026-11-26 00:32 UTC · [original](https://github.com/brcly/TuxBox/issues/191#issuecomment-7178859520) 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 (#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.
Author
Owner

@⁠brcly on GitHub · 2026-11-26 01:46 UTC · original

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.

**@⁠brcly** on GitHub · 2026-11-26 01:46 UTC · [original](https://github.com/brcly/TuxBox/issues/191#issuecomment-7180111759) ## Looking for help: let RADV read game memory directly `main` now has a fallback from #200: when the [host profile](https://github.com/brcly/TuxBox/blob/main/docs/USAGE.md#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](https://git.gtahub.st/github/brcly--TuxBox/issues/191)). **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.
Author
Owner

@⁠JeffreyBytes on GitHub · 2026-11-26 02:56 UTC · original

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.

**@⁠JeffreyBytes** on GitHub · 2026-11-26 02:56 UTC · [original](https://github.com/brcly/TuxBox/issues/191#issuecomment-7181251660) 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: ```text 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.
Author
Owner

@⁠DrArroway on GitHub · 2026-11-26 07:10 UTC · original

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.

**@⁠DrArroway** on GitHub · 2026-11-26 07:10 UTC · [original](https://github.com/brcly/TuxBox/issues/191#issuecomment-7185170197) 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](https://git.gtahub.st/github/brcly--TuxBox/issues/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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.